Skip to content

Commit

Permalink
Don't crash on classes with "empty" children (i.e. extraneous semicol…
Browse files Browse the repository at this point in the history
…ons in between methods in the class body)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=161271286
  • Loading branch information
tbreisacher committed Jul 11, 2017
1 parent 8db71c3 commit f230473
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/com/google/javascript/jscomp/StrictModeCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ private static void checkObjectLiteralOrClass(NodeTraversal t, Node n) {
for (Node key = n.getFirstChild();
key != null;
key = key.getNext()) {
if (key.isEmpty()) {
continue;
}
String keyName = key.getString();
if (!key.isSetterDef()) {
// normal property and getter cases
Expand Down
18 changes: 12 additions & 6 deletions test/com/google/javascript/jscomp/StrictModeCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,13 @@ public void testDuplicateObjectLiteralKey() {
StrictModeCheck.DUPLICATE_OBJECT_KEY);

testSame(
"'use strict';\n" +
"/** @constructor */ function App() {}\n" +
"App.prototype = {\n" +
" get appData() { return this.appData_; },\n" +
" set appData(data) { this.appData_ = data; }\n" +
"};");
LINE_JOINER.join(
"'use strict';",
"/** @constructor */ function App() {}",
"App.prototype = {",
" get appData() { return this.appData_; },",
" set appData(data) { this.appData_ = data; }",
"};"));

this.mode = TypeInferenceMode.NEITHER;
testError("var x = {a: 2, a(){}}", StrictModeCheck.DUPLICATE_OBJECT_KEY);
Expand Down Expand Up @@ -327,6 +328,11 @@ public void testClass() {
"}"), StrictModeCheck.ARGUMENTS_CALLER_FORBIDDEN);
}

public void testClassWithEmptyMembers() {
this.mode = TypeInferenceMode.NEITHER;
testError("class Foo { dup() {}; dup() {}; }", StrictModeCheck.DUPLICATE_CLASS_METHODS);
}

/**
* If the LanguageMode is ES2015 or higher, strict mode violations are automatically upgraded to
* errors, so set it to ES5 to get a warning.
Expand Down

0 comments on commit f230473

Please sign in to comment.