@rollup/wasm-node 4.22.5 → 4.24.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/dist/bin/rollup +2 -2
- package/dist/es/getLogFilter.js +2 -2
- package/dist/es/parseAst.js +2 -2
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/node-entry.js +884 -104
- package/dist/es/shared/parseAst.js +152 -7
- package/dist/es/shared/watch.js +2 -2
- package/dist/getLogFilter.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/parseAst.js +2 -2
- package/dist/rollup.d.ts +41 -2
- package/dist/rollup.js +2 -2
- package/dist/shared/fsevents-importer.js +2 -2
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/parseAst.js +154 -6
- package/dist/shared/rollup.js +883 -103
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/dist/wasm-node/bindings_wasm.js +3 -2
- package/dist/wasm-node/bindings_wasm_bg.wasm +0 -0
- package/package.json +3 -1
package/dist/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v4.
|
|
4
|
-
|
|
3
|
+
Rollup.js v4.24.0
|
|
4
|
+
Wed, 02 Oct 2024 09:36:48 GMT - commit d3c000f4fd453e39a354299f0cfaa6831f56d7d8
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -31,7 +31,7 @@ function _interopNamespaceDefault(e) {
|
|
|
31
31
|
|
|
32
32
|
const tty__namespace = /*#__PURE__*/_interopNamespaceDefault(tty);
|
|
33
33
|
|
|
34
|
-
var version = "4.
|
|
34
|
+
var version = "4.24.0";
|
|
35
35
|
|
|
36
36
|
function ensureArray$1(items) {
|
|
37
37
|
if (Array.isArray(items)) {
|
|
@@ -207,10 +207,25 @@ function makeUnique(name, { [lowercaseBundleKeys]: reservedLowercaseBundleKeys }
|
|
|
207
207
|
return uniqueName;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
function generateAssetFileName(name, source, originalFileName, sourceHash, outputOptions, bundle) {
|
|
210
|
+
function generateAssetFileName(name, names, source, originalFileName, originalFileNames, sourceHash, outputOptions, bundle, inputOptions) {
|
|
211
211
|
const emittedName = outputOptions.sanitizeFileName(name || 'asset');
|
|
212
212
|
return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
|
|
213
|
-
? outputOptions.assetFileNames({
|
|
213
|
+
? outputOptions.assetFileNames({
|
|
214
|
+
// Additionally, this should be non-enumerable in the next major
|
|
215
|
+
get name() {
|
|
216
|
+
parseAst_js.warnDeprecation('Accessing the "name" property of emitted assets when generating the file name is deprecated. Use the "names" property instead.', parseAst_js.URL_GENERATEBUNDLE, false, inputOptions);
|
|
217
|
+
return name;
|
|
218
|
+
},
|
|
219
|
+
names,
|
|
220
|
+
// Additionally, this should be non-enumerable in the next major
|
|
221
|
+
get originalFileName() {
|
|
222
|
+
parseAst_js.warnDeprecation('Accessing the "originalFileName" property of emitted assets when generating the file name is deprecated. Use the "originalFileNames" property instead.', parseAst_js.URL_GENERATEBUNDLE, false, inputOptions);
|
|
223
|
+
return originalFileName;
|
|
224
|
+
},
|
|
225
|
+
originalFileNames,
|
|
226
|
+
source,
|
|
227
|
+
type: 'asset'
|
|
228
|
+
})
|
|
214
229
|
: outputOptions.assetFileNames, 'output.assetFileNames', {
|
|
215
230
|
ext: () => path.extname(emittedName).slice(1),
|
|
216
231
|
extname: () => path.extname(emittedName),
|
|
@@ -326,7 +341,7 @@ class FileEmitter {
|
|
|
326
341
|
const getHash = hasherByType[outputOptions.hashCharacters];
|
|
327
342
|
const output = (this.output = {
|
|
328
343
|
bundle,
|
|
329
|
-
|
|
344
|
+
fileNamesBySourceHash: new Map(),
|
|
330
345
|
getHash,
|
|
331
346
|
outputOptions
|
|
332
347
|
});
|
|
@@ -481,15 +496,15 @@ class FileEmitter {
|
|
|
481
496
|
}
|
|
482
497
|
return referenceId;
|
|
483
498
|
}
|
|
484
|
-
finalizeAdditionalAsset(consumedFile, source, { bundle,
|
|
485
|
-
let { fileName, needsCodeReference, originalFileName, referenceId } = consumedFile;
|
|
499
|
+
finalizeAdditionalAsset(consumedFile, source, { bundle, fileNamesBySourceHash, getHash, outputOptions }) {
|
|
500
|
+
let { fileName, name, needsCodeReference, originalFileName, referenceId } = consumedFile;
|
|
486
501
|
// Deduplicate assets if an explicit fileName is not provided
|
|
487
502
|
if (!fileName) {
|
|
488
503
|
const sourceHash = getHash(source);
|
|
489
|
-
fileName =
|
|
504
|
+
fileName = fileNamesBySourceHash.get(sourceHash);
|
|
490
505
|
if (!fileName) {
|
|
491
|
-
fileName = generateAssetFileName(
|
|
492
|
-
|
|
506
|
+
fileName = generateAssetFileName(name, name ? [name] : [], source, originalFileName, originalFileName ? [originalFileName] : [], sourceHash, outputOptions, bundle, this.options);
|
|
507
|
+
fileNamesBySourceHash.set(sourceHash, fileName);
|
|
493
508
|
}
|
|
494
509
|
}
|
|
495
510
|
// We must not modify the original assets to avoid interaction between outputs
|
|
@@ -498,25 +513,43 @@ class FileEmitter {
|
|
|
498
513
|
const existingAsset = bundle[fileName];
|
|
499
514
|
if (existingAsset?.type === 'asset') {
|
|
500
515
|
existingAsset.needsCodeReference &&= needsCodeReference;
|
|
516
|
+
if (name) {
|
|
517
|
+
existingAsset.names.push(name);
|
|
518
|
+
}
|
|
519
|
+
if (originalFileName) {
|
|
520
|
+
existingAsset.originalFileNames.push(originalFileName);
|
|
521
|
+
}
|
|
501
522
|
}
|
|
502
523
|
else {
|
|
524
|
+
const { options } = this;
|
|
503
525
|
bundle[fileName] = {
|
|
504
526
|
fileName,
|
|
505
|
-
name
|
|
527
|
+
get name() {
|
|
528
|
+
// Additionally, this should be non-enumerable in the next major
|
|
529
|
+
parseAst_js.warnDeprecation('Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', parseAst_js.URL_GENERATEBUNDLE, false, options);
|
|
530
|
+
return name;
|
|
531
|
+
},
|
|
532
|
+
names: name ? [name] : [],
|
|
506
533
|
needsCodeReference,
|
|
507
|
-
originalFileName
|
|
534
|
+
get originalFileName() {
|
|
535
|
+
// Additionally, this should be non-enumerable in the next major
|
|
536
|
+
parseAst_js.warnDeprecation('Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', parseAst_js.URL_GENERATEBUNDLE, false, options);
|
|
537
|
+
return originalFileName;
|
|
538
|
+
},
|
|
539
|
+
originalFileNames: originalFileName ? [originalFileName] : [],
|
|
508
540
|
source,
|
|
509
541
|
type: 'asset'
|
|
510
542
|
};
|
|
511
543
|
}
|
|
512
544
|
}
|
|
513
|
-
finalizeAssetsWithSameSource(consumedFiles, sourceHash, { bundle,
|
|
545
|
+
finalizeAssetsWithSameSource(consumedFiles, sourceHash, { bundle, fileNamesBySourceHash, outputOptions }) {
|
|
546
|
+
const { names, originalFileNames } = getNamesFromAssets(consumedFiles);
|
|
514
547
|
let fileName = '';
|
|
515
548
|
let usedConsumedFile;
|
|
516
549
|
let needsCodeReference = true;
|
|
517
550
|
for (const consumedFile of consumedFiles) {
|
|
518
551
|
needsCodeReference &&= consumedFile.needsCodeReference;
|
|
519
|
-
const assetFileName = generateAssetFileName(consumedFile.name, consumedFile.source, consumedFile.originalFileName, sourceHash, outputOptions, bundle);
|
|
552
|
+
const assetFileName = generateAssetFileName(consumedFile.name, names, consumedFile.source, consumedFile.originalFileName, originalFileNames, sourceHash, outputOptions, bundle, this.options);
|
|
520
553
|
if (!fileName ||
|
|
521
554
|
assetFileName.length < fileName.length ||
|
|
522
555
|
(assetFileName.length === fileName.length && assetFileName < fileName)) {
|
|
@@ -524,22 +557,50 @@ class FileEmitter {
|
|
|
524
557
|
usedConsumedFile = consumedFile;
|
|
525
558
|
}
|
|
526
559
|
}
|
|
527
|
-
|
|
560
|
+
fileNamesBySourceHash.set(sourceHash, fileName);
|
|
528
561
|
for (const consumedFile of consumedFiles) {
|
|
529
562
|
// We must not modify the original assets to avoid interaction between outputs
|
|
530
563
|
const assetWithFileName = { ...consumedFile, fileName };
|
|
531
564
|
this.filesByReferenceId.set(consumedFile.referenceId, assetWithFileName);
|
|
532
565
|
}
|
|
566
|
+
const { options } = this;
|
|
533
567
|
bundle[fileName] = {
|
|
534
568
|
fileName,
|
|
535
|
-
name
|
|
569
|
+
get name() {
|
|
570
|
+
// Additionally, this should be non-enumerable in the next major
|
|
571
|
+
parseAst_js.warnDeprecation('Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', parseAst_js.URL_GENERATEBUNDLE, false, options);
|
|
572
|
+
return usedConsumedFile.name;
|
|
573
|
+
},
|
|
574
|
+
names,
|
|
536
575
|
needsCodeReference,
|
|
537
|
-
originalFileName
|
|
576
|
+
get originalFileName() {
|
|
577
|
+
// Additionally, this should be non-enumerable in the next major
|
|
578
|
+
parseAst_js.warnDeprecation('Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', parseAst_js.URL_GENERATEBUNDLE, false, options);
|
|
579
|
+
return usedConsumedFile.originalFileName;
|
|
580
|
+
},
|
|
581
|
+
originalFileNames,
|
|
538
582
|
source: usedConsumedFile.source,
|
|
539
583
|
type: 'asset'
|
|
540
584
|
};
|
|
541
585
|
}
|
|
542
586
|
}
|
|
587
|
+
function getNamesFromAssets(consumedFiles) {
|
|
588
|
+
const names = [];
|
|
589
|
+
const originalFileNames = [];
|
|
590
|
+
for (const { name, originalFileName } of consumedFiles) {
|
|
591
|
+
if (typeof name === 'string') {
|
|
592
|
+
names.push(name);
|
|
593
|
+
}
|
|
594
|
+
if (originalFileName) {
|
|
595
|
+
originalFileNames.push(originalFileName);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
originalFileNames.sort();
|
|
599
|
+
// Sort by length first and then alphabetically so that the order is stable
|
|
600
|
+
// and the shortest names come first
|
|
601
|
+
names.sort((a, b) => a.length - b.length || (a > b ? 1 : a === b ? 0 : -1));
|
|
602
|
+
return { names, originalFileNames };
|
|
603
|
+
}
|
|
543
604
|
|
|
544
605
|
const doNothing = () => { };
|
|
545
606
|
|
|
@@ -637,6 +698,32 @@ const treeshakePresets = {
|
|
|
637
698
|
unknownGlobalSideEffects: false
|
|
638
699
|
}
|
|
639
700
|
};
|
|
701
|
+
const jsxPresets = {
|
|
702
|
+
preserve: {
|
|
703
|
+
factory: null,
|
|
704
|
+
fragment: null,
|
|
705
|
+
importSource: null,
|
|
706
|
+
mode: 'preserve'
|
|
707
|
+
},
|
|
708
|
+
'preserve-react': {
|
|
709
|
+
factory: 'React.createElement',
|
|
710
|
+
fragment: 'React.Fragment',
|
|
711
|
+
importSource: 'react',
|
|
712
|
+
mode: 'preserve'
|
|
713
|
+
},
|
|
714
|
+
react: {
|
|
715
|
+
factory: 'React.createElement',
|
|
716
|
+
fragment: 'React.Fragment',
|
|
717
|
+
importSource: 'react',
|
|
718
|
+
mode: 'classic'
|
|
719
|
+
},
|
|
720
|
+
'react-jsx': {
|
|
721
|
+
factory: 'React.createElement',
|
|
722
|
+
importSource: 'react',
|
|
723
|
+
jsxImportSource: 'react/jsx-runtime',
|
|
724
|
+
mode: 'automatic'
|
|
725
|
+
}
|
|
726
|
+
};
|
|
640
727
|
const generatedCodePresets = {
|
|
641
728
|
es2015: {
|
|
642
729
|
arrowFunctions: true,
|
|
@@ -1199,6 +1286,7 @@ function mergeInputOptions(config, overrides, plugins, log, onLog) {
|
|
|
1199
1286
|
experimentalLogSideEffects: getOption('experimentalLogSideEffects'),
|
|
1200
1287
|
external: getExternal(config, overrides),
|
|
1201
1288
|
input: getOption('input') || [],
|
|
1289
|
+
jsx: getObjectOption(config, overrides, 'jsx', objectifyOptionWithPresets(jsxPresets, 'jsx', parseAst_js.URL_JSX, 'false, ')),
|
|
1202
1290
|
logLevel: getOption('logLevel'),
|
|
1203
1291
|
makeAbsoluteExternalsRelative: getOption('makeAbsoluteExternalsRelative'),
|
|
1204
1292
|
maxParallelFileOps: getOption('maxParallelFileOps'),
|
|
@@ -3650,6 +3738,7 @@ class Variable extends ExpressionEntity {
|
|
|
3650
3738
|
this.name = name;
|
|
3651
3739
|
this.alwaysRendered = false;
|
|
3652
3740
|
this.forbiddenNames = null;
|
|
3741
|
+
this.globalName = null;
|
|
3653
3742
|
this.initReached = false;
|
|
3654
3743
|
this.isId = false;
|
|
3655
3744
|
this.kind = null;
|
|
@@ -3695,6 +3784,9 @@ class Variable extends ExpressionEntity {
|
|
|
3695
3784
|
this.name);
|
|
3696
3785
|
}
|
|
3697
3786
|
getName(getPropertyAccess, useOriginalName) {
|
|
3787
|
+
if (this.globalName) {
|
|
3788
|
+
return this.globalName;
|
|
3789
|
+
}
|
|
3698
3790
|
if (useOriginalName?.(this)) {
|
|
3699
3791
|
return this.name;
|
|
3700
3792
|
}
|
|
@@ -3708,10 +3800,10 @@ class Variable extends ExpressionEntity {
|
|
|
3708
3800
|
return type !== INTERACTION_ACCESSED || path.length > 0;
|
|
3709
3801
|
}
|
|
3710
3802
|
/**
|
|
3711
|
-
* Marks this variable as being part of the bundle, which is usually the case
|
|
3712
|
-
* its identifiers becomes part of the bundle. Returns true if it
|
|
3713
|
-
* previously.
|
|
3714
|
-
*
|
|
3803
|
+
* Marks this variable as being part of the bundle, which is usually the case
|
|
3804
|
+
* when one of its identifiers becomes part of the bundle. Returns true if it
|
|
3805
|
+
* has not been included previously. Once a variable is included, it should
|
|
3806
|
+
* take care all its declarations are included.
|
|
3715
3807
|
*/
|
|
3716
3808
|
include() {
|
|
3717
3809
|
this.included = true;
|
|
@@ -4197,6 +4289,21 @@ const childNodeKeys = {
|
|
|
4197
4289
|
ImportExpression: ['source', 'options'],
|
|
4198
4290
|
ImportNamespaceSpecifier: ['local'],
|
|
4199
4291
|
ImportSpecifier: ['imported', 'local'],
|
|
4292
|
+
JSXAttribute: ['name', 'value'],
|
|
4293
|
+
JSXClosingElement: ['name'],
|
|
4294
|
+
JSXClosingFragment: [],
|
|
4295
|
+
JSXElement: ['openingElement', 'children', 'closingElement'],
|
|
4296
|
+
JSXEmptyExpression: [],
|
|
4297
|
+
JSXExpressionContainer: ['expression'],
|
|
4298
|
+
JSXFragment: ['openingFragment', 'children', 'closingFragment'],
|
|
4299
|
+
JSXIdentifier: [],
|
|
4300
|
+
JSXMemberExpression: ['object', 'property'],
|
|
4301
|
+
JSXNamespacedName: ['namespace', 'name'],
|
|
4302
|
+
JSXOpeningElement: ['name', 'attributes'],
|
|
4303
|
+
JSXOpeningFragment: [],
|
|
4304
|
+
JSXSpreadAttribute: ['argument'],
|
|
4305
|
+
JSXSpreadChild: ['expression'],
|
|
4306
|
+
JSXText: [],
|
|
4200
4307
|
LabeledStatement: ['label', 'body'],
|
|
4201
4308
|
Literal: [],
|
|
4202
4309
|
LogicalExpression: ['left', 'right'],
|
|
@@ -6311,11 +6418,11 @@ class LocalVariable extends Variable {
|
|
|
6311
6418
|
}
|
|
6312
6419
|
|
|
6313
6420
|
const tdzVariableKinds = new Set(['class', 'const', 'let', 'var', 'using', 'await using']);
|
|
6314
|
-
class
|
|
6421
|
+
class IdentifierBase extends NodeBase {
|
|
6315
6422
|
constructor() {
|
|
6316
6423
|
super(...arguments);
|
|
6317
6424
|
this.variable = null;
|
|
6318
|
-
this.
|
|
6425
|
+
this.isVariableReference = false;
|
|
6319
6426
|
}
|
|
6320
6427
|
get isTDZAccess() {
|
|
6321
6428
|
if (!isFlagSet(this.flags, 4 /* Flag.tdzAccessDefined */)) {
|
|
@@ -6327,55 +6434,6 @@ class Identifier extends NodeBase {
|
|
|
6327
6434
|
this.flags = setFlag(this.flags, 4 /* Flag.tdzAccessDefined */, true);
|
|
6328
6435
|
this.flags = setFlag(this.flags, 8 /* Flag.tdzAccess */, value);
|
|
6329
6436
|
}
|
|
6330
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
6331
|
-
if (exportNamesByVariable.has(this.variable)) {
|
|
6332
|
-
variables.push(this.variable);
|
|
6333
|
-
}
|
|
6334
|
-
}
|
|
6335
|
-
bind() {
|
|
6336
|
-
if (!this.variable && is_reference(this, this.parent)) {
|
|
6337
|
-
this.variable = this.scope.findVariable(this.name);
|
|
6338
|
-
this.variable.addReference(this);
|
|
6339
|
-
this.isReferenceVariable = true;
|
|
6340
|
-
}
|
|
6341
|
-
}
|
|
6342
|
-
declare(kind, init) {
|
|
6343
|
-
let variable;
|
|
6344
|
-
const { treeshake } = this.scope.context.options;
|
|
6345
|
-
switch (kind) {
|
|
6346
|
-
case 'var': {
|
|
6347
|
-
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
6348
|
-
if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
|
|
6349
|
-
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
6350
|
-
variable.markInitializersForDeoptimization();
|
|
6351
|
-
}
|
|
6352
|
-
break;
|
|
6353
|
-
}
|
|
6354
|
-
case 'function': {
|
|
6355
|
-
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
6356
|
-
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
6357
|
-
break;
|
|
6358
|
-
}
|
|
6359
|
-
case 'let':
|
|
6360
|
-
case 'const':
|
|
6361
|
-
case 'using':
|
|
6362
|
-
case 'await using':
|
|
6363
|
-
case 'class': {
|
|
6364
|
-
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
6365
|
-
break;
|
|
6366
|
-
}
|
|
6367
|
-
case 'parameter': {
|
|
6368
|
-
variable = this.scope.addParameterDeclaration(this);
|
|
6369
|
-
break;
|
|
6370
|
-
}
|
|
6371
|
-
/* istanbul ignore next */
|
|
6372
|
-
default: {
|
|
6373
|
-
/* istanbul ignore next */
|
|
6374
|
-
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
6375
|
-
}
|
|
6376
|
-
}
|
|
6377
|
-
return [(this.variable = variable)];
|
|
6378
|
-
}
|
|
6379
6437
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
6380
6438
|
this.variable.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
6381
6439
|
}
|
|
@@ -6466,32 +6524,6 @@ class Identifier extends NodeBase {
|
|
|
6466
6524
|
}
|
|
6467
6525
|
return (this.isTDZAccess = false);
|
|
6468
6526
|
}
|
|
6469
|
-
markDeclarationReached() {
|
|
6470
|
-
this.variable.initReached = true;
|
|
6471
|
-
}
|
|
6472
|
-
render(code, { snippets: { getPropertyAccess }, useOriginalName }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = parseAst_js.BLANK) {
|
|
6473
|
-
if (this.variable) {
|
|
6474
|
-
const name = this.variable.getName(getPropertyAccess, useOriginalName);
|
|
6475
|
-
if (name !== this.name) {
|
|
6476
|
-
code.overwrite(this.start, this.end, name, {
|
|
6477
|
-
contentOnly: true,
|
|
6478
|
-
storeName: true
|
|
6479
|
-
});
|
|
6480
|
-
if (isShorthandProperty) {
|
|
6481
|
-
code.prependRight(this.start, `${this.name}: `);
|
|
6482
|
-
}
|
|
6483
|
-
}
|
|
6484
|
-
// In strict mode, any variable named "eval" must be the actual "eval" function
|
|
6485
|
-
if (name === 'eval' &&
|
|
6486
|
-
renderedParentType === parseAst_js.CallExpression &&
|
|
6487
|
-
isCalleeOfRenderedParent) {
|
|
6488
|
-
code.appendRight(this.start, '0, ');
|
|
6489
|
-
}
|
|
6490
|
-
}
|
|
6491
|
-
}
|
|
6492
|
-
disallowImportReassignment() {
|
|
6493
|
-
return this.scope.context.error(parseAst_js.logIllegalImportReassignment(this.name, this.scope.context.module.id), this.start);
|
|
6494
|
-
}
|
|
6495
6527
|
applyDeoptimizations() {
|
|
6496
6528
|
this.deoptimized = true;
|
|
6497
6529
|
if (this.variable instanceof LocalVariable) {
|
|
@@ -6504,11 +6536,14 @@ class Identifier extends NodeBase {
|
|
|
6504
6536
|
this.variable.consolidateInitializers();
|
|
6505
6537
|
this.scope.context.requestTreeshakingPass();
|
|
6506
6538
|
}
|
|
6507
|
-
if (this.
|
|
6539
|
+
if (this.isVariableReference) {
|
|
6508
6540
|
this.variable.addUsedPlace(this);
|
|
6509
6541
|
this.scope.context.requestTreeshakingPass();
|
|
6510
6542
|
}
|
|
6511
6543
|
}
|
|
6544
|
+
disallowImportReassignment() {
|
|
6545
|
+
return this.scope.context.error(parseAst_js.logIllegalImportReassignment(this.name, this.scope.context.module.id), this.start);
|
|
6546
|
+
}
|
|
6512
6547
|
getVariableRespectingTDZ() {
|
|
6513
6548
|
if (this.isPossibleTDZ()) {
|
|
6514
6549
|
return UNKNOWN_EXPRESSION;
|
|
@@ -6539,6 +6574,85 @@ function closestParentFunctionOrProgram(node) {
|
|
|
6539
6574
|
return node;
|
|
6540
6575
|
}
|
|
6541
6576
|
|
|
6577
|
+
class Identifier extends IdentifierBase {
|
|
6578
|
+
constructor() {
|
|
6579
|
+
super(...arguments);
|
|
6580
|
+
this.variable = null;
|
|
6581
|
+
}
|
|
6582
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
6583
|
+
if (exportNamesByVariable.has(this.variable)) {
|
|
6584
|
+
variables.push(this.variable);
|
|
6585
|
+
}
|
|
6586
|
+
}
|
|
6587
|
+
bind() {
|
|
6588
|
+
if (!this.variable && is_reference(this, this.parent)) {
|
|
6589
|
+
this.variable = this.scope.findVariable(this.name);
|
|
6590
|
+
this.variable.addReference(this);
|
|
6591
|
+
this.isVariableReference = true;
|
|
6592
|
+
}
|
|
6593
|
+
}
|
|
6594
|
+
declare(kind, init) {
|
|
6595
|
+
let variable;
|
|
6596
|
+
const { treeshake } = this.scope.context.options;
|
|
6597
|
+
switch (kind) {
|
|
6598
|
+
case 'var': {
|
|
6599
|
+
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
6600
|
+
if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
|
|
6601
|
+
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
6602
|
+
variable.markInitializersForDeoptimization();
|
|
6603
|
+
}
|
|
6604
|
+
break;
|
|
6605
|
+
}
|
|
6606
|
+
case 'function': {
|
|
6607
|
+
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
6608
|
+
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
6609
|
+
break;
|
|
6610
|
+
}
|
|
6611
|
+
case 'let':
|
|
6612
|
+
case 'const':
|
|
6613
|
+
case 'using':
|
|
6614
|
+
case 'await using':
|
|
6615
|
+
case 'class': {
|
|
6616
|
+
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
6617
|
+
break;
|
|
6618
|
+
}
|
|
6619
|
+
case 'parameter': {
|
|
6620
|
+
variable = this.scope.addParameterDeclaration(this);
|
|
6621
|
+
break;
|
|
6622
|
+
}
|
|
6623
|
+
/* istanbul ignore next */
|
|
6624
|
+
default: {
|
|
6625
|
+
/* istanbul ignore next */
|
|
6626
|
+
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
6627
|
+
}
|
|
6628
|
+
}
|
|
6629
|
+
return [(this.variable = variable)];
|
|
6630
|
+
}
|
|
6631
|
+
markDeclarationReached() {
|
|
6632
|
+
this.variable.initReached = true;
|
|
6633
|
+
}
|
|
6634
|
+
render(code, { snippets: { getPropertyAccess }, useOriginalName }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = parseAst_js.BLANK) {
|
|
6635
|
+
if (this.variable) {
|
|
6636
|
+
const name = this.variable.getName(getPropertyAccess, useOriginalName);
|
|
6637
|
+
if (name !== this.name) {
|
|
6638
|
+
code.overwrite(this.start, this.end, name, {
|
|
6639
|
+
contentOnly: true,
|
|
6640
|
+
storeName: true
|
|
6641
|
+
});
|
|
6642
|
+
if (isShorthandProperty) {
|
|
6643
|
+
code.prependRight(this.start, `${this.name}: `);
|
|
6644
|
+
}
|
|
6645
|
+
}
|
|
6646
|
+
// In strict mode, any variable named "eval" must be the actual "eval" function
|
|
6647
|
+
if (name === 'eval' &&
|
|
6648
|
+
renderedParentType === parseAst_js.CallExpression &&
|
|
6649
|
+
isCalleeOfRenderedParent) {
|
|
6650
|
+
code.appendRight(this.start, '0, ');
|
|
6651
|
+
}
|
|
6652
|
+
}
|
|
6653
|
+
}
|
|
6654
|
+
}
|
|
6655
|
+
|
|
6542
6656
|
function getSafeName(baseName, usedNames, forbiddenNames) {
|
|
6543
6657
|
let safeName = baseName;
|
|
6544
6658
|
let count = 1;
|
|
@@ -6667,6 +6781,11 @@ class ChildScope extends Scope {
|
|
|
6667
6781
|
findLexicalBoundary() {
|
|
6668
6782
|
return this.parent.findLexicalBoundary();
|
|
6669
6783
|
}
|
|
6784
|
+
findGlobal(name) {
|
|
6785
|
+
const variable = this.parent.findVariable(name);
|
|
6786
|
+
this.accessedOutsideVariables.set(name, variable);
|
|
6787
|
+
return variable;
|
|
6788
|
+
}
|
|
6670
6789
|
findVariable(name) {
|
|
6671
6790
|
const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
|
|
6672
6791
|
if (knownVariable) {
|
|
@@ -13831,6 +13950,497 @@ class ImportSpecifier extends NodeBase {
|
|
|
13831
13950
|
applyDeoptimizations() { }
|
|
13832
13951
|
}
|
|
13833
13952
|
|
|
13953
|
+
class JSXIdentifier extends IdentifierBase {
|
|
13954
|
+
constructor() {
|
|
13955
|
+
super(...arguments);
|
|
13956
|
+
this.isNativeElement = false;
|
|
13957
|
+
}
|
|
13958
|
+
bind() {
|
|
13959
|
+
const type = this.getType();
|
|
13960
|
+
if (type === 0 /* IdentifierType.Reference */) {
|
|
13961
|
+
this.variable = this.scope.findVariable(this.name);
|
|
13962
|
+
this.variable.addReference(this);
|
|
13963
|
+
}
|
|
13964
|
+
else if (type === 1 /* IdentifierType.NativeElementName */) {
|
|
13965
|
+
this.isNativeElement = true;
|
|
13966
|
+
}
|
|
13967
|
+
}
|
|
13968
|
+
render(code, { snippets: { getPropertyAccess }, useOriginalName }) {
|
|
13969
|
+
if (this.variable) {
|
|
13970
|
+
const name = this.variable.getName(getPropertyAccess, useOriginalName);
|
|
13971
|
+
if (name !== this.name) {
|
|
13972
|
+
code.overwrite(this.start, this.end, name, {
|
|
13973
|
+
contentOnly: true,
|
|
13974
|
+
storeName: true
|
|
13975
|
+
});
|
|
13976
|
+
}
|
|
13977
|
+
}
|
|
13978
|
+
else if (this.isNativeElement &&
|
|
13979
|
+
this.scope.context.options.jsx.mode !== 'preserve') {
|
|
13980
|
+
code.update(this.start, this.end, JSON.stringify(this.name));
|
|
13981
|
+
}
|
|
13982
|
+
}
|
|
13983
|
+
getType() {
|
|
13984
|
+
switch (this.parent.type) {
|
|
13985
|
+
case 'JSXOpeningElement':
|
|
13986
|
+
case 'JSXClosingElement': {
|
|
13987
|
+
return this.name.startsWith(this.name.charAt(0).toUpperCase())
|
|
13988
|
+
? 0 /* IdentifierType.Reference */
|
|
13989
|
+
: 1 /* IdentifierType.NativeElementName */;
|
|
13990
|
+
}
|
|
13991
|
+
case 'JSXMemberExpression': {
|
|
13992
|
+
return this.parent.object === this
|
|
13993
|
+
? 0 /* IdentifierType.Reference */
|
|
13994
|
+
: 2 /* IdentifierType.Other */;
|
|
13995
|
+
}
|
|
13996
|
+
case 'JSXAttribute':
|
|
13997
|
+
case 'JSXNamespacedName': {
|
|
13998
|
+
return 2 /* IdentifierType.Other */;
|
|
13999
|
+
}
|
|
14000
|
+
default: {
|
|
14001
|
+
/* istanbul ignore next */
|
|
14002
|
+
throw new Error(`Unexpected parent node type for JSXIdentifier: ${this.parent.type}`);
|
|
14003
|
+
}
|
|
14004
|
+
}
|
|
14005
|
+
}
|
|
14006
|
+
}
|
|
14007
|
+
|
|
14008
|
+
class JSXAttribute extends NodeBase {
|
|
14009
|
+
render(code, options, { jsxMode } = parseAst_js.BLANK) {
|
|
14010
|
+
super.render(code, options);
|
|
14011
|
+
if (['classic', 'automatic'].includes(jsxMode)) {
|
|
14012
|
+
const { name, value } = this;
|
|
14013
|
+
const key = name instanceof JSXIdentifier ? name.name : `${name.namespace.name}:${name.name.name}`;
|
|
14014
|
+
if (!(jsxMode === 'automatic' && key === 'key')) {
|
|
14015
|
+
const safeKey = stringifyObjectKeyIfNeeded(key);
|
|
14016
|
+
if (key !== safeKey) {
|
|
14017
|
+
code.overwrite(name.start, name.end, safeKey, { contentOnly: true });
|
|
14018
|
+
}
|
|
14019
|
+
if (value) {
|
|
14020
|
+
code.overwrite(name.end, value.start, ': ', { contentOnly: true });
|
|
14021
|
+
}
|
|
14022
|
+
else {
|
|
14023
|
+
code.appendLeft(name.end, ': true');
|
|
14024
|
+
}
|
|
14025
|
+
}
|
|
14026
|
+
}
|
|
14027
|
+
}
|
|
14028
|
+
}
|
|
14029
|
+
|
|
14030
|
+
class JSXClosingBase extends NodeBase {
|
|
14031
|
+
render(code, options) {
|
|
14032
|
+
const { mode } = this.scope.context.options.jsx;
|
|
14033
|
+
if (mode !== 'preserve') {
|
|
14034
|
+
code.overwrite(this.start, this.end, ')', { contentOnly: true });
|
|
14035
|
+
}
|
|
14036
|
+
else {
|
|
14037
|
+
super.render(code, options);
|
|
14038
|
+
}
|
|
14039
|
+
}
|
|
14040
|
+
}
|
|
14041
|
+
|
|
14042
|
+
class JSXClosingElement extends JSXClosingBase {
|
|
14043
|
+
}
|
|
14044
|
+
|
|
14045
|
+
class JSXClosingFragment extends JSXClosingBase {
|
|
14046
|
+
}
|
|
14047
|
+
|
|
14048
|
+
class JSXSpreadAttribute extends NodeBase {
|
|
14049
|
+
render(code, options) {
|
|
14050
|
+
this.argument.render(code, options);
|
|
14051
|
+
const { mode } = this.scope.context.options.jsx;
|
|
14052
|
+
if (mode !== 'preserve') {
|
|
14053
|
+
code.overwrite(this.start, this.argument.start, '', { contentOnly: true });
|
|
14054
|
+
code.overwrite(this.argument.end, this.end, '', { contentOnly: true });
|
|
14055
|
+
}
|
|
14056
|
+
}
|
|
14057
|
+
}
|
|
14058
|
+
|
|
14059
|
+
class JSXEmptyExpression extends NodeBase {
|
|
14060
|
+
}
|
|
14061
|
+
|
|
14062
|
+
class JSXExpressionContainer extends NodeBase {
|
|
14063
|
+
render(code, options) {
|
|
14064
|
+
const { mode } = this.scope.context.options.jsx;
|
|
14065
|
+
if (mode !== 'preserve') {
|
|
14066
|
+
code.remove(this.start, this.expression.start);
|
|
14067
|
+
code.remove(this.expression.end, this.end);
|
|
14068
|
+
}
|
|
14069
|
+
this.expression.render(code, options);
|
|
14070
|
+
}
|
|
14071
|
+
}
|
|
14072
|
+
|
|
14073
|
+
function getRenderedJsxChildren(children) {
|
|
14074
|
+
let renderedChildren = 0;
|
|
14075
|
+
for (const child of children) {
|
|
14076
|
+
if (!(child instanceof JSXExpressionContainer && child.expression instanceof JSXEmptyExpression)) {
|
|
14077
|
+
renderedChildren++;
|
|
14078
|
+
}
|
|
14079
|
+
}
|
|
14080
|
+
return renderedChildren;
|
|
14081
|
+
}
|
|
14082
|
+
|
|
14083
|
+
function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
|
|
14084
|
+
const [baseName, nestedName] = factory.split('.');
|
|
14085
|
+
let factoryVariable;
|
|
14086
|
+
if (importSource) {
|
|
14087
|
+
factoryVariable = node.scope.context.getImportedJsxFactoryVariable(nestedName ? 'default' : baseName, node.start, importSource);
|
|
14088
|
+
if (preserve) {
|
|
14089
|
+
// This pretends we are accessing an included global variable of the same name
|
|
14090
|
+
const globalVariable = node.scope.findGlobal(baseName);
|
|
14091
|
+
globalVariable.include();
|
|
14092
|
+
// This excludes this variable from renaming
|
|
14093
|
+
factoryVariable.globalName = baseName;
|
|
14094
|
+
}
|
|
14095
|
+
}
|
|
14096
|
+
else {
|
|
14097
|
+
factoryVariable = node.scope.findGlobal(baseName);
|
|
14098
|
+
}
|
|
14099
|
+
node.scope.context.includeVariableInModule(factoryVariable);
|
|
14100
|
+
if (factoryVariable instanceof LocalVariable) {
|
|
14101
|
+
factoryVariable.consolidateInitializers();
|
|
14102
|
+
factoryVariable.addUsedPlace(node);
|
|
14103
|
+
node.scope.context.requestTreeshakingPass();
|
|
14104
|
+
}
|
|
14105
|
+
return factoryVariable;
|
|
14106
|
+
}
|
|
14107
|
+
|
|
14108
|
+
class JSXElementBase extends NodeBase {
|
|
14109
|
+
constructor() {
|
|
14110
|
+
super(...arguments);
|
|
14111
|
+
this.factoryVariable = null;
|
|
14112
|
+
this.factory = null;
|
|
14113
|
+
}
|
|
14114
|
+
initialise() {
|
|
14115
|
+
super.initialise();
|
|
14116
|
+
const { importSource } = (this.jsxMode = this.getRenderingMode());
|
|
14117
|
+
if (importSource) {
|
|
14118
|
+
this.scope.context.addImportSource(importSource);
|
|
14119
|
+
}
|
|
14120
|
+
}
|
|
14121
|
+
include(context, includeChildrenRecursively) {
|
|
14122
|
+
if (!this.included) {
|
|
14123
|
+
const { factory, importSource, mode } = this.jsxMode;
|
|
14124
|
+
if (factory) {
|
|
14125
|
+
this.factory = factory;
|
|
14126
|
+
this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
|
|
14127
|
+
}
|
|
14128
|
+
}
|
|
14129
|
+
super.include(context, includeChildrenRecursively);
|
|
14130
|
+
}
|
|
14131
|
+
applyDeoptimizations() { }
|
|
14132
|
+
getRenderingMode() {
|
|
14133
|
+
const jsx = this.scope.context.options.jsx;
|
|
14134
|
+
const { mode, factory, importSource } = jsx;
|
|
14135
|
+
if (mode === 'automatic') {
|
|
14136
|
+
return {
|
|
14137
|
+
factory: getRenderedJsxChildren(this.children) > 1 ? 'jsxs' : 'jsx',
|
|
14138
|
+
importSource: jsx.jsxImportSource,
|
|
14139
|
+
mode
|
|
14140
|
+
};
|
|
14141
|
+
}
|
|
14142
|
+
return { factory, importSource, mode };
|
|
14143
|
+
}
|
|
14144
|
+
renderChildren(code, options, openingEnd) {
|
|
14145
|
+
const { children } = this;
|
|
14146
|
+
let hasMultipleChildren = false;
|
|
14147
|
+
let childrenEnd = openingEnd;
|
|
14148
|
+
let firstChild = null;
|
|
14149
|
+
for (const child of children) {
|
|
14150
|
+
if (child instanceof JSXExpressionContainer &&
|
|
14151
|
+
child.expression instanceof JSXEmptyExpression) {
|
|
14152
|
+
code.remove(childrenEnd, child.end);
|
|
14153
|
+
}
|
|
14154
|
+
else {
|
|
14155
|
+
code.appendLeft(childrenEnd, ', ');
|
|
14156
|
+
child.render(code, options);
|
|
14157
|
+
if (firstChild) {
|
|
14158
|
+
hasMultipleChildren = true;
|
|
14159
|
+
}
|
|
14160
|
+
else {
|
|
14161
|
+
firstChild = child;
|
|
14162
|
+
}
|
|
14163
|
+
}
|
|
14164
|
+
childrenEnd = child.end;
|
|
14165
|
+
}
|
|
14166
|
+
return { childrenEnd, firstChild, hasMultipleChildren };
|
|
14167
|
+
}
|
|
14168
|
+
}
|
|
14169
|
+
|
|
14170
|
+
class JSXElement extends JSXElementBase {
|
|
14171
|
+
render(code, options) {
|
|
14172
|
+
switch (this.jsxMode.mode) {
|
|
14173
|
+
case 'classic': {
|
|
14174
|
+
this.renderClassicMode(code, options);
|
|
14175
|
+
break;
|
|
14176
|
+
}
|
|
14177
|
+
case 'automatic': {
|
|
14178
|
+
this.renderAutomaticMode(code, options);
|
|
14179
|
+
break;
|
|
14180
|
+
}
|
|
14181
|
+
default: {
|
|
14182
|
+
super.render(code, options);
|
|
14183
|
+
}
|
|
14184
|
+
}
|
|
14185
|
+
}
|
|
14186
|
+
getRenderingMode() {
|
|
14187
|
+
const jsx = this.scope.context.options.jsx;
|
|
14188
|
+
const { mode, factory, importSource } = jsx;
|
|
14189
|
+
if (mode === 'automatic') {
|
|
14190
|
+
// In the case there is a key after a spread attribute, we fall back to
|
|
14191
|
+
// classic mode, see https://github.com/facebook/react/issues/20031#issuecomment-710346866
|
|
14192
|
+
// for reasoning.
|
|
14193
|
+
let hasSpread = false;
|
|
14194
|
+
for (const attribute of this.openingElement.attributes) {
|
|
14195
|
+
if (attribute instanceof JSXSpreadAttribute) {
|
|
14196
|
+
hasSpread = true;
|
|
14197
|
+
}
|
|
14198
|
+
else if (hasSpread && attribute.name.name === 'key') {
|
|
14199
|
+
return { factory, importSource, mode: 'classic' };
|
|
14200
|
+
}
|
|
14201
|
+
}
|
|
14202
|
+
}
|
|
14203
|
+
return super.getRenderingMode();
|
|
14204
|
+
}
|
|
14205
|
+
renderClassicMode(code, options) {
|
|
14206
|
+
const { snippets: { getPropertyAccess }, useOriginalName } = options;
|
|
14207
|
+
const { closingElement, end, factory, factoryVariable, openingElement: { end: openingEnd, selfClosing } } = this;
|
|
14208
|
+
const [, ...nestedName] = factory.split('.');
|
|
14209
|
+
const { firstAttribute, hasAttributes, hasSpread, inObject, previousEnd } = this.renderAttributes(code, options, [factoryVariable.getName(getPropertyAccess, useOriginalName), ...nestedName].join('.'), false);
|
|
14210
|
+
this.wrapAttributes(code, inObject, hasAttributes, hasSpread, firstAttribute, 'null', previousEnd);
|
|
14211
|
+
this.renderChildren(code, options, openingEnd);
|
|
14212
|
+
if (selfClosing) {
|
|
14213
|
+
code.appendLeft(end, ')');
|
|
14214
|
+
}
|
|
14215
|
+
else {
|
|
14216
|
+
closingElement.render(code, options);
|
|
14217
|
+
}
|
|
14218
|
+
}
|
|
14219
|
+
renderAutomaticMode(code, options) {
|
|
14220
|
+
const { snippets: { getPropertyAccess }, useOriginalName } = options;
|
|
14221
|
+
const { closingElement, end, factoryVariable, openingElement: { end: openindEnd, selfClosing } } = this;
|
|
14222
|
+
let { firstAttribute, hasAttributes, hasSpread, inObject, keyAttribute, previousEnd } = this.renderAttributes(code, options, factoryVariable.getName(getPropertyAccess, useOriginalName), true);
|
|
14223
|
+
const { firstChild, hasMultipleChildren, childrenEnd } = this.renderChildren(code, options, openindEnd);
|
|
14224
|
+
if (firstChild) {
|
|
14225
|
+
code.prependRight(firstChild.start, `children: ${hasMultipleChildren ? '[' : ''}`);
|
|
14226
|
+
if (!inObject) {
|
|
14227
|
+
code.prependRight(firstChild.start, '{ ');
|
|
14228
|
+
inObject = true;
|
|
14229
|
+
}
|
|
14230
|
+
previousEnd = closingElement.start;
|
|
14231
|
+
if (hasMultipleChildren) {
|
|
14232
|
+
code.appendLeft(previousEnd, ']');
|
|
14233
|
+
}
|
|
14234
|
+
}
|
|
14235
|
+
this.wrapAttributes(code, inObject, hasAttributes || !!firstChild, hasSpread, firstAttribute || firstChild, '{}', childrenEnd);
|
|
14236
|
+
if (keyAttribute) {
|
|
14237
|
+
const { value } = keyAttribute;
|
|
14238
|
+
// This will appear to the left of the moved code...
|
|
14239
|
+
code.appendLeft(childrenEnd, ', ');
|
|
14240
|
+
if (value) {
|
|
14241
|
+
code.move(value.start, value.end, childrenEnd);
|
|
14242
|
+
}
|
|
14243
|
+
else {
|
|
14244
|
+
code.appendLeft(childrenEnd, 'true');
|
|
14245
|
+
}
|
|
14246
|
+
}
|
|
14247
|
+
if (selfClosing) {
|
|
14248
|
+
// Moving the key attribute will also move the parenthesis to the right position
|
|
14249
|
+
code.appendLeft(keyAttribute?.value?.end || end, ')');
|
|
14250
|
+
}
|
|
14251
|
+
else {
|
|
14252
|
+
closingElement.render(code, options);
|
|
14253
|
+
}
|
|
14254
|
+
}
|
|
14255
|
+
renderAttributes(code, options, factoryName, extractKeyAttribute) {
|
|
14256
|
+
const { jsxMode: { mode }, openingElement } = this;
|
|
14257
|
+
const { attributes, end: openingEnd, start: openingStart, name: { start: nameStart, end: nameEnd } } = openingElement;
|
|
14258
|
+
code.update(openingStart, nameStart, `/*#__PURE__*/${factoryName}(`);
|
|
14259
|
+
openingElement.render(code, options, { jsxMode: mode });
|
|
14260
|
+
let keyAttribute = null;
|
|
14261
|
+
let hasSpread = false;
|
|
14262
|
+
let inObject = false;
|
|
14263
|
+
let previousEnd = nameEnd;
|
|
14264
|
+
let hasAttributes = false;
|
|
14265
|
+
let firstAttribute = null;
|
|
14266
|
+
for (const attribute of attributes) {
|
|
14267
|
+
if (attribute instanceof JSXAttribute) {
|
|
14268
|
+
if (extractKeyAttribute && attribute.name.name === 'key') {
|
|
14269
|
+
keyAttribute = attribute;
|
|
14270
|
+
code.remove(previousEnd, attribute.value?.start || attribute.end);
|
|
14271
|
+
continue;
|
|
14272
|
+
}
|
|
14273
|
+
code.appendLeft(previousEnd, ',');
|
|
14274
|
+
if (!inObject) {
|
|
14275
|
+
code.prependRight(attribute.start, '{ ');
|
|
14276
|
+
inObject = true;
|
|
14277
|
+
}
|
|
14278
|
+
hasAttributes = true;
|
|
14279
|
+
}
|
|
14280
|
+
else {
|
|
14281
|
+
if (inObject) {
|
|
14282
|
+
if (hasAttributes) {
|
|
14283
|
+
code.appendLeft(previousEnd, ' ');
|
|
14284
|
+
}
|
|
14285
|
+
code.appendLeft(previousEnd, '},');
|
|
14286
|
+
inObject = false;
|
|
14287
|
+
}
|
|
14288
|
+
else {
|
|
14289
|
+
code.appendLeft(previousEnd, ',');
|
|
14290
|
+
}
|
|
14291
|
+
hasSpread = true;
|
|
14292
|
+
}
|
|
14293
|
+
previousEnd = attribute.end;
|
|
14294
|
+
if (!firstAttribute) {
|
|
14295
|
+
firstAttribute = attribute;
|
|
14296
|
+
}
|
|
14297
|
+
}
|
|
14298
|
+
code.remove(attributes.at(-1)?.end || previousEnd, openingEnd);
|
|
14299
|
+
return { firstAttribute, hasAttributes, hasSpread, inObject, keyAttribute, previousEnd };
|
|
14300
|
+
}
|
|
14301
|
+
wrapAttributes(code, inObject, hasAttributes, hasSpread, firstAttribute, missingAttributesFallback, attributesEnd) {
|
|
14302
|
+
if (inObject) {
|
|
14303
|
+
code.appendLeft(attributesEnd, ' }');
|
|
14304
|
+
}
|
|
14305
|
+
if (hasSpread) {
|
|
14306
|
+
if (hasAttributes) {
|
|
14307
|
+
const { start } = firstAttribute;
|
|
14308
|
+
if (firstAttribute instanceof JSXSpreadAttribute) {
|
|
14309
|
+
code.prependRight(start, '{}, ');
|
|
14310
|
+
}
|
|
14311
|
+
code.prependRight(start, 'Object.assign(');
|
|
14312
|
+
code.appendLeft(attributesEnd, ')');
|
|
14313
|
+
}
|
|
14314
|
+
}
|
|
14315
|
+
else if (!hasAttributes) {
|
|
14316
|
+
code.appendLeft(attributesEnd, `, ${missingAttributesFallback}`);
|
|
14317
|
+
}
|
|
14318
|
+
}
|
|
14319
|
+
}
|
|
14320
|
+
|
|
14321
|
+
class JSXFragment extends JSXElementBase {
|
|
14322
|
+
render(code, options) {
|
|
14323
|
+
switch (this.jsxMode.mode) {
|
|
14324
|
+
case 'classic': {
|
|
14325
|
+
this.renderClassicMode(code, options);
|
|
14326
|
+
break;
|
|
14327
|
+
}
|
|
14328
|
+
case 'automatic': {
|
|
14329
|
+
this.renderAutomaticMode(code, options);
|
|
14330
|
+
break;
|
|
14331
|
+
}
|
|
14332
|
+
default: {
|
|
14333
|
+
super.render(code, options);
|
|
14334
|
+
}
|
|
14335
|
+
}
|
|
14336
|
+
}
|
|
14337
|
+
renderClassicMode(code, options) {
|
|
14338
|
+
const { snippets: { getPropertyAccess }, useOriginalName } = options;
|
|
14339
|
+
const { closingFragment, factory, factoryVariable, openingFragment, start } = this;
|
|
14340
|
+
const [, ...nestedName] = factory.split('.');
|
|
14341
|
+
openingFragment.render(code, options);
|
|
14342
|
+
code.prependRight(start, `/*#__PURE__*/${[
|
|
14343
|
+
factoryVariable.getName(getPropertyAccess, useOriginalName),
|
|
14344
|
+
...nestedName
|
|
14345
|
+
].join('.')}(`);
|
|
14346
|
+
code.appendLeft(openingFragment.end, ', null');
|
|
14347
|
+
this.renderChildren(code, options, openingFragment.end);
|
|
14348
|
+
closingFragment.render(code, options);
|
|
14349
|
+
}
|
|
14350
|
+
renderAutomaticMode(code, options) {
|
|
14351
|
+
const { snippets: { getPropertyAccess }, useOriginalName } = options;
|
|
14352
|
+
const { closingFragment, factoryVariable, openingFragment, start } = this;
|
|
14353
|
+
openingFragment.render(code, options);
|
|
14354
|
+
code.prependRight(start, `/*#__PURE__*/${factoryVariable.getName(getPropertyAccess, useOriginalName)}(`);
|
|
14355
|
+
const { firstChild, hasMultipleChildren, childrenEnd } = this.renderChildren(code, options, openingFragment.end);
|
|
14356
|
+
if (firstChild) {
|
|
14357
|
+
code.prependRight(firstChild.start, `{ children: ${hasMultipleChildren ? '[' : ''}`);
|
|
14358
|
+
if (hasMultipleChildren) {
|
|
14359
|
+
code.appendLeft(closingFragment.start, ']');
|
|
14360
|
+
}
|
|
14361
|
+
code.appendLeft(childrenEnd, ' }');
|
|
14362
|
+
}
|
|
14363
|
+
else {
|
|
14364
|
+
code.appendLeft(openingFragment.end, ', {}');
|
|
14365
|
+
}
|
|
14366
|
+
closingFragment.render(code, options);
|
|
14367
|
+
}
|
|
14368
|
+
}
|
|
14369
|
+
|
|
14370
|
+
class JSXMemberExpression extends NodeBase {
|
|
14371
|
+
}
|
|
14372
|
+
|
|
14373
|
+
class JSXNamespacedName extends NodeBase {
|
|
14374
|
+
}
|
|
14375
|
+
|
|
14376
|
+
class JSXOpeningElement extends NodeBase {
|
|
14377
|
+
render(code, options, { jsxMode = this.scope.context.options.jsx.mode } = {}) {
|
|
14378
|
+
this.name.render(code, options);
|
|
14379
|
+
for (const attribute of this.attributes) {
|
|
14380
|
+
attribute.render(code, options, { jsxMode });
|
|
14381
|
+
}
|
|
14382
|
+
}
|
|
14383
|
+
}
|
|
14384
|
+
|
|
14385
|
+
class JSXOpeningFragment extends NodeBase {
|
|
14386
|
+
constructor() {
|
|
14387
|
+
super(...arguments);
|
|
14388
|
+
this.fragment = null;
|
|
14389
|
+
this.fragmentVariable = null;
|
|
14390
|
+
}
|
|
14391
|
+
include(context, includeChildrenRecursively) {
|
|
14392
|
+
if (!this.included) {
|
|
14393
|
+
const jsx = this.scope.context.options.jsx;
|
|
14394
|
+
if (jsx.mode === 'automatic') {
|
|
14395
|
+
this.fragment = 'Fragment';
|
|
14396
|
+
this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this);
|
|
14397
|
+
}
|
|
14398
|
+
else {
|
|
14399
|
+
const { fragment, importSource, mode } = jsx;
|
|
14400
|
+
if (fragment != null) {
|
|
14401
|
+
this.fragment = fragment;
|
|
14402
|
+
this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this);
|
|
14403
|
+
}
|
|
14404
|
+
}
|
|
14405
|
+
}
|
|
14406
|
+
super.include(context, includeChildrenRecursively);
|
|
14407
|
+
}
|
|
14408
|
+
render(code, options) {
|
|
14409
|
+
const { mode } = this.scope.context.options.jsx;
|
|
14410
|
+
if (mode !== 'preserve') {
|
|
14411
|
+
const { snippets: { getPropertyAccess }, useOriginalName } = options;
|
|
14412
|
+
const [, ...nestedFragment] = this.fragment.split('.');
|
|
14413
|
+
const fragment = [
|
|
14414
|
+
this.fragmentVariable.getName(getPropertyAccess, useOriginalName),
|
|
14415
|
+
...nestedFragment
|
|
14416
|
+
].join('.');
|
|
14417
|
+
code.update(this.start, this.end, fragment);
|
|
14418
|
+
}
|
|
14419
|
+
}
|
|
14420
|
+
}
|
|
14421
|
+
|
|
14422
|
+
class JSXSpreadChild extends NodeBase {
|
|
14423
|
+
render(code, options) {
|
|
14424
|
+
super.render(code, options);
|
|
14425
|
+
const { mode } = this.scope.context.options.jsx;
|
|
14426
|
+
if (mode !== 'preserve') {
|
|
14427
|
+
code.overwrite(this.start, this.expression.start, '...', { contentOnly: true });
|
|
14428
|
+
code.overwrite(this.expression.end, this.end, '', { contentOnly: true });
|
|
14429
|
+
}
|
|
14430
|
+
}
|
|
14431
|
+
}
|
|
14432
|
+
|
|
14433
|
+
class JSXText extends NodeBase {
|
|
14434
|
+
render(code) {
|
|
14435
|
+
const { mode } = this.scope.context.options.jsx;
|
|
14436
|
+
if (mode !== 'preserve') {
|
|
14437
|
+
code.overwrite(this.start, this.end, JSON.stringify(this.value), {
|
|
14438
|
+
contentOnly: true
|
|
14439
|
+
});
|
|
14440
|
+
}
|
|
14441
|
+
}
|
|
14442
|
+
}
|
|
14443
|
+
|
|
13834
14444
|
class LabeledStatement extends NodeBase {
|
|
13835
14445
|
hasEffects(context) {
|
|
13836
14446
|
const { brokenFlow, includedLabels } = context;
|
|
@@ -15159,6 +15769,21 @@ const nodeTypeStrings = [
|
|
|
15159
15769
|
'ImportExpression',
|
|
15160
15770
|
'ImportNamespaceSpecifier',
|
|
15161
15771
|
'ImportSpecifier',
|
|
15772
|
+
'JSXAttribute',
|
|
15773
|
+
'JSXClosingElement',
|
|
15774
|
+
'JSXClosingFragment',
|
|
15775
|
+
'JSXElement',
|
|
15776
|
+
'JSXEmptyExpression',
|
|
15777
|
+
'JSXExpressionContainer',
|
|
15778
|
+
'JSXFragment',
|
|
15779
|
+
'JSXIdentifier',
|
|
15780
|
+
'JSXMemberExpression',
|
|
15781
|
+
'JSXNamespacedName',
|
|
15782
|
+
'JSXOpeningElement',
|
|
15783
|
+
'JSXOpeningFragment',
|
|
15784
|
+
'JSXSpreadAttribute',
|
|
15785
|
+
'JSXSpreadChild',
|
|
15786
|
+
'JSXText',
|
|
15162
15787
|
'LabeledStatement',
|
|
15163
15788
|
'Literal',
|
|
15164
15789
|
'Literal',
|
|
@@ -15241,6 +15866,21 @@ const nodeConstructors$1 = [
|
|
|
15241
15866
|
ImportExpression,
|
|
15242
15867
|
ImportNamespaceSpecifier,
|
|
15243
15868
|
ImportSpecifier,
|
|
15869
|
+
JSXAttribute,
|
|
15870
|
+
JSXClosingElement,
|
|
15871
|
+
JSXClosingFragment,
|
|
15872
|
+
JSXElement,
|
|
15873
|
+
JSXEmptyExpression,
|
|
15874
|
+
JSXExpressionContainer,
|
|
15875
|
+
JSXFragment,
|
|
15876
|
+
JSXIdentifier,
|
|
15877
|
+
JSXMemberExpression,
|
|
15878
|
+
JSXNamespacedName,
|
|
15879
|
+
JSXOpeningElement,
|
|
15880
|
+
JSXOpeningFragment,
|
|
15881
|
+
JSXSpreadAttribute,
|
|
15882
|
+
JSXSpreadChild,
|
|
15883
|
+
JSXText,
|
|
15244
15884
|
LabeledStatement,
|
|
15245
15885
|
Literal,
|
|
15246
15886
|
Literal,
|
|
@@ -15547,6 +16187,74 @@ const bufferParsers = [
|
|
|
15547
16187
|
node.imported =
|
|
15548
16188
|
importedPosition === 0 ? node.local : convertNode(node, scope, importedPosition, buffer);
|
|
15549
16189
|
},
|
|
16190
|
+
function jsxAttribute(node, position, buffer) {
|
|
16191
|
+
const { scope } = node;
|
|
16192
|
+
node.name = convertNode(node, scope, buffer[position], buffer);
|
|
16193
|
+
const valuePosition = buffer[position + 1];
|
|
16194
|
+
node.value = valuePosition === 0 ? null : convertNode(node, scope, valuePosition, buffer);
|
|
16195
|
+
},
|
|
16196
|
+
function jsxClosingElement(node, position, buffer) {
|
|
16197
|
+
const { scope } = node;
|
|
16198
|
+
node.name = convertNode(node, scope, buffer[position], buffer);
|
|
16199
|
+
},
|
|
16200
|
+
function jsxClosingFragment() { },
|
|
16201
|
+
function jsxElement(node, position, buffer) {
|
|
16202
|
+
const { scope } = node;
|
|
16203
|
+
node.openingElement = convertNode(node, scope, buffer[position], buffer);
|
|
16204
|
+
node.children = convertNodeList(node, scope, buffer[position + 1], buffer);
|
|
16205
|
+
const closingElementPosition = buffer[position + 2];
|
|
16206
|
+
node.closingElement =
|
|
16207
|
+
closingElementPosition === 0
|
|
16208
|
+
? null
|
|
16209
|
+
: convertNode(node, scope, closingElementPosition, buffer);
|
|
16210
|
+
},
|
|
16211
|
+
function jsxEmptyExpression() { },
|
|
16212
|
+
function jsxExpressionContainer(node, position, buffer) {
|
|
16213
|
+
const { scope } = node;
|
|
16214
|
+
node.expression = convertNode(node, scope, buffer[position], buffer);
|
|
16215
|
+
},
|
|
16216
|
+
function jsxFragment(node, position, buffer) {
|
|
16217
|
+
const { scope } = node;
|
|
16218
|
+
node.openingFragment = convertNode(node, scope, buffer[position], buffer);
|
|
16219
|
+
node.children = convertNodeList(node, scope, buffer[position + 1], buffer);
|
|
16220
|
+
node.closingFragment = convertNode(node, scope, buffer[position + 2], buffer);
|
|
16221
|
+
},
|
|
16222
|
+
function jsxIdentifier(node, position, buffer) {
|
|
16223
|
+
node.name = buffer.convertString(buffer[position]);
|
|
16224
|
+
},
|
|
16225
|
+
function jsxMemberExpression(node, position, buffer) {
|
|
16226
|
+
const { scope } = node;
|
|
16227
|
+
node.object = convertNode(node, scope, buffer[position], buffer);
|
|
16228
|
+
node.property = convertNode(node, scope, buffer[position + 1], buffer);
|
|
16229
|
+
},
|
|
16230
|
+
function jsxNamespacedName(node, position, buffer) {
|
|
16231
|
+
const { scope } = node;
|
|
16232
|
+
node.namespace = convertNode(node, scope, buffer[position], buffer);
|
|
16233
|
+
node.name = convertNode(node, scope, buffer[position + 1], buffer);
|
|
16234
|
+
},
|
|
16235
|
+
function jsxOpeningElement(node, position, buffer) {
|
|
16236
|
+
const { scope } = node;
|
|
16237
|
+
const flags = buffer[position];
|
|
16238
|
+
node.selfClosing = (flags & 1) === 1;
|
|
16239
|
+
node.name = convertNode(node, scope, buffer[position + 1], buffer);
|
|
16240
|
+
node.attributes = convertNodeList(node, scope, buffer[position + 2], buffer);
|
|
16241
|
+
},
|
|
16242
|
+
function jsxOpeningFragment(node) {
|
|
16243
|
+
node.attributes = [];
|
|
16244
|
+
node.selfClosing = false;
|
|
16245
|
+
},
|
|
16246
|
+
function jsxSpreadAttribute(node, position, buffer) {
|
|
16247
|
+
const { scope } = node;
|
|
16248
|
+
node.argument = convertNode(node, scope, buffer[position], buffer);
|
|
16249
|
+
},
|
|
16250
|
+
function jsxSpreadChild(node, position, buffer) {
|
|
16251
|
+
const { scope } = node;
|
|
16252
|
+
node.expression = convertNode(node, scope, buffer[position], buffer);
|
|
16253
|
+
},
|
|
16254
|
+
function jsxText(node, position, buffer) {
|
|
16255
|
+
node.value = buffer.convertString(buffer[position]);
|
|
16256
|
+
node.raw = buffer.convertString(buffer[position + 1]);
|
|
16257
|
+
},
|
|
15550
16258
|
function labeledStatement(node, position, buffer) {
|
|
15551
16259
|
const { scope } = node;
|
|
15552
16260
|
node.label = convertNode(node, scope, buffer[position], buffer);
|
|
@@ -15836,6 +16544,21 @@ const nodeConstructors = {
|
|
|
15836
16544
|
ImportExpression,
|
|
15837
16545
|
ImportNamespaceSpecifier,
|
|
15838
16546
|
ImportSpecifier,
|
|
16547
|
+
JSXAttribute,
|
|
16548
|
+
JSXClosingElement,
|
|
16549
|
+
JSXClosingFragment,
|
|
16550
|
+
JSXElement,
|
|
16551
|
+
JSXEmptyExpression,
|
|
16552
|
+
JSXExpressionContainer,
|
|
16553
|
+
JSXFragment,
|
|
16554
|
+
JSXIdentifier,
|
|
16555
|
+
JSXMemberExpression,
|
|
16556
|
+
JSXNamespacedName,
|
|
16557
|
+
JSXOpeningElement,
|
|
16558
|
+
JSXOpeningFragment,
|
|
16559
|
+
JSXSpreadAttribute,
|
|
16560
|
+
JSXSpreadChild,
|
|
16561
|
+
JSXText,
|
|
15839
16562
|
LabeledStatement,
|
|
15840
16563
|
Literal,
|
|
15841
16564
|
LogicalExpression,
|
|
@@ -16696,11 +17419,13 @@ class Module {
|
|
|
16696
17419
|
addExport: this.addExport.bind(this),
|
|
16697
17420
|
addImport: this.addImport.bind(this),
|
|
16698
17421
|
addImportMeta: this.addImportMeta.bind(this),
|
|
17422
|
+
addImportSource: this.addImportSource.bind(this),
|
|
16699
17423
|
code, // Only needed for debugging
|
|
16700
17424
|
deoptimizationTracker: this.graph.deoptimizationTracker,
|
|
16701
17425
|
error: this.error.bind(this),
|
|
16702
17426
|
fileName, // Needed for warnings
|
|
16703
17427
|
getExports: this.getExports.bind(this),
|
|
17428
|
+
getImportedJsxFactoryVariable: this.getImportedJsxFactoryVariable.bind(this),
|
|
16704
17429
|
getModuleExecIndex: () => this.execIndex,
|
|
16705
17430
|
getModuleName: this.basename.bind(this),
|
|
16706
17431
|
getNodeConstructor: (name) => nodeConstructors[name] || nodeConstructors.UnknownNode,
|
|
@@ -16730,7 +17455,7 @@ class Module {
|
|
|
16730
17455
|
else {
|
|
16731
17456
|
// Measuring asynchronous code does not provide reasonable results
|
|
16732
17457
|
timeEnd('generate ast', 3);
|
|
16733
|
-
const astBuffer = await native_js.parseAsync(code, false);
|
|
17458
|
+
const astBuffer = await native_js.parseAsync(code, false, this.options.jsx !== false);
|
|
16734
17459
|
timeStart('generate ast', 3);
|
|
16735
17460
|
this.ast = convertProgram(astBuffer, programParent, this.scope);
|
|
16736
17461
|
// Make lazy and apply LRU cache to not hog the memory
|
|
@@ -16923,6 +17648,11 @@ class Module {
|
|
|
16923
17648
|
});
|
|
16924
17649
|
}
|
|
16925
17650
|
}
|
|
17651
|
+
addImportSource(importSource) {
|
|
17652
|
+
if (importSource && !this.sourcesWithAttributes.has(importSource)) {
|
|
17653
|
+
this.sourcesWithAttributes.set(importSource, parseAst_js.EMPTY_OBJECT);
|
|
17654
|
+
}
|
|
17655
|
+
}
|
|
16926
17656
|
addImportMeta(node) {
|
|
16927
17657
|
this.importMetas.push(node);
|
|
16928
17658
|
}
|
|
@@ -16986,6 +17716,15 @@ class Module {
|
|
|
16986
17716
|
this.sourcesWithAttributes.set(source, parsedAttributes);
|
|
16987
17717
|
}
|
|
16988
17718
|
}
|
|
17719
|
+
getImportedJsxFactoryVariable(baseName, nodeStart, importSource) {
|
|
17720
|
+
const { id } = this.resolvedIds[importSource];
|
|
17721
|
+
const module = this.graph.modulesById.get(id);
|
|
17722
|
+
const [variable] = module.getVariableForExportName(baseName);
|
|
17723
|
+
if (!variable) {
|
|
17724
|
+
return this.error(parseAst_js.logMissingJsxExport(baseName, id, this.id), nodeStart);
|
|
17725
|
+
}
|
|
17726
|
+
return variable;
|
|
17727
|
+
}
|
|
16989
17728
|
getVariableFromNamespaceReexports(name, importerForSideEffects, searchedNamesAndModules) {
|
|
16990
17729
|
let foundSyntheticDeclaration = null;
|
|
16991
17730
|
const foundInternalDeclarations = new Map();
|
|
@@ -17106,7 +17845,7 @@ class Module {
|
|
|
17106
17845
|
}
|
|
17107
17846
|
tryParse() {
|
|
17108
17847
|
try {
|
|
17109
|
-
return parseAst_js.parseAst(this.info.code);
|
|
17848
|
+
return parseAst_js.parseAst(this.info.code, { jsx: this.options.jsx !== false });
|
|
17110
17849
|
}
|
|
17111
17850
|
catch (error_) {
|
|
17112
17851
|
return this.error(parseAst_js.logModuleParseError(error_, this.id), error_.pos);
|
|
@@ -19730,7 +20469,7 @@ class Bundle {
|
|
|
19730
20469
|
for (const file of Object.values(bundle)) {
|
|
19731
20470
|
if ('code' in file) {
|
|
19732
20471
|
try {
|
|
19733
|
-
parseAst_js.parseAst(file.code);
|
|
20472
|
+
parseAst_js.parseAst(file.code, { jsx: this.inputOptions.jsx !== false });
|
|
19734
20473
|
}
|
|
19735
20474
|
catch (error_) {
|
|
19736
20475
|
this.inputOptions.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logChunkInvalid(file, error_));
|
|
@@ -20805,6 +21544,7 @@ async function normalizeInputOptions(config, watchMode) {
|
|
|
20805
21544
|
experimentalLogSideEffects: config.experimentalLogSideEffects || false,
|
|
20806
21545
|
external: getIdMatcher(config.external),
|
|
20807
21546
|
input: getInput(config),
|
|
21547
|
+
jsx: getJsx(config),
|
|
20808
21548
|
logLevel,
|
|
20809
21549
|
makeAbsoluteExternalsRelative: config.makeAbsoluteExternalsRelative ?? 'ifRelativeSource',
|
|
20810
21550
|
maxParallelFileOps,
|
|
@@ -20850,6 +21590,46 @@ const getInput = (config) => {
|
|
|
20850
21590
|
const configInput = config.input;
|
|
20851
21591
|
return configInput == null ? [] : typeof configInput === 'string' ? [configInput] : configInput;
|
|
20852
21592
|
};
|
|
21593
|
+
const getJsx = (config) => {
|
|
21594
|
+
const configJsx = config.jsx;
|
|
21595
|
+
if (!configJsx)
|
|
21596
|
+
return false;
|
|
21597
|
+
const configWithPreset = getOptionWithPreset(configJsx, jsxPresets, 'jsx', parseAst_js.URL_JSX, 'false, ');
|
|
21598
|
+
const { factory, importSource, mode } = configWithPreset;
|
|
21599
|
+
switch (mode) {
|
|
21600
|
+
case 'automatic': {
|
|
21601
|
+
return {
|
|
21602
|
+
factory: factory || 'React.createElement',
|
|
21603
|
+
importSource: importSource || 'react',
|
|
21604
|
+
jsxImportSource: configWithPreset.jsxImportSource || 'react/jsx-runtime',
|
|
21605
|
+
mode: 'automatic'
|
|
21606
|
+
};
|
|
21607
|
+
}
|
|
21608
|
+
case 'preserve': {
|
|
21609
|
+
if (importSource && !(factory || configWithPreset.fragment)) {
|
|
21610
|
+
parseAst_js.error(parseAst_js.logInvalidOption('jsx', parseAst_js.URL_JSX, 'when preserving JSX and specifying an importSource, you also need to specify a factory or fragment'));
|
|
21611
|
+
}
|
|
21612
|
+
return {
|
|
21613
|
+
factory: factory || null,
|
|
21614
|
+
fragment: configWithPreset.fragment || null,
|
|
21615
|
+
importSource: importSource || null,
|
|
21616
|
+
mode: 'preserve'
|
|
21617
|
+
};
|
|
21618
|
+
}
|
|
21619
|
+
// case 'classic':
|
|
21620
|
+
default: {
|
|
21621
|
+
if (mode && mode !== 'classic') {
|
|
21622
|
+
parseAst_js.error(parseAst_js.logInvalidOption('jsx.mode', parseAst_js.URL_JSX, 'mode must be "automatic", "classic" or "preserve"', mode));
|
|
21623
|
+
}
|
|
21624
|
+
return {
|
|
21625
|
+
factory: factory || 'React.createElement',
|
|
21626
|
+
fragment: configWithPreset.fragment || 'React.Fragment',
|
|
21627
|
+
importSource: importSource || null,
|
|
21628
|
+
mode: 'classic'
|
|
21629
|
+
};
|
|
21630
|
+
}
|
|
21631
|
+
}
|
|
21632
|
+
};
|
|
20853
21633
|
const getMaxParallelFileOps = (config) => {
|
|
20854
21634
|
const maxParallelFileOps = config.maxParallelFileOps;
|
|
20855
21635
|
if (typeof maxParallelFileOps === 'number') {
|