Skip to content

Commit f61074b

Browse files
authored
Fix handling of trailing comma in import arguments (#430)
* update test suite
1 parent d2771db commit f61074b

File tree

5 files changed

+36
-40
lines changed

5 files changed

+36
-40
lines changed

src/Esprima/JavaScriptParser.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,16 +1739,18 @@ private ImportExpression ParseImportCall()
17391739

17401740
_context.IsAssignmentTarget = previousIsAssignmentTarget;
17411741

1742-
if (!this.Match(")") && _tolerant)
1743-
{
1744-
this.TolerateUnexpectedToken(this.NextToken());
1745-
}
1746-
else
1742+
if (!this.Match(")"))
17471743
{
17481744
if (Match(","))
1745+
{
17491746
NextToken();
1747+
}
17501748
this.Expect(")");
17511749
}
1750+
else
1751+
{
1752+
NextToken();
1753+
}
17521754

17531755
return Finalize(node, new ImportExpression(source, attributes));
17541756
}

test/Esprima.Tests.Test262/Program.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,18 @@ public static async Task<int> Main(string[] args)
8282
},
8383
IsIgnored = file => file.Features.IndexOfAny(excludedFeatures.AsSpan()) != -1 || knownFailing.Contains(file.ToString()),
8484
IsParseError = exception => exception is ParserException,
85-
ShouldThrow = file => file.NegativeTestCase?.Type == ExpectedErrorType.SyntaxError || file.NegativeTestCase?.Phase == TestingPhase.Parse,
85+
ShouldThrow = file =>
86+
{
87+
var negativeTestCase = file.NegativeTestCase;
88+
if (negativeTestCase is null)
89+
{
90+
return false;
91+
}
92+
93+
return negativeTestCase.Type == ExpectedErrorType.SyntaxError
94+
&& negativeTestCase.Phase != TestingPhase.Resolution
95+
&& negativeTestCase.Phase != TestingPhase.Runtime;
96+
},
8697
OnTestExecuted = _ => testTask.Increment(1)
8798
};
8899

test/Esprima.Tests.Test262/Test262Harness.settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"SuiteGitSha": "83a46bfe0e79aed8274a1b9f4beb0a2efa0b3533",
2+
"SuiteGitSha": "2060494f280ba89d71a0f51d4ff171bafe476a05",
33
//"SuiteDirectory": "//mnt/c/work/test262",
44
"TargetPath": "./Generated",
55
"Namespace": "Esprima.Tests.Test262",

test/Esprima.Tests.Test262/Test262Test.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ public abstract partial class Test262Test
66
{
77
private JavaScriptParser BuildTestExecutor(Test262File file)
88
{
9-
var options = new ParserOptions()
10-
{
11-
Tolerant = false
12-
};
9+
var options = new ParserOptions() { Tolerant = false };
1310
return new JavaScriptParser(options);
1411
}
1512

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

2825
private partial bool ShouldThrow(Test262File testCase, bool strict)
2926
{
30-
return testCase.NegativeTestCase?.Type == ExpectedErrorType.SyntaxError || testCase.NegativeTestCase?.Phase == TestingPhase.Parse;
27+
var negativeTestCase = testCase.NegativeTestCase;
28+
29+
if (negativeTestCase is null)
30+
{
31+
return false;
32+
}
33+
34+
return negativeTestCase.Type == ExpectedErrorType.SyntaxError
35+
&& negativeTestCase.Phase != TestingPhase.Resolution
36+
&& negativeTestCase.Phase != TestingPhase.Runtime;
3137
}
3238
}

