From ecc937a4e81fd76ab6a3be9881ebaecefd89c183 Mon Sep 17 00:00:00 2001 From: dimvar Date: Tue, 31 Jan 2017 15:30:20 -0800 Subject: [PATCH] Run the extra smart name removal in advanced mode of the open-source compiler. Fixes one of the examples in issue #2249. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=146174486 --- .../javascript/jscomp/CompilationLevel.java | 1 + .../javascript/jscomp/IntegrationTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/com/google/javascript/jscomp/CompilationLevel.java b/src/com/google/javascript/jscomp/CompilationLevel.java index 0ab5f7aa232..a4392caf81a 100644 --- a/src/com/google/javascript/jscomp/CompilationLevel.java +++ b/src/com/google/javascript/jscomp/CompilationLevel.java @@ -175,6 +175,7 @@ private static void applyFullCompilationOptions(CompilerOptions options) { options.setCheckGlobalThisLevel(CheckLevel.WARNING); options.setRewriteFunctionExpressions(false); options.setSmartNameRemoval(true); + options.setExtraSmartNameRemoval(true); options.setInlineConstantVars(true); options.setInlineFunctions(Reach.ALL); options.setAssumeClosuresOnlyCaptureReferences(false); diff --git a/test/com/google/javascript/jscomp/IntegrationTest.java b/test/com/google/javascript/jscomp/IntegrationTest.java index c0550eb1551..11bf413a92a 100644 --- a/test/com/google/javascript/jscomp/IntegrationTest.java +++ b/test/com/google/javascript/jscomp/IntegrationTest.java @@ -269,6 +269,21 @@ public void testBug31301233() { test(options, source, ConstParamCheck.CONST_NOT_ASSIGNED_STRING_LITERAL_ERROR); } + public void testAdvancedModeIncludesExtraSmartNameRemoval() { + CompilerOptions options = new CompilerOptions(); + CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options); + test( + options, + LINE_JOINER.join( + "(function() {", + " /** @constructor} */", + " function Bar() {}", + " var y = Bar;", + " new y();", + "})();"), + ""); + } + public void testBug2410122() { CompilerOptions options = createCompilerOptions(); options.setGenerateExports(true); @@ -1600,6 +1615,7 @@ public void testClassWithGettersIsRemoved() { options.setLanguageIn(LanguageMode.ECMASCRIPT6); options.setLanguageOut(LanguageMode.ECMASCRIPT5); CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options); + options.setExtraSmartNameRemoval(false); test(options, code, expected); }