@rollup/wasm-node 4.23.0 → 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 +808 -89
- package/dist/es/shared/parseAst.js +150 -6
- 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 +37 -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 +151 -5
- package/dist/shared/rollup.js +807 -88
- 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 +2 -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)) {
|
|
@@ -698,6 +698,32 @@ const treeshakePresets = {
|
|
|
698
698
|
unknownGlobalSideEffects: false
|
|
699
699
|
}
|
|
700
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
|
+
};
|
|
701
727
|
const generatedCodePresets = {
|
|
702
728
|
es2015: {
|
|
703
729
|
arrowFunctions: true,
|
|
@@ -1260,6 +1286,7 @@ function mergeInputOptions(config, overrides, plugins, log, onLog) {
|
|
|
1260
1286
|
experimentalLogSideEffects: getOption('experimentalLogSideEffects'),
|
|
1261
1287
|
external: getExternal(config, overrides),
|
|
1262
1288
|
input: getOption('input') || [],
|
|
1289
|
+
jsx: getObjectOption(config, overrides, 'jsx', objectifyOptionWithPresets(jsxPresets, 'jsx', parseAst_js.URL_JSX, 'false, ')),
|
|
1263
1290
|
logLevel: getOption('logLevel'),
|
|
1264
1291
|
makeAbsoluteExternalsRelative: getOption('makeAbsoluteExternalsRelative'),
|
|
1265
1292
|
maxParallelFileOps: getOption('maxParallelFileOps'),
|
|
@@ -3711,6 +3738,7 @@ class Variable extends ExpressionEntity {
|
|
|
3711
3738
|
this.name = name;
|
|
3712
3739
|
this.alwaysRendered = false;
|
|
3713
3740
|
this.forbiddenNames = null;
|
|
3741
|
+
this.globalName = null;
|
|
3714
3742
|
this.initReached = false;
|
|
3715
3743
|
this.isId = false;
|
|
3716
3744
|
this.kind = null;
|
|
@@ -3756,6 +3784,9 @@ class Variable extends ExpressionEntity {
|
|
|
3756
3784
|
this.name);
|
|
3757
3785
|
}
|
|
3758
3786
|
getName(getPropertyAccess, useOriginalName) {
|
|
3787
|
+
if (this.globalName) {
|
|
3788
|
+
return this.globalName;
|
|
3789
|
+
}
|
|
3759
3790
|
if (useOriginalName?.(this)) {
|
|
3760
3791
|
return this.name;
|
|
3761
3792
|
}
|
|
@@ -3769,10 +3800,10 @@ class Variable extends ExpressionEntity {
|
|
|
3769
3800
|
return type !== INTERACTION_ACCESSED || path.length > 0;
|
|
3770
3801
|
}
|
|
3771
3802
|
/**
|
|
3772
|
-
* Marks this variable as being part of the bundle, which is usually the case
|
|
3773
|
-
* its identifiers becomes part of the bundle. Returns true if it
|
|
3774
|
-
* previously.
|
|
3775
|
-
*
|
|
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.
|
|
3776
3807
|
*/
|
|
3777
3808
|
include() {
|
|
3778
3809
|
this.included = true;
|
|
@@ -4258,6 +4289,21 @@ const childNodeKeys = {
|
|
|
4258
4289
|
ImportExpression: ['source', 'options'],
|
|
4259
4290
|
ImportNamespaceSpecifier: ['local'],
|
|
4260
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: [],
|
|
4261
4307
|
LabeledStatement: ['label', 'body'],
|
|
4262
4308
|
Literal: [],
|
|
4263
4309
|
LogicalExpression: ['left', 'right'],
|
|
@@ -6372,11 +6418,11 @@ class LocalVariable extends Variable {
|
|
|
6372
6418
|
}
|
|
6373
6419
|
|
|
6374
6420
|
const tdzVariableKinds = new Set(['class', 'const', 'let', 'var', 'using', 'await using']);
|
|
6375
|
-
class
|
|
6421
|
+
class IdentifierBase extends NodeBase {
|
|
6376
6422
|
constructor() {
|
|
6377
6423
|
super(...arguments);
|
|
6378
6424
|
this.variable = null;
|
|
6379
|
-
this.
|
|
6425
|
+
this.isVariableReference = false;
|
|
6380
6426
|
}
|
|
6381
6427
|
get isTDZAccess() {
|
|
6382
6428
|
if (!isFlagSet(this.flags, 4 /* Flag.tdzAccessDefined */)) {
|
|
@@ -6388,55 +6434,6 @@ class Identifier extends NodeBase {
|
|
|
6388
6434
|
this.flags = setFlag(this.flags, 4 /* Flag.tdzAccessDefined */, true);
|
|
6389
6435
|
this.flags = setFlag(this.flags, 8 /* Flag.tdzAccess */, value);
|
|
6390
6436
|
}
|
|
6391
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
6392
|
-
if (exportNamesByVariable.has(this.variable)) {
|
|
6393
|
-
variables.push(this.variable);
|
|
6394
|
-
}
|
|
6395
|
-
}
|
|
6396
|
-
bind() {
|
|
6397
|
-
if (!this.variable && is_reference(this, this.parent)) {
|
|
6398
|
-
this.variable = this.scope.findVariable(this.name);
|
|
6399
|
-
this.variable.addReference(this);
|
|
6400
|
-
this.isReferenceVariable = true;
|
|
6401
|
-
}
|
|
6402
|
-
}
|
|
6403
|
-
declare(kind, init) {
|
|
6404
|
-
let variable;
|
|
6405
|
-
const { treeshake } = this.scope.context.options;
|
|
6406
|
-
switch (kind) {
|
|
6407
|
-
case 'var': {
|
|
6408
|
-
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
6409
|
-
if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
|
|
6410
|
-
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
6411
|
-
variable.markInitializersForDeoptimization();
|
|
6412
|
-
}
|
|
6413
|
-
break;
|
|
6414
|
-
}
|
|
6415
|
-
case 'function': {
|
|
6416
|
-
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
6417
|
-
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
6418
|
-
break;
|
|
6419
|
-
}
|
|
6420
|
-
case 'let':
|
|
6421
|
-
case 'const':
|
|
6422
|
-
case 'using':
|
|
6423
|
-
case 'await using':
|
|
6424
|
-
case 'class': {
|
|
6425
|
-
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
6426
|
-
break;
|
|
6427
|
-
}
|
|
6428
|
-
case 'parameter': {
|
|
6429
|
-
variable = this.scope.addParameterDeclaration(this);
|
|
6430
|
-
break;
|
|
6431
|
-
}
|
|
6432
|
-
/* istanbul ignore next */
|
|
6433
|
-
default: {
|
|
6434
|
-
/* istanbul ignore next */
|
|
6435
|
-
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
6436
|
-
}
|
|
6437
|
-
}
|
|
6438
|
-
return [(this.variable = variable)];
|
|
6439
|
-
}
|
|
6440
6437
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
6441
6438
|
this.variable.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
6442
6439
|
}
|
|
@@ -6527,32 +6524,6 @@ class Identifier extends NodeBase {
|
|
|
6527
6524
|
}
|
|
6528
6525
|
return (this.isTDZAccess = false);
|
|
6529
6526
|
}
|
|
6530
|
-
markDeclarationReached() {
|
|
6531
|
-
this.variable.initReached = true;
|
|
6532
|
-
}
|
|
6533
|
-
render(code, { snippets: { getPropertyAccess }, useOriginalName }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = parseAst_js.BLANK) {
|
|
6534
|
-
if (this.variable) {
|
|
6535
|
-
const name = this.variable.getName(getPropertyAccess, useOriginalName);
|
|
6536
|
-
if (name !== this.name) {
|
|
6537
|
-
code.overwrite(this.start, this.end, name, {
|
|
6538
|
-
contentOnly: true,
|
|
6539
|
-
storeName: true
|
|
6540
|
-
});
|
|
6541
|
-
if (isShorthandProperty) {
|
|
6542
|
-
code.prependRight(this.start, `${this.name}: `);
|
|
6543
|
-
}
|
|
6544
|
-
}
|
|
6545
|
-
// In strict mode, any variable named "eval" must be the actual "eval" function
|
|
6546
|
-
if (name === 'eval' &&
|
|
6547
|
-
renderedParentType === parseAst_js.CallExpression &&
|
|
6548
|
-
isCalleeOfRenderedParent) {
|
|
6549
|
-
code.appendRight(this.start, '0, ');
|
|
6550
|
-
}
|
|
6551
|
-
}
|
|
6552
|
-
}
|
|
6553
|
-
disallowImportReassignment() {
|
|
6554
|
-
return this.scope.context.error(parseAst_js.logIllegalImportReassignment(this.name, this.scope.context.module.id), this.start);
|
|
6555
|
-
}
|
|
6556
6527
|
applyDeoptimizations() {
|
|
6557
6528
|
this.deoptimized = true;
|
|
6558
6529
|
if (this.variable instanceof LocalVariable) {
|
|
@@ -6565,11 +6536,14 @@ class Identifier extends NodeBase {
|
|
|
6565
6536
|
this.variable.consolidateInitializers();
|
|
6566
6537
|
this.scope.context.requestTreeshakingPass();
|
|
6567
6538
|
}
|
|
6568
|
-
if (this.
|
|
6539
|
+
if (this.isVariableReference) {
|
|
6569
6540
|
this.variable.addUsedPlace(this);
|
|
6570
6541
|
this.scope.context.requestTreeshakingPass();
|
|
6571
6542
|
}
|
|
6572
6543
|
}
|
|
6544
|
+
disallowImportReassignment() {
|
|
6545
|
+
return this.scope.context.error(parseAst_js.logIllegalImportReassignment(this.name, this.scope.context.module.id), this.start);
|
|
6546
|
+
}
|
|
6573
6547
|
getVariableRespectingTDZ() {
|
|
6574
6548
|
if (this.isPossibleTDZ()) {
|
|
6575
6549
|
return UNKNOWN_EXPRESSION;
|
|
@@ -6600,6 +6574,85 @@ function closestParentFunctionOrProgram(node) {
|
|
|
6600
6574
|
return node;
|
|
6601
6575
|
}
|
|
6602
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
|
+
|
|
6603
6656
|
function getSafeName(baseName, usedNames, forbiddenNames) {
|
|
6604
6657
|
let safeName = baseName;
|
|
6605
6658
|
let count = 1;
|
|
@@ -6728,6 +6781,11 @@ class ChildScope extends Scope {
|
|
|
6728
6781
|
findLexicalBoundary() {
|
|
6729
6782
|
return this.parent.findLexicalBoundary();
|
|
6730
6783
|
}
|
|
6784
|
+
findGlobal(name) {
|
|
6785
|
+
const variable = this.parent.findVariable(name);
|
|
6786
|
+
this.accessedOutsideVariables.set(name, variable);
|
|
6787
|
+
return variable;
|
|
6788
|
+
}
|
|
6731
6789
|
findVariable(name) {
|
|
6732
6790
|
const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
|
|
6733
6791
|
if (knownVariable) {
|
|
@@ -13892,6 +13950,497 @@ class ImportSpecifier extends NodeBase {
|
|
|
13892
13950
|
applyDeoptimizations() { }
|
|
13893
13951
|
}
|
|
13894
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
|
+
|
|
13895
14444
|
class LabeledStatement extends NodeBase {
|
|
13896
14445
|
hasEffects(context) {
|
|
13897
14446
|
const { brokenFlow, includedLabels } = context;
|
|
@@ -15220,6 +15769,21 @@ const nodeTypeStrings = [
|
|
|
15220
15769
|
'ImportExpression',
|
|
15221
15770
|
'ImportNamespaceSpecifier',
|
|
15222
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',
|
|
15223
15787
|
'LabeledStatement',
|
|
15224
15788
|
'Literal',
|
|
15225
15789
|
'Literal',
|
|
@@ -15302,6 +15866,21 @@ const nodeConstructors$1 = [
|
|
|
15302
15866
|
ImportExpression,
|
|
15303
15867
|
ImportNamespaceSpecifier,
|
|
15304
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,
|
|
15305
15884
|
LabeledStatement,
|
|
15306
15885
|
Literal,
|
|
15307
15886
|
Literal,
|
|
@@ -15608,6 +16187,74 @@ const bufferParsers = [
|
|
|
15608
16187
|
node.imported =
|
|
15609
16188
|
importedPosition === 0 ? node.local : convertNode(node, scope, importedPosition, buffer);
|
|
15610
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
|
+
},
|
|
15611
16258
|
function labeledStatement(node, position, buffer) {
|
|
15612
16259
|
const { scope } = node;
|
|
15613
16260
|
node.label = convertNode(node, scope, buffer[position], buffer);
|
|
@@ -15897,6 +16544,21 @@ const nodeConstructors = {
|
|
|
15897
16544
|
ImportExpression,
|
|
15898
16545
|
ImportNamespaceSpecifier,
|
|
15899
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,
|
|
15900
16562
|
LabeledStatement,
|
|
15901
16563
|
Literal,
|
|
15902
16564
|
LogicalExpression,
|
|
@@ -16757,11 +17419,13 @@ class Module {
|
|
|
16757
17419
|
addExport: this.addExport.bind(this),
|
|
16758
17420
|
addImport: this.addImport.bind(this),
|
|
16759
17421
|
addImportMeta: this.addImportMeta.bind(this),
|
|
17422
|
+
addImportSource: this.addImportSource.bind(this),
|
|
16760
17423
|
code, // Only needed for debugging
|
|
16761
17424
|
deoptimizationTracker: this.graph.deoptimizationTracker,
|
|
16762
17425
|
error: this.error.bind(this),
|
|
16763
17426
|
fileName, // Needed for warnings
|
|
16764
17427
|
getExports: this.getExports.bind(this),
|
|
17428
|
+
getImportedJsxFactoryVariable: this.getImportedJsxFactoryVariable.bind(this),
|
|
16765
17429
|
getModuleExecIndex: () => this.execIndex,
|
|
16766
17430
|
getModuleName: this.basename.bind(this),
|
|
16767
17431
|
getNodeConstructor: (name) => nodeConstructors[name] || nodeConstructors.UnknownNode,
|
|
@@ -16791,7 +17455,7 @@ class Module {
|
|
|
16791
17455
|
else {
|
|
16792
17456
|
// Measuring asynchronous code does not provide reasonable results
|
|
16793
17457
|
timeEnd('generate ast', 3);
|
|
16794
|
-
const astBuffer = await native_js.parseAsync(code, false);
|
|
17458
|
+
const astBuffer = await native_js.parseAsync(code, false, this.options.jsx !== false);
|
|
16795
17459
|
timeStart('generate ast', 3);
|
|
16796
17460
|
this.ast = convertProgram(astBuffer, programParent, this.scope);
|
|
16797
17461
|
// Make lazy and apply LRU cache to not hog the memory
|
|
@@ -16984,6 +17648,11 @@ class Module {
|
|
|
16984
17648
|
});
|
|
16985
17649
|
}
|
|
16986
17650
|
}
|
|
17651
|
+
addImportSource(importSource) {
|
|
17652
|
+
if (importSource && !this.sourcesWithAttributes.has(importSource)) {
|
|
17653
|
+
this.sourcesWithAttributes.set(importSource, parseAst_js.EMPTY_OBJECT);
|
|
17654
|
+
}
|
|
17655
|
+
}
|
|
16987
17656
|
addImportMeta(node) {
|
|
16988
17657
|
this.importMetas.push(node);
|
|
16989
17658
|
}
|
|
@@ -17047,6 +17716,15 @@ class Module {
|
|
|
17047
17716
|
this.sourcesWithAttributes.set(source, parsedAttributes);
|
|
17048
17717
|
}
|
|
17049
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
|
+
}
|
|
17050
17728
|
getVariableFromNamespaceReexports(name, importerForSideEffects, searchedNamesAndModules) {
|
|
17051
17729
|
let foundSyntheticDeclaration = null;
|
|
17052
17730
|
const foundInternalDeclarations = new Map();
|
|
@@ -17167,7 +17845,7 @@ class Module {
|
|
|
17167
17845
|
}
|
|
17168
17846
|
tryParse() {
|
|
17169
17847
|
try {
|
|
17170
|
-
return parseAst_js.parseAst(this.info.code);
|
|
17848
|
+
return parseAst_js.parseAst(this.info.code, { jsx: this.options.jsx !== false });
|
|
17171
17849
|
}
|
|
17172
17850
|
catch (error_) {
|
|
17173
17851
|
return this.error(parseAst_js.logModuleParseError(error_, this.id), error_.pos);
|
|
@@ -19791,7 +20469,7 @@ class Bundle {
|
|
|
19791
20469
|
for (const file of Object.values(bundle)) {
|
|
19792
20470
|
if ('code' in file) {
|
|
19793
20471
|
try {
|
|
19794
|
-
parseAst_js.parseAst(file.code);
|
|
20472
|
+
parseAst_js.parseAst(file.code, { jsx: this.inputOptions.jsx !== false });
|
|
19795
20473
|
}
|
|
19796
20474
|
catch (error_) {
|
|
19797
20475
|
this.inputOptions.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logChunkInvalid(file, error_));
|
|
@@ -20866,6 +21544,7 @@ async function normalizeInputOptions(config, watchMode) {
|
|
|
20866
21544
|
experimentalLogSideEffects: config.experimentalLogSideEffects || false,
|
|
20867
21545
|
external: getIdMatcher(config.external),
|
|
20868
21546
|
input: getInput(config),
|
|
21547
|
+
jsx: getJsx(config),
|
|
20869
21548
|
logLevel,
|
|
20870
21549
|
makeAbsoluteExternalsRelative: config.makeAbsoluteExternalsRelative ?? 'ifRelativeSource',
|
|
20871
21550
|
maxParallelFileOps,
|
|
@@ -20911,6 +21590,46 @@ const getInput = (config) => {
|
|
|
20911
21590
|
const configInput = config.input;
|
|
20912
21591
|
return configInput == null ? [] : typeof configInput === 'string' ? [configInput] : configInput;
|
|
20913
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
|
+
};
|
|
20914
21633
|
const getMaxParallelFileOps = (config) => {
|
|
20915
21634
|
const maxParallelFileOps = config.maxParallelFileOps;
|
|
20916
21635
|
if (typeof maxParallelFileOps === 'number') {
|