-
Here is my code, but it seems that Should I get the results into |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
It might be easier if you started with a Java program, rather than bridging between python and Java. In my experience, the command line options are deceptively simple compared to how flexible the Compiler class is. I've found it is nearly impossible to use it without first starting from the command line runner, figuring out what kinds of options it would have created, and what each of those options would have done to the Compiler to produce what you expected, and only they start tweaking things in ways that are impossible with the command line... With that said, poking quickly at the Java sources where result.transppiled files is read, for example: and (this one indirectly): In both cases, the compiler isn't optimizing, but just transpiling - as the name suggests. As such, you probably don't want this, if your implementation of createCompiler options is what you actually want As I understand it, this is mostly/only used for BUNDLE code, to rewrite es6 modules into something that can be inlined into a single output JS file. In contrast, you're probably after either a single output file, or the initial file and its corresponding chunks? If so, looking at how the command line runner walks the specified chunks then calls
|
Beta Was this translation helpful? Give feedback.
-
Yeah, I did the same.
I have also poked, and found nothing useful. I mean I have tried different options set in those context, but still get an empty array. But thanks for the info. It feels like that prop is used only when outputting legacy versions of ECMAScript is requested. The following snippet from ClosureCompiler import *
from ClosureCompiler.lowLevel import *
c = Compiler(createCompilerOptions(
languageOut = ji.CompileLanguageMode.ECMASCRIPT5,
))
res = c({
"a.jsm": "export const asdf = 'aaaa'; alert('1 ' + asdf);",
})
r = c.compiler.getResult()
s = list(r.transpiledFiles)[0]
print("s.getCode()", repr(str(s.getCode())))
print("res.files[None]", repr(res.files[None])) # res is my object causes
so reproducing code# https://repo.maven.apache.org/maven2/org/openjdk/jol/jol-core/0.17/jol-core-0.17.jar was added into the classpath and "org.openjdk.jol.vm.VM" was added into imported classes
from ClosureCompiler.lowLevel import *
options = createCompilerOptions(
languageOut = ji.CompileLanguageMode.ECMASCRIPT5,
)
sources = convertSourcesMapping({
"a.jsm": "export const asdf = 'aaaa'; alert('1 ' + asdf);",
})
builtinExterns = getBuiltInExterns(options.getEnvironment())
compiler = ji.Compiler()
lowLevelRes = compiler.compile(
ji.ArrayList(builtinExterns),
ji.ArrayList(sources),
options,
)
if not lowLevelRes.success:
raise Exception("Transpilation has failed, see the cli output for now")
s = list(lowLevelRes.transpiledFiles)[0]
vm = ji.VM.current()
vm.addressOf(s) == vm.addressOf(sources[0]) # True
In fact I assumed that the Closure Compiler optimizes each input taking in account the info from other inputs (kinda like externs do, but preserving only keeping the stuff that is determined to be used), but keeping the results a bit separately in different |
Beta Was this translation helpful? Give feedback.
-
Yes, that is what I was trying to convey. Odds are, you don't want this, unless you have es6 module inputs, and, without optimizing them, want to output them directly. For example, compilationLevel=BUNDLE will combine all JS files into one without any optimizations, and in order to achieve that any
I don't think you would want this. This would prevent inlining from one file to another from occurring, among other things. The compiler doesn't stop at "treeshaking", but is capable of substantially more than that, which blurs the lines between files. |
Beta Was this translation helpful? Give feedback.
-
Yeah, I know. I just assumed it having such a capability, so wanted to expose it through my bindings too. |
Beta Was this translation helpful? Give feedback.
Yeah, I did the same.
I have also poked, and found nothing useful. I mean I have tried different options set in those context, but still get an empty array.
But thanks for the info.
It feels like that prop is used only when outputting legacy versions of ECMAScript is requested. The …