Skip to content

Commit

Permalink
Avoid ASI between "get"/"set" and method name (babel#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 committed Oct 5, 2016
1 parent 680f35f commit d90f071
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,12 @@ pp.parseClass = function (node, isStatement, optionalId) {
return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
};

pp.isClassProperty = function () {
return this.match(tt.eq) || this.isLineTerminator();
pp.isInitializedClassProperty = function () {
return this.match(tt.eq);
};

pp.isUninitializedClassProperty = function () {
return this.isLineTerminator();
};

pp.isClassMutatorStarter = function () {
Expand Down Expand Up @@ -674,7 +678,7 @@ pp.parseClassBody = function (node) {
}

if (!isGenerator) {
if (this.isClassProperty()) {
if (this.isInitializedClassProperty() || (this.isUninitializedClassProperty() && method.key.name !== "get" && method.key.name !== "set")) {
classBody.body.push(this.parseClassProperty(method));
continue;
}
Expand Down
11 changes: 9 additions & 2 deletions src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,15 @@ export default function (instance) {
};
});

// determine whether or not we're currently in the position where a class property would appear
instance.extend("isClassProperty", function (inner) {
// determine whether or not we're currently in the position where an initialized class property would appear
instance.extend("isInitializedClassProperty", function (inner) {
return function () {
return this.match(tt.colon) || inner.call(this);
};
});

// determine whether or not we're currently in the position where an uninitialized class property would appear
instance.extend("isUninitializedClassProperty", function (inner) {
return function () {
return this.match(tt.colon) || inner.call(this);
};
Expand Down

0 comments on commit d90f071

Please sign in to comment.