Skip to content

Commit

Permalink
Remove the call to $jscomp.copyProperties even if there are no proper…
Browse files Browse the repository at this point in the history
…ties to copy.

-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=90071042
  • Loading branch information
tbreisacher authored and dimvar committed Apr 2, 2015
1 parent b8239c4 commit a9df90f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Expand Up @@ -109,8 +109,8 @@ public void visit(NodeTraversal t, Node n, Node parent) {
staticMembers.put(subClassName.getQualifiedName(),
staticMember);
}
parent.detachFromParent();
}
parent.detachFromParent();
}
}

Expand Down
54 changes: 54 additions & 0 deletions test/com/google/javascript/jscomp/IntegrationTest.java
Expand Up @@ -2867,6 +2867,60 @@ public void testES5toES6() throws Exception {
compile(options, code);
}

// Tests that unused classes are removed, even if they are passed to $jscomp.inherits.
public void testES6UnusedClassesAreRemoved() {
CompilerOptions options = createCompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT6_STRICT);
options.setLanguageOut(LanguageMode.ECMASCRIPT3);
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
Compiler compiler = compile(options, Joiner.on('\n').join(
"class Base {}",
"class Sub extends Base {}",
"alert(1);"));
String result = compiler.toSource(compiler.getJsRoot());
assertThat(result).isEqualTo("alert(1)");
}

/**
* @param js A snippet of JavaScript in which alert('No one ever calls me'); is called
* in a method which is never called. Verifies that the method is stripped out by
* asserting that the result does not contain the string 'No one ever calls me'.
*/
private void testES6StaticsAreRemoved(String js) {
CompilerOptions options = createCompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT6_STRICT);
options.setLanguageOut(LanguageMode.ECMASCRIPT3);
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
Compiler compiler = compile(options, js);
String result = compiler.toSource(compiler.getJsRoot());
assertThat(result).isNotEmpty();
assertThat(result).doesNotContain("No one ever calls me");
}

public void testES6StaticsAreRemoved1() {
testES6StaticsAreRemoved(Joiner.on('\n').join(
"class Base {",
" static called() { alert('I am called'); }",
" static notCalled() { alert('No one ever calls me'); }",
"}",
"class Sub extends Base {",
" static called() { super.called(); alert('I am called too'); }",
" static notCalled() { alert('No one ever calls me'); }",
"}",
"Sub.called();"));
}

public void failing_testES6StaticsAreRemoved2() {
testES6StaticsAreRemoved(Joiner.on('\n').join(
"class Base {",
" static calledInSubclassOnly() { alert('No one ever calls me'); }",
"}",
"class Sub extends Base {",
" static calledInSubclassOnly() { alert('I am called'); }",
"}",
"Sub.calledInSubclassOnly();"));
}

public void testIssue787() {
CompilerOptions options = createCompilerOptions();
CompilationLevel level = CompilationLevel.SIMPLE_OPTIMIZATIONS;
Expand Down

0 comments on commit a9df90f

Please sign in to comment.