Skip to content

Commit 159b2a5

Browse files
committed
Pass name of modified export to runSetters
1 parent 889e8fa commit 159b2a5

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

lib/assignment-visitor.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,30 @@ function assignmentHelper(visitor, path, childName) {
9696
visitor.exportedLocalNames[name] === true &&
9797
inModuleScope(name)
9898
) {
99-
wrap(visitor, path);
99+
wrap(visitor, path, name);
100100
break;
101101
}
102102
}
103103
}
104104

105-
function wrap(visitor, path) {
105+
function wrap(visitor, path, name) {
106106
const value = path.getValue();
107107

108108
if (visitor.magicString !== null) {
109+
let end = name ? `,"${name}")` : ')';
110+
109111
visitor.magicString.prependRight(
110112
value.start,
111113
visitor.moduleAlias + ".runSetters("
112-
).appendLeft(value.end, ")");
114+
).appendLeft(value.end, end);
113115
}
114116

115117
if (visitor.modifyAST) {
118+
let args = name ? [value, {
119+
type: "StringLiteral",
120+
value: name
121+
}] : [value];
122+
116123
path.replace({
117124
type: "CallExpression",
118125
callee: {
@@ -126,7 +133,7 @@ function wrap(visitor, path) {
126133
name: "runSetters"
127134
}
128135
},
129-
arguments: [value]
136+
arguments: args
130137
});
131138
}
132139
}

lib/runtime/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ function moduleExportAs(name) {
117117
// the module system is about to return module.exports from require. This
118118
// might happen more than once per module, in case of dependency cycles,
119119
// so we want Module.prototype.runSetters to run each time.
120-
function runSetters(valueToPassThrough) {
121-
Entry.getOrCreate(this.id, this).runSetters();
120+
function runSetters(valueToPassThrough, names) {
121+
if (typeof names === 'string') {
122+
names = [names];
123+
}
124+
125+
Entry.getOrCreate(this.id, this).runSetters(names, true);
122126

123127
// Assignments to exported local variables get wrapped with calls to
124128
// module.runSetters, so module.runSetters returns the

test/output/declarations-basic/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ function d() {
77
return b;
88
};
99

10-
module.runSetters(c = "c");
10+
module.runSetters(c = "c","c");

test/output/live/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";module.export({value:()=>value,reset:()=>reset,add:()=>add});var value = reset();
22

33
function reset() {
4-
return module.runSetters(value = 0);
4+
return module.runSetters(value = 0,"value");
55
}
66

77
function add(x) {
8-
module.runSetters(value += x);
8+
module.runSetters(value += x,"value");
99
};

0 commit comments

Comments
 (0)