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

Wrong location of JSXEmptyExpression #125

Closed
fisker opened this issue Oct 27, 2020 · 4 comments
Closed

Wrong location of JSXEmptyExpression #125

fisker opened this issue Oct 27, 2020 · 4 comments

Comments

@fisker
Copy link
Collaborator

fisker commented Oct 27, 2020

require("meriyah").parse('<div>{ }</div>', {loc: true, module: true, jsx: true}).body[0].expression.children[0].expression
{
  type: 'JSXEmptyExpression',
  loc: { start: { line: 1, column: 7 }, end: { line: 1, column: 6 } }
}

Should swap start and end

@3cp
Copy link
Member

3cp commented Oct 27, 2020

We tokenised { } as { and [space]}, the space is not a separate token. So when parseJSXEmptyExpression() runs, it didn't move to next token, but tries to finishNode from current position.

@KFlash we probably need to tokenise it as {, [space] and }, otherwise finishNode without nextToken/consume would not work. If don't change tokenisation, I guess we would need some ugly patch.

@fisker
Copy link
Collaborator Author

fisker commented Oct 27, 2020

FYI: '<div>{/* comment*/}</div>' have same problem

@3cp
Copy link
Member

3cp commented Oct 27, 2020

Same cause, comment is not counted as a token in meriyah, but empty space attached to next real token.

@3cp
Copy link
Member

3cp commented Oct 27, 2020

Without changing tokenisation, the patch look not too bad.

@3cp 3cp closed this as completed in 11765ce Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants