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, allowModifiers: ?boolean,
decorators: N.Decorator[], decorators: N.Decorator[],
): N.Pattern | N.TSParameterProperty { ): 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 accessibility: ?N.Accessibility;
let readonly = false; let readonly = false;
if (allowModifiers) { if (allowModifiers) {
@ -1375,7 +1379,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.parseAssignableListItemTypes(left); this.parseAssignableListItemTypes(left);
const elt = this.parseMaybeDefault(left.start, left.loc.start, left); const elt = this.parseMaybeDefault(left.start, left.loc.start, left);
if (accessibility || readonly) { if (accessibility || readonly) {
const pp: N.TSParameterProperty = this.startNodeAtNode(elt); const pp: N.TSParameterProperty = this.startNodeAt(startPos, startLoc);
if (decorators.length) { if (decorators.length) {
pp.decorators = decorators; pp.decorators = decorators;
} }
@ -1389,13 +1393,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
} }
pp.parameter = elt; pp.parameter = elt;
return this.finishNode(pp, "TSParameterProperty"); return this.finishNode(pp, "TSParameterProperty");
} else { }
if (decorators.length) { if (decorators.length) {
left.decorators = decorators; left.decorators = decorators;
} }
return elt; return elt;
} }
}
parseFunctionBodyAndFinish( parseFunctionBodyAndFinish(
node: N.BodilessFunctionOrMethodBase, 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": [ "params": [
{ {
"type": "TSParameterProperty", "type": "TSParameterProperty",
"start": 40, "start": 31,
"end": 49, "end": 49,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
"column": 30 "column": 21
}, },
"end": { "end": {
"line": 2, "line": 2,

View File

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