Skip to content

Commit

Permalink
fix(ts-estree): expand optional property to include question token (#138
Browse files Browse the repository at this point in the history
)
  • Loading branch information
armano2 authored and JamesHenry committed Jan 25, 2019
1 parent d8243b4 commit 9068b62
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
12 changes: 6 additions & 6 deletions packages/parser/tests/lib/__snapshots__/typescript.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -48454,7 +48454,7 @@ Object {
Object {
"loc": Object {
"end": Object {
"column": 13,
"column": 14,
"line": 12,
},
"start": Object {
Expand All @@ -48466,7 +48466,7 @@ Object {
"optional": true,
"range": Array [
253,
254,
255,
],
"type": "Identifier",
},
Expand Down Expand Up @@ -48544,7 +48544,7 @@ Object {
Object {
"loc": Object {
"end": Object {
"column": 16,
"column": 17,
"line": 13,
},
"start": Object {
Expand All @@ -48556,7 +48556,7 @@ Object {
"optional": true,
"range": Array [
281,
282,
283,
],
"type": "Identifier",
},
Expand Down Expand Up @@ -53553,7 +53553,7 @@ Object {
Object {
"loc": Object {
"end": Object {
"column": 31,
"column": 32,
"line": 4,
},
"start": Object {
Expand All @@ -53565,7 +53565,7 @@ Object {
"optional": true,
"range": Array [
73,
76,
77,
],
"type": "Identifier",
},
Expand Down
8 changes: 8 additions & 0 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,14 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
}

if (node.questionToken) {
if (node.questionToken.end > parameter.range[1]) {
parameter.range[1] = node.questionToken.end;
parameter.loc = getLocFor(
parameter.range[0],
parameter.range[1],
ast
);
}
parameter.optional = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,6 @@ tester.addFixturePatternConfig('typescript/basics', {
* TODO: Investigate in more depth, potentially split up different parts of the interface
*/
'interface-with-all-property-types', // babel parse errors
/**
* there is difference in range between babel and ts-estree
*/
'interface-with-optional-properties',
/**
* Babel parses it as TSQualifiedName
* ts parses it as MemberExpression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48344,7 +48344,7 @@ Object {
Object {
"loc": Object {
"end": Object {
"column": 13,
"column": 14,
"line": 12,
},
"start": Object {
Expand All @@ -48356,7 +48356,7 @@ Object {
"optional": true,
"range": Array [
253,
254,
255,
],
"type": "Identifier",
},
Expand Down Expand Up @@ -48434,7 +48434,7 @@ Object {
Object {
"loc": Object {
"end": Object {
"column": 16,
"column": 17,
"line": 13,
},
"start": Object {
Expand All @@ -48446,7 +48446,7 @@ Object {
"optional": true,
"range": Array [
281,
282,
283,
],
"type": "Identifier",
},
Expand Down Expand Up @@ -53414,7 +53414,7 @@ Object {
Object {
"loc": Object {
"end": Object {
"column": 31,
"column": 32,
"line": 4,
},
"start": Object {
Expand All @@ -53426,7 +53426,7 @@ Object {
"optional": true,
"range": Array [
73,
76,
77,
],
"type": "Identifier",
},
Expand Down

0 comments on commit 9068b62

Please sign in to comment.