ladybird/Tests/LibJS/Runtime/syntax/dynamic-import-usage.js
Andreas Kling 8b64f0079b LibJS: Allow parenthesized dynamic import under new
Parenthesized import calls are valid callees for new expressions. The
unparenthesized form remains a syntax error, but the grouped expression
must parse and then fail at runtime if the produced Promise is not a
constructor.

Add syntax coverage for both forms.
2026-05-22 14:30:35 +02:00

23 lines
805 B
JavaScript

describe("parsing", () => {
test("can parse call import call", () => {
expect("import('a')").toEval();
expect("import('a', )").toEval();
expect("import('a', {options: true})").toEval();
});
test("parenthesized import call can be used as a new callee", () => {
expect("new import('a')").not.toEval();
expect("new (import('a'), function() {})").toEval();
});
test("does not crash on unexpected tokens after import", () => {
expect("f = import('a')").toEval();
expect("f= import").not.toEval();
expect("f= import;").not.toEval();
expect("f= import?").not.toEval();
expect("f= import'").not.toEval();
expect("f= import 'a'").not.toEval();
expect("f= import['a']").not.toEval();
});
});