Skip to content

Commit

Permalink
Es6ToEs3ClassSideInheritance - handle let and const
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191441255
  • Loading branch information
brad4d authored and lauraharker committed Apr 4, 2018
1 parent 5a68bc0 commit 1099cc5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Expand Up @@ -311,8 +311,10 @@ public void visit(NodeTraversal t, Node n, Node parent) {
visitDefinedPropertiesCall(t, n); visitDefinedPropertiesCall(t, n);
} }
break; break;
case CONST:
case LET:
case VAR: case VAR:
visitVar(n); visitVariableDeclaration(n);
break; break;
case ASSIGN: case ASSIGN:
visitAssign(t, n); visitAssign(t, n);
Expand Down Expand Up @@ -383,7 +385,7 @@ private void visitAssign(NodeTraversal t, Node n) {
} }
} }


private void visitVar(Node n) { private void visitVariableDeclaration(Node n) {
Node child = n.getFirstChild(); Node child = n.getFirstChild();
if (!child.hasChildren()) { if (!child.hasChildren()) {
return; return;
Expand Down
Expand Up @@ -491,6 +491,28 @@ public void testAliasing() {
"/** @suppress {visibility} */", "/** @suppress {visibility} */",
"Bar.prop = aliasFoo.prop;")); "Bar.prop = aliasFoo.prop;"));


test(
lines(
"let x = 1;",
"/** @constructor */",
"function Foo() {}",
"Foo.prop = 123;",
"const aliasFoo = Foo;", // make sure a const alias works
"/** @constructor @extends {aliasFoo} */",
"function Bar() {}",
"$jscomp.inherits(Bar, aliasFoo);"),
lines(
"let x = 1;",
"/** @constructor */",
"function Foo() {}",
"Foo.prop = 123;",
"const aliasFoo = Foo;", // make sure a const alias works
"/** @constructor @extends {aliasFoo} */",
"function Bar() {}",
"$jscomp.inherits(Bar, aliasFoo);",
"/** @suppress {visibility} */",
"Bar.prop = aliasFoo.prop;"));

test( test(
lines( lines(
"let x = 1;", "let x = 1;",
Expand Down Expand Up @@ -528,6 +550,19 @@ public void testScopeHandling() {
"function Bar() {}", "function Bar() {}",
"$jscomp.inherits(Bar, Foo);")); "$jscomp.inherits(Bar, Foo);"));


testSame(
lines(
"/** @constructor */",
"let Foo = function() {}", // make sure let works
"",
"function f() {",
" let Foo = {};",
" Foo.prop = 123;", // Not a reference to the Foo class, so no change.
"}",
"/** @constructor @extends {Foo} */",
"function Bar() {}",
"$jscomp.inherits(Bar, Foo);"));

testSame( testSame(
lines( lines(
"/** @constructor */", "/** @constructor */",
Expand Down

0 comments on commit 1099cc5

Please sign in to comment.