Skip to content

Commit b18ce5e

Browse files
rishipalcopybara-github
authored andcommitted
Also add a unit test to demonstrate that we prohibit passes from adding already transpiled feature to the SCRIPT (except MODULES)
PiperOrigin-RevId: 555277972
1 parent fbc7922 commit b18ce5e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/com/google/javascript/jscomp/NodeUtilTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4404,16 +4404,22 @@ public void testIteratePreOrderWithPredicate() {
44044404
}
44054405

44064406
@Test
4407-
public void addFeatureToScriptUpdatesCompilerFeatureSet() {
4407+
public void prohibitAddingNonAllowableFeatureToScriptExceptModules() {
44084408
Node scriptNode = parse("");
44094409
Compiler compiler = new Compiler();
44104410
compiler.setAllowableFeatures(FeatureSet.BARE_MINIMUM);
44114411
NodeUtil.addFeatureToScript(scriptNode, Feature.MODULES, compiler);
44124412

4413+
// Adding MODULES to the script featureSet is okay, any other feature isn't
44134414
assertThat(NodeUtil.getFeatureSetOfScript(scriptNode))
44144415
.isEqualTo(FeatureSet.BARE_MINIMUM.with(Feature.MODULES));
44154416
assertFS(compiler.getAllowableFeatures())
44164417
.equals(FeatureSet.BARE_MINIMUM.with(Feature.MODULES));
4418+
4419+
compiler.setAllowableFeatures(FeatureSet.BARE_MINIMUM); // reset
4420+
assertThrows(
4421+
IllegalStateException.class,
4422+
() -> NodeUtil.addFeatureToScript(scriptNode, Feature.LET_DECLARATIONS, compiler));
44174423
}
44184424

44194425
@Test

0 commit comments

Comments
 (0)