Skip to content

Commit

Permalink
Allowing comma separated fields
Browse files Browse the repository at this point in the history
- Fixes babel#540
- Fixes location for publicFields (should not contain semi-colon)
- Added tests
  • Loading branch information
Diego committed Jul 1, 2017
1 parent 5e1e949 commit c51f834
Show file tree
Hide file tree
Showing 33 changed files with 1,527 additions and 135 deletions.
19 changes: 16 additions & 3 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,9 @@ export default class StatementParser extends ExpressionParser {

while (!this.eat(tt.braceR)) {
if (this.eat(tt.semi)) {
if (this.state.inCommaSeparatedFields) {
this.unexpected();
}
if (decorators.length > 0) {
this.raise(
this.state.lastTokEnd,
Expand All @@ -885,6 +888,16 @@ export default class StatementParser extends ExpressionParser {
}

this.parseClassMember(classBody, member, state);
const isClassField = member.kind == null;

if (isClassField) {
if (this.eat(tt.comma)) {
this.state.inCommaSeparatedFields = true;
} else {
this.state.inCommaSeparatedFields = false;
this.semicolon();
}
}

if (
this.hasPlugin("decorators2") &&
Expand Down Expand Up @@ -1071,7 +1084,7 @@ export default class StatementParser extends ExpressionParser {
/* isConstructor */ false,
);
this.checkGetterSetterParamCount(method);
} else if (this.isLineTerminator()) {
} else if (this.isLineTerminator() || this.match(tt.comma)) {
// an uninitialized class property (due to ASI, since we don't otherwise recognize the next token)
if (this.isNonstaticConstructor(prop)) {
this.raise(
Expand Down Expand Up @@ -1135,7 +1148,7 @@ export default class StatementParser extends ExpressionParser {
} else {
node.value = null;
}
this.semicolon();

this.state.inClassProperty = false;
return this.finishNode(node, "ClassPrivateProperty");
}
Expand All @@ -1158,7 +1171,7 @@ export default class StatementParser extends ExpressionParser {
} else {
node.value = null;
}
this.semicolon();

this.state.inClassProperty = false;
return this.finishNode(node, "ClassProperty");
}
Expand Down
1 change: 1 addition & 0 deletions src/tokenizer/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default class State {

// Check whether we are in a (nested) class or not.
classLevel: number;
inCommaSeparatedFields: boolean;

// Labels in scope.
labels: Array<{ kind: ?("loop" | "switch"), statementStart?: number }>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C {
#p1,#p2;
#p3 = 1, #p4 = 1;
#p5 = 1, #p6, #p7;
}
Loading

0 comments on commit c51f834

Please sign in to comment.