diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/tests/non262/reflect-parse/module-export-name.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
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 | 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); |