Skip to content

Commit

Permalink
Move runtime.initBindings() call into runtime.addDefaultValue().
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Nov 15, 2018
1 parent 6976dd6 commit 6feb50b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const {
const Runtime = {
addDefaultValue(value) {
this.addExportGetters([["default", () => value]])

if (value === void 0) {
this.initBindings(["default"])
}
},

addExportFromSetter(importedName, exportedName = importedName) {
Expand Down
8 changes: 2 additions & 6 deletions src/visitor/import-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ function init() {
// If the exported expression is a comma-separated sequence expression
// it may not include the vital parentheses, so we should wrap the
// expression with parentheses to make sure it's treated as a single
// argument to `runtime.default()`, rather than as multiple arguments.
// argument to `runtime.addDefaultValue()`, rather than as multiple
// arguments.
prefix += "("
suffix = ")" + suffix
}
Expand All @@ -300,11 +301,6 @@ function init() {

if (isInitable(declaration)) {
this.initedBindings.default = true

magicString.appendRight(
declaration.end,
runtimeName + '.j(["default"]);'
)
}

path.call(this, "visitWithoutReset", "declaration")
Expand Down
2 changes: 1 addition & 1 deletion test/output/default-expression/expected.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

// This default expression will evaluate to 0 if the parentheses are
// mistakenly stripped away.
_.d((value++, value));_.j(["default"]);
_.d((value++, value));

0 comments on commit 6feb50b

Please sign in to comment.