Skip to content
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

Fix import.meta support #245

Merged
merged 1 commit into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Esprima/JavascriptParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ private Expression ParsePrimaryExpression()
{
return ParseJsxRoot();
}

var node = CreateNode();

Expression expr;
Expand Down Expand Up @@ -1466,9 +1466,9 @@ private Expression ParseNewExpression()
return ThrowUnexpectedToken<Expression>(_lookahead);
}
}
else if (MatchKeyword("import"))
else if (MatchImportCall())
{
return ThrowUnexpectedToken<Expression>(_lookahead);
return ThrowUnexpectedToken<Expression>(_lookahead, Messages.CannotUseImportWithNew);
}
else
{
Expand Down Expand Up @@ -1543,7 +1543,7 @@ private Import ParseImportCall()
_context.IsAssignmentTarget = true;
var source = this.parseAssignmentExpression();
_context.IsAssignmentTarget = previousIsAssignmentTarget;

if (!this.Match(")") && this._config.Tolerant)
{
this.TolerateUnexpectedToken(this.NextToken());
Expand Down Expand Up @@ -4145,12 +4145,12 @@ private ArrayList<Statement> ParseDirectivePrologues()
while (true)
{
var token = _lookahead;

if (firstRestricted == null && token.Octal)
{
firstRestricted = token;
}

if (token.Type != TokenType.StringLiteral)
{
break;
Expand All @@ -4175,7 +4175,7 @@ private ArrayList<Statement> ParseDirectivePrologues()
}
}
}

if (_context.Strict && firstRestricted != null)
{
TolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);
Expand Down Expand Up @@ -4296,7 +4296,7 @@ private bool IsStartOfExpression()
{
return true;
}

var start = true;

if (!(_lookahead.Value is string value))
Expand Down Expand Up @@ -4658,7 +4658,7 @@ private ClassExpression ParseClassExpression()
var previousAllowSuper = _context.AllowSuper;
_context.Strict = true;
_context.AllowSuper = true;

ExpectKeyword("class");
var id = _lookahead.Type == TokenType.Identifier
? ParseVariableIdentifier()
Expand Down
1 change: 1 addition & 0 deletions src/Esprima/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class Messages
public const string BadSetterArity = "Setter must have exactly one formal parameter";
public const string BadSetterRestParameter = "Setter function argument must not be a rest parameter";
public const string CannotUseImportMetaOutsideAModule = "Cannot use 'import.meta' outside a module";
public const string CannotUseImportWithNew = "Cannot use new with import";
public const string ConstructorIsAsync = "Class constructor may not be an async method";
public const string ConstructorSpecialMethod = "Class constructor may not be an accessor";
public const string DeclarationMissingInitializer = "Missing initializer in {0} declaration";
Expand Down
7 changes: 4 additions & 3 deletions test/Esprima.Tests.Test262/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -17,7 +18,7 @@ public static async Task<int> Main(string[] args)
var projectRoot = Path.Combine(rootDirectory, "../../..");

var allowListFile = Path.Combine(projectRoot, "allow-list.txt");
var lines = await File.ReadAllLinesAsync(allowListFile);
var lines = File.Exists(allowListFile) ? await File.ReadAllLinesAsync(allowListFile) : Array.Empty<string>();
var knownFailing = new HashSet<string>(lines
.Where(x => !string.IsNullOrWhiteSpace(x) && !x.StartsWith("#"))
);
Expand All @@ -28,7 +29,7 @@ public static async Task<int> Main(string[] args)

// we materialize to give better feedback on progress
var test262Files = new ConcurrentBag<Test262File>();

TestExecutionSummary? summary = null;

AnsiConsole.Progress()
Expand Down
1 change: 0 additions & 1 deletion test/Esprima.Tests.Test262/allow-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,6 @@ test/language/expressions/function/early-errors/invalid-names-member-expression-
test/language/expressions/function/early-errors/invalid-names-member-expression-this.js(default)
test/language/expressions/function/early-errors/invalid-names-member-expression-this.js(strict mode)
test/language/expressions/generators/param-dflt-yield.js(default)
test/language/expressions/import.meta/import-meta-is-an-ordinary-object.js(strict mode)
test/language/expressions/in/private-field-in-nested.js(default)
test/language/expressions/in/private-field-in-nested.js(strict mode)
test/language/expressions/in/private-field-invalid-assignment-reference.js(default)
Expand Down
2 changes: 1 addition & 1 deletion test/Esprima.Tests/LocationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void InvalidStartAndEnd(int startLine, int startColumn, int endLine, int
{
var start = new Position(startLine, startColumn);
var end = new Position(endLine, endColumn);
var e = Assert.Throws<ArgumentOutOfRangeException>(() =>
var e = Assert.Throws<System.ArgumentOutOfRangeException>(() =>
new Location(start, end));
Assert.Equal("end", e.ParamName);
Assert.Equal(end, e.ActualValue);
Expand Down