@@ -109,32 +109,44 @@ public String applyClosureCompiler(String inputSourceCode) {
109
109
110
110
final CompilerOptions closureCompOpts = createClosureCompilerOptions ();
111
111
112
- List <SourceFile > externs = new ArrayList <>();
112
+ /*
113
+ * Collect externs we generate in separate list so that only those are dumped when
114
+ * pre-closure dumping is turned on.
115
+ */
116
+ List <SourceFile > ourExterns = new ArrayList <>();
113
117
114
118
// Add externs file that exposes the user-facing Web Image VM API.
115
- externs .add (vmApiExterns ());
119
+ ourExterns .add (vmApiExterns ());
116
120
// Add externs file for externally defined JavaScript classes.
117
- externs .add (jsExterns ());
121
+ ourExterns .add (jsExterns ());
118
122
119
123
/*
120
124
* Node.js externs are always needed due to the feature detection referencing node-specific
121
125
* variables
122
126
*/
123
- externs .add (nodejsExterns ());
127
+ ourExterns .add (nodejsExterns ());
124
128
125
129
// Dump all externs files generated by Web Image
126
- for (SourceFile f : externs ) {
130
+ for (SourceFile f : ourExterns ) {
127
131
dumpPreClosure (f .getName (), f ::getCode );
128
132
}
129
133
134
+ List <SourceFile > externs = new ArrayList <>();
135
+ /*
136
+ * Add the closure compiler externs first. Otherwise, those externs may redeclare symbols in
137
+ * our externs and fail the compilation. Our externs suppress those warnings to not fail the
138
+ * compilation.
139
+ */
130
140
try {
131
141
// TODO also add externs for stuff we use in our code (e.g process.argv for node)
132
142
// With that we could enable property renaming
133
143
externs .addAll (AbstractCommandLineRunner .getBuiltinExterns (closureCompOpts .getEnvironment ()));
134
144
} catch (IOException e ) {
135
- VMError .shouldNotReachHere (e );
145
+ throw VMError .shouldNotReachHere (e );
136
146
}
137
147
148
+ externs .addAll (ourExterns );
149
+
138
150
final Compiler closureCompiler = new Compiler ();
139
151
Result r = compile (closureCompiler , externs , sourceCode , closureCompOpts );
140
152
if (!r .warnings .isEmpty ()) {
@@ -338,14 +350,16 @@ private SourceFile jsExterns() {
338
350
for (Map .Entry <String , JSCodeGenTool .ExternClassDescriptor > entry : variables .entrySet ()) {
339
351
String var = entry .getKey ();
340
352
JSCodeGenTool .ExternClassDescriptor descriptor = entry .getValue ();
341
- sb .append ("var " ).append (var ).append (" = " + getExternClass (descriptor ) + ";\n " );
353
+ sb .append ("/** @suppress {checkVars|duplicate} */\n " );
354
+ sb .append ("var " ).append (var ).append (" = " ).append (getExternClass (descriptor )).append (";\n " );
342
355
sb .append ("\n " );
343
356
}
344
357
345
358
for (Map .Entry <String , JSCodeGenTool .ExternClassDescriptor > entry : components .entrySet ()) {
346
359
String comp = entry .getKey ();
347
360
JSCodeGenTool .ExternClassDescriptor descriptor = entry .getValue ();
348
- sb .append (comp ).append (" = " + getExternClass (descriptor ) + ";\n " );
361
+ sb .append ("/** @suppress {checkVars|duplicate} */\n " );
362
+ sb .append (comp ).append (" = " ).append (getExternClass (descriptor )).append (";\n " );
349
363
sb .append ("\n " );
350
364
}
351
365
0 commit comments