diff --git a/src/Esprima/JavascriptParser.cs b/src/Esprima/JavascriptParser.cs index 3a880843..5aaddcf1 100644 --- a/src/Esprima/JavascriptParser.cs +++ b/src/Esprima/JavascriptParser.cs @@ -558,7 +558,7 @@ private Expression ParsePrimaryExpression() { return ParseJsxRoot(); } - + var node = CreateNode(); Expression expr; @@ -1466,9 +1466,9 @@ private Expression ParseNewExpression() return ThrowUnexpectedToken(_lookahead); } } - else if (MatchKeyword("import")) + else if (MatchImportCall()) { - return ThrowUnexpectedToken(_lookahead); + return ThrowUnexpectedToken(_lookahead, Messages.CannotUseImportWithNew); } else { @@ -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()); @@ -4145,12 +4145,12 @@ private ArrayList ParseDirectivePrologues() while (true) { var token = _lookahead; - + if (firstRestricted == null && token.Octal) { firstRestricted = token; } - + if (token.Type != TokenType.StringLiteral) { break; @@ -4175,7 +4175,7 @@ private ArrayList ParseDirectivePrologues() } } } - + if (_context.Strict && firstRestricted != null) { TolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral); @@ -4296,7 +4296,7 @@ private bool IsStartOfExpression() { return true; } - + var start = true; if (!(_lookahead.Value is string value)) @@ -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() diff --git a/src/Esprima/Messages.cs b/src/Esprima/Messages.cs index b7fcb911..a2e0fe4f 100644 --- a/src/Esprima/Messages.cs +++ b/src/Esprima/Messages.cs @@ -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"; diff --git a/test/Esprima.Tests.Test262/Program.cs b/test/Esprima.Tests.Test262/Program.cs index 4fa3f4d2..b9a136e4 100644 --- a/test/Esprima.Tests.Test262/Program.cs +++ b/test/Esprima.Tests.Test262/Program.cs @@ -1,4 +1,5 @@ -using System.Collections.Concurrent; +using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; @@ -17,7 +18,7 @@ public static async Task 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(); var knownFailing = new HashSet(lines .Where(x => !string.IsNullOrWhiteSpace(x) && !x.StartsWith("#")) ); @@ -28,7 +29,7 @@ public static async Task Main(string[] args) // we materialize to give better feedback on progress var test262Files = new ConcurrentBag(); - + TestExecutionSummary? summary = null; AnsiConsole.Progress() diff --git a/test/Esprima.Tests.Test262/allow-list.txt b/test/Esprima.Tests.Test262/allow-list.txt index 859dbad8..c8c88a48 100644 --- a/test/Esprima.Tests.Test262/allow-list.txt +++ b/test/Esprima.Tests.Test262/allow-list.txt @@ -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) diff --git a/test/Esprima.Tests/LocationTests.cs b/test/Esprima.Tests/LocationTests.cs index 21ff9505..046ef3cb 100644 --- a/test/Esprima.Tests/LocationTests.cs +++ b/test/Esprima.Tests/LocationTests.cs @@ -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(() => + var e = Assert.Throws(() => new Location(start, end)); Assert.Equal("end", e.ParamName); Assert.Equal(end, e.ActualValue);