Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Avoid ASI between "get"/"set" and method name (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 committed Oct 5, 2016
1 parent 680f35f commit ca66f6b
Show file tree
Hide file tree
Showing 4 changed files with 161 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
4 changes: 4 additions & 0 deletions test/fixtures/core/regression/157/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class A {
get
x(){}
}
141 changes: 141 additions & 0 deletions test/fixtures/core/regression/157/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"type": "File",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "A"
},
"name": "A"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 12,
"end": 25,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 3,
"column": 9
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 5
},
"identifierName": "x"
},
"name": "x"
},
"static": false,
"kind": "get",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 23,
"end": 25,
"loc": {
"start": {
"line": 3,
"column": 7
},
"end": {
"line": 3,
"column": 9
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

0 comments on commit ca66f6b

Please sign in to comment.