test/Esprima.Tests.Test262/allow-list.txt

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -962,10 +962,6 @@ test/language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-g
962962
test/language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-generator.js(strict mode)
963963
test/language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-let.js(default)
964964
test/language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-let.js(strict mode)
965-
test/language/eval-code/direct/strict-caller-global.js(strict mode)
966-
test/language/eval-code/direct/var-env-global-lex-non-strict.js(default)
967-
test/language/eval-code/indirect/parse-failure-2.js(default)
968-
test/language/eval-code/indirect/parse-failure-2.js(strict mode)
969965
test/language/export/escaped-as-export-specifier.js(strict mode)
970966
test/language/export/escaped-from.js(strict mode)
971967
test/language/expressions/arrow-function/dstr/ary-ptrn-rest-init-ary.js(default)
@@ -1234,8 +1230,6 @@ test/language/expressions/tagged-template/invalid-escape-sequences.js(default)
12341230
test/language/expressions/tagged-template/invalid-escape-sequences.js(strict mode)
12351231
test/language/expressions/yield/rhs-template-middle.js(default)
12361232
test/language/expressions/yield/rhs-template-middle.js(strict mode)
1237-
test/language/global-code/decl-lex-restricted-global.js(default)
1238-
test/language/global-code/decl-lex-restricted-global.js(strict mode)
12391233
test/language/global-code/new.target-arrow.js(default)
12401234
test/language/global-code/new.target-arrow.js(strict mode)
12411235
test/language/identifier-resolution/static-init-invalid-await.js(default)
@@ -1244,6 +1238,11 @@ test/language/import/dup-bound-names.js(strict mode)
12441238
test/language/import/escaped-as-import-specifier.js(strict mode)
12451239
test/language/import/escaped-as-namespace-import.js(strict mode)
12461240
test/language/import/escaped-from.js(strict mode)
1241+
test/language/import/import-attributes/json-invalid.js(strict mode)
1242+
test/language/import/import-attributes/json-named-bindings.js(strict mode)
1243+
test/language/literals/boolean/false-with-unicode.js(default)
1244+
test/language/literals/boolean/true-with-unicode.js(default)
1245+
test/language/literals/null/null-with-unicode.js(default)
12471246
test/language/literals/regexp/named-groups/forward-reference.js(default)
12481247
test/language/literals/regexp/named-groups/forward-reference.js(strict mode)
12491248
test/language/module-code/comment-multi-line-html-close.js(strict mode)
@@ -1276,28 +1275,6 @@ test/language/module-code/export-expname-from-unpaired-surrogate.js(strict mode)
12761275
test/language/module-code/export-expname-import-unpaired-surrogate.js(strict mode)
12771276
test/language/module-code/export-expname-string-binding.js(strict mode)
12781277
test/language/module-code/export-expname-unpaired-surrogate.js(strict mode)
1279-
test/language/module-code/instn-iee-err-ambiguous-as.js(strict mode)
1280-
test/language/module-code/instn-iee-err-ambiguous.js(strict mode)
1281-
test/language/module-code/instn-iee-err-circular-as.js(strict mode)
1282-
test/language/module-code/instn-iee-err-circular.js(strict mode)
1283-
test/language/module-code/instn-iee-err-dflt-thru-star-as.js(strict mode)
1284-
test/language/module-code/instn-iee-err-dflt-thru-star.js(strict mode)
1285-
test/language/module-code/instn-iee-err-not-found-as.js(strict mode)
1286-
test/language/module-code/instn-iee-err-not-found.js(strict mode)
1287-
test/language/module-code/instn-named-err-ambiguous-as.js(strict mode)
1288-
test/language/module-code/instn-named-err-ambiguous.js(strict mode)
1289-
test/language/module-code/instn-named-err-dflt-thru-star-as.js(strict mode)
1290-
test/language/module-code/instn-named-err-dflt-thru-star-dflt.js(strict mode)
1291-
test/language/module-code/instn-named-err-not-found-as.js(strict mode)
1292-
test/language/module-code/instn-named-err-not-found-dflt.js(strict mode)
1293-
test/language/module-code/instn-named-err-not-found.js(strict mode)
1294-
test/language/module-code/instn-resolve-empty-export.js(strict mode)
1295-
test/language/module-code/instn-resolve-empty-import.js(strict mode)
1296-
test/language/module-code/instn-resolve-err-syntax-1.js(strict mode)
1297-
test/language/module-code/instn-resolve-err-syntax-2.js(strict mode)
1298-
test/language/module-code/instn-resolve-order-depth.js(strict mode)
1299-
test/language/module-code/instn-resolve-order-src.js(strict mode)
1300-
test/language/module-code/instn-star-err-not-found.js(strict mode)
13011278
test/language/module-code/parse-err-decl-pos-export-block-stmt-list.js(strict mode)
13021279
test/language/module-code/parse-err-decl-pos-export-block-stmt.js(strict mode)
13031280
test/language/module-code/parse-err-decl-pos-export-switch-case-dflt.js(strict mode)

0 commit comments

Comments
 (0)