19
19
import static com .google .common .truth .Truth .assertThat ;
20
20
import static com .google .javascript .jscomp .base .JSCompStrings .lines ;
21
21
import static com .google .javascript .rhino .testing .NodeSubject .assertNode ;
22
+ import static org .junit .Assert .assertThrows ;
22
23
23
24
import com .google .common .collect .ImmutableList ;
24
25
import com .google .common .collect .ImmutableMap ;
28
29
import com .google .javascript .jscomp .CompilerOptions .IncrementalCheckMode ;
29
30
import com .google .javascript .jscomp .CompilerOptions .LanguageMode ;
30
31
import com .google .javascript .jscomp .CrossChunkMethodMotion ;
32
+ import com .google .javascript .jscomp .DependencyOptions ;
31
33
import com .google .javascript .jscomp .DiagnosticGroups ;
32
34
import com .google .javascript .jscomp .JSChunk ;
35
+ import com .google .javascript .jscomp .ModuleIdentifier ;
33
36
import com .google .javascript .jscomp .SourceFile ;
34
37
import com .google .javascript .jscomp .VariableRenamingPolicy ;
35
38
import com .google .javascript .jscomp .WarningLevel ;
@@ -73,6 +76,7 @@ public void simpleAlertCall() throws IOException {
73
76
74
77
CompilerOptions options = new CompilerOptions ();
75
78
CompilationLevel .ADVANCED_OPTIMIZATIONS .setOptionsForCompilationLevel (options );
79
+ options .setDependencyOptions (DependencyOptions .none ());
76
80
77
81
Compiler compiler = compileTypedAstShards (options );
78
82
@@ -93,6 +97,7 @@ public void alertCallWithCrossLibraryVarReference() throws IOException {
93
97
94
98
CompilerOptions options = new CompilerOptions ();
95
99
CompilationLevel .ADVANCED_OPTIMIZATIONS .setOptionsForCompilationLevel (options );
100
+ options .setDependencyOptions (DependencyOptions .none ());
96
101
97
102
Compiler compiler = compileTypedAstShards (options );
98
103
@@ -139,6 +144,7 @@ public void disambiguatesAndDeletesMethodsAcrossLibraries() throws IOException {
139
144
140
145
CompilerOptions options = new CompilerOptions ();
141
146
CompilationLevel .ADVANCED_OPTIMIZATIONS .setOptionsForCompilationLevel (options );
147
+ options .setDependencyOptions (DependencyOptions .none ());
142
148
options .setDisambiguateProperties (true );
143
149
144
150
Compiler compiler = compileTypedAstShards (options );
@@ -163,6 +169,7 @@ public void disambiguatesAndDeletesMethodsAcrossLibraries_withTranspilation() th
163
169
164
170
CompilerOptions options = new CompilerOptions ();
165
171
CompilationLevel .ADVANCED_OPTIMIZATIONS .setOptionsForCompilationLevel (options );
172
+ options .setDependencyOptions (DependencyOptions .none ());
166
173
options .setDisambiguateProperties (true );
167
174
options .setLanguageOut (LanguageMode .ECMASCRIPT5 );
168
175
@@ -256,6 +263,7 @@ public void externJSDocPropertiesNotRenamed() throws IOException {
256
263
257
264
CompilerOptions options = new CompilerOptions ();
258
265
CompilationLevel .ADVANCED_OPTIMIZATIONS .setOptionsForCompilationLevel (options );
266
+ options .setDependencyOptions (DependencyOptions .none ());
259
267
260
268
Compiler compiler = compileTypedAstShards (options );
261
269
@@ -281,6 +289,7 @@ public void gatherExternProperties() throws IOException {
281
289
282
290
CompilerOptions options = new CompilerOptions ();
283
291
CompilationLevel .ADVANCED_OPTIMIZATIONS .setOptionsForCompilationLevel (options );
292
+ options .setDependencyOptions (DependencyOptions .none ());
284
293
285
294
Compiler compiler = compileTypedAstShards (options );
286
295
@@ -313,6 +322,7 @@ public void protectsHiddenSideEffects() throws IOException {
313
322
314
323
CompilerOptions options = new CompilerOptions ();
315
324
CompilationLevel .ADVANCED_OPTIMIZATIONS .setOptionsForCompilationLevel (options );
325
+ options .setDependencyOptions (DependencyOptions .none ());
316
326
317
327
Compiler compiler = compileTypedAstShards (options );
318
328
@@ -329,6 +339,7 @@ public void removesRegExpCallsIfSafe() throws IOException {
329
339
330
340
CompilerOptions options = new CompilerOptions ();
331
341
CompilationLevel .ADVANCED_OPTIMIZATIONS .setOptionsForCompilationLevel (options );
342
+ options .setDependencyOptions (DependencyOptions .none ());
332
343
333
344
Compiler compiler = compileTypedAstShards (options );
334
345
@@ -348,6 +359,7 @@ public void removesRegExpCallsIfUnsafelyReferenced() throws IOException {
348
359
349
360
CompilerOptions options = new CompilerOptions ();
350
361
CompilationLevel .ADVANCED_OPTIMIZATIONS .setOptionsForCompilationLevel (options );
362
+ options .setDependencyOptions (DependencyOptions .none ());
351
363
352
364
Compiler compiler = compileTypedAstShards (options );
353
365
@@ -374,6 +386,7 @@ public void runsJ2clOptimizations() throws IOException {
374
386
375
387
CompilerOptions options = new CompilerOptions ();
376
388
CompilationLevel .ADVANCED_OPTIMIZATIONS .setOptionsForCompilationLevel (options );
389
+ options .setDependencyOptions (DependencyOptions .none ());
377
390
378
391
Compiler compiler = compileTypedAstShards (options );
379
392
@@ -460,6 +473,27 @@ public void testCrossChunkMethodMotion() throws IOException {
460
473
.isEqualTo (expectedRoot );
461
474
}
462
475
476
+ @ Test
477
+ public void dependencyModePruningForGoogModules_banned () throws IOException {
478
+ precompileLibrary (
479
+ extern (new TestExternsBuilder ().addClosureExterns ().build ()),
480
+ code ("goog.module('keepMe'); const x = 1;" ), // input_1
481
+ code ("goog.module('entryPoint'); goog.require('keepMe');" ), // input_2
482
+ code ("goog.module('dropMe'); const x = 3;" )); // input_3
483
+
484
+ CompilerOptions options = new CompilerOptions ();
485
+ options .setDependencyOptions (
486
+ DependencyOptions .pruneForEntryPoints (
487
+ ImmutableList .of (ModuleIdentifier .forClosure ("entryPoint" ))));
488
+
489
+ // TODO(b/219588952): if we decide to support this, verify that JSCompiler no longer incorrectly
490
+ // prunes the 'keepMe' module.
491
+ // This might be fixable by just removing module rewriting from the 'checks' phase.
492
+ Exception ex =
493
+ assertThrows (IllegalArgumentException .class , () -> compileTypedAstShards (options ));
494
+ assertThat (ex ).hasMessageThat ().contains ("mode=PRUNE" );
495
+ }
496
+
463
497
// use over 'compileTypedAstShards' if you want to validate reported errors or warnings in your
464
498
// @Test case.
465
499
private Compiler compileTypedAstShardsWithoutErrorChecks (CompilerOptions options )
0 commit comments