requirejs-esm 2.4.0 → 2.4.2
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 +5 -6
- package/dist/api.js +8845 -9017
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +8845 -9017
- package/dist/plugin.js.map +1 -1
- package/package.json +33 -16
- package/src/transformer/esm.js +18 -66
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "requirejs-esm",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.2",
|
|
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,29 +67,46 @@
|
|
|
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
|
+
},
|
|
70
85
|
"dependencies": {
|
|
71
86
|
"@prantlf/convert-source-map": "^2.0.0",
|
|
72
|
-
"astring": "^1.8.
|
|
87
|
+
"astring": "^1.8.4",
|
|
73
88
|
"charcodes": "^0.2.0",
|
|
74
|
-
"commander": "^
|
|
75
|
-
"meriyah": "^
|
|
76
|
-
"punycode": "^2.3.
|
|
89
|
+
"commander": "^10.0.1",
|
|
90
|
+
"meriyah": "^4.3.5",
|
|
91
|
+
"punycode": "^2.3.0",
|
|
77
92
|
"source-map": "^0.8.0-beta.0",
|
|
78
93
|
"tiny-glob": "^0.2.9"
|
|
79
94
|
},
|
|
80
95
|
"devDependencies": {
|
|
81
|
-
"@prantlf/requirejs": "^3.2
|
|
82
|
-
"@rollup/plugin-commonjs": "^
|
|
83
|
-
"@rollup/plugin-json": "^6.
|
|
84
|
-
"@rollup/plugin-node-resolve": "^15.2
|
|
85
|
-
"
|
|
86
|
-
"
|
|
96
|
+
"@prantlf/requirejs": "^3.0.2",
|
|
97
|
+
"@rollup/plugin-commonjs": "^24.1.0",
|
|
98
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
99
|
+
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
100
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
101
|
+
"@semantic-release/git": "^10.0.1",
|
|
102
|
+
"c8": "^7.13.0",
|
|
103
|
+
"eslint": "^8.40.0",
|
|
87
104
|
"lit-html": "^1",
|
|
88
|
-
"rollup": "^
|
|
105
|
+
"rollup": "^3.21.5",
|
|
89
106
|
"tehanu": "^1.0.1",
|
|
90
|
-
"tehanu-repo-coco": "^1.0.
|
|
91
|
-
"tehanu-teru": "^1.0.
|
|
92
|
-
"terser": "^5.
|
|
107
|
+
"tehanu-repo-coco": "^1.0.0",
|
|
108
|
+
"tehanu-teru": "^1.0.0",
|
|
109
|
+
"terser": "^5.17.1"
|
|
93
110
|
},
|
|
94
111
|
"keywords": [
|
|
95
112
|
"requirejs-plugin",
|
|
@@ -99,4 +116,4 @@
|
|
|
99
116
|
"esm",
|
|
100
117
|
"es6"
|
|
101
118
|
]
|
|
102
|
-
}
|
|
119
|
+
}
|
package/src/transformer/esm.js
CHANGED
|
@@ -93,7 +93,6 @@ export function transformEsmToAmd(program, options) {
|
|
|
93
93
|
let hasExport = false
|
|
94
94
|
let needReturnExport = false
|
|
95
95
|
let isOnlyDefaultExport = true
|
|
96
|
-
let defaultExportVar
|
|
97
96
|
|
|
98
97
|
for (let i = 0; i < length; ++i) {
|
|
99
98
|
const statement = body[i]
|
|
@@ -189,7 +188,6 @@ export function transformEsmToAmd(program, options) {
|
|
|
189
188
|
// export var a = 1
|
|
190
189
|
// export function test() {}
|
|
191
190
|
// export class Test {}
|
|
192
|
-
// export {default as A} from "module"
|
|
193
191
|
if (statement.type === 'ExportNamedDeclaration') {
|
|
194
192
|
hasExport = true
|
|
195
193
|
needReturnExport = true
|
|
@@ -248,45 +246,13 @@ export function transformEsmToAmd(program, options) {
|
|
|
248
246
|
addExportStatement({ exported, local: identifier(localName) })
|
|
249
247
|
} else {
|
|
250
248
|
localName = name
|
|
251
|
-
|
|
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))
|
|
249
|
+
addExportStatement(specifier)
|
|
270
250
|
}
|
|
251
|
+
namedImports.push(declareImport(localName, importVar.name, name))
|
|
271
252
|
}
|
|
272
253
|
} else {
|
|
273
254
|
for (const specifier of specifiers) {
|
|
274
|
-
|
|
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
|
-
}
|
|
255
|
+
addExportStatement(specifier)
|
|
290
256
|
}
|
|
291
257
|
}
|
|
292
258
|
|
|
@@ -314,27 +280,22 @@ export function transformEsmToAmd(program, options) {
|
|
|
314
280
|
|
|
315
281
|
// adding define wrapper
|
|
316
282
|
if (hasExport && needReturnExport) {
|
|
283
|
+
// var _exports = {}
|
|
284
|
+
body.unshift(
|
|
285
|
+
variableDeclaration('let', [
|
|
286
|
+
variableDeclarator(exportsVar, objectExpression([]))
|
|
287
|
+
])
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
// return <expression>
|
|
317
291
|
let returnStat
|
|
318
|
-
if (
|
|
319
|
-
// return
|
|
320
|
-
returnStat = returnStatement(
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
}
|
|
292
|
+
if (isOnlyDefaultExport) {
|
|
293
|
+
// return _exports.default
|
|
294
|
+
returnStat = returnStatement(memberExpression(exportsVar, identifier('default')))
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
// return _exports
|
|
298
|
+
returnStat = returnStatement(exportsVar)
|
|
338
299
|
}
|
|
339
300
|
|
|
340
301
|
body.push(returnStat)
|
|
@@ -350,15 +311,6 @@ export function transformEsmToAmd(program, options) {
|
|
|
350
311
|
const exportStat = exportStatement(exportsVar, asName, local)
|
|
351
312
|
body.push(exportStat)
|
|
352
313
|
}
|
|
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
|
-
}
|
|
362
314
|
}
|
|
363
315
|
|
|
364
316
|
function declareImport(varName, object, property) {
|