diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/reflect-parse/module-export-name.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/reflect-parse/module-export-name.js | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/js/src/tests/non262/reflect-parse/module-export-name.js b/js/src/tests/non262/reflect-parse/module-export-name.js new file mode 100644 index 0000000000..405e62767a --- /dev/null +++ b/js/src/tests/non262/reflect-parse/module-export-name.js @@ -0,0 +1,117 @@ +// |reftest| skip-if(!xulRuntime.shell) + +function moduleRequest(source, assertions) { + return { + type: "ModuleRequest", + source, + assertions, + }; +} + +function importAssertion(key, value) { + return { + type: "ImportAssertion", + key, + value, + }; +} + +function importDecl(specifiers, moduleRequest) { + return { + type: "ImportDeclaration", + specifiers, + moduleRequest, + }; +} + +function importSpec(id, name) { + return { + type: "ImportSpecifier", + id, + name, + }; +} + +function exportDecl(declaration, specifiers, moduleRequest, isDefault) { + return { + type: "ExportDeclaration", + declaration, + specifiers, + moduleRequest, + isDefault, + }; +} + +function exportSpec(id, name) { + return { + type: "ExportSpecifier", + id, + name, + }; +} + +function exportNamespaceSpec(name) { + return { + type: "ExportNamespaceSpecifier", + name, + }; +} + +function assertModule(src, patt) { + program(patt).assert(Reflect.parse(src, {target: "module"})); +} + +assertModule(` + import {"x" as y} from "module"; +`, [ + importDecl([importSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), [])), +]); + +assertModule(` + var x; + export {x as "y"}; +`, [ + varDecl([{id: ident("x"), init: null}]), + exportDecl(null, [exportSpec(ident("x"), literal("y"))], null, false), +]); + +assertModule(` + export {x as "y"} from "module"; +`, [ + exportDecl(null, [exportSpec(ident("x"), literal("y"))], moduleRequest(literal("module"), []), false), +]); + +assertModule(` + export {"x" as y} from "module"; +`, [ + exportDecl(null, [exportSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), []), false), +]); + +assertModule(` + export {"x" as "y"} from "module"; +`, [ + exportDecl(null, [exportSpec(literal("x"), literal("y"))], moduleRequest(literal("module"), []), false), +]); + +assertModule(` + export {"x"} from "module"; +`, [ + exportDecl(null, [exportSpec(literal("x"), literal("x"))], moduleRequest(literal("module"), []), false), +]); + +assertModule(` + export * as "x" from "module"; +`, [ + exportDecl(null, [exportNamespaceSpec(literal("x"))], moduleRequest(literal("module"), []), false), +]); + +if (getRealmConfiguration()['importAssertions']) { + assertModule(` + import {"x" as y} from "module" assert {type: "json"}; + `, [ + importDecl([importSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), [importAssertion(ident("type"), literal("json"))])), + ]); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |