@rollup/wasm-node 4.23.0 → 4.24.1
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 +888 -153
- package/dist/es/shared/parseAst.js +150 -6
- package/dist/es/shared/watch.js +4 -3
- 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 +886 -151
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +4 -3
- package/dist/wasm-node/bindings_wasm.js +35 -34
- package/dist/wasm-node/bindings_wasm_bg.wasm +0 -0
- package/package.json +27 -26
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v4.
|
|
4
|
-
|
|
3
|
+
Rollup.js v4.24.1
|
|
4
|
+
Sun, 27 Oct 2024 06:42:30 GMT - commit 88a54d892dacbb0efdbcade263a32d9df1a77b37
|
|
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,
|
|
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
|
-
import
|
|
12
|
+
import { posix, win32, isAbsolute, resolve } from 'path';
|
|
13
13
|
import { parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } from '../../native.js';
|
|
14
14
|
import process$1, { env as env$1 } from 'node:process';
|
|
15
15
|
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.
|
|
19
|
+
var version = "4.24.1";
|
|
20
20
|
|
|
21
21
|
const comma = ','.charCodeAt(0);
|
|
22
22
|
const semicolon = ';'.charCodeAt(0);
|
|
@@ -565,27 +565,6 @@ class Mappings {
|
|
|
565
565
|
let charInHiresBoundary = false;
|
|
566
566
|
|
|
567
567
|
while (originalCharIndex < chunk.end) {
|
|
568
|
-
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
569
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
570
|
-
|
|
571
|
-
if (this.hires === 'boundary') {
|
|
572
|
-
// in hires "boundary", group segments per word boundary than per char
|
|
573
|
-
if (wordRegex.test(original[originalCharIndex])) {
|
|
574
|
-
// for first char in the boundary found, start the boundary by pushing a segment
|
|
575
|
-
if (!charInHiresBoundary) {
|
|
576
|
-
this.rawSegments.push(segment);
|
|
577
|
-
charInHiresBoundary = true;
|
|
578
|
-
}
|
|
579
|
-
} else {
|
|
580
|
-
// for non-word char, end the boundary by pushing a segment
|
|
581
|
-
this.rawSegments.push(segment);
|
|
582
|
-
charInHiresBoundary = false;
|
|
583
|
-
}
|
|
584
|
-
} else {
|
|
585
|
-
this.rawSegments.push(segment);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
568
|
if (original[originalCharIndex] === '\n') {
|
|
590
569
|
loc.line += 1;
|
|
591
570
|
loc.column = 0;
|
|
@@ -594,6 +573,27 @@ class Mappings {
|
|
|
594
573
|
this.generatedCodeColumn = 0;
|
|
595
574
|
first = true;
|
|
596
575
|
} else {
|
|
576
|
+
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
577
|
+
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
578
|
+
|
|
579
|
+
if (this.hires === 'boundary') {
|
|
580
|
+
// in hires "boundary", group segments per word boundary than per char
|
|
581
|
+
if (wordRegex.test(original[originalCharIndex])) {
|
|
582
|
+
// for first char in the boundary found, start the boundary by pushing a segment
|
|
583
|
+
if (!charInHiresBoundary) {
|
|
584
|
+
this.rawSegments.push(segment);
|
|
585
|
+
charInHiresBoundary = true;
|
|
586
|
+
}
|
|
587
|
+
} else {
|
|
588
|
+
// for non-word char, end the boundary by pushing a segment
|
|
589
|
+
this.rawSegments.push(segment);
|
|
590
|
+
charInHiresBoundary = false;
|
|
591
|
+
}
|
|
592
|
+
} else {
|
|
593
|
+
this.rawSegments.push(segment);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
597
|
loc.column += 1;
|
|
598
598
|
this.generatedCodeColumn += 1;
|
|
599
599
|
first = false;
|
|
@@ -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
|
|
2244
|
-
* its identifiers becomes part of the bundle. Returns true if it
|
|
2245
|
-
* previously.
|
|
2246
|
-
*
|
|
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
|
|
4867
|
+
class IdentifierBase extends NodeBase {
|
|
4849
4868
|
constructor() {
|
|
4850
4869
|
super(...arguments);
|
|
4851
4870
|
this.variable = null;
|
|
4852
|
-
this.
|
|
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.
|
|
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) {
|
|
@@ -8482,7 +8513,6 @@ function requireConstants () {
|
|
|
8482
8513
|
if (hasRequiredConstants) return constants;
|
|
8483
8514
|
hasRequiredConstants = 1;
|
|
8484
8515
|
|
|
8485
|
-
const path = require$$0;
|
|
8486
8516
|
const WIN_SLASH = '\\\\/';
|
|
8487
8517
|
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
8488
8518
|
|
|
@@ -8505,6 +8535,7 @@ function requireConstants () {
|
|
|
8505
8535
|
const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
|
8506
8536
|
const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
|
8507
8537
|
const STAR = `${QMARK}*?`;
|
|
8538
|
+
const SEP = '/';
|
|
8508
8539
|
|
|
8509
8540
|
const POSIX_CHARS = {
|
|
8510
8541
|
DOT_LITERAL,
|
|
@@ -8521,7 +8552,8 @@ function requireConstants () {
|
|
|
8521
8552
|
NO_DOTS_SLASH,
|
|
8522
8553
|
QMARK_NO_DOT,
|
|
8523
8554
|
STAR,
|
|
8524
|
-
START_ANCHOR
|
|
8555
|
+
START_ANCHOR,
|
|
8556
|
+
SEP
|
|
8525
8557
|
};
|
|
8526
8558
|
|
|
8527
8559
|
/**
|
|
@@ -8541,7 +8573,8 @@ function requireConstants () {
|
|
|
8541
8573
|
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
8542
8574
|
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
8543
8575
|
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
8544
|
-
END_ANCHOR: `(?:[${WIN_SLASH}]|$)
|
|
8576
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
8577
|
+
SEP: '\\'
|
|
8545
8578
|
};
|
|
8546
8579
|
|
|
8547
8580
|
/**
|
|
@@ -8635,8 +8668,6 @@ function requireConstants () {
|
|
|
8635
8668
|
CHAR_VERTICAL_LINE: 124, /* | */
|
|
8636
8669
|
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279, /* \uFEFF */
|
|
8637
8670
|
|
|
8638
|
-
SEP: path.sep,
|
|
8639
|
-
|
|
8640
8671
|
/**
|
|
8641
8672
|
* Create EXTGLOB_CHARS
|
|
8642
8673
|
*/
|
|
@@ -8662,6 +8693,8 @@ function requireConstants () {
|
|
|
8662
8693
|
return constants;
|
|
8663
8694
|
}
|
|
8664
8695
|
|
|
8696
|
+
/*global navigator*/
|
|
8697
|
+
|
|
8665
8698
|
var hasRequiredUtils;
|
|
8666
8699
|
|
|
8667
8700
|
function requireUtils () {
|
|
@@ -8669,8 +8702,6 @@ function requireUtils () {
|
|
|
8669
8702
|
hasRequiredUtils = 1;
|
|
8670
8703
|
(function (exports) {
|
|
8671
8704
|
|
|
8672
|
-
const path = require$$0;
|
|
8673
|
-
const win32 = process.platform === 'win32';
|
|
8674
8705
|
const {
|
|
8675
8706
|
REGEX_BACKSLASH,
|
|
8676
8707
|
REGEX_REMOVE_BACKSLASH,
|
|
@@ -8684,25 +8715,23 @@ function requireUtils () {
|
|
|
8684
8715
|
exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
|
|
8685
8716
|
exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
|
|
8686
8717
|
|
|
8687
|
-
exports.
|
|
8688
|
-
|
|
8689
|
-
|
|
8690
|
-
|
|
8691
|
-
|
|
8718
|
+
exports.isWindows = () => {
|
|
8719
|
+
if (typeof navigator !== 'undefined' && navigator.platform) {
|
|
8720
|
+
const platform = navigator.platform.toLowerCase();
|
|
8721
|
+
return platform === 'win32' || platform === 'windows';
|
|
8722
|
+
}
|
|
8692
8723
|
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
|
|
8696
|
-
return true;
|
|
8724
|
+
if (typeof process !== 'undefined' && process.platform) {
|
|
8725
|
+
return process.platform === 'win32';
|
|
8697
8726
|
}
|
|
8727
|
+
|
|
8698
8728
|
return false;
|
|
8699
8729
|
};
|
|
8700
8730
|
|
|
8701
|
-
exports.
|
|
8702
|
-
|
|
8703
|
-
return
|
|
8704
|
-
}
|
|
8705
|
-
return win32 === true || path.sep === '\\';
|
|
8731
|
+
exports.removeBackslashes = str => {
|
|
8732
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, match => {
|
|
8733
|
+
return match === '\\' ? '' : match;
|
|
8734
|
+
});
|
|
8706
8735
|
};
|
|
8707
8736
|
|
|
8708
8737
|
exports.escapeLast = (input, char, lastIdx) => {
|
|
@@ -8730,6 +8759,17 @@ function requireUtils () {
|
|
|
8730
8759
|
output = `(?:^(?!${output}).*$)`;
|
|
8731
8760
|
}
|
|
8732
8761
|
return output;
|
|
8762
|
+
};
|
|
8763
|
+
|
|
8764
|
+
exports.basename = (path, { windows } = {}) => {
|
|
8765
|
+
const segs = path.split(windows ? /[\\/]/ : '/');
|
|
8766
|
+
const last = segs[segs.length - 1];
|
|
8767
|
+
|
|
8768
|
+
if (last === '') {
|
|
8769
|
+
return segs[segs.length - 2];
|
|
8770
|
+
}
|
|
8771
|
+
|
|
8772
|
+
return last;
|
|
8733
8773
|
};
|
|
8734
8774
|
} (utils));
|
|
8735
8775
|
return utils;
|
|
@@ -9205,10 +9245,9 @@ function requireParse () {
|
|
|
9205
9245
|
const tokens = [bos];
|
|
9206
9246
|
|
|
9207
9247
|
const capture = opts.capture ? '' : '?:';
|
|
9208
|
-
const win32 = utils.isWindows(options);
|
|
9209
9248
|
|
|
9210
9249
|
// create constants based on platform, for windows or posix
|
|
9211
|
-
const PLATFORM_CHARS = constants.globChars(
|
|
9250
|
+
const PLATFORM_CHARS = constants.globChars(opts.windows);
|
|
9212
9251
|
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
9213
9252
|
|
|
9214
9253
|
const {
|
|
@@ -9344,8 +9383,8 @@ function requireParse () {
|
|
|
9344
9383
|
|
|
9345
9384
|
if (tok.value || tok.output) append(tok);
|
|
9346
9385
|
if (prev && prev.type === 'text' && tok.type === 'text') {
|
|
9386
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
9347
9387
|
prev.value += tok.value;
|
|
9348
|
-
prev.output = (prev.output || '') + tok.value;
|
|
9349
9388
|
return;
|
|
9350
9389
|
}
|
|
9351
9390
|
|
|
@@ -9833,10 +9872,6 @@ function requireParse () {
|
|
|
9833
9872
|
const next = peek();
|
|
9834
9873
|
let output = value;
|
|
9835
9874
|
|
|
9836
|
-
if (next === '<' && !utils.supportsLookbehinds()) {
|
|
9837
|
-
throw new Error('Node.js v10 or higher is required for regex lookbehinds');
|
|
9838
|
-
}
|
|
9839
|
-
|
|
9840
9875
|
if ((prev.value === '(' && !/[!=<:]/.test(next)) || (next === '<' && !/<([!=]|\w+>)/.test(remaining()))) {
|
|
9841
9876
|
output = `\\${value}`;
|
|
9842
9877
|
}
|
|
@@ -10144,7 +10179,6 @@ function requireParse () {
|
|
|
10144
10179
|
}
|
|
10145
10180
|
|
|
10146
10181
|
input = REPLACEMENTS[input] || input;
|
|
10147
|
-
const win32 = utils.isWindows(options);
|
|
10148
10182
|
|
|
10149
10183
|
// create constants based on platform, for windows or posix
|
|
10150
10184
|
const {
|
|
@@ -10157,7 +10191,7 @@ function requireParse () {
|
|
|
10157
10191
|
NO_DOTS_SLASH,
|
|
10158
10192
|
STAR,
|
|
10159
10193
|
START_ANCHOR
|
|
10160
|
-
} = constants.globChars(
|
|
10194
|
+
} = constants.globChars(opts.windows);
|
|
10161
10195
|
|
|
10162
10196
|
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
10163
10197
|
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
@@ -10226,14 +10260,13 @@ function requireParse () {
|
|
|
10226
10260
|
return parse_1;
|
|
10227
10261
|
}
|
|
10228
10262
|
|
|
10229
|
-
var picomatch_1;
|
|
10263
|
+
var picomatch_1$1;
|
|
10230
10264
|
var hasRequiredPicomatch$1;
|
|
10231
10265
|
|
|
10232
10266
|
function requirePicomatch$1 () {
|
|
10233
|
-
if (hasRequiredPicomatch$1) return picomatch_1;
|
|
10267
|
+
if (hasRequiredPicomatch$1) return picomatch_1$1;
|
|
10234
10268
|
hasRequiredPicomatch$1 = 1;
|
|
10235
10269
|
|
|
10236
|
-
const path = require$$0;
|
|
10237
10270
|
const scan = /*@__PURE__*/ requireScan();
|
|
10238
10271
|
const parse = /*@__PURE__*/ requireParse();
|
|
10239
10272
|
const utils = /*@__PURE__*/ requireUtils();
|
|
@@ -10282,7 +10315,7 @@ function requirePicomatch$1 () {
|
|
|
10282
10315
|
}
|
|
10283
10316
|
|
|
10284
10317
|
const opts = options || {};
|
|
10285
|
-
const posix =
|
|
10318
|
+
const posix = opts.windows;
|
|
10286
10319
|
const regex = isState
|
|
10287
10320
|
? picomatch.compileRe(glob, options)
|
|
10288
10321
|
: picomatch.makeRe(glob, options, false, true);
|
|
@@ -10391,9 +10424,9 @@ function requirePicomatch$1 () {
|
|
|
10391
10424
|
* @api public
|
|
10392
10425
|
*/
|
|
10393
10426
|
|
|
10394
|
-
picomatch.matchBase = (input, glob, options
|
|
10427
|
+
picomatch.matchBase = (input, glob, options) => {
|
|
10395
10428
|
const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
|
|
10396
|
-
return regex.test(
|
|
10429
|
+
return regex.test(utils.basename(input));
|
|
10397
10430
|
};
|
|
10398
10431
|
|
|
10399
10432
|
/**
|
|
@@ -10572,19 +10605,33 @@ function requirePicomatch$1 () {
|
|
|
10572
10605
|
* Expose "picomatch"
|
|
10573
10606
|
*/
|
|
10574
10607
|
|
|
10575
|
-
picomatch_1 = picomatch;
|
|
10576
|
-
return picomatch_1;
|
|
10608
|
+
picomatch_1$1 = picomatch;
|
|
10609
|
+
return picomatch_1$1;
|
|
10577
10610
|
}
|
|
10578
10611
|
|
|
10579
|
-
var
|
|
10612
|
+
var picomatch_1;
|
|
10580
10613
|
var hasRequiredPicomatch;
|
|
10581
10614
|
|
|
10582
10615
|
function requirePicomatch () {
|
|
10583
|
-
if (hasRequiredPicomatch) return
|
|
10616
|
+
if (hasRequiredPicomatch) return picomatch_1;
|
|
10584
10617
|
hasRequiredPicomatch = 1;
|
|
10585
10618
|
|
|
10586
|
-
|
|
10587
|
-
|
|
10619
|
+
const pico = /*@__PURE__*/ requirePicomatch$1();
|
|
10620
|
+
const utils = /*@__PURE__*/ requireUtils();
|
|
10621
|
+
|
|
10622
|
+
function picomatch(glob, options, returnState = false) {
|
|
10623
|
+
// default to os.platform()
|
|
10624
|
+
if (options && (options.windows === null || options.windows === undefined)) {
|
|
10625
|
+
// don't mutate the original options object
|
|
10626
|
+
options = { ...options, windows: utils.isWindows() };
|
|
10627
|
+
}
|
|
10628
|
+
|
|
10629
|
+
return pico(glob, options, returnState);
|
|
10630
|
+
}
|
|
10631
|
+
|
|
10632
|
+
Object.assign(picomatch, pico);
|
|
10633
|
+
picomatch_1 = picomatch;
|
|
10634
|
+
return picomatch_1;
|
|
10588
10635
|
}
|
|
10589
10636
|
|
|
10590
10637
|
var picomatchExports = /*@__PURE__*/ requirePicomatch();
|
|
@@ -12377,6 +12424,497 @@ class ImportSpecifier extends NodeBase {
|
|
|
12377
12424
|
applyDeoptimizations() { }
|
|
12378
12425
|
}
|
|
12379
12426
|
|
|
12427
|
+
class JSXIdentifier extends IdentifierBase {
|
|
12428
|
+
constructor() {
|
|
12429
|
+
super(...arguments);
|
|
12430
|
+
this.isNativeElement = false;
|
|
12431
|
+
}
|
|
12432
|
+
bind() {
|
|
12433
|
+
const type = this.getType();
|
|
12434
|
+
if (type === 0 /* IdentifierType.Reference */) {
|
|
12435
|
+
this.variable = this.scope.findVariable(this.name);
|
|
12436
|
+
this.variable.addReference(this);
|
|
12437
|
+
}
|
|
12438
|
+
else if (type === 1 /* IdentifierType.NativeElementName */) {
|
|
12439
|
+
this.isNativeElement = true;
|
|
12440
|
+
}
|
|
12441
|
+
}
|
|
12442
|
+
render(code, { snippets: { getPropertyAccess }, useOriginalName }) {
|
|
12443
|
+
if (this.variable) {
|
|
12444
|
+
const name = this.variable.getName(getPropertyAccess, useOriginalName);
|
|
12445
|
+
if (name !== this.name) {
|
|
12446
|
+
code.overwrite(this.start, this.end, name, {
|
|
12447
|
+
contentOnly: true,
|
|
12448
|
+
storeName: true
|
|
12449
|
+
});
|
|
12450
|
+
}
|
|
12451
|
+
}
|
|
12452
|
+
else if (this.isNativeElement &&
|
|
12453
|
+
this.scope.context.options.jsx.mode !== 'preserve') {
|
|
12454
|
+
code.update(this.start, this.end, JSON.stringify(this.name));
|
|
12455
|
+
}
|
|
12456
|
+
}
|
|
12457
|
+
getType() {
|
|
12458
|
+
switch (this.parent.type) {
|
|
12459
|
+
case 'JSXOpeningElement':
|
|
12460
|
+
case 'JSXClosingElement': {
|
|
12461
|
+
return this.name.startsWith(this.name.charAt(0).toUpperCase())
|
|
12462
|
+
? 0 /* IdentifierType.Reference */
|
|
12463
|
+
: 1 /* IdentifierType.NativeElementName */;
|
|
12464
|
+
}
|
|
12465
|
+
case 'JSXMemberExpression': {
|
|
12466
|
+
return this.parent.object === this
|
|
12467
|
+
? 0 /* IdentifierType.Reference */
|
|
12468
|
+
: 2 /* IdentifierType.Other */;
|
|
12469
|
+
}
|
|
12470
|
+
case 'JSXAttribute':
|
|
12471
|
+
case 'JSXNamespacedName': {
|
|
12472
|
+
return 2 /* IdentifierType.Other */;
|
|
12473
|
+
}
|
|
12474
|
+
default: {
|
|
12475
|
+
/* istanbul ignore next */
|
|
12476
|
+
throw new Error(`Unexpected parent node type for JSXIdentifier: ${this.parent.type}`);
|
|
12477
|
+
}
|
|
12478
|
+
}
|
|
12479
|
+
}
|
|
12480
|
+
}
|
|
12481
|
+
|
|
12482
|
+
class JSXAttribute extends NodeBase {
|
|
12483
|
+
render(code, options, { jsxMode } = BLANK) {
|
|
12484
|
+
super.render(code, options);
|
|
12485
|
+
if (['classic', 'automatic'].includes(jsxMode)) {
|
|
12486
|
+
const { name, value } = this;
|
|
12487
|
+
const key = name instanceof JSXIdentifier ? name.name : `${name.namespace.name}:${name.name.name}`;
|
|
12488
|
+
if (!(jsxMode === 'automatic' && key === 'key')) {
|
|
12489
|
+
const safeKey = stringifyObjectKeyIfNeeded(key);
|
|
12490
|
+
if (key !== safeKey) {
|
|
12491
|
+
code.overwrite(name.start, name.end, safeKey, { contentOnly: true });
|
|
12492
|
+
}
|
|
12493
|
+
if (value) {
|
|
12494
|
+
code.overwrite(name.end, value.start, ': ', { contentOnly: true });
|
|
12495
|
+
}
|
|
12496
|
+
else {
|
|
12497
|
+
code.appendLeft(name.end, ': true');
|
|
12498
|
+
}
|
|
12499
|
+
}
|
|
12500
|
+
}
|
|
12501
|
+
}
|
|
12502
|
+
}
|
|
12503
|
+
|
|
12504
|
+
class JSXClosingBase extends NodeBase {
|
|
12505
|
+
render(code, options) {
|
|
12506
|
+
const { mode } = this.scope.context.options.jsx;
|
|
12507
|
+
if (mode !== 'preserve') {
|
|
12508
|
+
code.overwrite(this.start, this.end, ')', { contentOnly: true });
|
|
12509
|
+
}
|
|
12510
|
+
else {
|
|
12511
|
+
super.render(code, options);
|
|
12512
|
+
}
|
|
12513
|
+
}
|
|
12514
|
+
}
|
|
12515
|
+
|
|
12516
|
+
class JSXClosingElement extends JSXClosingBase {
|
|
12517
|
+
}
|
|
12518
|
+
|
|
12519
|
+
class JSXClosingFragment extends JSXClosingBase {
|
|
12520
|
+
}
|
|
12521
|
+
|
|
12522
|
+
class JSXSpreadAttribute extends NodeBase {
|
|
12523
|
+
render(code, options) {
|
|
12524
|
+
this.argument.render(code, options);
|
|
12525
|
+
const { mode } = this.scope.context.options.jsx;
|
|
12526
|
+
if (mode !== 'preserve') {
|
|
12527
|
+
code.overwrite(this.start, this.argument.start, '', { contentOnly: true });
|
|
12528
|
+
code.overwrite(this.argument.end, this.end, '', { contentOnly: true });
|
|
12529
|
+
}
|
|
12530
|
+
}
|
|
12531
|
+
}
|
|
12532
|
+
|
|
12533
|
+
class JSXEmptyExpression extends NodeBase {
|
|
12534
|
+
}
|
|
12535
|
+
|
|
12536
|
+
class JSXExpressionContainer extends NodeBase {
|
|
12537
|
+
render(code, options) {
|
|
12538
|
+
const { mode } = this.scope.context.options.jsx;
|
|
12539
|
+
if (mode !== 'preserve') {
|
|
12540
|
+
code.remove(this.start, this.expression.start);
|
|
12541
|
+
code.remove(this.expression.end, this.end);
|
|
12542
|
+
}
|
|
12543
|
+
this.expression.render(code, options);
|
|
12544
|
+
}
|
|
12545
|
+
}
|
|
12546
|
+
|
|
12547
|
+
function getRenderedJsxChildren(children) {
|
|
12548
|
+
let renderedChildren = 0;
|
|
12549
|
+
for (const child of children) {
|
|
12550
|
+
if (!(child instanceof JSXExpressionContainer && child.expression instanceof JSXEmptyExpression)) {
|
|
12551
|
+
renderedChildren++;
|
|
12552
|
+
}
|
|
12553
|
+
}
|
|
12554
|
+
return renderedChildren;
|
|
12555
|
+
}
|
|
12556
|
+
|
|
12557
|
+
function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
|
|
12558
|
+
const [baseName, nestedName] = factory.split('.');
|
|
12559
|
+
let factoryVariable;
|
|
12560
|
+
if (importSource) {
|
|
12561
|
+
factoryVariable = node.scope.context.getImportedJsxFactoryVariable(nestedName ? 'default' : baseName, node.start, importSource);
|
|
12562
|
+
if (preserve) {
|
|
12563
|
+
// This pretends we are accessing an included global variable of the same name
|
|
12564
|
+
const globalVariable = node.scope.findGlobal(baseName);
|
|
12565
|
+
globalVariable.include();
|
|
12566
|
+
// This excludes this variable from renaming
|
|
12567
|
+
factoryVariable.globalName = baseName;
|
|
12568
|
+
}
|
|
12569
|
+
}
|
|
12570
|
+
else {
|
|
12571
|
+
factoryVariable = node.scope.findGlobal(baseName);
|
|
12572
|
+
}
|
|
12573
|
+
node.scope.context.includeVariableInModule(factoryVariable);
|
|
12574
|
+
if (factoryVariable instanceof LocalVariable) {
|
|
12575
|
+
factoryVariable.consolidateInitializers();
|
|
12576
|
+
factoryVariable.addUsedPlace(node);
|
|
12577
|
+
node.scope.context.requestTreeshakingPass();
|
|
12578
|
+
}
|
|
12579
|
+
return factoryVariable;
|
|
12580
|
+
}
|
|
12581
|
+
|
|
12582
|
+
class JSXElementBase extends NodeBase {
|
|
12583
|
+
constructor() {
|
|
12584
|
+
super(...arguments);
|
|
12585
|
+
this.factoryVariable = null;
|
|
12586
|
+
this.factory = null;
|
|
12587
|
+
}
|
|
12588
|
+
initialise() {
|
|
12589
|
+
super.initialise();
|
|
12590
|
+
const { importSource } = (this.jsxMode = this.getRenderingMode());
|
|
12591
|
+
if (importSource) {
|
|
12592
|
+
this.scope.context.addImportSource(importSource);
|
|
12593
|
+
}
|
|
12594
|
+
}
|
|
12595
|
+
include(context, includeChildrenRecursively) {
|
|
12596
|
+
if (!this.included) {
|
|
12597
|
+
const { factory, importSource, mode } = this.jsxMode;
|
|
12598
|
+
if (factory) {
|
|
12599
|
+
this.factory = factory;
|
|
12600
|
+
this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
|
|
12601
|
+
}
|
|
12602
|
+
}
|
|
12603
|
+
super.include(context, includeChildrenRecursively);
|
|
12604
|
+
}
|
|
12605
|
+
applyDeoptimizations() { }
|
|
12606
|
+
getRenderingMode() {
|
|
12607
|
+
const jsx = this.scope.context.options.jsx;
|
|
12608
|
+
const { mode, factory, importSource } = jsx;
|
|
12609
|
+
if (mode === 'automatic') {
|
|
12610
|
+
return {
|
|
12611
|
+
factory: getRenderedJsxChildren(this.children) > 1 ? 'jsxs' : 'jsx',
|
|
12612
|
+
importSource: jsx.jsxImportSource,
|
|
12613
|
+
mode
|
|
12614
|
+
};
|
|
12615
|
+
}
|
|
12616
|
+
return { factory, importSource, mode };
|
|
12617
|
+
}
|
|
12618
|
+
renderChildren(code, options, openingEnd) {
|
|
12619
|
+
const { children } = this;
|
|
12620
|
+
let hasMultipleChildren = false;
|
|
12621
|
+
let childrenEnd = openingEnd;
|
|
12622
|
+
let firstChild = null;
|
|
12623
|
+
for (const child of children) {
|
|
12624
|
+
if (child instanceof JSXExpressionContainer &&
|
|
12625
|
+
child.expression instanceof JSXEmptyExpression) {
|
|
12626
|
+
code.remove(childrenEnd, child.end);
|
|
12627
|
+
}
|
|
12628
|
+
else {
|
|
12629
|
+
code.appendLeft(childrenEnd, ', ');
|
|
12630
|
+
child.render(code, options);
|
|
12631
|
+
if (firstChild) {
|
|
12632
|
+
hasMultipleChildren = true;
|
|
12633
|
+
}
|
|
12634
|
+
else {
|
|
12635
|
+
firstChild = child;
|
|
12636
|
+
}
|
|
12637
|
+
}
|
|
12638
|
+
childrenEnd = child.end;
|
|
12639
|
+
}
|
|
12640
|
+
return { childrenEnd, firstChild, hasMultipleChildren };
|
|
12641
|
+
}
|
|
12642
|
+
}
|
|
12643
|
+
|
|
12644
|
+
class JSXElement extends JSXElementBase {
|
|
12645
|
+
render(code, options) {
|
|
12646
|
+
switch (this.jsxMode.mode) {
|
|
12647
|
+
case 'classic': {
|
|
12648
|
+
this.renderClassicMode(code, options);
|
|
12649
|
+
break;
|
|
12650
|
+
}
|
|
12651
|
+
case 'automatic': {
|
|
12652
|
+
this.renderAutomaticMode(code, options);
|
|
12653
|
+
break;
|
|
12654
|
+
}
|
|
12655
|
+
default: {
|
|
12656
|
+
super.render(code, options);
|
|
12657
|
+
}
|
|
12658
|
+
}
|
|
12659
|
+
}
|
|
12660
|
+
getRenderingMode() {
|
|
12661
|
+
const jsx = this.scope.context.options.jsx;
|
|
12662
|
+
const { mode, factory, importSource } = jsx;
|
|
12663
|
+
if (mode === 'automatic') {
|
|
12664
|
+
// In the case there is a key after a spread attribute, we fall back to
|
|
12665
|
+
// classic mode, see https://github.com/facebook/react/issues/20031#issuecomment-710346866
|
|
12666
|
+
// for reasoning.
|
|
12667
|
+
let hasSpread = false;
|
|
12668
|
+
for (const attribute of this.openingElement.attributes) {
|
|
12669
|
+
if (attribute instanceof JSXSpreadAttribute) {
|
|
12670
|
+
hasSpread = true;
|
|
12671
|
+
}
|
|
12672
|
+
else if (hasSpread && attribute.name.name === 'key') {
|
|
12673
|
+
return { factory, importSource, mode: 'classic' };
|
|
12674
|
+
}
|
|
12675
|
+
}
|
|
12676
|
+
}
|
|
12677
|
+
return super.getRenderingMode();
|
|
12678
|
+
}
|
|
12679
|
+
renderClassicMode(code, options) {
|
|
12680
|
+
const { snippets: { getPropertyAccess }, useOriginalName } = options;
|
|
12681
|
+
const { closingElement, end, factory, factoryVariable, openingElement: { end: openingEnd, selfClosing } } = this;
|
|
12682
|
+
const [, ...nestedName] = factory.split('.');
|
|
12683
|
+
const { firstAttribute, hasAttributes, hasSpread, inObject, previousEnd } = this.renderAttributes(code, options, [factoryVariable.getName(getPropertyAccess, useOriginalName), ...nestedName].join('.'), false);
|
|
12684
|
+
this.wrapAttributes(code, inObject, hasAttributes, hasSpread, firstAttribute, 'null', previousEnd);
|
|
12685
|
+
this.renderChildren(code, options, openingEnd);
|
|
12686
|
+
if (selfClosing) {
|
|
12687
|
+
code.appendLeft(end, ')');
|
|
12688
|
+
}
|
|
12689
|
+
else {
|
|
12690
|
+
closingElement.render(code, options);
|
|
12691
|
+
}
|
|
12692
|
+
}
|
|
12693
|
+
renderAutomaticMode(code, options) {
|
|
12694
|
+
const { snippets: { getPropertyAccess }, useOriginalName } = options;
|
|
12695
|
+
const { closingElement, end, factoryVariable, openingElement: { end: openindEnd, selfClosing } } = this;
|
|
12696
|
+
let { firstAttribute, hasAttributes, hasSpread, inObject, keyAttribute, previousEnd } = this.renderAttributes(code, options, factoryVariable.getName(getPropertyAccess, useOriginalName), true);
|
|
12697
|
+
const { firstChild, hasMultipleChildren, childrenEnd } = this.renderChildren(code, options, openindEnd);
|
|
12698
|
+
if (firstChild) {
|
|
12699
|
+
code.prependRight(firstChild.start, `children: ${hasMultipleChildren ? '[' : ''}`);
|
|
12700
|
+
if (!inObject) {
|
|
12701
|
+
code.prependRight(firstChild.start, '{ ');
|
|
12702
|
+
inObject = true;
|
|
12703
|
+
}
|
|
12704
|
+
previousEnd = closingElement.start;
|
|
12705
|
+
if (hasMultipleChildren) {
|
|
12706
|
+
code.appendLeft(previousEnd, ']');
|
|
12707
|
+
}
|
|
12708
|
+
}
|
|
12709
|
+
this.wrapAttributes(code, inObject, hasAttributes || !!firstChild, hasSpread, firstAttribute || firstChild, '{}', childrenEnd);
|
|
12710
|
+
if (keyAttribute) {
|
|
12711
|
+
const { value } = keyAttribute;
|
|
12712
|
+
// This will appear to the left of the moved code...
|
|
12713
|
+
code.appendLeft(childrenEnd, ', ');
|
|
12714
|
+
if (value) {
|
|
12715
|
+
code.move(value.start, value.end, childrenEnd);
|
|
12716
|
+
}
|
|
12717
|
+
else {
|
|
12718
|
+
code.appendLeft(childrenEnd, 'true');
|
|
12719
|
+
}
|
|
12720
|
+
}
|
|
12721
|
+
if (selfClosing) {
|
|
12722
|
+
// Moving the key attribute will also move the parenthesis to the right position
|
|
12723
|
+
code.appendLeft(keyAttribute?.value?.end || end, ')');
|
|
12724
|
+
}
|
|
12725
|
+
else {
|
|
12726
|
+
closingElement.render(code, options);
|
|
12727
|
+
}
|
|
12728
|
+
}
|
|
12729
|
+
renderAttributes(code, options, factoryName, extractKeyAttribute) {
|
|
12730
|
+
const { jsxMode: { mode }, openingElement } = this;
|
|
12731
|
+
const { attributes, end: openingEnd, start: openingStart, name: { start: nameStart, end: nameEnd } } = openingElement;
|
|
12732
|
+
code.update(openingStart, nameStart, `/*#__PURE__*/${factoryName}(`);
|
|
12733
|
+
openingElement.render(code, options, { jsxMode: mode });
|
|
12734
|
+
let keyAttribute = null;
|
|
12735
|
+
let hasSpread = false;
|
|
12736
|
+
let inObject = false;
|
|
12737
|
+
let previousEnd = nameEnd;
|
|
12738
|
+
let hasAttributes = false;
|
|
12739
|
+
let firstAttribute = null;
|
|
12740
|
+
for (const attribute of attributes) {
|
|
12741
|
+
if (attribute instanceof JSXAttribute) {
|
|
12742
|
+
if (extractKeyAttribute && attribute.name.name === 'key') {
|
|
12743
|
+
keyAttribute = attribute;
|
|
12744
|
+
code.remove(previousEnd, attribute.value?.start || attribute.end);
|
|
12745
|
+
continue;
|
|
12746
|
+
}
|
|
12747
|
+
code.appendLeft(previousEnd, ',');
|
|
12748
|
+
if (!inObject) {
|
|
12749
|
+
code.prependRight(attribute.start, '{ ');
|
|
12750
|
+
inObject = true;
|
|
12751
|
+
}
|
|
12752
|
+
hasAttributes = true;
|
|
12753
|
+
}
|
|
12754
|
+
else {
|
|
12755
|
+
if (inObject) {
|
|
12756
|
+
if (hasAttributes) {
|
|
12757
|
+
code.appendLeft(previousEnd, ' ');
|
|
12758
|
+
}
|
|
12759
|
+
code.appendLeft(previousEnd, '},');
|
|
12760
|
+
inObject = false;
|
|
12761
|
+
}
|
|
12762
|
+
else {
|
|
12763
|
+
code.appendLeft(previousEnd, ',');
|
|
12764
|
+
}
|
|
12765
|
+
hasSpread = true;
|
|
12766
|
+
}
|
|
12767
|
+
previousEnd = attribute.end;
|
|
12768
|
+
if (!firstAttribute) {
|
|
12769
|
+
firstAttribute = attribute;
|
|
12770
|
+
}
|
|
12771
|
+
}
|
|
12772
|
+
code.remove(attributes.at(-1)?.end || previousEnd, openingEnd);
|
|
12773
|
+
return { firstAttribute, hasAttributes, hasSpread, inObject, keyAttribute, previousEnd };
|
|
12774
|
+
}
|
|
12775
|
+
wrapAttributes(code, inObject, hasAttributes, hasSpread, firstAttribute, missingAttributesFallback, attributesEnd) {
|
|
12776
|
+
if (inObject) {
|
|
12777
|
+
code.appendLeft(attributesEnd, ' }');
|
|
12778
|
+
}
|
|
12779
|
+
if (hasSpread) {
|
|
12780
|
+
if (hasAttributes) {
|
|
12781
|
+
const { start } = firstAttribute;
|
|
12782
|
+
if (firstAttribute instanceof JSXSpreadAttribute) {
|
|
12783
|
+
code.prependRight(start, '{}, ');
|
|
12784
|
+
}
|
|
12785
|
+
code.prependRight(start, 'Object.assign(');
|
|
12786
|
+
code.appendLeft(attributesEnd, ')');
|
|
12787
|
+
}
|
|
12788
|
+
}
|
|
12789
|
+
else if (!hasAttributes) {
|
|
12790
|
+
code.appendLeft(attributesEnd, `, ${missingAttributesFallback}`);
|
|
12791
|
+
}
|
|
12792
|
+
}
|
|
12793
|
+
}
|
|
12794
|
+
|
|
12795
|
+
class JSXFragment extends JSXElementBase {
|
|
12796
|
+
render(code, options) {
|
|
12797
|
+
switch (this.jsxMode.mode) {
|
|
12798
|
+
case 'classic': {
|
|
12799
|
+
this.renderClassicMode(code, options);
|
|
12800
|
+
break;
|
|
12801
|
+
}
|
|
12802
|
+
case 'automatic': {
|
|
12803
|
+
this.renderAutomaticMode(code, options);
|
|
12804
|
+
break;
|
|
12805
|
+
}
|
|
12806
|
+
default: {
|
|
12807
|
+
super.render(code, options);
|
|
12808
|
+
}
|
|
12809
|
+
}
|
|
12810
|
+
}
|
|
12811
|
+
renderClassicMode(code, options) {
|
|
12812
|
+
const { snippets: { getPropertyAccess }, useOriginalName } = options;
|
|
12813
|
+
const { closingFragment, factory, factoryVariable, openingFragment, start } = this;
|
|
12814
|
+
const [, ...nestedName] = factory.split('.');
|
|
12815
|
+
openingFragment.render(code, options);
|
|
12816
|
+
code.prependRight(start, `/*#__PURE__*/${[
|
|
12817
|
+
factoryVariable.getName(getPropertyAccess, useOriginalName),
|
|
12818
|
+
...nestedName
|
|
12819
|
+
].join('.')}(`);
|
|
12820
|
+
code.appendLeft(openingFragment.end, ', null');
|
|
12821
|
+
this.renderChildren(code, options, openingFragment.end);
|
|
12822
|
+
closingFragment.render(code, options);
|
|
12823
|
+
}
|
|
12824
|
+
renderAutomaticMode(code, options) {
|
|
12825
|
+
const { snippets: { getPropertyAccess }, useOriginalName } = options;
|
|
12826
|
+
const { closingFragment, factoryVariable, openingFragment, start } = this;
|
|
12827
|
+
openingFragment.render(code, options);
|
|
12828
|
+
code.prependRight(start, `/*#__PURE__*/${factoryVariable.getName(getPropertyAccess, useOriginalName)}(`);
|
|
12829
|
+
const { firstChild, hasMultipleChildren, childrenEnd } = this.renderChildren(code, options, openingFragment.end);
|
|
12830
|
+
if (firstChild) {
|
|
12831
|
+
code.prependRight(firstChild.start, `{ children: ${hasMultipleChildren ? '[' : ''}`);
|
|
12832
|
+
if (hasMultipleChildren) {
|
|
12833
|
+
code.appendLeft(closingFragment.start, ']');
|
|
12834
|
+
}
|
|
12835
|
+
code.appendLeft(childrenEnd, ' }');
|
|
12836
|
+
}
|
|
12837
|
+
else {
|
|
12838
|
+
code.appendLeft(openingFragment.end, ', {}');
|
|
12839
|
+
}
|
|
12840
|
+
closingFragment.render(code, options);
|
|
12841
|
+
}
|
|
12842
|
+
}
|
|
12843
|
+
|
|
12844
|
+
class JSXMemberExpression extends NodeBase {
|
|
12845
|
+
}
|
|
12846
|
+
|
|
12847
|
+
class JSXNamespacedName extends NodeBase {
|
|
12848
|
+
}
|
|
12849
|
+
|
|
12850
|
+
class JSXOpeningElement extends NodeBase {
|
|
12851
|
+
render(code, options, { jsxMode = this.scope.context.options.jsx.mode } = {}) {
|
|
12852
|
+
this.name.render(code, options);
|
|
12853
|
+
for (const attribute of this.attributes) {
|
|
12854
|
+
attribute.render(code, options, { jsxMode });
|
|
12855
|
+
}
|
|
12856
|
+
}
|
|
12857
|
+
}
|
|
12858
|
+
|
|
12859
|
+
class JSXOpeningFragment extends NodeBase {
|
|
12860
|
+
constructor() {
|
|
12861
|
+
super(...arguments);
|
|
12862
|
+
this.fragment = null;
|
|
12863
|
+
this.fragmentVariable = null;
|
|
12864
|
+
}
|
|
12865
|
+
include(context, includeChildrenRecursively) {
|
|
12866
|
+
if (!this.included) {
|
|
12867
|
+
const jsx = this.scope.context.options.jsx;
|
|
12868
|
+
if (jsx.mode === 'automatic') {
|
|
12869
|
+
this.fragment = 'Fragment';
|
|
12870
|
+
this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this);
|
|
12871
|
+
}
|
|
12872
|
+
else {
|
|
12873
|
+
const { fragment, importSource, mode } = jsx;
|
|
12874
|
+
if (fragment != null) {
|
|
12875
|
+
this.fragment = fragment;
|
|
12876
|
+
this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this);
|
|
12877
|
+
}
|
|
12878
|
+
}
|
|
12879
|
+
}
|
|
12880
|
+
super.include(context, includeChildrenRecursively);
|
|
12881
|
+
}
|
|
12882
|
+
render(code, options) {
|
|
12883
|
+
const { mode } = this.scope.context.options.jsx;
|
|
12884
|
+
if (mode !== 'preserve') {
|
|
12885
|
+
const { snippets: { getPropertyAccess }, useOriginalName } = options;
|
|
12886
|
+
const [, ...nestedFragment] = this.fragment.split('.');
|
|
12887
|
+
const fragment = [
|
|
12888
|
+
this.fragmentVariable.getName(getPropertyAccess, useOriginalName),
|
|
12889
|
+
...nestedFragment
|
|
12890
|
+
].join('.');
|
|
12891
|
+
code.update(this.start, this.end, fragment);
|
|
12892
|
+
}
|
|
12893
|
+
}
|
|
12894
|
+
}
|
|
12895
|
+
|
|
12896
|
+
class JSXSpreadChild extends NodeBase {
|
|
12897
|
+
render(code, options) {
|
|
12898
|
+
super.render(code, options);
|
|
12899
|
+
const { mode } = this.scope.context.options.jsx;
|
|
12900
|
+
if (mode !== 'preserve') {
|
|
12901
|
+
code.overwrite(this.start, this.expression.start, '...', { contentOnly: true });
|
|
12902
|
+
code.overwrite(this.expression.end, this.end, '', { contentOnly: true });
|
|
12903
|
+
}
|
|
12904
|
+
}
|
|
12905
|
+
}
|
|
12906
|
+
|
|
12907
|
+
class JSXText extends NodeBase {
|
|
12908
|
+
render(code) {
|
|
12909
|
+
const { mode } = this.scope.context.options.jsx;
|
|
12910
|
+
if (mode !== 'preserve') {
|
|
12911
|
+
code.overwrite(this.start, this.end, JSON.stringify(this.value), {
|
|
12912
|
+
contentOnly: true
|
|
12913
|
+
});
|
|
12914
|
+
}
|
|
12915
|
+
}
|
|
12916
|
+
}
|
|
12917
|
+
|
|
12380
12918
|
class LabeledStatement extends NodeBase {
|
|
12381
12919
|
hasEffects(context) {
|
|
12382
12920
|
const { brokenFlow, includedLabels } = context;
|
|
@@ -13705,6 +14243,21 @@ const nodeTypeStrings = [
|
|
|
13705
14243
|
'ImportExpression',
|
|
13706
14244
|
'ImportNamespaceSpecifier',
|
|
13707
14245
|
'ImportSpecifier',
|
|
14246
|
+
'JSXAttribute',
|
|
14247
|
+
'JSXClosingElement',
|
|
14248
|
+
'JSXClosingFragment',
|
|
14249
|
+
'JSXElement',
|
|
14250
|
+
'JSXEmptyExpression',
|
|
14251
|
+
'JSXExpressionContainer',
|
|
14252
|
+
'JSXFragment',
|
|
14253
|
+
'JSXIdentifier',
|
|
14254
|
+
'JSXMemberExpression',
|
|
14255
|
+
'JSXNamespacedName',
|
|
14256
|
+
'JSXOpeningElement',
|
|
14257
|
+
'JSXOpeningFragment',
|
|
14258
|
+
'JSXSpreadAttribute',
|
|
14259
|
+
'JSXSpreadChild',
|
|
14260
|
+
'JSXText',
|
|
13708
14261
|
'LabeledStatement',
|
|
13709
14262
|
'Literal',
|
|
13710
14263
|
'Literal',
|
|
@@ -13787,6 +14340,21 @@ const nodeConstructors$1 = [
|
|
|
13787
14340
|
ImportExpression,
|
|
13788
14341
|
ImportNamespaceSpecifier,
|
|
13789
14342
|
ImportSpecifier,
|
|
14343
|
+
JSXAttribute,
|
|
14344
|
+
JSXClosingElement,
|
|
14345
|
+
JSXClosingFragment,
|
|
14346
|
+
JSXElement,
|
|
14347
|
+
JSXEmptyExpression,
|
|
14348
|
+
JSXExpressionContainer,
|
|
14349
|
+
JSXFragment,
|
|
14350
|
+
JSXIdentifier,
|
|
14351
|
+
JSXMemberExpression,
|
|
14352
|
+
JSXNamespacedName,
|
|
14353
|
+
JSXOpeningElement,
|
|
14354
|
+
JSXOpeningFragment,
|
|
14355
|
+
JSXSpreadAttribute,
|
|
14356
|
+
JSXSpreadChild,
|
|
14357
|
+
JSXText,
|
|
13790
14358
|
LabeledStatement,
|
|
13791
14359
|
Literal,
|
|
13792
14360
|
Literal,
|
|
@@ -14093,6 +14661,74 @@ const bufferParsers = [
|
|
|
14093
14661
|
node.imported =
|
|
14094
14662
|
importedPosition === 0 ? node.local : convertNode(node, scope, importedPosition, buffer);
|
|
14095
14663
|
},
|
|
14664
|
+
function jsxAttribute(node, position, buffer) {
|
|
14665
|
+
const { scope } = node;
|
|
14666
|
+
node.name = convertNode(node, scope, buffer[position], buffer);
|
|
14667
|
+
const valuePosition = buffer[position + 1];
|
|
14668
|
+
node.value = valuePosition === 0 ? null : convertNode(node, scope, valuePosition, buffer);
|
|
14669
|
+
},
|
|
14670
|
+
function jsxClosingElement(node, position, buffer) {
|
|
14671
|
+
const { scope } = node;
|
|
14672
|
+
node.name = convertNode(node, scope, buffer[position], buffer);
|
|
14673
|
+
},
|
|
14674
|
+
function jsxClosingFragment() { },
|
|
14675
|
+
function jsxElement(node, position, buffer) {
|
|
14676
|
+
const { scope } = node;
|
|
14677
|
+
node.openingElement = convertNode(node, scope, buffer[position], buffer);
|
|
14678
|
+
node.children = convertNodeList(node, scope, buffer[position + 1], buffer);
|
|
14679
|
+
const closingElementPosition = buffer[position + 2];
|
|
14680
|
+
node.closingElement =
|
|
14681
|
+
closingElementPosition === 0
|
|
14682
|
+
? null
|
|
14683
|
+
: convertNode(node, scope, closingElementPosition, buffer);
|
|
14684
|
+
},
|
|
14685
|
+
function jsxEmptyExpression() { },
|
|
14686
|
+
function jsxExpressionContainer(node, position, buffer) {
|
|
14687
|
+
const { scope } = node;
|
|
14688
|
+
node.expression = convertNode(node, scope, buffer[position], buffer);
|
|
14689
|
+
},
|
|
14690
|
+
function jsxFragment(node, position, buffer) {
|
|
14691
|
+
const { scope } = node;
|
|
14692
|
+
node.openingFragment = convertNode(node, scope, buffer[position], buffer);
|
|
14693
|
+
node.children = convertNodeList(node, scope, buffer[position + 1], buffer);
|
|
14694
|
+
node.closingFragment = convertNode(node, scope, buffer[position + 2], buffer);
|
|
14695
|
+
},
|
|
14696
|
+
function jsxIdentifier(node, position, buffer) {
|
|
14697
|
+
node.name = buffer.convertString(buffer[position]);
|
|
14698
|
+
},
|
|
14699
|
+
function jsxMemberExpression(node, position, buffer) {
|
|
14700
|
+
const { scope } = node;
|
|
14701
|
+
node.object = convertNode(node, scope, buffer[position], buffer);
|
|
14702
|
+
node.property = convertNode(node, scope, buffer[position + 1], buffer);
|
|
14703
|
+
},
|
|
14704
|
+
function jsxNamespacedName(node, position, buffer) {
|
|
14705
|
+
const { scope } = node;
|
|
14706
|
+
node.namespace = convertNode(node, scope, buffer[position], buffer);
|
|
14707
|
+
node.name = convertNode(node, scope, buffer[position + 1], buffer);
|
|
14708
|
+
},
|
|
14709
|
+
function jsxOpeningElement(node, position, buffer) {
|
|
14710
|
+
const { scope } = node;
|
|
14711
|
+
const flags = buffer[position];
|
|
14712
|
+
node.selfClosing = (flags & 1) === 1;
|
|
14713
|
+
node.name = convertNode(node, scope, buffer[position + 1], buffer);
|
|
14714
|
+
node.attributes = convertNodeList(node, scope, buffer[position + 2], buffer);
|
|
14715
|
+
},
|
|
14716
|
+
function jsxOpeningFragment(node) {
|
|
14717
|
+
node.attributes = [];
|
|
14718
|
+
node.selfClosing = false;
|
|
14719
|
+
},
|
|
14720
|
+
function jsxSpreadAttribute(node, position, buffer) {
|
|
14721
|
+
const { scope } = node;
|
|
14722
|
+
node.argument = convertNode(node, scope, buffer[position], buffer);
|
|
14723
|
+
},
|
|
14724
|
+
function jsxSpreadChild(node, position, buffer) {
|
|
14725
|
+
const { scope } = node;
|
|
14726
|
+
node.expression = convertNode(node, scope, buffer[position], buffer);
|
|
14727
|
+
},
|
|
14728
|
+
function jsxText(node, position, buffer) {
|
|
14729
|
+
node.value = buffer.convertString(buffer[position]);
|
|
14730
|
+
node.raw = buffer.convertString(buffer[position + 1]);
|
|
14731
|
+
},
|
|
14096
14732
|
function labeledStatement(node, position, buffer) {
|
|
14097
14733
|
const { scope } = node;
|
|
14098
14734
|
node.label = convertNode(node, scope, buffer[position], buffer);
|
|
@@ -14382,6 +15018,21 @@ const nodeConstructors = {
|
|
|
14382
15018
|
ImportExpression,
|
|
14383
15019
|
ImportNamespaceSpecifier,
|
|
14384
15020
|
ImportSpecifier,
|
|
15021
|
+
JSXAttribute,
|
|
15022
|
+
JSXClosingElement,
|
|
15023
|
+
JSXClosingFragment,
|
|
15024
|
+
JSXElement,
|
|
15025
|
+
JSXEmptyExpression,
|
|
15026
|
+
JSXExpressionContainer,
|
|
15027
|
+
JSXFragment,
|
|
15028
|
+
JSXIdentifier,
|
|
15029
|
+
JSXMemberExpression,
|
|
15030
|
+
JSXNamespacedName,
|
|
15031
|
+
JSXOpeningElement,
|
|
15032
|
+
JSXOpeningFragment,
|
|
15033
|
+
JSXSpreadAttribute,
|
|
15034
|
+
JSXSpreadChild,
|
|
15035
|
+
JSXText,
|
|
14385
15036
|
LabeledStatement,
|
|
14386
15037
|
Literal,
|
|
14387
15038
|
LogicalExpression,
|
|
@@ -15249,11 +15900,13 @@ class Module {
|
|
|
15249
15900
|
addExport: this.addExport.bind(this),
|
|
15250
15901
|
addImport: this.addImport.bind(this),
|
|
15251
15902
|
addImportMeta: this.addImportMeta.bind(this),
|
|
15903
|
+
addImportSource: this.addImportSource.bind(this),
|
|
15252
15904
|
code, // Only needed for debugging
|
|
15253
15905
|
deoptimizationTracker: this.graph.deoptimizationTracker,
|
|
15254
15906
|
error: this.error.bind(this),
|
|
15255
15907
|
fileName, // Needed for warnings
|
|
15256
15908
|
getExports: this.getExports.bind(this),
|
|
15909
|
+
getImportedJsxFactoryVariable: this.getImportedJsxFactoryVariable.bind(this),
|
|
15257
15910
|
getModuleExecIndex: () => this.execIndex,
|
|
15258
15911
|
getModuleName: this.basename.bind(this),
|
|
15259
15912
|
getNodeConstructor: (name) => nodeConstructors[name] || nodeConstructors.UnknownNode,
|
|
@@ -15283,7 +15936,7 @@ class Module {
|
|
|
15283
15936
|
else {
|
|
15284
15937
|
// Measuring asynchronous code does not provide reasonable results
|
|
15285
15938
|
timeEnd('generate ast', 3);
|
|
15286
|
-
const astBuffer = await parseAsync(code, false);
|
|
15939
|
+
const astBuffer = await parseAsync(code, false, this.options.jsx !== false);
|
|
15287
15940
|
timeStart('generate ast', 3);
|
|
15288
15941
|
this.ast = convertProgram(astBuffer, programParent, this.scope);
|
|
15289
15942
|
// Make lazy and apply LRU cache to not hog the memory
|
|
@@ -15476,6 +16129,11 @@ class Module {
|
|
|
15476
16129
|
});
|
|
15477
16130
|
}
|
|
15478
16131
|
}
|
|
16132
|
+
addImportSource(importSource) {
|
|
16133
|
+
if (importSource && !this.sourcesWithAttributes.has(importSource)) {
|
|
16134
|
+
this.sourcesWithAttributes.set(importSource, EMPTY_OBJECT);
|
|
16135
|
+
}
|
|
16136
|
+
}
|
|
15479
16137
|
addImportMeta(node) {
|
|
15480
16138
|
this.importMetas.push(node);
|
|
15481
16139
|
}
|
|
@@ -15539,6 +16197,15 @@ class Module {
|
|
|
15539
16197
|
this.sourcesWithAttributes.set(source, parsedAttributes);
|
|
15540
16198
|
}
|
|
15541
16199
|
}
|
|
16200
|
+
getImportedJsxFactoryVariable(baseName, nodeStart, importSource) {
|
|
16201
|
+
const { id } = this.resolvedIds[importSource];
|
|
16202
|
+
const module = this.graph.modulesById.get(id);
|
|
16203
|
+
const [variable] = module.getVariableForExportName(baseName);
|
|
16204
|
+
if (!variable) {
|
|
16205
|
+
return this.error(logMissingJsxExport(baseName, id, this.id), nodeStart);
|
|
16206
|
+
}
|
|
16207
|
+
return variable;
|
|
16208
|
+
}
|
|
15542
16209
|
getVariableFromNamespaceReexports(name, importerForSideEffects, searchedNamesAndModules) {
|
|
15543
16210
|
let foundSyntheticDeclaration = null;
|
|
15544
16211
|
const foundInternalDeclarations = new Map();
|
|
@@ -15659,7 +16326,7 @@ class Module {
|
|
|
15659
16326
|
}
|
|
15660
16327
|
tryParse() {
|
|
15661
16328
|
try {
|
|
15662
|
-
return parseAst(this.info.code);
|
|
16329
|
+
return parseAst(this.info.code, { jsx: this.options.jsx !== false });
|
|
15663
16330
|
}
|
|
15664
16331
|
catch (error_) {
|
|
15665
16332
|
return this.error(logModuleParseError(error_, this.id), error_.pos);
|
|
@@ -18412,7 +19079,7 @@ class Bundle {
|
|
|
18412
19079
|
for (const file of Object.values(bundle)) {
|
|
18413
19080
|
if ('code' in file) {
|
|
18414
19081
|
try {
|
|
18415
|
-
parseAst(file.code);
|
|
19082
|
+
parseAst(file.code, { jsx: this.inputOptions.jsx !== false });
|
|
18416
19083
|
}
|
|
18417
19084
|
catch (error_) {
|
|
18418
19085
|
this.inputOptions.onLog(LOGLEVEL_WARN, logChunkInvalid(file, error_));
|
|
@@ -18807,6 +19474,32 @@ const treeshakePresets = {
|
|
|
18807
19474
|
unknownGlobalSideEffects: false
|
|
18808
19475
|
}
|
|
18809
19476
|
};
|
|
19477
|
+
const jsxPresets = {
|
|
19478
|
+
preserve: {
|
|
19479
|
+
factory: null,
|
|
19480
|
+
fragment: null,
|
|
19481
|
+
importSource: null,
|
|
19482
|
+
mode: 'preserve'
|
|
19483
|
+
},
|
|
19484
|
+
'preserve-react': {
|
|
19485
|
+
factory: 'React.createElement',
|
|
19486
|
+
fragment: 'React.Fragment',
|
|
19487
|
+
importSource: 'react',
|
|
19488
|
+
mode: 'preserve'
|
|
19489
|
+
},
|
|
19490
|
+
react: {
|
|
19491
|
+
factory: 'React.createElement',
|
|
19492
|
+
fragment: 'React.Fragment',
|
|
19493
|
+
importSource: 'react',
|
|
19494
|
+
mode: 'classic'
|
|
19495
|
+
},
|
|
19496
|
+
'react-jsx': {
|
|
19497
|
+
factory: 'React.createElement',
|
|
19498
|
+
importSource: 'react',
|
|
19499
|
+
jsxImportSource: 'react/jsx-runtime',
|
|
19500
|
+
mode: 'automatic'
|
|
19501
|
+
}
|
|
19502
|
+
};
|
|
18810
19503
|
const generatedCodePresets = {
|
|
18811
19504
|
es2015: {
|
|
18812
19505
|
arrowFunctions: true,
|
|
@@ -20471,6 +21164,7 @@ async function normalizeInputOptions(config, watchMode) {
|
|
|
20471
21164
|
experimentalLogSideEffects: config.experimentalLogSideEffects || false,
|
|
20472
21165
|
external: getIdMatcher(config.external),
|
|
20473
21166
|
input: getInput(config),
|
|
21167
|
+
jsx: getJsx(config),
|
|
20474
21168
|
logLevel,
|
|
20475
21169
|
makeAbsoluteExternalsRelative: config.makeAbsoluteExternalsRelative ?? 'ifRelativeSource',
|
|
20476
21170
|
maxParallelFileOps,
|
|
@@ -20516,6 +21210,46 @@ const getInput = (config) => {
|
|
|
20516
21210
|
const configInput = config.input;
|
|
20517
21211
|
return configInput == null ? [] : typeof configInput === 'string' ? [configInput] : configInput;
|
|
20518
21212
|
};
|
|
21213
|
+
const getJsx = (config) => {
|
|
21214
|
+
const configJsx = config.jsx;
|
|
21215
|
+
if (!configJsx)
|
|
21216
|
+
return false;
|
|
21217
|
+
const configWithPreset = getOptionWithPreset(configJsx, jsxPresets, 'jsx', URL_JSX, 'false, ');
|
|
21218
|
+
const { factory, importSource, mode } = configWithPreset;
|
|
21219
|
+
switch (mode) {
|
|
21220
|
+
case 'automatic': {
|
|
21221
|
+
return {
|
|
21222
|
+
factory: factory || 'React.createElement',
|
|
21223
|
+
importSource: importSource || 'react',
|
|
21224
|
+
jsxImportSource: configWithPreset.jsxImportSource || 'react/jsx-runtime',
|
|
21225
|
+
mode: 'automatic'
|
|
21226
|
+
};
|
|
21227
|
+
}
|
|
21228
|
+
case 'preserve': {
|
|
21229
|
+
if (importSource && !(factory || configWithPreset.fragment)) {
|
|
21230
|
+
error(logInvalidOption('jsx', URL_JSX, 'when preserving JSX and specifying an importSource, you also need to specify a factory or fragment'));
|
|
21231
|
+
}
|
|
21232
|
+
return {
|
|
21233
|
+
factory: factory || null,
|
|
21234
|
+
fragment: configWithPreset.fragment || null,
|
|
21235
|
+
importSource: importSource || null,
|
|
21236
|
+
mode: 'preserve'
|
|
21237
|
+
};
|
|
21238
|
+
}
|
|
21239
|
+
// case 'classic':
|
|
21240
|
+
default: {
|
|
21241
|
+
if (mode && mode !== 'classic') {
|
|
21242
|
+
error(logInvalidOption('jsx.mode', URL_JSX, 'mode must be "automatic", "classic" or "preserve"', mode));
|
|
21243
|
+
}
|
|
21244
|
+
return {
|
|
21245
|
+
factory: factory || 'React.createElement',
|
|
21246
|
+
fragment: configWithPreset.fragment || 'React.Fragment',
|
|
21247
|
+
importSource: importSource || null,
|
|
21248
|
+
mode: 'classic'
|
|
21249
|
+
};
|
|
21250
|
+
}
|
|
21251
|
+
}
|
|
21252
|
+
};
|
|
20519
21253
|
const getMaxParallelFileOps = (config) => {
|
|
20520
21254
|
const maxParallelFileOps = config.maxParallelFileOps;
|
|
20521
21255
|
if (typeof maxParallelFileOps === 'number') {
|
|
@@ -21270,6 +22004,7 @@ function mergeInputOptions(config, overrides, plugins, log, onLog) {
|
|
|
21270
22004
|
experimentalLogSideEffects: getOption('experimentalLogSideEffects'),
|
|
21271
22005
|
external: getExternal(config, overrides),
|
|
21272
22006
|
input: getOption('input') || [],
|
|
22007
|
+
jsx: getObjectOption(config, overrides, 'jsx', objectifyOptionWithPresets(jsxPresets, 'jsx', URL_JSX, 'false, ')),
|
|
21273
22008
|
logLevel: getOption('logLevel'),
|
|
21274
22009
|
makeAbsoluteExternalsRelative: getOption('makeAbsoluteExternalsRelative'),
|
|
21275
22010
|
maxParallelFileOps: getOption('maxParallelFileOps'),
|