Skip to content

Commit

Permalink
Move strict mode checks earlier.
Browse files Browse the repository at this point in the history
This avoids crashing on duplicate keys in the exports object of a goog module, and finds some strict-mode checks that were being missed before.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=162274729
  • Loading branch information
tbreisacher authored and blickly committed Jul 18, 2017
1 parent e14d152 commit c2b3979
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ protected List<PassFactory> getChecks() {
}

checks.add(checkVariableReferences);
checks.add(checkStrictMode);

if (options.closurePass) {
checks.add(closureCheckModule);
Expand Down Expand Up @@ -466,8 +467,6 @@ private void addNonTranspilationCheckPasses(List<PassFactory> checks) {
checks.add(checkGlobalNames);
}

checks.add(checkStrictMode);

if (!options.getConformanceConfigs().isEmpty()) {
checks.add(checkConformance);
}
Expand Down
36 changes: 36 additions & 0 deletions test/com/google/javascript/jscomp/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2873,6 +2873,21 @@ public void testCheckStrictMode() {
test(options, code, "", StrictModeCheck.ARGUMENTS_CALLEE_FORBIDDEN);
}

public void testCheckStrictModeGeneratorFunction() {
CompilerOptions options = createCompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT_2015);
options.setLanguageOut(LanguageMode.ECMASCRIPT3);
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setWarningLevel(DiagnosticGroups.ES5_STRICT, CheckLevel.WARNING);

externs = ImmutableList.of(
SourceFile.fromCode("externs", "var arguments; arguments.callee;"));

String code = "function *gen() { arguments.callee; }";

test(options, code, StrictModeCheck.ARGUMENTS_CALLEE_FORBIDDEN);
}

// http://blickly.github.io/closure-compiler-issues/#701
public void testIssue701() {
// Check ASCII art in license comments.
Expand Down Expand Up @@ -3590,6 +3605,27 @@ public void testSortingOff() {
ProcessClosurePrimitives.LATE_PROVIDE_ERROR);
}

public void testGoogModuleDuplicateExport() {
CompilerOptions options = createCompilerOptions();
options.setClosurePass(true);
options.setLanguageIn(LanguageMode.ECMASCRIPT_2015);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setStrictModeInput(true);
options.setWarningLevel(DiagnosticGroups.ES5_STRICT, CheckLevel.ERROR);

test(
options,
LINE_JOINER.join(
"goog.module('example');",
"",
"class Foo {}",
"exports = {",
" Foo,",
" Foo,",
"};"),
StrictModeCheck.DUPLICATE_OBJECT_KEY);
}

public void testGoogModuleOuterLegacyInner() {
CompilerOptions options = new CompilerOptions();
options.setClosurePass(true);
Expand Down

0 comments on commit c2b3979

Please sign in to comment.