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

Commit

Permalink
Allow setting globals of restricted cjs variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Mar 23, 2019
1 parent 876f043 commit 86123b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,13 @@ const Runtime = {
throw new ERR_CONST_ASSIGNMENT(throwConstAssignment)
},
throwUndeclared: function throwUndeclared(name) {
throw new ERR_UNDEFINED_IDENTIFIER(name, throwUndeclared)
const { unsafeGlobal } = shared

if (! Reflect.has(unsafeGlobal, name)) {
throw new ERR_UNDEFINED_IDENTIFIER(name, throwUndeclared)
}

return unsafeGlobal[name]
},
updateBindings(valueToPassThrough) {
this.entry.updateBindings(null, UPDATE_TYPE_LIVE)
Expand Down
5 changes: 1 addition & 4 deletions src/visitor/undeclared.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ function init() {
if (parent.type === "UnaryExpression" &&
parent.operator === "typeof") {
this.transforms |= TRANSFORMS_UNDECLARED

// Use `runtimeName` as the voided expression for content sniffing
// based on the presence of the runtime identifier.
overwrite(this, node.start, node.end, "void " + runtimeName)
overwrite(this, node.start, node.end, runtimeName + ".g." + name)
return
}

Expand Down

0 comments on commit 86123b5

Please sign in to comment.