Ensure modifiers are included in TSParameterProperty ranges (#9276)

This commit is contained in:
Brian Ng 2019-01-04 10:02:09 -06:00 committed by GitHub
parent 865eb93c2d
commit a58893d1e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 23 deletions

View File

@ -1364,6 +1364,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
allowModifiers: ?boolean,
decorators: N.Decorator[],
): N.Pattern | N.TSParameterProperty {
// Store original location/position to include modifiers in range
const startPos = this.state.start;
const startLoc = this.state.startLoc;
let accessibility: ?N.Accessibility;
let readonly = false;
if (allowModifiers) {
@ -1375,7 +1379,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.parseAssignableListItemTypes(left);
const elt = this.parseMaybeDefault(left.start, left.loc.start, left);
if (accessibility || readonly) {
const pp: N.TSParameterProperty = this.startNodeAtNode(elt);
const pp: N.TSParameterProperty = this.startNodeAt(startPos, startLoc);
if (decorators.length) {
pp.decorators = decorators;
}
@ -1389,13 +1393,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
pp.parameter = elt;
return this.finishNode(pp, "TSParameterProperty");
} else {
}
if (decorators.length) {
left.decorators = decorators;
}
return elt;
}
}
parseFunctionBodyAndFinish(
node: N.BodilessFunctionOrMethodBase,

View File

@ -1,3 +1,3 @@
{
"throws": "A parameter property may not be declared using a binding pattern. (2:23)"
"throws": "A parameter property may not be declared using a binding pattern. (2:16)"
}

View File

@ -116,12 +116,12 @@
"params": [
{
"type": "TSParameterProperty",
"start": 40,
"start": 31,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 30
"column": 21
},
"end": {
"line": 2,

View File

@ -116,12 +116,12 @@
"params": [
{
"type": "TSParameterProperty",
"start": 44,
"start": 35,
"end": 45,
"loc": {
"start": {
"line": 3,
"column": 17
"column": 8
},
"end": {
"line": 3,
@ -149,12 +149,12 @@
},
{
"type": "TSParameterProperty",
"start": 62,
"start": 55,
"end": 72,
"loc": {
"start": {
"line": 4,
"column": 15
"column": 8
},
"end": {
"line": 4,
@ -212,12 +212,12 @@
},
{
"type": "TSParameterProperty",
"start": 92,
"start": 82,
"end": 95,
"loc": {
"start": {
"line": 5,
"column": 18
"column": 8
},
"end": {
"line": 5,
@ -246,12 +246,12 @@
},
{
"type": "TSParameterProperty",
"start": 113,
"start": 105,
"end": 124,
"loc": {
"start": {
"line": 6,
"column": 16
"column": 8
},
"end": {
"line": 6,
@ -310,12 +310,12 @@
},
{
"type": "TSParameterProperty",
"start": 150,
"start": 134,
"end": 153,
"loc": {
"start": {
"line": 7,
"column": 24
"column": 8
},
"end": {
"line": 7,
@ -344,12 +344,12 @@
},
{
"type": "TSParameterProperty",
"start": 215,
"start": 206,
"end": 220,
"loc": {
"start": {
"line": 9,
"column": 17
"column": 8
},
"end": {
"line": 9,
@ -430,12 +430,12 @@
},
{
"type": "TSParameterProperty",
"start": 237,
"start": 230,
"end": 251,
"loc": {
"start": {
"line": 10,
"column": 15
"column": 8
},
"end": {
"line": 10,