Skip to content

Commit

Permalink
Fix a compiler crash with ES5 inputs when the language_out is ES6.
Browse files Browse the repository at this point in the history
The ES6->ES5 passes were being enabled incorrectly based on the
assumption that was the only kind of transpilation.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=85117586
  • Loading branch information
alexeagle authored and dimvar committed Jan 30, 2015
1 parent 486345c commit 34adc40
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/com/google/javascript/jscomp/CompilerOptions.java
Expand Up @@ -1634,9 +1634,13 @@ public LanguageMode getLanguageOut() {
return languageOut; return languageOut;
} }


boolean needsConversion() { /**
* @return whether we are currently transpiling from ES6 to a lower version.
*/
boolean lowerFromEs6() {
return languageOut != LanguageMode.NO_TRANSPILE return languageOut != LanguageMode.NO_TRANSPILE
&& languageIn != languageOut; && languageIn.isEs6OrHigher()
&& !languageOut.isEs6OrHigher();
} }


@Override @Override
Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -216,11 +216,11 @@ protected List<PassFactory> getChecks() {
checks.add(closureRewriteModule); checks.add(closureRewriteModule);
} }


if (options.needsConversion() || options.aggressiveVarCheck.isOn()) { if (options.lowerFromEs6() || options.aggressiveVarCheck.isOn()) {
checks.add(checkVariableReferences); checks.add(checkVariableReferences);
} }


if (options.needsConversion()) { if (options.lowerFromEs6()) {
checks.add(es6RenameVariablesInParamLists); checks.add(es6RenameVariablesInParamLists);
checks.add(es6SplitVariableDeclarations); checks.add(es6SplitVariableDeclarations);
checks.add(es6ConvertSuper); checks.add(es6ConvertSuper);
Expand All @@ -234,7 +234,7 @@ protected List<PassFactory> getChecks() {
return checks; return checks;
} }


if (options.needsConversion()) { if (options.lowerFromEs6()) {
checks.add(es6RuntimeLibrary); checks.add(es6RuntimeLibrary);
} }


Expand Down
11 changes: 10 additions & 1 deletion test/com/google/javascript/jscomp/IntegrationTest.java
Expand Up @@ -2876,7 +2876,16 @@ public void testIssue937() {
test(options, code, result); test(options, code, result);
} }



public void testES5toES6() throws Exception {
CompilerOptions options = createCompilerOptions();
options.setAllowEs6Out(true);
options.setLanguageIn(LanguageMode.ECMASCRIPT5_STRICT);
options.setLanguageOut(LanguageMode.ECMASCRIPT6_STRICT);
CompilationLevel.SIMPLE_OPTIMIZATIONS
.setOptionsForCompilationLevel(options);
String code = "f = function(c) { for (var i = 0; i < c.length; i++) {} };";
compile(options, code);
}


public void testIssue787() { public void testIssue787() {
CompilerOptions options = createCompilerOptions(); CompilerOptions options = createCompilerOptions();
Expand Down

0 comments on commit 34adc40

Please sign in to comment.