Skip to content

Commit

Permalink
Cleanup Entry#addGetterFrom(), Runtime.addExportFromSetter(), and Run…
Browse files Browse the repository at this point in the history
…time.addNamespaceSetter().
  • Loading branch information
jdalton committed Sep 17, 2018
1 parent 0d7117c commit 04e567c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
18 changes: 12 additions & 6 deletions src/entry.js
Expand Up @@ -261,14 +261,20 @@ class Entry {
const { getters } = this
const otherGetters = otherEntry.getters

const getter = getters[exportedName]
const otherGetter = otherGetters[importedName]
if (Reflect.has(getters, exportedName) ||
! Reflect.has(otherGetters, importedName)) {
return this
}

if (typeof getter !== "function" &&
typeof otherGetter === "function") {
this.addGetter(exportedName, otherGetter)
runGetter(this, exportedName)
let otherGetter = otherGetters[importedName]

if (this.extname === ".mjs" &&
otherEntry.type !== TYPE_ESM) {
otherGetter = () => otherEntry.cjsNamespace[importedName]
otherGetter.owner = otherEntry
}

return this.addGetter(exportedName, otherGetter)
}

addSetter(name, localNames, setter, parent) {
Expand Down
27 changes: 9 additions & 18 deletions src/runtime.js
Expand Up @@ -42,11 +42,8 @@ const Runtime = {
return createSetter("from", (value, childEntry) => {
const { entry } = this

entry.exports[importedName] = value
entry.assignExportsToNamespace([importedName])

if (! Reflect.has(entry.getters, exportedName)) {
entry.addGetterFrom(childEntry, importedName, exportedName)
entry.addGetterFrom(childEntry, importedName, exportedName)
}
})
},
Expand All @@ -57,44 +54,38 @@ const Runtime = {

addNamespaceSetter() {
return createSetter("namespace", (value, childEntry) => {
const { _namespace } = childEntry
const { entry } = this
const { getters, type } = entry
const isESM = type === TYPE_ESM
const otherGetters = childEntry.getters
const otherType = childEntry.type

if ((type === TYPE_ESM &&
if ((isESM &&
otherType !== TYPE_ESM &&
entry.extname === ".mjs") ||
(otherType === TYPE_CJS &&
! childEntry.package.options.cjs.namedExports)) {
return
}

for (const name in _namespace) {
for (const name in childEntry._namespace) {
if (name === "default") {
continue
}

entry.exports[name] = _namespace[name]
entry.assignExportsToNamespace([name])

if (! Reflect.has(getters, name)) {
entry.addGetterFrom(childEntry, name)

const getter = getters[name]
const otherGetter = otherGetters[name]

if (type === TYPE_ESM ||
typeof getter !== "function" ||
typeof otherGetter !== "function") {
if (isESM ||
! Reflect.has(getters, name) ||
! Reflect.has(otherGetters, name)) {
continue
}

const ownerName = getter.owner.name
const ownerName = getters[name].owner.name

if (ownerName !== entry.name &&
ownerName !== otherGetter.owner.name) {
ownerName !== otherGetters[name].owner.name) {
entry.addGetter(name, () => ERROR_STAR)
}
}
Expand Down

0 comments on commit 04e567c

Please sign in to comment.