From 6feb50b1e7366f1ed075ed5ce05c8832e5493278 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 14 Nov 2018 18:29:28 -0800 Subject: [PATCH] Move runtime.initBindings() call into runtime.addDefaultValue(). --- src/runtime.js | 4 ++++ src/visitor/import-export.js | 8 ++------ test/output/default-expression/expected.mjs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/runtime.js b/src/runtime.js index faacb3150..bf238e1b7 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -37,6 +37,10 @@ const { const Runtime = { addDefaultValue(value) { this.addExportGetters([["default", () => value]]) + + if (value === void 0) { + this.initBindings(["default"]) + } }, addExportFromSetter(importedName, exportedName = importedName) { diff --git a/src/visitor/import-export.js b/src/visitor/import-export.js index f4e7563cb..27c043f43 100644 --- a/src/visitor/import-export.js +++ b/src/visitor/import-export.js @@ -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 } @@ -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") diff --git a/test/output/default-expression/expected.mjs b/test/output/default-expression/expected.mjs index 203c13d01..5ee42f703 100644 --- a/test/output/default-expression/expected.mjs +++ b/test/output/default-expression/expected.mjs @@ -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));