@@ -135,43 +135,7 @@ export const wrap = ({
135
135
} ,
136
136
} ) ;
137
137
138
- let finalExports = originalExports ;
139
-
140
- // This might need some work on fidelity of the define semantics, but I feel bad about making it even more lines
141
- const moduleHandler = {
142
- get ( target , prop ) {
143
- if ( prop === 'exports' ) {
144
- return finalExports ;
145
- }
146
- return target [ prop ] ;
147
- } ,
148
- set ( target , prop , value ) {
149
- if ( prop === 'exports' ) {
150
- finalExports = value ;
151
- }
152
- return true ;
153
- } ,
154
- defineProperty ( target , prop , descriptor ) {
155
- if ( prop === 'exports' ) {
156
- if ( descriptor . configurable === false ) {
157
- // For non-configurable properties, we must define it on the target because ECMAScript spec says so
158
- defineProperty ( target , prop , descriptor ) ;
159
- }
160
- if ( has ( descriptor , 'value' ) ) {
161
- finalExports = descriptor . value ;
162
- return true ;
163
- }
164
- if ( has ( descriptor , 'get' ) ) {
165
- finalExports = descriptor . get ( ) ;
166
- return true ;
167
- }
168
- }
169
- // Seems like there are no reasonable other fields anyone would define https://github.com/search?q=%22Object.defineProperty%28module%2C%22&type=code
170
- return false ;
171
- } ,
172
- } ;
173
-
174
- const module = new Proxy ( { } , moduleHandler ) ;
138
+ const module = { exports : originalExports } ;
175
139
176
140
/** @param {string } importSpecifier */
177
141
const require = importSpecifier => {
@@ -219,6 +183,7 @@ export const wrap = ({
219
183
freeze ( require ) ;
220
184
221
185
const afterExecute = ( ) => {
186
+ const finalExports = module . exports ; // in case it's a getter, only call it once
222
187
const exportsHaveBeenOverwritten = finalExports !== originalExports ;
223
188
// Promotes keys from redefined module.export to top level namespace for import *
224
189
// Note: We could do it less consistently but closer to how node does it if we iterated over exports detected by
0 commit comments