Skip to content

Commit

Permalink
refactor(fe): remove special handling for keywords in JSX
Browse files Browse the repository at this point in the history
As of the previous commit, we now always use skip_in_jsx() instead of
skip(), therefore we never see kw_as, etc. when parsing a JSX
attribute name.
  • Loading branch information
strager committed Jan 1, 2024
1 parent f3e639a commit b80b256
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/quick-lint-js/fe/parse-expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3818,13 +3818,13 @@ Expression* Parser::parse_jsx_element_or_fragment(Parse_Visitor_Base& v,

next_attribute:
switch (this->peek().type) {
// NOTE[JSX-keyword-after-TypeScript-generic]: Normally, JS/TS keywords would
// appear as Token_Type::identifier here. However, when parsing
// '<C<T> class="" />' in TypeScript, the 'class' following '>' is parsed as a
// keyword. This is because parse_and_visit_typescript_generic_arguments calls
// this->skip() rather than this->skip_in_jsx(). That's why we need to check
// for keywords here.
QLJS_CASE_KEYWORD:
// JS/TS keywords should not happen here because skip_in_jsx() should have
// been called.
QLJS_ASSERT(false);
goto identifier_attribute_name;

identifier_attribute_name:
case Token_Type::identifier: {
Identifier attribute = this->peek().identifier_name();
bool has_namespace = false;
Expand Down
1 change: 0 additions & 1 deletion test/test-parse-typescript-generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,6 @@ TEST_F(Test_Parse_TypeScript_Generic, jsx_element) {

{
// 'as' should be treated as an attribute name, not a keyword.
// See NOTE[JSX-keyword-after-TypeScript-generic].
Test_Parser p(u8"<C<T> as={value} />"_sv, typescript_jsx_options);
Expression* ast = p.parse_expression();
EXPECT_EQ(summarize(ast), "jsxelement(C, var value)");
Expand Down

0 comments on commit b80b256

Please sign in to comment.