@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.
@@ -1,13 +1,13 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.22.5
4
- Fri, 27 Sep 2024 11:47:46 GMT - commit bc7780c322e134492f40a76bf64afe561670425c
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
 
8
8
  Released under the MIT License.
9
9
  */
10
- import { ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, LOGLEVEL_WARN, logUnusedExternalImports, ANNOTATION_KEY, INVALID_ANNOTATION_KEY, Program as Program$1, BLANK, logIllegalImportReassignment, logRedeclarationError, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, ExpressionStatement as ExpressionStatement$1, logMissingExport, normalize, getImportPath, logMissingNodeBuiltins, logReservedNamespace, error, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, Property as Property$1, logConstVariableReassignError, ArrowFunctionExpression as ArrowFunctionExpression$1, EMPTY_SET, logCannotCallNamespace, logEval, BlockStatement as BlockStatement$1, getRollupError, logParseError, logModuleParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, Identifier as Identifier$1, logThisIsUndefined, getAstBuffer, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, EMPTY_OBJECT, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logSyntheticNamedExportsNeedNamespaceExport, logMissingEntryExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, logCircularReexport, logInvalidFormatForTopLevelAwait, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport, isAbsolute as isAbsolute$1, relative as relative$1, logUnexpectedNamespaceReexport, logEmptyChunk, logMissingGlobalName, logOptimizeChunkStatus, logSourcemapBroken, logConflictingSourcemapSources, logChunkInvalid, logInvalidOption, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logCannotAssignModuleToChunk, logAnonymousPluginCache, logDuplicatePluginName, logUnknownOption, printQuotedStringList, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, logInvalidSetAssetSourceCall, logPluginError, logNoTransformMapOrAstWithoutCode, relativeId, logBadLoader, logExternalModulesCannotBeTransformedToModules, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, logFileNameConflict, logAssetNotFinalisedForFileName, logChunkNotGeneratedForFileName, logInvalidLogPosition, logInputHookInOutputPlugin, logInvalidFunctionPluginHook, logInvalidAddonPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_TREESHAKE, URL_TREESHAKE_MODULESIDEEFFECTS, logInvalidExportOptionValue, warnDeprecation, URL_OUTPUT_INTEROP, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_GENERATEDCODE, URL_OUTPUT_MANUALCHUNKS, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
10
+ import { ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, LOGLEVEL_WARN, logUnusedExternalImports, ANNOTATION_KEY, INVALID_ANNOTATION_KEY, Program as Program$1, logIllegalImportReassignment, BLANK, logRedeclarationError, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, ExpressionStatement as ExpressionStatement$1, logMissingExport, normalize, getImportPath, logMissingNodeBuiltins, logReservedNamespace, error, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, Property as Property$1, logConstVariableReassignError, ArrowFunctionExpression as ArrowFunctionExpression$1, EMPTY_SET, logCannotCallNamespace, logEval, BlockStatement as BlockStatement$1, getRollupError, logParseError, logModuleParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, Identifier as Identifier$1, logThisIsUndefined, getAstBuffer, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, EMPTY_OBJECT, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logSyntheticNamedExportsNeedNamespaceExport, logMissingEntryExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, logCircularReexport, logInvalidFormatForTopLevelAwait, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport, isAbsolute as isAbsolute$1, relative as relative$1, logUnexpectedNamespaceReexport, logEmptyChunk, logMissingGlobalName, logOptimizeChunkStatus, logSourcemapBroken, logConflictingSourcemapSources, logChunkInvalid, logInvalidOption, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logCannotAssignModuleToChunk, logAnonymousPluginCache, logDuplicatePluginName, logUnknownOption, printQuotedStringList, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, logInvalidSetAssetSourceCall, logPluginError, logNoTransformMapOrAstWithoutCode, relativeId, logBadLoader, logExternalModulesCannotBeTransformedToModules, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, warnDeprecation, URL_GENERATEBUNDLE, logFileNameConflict, logAssetNotFinalisedForFileName, logChunkNotGeneratedForFileName, logInvalidLogPosition, logInputHookInOutputPlugin, logInvalidFunctionPluginHook, logInvalidAddonPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_JSX, URL_TREESHAKE, URL_TREESHAKE_MODULESIDEEFFECTS, logInvalidExportOptionValue, URL_OUTPUT_INTEROP, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_GENERATEDCODE, URL_OUTPUT_MANUALCHUNKS, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
11
11
  import { relative, dirname, basename, extname, resolve as resolve$1 } from 'node:path';
12
12
  import require$$0, { posix, win32, isAbsolute, resolve } from 'path';
13
13
  import { parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } from '../../native.js';
@@ -16,7 +16,7 @@ import { performance } from 'node:perf_hooks';
16
16
  import { lstat, realpath, readdir, readFile, mkdir, writeFile } from 'node:fs/promises';
17
17
  import * as tty from 'tty';
18
18
 
19
- var version = "4.22.5";
19
+ var version = "4.24.0";
20
20
 
21
21
  const comma = ','.charCodeAt(0);
22
22
  const semicolon = ';'.charCodeAt(0);
@@ -2182,6 +2182,7 @@ class Variable extends ExpressionEntity {
2182
2182
  this.name = name;
2183
2183
  this.alwaysRendered = false;
2184
2184
  this.forbiddenNames = null;
2185
+ this.globalName = null;
2185
2186
  this.initReached = false;
2186
2187
  this.isId = false;
2187
2188
  this.kind = null;
@@ -2227,6 +2228,9 @@ class Variable extends ExpressionEntity {
2227
2228
  this.name);
2228
2229
  }
2229
2230
  getName(getPropertyAccess, useOriginalName) {
2231
+ if (this.globalName) {
2232
+ return this.globalName;
2233
+ }
2230
2234
  if (useOriginalName?.(this)) {
2231
2235
  return this.name;
2232
2236
  }
@@ -2240,10 +2244,10 @@ class Variable extends ExpressionEntity {
2240
2244
  return type !== INTERACTION_ACCESSED || path.length > 0;
2241
2245
  }
2242
2246
  /**
2243
- * Marks this variable as being part of the bundle, which is usually the case when one of
2244
- * its identifiers becomes part of the bundle. Returns true if it has not been included
2245
- * previously.
2246
- * Once a variable is included, it should take care all its declarations are included.
2247
+ * Marks this variable as being part of the bundle, which is usually the case
2248
+ * when one of its identifiers becomes part of the bundle. Returns true if it
2249
+ * has not been included previously. Once a variable is included, it should
2250
+ * take care all its declarations are included.
2247
2251
  */
2248
2252
  include() {
2249
2253
  this.included = true;
@@ -2731,6 +2735,21 @@ const childNodeKeys = {
2731
2735
  ImportExpression: ['source', 'options'],
2732
2736
  ImportNamespaceSpecifier: ['local'],
2733
2737
  ImportSpecifier: ['imported', 'local'],
2738
+ JSXAttribute: ['name', 'value'],
2739
+ JSXClosingElement: ['name'],
2740
+ JSXClosingFragment: [],
2741
+ JSXElement: ['openingElement', 'children', 'closingElement'],
2742
+ JSXEmptyExpression: [],
2743
+ JSXExpressionContainer: ['expression'],
2744
+ JSXFragment: ['openingFragment', 'children', 'closingFragment'],
2745
+ JSXIdentifier: [],
2746
+ JSXMemberExpression: ['object', 'property'],
2747
+ JSXNamespacedName: ['namespace', 'name'],
2748
+ JSXOpeningElement: ['name', 'attributes'],
2749
+ JSXOpeningFragment: [],
2750
+ JSXSpreadAttribute: ['argument'],
2751
+ JSXSpreadChild: ['expression'],
2752
+ JSXText: [],
2734
2753
  LabeledStatement: ['label', 'body'],
2735
2754
  Literal: [],
2736
2755
  LogicalExpression: ['left', 'right'],
@@ -4845,11 +4864,11 @@ class LocalVariable extends Variable {
4845
4864
  }
4846
4865
 
4847
4866
  const tdzVariableKinds = new Set(['class', 'const', 'let', 'var', 'using', 'await using']);
4848
- class Identifier extends NodeBase {
4867
+ class IdentifierBase extends NodeBase {
4849
4868
  constructor() {
4850
4869
  super(...arguments);
4851
4870
  this.variable = null;
4852
- this.isReferenceVariable = false;
4871
+ this.isVariableReference = false;
4853
4872
  }
4854
4873
  get isTDZAccess() {
4855
4874
  if (!isFlagSet(this.flags, 4 /* Flag.tdzAccessDefined */)) {
@@ -4861,55 +4880,6 @@ class Identifier extends NodeBase {
4861
4880
  this.flags = setFlag(this.flags, 4 /* Flag.tdzAccessDefined */, true);
4862
4881
  this.flags = setFlag(this.flags, 8 /* Flag.tdzAccess */, value);
4863
4882
  }
4864
- addExportedVariables(variables, exportNamesByVariable) {
4865
- if (exportNamesByVariable.has(this.variable)) {
4866
- variables.push(this.variable);
4867
- }
4868
- }
4869
- bind() {
4870
- if (!this.variable && is_reference(this, this.parent)) {
4871
- this.variable = this.scope.findVariable(this.name);
4872
- this.variable.addReference(this);
4873
- this.isReferenceVariable = true;
4874
- }
4875
- }
4876
- declare(kind, init) {
4877
- let variable;
4878
- const { treeshake } = this.scope.context.options;
4879
- switch (kind) {
4880
- case 'var': {
4881
- variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
4882
- if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
4883
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
4884
- variable.markInitializersForDeoptimization();
4885
- }
4886
- break;
4887
- }
4888
- case 'function': {
4889
- // in strict mode, functions are only hoisted within a scope but not across block scopes
4890
- variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
4891
- break;
4892
- }
4893
- case 'let':
4894
- case 'const':
4895
- case 'using':
4896
- case 'await using':
4897
- case 'class': {
4898
- variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
4899
- break;
4900
- }
4901
- case 'parameter': {
4902
- variable = this.scope.addParameterDeclaration(this);
4903
- break;
4904
- }
4905
- /* istanbul ignore next */
4906
- default: {
4907
- /* istanbul ignore next */
4908
- throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
4909
- }
4910
- }
4911
- return [(this.variable = variable)];
4912
- }
4913
4883
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
4914
4884
  this.variable.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
4915
4885
  }
@@ -5000,32 +4970,6 @@ class Identifier extends NodeBase {
5000
4970
  }
5001
4971
  return (this.isTDZAccess = false);
5002
4972
  }
5003
- markDeclarationReached() {
5004
- this.variable.initReached = true;
5005
- }
5006
- render(code, { snippets: { getPropertyAccess }, useOriginalName }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
5007
- if (this.variable) {
5008
- const name = this.variable.getName(getPropertyAccess, useOriginalName);
5009
- if (name !== this.name) {
5010
- code.overwrite(this.start, this.end, name, {
5011
- contentOnly: true,
5012
- storeName: true
5013
- });
5014
- if (isShorthandProperty) {
5015
- code.prependRight(this.start, `${this.name}: `);
5016
- }
5017
- }
5018
- // In strict mode, any variable named "eval" must be the actual "eval" function
5019
- if (name === 'eval' &&
5020
- renderedParentType === CallExpression$1 &&
5021
- isCalleeOfRenderedParent) {
5022
- code.appendRight(this.start, '0, ');
5023
- }
5024
- }
5025
- }
5026
- disallowImportReassignment() {
5027
- return this.scope.context.error(logIllegalImportReassignment(this.name, this.scope.context.module.id), this.start);
5028
- }
5029
4973
  applyDeoptimizations() {
5030
4974
  this.deoptimized = true;
5031
4975
  if (this.variable instanceof LocalVariable) {
@@ -5038,11 +4982,14 @@ class Identifier extends NodeBase {
5038
4982
  this.variable.consolidateInitializers();
5039
4983
  this.scope.context.requestTreeshakingPass();
5040
4984
  }
5041
- if (this.isReferenceVariable) {
4985
+ if (this.isVariableReference) {
5042
4986
  this.variable.addUsedPlace(this);
5043
4987
  this.scope.context.requestTreeshakingPass();
5044
4988
  }
5045
4989
  }
4990
+ disallowImportReassignment() {
4991
+ return this.scope.context.error(logIllegalImportReassignment(this.name, this.scope.context.module.id), this.start);
4992
+ }
5046
4993
  getVariableRespectingTDZ() {
5047
4994
  if (this.isPossibleTDZ()) {
5048
4995
  return UNKNOWN_EXPRESSION;
@@ -5073,6 +5020,85 @@ function closestParentFunctionOrProgram(node) {
5073
5020
  return node;
5074
5021
  }
5075
5022
 
5023
+ class Identifier extends IdentifierBase {
5024
+ constructor() {
5025
+ super(...arguments);
5026
+ this.variable = null;
5027
+ }
5028
+ addExportedVariables(variables, exportNamesByVariable) {
5029
+ if (exportNamesByVariable.has(this.variable)) {
5030
+ variables.push(this.variable);
5031
+ }
5032
+ }
5033
+ bind() {
5034
+ if (!this.variable && is_reference(this, this.parent)) {
5035
+ this.variable = this.scope.findVariable(this.name);
5036
+ this.variable.addReference(this);
5037
+ this.isVariableReference = true;
5038
+ }
5039
+ }
5040
+ declare(kind, init) {
5041
+ let variable;
5042
+ const { treeshake } = this.scope.context.options;
5043
+ switch (kind) {
5044
+ case 'var': {
5045
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5046
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
5047
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
5048
+ variable.markInitializersForDeoptimization();
5049
+ }
5050
+ break;
5051
+ }
5052
+ case 'function': {
5053
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
5054
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5055
+ break;
5056
+ }
5057
+ case 'let':
5058
+ case 'const':
5059
+ case 'using':
5060
+ case 'await using':
5061
+ case 'class': {
5062
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
5063
+ break;
5064
+ }
5065
+ case 'parameter': {
5066
+ variable = this.scope.addParameterDeclaration(this);
5067
+ break;
5068
+ }
5069
+ /* istanbul ignore next */
5070
+ default: {
5071
+ /* istanbul ignore next */
5072
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
5073
+ }
5074
+ }
5075
+ return [(this.variable = variable)];
5076
+ }
5077
+ markDeclarationReached() {
5078
+ this.variable.initReached = true;
5079
+ }
5080
+ render(code, { snippets: { getPropertyAccess }, useOriginalName }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
5081
+ if (this.variable) {
5082
+ const name = this.variable.getName(getPropertyAccess, useOriginalName);
5083
+ if (name !== this.name) {
5084
+ code.overwrite(this.start, this.end, name, {
5085
+ contentOnly: true,
5086
+ storeName: true
5087
+ });
5088
+ if (isShorthandProperty) {
5089
+ code.prependRight(this.start, `${this.name}: `);
5090
+ }
5091
+ }
5092
+ // In strict mode, any variable named "eval" must be the actual "eval" function
5093
+ if (name === 'eval' &&
5094
+ renderedParentType === CallExpression$1 &&
5095
+ isCalleeOfRenderedParent) {
5096
+ code.appendRight(this.start, '0, ');
5097
+ }
5098
+ }
5099
+ }
5100
+ }
5101
+
5076
5102
  const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
5077
5103
  const base = 64;
5078
5104
  function toBase64(value) {
@@ -5213,6 +5239,11 @@ class ChildScope extends Scope {
5213
5239
  findLexicalBoundary() {
5214
5240
  return this.parent.findLexicalBoundary();
5215
5241
  }
5242
+ findGlobal(name) {
5243
+ const variable = this.parent.findVariable(name);
5244
+ this.accessedOutsideVariables.set(name, variable);
5245
+ return variable;
5246
+ }
5216
5247
  findVariable(name) {
5217
5248
  const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
5218
5249
  if (knownVariable) {
@@ -12377,6 +12408,497 @@ class ImportSpecifier extends NodeBase {
12377
12408
  applyDeoptimizations() { }
12378
12409
  }
12379
12410
 
12411
+ class JSXIdentifier extends IdentifierBase {
12412
+ constructor() {
12413
+ super(...arguments);
12414
+ this.isNativeElement = false;
12415
+ }
12416
+ bind() {
12417
+ const type = this.getType();
12418
+ if (type === 0 /* IdentifierType.Reference */) {
12419
+ this.variable = this.scope.findVariable(this.name);
12420
+ this.variable.addReference(this);
12421
+ }
12422
+ else if (type === 1 /* IdentifierType.NativeElementName */) {
12423
+ this.isNativeElement = true;
12424
+ }
12425
+ }
12426
+ render(code, { snippets: { getPropertyAccess }, useOriginalName }) {
12427
+ if (this.variable) {
12428
+ const name = this.variable.getName(getPropertyAccess, useOriginalName);
12429
+ if (name !== this.name) {
12430
+ code.overwrite(this.start, this.end, name, {
12431
+ contentOnly: true,
12432
+ storeName: true
12433
+ });
12434
+ }
12435
+ }
12436
+ else if (this.isNativeElement &&
12437
+ this.scope.context.options.jsx.mode !== 'preserve') {
12438
+ code.update(this.start, this.end, JSON.stringify(this.name));
12439
+ }
12440
+ }
12441
+ getType() {
12442
+ switch (this.parent.type) {
12443
+ case 'JSXOpeningElement':
12444
+ case 'JSXClosingElement': {
12445
+ return this.name.startsWith(this.name.charAt(0).toUpperCase())
12446
+ ? 0 /* IdentifierType.Reference */
12447
+ : 1 /* IdentifierType.NativeElementName */;
12448
+ }
12449
+ case 'JSXMemberExpression': {
12450
+ return this.parent.object === this
12451
+ ? 0 /* IdentifierType.Reference */
12452
+ : 2 /* IdentifierType.Other */;
12453
+ }
12454
+ case 'JSXAttribute':
12455
+ case 'JSXNamespacedName': {
12456
+ return 2 /* IdentifierType.Other */;
12457
+ }
12458
+ default: {
12459
+ /* istanbul ignore next */
12460
+ throw new Error(`Unexpected parent node type for JSXIdentifier: ${this.parent.type}`);
12461
+ }
12462
+ }
12463
+ }
12464
+ }
12465
+
12466
+ class JSXAttribute extends NodeBase {
12467
+ render(code, options, { jsxMode } = BLANK) {
12468
+ super.render(code, options);
12469
+ if (['classic', 'automatic'].includes(jsxMode)) {
12470
+ const { name, value } = this;
12471
+ const key = name instanceof JSXIdentifier ? name.name : `${name.namespace.name}:${name.name.name}`;
12472
+ if (!(jsxMode === 'automatic' && key === 'key')) {
12473
+ const safeKey = stringifyObjectKeyIfNeeded(key);
12474
+ if (key !== safeKey) {
12475
+ code.overwrite(name.start, name.end, safeKey, { contentOnly: true });
12476
+ }
12477
+ if (value) {
12478
+ code.overwrite(name.end, value.start, ': ', { contentOnly: true });
12479
+ }
12480
+ else {
12481
+ code.appendLeft(name.end, ': true');
12482
+ }
12483
+ }
12484
+ }
12485
+ }
12486
+ }
12487
+
12488
+ class JSXClosingBase extends NodeBase {
12489
+ render(code, options) {
12490
+ const { mode } = this.scope.context.options.jsx;
12491
+ if (mode !== 'preserve') {
12492
+ code.overwrite(this.start, this.end, ')', { contentOnly: true });
12493
+ }
12494
+ else {
12495
+ super.render(code, options);
12496
+ }
12497
+ }
12498
+ }
12499
+
12500
+ class JSXClosingElement extends JSXClosingBase {
12501
+ }
12502
+
12503
+ class JSXClosingFragment extends JSXClosingBase {
12504
+ }
12505
+
12506
+ class JSXSpreadAttribute extends NodeBase {
12507
+ render(code, options) {
12508
+ this.argument.render(code, options);
12509
+ const { mode } = this.scope.context.options.jsx;
12510
+ if (mode !== 'preserve') {
12511
+ code.overwrite(this.start, this.argument.start, '', { contentOnly: true });
12512
+ code.overwrite(this.argument.end, this.end, '', { contentOnly: true });
12513
+ }
12514
+ }
12515
+ }
12516
+
12517
+ class JSXEmptyExpression extends NodeBase {
12518
+ }
12519
+
12520
+ class JSXExpressionContainer extends NodeBase {
12521
+ render(code, options) {
12522
+ const { mode } = this.scope.context.options.jsx;
12523
+ if (mode !== 'preserve') {
12524
+ code.remove(this.start, this.expression.start);
12525
+ code.remove(this.expression.end, this.end);
12526
+ }
12527
+ this.expression.render(code, options);
12528
+ }
12529
+ }
12530
+
12531
+ function getRenderedJsxChildren(children) {
12532
+ let renderedChildren = 0;
12533
+ for (const child of children) {
12534
+ if (!(child instanceof JSXExpressionContainer && child.expression instanceof JSXEmptyExpression)) {
12535
+ renderedChildren++;
12536
+ }
12537
+ }
12538
+ return renderedChildren;
12539
+ }
12540
+
12541
+ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
12542
+ const [baseName, nestedName] = factory.split('.');
12543
+ let factoryVariable;
12544
+ if (importSource) {
12545
+ factoryVariable = node.scope.context.getImportedJsxFactoryVariable(nestedName ? 'default' : baseName, node.start, importSource);
12546
+ if (preserve) {
12547
+ // This pretends we are accessing an included global variable of the same name
12548
+ const globalVariable = node.scope.findGlobal(baseName);
12549
+ globalVariable.include();
12550
+ // This excludes this variable from renaming
12551
+ factoryVariable.globalName = baseName;
12552
+ }
12553
+ }
12554
+ else {
12555
+ factoryVariable = node.scope.findGlobal(baseName);
12556
+ }
12557
+ node.scope.context.includeVariableInModule(factoryVariable);
12558
+ if (factoryVariable instanceof LocalVariable) {
12559
+ factoryVariable.consolidateInitializers();
12560
+ factoryVariable.addUsedPlace(node);
12561
+ node.scope.context.requestTreeshakingPass();
12562
+ }
12563
+ return factoryVariable;
12564
+ }
12565
+
12566
+ class JSXElementBase extends NodeBase {
12567
+ constructor() {
12568
+ super(...arguments);
12569
+ this.factoryVariable = null;
12570
+ this.factory = null;
12571
+ }
12572
+ initialise() {
12573
+ super.initialise();
12574
+ const { importSource } = (this.jsxMode = this.getRenderingMode());
12575
+ if (importSource) {
12576
+ this.scope.context.addImportSource(importSource);
12577
+ }
12578
+ }
12579
+ include(context, includeChildrenRecursively) {
12580
+ if (!this.included) {
12581
+ const { factory, importSource, mode } = this.jsxMode;
12582
+ if (factory) {
12583
+ this.factory = factory;
12584
+ this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
12585
+ }
12586
+ }
12587
+ super.include(context, includeChildrenRecursively);
12588
+ }
12589
+ applyDeoptimizations() { }
12590
+ getRenderingMode() {
12591
+ const jsx = this.scope.context.options.jsx;
12592
+ const { mode, factory, importSource } = jsx;
12593
+ if (mode === 'automatic') {
12594
+ return {
12595
+ factory: getRenderedJsxChildren(this.children) > 1 ? 'jsxs' : 'jsx',
12596
+ importSource: jsx.jsxImportSource,
12597
+ mode
12598
+ };
12599
+ }
12600
+ return { factory, importSource, mode };
12601
+ }
12602
+ renderChildren(code, options, openingEnd) {
12603
+ const { children } = this;
12604
+ let hasMultipleChildren = false;
12605
+ let childrenEnd = openingEnd;
12606
+ let firstChild = null;
12607
+ for (const child of children) {
12608
+ if (child instanceof JSXExpressionContainer &&
12609
+ child.expression instanceof JSXEmptyExpression) {
12610
+ code.remove(childrenEnd, child.end);
12611
+ }
12612
+ else {
12613
+ code.appendLeft(childrenEnd, ', ');
12614
+ child.render(code, options);
12615
+ if (firstChild) {
12616
+ hasMultipleChildren = true;
12617
+ }
12618
+ else {
12619
+ firstChild = child;
12620
+ }
12621
+ }
12622
+ childrenEnd = child.end;
12623
+ }
12624
+ return { childrenEnd, firstChild, hasMultipleChildren };
12625
+ }
12626
+ }
12627
+
12628
+ class JSXElement extends JSXElementBase {
12629
+ render(code, options) {
12630
+ switch (this.jsxMode.mode) {
12631
+ case 'classic': {
12632
+ this.renderClassicMode(code, options);
12633
+ break;
12634
+ }
12635
+ case 'automatic': {
12636
+ this.renderAutomaticMode(code, options);
12637
+ break;
12638
+ }
12639
+ default: {
12640
+ super.render(code, options);
12641
+ }
12642
+ }
12643
+ }
12644
+ getRenderingMode() {
12645
+ const jsx = this.scope.context.options.jsx;
12646
+ const { mode, factory, importSource } = jsx;
12647
+ if (mode === 'automatic') {
12648
+ // In the case there is a key after a spread attribute, we fall back to
12649
+ // classic mode, see https://github.com/facebook/react/issues/20031#issuecomment-710346866
12650
+ // for reasoning.
12651
+ let hasSpread = false;
12652
+ for (const attribute of this.openingElement.attributes) {
12653
+ if (attribute instanceof JSXSpreadAttribute) {
12654
+ hasSpread = true;
12655
+ }
12656
+ else if (hasSpread && attribute.name.name === 'key') {
12657
+ return { factory, importSource, mode: 'classic' };
12658
+ }
12659
+ }
12660
+ }
12661
+ return super.getRenderingMode();
12662
+ }
12663
+ renderClassicMode(code, options) {
12664
+ const { snippets: { getPropertyAccess }, useOriginalName } = options;
12665
+ const { closingElement, end, factory, factoryVariable, openingElement: { end: openingEnd, selfClosing } } = this;
12666
+ const [, ...nestedName] = factory.split('.');
12667
+ const { firstAttribute, hasAttributes, hasSpread, inObject, previousEnd } = this.renderAttributes(code, options, [factoryVariable.getName(getPropertyAccess, useOriginalName), ...nestedName].join('.'), false);
12668
+ this.wrapAttributes(code, inObject, hasAttributes, hasSpread, firstAttribute, 'null', previousEnd);
12669
+ this.renderChildren(code, options, openingEnd);
12670
+ if (selfClosing) {
12671
+ code.appendLeft(end, ')');
12672
+ }
12673
+ else {
12674
+ closingElement.render(code, options);
12675
+ }
12676
+ }
12677
+ renderAutomaticMode(code, options) {
12678
+ const { snippets: { getPropertyAccess }, useOriginalName } = options;
12679
+ const { closingElement, end, factoryVariable, openingElement: { end: openindEnd, selfClosing } } = this;
12680
+ let { firstAttribute, hasAttributes, hasSpread, inObject, keyAttribute, previousEnd } = this.renderAttributes(code, options, factoryVariable.getName(getPropertyAccess, useOriginalName), true);
12681
+ const { firstChild, hasMultipleChildren, childrenEnd } = this.renderChildren(code, options, openindEnd);
12682
+ if (firstChild) {
12683
+ code.prependRight(firstChild.start, `children: ${hasMultipleChildren ? '[' : ''}`);
12684
+ if (!inObject) {
12685
+ code.prependRight(firstChild.start, '{ ');
12686
+ inObject = true;
12687
+ }
12688
+ previousEnd = closingElement.start;
12689
+ if (hasMultipleChildren) {
12690
+ code.appendLeft(previousEnd, ']');
12691
+ }
12692
+ }
12693
+ this.wrapAttributes(code, inObject, hasAttributes || !!firstChild, hasSpread, firstAttribute || firstChild, '{}', childrenEnd);
12694
+ if (keyAttribute) {
12695
+ const { value } = keyAttribute;
12696
+ // This will appear to the left of the moved code...
12697
+ code.appendLeft(childrenEnd, ', ');
12698
+ if (value) {
12699
+ code.move(value.start, value.end, childrenEnd);
12700
+ }
12701
+ else {
12702
+ code.appendLeft(childrenEnd, 'true');
12703
+ }
12704
+ }
12705
+ if (selfClosing) {
12706
+ // Moving the key attribute will also move the parenthesis to the right position
12707
+ code.appendLeft(keyAttribute?.value?.end || end, ')');
12708
+ }
12709
+ else {
12710
+ closingElement.render(code, options);
12711
+ }
12712
+ }
12713
+ renderAttributes(code, options, factoryName, extractKeyAttribute) {
12714
+ const { jsxMode: { mode }, openingElement } = this;
12715
+ const { attributes, end: openingEnd, start: openingStart, name: { start: nameStart, end: nameEnd } } = openingElement;
12716
+ code.update(openingStart, nameStart, `/*#__PURE__*/${factoryName}(`);
12717
+ openingElement.render(code, options, { jsxMode: mode });
12718
+ let keyAttribute = null;
12719
+ let hasSpread = false;
12720
+ let inObject = false;
12721
+ let previousEnd = nameEnd;
12722
+ let hasAttributes = false;
12723
+ let firstAttribute = null;
12724
+ for (const attribute of attributes) {
12725
+ if (attribute instanceof JSXAttribute) {
12726
+ if (extractKeyAttribute && attribute.name.name === 'key') {
12727
+ keyAttribute = attribute;
12728
+ code.remove(previousEnd, attribute.value?.start || attribute.end);
12729
+ continue;
12730
+ }
12731
+ code.appendLeft(previousEnd, ',');
12732
+ if (!inObject) {
12733
+ code.prependRight(attribute.start, '{ ');
12734
+ inObject = true;
12735
+ }
12736
+ hasAttributes = true;
12737
+ }
12738
+ else {
12739
+ if (inObject) {
12740
+ if (hasAttributes) {
12741
+ code.appendLeft(previousEnd, ' ');
12742
+ }
12743
+ code.appendLeft(previousEnd, '},');
12744
+ inObject = false;
12745
+ }
12746
+ else {
12747
+ code.appendLeft(previousEnd, ',');
12748
+ }
12749
+ hasSpread = true;
12750
+ }
12751
+ previousEnd = attribute.end;
12752
+ if (!firstAttribute) {
12753
+ firstAttribute = attribute;
12754
+ }
12755
+ }
12756
+ code.remove(attributes.at(-1)?.end || previousEnd, openingEnd);
12757
+ return { firstAttribute, hasAttributes, hasSpread, inObject, keyAttribute, previousEnd };
12758
+ }
12759
+ wrapAttributes(code, inObject, hasAttributes, hasSpread, firstAttribute, missingAttributesFallback, attributesEnd) {
12760
+ if (inObject) {
12761
+ code.appendLeft(attributesEnd, ' }');
12762
+ }
12763
+ if (hasSpread) {
12764
+ if (hasAttributes) {
12765
+ const { start } = firstAttribute;
12766
+ if (firstAttribute instanceof JSXSpreadAttribute) {
12767
+ code.prependRight(start, '{}, ');
12768
+ }
12769
+ code.prependRight(start, 'Object.assign(');
12770
+ code.appendLeft(attributesEnd, ')');
12771
+ }
12772
+ }
12773
+ else if (!hasAttributes) {
12774
+ code.appendLeft(attributesEnd, `, ${missingAttributesFallback}`);
12775
+ }
12776
+ }
12777
+ }
12778
+
12779
+ class JSXFragment extends JSXElementBase {
12780
+ render(code, options) {
12781
+ switch (this.jsxMode.mode) {
12782
+ case 'classic': {
12783
+ this.renderClassicMode(code, options);
12784
+ break;
12785
+ }
12786
+ case 'automatic': {
12787
+ this.renderAutomaticMode(code, options);
12788
+ break;
12789
+ }
12790
+ default: {
12791
+ super.render(code, options);
12792
+ }
12793
+ }
12794
+ }
12795
+ renderClassicMode(code, options) {
12796
+ const { snippets: { getPropertyAccess }, useOriginalName } = options;
12797
+ const { closingFragment, factory, factoryVariable, openingFragment, start } = this;
12798
+ const [, ...nestedName] = factory.split('.');
12799
+ openingFragment.render(code, options);
12800
+ code.prependRight(start, `/*#__PURE__*/${[
12801
+ factoryVariable.getName(getPropertyAccess, useOriginalName),
12802
+ ...nestedName
12803
+ ].join('.')}(`);
12804
+ code.appendLeft(openingFragment.end, ', null');
12805
+ this.renderChildren(code, options, openingFragment.end);
12806
+ closingFragment.render(code, options);
12807
+ }
12808
+ renderAutomaticMode(code, options) {
12809
+ const { snippets: { getPropertyAccess }, useOriginalName } = options;
12810
+ const { closingFragment, factoryVariable, openingFragment, start } = this;
12811
+ openingFragment.render(code, options);
12812
+ code.prependRight(start, `/*#__PURE__*/${factoryVariable.getName(getPropertyAccess, useOriginalName)}(`);
12813
+ const { firstChild, hasMultipleChildren, childrenEnd } = this.renderChildren(code, options, openingFragment.end);
12814
+ if (firstChild) {
12815
+ code.prependRight(firstChild.start, `{ children: ${hasMultipleChildren ? '[' : ''}`);
12816
+ if (hasMultipleChildren) {
12817
+ code.appendLeft(closingFragment.start, ']');
12818
+ }
12819
+ code.appendLeft(childrenEnd, ' }');
12820
+ }
12821
+ else {
12822
+ code.appendLeft(openingFragment.end, ', {}');
12823
+ }
12824
+ closingFragment.render(code, options);
12825
+ }
12826
+ }
12827
+
12828
+ class JSXMemberExpression extends NodeBase {
12829
+ }
12830
+
12831
+ class JSXNamespacedName extends NodeBase {
12832
+ }
12833
+
12834
+ class JSXOpeningElement extends NodeBase {
12835
+ render(code, options, { jsxMode = this.scope.context.options.jsx.mode } = {}) {
12836
+ this.name.render(code, options);
12837
+ for (const attribute of this.attributes) {
12838
+ attribute.render(code, options, { jsxMode });
12839
+ }
12840
+ }
12841
+ }
12842
+
12843
+ class JSXOpeningFragment extends NodeBase {
12844
+ constructor() {
12845
+ super(...arguments);
12846
+ this.fragment = null;
12847
+ this.fragmentVariable = null;
12848
+ }
12849
+ include(context, includeChildrenRecursively) {
12850
+ if (!this.included) {
12851
+ const jsx = this.scope.context.options.jsx;
12852
+ if (jsx.mode === 'automatic') {
12853
+ this.fragment = 'Fragment';
12854
+ this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this);
12855
+ }
12856
+ else {
12857
+ const { fragment, importSource, mode } = jsx;
12858
+ if (fragment != null) {
12859
+ this.fragment = fragment;
12860
+ this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this);
12861
+ }
12862
+ }
12863
+ }
12864
+ super.include(context, includeChildrenRecursively);
12865
+ }
12866
+ render(code, options) {
12867
+ const { mode } = this.scope.context.options.jsx;
12868
+ if (mode !== 'preserve') {
12869
+ const { snippets: { getPropertyAccess }, useOriginalName } = options;
12870
+ const [, ...nestedFragment] = this.fragment.split('.');
12871
+ const fragment = [
12872
+ this.fragmentVariable.getName(getPropertyAccess, useOriginalName),
12873
+ ...nestedFragment
12874
+ ].join('.');
12875
+ code.update(this.start, this.end, fragment);
12876
+ }
12877
+ }
12878
+ }
12879
+
12880
+ class JSXSpreadChild extends NodeBase {
12881
+ render(code, options) {
12882
+ super.render(code, options);
12883
+ const { mode } = this.scope.context.options.jsx;
12884
+ if (mode !== 'preserve') {
12885
+ code.overwrite(this.start, this.expression.start, '...', { contentOnly: true });
12886
+ code.overwrite(this.expression.end, this.end, '', { contentOnly: true });
12887
+ }
12888
+ }
12889
+ }
12890
+
12891
+ class JSXText extends NodeBase {
12892
+ render(code) {
12893
+ const { mode } = this.scope.context.options.jsx;
12894
+ if (mode !== 'preserve') {
12895
+ code.overwrite(this.start, this.end, JSON.stringify(this.value), {
12896
+ contentOnly: true
12897
+ });
12898
+ }
12899
+ }
12900
+ }
12901
+
12380
12902
  class LabeledStatement extends NodeBase {
12381
12903
  hasEffects(context) {
12382
12904
  const { brokenFlow, includedLabels } = context;
@@ -13705,6 +14227,21 @@ const nodeTypeStrings = [
13705
14227
  'ImportExpression',
13706
14228
  'ImportNamespaceSpecifier',
13707
14229
  'ImportSpecifier',
14230
+ 'JSXAttribute',
14231
+ 'JSXClosingElement',
14232
+ 'JSXClosingFragment',
14233
+ 'JSXElement',
14234
+ 'JSXEmptyExpression',
14235
+ 'JSXExpressionContainer',
14236
+ 'JSXFragment',
14237
+ 'JSXIdentifier',
14238
+ 'JSXMemberExpression',
14239
+ 'JSXNamespacedName',
14240
+ 'JSXOpeningElement',
14241
+ 'JSXOpeningFragment',
14242
+ 'JSXSpreadAttribute',
14243
+ 'JSXSpreadChild',
14244
+ 'JSXText',
13708
14245
  'LabeledStatement',
13709
14246
  'Literal',
13710
14247
  'Literal',
@@ -13787,6 +14324,21 @@ const nodeConstructors$1 = [
13787
14324
  ImportExpression,
13788
14325
  ImportNamespaceSpecifier,
13789
14326
  ImportSpecifier,
14327
+ JSXAttribute,
14328
+ JSXClosingElement,
14329
+ JSXClosingFragment,
14330
+ JSXElement,
14331
+ JSXEmptyExpression,
14332
+ JSXExpressionContainer,
14333
+ JSXFragment,
14334
+ JSXIdentifier,
14335
+ JSXMemberExpression,
14336
+ JSXNamespacedName,
14337
+ JSXOpeningElement,
14338
+ JSXOpeningFragment,
14339
+ JSXSpreadAttribute,
14340
+ JSXSpreadChild,
14341
+ JSXText,
13790
14342
  LabeledStatement,
13791
14343
  Literal,
13792
14344
  Literal,
@@ -14093,6 +14645,74 @@ const bufferParsers = [
14093
14645
  node.imported =
14094
14646
  importedPosition === 0 ? node.local : convertNode(node, scope, importedPosition, buffer);
14095
14647
  },
14648
+ function jsxAttribute(node, position, buffer) {
14649
+ const { scope } = node;
14650
+ node.name = convertNode(node, scope, buffer[position], buffer);
14651
+ const valuePosition = buffer[position + 1];
14652
+ node.value = valuePosition === 0 ? null : convertNode(node, scope, valuePosition, buffer);
14653
+ },
14654
+ function jsxClosingElement(node, position, buffer) {
14655
+ const { scope } = node;
14656
+ node.name = convertNode(node, scope, buffer[position], buffer);
14657
+ },
14658
+ function jsxClosingFragment() { },
14659
+ function jsxElement(node, position, buffer) {
14660
+ const { scope } = node;
14661
+ node.openingElement = convertNode(node, scope, buffer[position], buffer);
14662
+ node.children = convertNodeList(node, scope, buffer[position + 1], buffer);
14663
+ const closingElementPosition = buffer[position + 2];
14664
+ node.closingElement =
14665
+ closingElementPosition === 0
14666
+ ? null
14667
+ : convertNode(node, scope, closingElementPosition, buffer);
14668
+ },
14669
+ function jsxEmptyExpression() { },
14670
+ function jsxExpressionContainer(node, position, buffer) {
14671
+ const { scope } = node;
14672
+ node.expression = convertNode(node, scope, buffer[position], buffer);
14673
+ },
14674
+ function jsxFragment(node, position, buffer) {
14675
+ const { scope } = node;
14676
+ node.openingFragment = convertNode(node, scope, buffer[position], buffer);
14677
+ node.children = convertNodeList(node, scope, buffer[position + 1], buffer);
14678
+ node.closingFragment = convertNode(node, scope, buffer[position + 2], buffer);
14679
+ },
14680
+ function jsxIdentifier(node, position, buffer) {
14681
+ node.name = buffer.convertString(buffer[position]);
14682
+ },
14683
+ function jsxMemberExpression(node, position, buffer) {
14684
+ const { scope } = node;
14685
+ node.object = convertNode(node, scope, buffer[position], buffer);
14686
+ node.property = convertNode(node, scope, buffer[position + 1], buffer);
14687
+ },
14688
+ function jsxNamespacedName(node, position, buffer) {
14689
+ const { scope } = node;
14690
+ node.namespace = convertNode(node, scope, buffer[position], buffer);
14691
+ node.name = convertNode(node, scope, buffer[position + 1], buffer);
14692
+ },
14693
+ function jsxOpeningElement(node, position, buffer) {
14694
+ const { scope } = node;
14695
+ const flags = buffer[position];
14696
+ node.selfClosing = (flags & 1) === 1;
14697
+ node.name = convertNode(node, scope, buffer[position + 1], buffer);
14698
+ node.attributes = convertNodeList(node, scope, buffer[position + 2], buffer);
14699
+ },
14700
+ function jsxOpeningFragment(node) {
14701
+ node.attributes = [];
14702
+ node.selfClosing = false;
14703
+ },
14704
+ function jsxSpreadAttribute(node, position, buffer) {
14705
+ const { scope } = node;
14706
+ node.argument = convertNode(node, scope, buffer[position], buffer);
14707
+ },
14708
+ function jsxSpreadChild(node, position, buffer) {
14709
+ const { scope } = node;
14710
+ node.expression = convertNode(node, scope, buffer[position], buffer);
14711
+ },
14712
+ function jsxText(node, position, buffer) {
14713
+ node.value = buffer.convertString(buffer[position]);
14714
+ node.raw = buffer.convertString(buffer[position + 1]);
14715
+ },
14096
14716
  function labeledStatement(node, position, buffer) {
14097
14717
  const { scope } = node;
14098
14718
  node.label = convertNode(node, scope, buffer[position], buffer);
@@ -14382,6 +15002,21 @@ const nodeConstructors = {
14382
15002
  ImportExpression,
14383
15003
  ImportNamespaceSpecifier,
14384
15004
  ImportSpecifier,
15005
+ JSXAttribute,
15006
+ JSXClosingElement,
15007
+ JSXClosingFragment,
15008
+ JSXElement,
15009
+ JSXEmptyExpression,
15010
+ JSXExpressionContainer,
15011
+ JSXFragment,
15012
+ JSXIdentifier,
15013
+ JSXMemberExpression,
15014
+ JSXNamespacedName,
15015
+ JSXOpeningElement,
15016
+ JSXOpeningFragment,
15017
+ JSXSpreadAttribute,
15018
+ JSXSpreadChild,
15019
+ JSXText,
14385
15020
  LabeledStatement,
14386
15021
  Literal,
14387
15022
  LogicalExpression,
@@ -15249,11 +15884,13 @@ class Module {
15249
15884
  addExport: this.addExport.bind(this),
15250
15885
  addImport: this.addImport.bind(this),
15251
15886
  addImportMeta: this.addImportMeta.bind(this),
15887
+ addImportSource: this.addImportSource.bind(this),
15252
15888
  code, // Only needed for debugging
15253
15889
  deoptimizationTracker: this.graph.deoptimizationTracker,
15254
15890
  error: this.error.bind(this),
15255
15891
  fileName, // Needed for warnings
15256
15892
  getExports: this.getExports.bind(this),
15893
+ getImportedJsxFactoryVariable: this.getImportedJsxFactoryVariable.bind(this),
15257
15894
  getModuleExecIndex: () => this.execIndex,
15258
15895
  getModuleName: this.basename.bind(this),
15259
15896
  getNodeConstructor: (name) => nodeConstructors[name] || nodeConstructors.UnknownNode,
@@ -15283,7 +15920,7 @@ class Module {
15283
15920
  else {
15284
15921
  // Measuring asynchronous code does not provide reasonable results
15285
15922
  timeEnd('generate ast', 3);
15286
- const astBuffer = await parseAsync(code, false);
15923
+ const astBuffer = await parseAsync(code, false, this.options.jsx !== false);
15287
15924
  timeStart('generate ast', 3);
15288
15925
  this.ast = convertProgram(astBuffer, programParent, this.scope);
15289
15926
  // Make lazy and apply LRU cache to not hog the memory
@@ -15476,6 +16113,11 @@ class Module {
15476
16113
  });
15477
16114
  }
15478
16115
  }
16116
+ addImportSource(importSource) {
16117
+ if (importSource && !this.sourcesWithAttributes.has(importSource)) {
16118
+ this.sourcesWithAttributes.set(importSource, EMPTY_OBJECT);
16119
+ }
16120
+ }
15479
16121
  addImportMeta(node) {
15480
16122
  this.importMetas.push(node);
15481
16123
  }
@@ -15539,6 +16181,15 @@ class Module {
15539
16181
  this.sourcesWithAttributes.set(source, parsedAttributes);
15540
16182
  }
15541
16183
  }
16184
+ getImportedJsxFactoryVariable(baseName, nodeStart, importSource) {
16185
+ const { id } = this.resolvedIds[importSource];
16186
+ const module = this.graph.modulesById.get(id);
16187
+ const [variable] = module.getVariableForExportName(baseName);
16188
+ if (!variable) {
16189
+ return this.error(logMissingJsxExport(baseName, id, this.id), nodeStart);
16190
+ }
16191
+ return variable;
16192
+ }
15542
16193
  getVariableFromNamespaceReexports(name, importerForSideEffects, searchedNamesAndModules) {
15543
16194
  let foundSyntheticDeclaration = null;
15544
16195
  const foundInternalDeclarations = new Map();
@@ -15659,7 +16310,7 @@ class Module {
15659
16310
  }
15660
16311
  tryParse() {
15661
16312
  try {
15662
- return parseAst(this.info.code);
16313
+ return parseAst(this.info.code, { jsx: this.options.jsx !== false });
15663
16314
  }
15664
16315
  catch (error_) {
15665
16316
  return this.error(logModuleParseError(error_, this.id), error_.pos);
@@ -18412,7 +19063,7 @@ class Bundle {
18412
19063
  for (const file of Object.values(bundle)) {
18413
19064
  if ('code' in file) {
18414
19065
  try {
18415
- parseAst(file.code);
19066
+ parseAst(file.code, { jsx: this.inputOptions.jsx !== false });
18416
19067
  }
18417
19068
  catch (error_) {
18418
19069
  this.inputOptions.onLog(LOGLEVEL_WARN, logChunkInvalid(file, error_));
@@ -18807,6 +19458,32 @@ const treeshakePresets = {
18807
19458
  unknownGlobalSideEffects: false
18808
19459
  }
18809
19460
  };
19461
+ const jsxPresets = {
19462
+ preserve: {
19463
+ factory: null,
19464
+ fragment: null,
19465
+ importSource: null,
19466
+ mode: 'preserve'
19467
+ },
19468
+ 'preserve-react': {
19469
+ factory: 'React.createElement',
19470
+ fragment: 'React.Fragment',
19471
+ importSource: 'react',
19472
+ mode: 'preserve'
19473
+ },
19474
+ react: {
19475
+ factory: 'React.createElement',
19476
+ fragment: 'React.Fragment',
19477
+ importSource: 'react',
19478
+ mode: 'classic'
19479
+ },
19480
+ 'react-jsx': {
19481
+ factory: 'React.createElement',
19482
+ importSource: 'react',
19483
+ jsxImportSource: 'react/jsx-runtime',
19484
+ mode: 'automatic'
19485
+ }
19486
+ };
18810
19487
  const generatedCodePresets = {
18811
19488
  es2015: {
18812
19489
  arrowFunctions: true,
@@ -19420,10 +20097,25 @@ async function waitForDependencyResolution(loadPromise) {
19420
20097
  return Promise.all([...resolveStaticDependencyPromises, ...resolveDynamicImportPromises]);
19421
20098
  }
19422
20099
 
19423
- function generateAssetFileName(name, source, originalFileName, sourceHash, outputOptions, bundle) {
20100
+ function generateAssetFileName(name, names, source, originalFileName, originalFileNames, sourceHash, outputOptions, bundle, inputOptions) {
19424
20101
  const emittedName = outputOptions.sanitizeFileName(name || 'asset');
19425
20102
  return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
19426
- ? outputOptions.assetFileNames({ name, originalFileName, source, type: 'asset' })
20103
+ ? outputOptions.assetFileNames({
20104
+ // Additionally, this should be non-enumerable in the next major
20105
+ get name() {
20106
+ warnDeprecation('Accessing the "name" property of emitted assets when generating the file name is deprecated. Use the "names" property instead.', URL_GENERATEBUNDLE, false, inputOptions);
20107
+ return name;
20108
+ },
20109
+ names,
20110
+ // Additionally, this should be non-enumerable in the next major
20111
+ get originalFileName() {
20112
+ warnDeprecation('Accessing the "originalFileName" property of emitted assets when generating the file name is deprecated. Use the "originalFileNames" property instead.', URL_GENERATEBUNDLE, false, inputOptions);
20113
+ return originalFileName;
20114
+ },
20115
+ originalFileNames,
20116
+ source,
20117
+ type: 'asset'
20118
+ })
19427
20119
  : outputOptions.assetFileNames, 'output.assetFileNames', {
19428
20120
  ext: () => extname(emittedName).slice(1),
19429
20121
  extname: () => extname(emittedName),
@@ -19539,7 +20231,7 @@ class FileEmitter {
19539
20231
  const getHash = hasherByType[outputOptions.hashCharacters];
19540
20232
  const output = (this.output = {
19541
20233
  bundle,
19542
- fileNamesBySource: new Map(),
20234
+ fileNamesBySourceHash: new Map(),
19543
20235
  getHash,
19544
20236
  outputOptions
19545
20237
  });
@@ -19694,15 +20386,15 @@ class FileEmitter {
19694
20386
  }
19695
20387
  return referenceId;
19696
20388
  }
19697
- finalizeAdditionalAsset(consumedFile, source, { bundle, fileNamesBySource, getHash, outputOptions }) {
19698
- let { fileName, needsCodeReference, originalFileName, referenceId } = consumedFile;
20389
+ finalizeAdditionalAsset(consumedFile, source, { bundle, fileNamesBySourceHash, getHash, outputOptions }) {
20390
+ let { fileName, name, needsCodeReference, originalFileName, referenceId } = consumedFile;
19699
20391
  // Deduplicate assets if an explicit fileName is not provided
19700
20392
  if (!fileName) {
19701
20393
  const sourceHash = getHash(source);
19702
- fileName = fileNamesBySource.get(sourceHash);
20394
+ fileName = fileNamesBySourceHash.get(sourceHash);
19703
20395
  if (!fileName) {
19704
- fileName = generateAssetFileName(consumedFile.name, source, originalFileName, sourceHash, outputOptions, bundle);
19705
- fileNamesBySource.set(sourceHash, fileName);
20396
+ fileName = generateAssetFileName(name, name ? [name] : [], source, originalFileName, originalFileName ? [originalFileName] : [], sourceHash, outputOptions, bundle, this.options);
20397
+ fileNamesBySourceHash.set(sourceHash, fileName);
19706
20398
  }
19707
20399
  }
19708
20400
  // We must not modify the original assets to avoid interaction between outputs
@@ -19711,25 +20403,43 @@ class FileEmitter {
19711
20403
  const existingAsset = bundle[fileName];
19712
20404
  if (existingAsset?.type === 'asset') {
19713
20405
  existingAsset.needsCodeReference &&= needsCodeReference;
20406
+ if (name) {
20407
+ existingAsset.names.push(name);
20408
+ }
20409
+ if (originalFileName) {
20410
+ existingAsset.originalFileNames.push(originalFileName);
20411
+ }
19714
20412
  }
19715
20413
  else {
20414
+ const { options } = this;
19716
20415
  bundle[fileName] = {
19717
20416
  fileName,
19718
- name: consumedFile.name,
20417
+ get name() {
20418
+ // Additionally, this should be non-enumerable in the next major
20419
+ warnDeprecation('Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', URL_GENERATEBUNDLE, false, options);
20420
+ return name;
20421
+ },
20422
+ names: name ? [name] : [],
19719
20423
  needsCodeReference,
19720
- originalFileName,
20424
+ get originalFileName() {
20425
+ // Additionally, this should be non-enumerable in the next major
20426
+ warnDeprecation('Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', URL_GENERATEBUNDLE, false, options);
20427
+ return originalFileName;
20428
+ },
20429
+ originalFileNames: originalFileName ? [originalFileName] : [],
19721
20430
  source,
19722
20431
  type: 'asset'
19723
20432
  };
19724
20433
  }
19725
20434
  }
19726
- finalizeAssetsWithSameSource(consumedFiles, sourceHash, { bundle, fileNamesBySource, outputOptions }) {
20435
+ finalizeAssetsWithSameSource(consumedFiles, sourceHash, { bundle, fileNamesBySourceHash, outputOptions }) {
20436
+ const { names, originalFileNames } = getNamesFromAssets(consumedFiles);
19727
20437
  let fileName = '';
19728
20438
  let usedConsumedFile;
19729
20439
  let needsCodeReference = true;
19730
20440
  for (const consumedFile of consumedFiles) {
19731
20441
  needsCodeReference &&= consumedFile.needsCodeReference;
19732
- const assetFileName = generateAssetFileName(consumedFile.name, consumedFile.source, consumedFile.originalFileName, sourceHash, outputOptions, bundle);
20442
+ const assetFileName = generateAssetFileName(consumedFile.name, names, consumedFile.source, consumedFile.originalFileName, originalFileNames, sourceHash, outputOptions, bundle, this.options);
19733
20443
  if (!fileName ||
19734
20444
  assetFileName.length < fileName.length ||
19735
20445
  (assetFileName.length === fileName.length && assetFileName < fileName)) {
@@ -19737,22 +20447,50 @@ class FileEmitter {
19737
20447
  usedConsumedFile = consumedFile;
19738
20448
  }
19739
20449
  }
19740
- fileNamesBySource.set(sourceHash, fileName);
20450
+ fileNamesBySourceHash.set(sourceHash, fileName);
19741
20451
  for (const consumedFile of consumedFiles) {
19742
20452
  // We must not modify the original assets to avoid interaction between outputs
19743
20453
  const assetWithFileName = { ...consumedFile, fileName };
19744
20454
  this.filesByReferenceId.set(consumedFile.referenceId, assetWithFileName);
19745
20455
  }
20456
+ const { options } = this;
19746
20457
  bundle[fileName] = {
19747
20458
  fileName,
19748
- name: usedConsumedFile.name,
20459
+ get name() {
20460
+ // Additionally, this should be non-enumerable in the next major
20461
+ warnDeprecation('Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', URL_GENERATEBUNDLE, false, options);
20462
+ return usedConsumedFile.name;
20463
+ },
20464
+ names,
19749
20465
  needsCodeReference,
19750
- originalFileName: usedConsumedFile.originalFileName,
20466
+ get originalFileName() {
20467
+ // Additionally, this should be non-enumerable in the next major
20468
+ warnDeprecation('Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', URL_GENERATEBUNDLE, false, options);
20469
+ return usedConsumedFile.originalFileName;
20470
+ },
20471
+ originalFileNames,
19751
20472
  source: usedConsumedFile.source,
19752
20473
  type: 'asset'
19753
20474
  };
19754
20475
  }
19755
20476
  }
20477
+ function getNamesFromAssets(consumedFiles) {
20478
+ const names = [];
20479
+ const originalFileNames = [];
20480
+ for (const { name, originalFileName } of consumedFiles) {
20481
+ if (typeof name === 'string') {
20482
+ names.push(name);
20483
+ }
20484
+ if (originalFileName) {
20485
+ originalFileNames.push(originalFileName);
20486
+ }
20487
+ }
20488
+ originalFileNames.sort();
20489
+ // Sort by length first and then alphabetically so that the order is stable
20490
+ // and the shortest names come first
20491
+ names.sort((a, b) => a.length - b.length || (a > b ? 1 : a === b ? 0 : -1));
20492
+ return { names, originalFileNames };
20493
+ }
19756
20494
 
19757
20495
  function getLogHandler(level, code, logger, pluginName, logLevel) {
19758
20496
  if (logLevelPriority[level] < logLevelPriority[logLevel]) {
@@ -20410,6 +21148,7 @@ async function normalizeInputOptions(config, watchMode) {
20410
21148
  experimentalLogSideEffects: config.experimentalLogSideEffects || false,
20411
21149
  external: getIdMatcher(config.external),
20412
21150
  input: getInput(config),
21151
+ jsx: getJsx(config),
20413
21152
  logLevel,
20414
21153
  makeAbsoluteExternalsRelative: config.makeAbsoluteExternalsRelative ?? 'ifRelativeSource',
20415
21154
  maxParallelFileOps,
@@ -20455,6 +21194,46 @@ const getInput = (config) => {
20455
21194
  const configInput = config.input;
20456
21195
  return configInput == null ? [] : typeof configInput === 'string' ? [configInput] : configInput;
20457
21196
  };
21197
+ const getJsx = (config) => {
21198
+ const configJsx = config.jsx;
21199
+ if (!configJsx)
21200
+ return false;
21201
+ const configWithPreset = getOptionWithPreset(configJsx, jsxPresets, 'jsx', URL_JSX, 'false, ');
21202
+ const { factory, importSource, mode } = configWithPreset;
21203
+ switch (mode) {
21204
+ case 'automatic': {
21205
+ return {
21206
+ factory: factory || 'React.createElement',
21207
+ importSource: importSource || 'react',
21208
+ jsxImportSource: configWithPreset.jsxImportSource || 'react/jsx-runtime',
21209
+ mode: 'automatic'
21210
+ };
21211
+ }
21212
+ case 'preserve': {
21213
+ if (importSource && !(factory || configWithPreset.fragment)) {
21214
+ error(logInvalidOption('jsx', URL_JSX, 'when preserving JSX and specifying an importSource, you also need to specify a factory or fragment'));
21215
+ }
21216
+ return {
21217
+ factory: factory || null,
21218
+ fragment: configWithPreset.fragment || null,
21219
+ importSource: importSource || null,
21220
+ mode: 'preserve'
21221
+ };
21222
+ }
21223
+ // case 'classic':
21224
+ default: {
21225
+ if (mode && mode !== 'classic') {
21226
+ error(logInvalidOption('jsx.mode', URL_JSX, 'mode must be "automatic", "classic" or "preserve"', mode));
21227
+ }
21228
+ return {
21229
+ factory: factory || 'React.createElement',
21230
+ fragment: configWithPreset.fragment || 'React.Fragment',
21231
+ importSource: importSource || null,
21232
+ mode: 'classic'
21233
+ };
21234
+ }
21235
+ }
21236
+ };
20458
21237
  const getMaxParallelFileOps = (config) => {
20459
21238
  const maxParallelFileOps = config.maxParallelFileOps;
20460
21239
  if (typeof maxParallelFileOps === 'number') {
@@ -21209,6 +21988,7 @@ function mergeInputOptions(config, overrides, plugins, log, onLog) {
21209
21988
  experimentalLogSideEffects: getOption('experimentalLogSideEffects'),
21210
21989
  external: getExternal(config, overrides),
21211
21990
  input: getOption('input') || [],
21991
+ jsx: getObjectOption(config, overrides, 'jsx', objectifyOptionWithPresets(jsxPresets, 'jsx', URL_JSX, 'false, ')),
21212
21992
  logLevel: getOption('logLevel'),
21213
21993
  makeAbsoluteExternalsRelative: getOption('makeAbsoluteExternalsRelative'),
21214
21994
  maxParallelFileOps: getOption('maxParallelFileOps'),