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
Simplifiy tracking of valid JSX positions #13891
Changes from all commits
e1933dc
16e6677
6cab86a
560ad9f
ab1fc04
5267395
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -482,7 +482,7 @@ export default class Tokenizer extends ParserErrors { | |
} | ||
|
||
// Called at the end of every token. Sets `end`, `val`, and | ||
// maintains `context` and `exprAllowed`, and skips the space after | ||
// maintains `context` and `canStartJSXElement`, and skips the space after | ||
// the token, so that the next one's `start` will point at the | ||
// right position. | ||
|
||
|
@@ -498,6 +498,14 @@ export default class Tokenizer extends ParserErrors { | |
} | ||
} | ||
|
||
replaceToken(type: TokenType): void { | ||
this.state.type = type; | ||
// the prevType of updateContext is required | ||
// only when the new type is tt.slash/tt.jsxTagEnd | ||
// $FlowIgnore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might consider marking it as optional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am working on completely removing |
||
this.updateContext(); | ||
} | ||
|
||
// ### Token reading | ||
|
||
// This is the function that is called to fetch the next token. It | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
updateContext
needed when replacing a keyword withtt.name
? (I don't think it is).Because we could just to
this.state.type = tt.name
here (and maybethis.state.exprAllowed = false
, even if I don't see why it would be needed) and keep theprevType
handling all in the JSX plugin (to avoid needing the type error suppression comment).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, or maybe it would break this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
updateContext
is currently required by the jsx plugin, to disable JSX element forming in the following situations, where a keyword token was re-interpreted as an identifier token and thus it can not start a JSX element: