From cce2f219f0a1237eefe3ee3e91a6461d8503484c Mon Sep 17 00:00:00 2001 From: Leo Balter <leonardo.balter@gmail.com> Date: Fri, 12 Oct 2018 13:51:09 -0400 Subject: [PATCH] Add tests for export * as ns from mod to dyn imports --- .../ns-get-nested-namespace-dflt-direct.case | 60 ++++++++++++++++++ ...ns-get-nested-namespace-dflt-indirect.case | 61 +++++++++++++++++++ .../ns-get-nested-namespace-props-nrml.case | 58 ++++++++++++++++++ ...d-namespace-dflt-skip-named-end_FIXTURE.js | 6 ++ ...ested-namespace-dflt-skip-named_FIXTURE.js | 4 ++ ...ed-namespace-dflt-skip-prod-end_FIXTURE.js | 5 ++ ...nested-namespace-dflt-skip-prod_FIXTURE.js | 4 ++ ...t-nested-namespace-props-nrml-1_FIXTURE.js | 4 ++ ...t-nested-namespace-props-nrml-2_FIXTURE.js | 23 +++++++ ...t-nested-namespace-props-nrml-3_FIXTURE.js | 5 ++ 10 files changed, 230 insertions(+) create mode 100644 src/dynamic-import/ns-get-nested-namespace-dflt-direct.case create mode 100644 src/dynamic-import/ns-get-nested-namespace-dflt-indirect.case create mode 100644 src/dynamic-import/ns-get-nested-namespace-props-nrml.case create mode 100644 test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-named-end_FIXTURE.js create mode 100644 test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-named_FIXTURE.js create mode 100644 test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-prod-end_FIXTURE.js create mode 100644 test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-prod_FIXTURE.js create mode 100644 test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-1_FIXTURE.js create mode 100644 test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-2_FIXTURE.js create mode 100644 test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-3_FIXTURE.js diff --git a/src/dynamic-import/ns-get-nested-namespace-dflt-direct.case b/src/dynamic-import/ns-get-nested-namespace-dflt-direct.case new file mode 100644 index 0000000000..f8c524f348 --- /dev/null +++ b/src/dynamic-import/ns-get-nested-namespace-dflt-direct.case @@ -0,0 +1,60 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + Direct Default exports are included in an imported module namespace object when + a namespace object is created. +esid: sec-module-namespace-exotic-objects-get-p-receiver +info: | + [...] + 6. Let binding be ! m.ResolveExport(P, « »). + 7. Assert: binding is a ResolvedBinding Record. + 8. Let targetModule be binding.[[Module]]. + 9. Assert: targetModule is not undefined. + 10. If binding.[[BindingName]] is "*namespace*", then + 11. Return ? GetModuleNamespace(targetModule). + + Runtime Semantics: GetModuleNamespace + [...] + 3. If namespace is undefined, then + a. Let exportedNames be ? module.GetExportedNames(« »). + b. Let unambiguousNames be a new empty List. + c. For each name that is an element of exportedNames, + i. Let resolution be ? module.ResolveExport(name, « », « »). + ii. If resolution is null, throw a SyntaxError exception. + iii. If resolution is not "ambiguous", append name to + unambiguousNames. + d. Let namespace be ModuleNamespaceCreate(module, unambiguousNames). + [...] +features: [export-star-as-namespace-from-module] +template: namespace +---*/ + +//- import +import('./get-nested-namespace-dflt-skip-prod_FIXTURE.js') +//- body +var desc = Object.getOwnPropertyDescriptor(ns, 'productionNS2'); + +assert.sameValue(desc.enumerable, true, 'ns.productionNS2: is enumerable'); +assert.sameValue(desc.writable, true, 'ns.productionNS2: is writable'); +assert.sameValue(desc.configurable, false, 'ns.productionNS2: is non-configurable'); + +var keys = Object.keys(ns.productionNS2); + +assert.sameValue(keys.length, 2); +assert.sameValue(keys[0], 'default'); +assert.sameValue(keys[1], 'productionOther'); + +desc = Object.getOwnPropertyDescriptor(ns.productionNS2, 'productionOther'); + +assert.sameValue(desc.value, null, 'ns.productionNS2.productionOther: value is null'); +assert.sameValue(desc.enumerable, true, 'ns.productionNS2.productionOther: is enumerable'); +assert.sameValue(desc.writable, true, 'ns.productionNS2.productionOther: is writable'); +assert.sameValue(desc.configurable, false, 'ns.productionNS2.productionOther: is non-configurable'); + +desc = Object.getOwnPropertyDescriptor(ns.productionNS2, 'default'); + +assert.sameValue(desc.value, 42, 'ns.productionNS2.default value is 42'); +assert.sameValue(desc.enumerable, true, 'ns.productionNS2.default is enumerable'); +assert.sameValue(desc.writable, true, 'ns.productionNS2.default is writable'); +assert.sameValue(desc.configurable, false, 'ns.productionNS2.default is non-configurable'); diff --git a/src/dynamic-import/ns-get-nested-namespace-dflt-indirect.case b/src/dynamic-import/ns-get-nested-namespace-dflt-indirect.case new file mode 100644 index 0000000000..f928107162 --- /dev/null +++ b/src/dynamic-import/ns-get-nested-namespace-dflt-indirect.case @@ -0,0 +1,61 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + Inirect Default exports are included in an imported module namespace object when + a namespace object is created. +esid: sec-module-namespace-exotic-objects-get-p-receiver +info: | + [...] + 6. Let binding be ! m.ResolveExport(P, « »). + 7. Assert: binding is a ResolvedBinding Record. + 8. Let targetModule be binding.[[Module]]. + 9. Assert: targetModule is not undefined. + 10. If binding.[[BindingName]] is "*namespace*", then + 11. Return ? GetModuleNamespace(targetModule). + + Runtime Semantics: GetModuleNamespace + [...] + 3. If namespace is undefined, then + a. Let exportedNames be ? module.GetExportedNames(« »). + b. Let unambiguousNames be a new empty List. + c. For each name that is an element of exportedNames, + i. Let resolution be ? module.ResolveExport(name, « », « »). + ii. If resolution is null, throw a SyntaxError exception. + iii. If resolution is not "ambiguous", append name to + unambiguousNames. + d. Let namespace be ModuleNamespaceCreate(module, unambiguousNames). + [...] +flags: [module] +features: [export-star-as-namespace-from-module] +template: namespace +---*/ + +//- import +import('./get-nested-namespace-dflt-skip-named_FIXTURE.js') +//- body +var desc = Object.getOwnPropertyDescriptor(ns, 'namedNS2'); + +assert.sameValue(desc.enumerable, true, 'ns.namedNS2: is enumerable'); +assert.sameValue(desc.writable, true, 'ns.namedNS2: is writable'); +assert.sameValue(desc.configurable, false, 'ns.namedNS2: is non-configurable'); + +var keys = Object.keys(ns.namedNS2); + +assert.sameValue(keys.length, 2); +assert.sameValue(keys[0], 'default'); +assert.sameValue(keys[1], 'namedOther'); + +desc = Object.getOwnPropertyDescriptor(ns.namedNS2, 'namedOther'); + +assert.sameValue(desc.value, null, 'ns.namedNS2.namedOther value is null'); +assert.sameValue(desc.enumerable, true, 'ns.namedNS2.namedOther: is enumerable'); +assert.sameValue(desc.writable, true, 'ns.namedNS2.namedOther: is writable'); +assert.sameValue(desc.configurable, false, 'ns.namedNS2.namedOther: is non-configurable'); + +desc = Object.getOwnPropertyDescriptor(ns.namedNS2, 'default'); + +assert.sameValue(desc.value, 42, 'ns.namedNS2.default value is 42'); +assert.sameValue(desc.enumerable, true, 'ns.namedNS2.default is enumerable'); +assert.sameValue(desc.writable, true, 'ns.namedNS2.default is writable'); +assert.sameValue(desc.configurable, false, 'ns.namedNS2.default is non-configurable'); diff --git a/src/dynamic-import/ns-get-nested-namespace-props-nrml.case b/src/dynamic-import/ns-get-nested-namespace-props-nrml.case new file mode 100644 index 0000000000..16ed8ef6f9 --- /dev/null +++ b/src/dynamic-import/ns-get-nested-namespace-props-nrml.case @@ -0,0 +1,58 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + Module namespace object reports properties for all ExportEntries of all + dependencies. +esid: sec-moduledeclarationinstantiation +info: | + [...] + 12. For each ImportEntry Record in in module.[[ImportEntries]], do + a. Let importedModule be ? HostResolveImportedModule(module, + in.[[ModuleRequest]]). + b. If in.[[ImportName]] is "*", then + i. Let namespace be ? GetModuleNamespace(importedModule). + [...] + + Runtime Semantics: GetModuleNamespace + 3. If namespace is undefined, then + a. Let exportedNames be ? module.GetExportedNames(« »). + b. Let unambiguousNames be a new empty List. + c. For each name that is an element of exportedNames, + i. Let resolution be ? module.ResolveExport(name, « », « »). + ii. If resolution is null, throw a SyntaxError exception. + iii. If resolution is not "ambiguous", append name to + unambiguousNames. + d. Let namespace be ModuleNamespaceCreate(module, unambiguousNames). +features: [export-star-as-namespace-from-module] +template: namespace +---*/ + +//- setup +function hasOwnProperty(obj, property) { + return Object.prototype.hasOwnProperty.call(obj, property); +} + +//- import +import('./get-nested-namespace-props-nrml-1_FIXTURE.js') +//- body +// Export entries defined by a re-exported as exportns module +assert(hasOwnProperty(ns.exportns, 'starAsVarDecl'), 'starssVarDecl'); +assert(hasOwnProperty(ns.exportns, 'starAsLetDecl'), 'starSsLetDecl'); +assert(hasOwnProperty(ns.exportns, 'starAsConstDecl'), 'starSsConstDecl'); +assert(hasOwnProperty(ns.exportns, 'starAsFuncDecl'), 'starAsFuncDecl'); +assert(hasOwnProperty(ns.exportns, 'starAsGenDecl'), 'starAsGenDecl'); +assert(hasOwnProperty(ns.exportns, 'starAsClassDecl'), 'starAsClassDecl'); +assert(hasOwnProperty(ns.exportns, 'starAsBindingId'), 'starAsBindingId'); +assert(hasOwnProperty(ns.exportns, 'starIdName'), 'starIdName'); +assert(hasOwnProperty(ns.exportns, 'starAsIndirectIdName'), 'starAsIndirectIdName'); +assert(hasOwnProperty(ns.exportns, 'starAsIndirectIdName2'), 'starAsIndirectIdName2'); +assert(hasOwnProperty(ns.exportns, 'namespaceBinding'), 'namespaceBinding'); + +// Bindings that were not exported from any module +assert.sameValue(hasOwnProperty(ns.exportns, 'nonExportedVar'), false, 'nonExportedVar'); +assert.sameValue(hasOwnProperty(ns.exportns, 'nonExportedLet'), false, 'nonExportedLet'); +assert.sameValue(hasOwnProperty(ns.exportns, 'nonExportedConst'), false, 'nonExportedConst'); +assert.sameValue(hasOwnProperty(ns.exportns, 'nonExportedFunc'), false, 'nonExportedFunc'); +assert.sameValue(hasOwnProperty(ns.exportns, 'nonExportedGen'), false, 'nonExportedGen'); +assert.sameValue(hasOwnProperty(ns.exportns, 'nonExportedClass'), false, 'nonExportedClass'); diff --git a/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-named-end_FIXTURE.js b/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-named-end_FIXTURE.js new file mode 100644 index 0000000000..510e2b6642 --- /dev/null +++ b/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-named-end_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +var x = 42; +export var namedOther = null; +export { x as default }; diff --git a/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-named_FIXTURE.js b/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-named_FIXTURE.js new file mode 100644 index 0000000000..fbd2343b7a --- /dev/null +++ b/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-named_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * as namedNS2 from './get-nested-namespace-dflt-skip-named-end_FIXTURE.js'; diff --git a/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-prod-end_FIXTURE.js b/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-prod-end_FIXTURE.js new file mode 100644 index 0000000000..3343f91a54 --- /dev/null +++ b/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-prod-end_FIXTURE.js @@ -0,0 +1,5 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var productionOther = null; +export default 42; diff --git a/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-prod_FIXTURE.js b/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-prod_FIXTURE.js new file mode 100644 index 0000000000..a626c903ab --- /dev/null +++ b/test/language/module-code/dynamic-import/ns/get-nested-namespace-dflt-skip-prod_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * as productionNS2 from './get-nested-namespace-dflt-skip-prod-end_FIXTURE.js'; diff --git a/test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-1_FIXTURE.js b/test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-1_FIXTURE.js new file mode 100644 index 0000000000..c3b3ea40c5 --- /dev/null +++ b/test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-1_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export * as exportns from './get-nested-namespace-props-nrml-2_FIXTURE.js'; diff --git a/test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-2_FIXTURE.js b/test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-2_FIXTURE.js new file mode 100644 index 0000000000..8e3281868d --- /dev/null +++ b/test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-2_FIXTURE.js @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +var notExportedVar; +let notExportedLet; +const notExportedConst = null; +function notExportedFunc() {} +function* notExportedGen() {} +class notExportedClass {} + +var starAsBindingId; + +export var starAsVarDecl; +export let starAsLetDecl; +export const starAsConstDecl = null; +export function starAsFuncDecl() {} +export function* starAsGenDecl() {} +export class starAsClassDecl {} +export { starAsBindingId }; +export { starAsBindingId as starIdName }; +export { starAsIndirectIdName } from './get-nested-namespace-props-nrml-3_FIXTURE.js'; +export { starAsIndirectIdName as starAsIndirectIdName2 } from './get-nested-namespace-props-nrml-3_FIXTURE.js'; +export * as namespaceBinding from './get-nested-namespace-props-nrml-3_FIXTURE.js';; diff --git a/test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-3_FIXTURE.js b/test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-3_FIXTURE.js new file mode 100644 index 0000000000..0c1192c1ad --- /dev/null +++ b/test/language/module-code/dynamic-import/ns/get-nested-namespace-props-nrml-3_FIXTURE.js @@ -0,0 +1,5 @@ +// Copyright (C) 2016 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export var indirectIdName; +export var starAsIndirectIdName; -- GitLab