Skip to content

Commit

Permalink
Adds a check for classes which require two names to be bound in the c…
Browse files Browse the repository at this point in the history
…lass body. Ex:

var Foo = class Bar {};
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=70662888
  • Loading branch information
dimvar committed Jul 7, 2014
1 parent 7a750e8 commit f7b0664
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/com/google/javascript/jscomp/Es6ToEs3Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ private void visitClass(Node classNode, Node parent) {
+ " side of a simple assignment.");
return;
}

if (!className.isEmpty() && !className.getString().equals(fullClassName)) {
// cannot bind two class names in the case of: var Foo = class Bar {};
cannotConvertYet(classNode, "named class in an assignment");
return;
}

boolean useUnique = NodeUtil.isStatement(classNode) && !isInFunction(classNode);
String uniqueFullClassName = useUnique ? getUniqueClassName(fullClassName) : fullClassName;
String superClassString = superClassName.getQualifiedName();
Expand Down
12 changes: 7 additions & 5 deletions test/com/google/javascript/jscomp/Es6ToEs3ConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,8 @@ public void testClassExpressionInAssignment() {
test("goog.example.C = class { }",
"/** @constructor @struct */ goog.example.C = function() {}");

test("goog.example.C = class C { }",
"/** @constructor @struct */ goog.example.C = function() {}");

test("goog.example.C = class C { foo() {} }", Joiner.on('\n').join(
test("goog.example.C = class { foo() {} }", Joiner.on('\n').join(
"/** @constructor @struct */ goog.example.C = function() {}",
"",
"goog.example.C.prototype.foo = function() {};"
));
}
Expand Down Expand Up @@ -496,6 +492,12 @@ public void testSuperCall() {
));
}

public void testMultiNameClass() {
test("var F = class G {}", null, Es6ToEs3Converter.CANNOT_CONVERT_YET);

test("F = class G {}", null, Es6ToEs3Converter.CANNOT_CONVERT_YET);
}

public void testClassNested() {
test("class C { f() { class D {} } }", Joiner.on('\n').join(
"/** @constructor @struct */",
Expand Down

0 comments on commit f7b0664

Please sign in to comment.