Skip to content

Commit

Permalink
Use fallback content for mod._compile() if provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Mar 7, 2019
1 parent 3ea7eef commit 8b8bcd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/hook/module.js
Expand Up @@ -101,9 +101,24 @@ function hook(Mod, parent) {
const ext = entry.extname
const pkg = entry.package

const compileFallback = () => {
const compileFallback = (content) => {
entry.state = STATE_EXECUTION_STARTED

if (typeof content === "string") {
const { _compile } = mod
const shouldRestore = has(mod, "_compile")

setProperty(mod, "_compile", toExternalFunction(function (ignoredContent, filename) {
if (shouldRestore) {
setProperty(mod, "_compile", _compile)
} else {
Reflect.deleteProperty(mod, "_compile")
}

return Reflect.apply(_compile, this, [content, filename])
}))
}

let threw = true

try {
Expand Down
2 changes: 1 addition & 1 deletion src/module/internal/compile.js
Expand Up @@ -214,7 +214,7 @@ function compile(caller, entry, content, filename, fallback) {

if (isAbsolute(framePath) &&
! isOwnPath(framePath)) {
return fallback()
return fallback(content)
}
}

Expand Down

0 comments on commit 8b8bcd1

Please sign in to comment.