requirejs-esm 4.3.0 → 4.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/README.md +4 -1
- package/bin/esm2requirejs.js +3 -0
- package/dist/api.js +91 -80
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +88 -73
- package/dist/plugin.js.map +1 -1
- package/package.json +6 -6
- package/src/api.d.ts +1 -0
- package/src/plugin.js +4 -0
- package/src/transform.js +4 -0
- package/src/transformer/esm.js +41 -35
package/README.md
CHANGED
|
@@ -128,6 +128,9 @@ The `esm` plugin supports configuration with the following defaults:
|
|
|
128
128
|
// Do not insert `"use strict"` expression to the AMD modules. You'd set it
|
|
129
129
|
// to `false` if your bundler inserts `"use strict"` to the outer scope.
|
|
130
130
|
useStrict: true,
|
|
131
|
+
// Split `export default class A {}` to `class A {}; export default A`
|
|
132
|
+
// to trade easier AST manipulation for 100% code compatibility.
|
|
133
|
+
splitDefaultNamedDeclarations: false,
|
|
131
134
|
// Enable source maps, can be an object with booleans { inline, content }.
|
|
132
135
|
// If set to true, the object will be set to { inline: true, content: true }.
|
|
133
136
|
sourceMap: false,
|
|
@@ -184,7 +187,7 @@ The returned object:
|
|
|
184
187
|
}
|
|
185
188
|
```
|
|
186
189
|
|
|
187
|
-
## Skipping
|
|
190
|
+
## Skipping and Forcing Transformation
|
|
188
191
|
|
|
189
192
|
If the option `skipIfNoImportExport` of `transform` is set to `true` and the input source contains neither `import` nor `export` statements, the input source won't be enclosed in the AMD wrapper. The input will be assumed to be in AMD/UMD format already.
|
|
190
193
|
|
package/bin/esm2requirejs.js
CHANGED
|
@@ -17,6 +17,7 @@ program.description('Transforms an ESM module to AMD or adapts an AMD module for
|
|
|
17
17
|
.option('-r, --rewrite', 'rewrite the input files with the adapted output')
|
|
18
18
|
.option('-s, --source-map', 'write inline source maps to the adapted output')
|
|
19
19
|
.option('-a, --skip-if-no-import-export', 'assume AMD/UMD if there\'re no import or export statements')
|
|
20
|
+
.option('-d, --split-default-named-declarations', 'split default named export to declaration and export')
|
|
20
21
|
.option('-v, --verbose', 'print progress and call stack in case of error')
|
|
21
22
|
.argument('[files...]')
|
|
22
23
|
.on('--help', () => {
|
|
@@ -37,6 +38,7 @@ const {
|
|
|
37
38
|
plugin: pluginName,
|
|
38
39
|
sourceMap,
|
|
39
40
|
skipIfNoImportExport,
|
|
41
|
+
splitDefaultNamedDeclarations,
|
|
40
42
|
output: outputFile,
|
|
41
43
|
rewrite,
|
|
42
44
|
verbose
|
|
@@ -60,6 +62,7 @@ if (!args.length) {
|
|
|
60
62
|
pluginName,
|
|
61
63
|
sourceMap,
|
|
62
64
|
skipIfNoImportExport,
|
|
65
|
+
splitDefaultNamedDeclarations,
|
|
63
66
|
verbose
|
|
64
67
|
})
|
|
65
68
|
if (updated) {
|
package/dist/api.js
CHANGED
|
@@ -10541,7 +10541,7 @@
|
|
|
10541
10541
|
var isInstance = false;
|
|
10542
10542
|
try {
|
|
10543
10543
|
isInstance = this instanceof a;
|
|
10544
|
-
} catch {}
|
|
10544
|
+
} catch (e) {}
|
|
10545
10545
|
if (isInstance) {
|
|
10546
10546
|
return Reflect.construct(f, arguments, this.constructor);
|
|
10547
10547
|
}
|
|
@@ -10715,7 +10715,7 @@
|
|
|
10715
10715
|
function requireLib () {
|
|
10716
10716
|
if (hasRequiredLib) return lib;
|
|
10717
10717
|
hasRequiredLib = 1;
|
|
10718
|
-
(function (exports
|
|
10718
|
+
(function (exports) {
|
|
10719
10719
|
|
|
10720
10720
|
function _(message, opts) {
|
|
10721
10721
|
return `${opts && opts.context ? opts.context : "Value"} ${message}.`;
|
|
@@ -10858,31 +10858,31 @@
|
|
|
10858
10858
|
};
|
|
10859
10859
|
}
|
|
10860
10860
|
|
|
10861
|
-
exports
|
|
10861
|
+
exports.any = V => {
|
|
10862
10862
|
return V;
|
|
10863
10863
|
};
|
|
10864
10864
|
|
|
10865
|
-
exports
|
|
10865
|
+
exports.void = function () {
|
|
10866
10866
|
return undefined;
|
|
10867
10867
|
};
|
|
10868
10868
|
|
|
10869
|
-
exports
|
|
10869
|
+
exports.boolean = function (val) {
|
|
10870
10870
|
return !!val;
|
|
10871
10871
|
};
|
|
10872
10872
|
|
|
10873
|
-
exports
|
|
10874
|
-
exports
|
|
10873
|
+
exports.byte = createIntegerConversion(8, { unsigned: false });
|
|
10874
|
+
exports.octet = createIntegerConversion(8, { unsigned: true });
|
|
10875
10875
|
|
|
10876
|
-
exports
|
|
10877
|
-
exports
|
|
10876
|
+
exports.short = createIntegerConversion(16, { unsigned: false });
|
|
10877
|
+
exports["unsigned short"] = createIntegerConversion(16, { unsigned: true });
|
|
10878
10878
|
|
|
10879
|
-
exports
|
|
10880
|
-
exports
|
|
10879
|
+
exports.long = createIntegerConversion(32, { unsigned: false });
|
|
10880
|
+
exports["unsigned long"] = createIntegerConversion(32, { unsigned: true });
|
|
10881
10881
|
|
|
10882
|
-
exports
|
|
10883
|
-
exports
|
|
10882
|
+
exports["long long"] = createIntegerConversion(64, { unsigned: false });
|
|
10883
|
+
exports["unsigned long long"] = createIntegerConversion(64, { unsigned: true });
|
|
10884
10884
|
|
|
10885
|
-
exports
|
|
10885
|
+
exports.double = (V, opts) => {
|
|
10886
10886
|
const x = +V;
|
|
10887
10887
|
|
|
10888
10888
|
if (!Number.isFinite(x)) {
|
|
@@ -10892,13 +10892,13 @@
|
|
|
10892
10892
|
return x;
|
|
10893
10893
|
};
|
|
10894
10894
|
|
|
10895
|
-
exports
|
|
10895
|
+
exports["unrestricted double"] = V => {
|
|
10896
10896
|
const x = +V;
|
|
10897
10897
|
|
|
10898
10898
|
return x;
|
|
10899
10899
|
};
|
|
10900
10900
|
|
|
10901
|
-
exports
|
|
10901
|
+
exports.float = (V, opts) => {
|
|
10902
10902
|
const x = +V;
|
|
10903
10903
|
|
|
10904
10904
|
if (!Number.isFinite(x)) {
|
|
@@ -10918,7 +10918,7 @@
|
|
|
10918
10918
|
return y;
|
|
10919
10919
|
};
|
|
10920
10920
|
|
|
10921
|
-
exports
|
|
10921
|
+
exports["unrestricted float"] = V => {
|
|
10922
10922
|
const x = +V;
|
|
10923
10923
|
|
|
10924
10924
|
if (isNaN(x)) {
|
|
@@ -10932,7 +10932,7 @@
|
|
|
10932
10932
|
return Math.fround(x);
|
|
10933
10933
|
};
|
|
10934
10934
|
|
|
10935
|
-
exports
|
|
10935
|
+
exports.DOMString = function (V, opts) {
|
|
10936
10936
|
if (opts === undefined) {
|
|
10937
10937
|
opts = {};
|
|
10938
10938
|
}
|
|
@@ -10948,8 +10948,8 @@
|
|
|
10948
10948
|
return String(V);
|
|
10949
10949
|
};
|
|
10950
10950
|
|
|
10951
|
-
exports
|
|
10952
|
-
const x = exports
|
|
10951
|
+
exports.ByteString = (V, opts) => {
|
|
10952
|
+
const x = exports.DOMString(V, opts);
|
|
10953
10953
|
let c;
|
|
10954
10954
|
for (let i = 0; (c = x.codePointAt(i)) !== undefined; ++i) {
|
|
10955
10955
|
if (c > 255) {
|
|
@@ -10960,8 +10960,8 @@
|
|
|
10960
10960
|
return x;
|
|
10961
10961
|
};
|
|
10962
10962
|
|
|
10963
|
-
exports
|
|
10964
|
-
const S = exports
|
|
10963
|
+
exports.USVString = (V, opts) => {
|
|
10964
|
+
const S = exports.DOMString(V, opts);
|
|
10965
10965
|
const n = S.length;
|
|
10966
10966
|
const U = [];
|
|
10967
10967
|
for (let i = 0; i < n; ++i) {
|
|
@@ -10988,7 +10988,7 @@
|
|
|
10988
10988
|
return U.join("");
|
|
10989
10989
|
};
|
|
10990
10990
|
|
|
10991
|
-
exports
|
|
10991
|
+
exports.object = (V, opts) => {
|
|
10992
10992
|
if (type(V) !== "Object") {
|
|
10993
10993
|
throw new TypeError(_("is not an object", opts));
|
|
10994
10994
|
}
|
|
@@ -11015,7 +11015,7 @@
|
|
|
11015
11015
|
].forEach(func => {
|
|
11016
11016
|
const name = func.name;
|
|
11017
11017
|
const article = /^[AEIOU]/.test(name) ? "an" : "a";
|
|
11018
|
-
exports
|
|
11018
|
+
exports[name] = (V, opts) => {
|
|
11019
11019
|
if (!(V instanceof func)) {
|
|
11020
11020
|
throw new TypeError(_(`is not ${article} ${name} object`, opts));
|
|
11021
11021
|
}
|
|
@@ -11026,7 +11026,7 @@
|
|
|
11026
11026
|
|
|
11027
11027
|
// Common definitions
|
|
11028
11028
|
|
|
11029
|
-
exports
|
|
11029
|
+
exports.ArrayBufferView = (V, opts) => {
|
|
11030
11030
|
if (!ArrayBuffer.isView(V)) {
|
|
11031
11031
|
throw new TypeError(_("is not a view on an ArrayBuffer object", opts));
|
|
11032
11032
|
}
|
|
@@ -11034,7 +11034,7 @@
|
|
|
11034
11034
|
return V;
|
|
11035
11035
|
};
|
|
11036
11036
|
|
|
11037
|
-
exports
|
|
11037
|
+
exports.BufferSource = (V, opts) => {
|
|
11038
11038
|
if (!(ArrayBuffer.isView(V) || V instanceof ArrayBuffer)) {
|
|
11039
11039
|
throw new TypeError(_("is not an ArrayBuffer object or a view on one", opts));
|
|
11040
11040
|
}
|
|
@@ -11042,11 +11042,11 @@
|
|
|
11042
11042
|
return V;
|
|
11043
11043
|
};
|
|
11044
11044
|
|
|
11045
|
-
exports
|
|
11045
|
+
exports.DOMTimeStamp = exports["unsigned long long"];
|
|
11046
11046
|
|
|
11047
|
-
exports
|
|
11047
|
+
exports.Function = convertCallbackFunction;
|
|
11048
11048
|
|
|
11049
|
-
exports
|
|
11049
|
+
exports.VoidFunction = convertCallbackFunction;
|
|
11050
11050
|
} (lib));
|
|
11051
11051
|
return lib;
|
|
11052
11052
|
}
|
|
@@ -11058,7 +11058,7 @@
|
|
|
11058
11058
|
function requireUtils () {
|
|
11059
11059
|
if (hasRequiredUtils) return utils.exports;
|
|
11060
11060
|
hasRequiredUtils = 1;
|
|
11061
|
-
(function (module, exports
|
|
11061
|
+
(function (module, exports) {
|
|
11062
11062
|
|
|
11063
11063
|
// Returns "Type(value) is Object" in ES terminology.
|
|
11064
11064
|
function isObject(value) {
|
|
@@ -79148,7 +79148,7 @@
|
|
|
79148
79148
|
function requireLodash_sortby () {
|
|
79149
79149
|
if (hasRequiredLodash_sortby) return lodash_sortby.exports;
|
|
79150
79150
|
hasRequiredLodash_sortby = 1;
|
|
79151
|
-
(function (module, exports
|
|
79151
|
+
(function (module, exports) {
|
|
79152
79152
|
/** Used as the size to enable large array optimizations. */
|
|
79153
79153
|
var LARGE_ARRAY_SIZE = 200;
|
|
79154
79154
|
|
|
@@ -79242,7 +79242,7 @@
|
|
|
79242
79242
|
var root = freeGlobal || freeSelf || Function('return this')();
|
|
79243
79243
|
|
|
79244
79244
|
/** Detect free variable `exports`. */
|
|
79245
|
-
var freeExports = exports
|
|
79245
|
+
var freeExports = exports && !exports.nodeType && exports;
|
|
79246
79246
|
|
|
79247
79247
|
/** Detect free variable `module`. */
|
|
79248
79248
|
var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
|
@@ -84031,15 +84031,15 @@
|
|
|
84031
84031
|
function requireBinarySearch () {
|
|
84032
84032
|
if (hasRequiredBinarySearch) return binarySearch;
|
|
84033
84033
|
hasRequiredBinarySearch = 1;
|
|
84034
|
-
(function (exports
|
|
84034
|
+
(function (exports) {
|
|
84035
84035
|
/*
|
|
84036
84036
|
* Copyright 2011 Mozilla Foundation and contributors
|
|
84037
84037
|
* Licensed under the New BSD license. See LICENSE or:
|
|
84038
84038
|
* http://opensource.org/licenses/BSD-3-Clause
|
|
84039
84039
|
*/
|
|
84040
84040
|
|
|
84041
|
-
exports
|
|
84042
|
-
exports
|
|
84041
|
+
exports.GREATEST_LOWER_BOUND = 1;
|
|
84042
|
+
exports.LEAST_UPPER_BOUND = 2;
|
|
84043
84043
|
|
|
84044
84044
|
/**
|
|
84045
84045
|
* Recursive implementation of binary search.
|
|
@@ -84078,7 +84078,7 @@
|
|
|
84078
84078
|
|
|
84079
84079
|
// The exact needle element was not found in this haystack. Determine if
|
|
84080
84080
|
// we are in termination case (3) or (2) and return the appropriate thing.
|
|
84081
|
-
if (aBias == exports
|
|
84081
|
+
if (aBias == exports.LEAST_UPPER_BOUND) {
|
|
84082
84082
|
return aHigh < aHaystack.length ? aHigh : -1;
|
|
84083
84083
|
}
|
|
84084
84084
|
return mid;
|
|
@@ -84091,7 +84091,7 @@
|
|
|
84091
84091
|
}
|
|
84092
84092
|
|
|
84093
84093
|
// we are in termination case (3) or (2) and return the appropriate thing.
|
|
84094
|
-
if (aBias == exports
|
|
84094
|
+
if (aBias == exports.LEAST_UPPER_BOUND) {
|
|
84095
84095
|
return mid;
|
|
84096
84096
|
}
|
|
84097
84097
|
return aLow < 0 ? -1 : aLow;
|
|
@@ -84115,13 +84115,13 @@
|
|
|
84115
84115
|
* searching for, respectively, if the exact element cannot be found.
|
|
84116
84116
|
* Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
|
|
84117
84117
|
*/
|
|
84118
|
-
exports
|
|
84118
|
+
exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
|
|
84119
84119
|
if (aHaystack.length === 0) {
|
|
84120
84120
|
return -1;
|
|
84121
84121
|
}
|
|
84122
84122
|
|
|
84123
84123
|
let index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
|
|
84124
|
-
aCompare, aBias || exports
|
|
84124
|
+
aCompare, aBias || exports.GREATEST_LOWER_BOUND);
|
|
84125
84125
|
if (index < 0) {
|
|
84126
84126
|
return -1;
|
|
84127
84127
|
}
|
|
@@ -86524,7 +86524,7 @@
|
|
|
86524
86524
|
const { length } = body;
|
|
86525
86525
|
|
|
86526
86526
|
const imports = [];
|
|
86527
|
-
const exports
|
|
86527
|
+
const exports = [];
|
|
86528
86528
|
|
|
86529
86529
|
for (let i = 0; i < length; ++i) {
|
|
86530
86530
|
const node = body[i];
|
|
@@ -86552,7 +86552,7 @@
|
|
|
86552
86552
|
|
|
86553
86553
|
// export default
|
|
86554
86554
|
else if (node.type === 'ExportDefaultDeclaration') {
|
|
86555
|
-
exports
|
|
86555
|
+
exports.push({ node, default: true });
|
|
86556
86556
|
}
|
|
86557
86557
|
|
|
86558
86558
|
// export {x as y}
|
|
@@ -86564,29 +86564,29 @@
|
|
|
86564
86564
|
|
|
86565
86565
|
// export var a = 1
|
|
86566
86566
|
if (!specifiers.length) {
|
|
86567
|
-
exports
|
|
86567
|
+
exports.push({ node });
|
|
86568
86568
|
} else { // export {x as y}
|
|
86569
86569
|
// export { ... } from "module"
|
|
86570
86570
|
const { source } = node;
|
|
86571
86571
|
if (source) {
|
|
86572
|
-
exports
|
|
86572
|
+
exports.push({ node, source, import: true });
|
|
86573
86573
|
const specifiers = node.specifiers.map(({ exported: imported, local }) => ({ imported, local }));
|
|
86574
86574
|
imports.push({ node, source, specifiers, export: true });
|
|
86575
86575
|
} else {
|
|
86576
|
-
exports
|
|
86576
|
+
exports.push({ node });
|
|
86577
86577
|
}
|
|
86578
86578
|
}
|
|
86579
86579
|
}
|
|
86580
86580
|
|
|
86581
86581
|
// export * from "module"
|
|
86582
86582
|
if (node.type === 'ExportAllDeclaration') {
|
|
86583
|
-
exports
|
|
86583
|
+
exports.push({ node, import: true });
|
|
86584
86584
|
const { source } = node;
|
|
86585
86585
|
imports.push({ node, source, export: true });
|
|
86586
86586
|
}
|
|
86587
86587
|
}
|
|
86588
86588
|
|
|
86589
|
-
return { imports, exports
|
|
86589
|
+
return { imports, exports }
|
|
86590
86590
|
}
|
|
86591
86591
|
|
|
86592
86592
|
// Transforms the module format from ESM to AMD.
|
|
@@ -86596,6 +86596,7 @@
|
|
|
86596
86596
|
program
|
|
86597
86597
|
});
|
|
86598
86598
|
|
|
86599
|
+
const { splitDefaultNamedDeclarations } = options;
|
|
86599
86600
|
const { body } = program;
|
|
86600
86601
|
let { length } = body;
|
|
86601
86602
|
|
|
@@ -86657,46 +86658,52 @@
|
|
|
86657
86658
|
|
|
86658
86659
|
// expression after keyword default
|
|
86659
86660
|
const { declaration } = statement;
|
|
86661
|
+
// export default X
|
|
86660
86662
|
let exportValue = declaration;
|
|
86661
|
-
|
|
86662
|
-
|
|
86663
|
-
|
|
86664
|
-
|
|
86665
|
-
|
|
86666
|
-
|
|
86667
|
-
|
|
86668
|
-
|
|
86669
|
-
|
|
86670
|
-
|
|
86671
|
-
|
|
86672
|
-
|
|
86673
|
-
|
|
86674
|
-
|
|
86675
|
-
|
|
86676
|
-
// needReturnExport = false
|
|
86677
|
-
// } else {
|
|
86678
|
-
// exportStat = exportStatement(exportsVar, 'default', className)
|
|
86679
|
-
// }
|
|
86680
|
-
|
|
86681
|
-
// program.pushContainer('body', [exportStat])
|
|
86682
|
-
// needExportExpression = false
|
|
86683
|
-
// } else {
|
|
86684
|
-
// exportValue = toExpression(classNode)
|
|
86685
|
-
// }
|
|
86663
|
+
let keepDeclaration;
|
|
86664
|
+
|
|
86665
|
+
if (declaration.type === 'FunctionDeclaration' ||
|
|
86666
|
+
declaration.type === 'ClassDeclaration') {
|
|
86667
|
+
const { id } = declaration;
|
|
86668
|
+
if (id && splitDefaultNamedDeclarations) {
|
|
86669
|
+
// export default function X() {}
|
|
86670
|
+
// export default class X {}
|
|
86671
|
+
exportValue = identifier(declaration.id.name);
|
|
86672
|
+
keepDeclaration = true;
|
|
86673
|
+
} else {
|
|
86674
|
+
// export default function () {}
|
|
86675
|
+
// export default class {}
|
|
86676
|
+
exportValue = toExpression(declaration);
|
|
86677
|
+
}
|
|
86686
86678
|
}
|
|
86687
86679
|
|
|
86688
|
-
|
|
86689
|
-
let exportStat;
|
|
86680
|
+
let exportStat;
|
|
86690
86681
|
|
|
86691
|
-
|
|
86692
|
-
|
|
86693
|
-
|
|
86694
|
-
|
|
86695
|
-
|
|
86696
|
-
|
|
86682
|
+
if (i + 1 === length && isOnlyDefaultExport) {
|
|
86683
|
+
exportStat = returnStatement(exportValue);
|
|
86684
|
+
needReturnExport = false;
|
|
86685
|
+
} else {
|
|
86686
|
+
exportStat = exportStatement(exportsVar, 'default', exportValue);
|
|
86687
|
+
}
|
|
86697
86688
|
|
|
86698
|
-
|
|
86689
|
+
// This changes the original code by putting the name of the exported
|
|
86690
|
+
// function or class to the module scope. Being able to access the class
|
|
86691
|
+
// by name simplifies other AST manipulations, which would have to be more
|
|
86692
|
+
// complicated. Or the developer would have to help the manipulator
|
|
86693
|
+
// by separating the export expression to a declaration and an export
|
|
86694
|
+
// of an identifier. Use it if it doesn't break your code.
|
|
86695
|
+
//
|
|
86696
|
+
// // original, the name X is not in the module scope
|
|
86697
|
+
// export default class X {}
|
|
86698
|
+
//
|
|
86699
|
+
// // converted, the name X is in the module scope
|
|
86700
|
+
// class X {}
|
|
86701
|
+
// export default X
|
|
86702
|
+
if (keepDeclaration) {
|
|
86703
|
+
body.splice(i++, 0, declaration);
|
|
86704
|
+
++length;
|
|
86699
86705
|
}
|
|
86706
|
+
body[i] = exportStat;
|
|
86700
86707
|
}
|
|
86701
86708
|
|
|
86702
86709
|
// export {x as y}
|
|
@@ -87004,6 +87011,9 @@
|
|
|
87004
87011
|
// Do not insert `"use strict"` expression to the AMD modules. You'd set it
|
|
87005
87012
|
// to `false` if your bundler inserts `"use strict"` to the outer scope.
|
|
87006
87013
|
useStrict,
|
|
87014
|
+
// Split `export default class A {}` to `class A {}; export default A`
|
|
87015
|
+
// to trade easier AST manipulation for 100% code compatibility.
|
|
87016
|
+
splitDefaultNamedDeclarations,
|
|
87007
87017
|
// Enable source maps, can be an object with booleans { inline, content }.
|
|
87008
87018
|
// If set to true, the object will be set to { inline: true, content: true }.
|
|
87009
87019
|
sourceMap,
|
|
@@ -87031,6 +87041,7 @@
|
|
|
87031
87041
|
originalResolvePath: resolvePath,
|
|
87032
87042
|
useStrict,
|
|
87033
87043
|
skipIfNoImportExport,
|
|
87044
|
+
splitDefaultNamedDeclarations,
|
|
87034
87045
|
onBeforeTransform,
|
|
87035
87046
|
onAfterTransform,
|
|
87036
87047
|
onBeforeUpdate,
|