Skip to content

Commit

Permalink
Fix handling of trailing comma in import arguments (#430)
Browse files Browse the repository at this point in the history
* update test suite
  • Loading branch information
lahma authored Dec 31, 2023
1 parent d2771db commit f61074b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
12 changes: 7 additions & 5 deletions src/Esprima/JavaScriptParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,16 +1739,18 @@ private ImportExpression ParseImportCall()

_context.IsAssignmentTarget = previousIsAssignmentTarget;

if (!this.Match(")") && _tolerant)
{
this.TolerateUnexpectedToken(this.NextToken());
}
else
if (!this.Match(")"))
{
if (Match(","))
{
NextToken();
}
this.Expect(")");
}
else
{
NextToken();
}

return Finalize(node, new ImportExpression(source, attributes));
}
Expand Down
13 changes: 12 additions & 1 deletion test/Esprima.Tests.Test262/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,18 @@ public static async Task<int> Main(string[] args)
},
IsIgnored = file => file.Features.IndexOfAny(excludedFeatures.AsSpan()) != -1 || knownFailing.Contains(file.ToString()),
IsParseError = exception => exception is ParserException,
ShouldThrow = file => file.NegativeTestCase?.Type == ExpectedErrorType.SyntaxError || file.NegativeTestCase?.Phase == TestingPhase.Parse,
ShouldThrow = file =>
{
var negativeTestCase = file.NegativeTestCase;
if (negativeTestCase is null)
{
return false;
}
return negativeTestCase.Type == ExpectedErrorType.SyntaxError
&& negativeTestCase.Phase != TestingPhase.Resolution
&& negativeTestCase.Phase != TestingPhase.Runtime;
},
OnTestExecuted = _ => testTask.Increment(1)
};
Expand Down
2 changes: 1 addition & 1 deletion test/Esprima.Tests.Test262/Test262Harness.settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"SuiteGitSha": "83a46bfe0e79aed8274a1b9f4beb0a2efa0b3533",
"SuiteGitSha": "2060494f280ba89d71a0f51d4ff171bafe476a05",
//"SuiteDirectory": "//mnt/c/work/test262",
"TargetPath": "./Generated",
"Namespace": "Esprima.Tests.Test262",
Expand Down
16 changes: 11 additions & 5 deletions test/Esprima.Tests.Test262/Test262Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ public abstract partial class Test262Test
{
private JavaScriptParser BuildTestExecutor(Test262File file)
{
var options = new ParserOptions()
{
Tolerant = false
};
var options = new ParserOptions() { Tolerant = false };
return new JavaScriptParser(options);
}

Expand All @@ -27,6 +24,15 @@ private static void ExecuteTest(JavaScriptParser parser, Test262File file)

private partial bool ShouldThrow(Test262File testCase, bool strict)
{
return testCase.NegativeTestCase?.Type == ExpectedErrorType.SyntaxError || testCase.NegativeTestCase?.Phase == TestingPhase.Parse;
var negativeTestCase = testCase.NegativeTestCase;

if (negativeTestCase is null)
{
return false;
}

return negativeTestCase.Type == ExpectedErrorType.SyntaxError
&& negativeTestCase.Phase != TestingPhase.Resolution
&& negativeTestCase.Phase != TestingPhase.Runtime;
}
}
33 changes: 5 additions & 28 deletions test/Esprima.Tests.Test262/allow-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -962,10 +962,6 @@ test/language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-g
test/language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-generator.js(strict mode)
test/language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-let.js(default)
test/language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-let.js(strict mode)
test/language/eval-code/direct/strict-caller-global.js(strict mode)
test/language/eval-code/direct/var-env-global-lex-non-strict.js(default)
test/language/eval-code/indirect/parse-failure-2.js(default)
test/language/eval-code/indirect/parse-failure-2.js(strict mode)
test/language/export/escaped-as-export-specifier.js(strict mode)
test/language/export/escaped-from.js(strict mode)
test/language/expressions/arrow-function/dstr/ary-ptrn-rest-init-ary.js(default)
Expand Down Expand Up @@ -1234,8 +1230,6 @@ test/language/expressions/tagged-template/invalid-escape-sequences.js(default)
test/language/expressions/tagged-template/invalid-escape-sequences.js(strict mode)
test/language/expressions/yield/rhs-template-middle.js(default)
test/language/expressions/yield/rhs-template-middle.js(strict mode)
test/language/global-code/decl-lex-restricted-global.js(default)
test/language/global-code/decl-lex-restricted-global.js(strict mode)
test/language/global-code/new.target-arrow.js(default)
test/language/global-code/new.target-arrow.js(strict mode)
test/language/identifier-resolution/static-init-invalid-await.js(default)
Expand All @@ -1244,6 +1238,11 @@ test/language/import/dup-bound-names.js(strict mode)
test/language/import/escaped-as-import-specifier.js(strict mode)
test/language/import/escaped-as-namespace-import.js(strict mode)
test/language/import/escaped-from.js(strict mode)
test/language/import/import-attributes/json-invalid.js(strict mode)
test/language/import/import-attributes/json-named-bindings.js(strict mode)
test/language/literals/boolean/false-with-unicode.js(default)
test/language/literals/boolean/true-with-unicode.js(default)
test/language/literals/null/null-with-unicode.js(default)
test/language/literals/regexp/named-groups/forward-reference.js(default)
test/language/literals/regexp/named-groups/forward-reference.js(strict mode)
test/language/module-code/comment-multi-line-html-close.js(strict mode)
Expand Down Expand Up @@ -1276,28 +1275,6 @@ test/language/module-code/export-expname-from-unpaired-surrogate.js(strict mode)
test/language/module-code/export-expname-import-unpaired-surrogate.js(strict mode)
test/language/module-code/export-expname-string-binding.js(strict mode)
test/language/module-code/export-expname-unpaired-surrogate.js(strict mode)
test/language/module-code/instn-iee-err-ambiguous-as.js(strict mode)
test/language/module-code/instn-iee-err-ambiguous.js(strict mode)
test/language/module-code/instn-iee-err-circular-as.js(strict mode)
test/language/module-code/instn-iee-err-circular.js(strict mode)
test/language/module-code/instn-iee-err-dflt-thru-star-as.js(strict mode)
test/language/module-code/instn-iee-err-dflt-thru-star.js(strict mode)
test/language/module-code/instn-iee-err-not-found-as.js(strict mode)
test/language/module-code/instn-iee-err-not-found.js(strict mode)
test/language/module-code/instn-named-err-ambiguous-as.js(strict mode)
test/language/module-code/instn-named-err-ambiguous.js(strict mode)
test/language/module-code/instn-named-err-dflt-thru-star-as.js(strict mode)
test/language/module-code/instn-named-err-dflt-thru-star-dflt.js(strict mode)
test/language/module-code/instn-named-err-not-found-as.js(strict mode)
test/language/module-code/instn-named-err-not-found-dflt.js(strict mode)
test/language/module-code/instn-named-err-not-found.js(strict mode)
test/language/module-code/instn-resolve-empty-export.js(strict mode)
test/language/module-code/instn-resolve-empty-import.js(strict mode)
test/language/module-code/instn-resolve-err-syntax-1.js(strict mode)
test/language/module-code/instn-resolve-err-syntax-2.js(strict mode)
test/language/module-code/instn-resolve-order-depth.js(strict mode)
test/language/module-code/instn-resolve-order-src.js(strict mode)
test/language/module-code/instn-star-err-not-found.js(strict mode)
test/language/module-code/parse-err-decl-pos-export-block-stmt-list.js(strict mode)
test/language/module-code/parse-err-decl-pos-export-block-stmt.js(strict mode)
test/language/module-code/parse-err-decl-pos-export-switch-case-dflt.js(strict mode)
Expand Down

0 comments on commit f61074b

Please sign in to comment.