Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Entries should snapshot exports. [closes #36]
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Aug 16, 2017
1 parent c984a3c commit 4d19031
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
27 changes: 13 additions & 14 deletions src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,28 @@ class Entry {
exported = mod.exports
}

let entry

if (! isObjectLike(exported)) {
// Create a temporary `Entry` object to call `entry.addSetters()` and
// trigger `entry.update()`, so that `runtime.watch()` behaves as expected.
entry = new Entry(mod, exported)
entry.loaded()
return entry
}
let entry = entryMap.get(mod)
const useExports = isObjectLike(exported)

entry = entryMap.get(exported)
if (useExports) {
entry = entryMap.get(exported) || entry
}

if (entry === void 0) {
entry = new Entry(mod, exported, options)
entryMap.set(exported, entry)
entryMap.set(mod, entry)

if (useExports) {
entryMap.set(exported, entry)
}
}

return entry
}

static set(exported, entry) {
if (isObjectLike(exported)) {
entryMap.set(exported, entry)
static set(key, entry) {
if (isObjectLike(key)) {
entryMap.set(key, entry)
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import assign from "./util/assign.js"
import builtinModules from "./builtin-modules.js"
import createOptions from "./util/create-options.js"
import getSourceType from "./util/get-source-type.js"
import isObjectLike from "./util/is-object-like.js"
import resolveId from "./util/resolve-id.js"
import setGetter from "./util/set-getter.js"

Expand Down Expand Up @@ -87,15 +86,14 @@ class Runtime {
moduleWrapper.call(exported, exported, wrappedRequire, mod, __filename, __dirname)
mod.loaded = true

if (! isObjectLike(mod.exports)) {
return
}

const newEntry = Entry.get(mod, mod.exports, options)
newEntry.exports = mod.exports
newEntry.sourceType = getSourceType(newEntry.exports)
newEntry.update().loaded()

Entry.set(mod.exports, entry.merge(newEntry))
entry.merge(newEntry)
Entry.set(mod, entry)
Entry.set(mod.exports, entry)
}

// Platform-specific code should find a way to call this method whenever
Expand Down

0 comments on commit 4d19031

Please sign in to comment.