Skip to content

Commit

Permalink
fix(parser): fix loc info for JSXSpreadChild
Browse files Browse the repository at this point in the history
closes #235
  • Loading branch information
3cp committed Feb 18, 2023
1 parent e3f8b47 commit 4a99416
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9107,7 +9107,7 @@ function parseJSXExpressionContainer(
): ESTree.JSXExpressionContainer | ESTree.JSXSpreadChild {
nextToken(parser, context | Context.AllowRegExp);
const { tokenPos, linePos, colPos } = parser;
if (parser.token === Token.Ellipsis) return parseJSXSpreadChild(parser, context, tokenPos, linePos, colPos);
if (parser.token === Token.Ellipsis) return parseJSXSpreadChild(parser, context, start, line, column);

let expression: ESTree.Expression | ESTree.JSXEmptyExpression | null = null;

Expand Down
124 changes: 117 additions & 7 deletions test/parser/miscellaneous/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9225,7 +9225,7 @@ describe('Miscellaneous - JSX', () => {
],
[
'<div {...a }>{...b}</div>',
Context.OptionsJSX,
Context.OptionsJSX | Context.OptionsLoc,
{
type: 'Program',
sourceType: 'script',
Expand All @@ -9239,37 +9239,147 @@ describe('Miscellaneous - JSX', () => {
type: 'JSXSpreadChild',
expression: {
type: 'Identifier',
name: 'b'
name: 'b',
loc: {
start: {
line: 1,
column: 17
},
end: {
line: 1,
column: 18
}
}
},
loc: {
start: {
line: 1,
column: 13
},
end: {
line: 1,
column: 19
}
}
}
],
openingElement: {
type: 'JSXOpeningElement',
name: {
type: 'JSXIdentifier',
name: 'div'
name: 'div',
loc: {
start: {
line: 1,
column: 1
},
end: {
line: 1,
column: 4
}
}
},
attributes: [
{
type: 'JSXSpreadAttribute',
argument: {
type: 'Identifier',
name: 'a'
name: 'a',
loc: {
start: {
line: 1,
column: 9
},
end: {
line: 1,
column: 10
}
}
},
loc: {
start: {
line: 1,
column: 5
},
end: {
line: 1,
column: 12
}
}
}
],
selfClosing: false
selfClosing: false,
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 13
}
}
},
closingElement: {
type: 'JSXClosingElement',
name: {
type: 'JSXIdentifier',
name: 'div'
name: 'div',
loc: {
start: {
line: 1,
column: 21
},
end: {
line: 1,
column: 24
}
}
},
loc: {
start: {
line: 1,
column: 19
},
end: {
line: 1,
column: 25
}
}
},
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 25
}
}
},
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 25
}
}
}
]
],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 25
}
}
}
],
[
Expand Down

0 comments on commit 4a99416

Please sign in to comment.