requirejs-esm 2.3.1 → 2.4.0
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/LICENSE +1 -1
- package/README.md +1 -1
- package/bin/esm2requirejs.js +6 -5
- package/dist/api.js +9017 -8845
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +9017 -8845
- package/dist/plugin.js.map +1 -1
- package/package.json +16 -33
- package/src/transformer/esm.js +66 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "requirejs-esm",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "A RequireJS plugin converting JavaScript modules from ESM to AMD.",
|
|
5
5
|
"author": "Ferdinand Prantl <prantlf@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,46 +67,29 @@
|
|
|
67
67
|
"functions": 20,
|
|
68
68
|
"statements": 45
|
|
69
69
|
},
|
|
70
|
-
"release": {
|
|
71
|
-
"plugins": [
|
|
72
|
-
"@semantic-release/commit-analyzer",
|
|
73
|
-
"@semantic-release/release-notes-generator",
|
|
74
|
-
"@semantic-release/changelog",
|
|
75
|
-
"@semantic-release/npm",
|
|
76
|
-
[
|
|
77
|
-
"@semantic-release/github",
|
|
78
|
-
{
|
|
79
|
-
"failComment": false
|
|
80
|
-
}
|
|
81
|
-
],
|
|
82
|
-
"@semantic-release/git"
|
|
83
|
-
]
|
|
84
|
-
},
|
|
85
70
|
"dependencies": {
|
|
86
71
|
"@prantlf/convert-source-map": "^2.0.0",
|
|
87
|
-
"astring": "^1.8.
|
|
72
|
+
"astring": "^1.8.6",
|
|
88
73
|
"charcodes": "^0.2.0",
|
|
89
|
-
"commander": "^
|
|
90
|
-
"meriyah": "^
|
|
91
|
-
"punycode": "^2.3.
|
|
74
|
+
"commander": "^12.1.0",
|
|
75
|
+
"meriyah": "^5.0.0",
|
|
76
|
+
"punycode": "^2.3.1",
|
|
92
77
|
"source-map": "^0.8.0-beta.0",
|
|
93
78
|
"tiny-glob": "^0.2.9"
|
|
94
79
|
},
|
|
95
80
|
"devDependencies": {
|
|
96
|
-
"@prantlf/requirejs": "^3.0
|
|
97
|
-
"@rollup/plugin-commonjs": "^
|
|
98
|
-
"@rollup/plugin-json": "^6.
|
|
99
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"c8": "^7.13.0",
|
|
103
|
-
"eslint": "^8.40.0",
|
|
81
|
+
"@prantlf/requirejs": "^3.2.0",
|
|
82
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
83
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
84
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
85
|
+
"c8": "^10.1.2",
|
|
86
|
+
"eslint": "^8.57.0",
|
|
104
87
|
"lit-html": "^1",
|
|
105
|
-
"rollup": "^
|
|
88
|
+
"rollup": "^4.19.0",
|
|
106
89
|
"tehanu": "^1.0.1",
|
|
107
|
-
"tehanu-repo-coco": "^1.0.
|
|
108
|
-
"tehanu-teru": "^1.0.
|
|
109
|
-
"terser": "^5.
|
|
90
|
+
"tehanu-repo-coco": "^1.0.1",
|
|
91
|
+
"tehanu-teru": "^1.0.1",
|
|
92
|
+
"terser": "^5.31.3"
|
|
110
93
|
},
|
|
111
94
|
"keywords": [
|
|
112
95
|
"requirejs-plugin",
|
|
@@ -116,4 +99,4 @@
|
|
|
116
99
|
"esm",
|
|
117
100
|
"es6"
|
|
118
101
|
]
|
|
119
|
-
}
|
|
102
|
+
}
|
package/src/transformer/esm.js
CHANGED
|
@@ -93,6 +93,7 @@ export function transformEsmToAmd(program, options) {
|
|
|
93
93
|
let hasExport = false
|
|
94
94
|
let needReturnExport = false
|
|
95
95
|
let isOnlyDefaultExport = true
|
|
96
|
+
let defaultExportVar
|
|
96
97
|
|
|
97
98
|
for (let i = 0; i < length; ++i) {
|
|
98
99
|
const statement = body[i]
|
|
@@ -188,6 +189,7 @@ export function transformEsmToAmd(program, options) {
|
|
|
188
189
|
// export var a = 1
|
|
189
190
|
// export function test() {}
|
|
190
191
|
// export class Test {}
|
|
192
|
+
// export {default as A} from "module"
|
|
191
193
|
if (statement.type === 'ExportNamedDeclaration') {
|
|
192
194
|
hasExport = true
|
|
193
195
|
needReturnExport = true
|
|
@@ -246,13 +248,45 @@ export function transformEsmToAmd(program, options) {
|
|
|
246
248
|
addExportStatement({ exported, local: identifier(localName) })
|
|
247
249
|
} else {
|
|
248
250
|
localName = name
|
|
249
|
-
|
|
251
|
+
if (localName === 'default') {
|
|
252
|
+
if (exported.name === 'default') {
|
|
253
|
+
// export {default} from "module"
|
|
254
|
+
defaultExportVar = importVar
|
|
255
|
+
} else {
|
|
256
|
+
// export {default as A} from "module"
|
|
257
|
+
addExportDefaultStatement(exported, importVar)
|
|
258
|
+
}
|
|
259
|
+
} else if (exported.name === 'default') {
|
|
260
|
+
// export {A as default} from "module"
|
|
261
|
+
defaultExportVar = importVar
|
|
262
|
+
} else {
|
|
263
|
+
// export {A as B} from "module"
|
|
264
|
+
addExportStatement(specifier)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (localName !== 'default' && !defaultExportVar) {
|
|
268
|
+
// _exports.B = A;
|
|
269
|
+
namedImports.push(declareImport(localName, importVar.name, name))
|
|
250
270
|
}
|
|
251
|
-
namedImports.push(declareImport(localName, importVar.name, name))
|
|
252
271
|
}
|
|
253
272
|
} else {
|
|
254
273
|
for (const specifier of specifiers) {
|
|
255
|
-
|
|
274
|
+
const { exported, local } = specifier
|
|
275
|
+
if (local.name === 'default') {
|
|
276
|
+
if (exported.name === 'default') {
|
|
277
|
+
// export {default}
|
|
278
|
+
throw new Error('Expression `export { default }` is not supported.')
|
|
279
|
+
} else {
|
|
280
|
+
// export {default as A}
|
|
281
|
+
throw new Error(`Expression \`export { default as ${exported.name} }\` is not supported.`)
|
|
282
|
+
}
|
|
283
|
+
} else if (exported.name === 'default') {
|
|
284
|
+
// export {A as default}
|
|
285
|
+
defaultExportVar = local
|
|
286
|
+
} else {
|
|
287
|
+
// export {A as B}
|
|
288
|
+
addExportStatement(specifier)
|
|
289
|
+
}
|
|
256
290
|
}
|
|
257
291
|
}
|
|
258
292
|
|
|
@@ -280,22 +314,27 @@ export function transformEsmToAmd(program, options) {
|
|
|
280
314
|
|
|
281
315
|
// adding define wrapper
|
|
282
316
|
if (hasExport && needReturnExport) {
|
|
283
|
-
// var _exports = {}
|
|
284
|
-
body.unshift(
|
|
285
|
-
variableDeclaration('let', [
|
|
286
|
-
variableDeclarator(exportsVar, objectExpression([]))
|
|
287
|
-
])
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
// return <expression>
|
|
291
317
|
let returnStat
|
|
292
|
-
if (
|
|
293
|
-
// return
|
|
294
|
-
returnStat = returnStatement(
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
318
|
+
if (defaultExportVar) {
|
|
319
|
+
// return _import
|
|
320
|
+
returnStat = returnStatement(defaultExportVar)
|
|
321
|
+
} else {
|
|
322
|
+
// var _exports = {}
|
|
323
|
+
body.unshift(
|
|
324
|
+
variableDeclaration('let', [
|
|
325
|
+
variableDeclarator(exportsVar, objectExpression([]))
|
|
326
|
+
])
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
// return <expression>
|
|
330
|
+
if (isOnlyDefaultExport) {
|
|
331
|
+
// return _exports.default
|
|
332
|
+
returnStat = returnStatement(memberExpression(exportsVar, identifier('default')))
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
// return _exports
|
|
336
|
+
returnStat = returnStatement(exportsVar)
|
|
337
|
+
}
|
|
299
338
|
}
|
|
300
339
|
|
|
301
340
|
body.push(returnStat)
|
|
@@ -311,6 +350,15 @@ export function transformEsmToAmd(program, options) {
|
|
|
311
350
|
const exportStat = exportStatement(exportsVar, asName, local)
|
|
312
351
|
body.push(exportStat)
|
|
313
352
|
}
|
|
353
|
+
|
|
354
|
+
function addExportDefaultStatement(exported, imported) {
|
|
355
|
+
const asName = exported.name
|
|
356
|
+
if (asName !== 'default') {
|
|
357
|
+
isOnlyDefaultExport = false
|
|
358
|
+
}
|
|
359
|
+
const exportStat = exportStatement(exportsVar, asName, imported)
|
|
360
|
+
body.push(exportStat)
|
|
361
|
+
}
|
|
314
362
|
}
|
|
315
363
|
|
|
316
364
|
function declareImport(varName, object, property) {
|