Skip to content

Commit

Permalink
Parse string literal annotations as correct type
Browse files Browse the repository at this point in the history
Summary:
Previously we were parsing these to `StringLiteral`,
when they should be `StringLiteralTypeAnnotation`, just like the other
literal annotations.

Add the node.

Reviewed By: tmikov

Differential Revision: D23088830

fbshipit-source-id: 57a1fbf845b69d228ea8d6a79dc19e1b962373c3
  • Loading branch information
avp authored and facebook-github-bot committed Oct 27, 2020
1 parent af2ac8b commit f4f93eb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/hermes/AST/ESTree.def
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ ESTREE_NODE_0_ARGS(ExistsTypeAnnotation, Base)
ESTREE_NODE_0_ARGS(EmptyTypeAnnotation, Base)
ESTREE_NODE_0_ARGS(StringTypeAnnotation, Base)
ESTREE_NODE_0_ARGS(NumberTypeAnnotation, Base)
ESTREE_NODE_1_ARGS(
StringLiteralTypeAnnotation, Base,
NodeLabel, value, false)
ESTREE_NODE_2_ARGS(
NumberLiteralTypeAnnotation, Base,
NodeNumber, value, false,
Expand Down
2 changes: 1 addition & 1 deletion lib/Parser/JSParserImpl-flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ Optional<ESTree::Node *> JSParserImpl::parsePrimaryTypeAnnotation() {
return setLocation(
start,
advance(JSLexer::GrammarContext::Flow).End,
new (context_) ESTree::StringLiteralNode(str));
new (context_) ESTree::StringLiteralTypeAnnotationNode(str));
}

case TokenKind::numeric_literal: {
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/flow/primitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ type A = 'foo';
// CHECK-NEXT: },
// CHECK-NEXT: "typeParameters": null,
// CHECK-NEXT: "right": {
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "type": "StringLiteralTypeAnnotation",
// CHECK-NEXT: "value": "foo"
// CHECK-NEXT: }
// CHECK-NEXT: }
Expand Down
1 change: 1 addition & 0 deletions utils/testsuite/esprima_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TestStatus(enum.IntEnum):
# Some literals support "raw" and others don't.
# ESPrima doesn't distinguish.
"Literal": {"raw"},
"StringLiteralTypeAnnotation": {"raw"},
}
ESPRIMA_OMITTED_KEYS = {
"Program": {"tokens", "sourceType", "comments"},
Expand Down

0 comments on commit f4f93eb

Please sign in to comment.