diff --git a/src/com/google/javascript/jscomp/Compiler.java b/src/com/google/javascript/jscomp/Compiler.java index 99fdf305944..644ff4a3457 100644 --- a/src/com/google/javascript/jscomp/Compiler.java +++ b/src/com/google/javascript/jscomp/Compiler.java @@ -735,17 +735,17 @@ private void compileInternal() { if (options.skipNonTranspilationPasses) { // i.e. whitespace-only mode, which will not work with goog.module without: whitespaceOnlyPasses(); + transpile(); + return; } - if (!options.skipNonTranspilationPasses || options.lowerFromEs6()) { - check(); - if (hasErrors()) { - return; - } + check(); + if (hasErrors()) { + return; + } - if (!options.checksOnly && !options.shouldGenerateTypedExterns()) { - optimize(); - } + if (!options.checksOnly && !options.shouldGenerateTypedExterns()) { + optimize(); } if (options.recordFunctionInformation) { @@ -818,6 +818,17 @@ public void whitespaceOnlyPasses() { } } + public void transpile() { + Tracer t = newTracer("runTranspileOnlyPasses"); + try { + for (PassFactory pf : getPassConfig().getTranspileOnlyPasses()) { + pf.create(this).process(externsRoot, jsRoot); + } + } finally { + stopTracer(t, "runTranspileOnlyPasses"); + } + } + public void check() { runCustomPasses(CustomPassExecutionTime.BEFORE_CHECKS); diff --git a/src/com/google/javascript/jscomp/DefaultPassConfig.java b/src/com/google/javascript/jscomp/DefaultPassConfig.java index 7190eb99b5e..480e5319760 100644 --- a/src/com/google/javascript/jscomp/DefaultPassConfig.java +++ b/src/com/google/javascript/jscomp/DefaultPassConfig.java @@ -185,6 +185,43 @@ void maybeInitializeModuleRewriteState() { } } + @Override + protected List getTranspileOnlyPasses() { + List passes = new ArrayList<>(); + + if (options.getLanguageIn() == LanguageMode.ECMASCRIPT6_TYPED + && options.getLanguageOut() != LanguageMode.ECMASCRIPT6_TYPED) { + passes.add(convertEs6TypedToEs6); + } + + passes.add(checkMissingSuper); + passes.add(checkVariableReferences); + + // It's important that the Dart super accessors pass run *before* es6ConvertSuper, + // which is a "late" ES6 pass. This is enforced in the assertValidOrder method. + if (options.dartPass && !options.getLanguageOut().isEs6OrHigher()) { + passes.add(dartSuperAccessorsPass); + } + + if (options.getLanguageIn().isEs6OrHigher() && !options.skipTranspilationAndCrash) { + TranspilationPasses.addEs6EarlyPasses(passes); + TranspilationPasses.addEs6LatePasses(passes); + passes.add(markTranspilationDone); + } + + if (options.raiseToEs6Typed()) { + passes.add(convertToTypedES6); + } + + if (!options.forceLibraryInjection.isEmpty()) { + passes.add(injectRuntimeLibraries); + } + + assertAllOneTimePasses(passes); + assertValidOrder(passes); + return passes; + } + @Override protected List getWhitespaceOnlyPasses() { List passes = new ArrayList<>(); @@ -226,24 +263,22 @@ protected List getChecks() { checks.add(lintChecks); } - if (!options.skipNonTranspilationPasses && options.closurePass - && options.enables(DiagnosticGroups.LINT_CHECKS)) { + if (options.closurePass && options.enables(DiagnosticGroups.LINT_CHECKS)) { checks.add(checkRequiresAndProvidesSorted); } - if (!options.skipNonTranspilationPasses - && (options.enables(DiagnosticGroups.MISSING_REQUIRE) - || options.enables(DiagnosticGroups.STRICT_MISSING_REQUIRE) - || options.enables(DiagnosticGroups.EXTRA_REQUIRE))) { + if (options.enables(DiagnosticGroups.MISSING_REQUIRE) + || options.enables(DiagnosticGroups.STRICT_MISSING_REQUIRE) + || options.enables(DiagnosticGroups.EXTRA_REQUIRE)) { checks.add(checkRequires); } - if (!options.skipNonTranspilationPasses && options.closurePass) { + if (options.closurePass) { checks.add(closureCheckModule); checks.add(closureRewriteModule); } - if (!options.skipNonTranspilationPasses && options.declaredGlobalExternsOnWindow) { + if (options.declaredGlobalExternsOnWindow) { checks.add(declaredGlobalExternsOnWindow); } @@ -255,78 +290,71 @@ protected List getChecks() { checks.add(checkMissingSuper); checks.add(checkVariableReferences); - if (!options.skipNonTranspilationPasses && options.closurePass) { + if (options.closurePass) { checks.add(closureGoogScopeAliases); checks.add(closureRewriteClass); } - if (!options.skipNonTranspilationPasses) { - checks.add(checkSideEffects); - } + checks.add(checkSideEffects); if (options.enables(DiagnosticGroups.MISSING_PROVIDE)) { checks.add(checkProvides); } - if (options.jqueryPass && !options.skipNonTranspilationPasses) { + if (options.jqueryPass) { checks.add(jqueryAliases); } - if (options.angularPass && !options.skipNonTranspilationPasses) { + if (options.angularPass) { checks.add(angularPass); } - if (!options.generateExportsAfterTypeChecking - && options.generateExports && !options.skipNonTranspilationPasses) { + if (!options.generateExportsAfterTypeChecking && options.generateExports) { checks.add(generateExports); } - if (options.exportTestFunctions && !options.skipNonTranspilationPasses) { + if (options.exportTestFunctions) { checks.add(exportTestFunctions); } - if (options.closurePass && !options.skipNonTranspilationPasses) { + if (options.closurePass) { checks.add(closurePrimitives); } // It's important that the PolymerPass run *after* the ClosurePrimitives // rewrite and *before* the suspicious code checks. // This is enforced in the assertValidOrder method. - if (options.polymerPass && !options.skipNonTranspilationPasses) { + if (options.polymerPass) { checks.add(polymerPass); } - if ((options.checkSuspiciousCode - || options.enables(DiagnosticGroups.GLOBAL_THIS) - || options.enables(DiagnosticGroups.DEBUGGER_STATEMENT_PRESENT)) - && !options.skipNonTranspilationPasses) { + if (options.checkSuspiciousCode + || options.enables(DiagnosticGroups.GLOBAL_THIS) + || options.enables(DiagnosticGroups.DEBUGGER_STATEMENT_PRESENT)) { checks.add(suspiciousCode); } - if (options.closurePass && options.checkMissingGetCssNameLevel.isOn() - && !options.skipNonTranspilationPasses) { + if (options.closurePass && options.checkMissingGetCssNameLevel.isOn()) { checks.add(closureCheckGetCssName); } - if (options.syntheticBlockStartMarker != null && !options.skipNonTranspilationPasses) { + if (options.syntheticBlockStartMarker != null) { // This pass must run before the first fold constants pass. checks.add(createSyntheticBlocks); } - if (!options.skipNonTranspilationPasses) { - checks.add(checkVars); - } + checks.add(checkVars); - if (options.inferConsts && !options.skipNonTranspilationPasses) { + if (options.inferConsts) { checks.add(inferConsts); } - if (options.computeFunctionSideEffects && !options.skipNonTranspilationPasses) { + if (options.computeFunctionSideEffects) { checks.add(checkRegExp); } // This pass should run before types are assigned. - if (options.processObjectPropertyString && !options.skipNonTranspilationPasses) { + if (options.processObjectPropertyString) { checks.add(objectPropertyStringPreprocess); } @@ -337,10 +365,7 @@ protected List getChecks() { } if (options.getLanguageIn().isEs6OrHigher() && !options.skipTranspilationAndCrash) { - if (!options.skipNonTranspilationPasses) { - checks.add(es6ExternsCheck); - } - checks.add(es6SuperCheck); + checks.add(es6ExternsCheck); TranspilationPasses.addEs6EarlyPasses(checks); } @@ -1293,14 +1318,6 @@ protected CompilerPass create(final AbstractCompiler compiler) { } }; - private final PassFactory es6SuperCheck = - new PassFactory("es6SuperCheck", true) { - @Override - protected CompilerPass create(final AbstractCompiler compiler) { - return new Es6SuperCheck(compiler); - } - }; - /** * Desugars ES6_TYPED features into ES6 code. */ diff --git a/src/com/google/javascript/jscomp/PassConfig.java b/src/com/google/javascript/jscomp/PassConfig.java index e732a7133f6..4462979de89 100644 --- a/src/com/google/javascript/jscomp/PassConfig.java +++ b/src/com/google/javascript/jscomp/PassConfig.java @@ -109,6 +109,11 @@ protected List getWhitespaceOnlyPasses() { return Collections.emptyList(); } + /** Gets the transpilation passes */ + protected List getTranspileOnlyPasses() { + return Collections.emptyList(); + } + /** * Gets the checking passes to run. * diff --git a/src/com/google/javascript/jscomp/TranspilationPasses.java b/src/com/google/javascript/jscomp/TranspilationPasses.java index f6294e6bfd8..edde6d3b85e 100644 --- a/src/com/google/javascript/jscomp/TranspilationPasses.java +++ b/src/com/google/javascript/jscomp/TranspilationPasses.java @@ -34,6 +34,7 @@ private TranspilationPasses() {} * transpile them, even if the output language is also ES6. */ public static void addEs6EarlyPasses(List passes) { + passes.add(es6SuperCheck); passes.add(es6ConvertSuper); passes.add(es6RewriteArrowFunction); passes.add(es6RenameVariablesInParamLists); @@ -57,6 +58,13 @@ public static void addEs6LatePasses(List passes) { passes.add(rewritePolyfills); } + private static final PassFactory es6SuperCheck = + new PassFactory("es6SuperCheck", true) { + @Override + protected CompilerPass create(final AbstractCompiler compiler) { + return new Es6SuperCheck(compiler); + } + }; static final HotSwapPassFactory es6ExtractClasses = new HotSwapPassFactory("Es6ExtractClasses", true) {