requirejs-esm 4.2.0 → 4.3.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 +11 -1
- package/bin/esm2requirejs.js +7 -4
- package/dist/api.js +121 -46
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +127 -50
- package/dist/plugin.js.map +1 -1
- package/package.json +9 -11
- package/src/api.d.ts +2 -0
- package/src/api.js +6 -1
- package/src/fetch-text.js +1 -1
- package/src/plugin.js +4 -1
- package/src/resolve-path.js +1 -1
- package/src/transform.js +12 -2
- package/src/transformer/comments.js +16 -0
- package/src/transformer/converters.js +2 -4
- package/src/transformer/esm.js +16 -2
- package/src/transformer/index.js +3 -3
- package/src/write-text.js +2 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -123,6 +123,8 @@ The `esm` plugin supports configuration with the following defaults:
|
|
|
123
123
|
mixedAmdAndEsm: false,
|
|
124
124
|
// Suppress transpiling even if an optimized module has not been loaded yet.
|
|
125
125
|
onlyAmd: false,
|
|
126
|
+
// Assume AMD/UMD if there're no import or export statements.
|
|
127
|
+
skipIfNoImportExport: false,
|
|
126
128
|
// Do not insert `"use strict"` expression to the AMD modules. You'd set it
|
|
127
129
|
// to `false` if your bundler inserts `"use strict"` to the outer scope.
|
|
128
130
|
useStrict: true,
|
|
@@ -182,13 +184,21 @@ The returned object:
|
|
|
182
184
|
}
|
|
183
185
|
```
|
|
184
186
|
|
|
187
|
+
## Skipping ann Forcing Transformation
|
|
188
|
+
|
|
189
|
+
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
|
+
|
|
191
|
+
If the input source contains a line "// requirejs-esm-skip-file" among the first 10 lines shorter than 100 characters, the input file will not be transformed.
|
|
192
|
+
|
|
193
|
+
If the input source contains a line "// requirejs-esm-process-file" among the first 10 lines shorter than 100 characters and the `transform` option `skipIfNoImportExport` is set to `true`, the input will be transformed nevertheless. The comment has a higher priority than the option.
|
|
194
|
+
|
|
185
195
|
## Contributing
|
|
186
196
|
|
|
187
197
|
In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.
|
|
188
198
|
|
|
189
199
|
## License
|
|
190
200
|
|
|
191
|
-
Copyright (c) 2022-
|
|
201
|
+
Copyright (c) 2022-2026 Ferdinand Prantl
|
|
192
202
|
|
|
193
203
|
Licensed under the MIT license.
|
|
194
204
|
|
package/bin/esm2requirejs.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Require module dependencies.
|
|
4
4
|
const { Command } = require('commander')
|
|
5
5
|
const glob = require('tiny-glob')
|
|
6
|
-
const { readFile, writeFile } = require('fs/promises')
|
|
6
|
+
const { readFile, writeFile } = require('node:fs/promises')
|
|
7
7
|
const { transform } = require('../dist/api')
|
|
8
8
|
|
|
9
9
|
// Define the command-line interface.
|
|
@@ -16,9 +16,10 @@ program.description('Transforms an ESM module to AMD or adapts an AMD module for
|
|
|
16
16
|
.option('-o, --output <file>', 'write the adapted module source to a file')
|
|
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
|
+
.option('-a, --skip-if-no-import-export', 'assume AMD/UMD if there\'re no import or export statements')
|
|
19
20
|
.option('-v, --verbose', 'print progress and call stack in case of error')
|
|
20
21
|
.argument('[files...]')
|
|
21
|
-
.on('--help',
|
|
22
|
+
.on('--help', () => {
|
|
22
23
|
console.log()
|
|
23
24
|
console.log('You can use one or more file names or one or more glob patterns to specify one')
|
|
24
25
|
console.log('or more files. If you set the plugin name to an empty string, modules already')
|
|
@@ -35,6 +36,7 @@ const {
|
|
|
35
36
|
/*ecma: ecmaVersion,*/
|
|
36
37
|
plugin: pluginName,
|
|
37
38
|
sourceMap,
|
|
39
|
+
skipIfNoImportExport,
|
|
38
40
|
output: outputFile,
|
|
39
41
|
rewrite,
|
|
40
42
|
verbose
|
|
@@ -45,7 +47,7 @@ if (!args.length) {
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
// Main entry point.
|
|
48
|
-
(async
|
|
50
|
+
((async () => {
|
|
49
51
|
try {
|
|
50
52
|
const files = (await Promise.all(args.map(arg => glob(arg)))).flat()
|
|
51
53
|
if (!files.length) {
|
|
@@ -57,6 +59,7 @@ if (!args.length) {
|
|
|
57
59
|
/*ecmaVersion,*/
|
|
58
60
|
pluginName,
|
|
59
61
|
sourceMap,
|
|
62
|
+
skipIfNoImportExport,
|
|
60
63
|
verbose
|
|
61
64
|
})
|
|
62
65
|
if (updated) {
|
|
@@ -75,4 +78,4 @@ if (!args.length) {
|
|
|
75
78
|
console.error((!verbose && error.message) || error)
|
|
76
79
|
process.exitCode = 1
|
|
77
80
|
}
|
|
78
|
-
}())
|
|
81
|
+
})())
|
package/dist/api.js
CHANGED
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
// mapped there using the `paths` of `map` configuration properties.
|
|
70
70
|
if ((sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
|
|
71
71
|
sourcePath.charAt(1) === '.' && sourcePath.charAt(2) === '/')) &&
|
|
72
|
-
!(needsResolve
|
|
72
|
+
!(needsResolve?.(sourcePath, currentFile))) {
|
|
73
73
|
sourcePath = joinPath(parentDir(currentFile), sourcePath);
|
|
74
74
|
if (sourcePath.endsWith('.js')) sourcePath = sourcePath.substring(0, sourcePath.length - 3);
|
|
75
75
|
}
|
|
@@ -2080,7 +2080,7 @@
|
|
|
2080
2080
|
advanceChar(parser);
|
|
2081
2081
|
if (parser.currentChar === 61) {
|
|
2082
2082
|
advanceChar(parser);
|
|
2083
|
-
return
|
|
2083
|
+
return 4718632;
|
|
2084
2084
|
}
|
|
2085
2085
|
return 8913465;
|
|
2086
2086
|
}
|
|
@@ -2123,7 +2123,7 @@
|
|
|
2123
2123
|
advanceChar(parser);
|
|
2124
2124
|
if (parser.currentChar === 61) {
|
|
2125
2125
|
advanceChar(parser);
|
|
2126
|
-
return
|
|
2126
|
+
return 4718633;
|
|
2127
2127
|
}
|
|
2128
2128
|
return 8913720;
|
|
2129
2129
|
}
|
|
@@ -2139,7 +2139,7 @@
|
|
|
2139
2139
|
advanceChar(parser);
|
|
2140
2140
|
if (parser.currentChar === 61) {
|
|
2141
2141
|
advanceChar(parser);
|
|
2142
|
-
return
|
|
2142
|
+
return 4718634;
|
|
2143
2143
|
}
|
|
2144
2144
|
return 276824445;
|
|
2145
2145
|
}
|
|
@@ -4805,7 +4805,7 @@
|
|
|
4805
4805
|
currentChar = 0;
|
|
4806
4806
|
exportedNames = new Set();
|
|
4807
4807
|
exportedBindings = new Set();
|
|
4808
|
-
assignable =
|
|
4808
|
+
assignable = 0;
|
|
4809
4809
|
destructible = 0;
|
|
4810
4810
|
leadingDecorators = { decorators: [] };
|
|
4811
4811
|
constructor(source, rawOptions = {}) {
|
|
@@ -6094,6 +6094,8 @@
|
|
|
6094
6094
|
if ((token & 4194304) === 4194304) {
|
|
6095
6095
|
if (parser.assignable & 2)
|
|
6096
6096
|
parser.report(26);
|
|
6097
|
+
if ((token & 524288) === 524288 && parser.assignable & 4)
|
|
6098
|
+
parser.report(26);
|
|
6097
6099
|
if ((!isPattern && token === 1077936155 && left.type === 'ArrayExpression') ||
|
|
6098
6100
|
left.type === 'ObjectExpression') {
|
|
6099
6101
|
reinterpretToPattern(parser, left);
|
|
@@ -6459,7 +6461,12 @@
|
|
|
6459
6461
|
parser.flags = (parser.flags | 2048) ^ 2048;
|
|
6460
6462
|
}
|
|
6461
6463
|
const args = parseArguments(parser, context, privateScope, inGroup);
|
|
6462
|
-
parser.
|
|
6464
|
+
if (!(context & 1) && parser.options.webcompat) {
|
|
6465
|
+
parser.assignable = 4;
|
|
6466
|
+
}
|
|
6467
|
+
else {
|
|
6468
|
+
parser.assignable = 2;
|
|
6469
|
+
}
|
|
6463
6470
|
expr = parser.finishNode({
|
|
6464
6471
|
type: 'CallExpression',
|
|
6465
6472
|
callee: expr,
|
|
@@ -6527,7 +6534,12 @@
|
|
|
6527
6534
|
}
|
|
6528
6535
|
else if (parser.getToken() === 67174411) {
|
|
6529
6536
|
const args = parseArguments(parser, context, privateScope, 0);
|
|
6530
|
-
parser.
|
|
6537
|
+
if (!(context & 1) && parser.options.webcompat) {
|
|
6538
|
+
parser.assignable = 4;
|
|
6539
|
+
}
|
|
6540
|
+
else {
|
|
6541
|
+
parser.assignable = 2;
|
|
6542
|
+
}
|
|
6531
6543
|
node = parser.finishNode({
|
|
6532
6544
|
type: 'CallExpression',
|
|
6533
6545
|
callee: expr,
|
|
@@ -7132,9 +7144,9 @@
|
|
|
7132
7144
|
}
|
|
7133
7145
|
else if (parser.getToken() !== 1077936155) {
|
|
7134
7146
|
destructible |=
|
|
7135
|
-
parser.assignable &
|
|
7136
|
-
?
|
|
7137
|
-
:
|
|
7147
|
+
parser.assignable & 1
|
|
7148
|
+
? 32
|
|
7149
|
+
: 16;
|
|
7138
7150
|
}
|
|
7139
7151
|
}
|
|
7140
7152
|
}
|
|
@@ -7164,9 +7176,9 @@
|
|
|
7164
7176
|
}
|
|
7165
7177
|
else if (parser.getToken() !== 1077936155) {
|
|
7166
7178
|
destructible |=
|
|
7167
|
-
parser.assignable &
|
|
7168
|
-
?
|
|
7169
|
-
:
|
|
7179
|
+
parser.assignable & 1
|
|
7180
|
+
? 32
|
|
7181
|
+
: 16;
|
|
7170
7182
|
}
|
|
7171
7183
|
}
|
|
7172
7184
|
}
|
|
@@ -7283,7 +7295,7 @@
|
|
|
7283
7295
|
if (parser.destructible & 8)
|
|
7284
7296
|
parser.report(71);
|
|
7285
7297
|
argument = parseMemberOrUpdateExpression(parser, context, privateScope, argument, inGroup, 0, tokenStart);
|
|
7286
|
-
destructible |= parser.assignable &
|
|
7298
|
+
destructible |= parser.assignable & 1 ? 0 : 16;
|
|
7287
7299
|
if ((parser.getToken() & 4194304) === 4194304) {
|
|
7288
7300
|
if (parser.getToken() !== 1077936155)
|
|
7289
7301
|
destructible |= 16;
|
|
@@ -7297,9 +7309,9 @@
|
|
|
7297
7309
|
argument = parseConditionalExpression(parser, context, privateScope, argument, tokenStart);
|
|
7298
7310
|
}
|
|
7299
7311
|
destructible |=
|
|
7300
|
-
parser.assignable &
|
|
7301
|
-
?
|
|
7302
|
-
:
|
|
7312
|
+
parser.assignable & 1
|
|
7313
|
+
? 32
|
|
7314
|
+
: 16;
|
|
7303
7315
|
}
|
|
7304
7316
|
}
|
|
7305
7317
|
else {
|
|
@@ -7328,7 +7340,9 @@
|
|
|
7328
7340
|
argument = parseAssignmentExpression(parser, context, privateScope, inGroup, isPattern, tokenStart, argument);
|
|
7329
7341
|
}
|
|
7330
7342
|
destructible |=
|
|
7331
|
-
parser.assignable & 1
|
|
7343
|
+
parser.assignable & 1
|
|
7344
|
+
? 32
|
|
7345
|
+
: 16;
|
|
7332
7346
|
}
|
|
7333
7347
|
parser.destructible = destructible;
|
|
7334
7348
|
if (parser.getToken() !== closingToken && parser.getToken() !== 18)
|
|
@@ -7520,7 +7534,9 @@
|
|
|
7520
7534
|
: parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
|
|
7521
7535
|
destructible = parser.destructible;
|
|
7522
7536
|
parser.assignable =
|
|
7523
|
-
destructible & 16
|
|
7537
|
+
destructible & 16
|
|
7538
|
+
? 2
|
|
7539
|
+
: 1;
|
|
7524
7540
|
if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
|
|
7525
7541
|
if (parser.assignable & 2)
|
|
7526
7542
|
destructible |= 16;
|
|
@@ -7542,9 +7558,9 @@
|
|
|
7542
7558
|
value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
|
|
7543
7559
|
}
|
|
7544
7560
|
destructible |=
|
|
7545
|
-
parser.assignable &
|
|
7546
|
-
?
|
|
7547
|
-
:
|
|
7561
|
+
parser.assignable & 1
|
|
7562
|
+
? 32
|
|
7563
|
+
: 16;
|
|
7548
7564
|
}
|
|
7549
7565
|
}
|
|
7550
7566
|
}
|
|
@@ -7701,7 +7717,9 @@
|
|
|
7701
7717
|
: parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
|
|
7702
7718
|
destructible = parser.destructible;
|
|
7703
7719
|
parser.assignable =
|
|
7704
|
-
destructible & 16
|
|
7720
|
+
destructible & 16
|
|
7721
|
+
? 2
|
|
7722
|
+
: 1;
|
|
7705
7723
|
if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
|
|
7706
7724
|
if (parser.assignable & 2) {
|
|
7707
7725
|
destructible |= 16;
|
|
@@ -7721,9 +7739,9 @@
|
|
|
7721
7739
|
value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
|
|
7722
7740
|
}
|
|
7723
7741
|
destructible |=
|
|
7724
|
-
parser.assignable &
|
|
7725
|
-
?
|
|
7726
|
-
:
|
|
7742
|
+
parser.assignable & 1
|
|
7743
|
+
? 32
|
|
7744
|
+
: 16;
|
|
7727
7745
|
}
|
|
7728
7746
|
}
|
|
7729
7747
|
}
|
|
@@ -7752,7 +7770,7 @@
|
|
|
7752
7770
|
else if (parser.getToken() === 67174411) {
|
|
7753
7771
|
state |= 1;
|
|
7754
7772
|
value = parseMethodDefinition(parser, context, privateScope, state, inGroup, parser.tokenStart);
|
|
7755
|
-
destructible =
|
|
7773
|
+
destructible = 16;
|
|
7756
7774
|
}
|
|
7757
7775
|
else {
|
|
7758
7776
|
parser.report(134);
|
|
@@ -7772,11 +7790,11 @@
|
|
|
7772
7790
|
value = parseMemberOrUpdateExpression(parser, context, privateScope, value, inGroup, 0, tokenStart);
|
|
7773
7791
|
if ((parser.getToken() & 4194304) === 4194304) {
|
|
7774
7792
|
destructible |=
|
|
7775
|
-
parser.assignable &
|
|
7776
|
-
?
|
|
7777
|
-
: token === 1077936155
|
|
7793
|
+
parser.assignable & 1
|
|
7794
|
+
? token === 1077936155
|
|
7778
7795
|
? 0
|
|
7779
|
-
: 32
|
|
7796
|
+
: 32
|
|
7797
|
+
: 16;
|
|
7780
7798
|
value = parseAssignmentExpressionOrPattern(parser, context, privateScope, inGroup, isPattern, tokenStart, value);
|
|
7781
7799
|
}
|
|
7782
7800
|
else if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
|
|
@@ -7807,7 +7825,9 @@
|
|
|
7807
7825
|
: parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
|
|
7808
7826
|
destructible = parser.destructible;
|
|
7809
7827
|
parser.assignable =
|
|
7810
|
-
destructible & 16
|
|
7828
|
+
destructible & 16
|
|
7829
|
+
? 2
|
|
7830
|
+
: 1;
|
|
7811
7831
|
if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
|
|
7812
7832
|
if (parser.assignable & 2)
|
|
7813
7833
|
destructible |= 16;
|
|
@@ -7832,9 +7852,9 @@
|
|
|
7832
7852
|
value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
|
|
7833
7853
|
}
|
|
7834
7854
|
destructible |=
|
|
7835
|
-
parser.assignable &
|
|
7836
|
-
?
|
|
7837
|
-
:
|
|
7855
|
+
parser.assignable & 1
|
|
7856
|
+
? 32
|
|
7857
|
+
: 16;
|
|
7838
7858
|
}
|
|
7839
7859
|
}
|
|
7840
7860
|
}
|
|
@@ -8439,6 +8459,12 @@
|
|
|
8439
8459
|
parser.report(48);
|
|
8440
8460
|
return parseParenthesizedArrow(parser, context, scope, privateScope, [], canAssign, 1, start);
|
|
8441
8461
|
}
|
|
8462
|
+
if (!(context & 1) && parser.options.webcompat) {
|
|
8463
|
+
parser.assignable = 4;
|
|
8464
|
+
}
|
|
8465
|
+
else {
|
|
8466
|
+
parser.assignable = 2;
|
|
8467
|
+
}
|
|
8442
8468
|
return parser.finishNode({
|
|
8443
8469
|
type: 'CallExpression',
|
|
8444
8470
|
callee,
|
|
@@ -8512,7 +8538,7 @@
|
|
|
8512
8538
|
}
|
|
8513
8539
|
else {
|
|
8514
8540
|
expr = parseExpression(parser, context, privateScope, 1, 0, tokenStart);
|
|
8515
|
-
destructible =
|
|
8541
|
+
destructible = 0;
|
|
8516
8542
|
params.push(expr);
|
|
8517
8543
|
while (consumeOpt(parser, context | 32, 18)) {
|
|
8518
8544
|
params.push(parseExpression(parser, context, privateScope, 1, 0, tokenStart));
|
|
@@ -8520,7 +8546,12 @@
|
|
|
8520
8546
|
destructible |= parser.assignable;
|
|
8521
8547
|
consume(parser, context, 16);
|
|
8522
8548
|
parser.destructible = destructible | 16;
|
|
8523
|
-
parser.
|
|
8549
|
+
if (!(context & 1) && parser.options.webcompat) {
|
|
8550
|
+
parser.assignable = 4;
|
|
8551
|
+
}
|
|
8552
|
+
else {
|
|
8553
|
+
parser.assignable = 2;
|
|
8554
|
+
}
|
|
8524
8555
|
return parser.finishNode({
|
|
8525
8556
|
type: 'CallExpression',
|
|
8526
8557
|
callee,
|
|
@@ -8558,7 +8589,12 @@
|
|
|
8558
8589
|
if (destructible & 8) {
|
|
8559
8590
|
parser.report(62);
|
|
8560
8591
|
}
|
|
8561
|
-
parser.
|
|
8592
|
+
if (!(context & 1) && parser.options.webcompat) {
|
|
8593
|
+
parser.assignable = 4;
|
|
8594
|
+
}
|
|
8595
|
+
else {
|
|
8596
|
+
parser.assignable = 2;
|
|
8597
|
+
}
|
|
8562
8598
|
return parser.finishNode({
|
|
8563
8599
|
type: 'CallExpression',
|
|
8564
8600
|
callee,
|
|
@@ -86090,7 +86126,7 @@
|
|
|
86090
86126
|
}
|
|
86091
86127
|
|
|
86092
86128
|
function toIdentifier(input) {
|
|
86093
|
-
input = input
|
|
86129
|
+
input = `${input}`;
|
|
86094
86130
|
|
|
86095
86131
|
let name = '';
|
|
86096
86132
|
for (const c of input) {
|
|
@@ -86099,9 +86135,7 @@
|
|
|
86099
86135
|
|
|
86100
86136
|
name = name.replace(/^[-0-9]+/, '');
|
|
86101
86137
|
|
|
86102
|
-
name = name.replace(/[-\s]+(.)?/g,
|
|
86103
|
-
return c ? c.toUpperCase() : ''
|
|
86104
|
-
});
|
|
86138
|
+
name = name.replace(/[-\s]+(.)?/g, (_match, c) => c ? c.toUpperCase() : '');
|
|
86105
86139
|
|
|
86106
86140
|
if (!isValidIdentifier(name)) {
|
|
86107
86141
|
name = `_${name}`;
|
|
@@ -86718,7 +86752,7 @@
|
|
|
86718
86752
|
const importVar = generateUidIdentifier(exportSource.value, program);
|
|
86719
86753
|
importVars.push(importVar);
|
|
86720
86754
|
|
|
86721
|
-
for (
|
|
86755
|
+
for (const specifier of specifiers) {
|
|
86722
86756
|
const { exported, local } = specifier;
|
|
86723
86757
|
const { name } = local;
|
|
86724
86758
|
let localName;
|
|
@@ -86792,6 +86826,17 @@
|
|
|
86792
86826
|
}
|
|
86793
86827
|
}
|
|
86794
86828
|
|
|
86829
|
+
// no imports and exports, do not wrap to AMD module, if AMD/UMD should be assumed
|
|
86830
|
+
if (options.skipIfNoImportExport && !(importPaths.length || hasExport)) {
|
|
86831
|
+
options.onAfterTransform?.({
|
|
86832
|
+
...options,
|
|
86833
|
+
updated: false,
|
|
86834
|
+
program,
|
|
86835
|
+
callbackBody: body
|
|
86836
|
+
});
|
|
86837
|
+
return false
|
|
86838
|
+
}
|
|
86839
|
+
|
|
86795
86840
|
// adding define wrapper
|
|
86796
86841
|
if (hasExport && needReturnExport) {
|
|
86797
86842
|
let returnStat;
|
|
@@ -86824,10 +86869,13 @@
|
|
|
86824
86869
|
|
|
86825
86870
|
options.onAfterTransform?.({
|
|
86826
86871
|
...options,
|
|
86872
|
+
updated: true,
|
|
86827
86873
|
program,
|
|
86828
86874
|
callbackBody: body
|
|
86829
86875
|
});
|
|
86830
86876
|
|
|
86877
|
+
return true
|
|
86878
|
+
|
|
86831
86879
|
function addExportStatement({ exported, local }) {
|
|
86832
86880
|
const asName = exported.name;
|
|
86833
86881
|
if (asName !== 'default') {
|
|
@@ -86909,6 +86957,23 @@
|
|
|
86909
86957
|
return arrayExpression(importPaths)
|
|
86910
86958
|
}
|
|
86911
86959
|
|
|
86960
|
+
// Check if one of the first 10 lines shorter than 100 characters contains
|
|
86961
|
+
// "// requirejs-esm-skip-file" or // requirejs-esm-process-file".
|
|
86962
|
+
function processOrSkipByComment(text) {
|
|
86963
|
+
for (let start = 0, i = 0; i < 10; ++i) {
|
|
86964
|
+
const endLine = text.indexOf('\n', start);
|
|
86965
|
+
if (endLine < 0 || endLine > 100) break
|
|
86966
|
+
const line = text.substring(start, endLine);
|
|
86967
|
+
const comment = /^\s*\/\//.test(line);
|
|
86968
|
+
if (!comment) break
|
|
86969
|
+
const directive = /^\s*\/\/\s*requirejs-esm-(skip|process)-file\s*$/.exec(line);
|
|
86970
|
+
if (directive) {
|
|
86971
|
+
return directive[1] === 'process'
|
|
86972
|
+
}
|
|
86973
|
+
start = endLine + 1;
|
|
86974
|
+
}
|
|
86975
|
+
}
|
|
86976
|
+
|
|
86912
86977
|
function transformAst(program, options = {}) {
|
|
86913
86978
|
const amds = detectDefinesOrRequires(program);
|
|
86914
86979
|
const { length } = amds;
|
|
@@ -86922,8 +86987,7 @@
|
|
|
86922
86987
|
result.updated ||= updated;
|
|
86923
86988
|
}
|
|
86924
86989
|
} else {
|
|
86925
|
-
transformEsmToAmd(program, options);
|
|
86926
|
-
result.updated = true;
|
|
86990
|
+
result.updated = transformEsmToAmd(program, options);
|
|
86927
86991
|
}
|
|
86928
86992
|
return result
|
|
86929
86993
|
}
|
|
@@ -86934,6 +86998,8 @@
|
|
|
86934
86998
|
// Method to update paths of module dependencies, to prefix JavaScript module
|
|
86935
86999
|
// name with `esm!`, above all.
|
|
86936
87000
|
resolvePath: resolvePath$1 = resolvePath,
|
|
87001
|
+
// Assume AMD/UMD if there're no import or export statements.
|
|
87002
|
+
skipIfNoImportExport,
|
|
86937
87003
|
// ecmaVersion = 2020,
|
|
86938
87004
|
// Do not insert `"use strict"` expression to the AMD modules. You'd set it
|
|
86939
87005
|
// to `false` if your bundler inserts `"use strict"` to the outer scope.
|
|
@@ -86948,8 +87014,15 @@
|
|
|
86948
87014
|
onBeforeUpdate,
|
|
86949
87015
|
onAfterUpdate
|
|
86950
87016
|
} = {}) {
|
|
87017
|
+
const processOrSkip = processOrSkipByComment(text);
|
|
87018
|
+
if (processOrSkip === false) {
|
|
87019
|
+
return { code: text, map: null, updated: false }
|
|
87020
|
+
} else if (processOrSkip === true) {
|
|
87021
|
+
skipIfNoImportExport = undefined;
|
|
87022
|
+
}
|
|
87023
|
+
|
|
86951
87024
|
// const ast = parse(text, { ecmaVersion, sourceType: 'module', locations: true })
|
|
86952
|
-
|
|
87025
|
+
const ast = parseModule(text, { next: true, loc: true });
|
|
86953
87026
|
|
|
86954
87027
|
const options = {
|
|
86955
87028
|
sourceFileName: file,
|
|
@@ -86957,6 +87030,7 @@
|
|
|
86957
87030
|
resolvePath: resolvePath$1,
|
|
86958
87031
|
originalResolvePath: resolvePath,
|
|
86959
87032
|
useStrict,
|
|
87033
|
+
skipIfNoImportExport,
|
|
86960
87034
|
onBeforeTransform,
|
|
86961
87035
|
onAfterTransform,
|
|
86962
87036
|
onBeforeUpdate,
|
|
@@ -86990,6 +87064,7 @@
|
|
|
86990
87064
|
|
|
86991
87065
|
exports.detectDefinesOrRequires = detectDefinesOrRequires;
|
|
86992
87066
|
exports.detectImportsAndExports = detectImportsAndExports;
|
|
87067
|
+
exports.processOrSkipByComment = processOrSkipByComment;
|
|
86993
87068
|
exports.resolvePath = resolvePath;
|
|
86994
87069
|
exports.transform = transform;
|
|
86995
87070
|
exports.transformAst = transformAst;
|