Skip to content

Commit 5d45a8b

Browse files
authored
AST correction for ImportDeclarationSpecifier (Local is an Identifier instead of an Expression) (#238)
1 parent 03492d2 commit 5d45a8b

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

src/Esprima/Ast/ImportDeclarationSpecifier.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
{
33
public abstract class ImportDeclarationSpecifier : Declaration
44
{
5-
/// <summary>
6-
/// Identifier | StringLiteral
7-
/// </summary>
8-
public readonly Expression Local;
5+
public readonly Identifier Local;
96

10-
protected ImportDeclarationSpecifier(Expression local, Nodes type) : base(type)
7+
protected ImportDeclarationSpecifier(Identifier local, Nodes type) : base(type)
118
{
129
Local = local;
1310
}

src/Esprima/Ast/ImportSpecifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public sealed class ImportSpecifier : ImportDeclarationSpecifier
99
/// </summary>
1010
public readonly Expression Imported;
1111

12-
public ImportSpecifier(Expression local, Expression imported) : base(local, Nodes.ImportSpecifier)
12+
public ImportSpecifier(Identifier local, Expression imported) : base(local, Nodes.ImportSpecifier)
1313
{
1414
Imported = imported;
1515
}

src/Esprima/JavascriptParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4691,13 +4691,13 @@ private ImportSpecifier ParseImportSpecifier()
46914691
{
46924692
var node = CreateNode();
46934693

4694-
Expression local;
4694+
Identifier local;
46954695
Expression imported;
46964696

46974697
if (_lookahead.Type == TokenType.Identifier)
46984698
{
4699-
imported = ParseVariableIdentifier(allowAwaitKeyword: true);
4700-
local = imported;
4699+
imported = local = ParseVariableIdentifier(allowAwaitKeyword: true);
4700+
47014701
if (MatchContextualKeyword("as"))
47024702
{
47034703
NextToken();
@@ -4710,7 +4710,6 @@ private ImportSpecifier ParseImportSpecifier()
47104710
? ParseModuleSpecifier()
47114711
: ParseIdentifierName();
47124712

4713-
local = imported;
47144713
if (MatchContextualKeyword("as"))
47154714
{
47164715
NextToken();
@@ -4719,6 +4718,7 @@ private ImportSpecifier ParseImportSpecifier()
47194718
else
47204719
{
47214720
ThrowUnexpectedToken(NextToken());
4721+
local = default!; // never executes, just keeps the compilery happy
47224722
}
47234723
}
47244724

0 commit comments

Comments
 (0)