diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/non262/reflect-parse/module-export-name.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/reflect-parse/module-export-name.js')
-rw-r--r-- | js/src/tests/non262/reflect-parse/module-export-name.js | 121 |
1 files changed, 121 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..9b51bf910b --- /dev/null +++ b/js/src/tests/non262/reflect-parse/module-export-name.js @@ -0,0 +1,121 @@ +// |reftest| skip-if(!xulRuntime.shell) shell-option(--enable-import-assertions) + +function moduleRequest(source, attributes) { + return { + type: "ModuleRequest", + source, + attributes, + }; +} + +function importAttribute(key, value) { + return { + type: "ImportAttribute", + 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("importAttributes")) { + assertModule(` + import {"x" as y} from "module" with {type: "json"}; + `, [ + importDecl([importSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), [importAttribute(ident("type"), literal("json"))])), + ]); + assertModule(` + import {"x" as y} from "module" assert {type: "json"}; + `, [ + importDecl([importSpec(literal("x"), ident("y"))], moduleRequest(literal("module"), [importAttribute(ident("type"), literal("json"))])), + ]); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |