Merge pull request #3332 from loganfsmyth/revert-prop-semi
Revert to standard ASI behavior for class properties
This commit is contained in:
commit
88a67773e6
@ -595,7 +595,7 @@ pp.parseClass = function (node, isStatement, optionalId) {
|
||||
};
|
||||
|
||||
pp.isClassProperty = function () {
|
||||
return this.match(tt.eq) || this.match(tt.semi) || this.canInsertSemicolon();
|
||||
return this.match(tt.eq) || this.isLineTerminator();
|
||||
};
|
||||
|
||||
pp.parseClassBody = function (node) {
|
||||
@ -747,9 +747,7 @@ pp.parseClassProperty = function (node) {
|
||||
} else {
|
||||
node.value = null;
|
||||
}
|
||||
if (!this.eat(tt.semi)) {
|
||||
this.raise(node.value && node.value.end || node.key.end, "A semicolon is required after a class property");
|
||||
}
|
||||
this.semicolon();
|
||||
return this.finishNode(node, "ClassProperty");
|
||||
};
|
||||
|
||||
|
||||
4
test/fixtures/experimental/class-properties/asi-failure/actual.js
vendored
Normal file
4
test/fixtures/experimental/class-properties/asi-failure/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
p = x
|
||||
[m] () {}
|
||||
}
|
||||
4
test/fixtures/experimental/class-properties/asi-failure/options.json
vendored
Normal file
4
test/fixtures/experimental/class-properties/asi-failure/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"throws": "Unexpected token (3:9)",
|
||||
"plugins": ["classProperties"]
|
||||
}
|
||||
9
test/fixtures/experimental/class-properties/asi-success/actual.js
vendored
Normal file
9
test/fixtures/experimental/class-properties/asi-success/actual.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
x
|
||||
y
|
||||
}
|
||||
|
||||
class Foo {
|
||||
p
|
||||
[m] () {}
|
||||
}
|
||||
289
test/fixtures/experimental/class-properties/asi-success/expected.json
vendored
Normal file
289
test/fixtures/experimental/class-properties/asi-success/expected.json
vendored
Normal file
@ -0,0 +1,289 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 52,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 52,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start": 0,
|
||||
"end": 21,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 6,
|
||||
"end": 9,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"name": "Foo"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 10,
|
||||
"end": 21,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassProperty",
|
||||
"start": 14,
|
||||
"end": 15,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 14,
|
||||
"end": 15,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"name": "x"
|
||||
},
|
||||
"static": false,
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"type": "ClassProperty",
|
||||
"start": 18,
|
||||
"end": 19,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 18,
|
||||
"end": 19,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"name": "y"
|
||||
},
|
||||
"static": false,
|
||||
"value": null
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start": 23,
|
||||
"end": 52,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 29,
|
||||
"end": 32,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"name": "Foo"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 33,
|
||||
"end": 52,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassProperty",
|
||||
"start": 37,
|
||||
"end": 38,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 37,
|
||||
"end": 38,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"name": "p"
|
||||
},
|
||||
"static": false,
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start": 41,
|
||||
"end": 50,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"computed": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 42,
|
||||
"end": 43,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"column": 3
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"column": 4
|
||||
}
|
||||
},
|
||||
"name": "m"
|
||||
},
|
||||
"static": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"expression": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 48,
|
||||
"end": 50,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
3
test/fixtures/experimental/class-properties/asi-success/options.json
vendored
Normal file
3
test/fixtures/experimental/class-properties/asi-success/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["classProperties"]
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
class A {
|
||||
asdf = 1
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"throws": "A semicolon is required after a class property (2:10)",
|
||||
"plugins": ["classProperties"]
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
class A {
|
||||
asdf
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"throws": "A semicolon is required after a class property (2:6)",
|
||||
"plugins": ["classProperties"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user