bare-module 3.1.10 → 3.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +43 -33
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -132,7 +132,7 @@ const Module = module.exports = exports = class Module {
|
|
|
132
132
|
|
|
133
133
|
if (this._type === constants.types.MODULE) return
|
|
134
134
|
|
|
135
|
-
const names = ['default']
|
|
135
|
+
const names = new Set(['default'])
|
|
136
136
|
const queue = [this]
|
|
137
137
|
const seen = new Set()
|
|
138
138
|
|
|
@@ -147,7 +147,7 @@ const Module = module.exports = exports = class Module {
|
|
|
147
147
|
case constants.types.SCRIPT: {
|
|
148
148
|
const result = parse(module._function.toString())
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
for (const name of result.exports) names.add(name)
|
|
151
151
|
|
|
152
152
|
const referrer = module
|
|
153
153
|
|
|
@@ -165,20 +165,16 @@ const Module = module.exports = exports = class Module {
|
|
|
165
165
|
case constants.types.MODULE:
|
|
166
166
|
module._evaluate()
|
|
167
167
|
|
|
168
|
-
for (const name of Object.keys(module._exports))
|
|
169
|
-
names.push(name)
|
|
170
|
-
}
|
|
168
|
+
for (const name of Object.keys(module._exports)) names.add(name)
|
|
171
169
|
|
|
172
170
|
break
|
|
173
171
|
|
|
174
172
|
case constants.types.JSON:
|
|
175
|
-
for (const name of Object.keys(module._exports))
|
|
176
|
-
names.push(name)
|
|
177
|
-
}
|
|
173
|
+
for (const name of Object.keys(module._exports)) names.add(name)
|
|
178
174
|
}
|
|
179
175
|
}
|
|
180
176
|
|
|
181
|
-
this._names = names
|
|
177
|
+
this._names = Array.from(names)
|
|
182
178
|
|
|
183
179
|
this._handle = binding.createSyntheticModule(this._url.href, this._names, Module._handle)
|
|
184
180
|
}
|
|
@@ -296,7 +292,21 @@ const Module = module.exports = exports = class Module {
|
|
|
296
292
|
module._evaluate()
|
|
297
293
|
|
|
298
294
|
for (const name of module._names) {
|
|
299
|
-
|
|
295
|
+
let value
|
|
296
|
+
|
|
297
|
+
if (
|
|
298
|
+
name === 'default' && (
|
|
299
|
+
typeof module._exports !== 'object' ||
|
|
300
|
+
module._exports === null ||
|
|
301
|
+
name in module._exports === false
|
|
302
|
+
)
|
|
303
|
+
) {
|
|
304
|
+
value = module._exports
|
|
305
|
+
} else {
|
|
306
|
+
value = module._exports[name]
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
binding.setExport(module._handle, name, value)
|
|
300
310
|
}
|
|
301
311
|
}
|
|
302
312
|
|
|
@@ -373,33 +383,33 @@ const Module = module.exports = exports = class Module {
|
|
|
373
383
|
|
|
374
384
|
const module = cache[url.href] = new Module(url)
|
|
375
385
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
386
|
+
try {
|
|
387
|
+
switch (url.protocol) {
|
|
388
|
+
case 'builtin:':
|
|
389
|
+
module._exports = builtins[url.pathname]
|
|
390
|
+
break
|
|
380
391
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
392
|
+
default: {
|
|
393
|
+
module._defaultType = defaultType
|
|
394
|
+
module._cache = cache
|
|
395
|
+
module._main = main || module
|
|
396
|
+
module._protocol = protocol
|
|
397
|
+
module._imports = imports
|
|
398
|
+
module._resolutions = resolutions
|
|
399
|
+
module._builtins = builtins
|
|
400
|
+
module._conditions = conditions
|
|
401
|
+
|
|
402
|
+
let extension = self._extensionFor(type) || path.extname(url.pathname)
|
|
403
|
+
|
|
404
|
+
if (extension in self._extensions === false) {
|
|
405
|
+
if (defaultType) extension = self._extensionFor(defaultType) || '.js'
|
|
406
|
+
else extension = '.js'
|
|
407
|
+
}
|
|
397
408
|
|
|
398
|
-
|
|
409
|
+
self._extensions[extension](module, source, referrer)
|
|
410
|
+
}
|
|
399
411
|
}
|
|
400
|
-
}
|
|
401
412
|
|
|
402
|
-
try {
|
|
403
413
|
return module._transform(isImport, isDynamicImport)
|
|
404
414
|
} catch (err) {
|
|
405
415
|
delete cache[url.href]
|