Skip to content

Commit

Permalink
Add error check for invalid JSX attr initializer
Browse files Browse the repository at this point in the history
Summary:
There was an invalid assert as a result of using `else if` instead of
`else`. Fix the case and ensure that one of the two branches execute.

Reviewed By: tmikov

Differential Revision: D30710922

fbshipit-source-id: de48ece5a6d87deb3df72ba01e1a71d38076c607
  • Loading branch information
avp authored and facebook-github-bot committed Sep 2, 2021
1 parent d8d2f36 commit 24f8451
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Parser/JSParserImpl-jsx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,16 @@ Optional<ESTree::Node *> JSParserImpl::parseJSXAttribute() {
tok_,
new (context_) ESTree::StringLiteralNode(tok_->getStringLiteral()));
advance(JSLexer::GrammarContext::AllowJSXIdentifier);
} else if (check(TokenKind::l_brace)) {
} else {
// { AssignmentExpression }
// ^
if (!need(
TokenKind::l_brace,
"in JSX attribute",
"location of attribute",
start))
return None;

SMLoc valueStart = advance().Start;

auto optAssign = parseAssignmentExpression();
Expand Down
13 changes: 13 additions & 0 deletions test/Parser/jsx-error-attr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// RUN: (! %hermes -parse-jsx -dump-ast -pretty-json %s 2>&1 ) | %FileCheck %s --match-full-lines

<foo x=y></foo>
// CHECK: {{.*}}:10:8: error: '{' expected in JSX attribute
// CHECK-NEXT: <foo x=y></foo>
// CHECK-NEXT: ~~^

0 comments on commit 24f8451

Please sign in to comment.