Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure modifiers are included in TSParameterProperty ranges #9276

Merged
merged 1 commit into from Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/babel-parser/src/plugins/typescript.js
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -1389,12 +1393,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
pp.parameter = elt;
return this.finishNode(pp, "TSParameterProperty");
} else {
if (decorators.length) {
left.decorators = decorators;
}
return elt;
}

if (decorators.length) {
left.decorators = decorators;
}

return elt;
}

parseFunctionBodyAndFinish(
Expand Down
@@ -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)"
}
Expand Up @@ -116,12 +116,12 @@
"params": [
{
"type": "TSParameterProperty",
"start": 40,
"start": 31,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 30
"column": 21
},
"end": {
"line": 2,
Expand Down
Expand Up @@ -116,12 +116,12 @@
"params": [
{
"type": "TSParameterProperty",
"start": 44,
"start": 35,
"end": 45,
"loc": {
"start": {
"line": 3,
"column": 17
"column": 8
},
"end": {
"line": 3,
Expand Down Expand Up @@ -149,12 +149,12 @@
},
{
"type": "TSParameterProperty",
"start": 62,
"start": 55,
"end": 72,
"loc": {
"start": {
"line": 4,
"column": 15
"column": 8
},
"end": {
"line": 4,
Expand Down Expand Up @@ -212,12 +212,12 @@
},
{
"type": "TSParameterProperty",
"start": 92,
"start": 82,
"end": 95,
"loc": {
"start": {
"line": 5,
"column": 18
"column": 8
},
"end": {
"line": 5,
Expand Down Expand Up @@ -246,12 +246,12 @@
},
{
"type": "TSParameterProperty",
"start": 113,
"start": 105,
"end": 124,
"loc": {
"start": {
"line": 6,
"column": 16
"column": 8
},
"end": {
"line": 6,
Expand Down Expand Up @@ -310,12 +310,12 @@
},
{
"type": "TSParameterProperty",
"start": 150,
"start": 134,
"end": 153,
"loc": {
"start": {
"line": 7,
"column": 24
"column": 8
},
"end": {
"line": 7,
Expand Down Expand Up @@ -344,12 +344,12 @@
},
{
"type": "TSParameterProperty",
"start": 215,
"start": 206,
"end": 220,
"loc": {
"start": {
"line": 9,
"column": 17
"column": 8
},
"end": {
"line": 9,
Expand Down Expand Up @@ -430,12 +430,12 @@
},
{
"type": "TSParameterProperty",
"start": 237,
"start": 230,
"end": 251,
"loc": {
"start": {
"line": 10,
"column": 15
"column": 8
},
"end": {
"line": 10,
Expand Down