Skip to content

Commit

Permalink
Disable InlineVariables when language_out is ES6+, for now.
Browse files Browse the repository at this point in the history
Add test case showing that InlineVariables sometimes produces incorrect code when operating on ES6 features.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=169600823
  • Loading branch information
tbreisacher authored and blickly committed Sep 22, 2017
1 parent 36f8393 commit a5b81ba
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -1704,7 +1704,7 @@ protected CompilerPass create(AbstractCompiler compiler) {


@Override @Override
protected FeatureSet featureSet() { protected FeatureSet featureSet() {
return ES8; return ES5;
} }
}; };


Expand Down Expand Up @@ -2523,7 +2523,7 @@ protected CompilerPass create(AbstractCompiler compiler) {


@Override @Override
protected FeatureSet featureSet() { protected FeatureSet featureSet() {
return ES8_MODULES; return ES5;
} }
}; };


Expand All @@ -2537,7 +2537,7 @@ protected CompilerPass create(AbstractCompiler compiler) {


@Override @Override
protected FeatureSet featureSet() { protected FeatureSet featureSet() {
return ES8_MODULES; return ES5;
} }
}; };


Expand Down
24 changes: 24 additions & 0 deletions test/com/google/javascript/jscomp/InlineVariablesTest.java
Expand Up @@ -54,6 +54,30 @@ public void tearDown() {
inlineLocalsOnly = false; inlineLocalsOnly = false;
} }


// TODO(tbreisacher): Fix this and re-enable InlineVariables in ES6-out mode.
public void testPassProducesInvalidCode() {
test(
LINE_JOINER.join(
"function f(x = void 0) {",
" var z;",
" {",
" const y = {};",
" x && (y['x'] = x);",
" z = y;",
" }",
" return z;",
"}"),
LINE_JOINER.join(
"function f(x = void 0) {",
" {",
" const y = {};",
" x && (y['x'] = x);",
" }",
" // NOTE! Invalid code: y is no longer in scope here.",
" return y;",
"}"));
}

// Test respect for scopes and blocks // Test respect for scopes and blocks


public void testInlineGlobal() { public void testInlineGlobal() {
Expand Down
6 changes: 4 additions & 2 deletions test/com/google/javascript/jscomp/IntegrationTest.java
Expand Up @@ -4569,7 +4569,8 @@ public void testDefaultParameters() {
"var a={a:9}; a=void 0===a?{a:5}:a;alert(3+a.a)"); "var a={a:9}; a=void 0===a?{a:5}:a;alert(3+a.a)");
} }


public void testDefaultParametersNonTranspiling() { // TODO(tbreisacher): Enable this test when InlineVariables is re-enabled in non-transpile mode.
public void disabled_testDefaultParametersNonTranspiling() {
CompilerOptions options = createCompilerOptions(); CompilerOptions options = createCompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options); CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setLanguageIn(LanguageMode.ECMASCRIPT_2017); options.setLanguageIn(LanguageMode.ECMASCRIPT_2017);
Expand Down Expand Up @@ -4606,7 +4607,8 @@ public void testRestObjectPatternParameters() {
"}(1,1,1,1,1))")); "}(1,1,1,1,1))"));
} }


public void testRestObjectPatternParametersNonTranspiling() { // TODO(tbreisacher): Enable this test when InlineVariables is re-enabled in non-transpile mode.
public void disabled_testRestObjectPatternParametersNonTranspiling() {
CompilerOptions options = createCompilerOptions(); CompilerOptions options = createCompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options); CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setLanguageIn(LanguageMode.ECMASCRIPT_2017); options.setLanguageIn(LanguageMode.ECMASCRIPT_2017);
Expand Down

0 comments on commit a5b81ba

Please sign in to comment.