@bamboocss/extractor 1.48.5 → 1.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +330 -329
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +222 -221
- package/package.json +6 -3
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _bamboocss_shared = require("@bamboocss/shared");
|
|
3
|
-
let
|
|
3
|
+
let _bamboocss_ts_ast = require("@bamboocss/ts-ast");
|
|
4
4
|
let ts_evaluator = require("ts-evaluator");
|
|
5
5
|
//#region src/get-typeof-literal.ts
|
|
6
6
|
const getTypeOfLiteral = (value) => {
|
|
@@ -25,15 +25,15 @@ const isPrimitiveType = (value) => {
|
|
|
25
25
|
return type === "string" || type === "number" || type === "boolean" || value === null || value === void 0;
|
|
26
26
|
};
|
|
27
27
|
const unwrapExpression = (node) => {
|
|
28
|
-
if (
|
|
29
|
-
if (
|
|
30
|
-
if (
|
|
31
|
-
if (
|
|
32
|
-
if (
|
|
28
|
+
if (_bamboocss_ts_ast.Node.isAsExpression(node)) return unwrapExpression(node.expression);
|
|
29
|
+
if (_bamboocss_ts_ast.Node.isParenthesizedExpression(node)) return unwrapExpression(node.expression);
|
|
30
|
+
if (_bamboocss_ts_ast.Node.isNonNullExpression(node)) return unwrapExpression(node.expression);
|
|
31
|
+
if (_bamboocss_ts_ast.Node.isTypeAssertion(node)) return unwrapExpression(node.expression);
|
|
32
|
+
if (_bamboocss_ts_ast.Node.isSatisfiesExpression(node)) return unwrapExpression(node.expression);
|
|
33
33
|
return node;
|
|
34
34
|
};
|
|
35
35
|
const getComponentName = (node) => {
|
|
36
|
-
return node.
|
|
36
|
+
return node.tagName.getText();
|
|
37
37
|
};
|
|
38
38
|
const whitespaceRegex = /\s+/g;
|
|
39
39
|
const trimWhitespace = (str) => {
|
|
@@ -44,8 +44,8 @@ const trimWhitespace = (str) => {
|
|
|
44
44
|
const getNodeRange = (node) => {
|
|
45
45
|
const src = node.getSourceFile();
|
|
46
46
|
const [startPosition, endPosition] = [node.getStart(), node.getEnd()];
|
|
47
|
-
const startInfo =
|
|
48
|
-
const endInfo =
|
|
47
|
+
const startInfo = (0, _bamboocss_ts_ast.getLineAndColumnAtPos)(src, startPosition);
|
|
48
|
+
const endInfo = (0, _bamboocss_ts_ast.getLineAndColumnAtPos)(src, endPosition);
|
|
49
49
|
return {
|
|
50
50
|
startPosition,
|
|
51
51
|
startLineNumber: startInfo.line,
|
|
@@ -78,7 +78,7 @@ var BoxNodeType = class {
|
|
|
78
78
|
return {
|
|
79
79
|
type: this.type,
|
|
80
80
|
value: this.value,
|
|
81
|
-
node: this.node.
|
|
81
|
+
node: (0, _bamboocss_ts_ast.kindNameOf)(this.node.kind),
|
|
82
82
|
line: range.startLineNumber,
|
|
83
83
|
column: range.startColumn,
|
|
84
84
|
endLineNumber: range.endLineNumber,
|
|
@@ -446,15 +446,15 @@ const clearImportedValueCache = () => {
|
|
|
446
446
|
*/
|
|
447
447
|
const importBindingsFor = (sourceFile) => {
|
|
448
448
|
const bindings = /* @__PURE__ */ new Map();
|
|
449
|
-
for (const declaration of
|
|
450
|
-
for (const specifier of
|
|
451
|
-
const local = (
|
|
452
|
-
bindings.set(local, {
|
|
449
|
+
for (const declaration of (0, _bamboocss_ts_ast.getImportDeclarations)(sourceFile)) {
|
|
450
|
+
for (const specifier of (0, _bamboocss_ts_ast.getNamedImports)(declaration)) {
|
|
451
|
+
const local = ((0, _bamboocss_ts_ast.getAliasNode)(specifier) ?? (0, _bamboocss_ts_ast.nameNodeOf)(specifier))?.getText();
|
|
452
|
+
bindings.set(local ?? "", {
|
|
453
453
|
declaration,
|
|
454
|
-
exportedName:
|
|
454
|
+
exportedName: (0, _bamboocss_ts_ast.nameNodeOf)(specifier)?.getText() ?? ""
|
|
455
455
|
});
|
|
456
456
|
}
|
|
457
|
-
const defaultImport =
|
|
457
|
+
const defaultImport = (0, _bamboocss_ts_ast.getDefaultImport)(declaration);
|
|
458
458
|
if (defaultImport) bindings.set(defaultImport.getText(), {
|
|
459
459
|
declaration,
|
|
460
460
|
exportedName: "default"
|
|
@@ -466,7 +466,7 @@ const importBindingsFor = (sourceFile) => {
|
|
|
466
466
|
const valueForBinding = (binding, ctx, stack, depth, evaluateExpression) => {
|
|
467
467
|
const sourceFile = getModuleSpecifierSourceFile(binding.declaration, ctx);
|
|
468
468
|
if (!sourceFile) return;
|
|
469
|
-
if (
|
|
469
|
+
if ((0, _bamboocss_ts_ast.isInNodeModules)(sourceFile)) return;
|
|
470
470
|
const declaration = getExportedVarDeclarationWithName(binding.exportedName, sourceFile, stack, ctx);
|
|
471
471
|
if (!declaration) return;
|
|
472
472
|
const cached = evaluatedValues.get(declaration);
|
|
@@ -474,7 +474,7 @@ const valueForBinding = (binding, ctx, stack, depth, evaluateExpression) => {
|
|
|
474
474
|
const replayed = replayDependencyCache(cached, ctx);
|
|
475
475
|
if (replayed.hit) return { value: replayed.value };
|
|
476
476
|
}
|
|
477
|
-
const initializer = declaration.
|
|
477
|
+
const initializer = declaration.initializer;
|
|
478
478
|
if (!initializer) return;
|
|
479
479
|
const capture = beginDependencyCapture(ctx);
|
|
480
480
|
let value;
|
|
@@ -500,8 +500,8 @@ const importedEnvironmentFor = (node, ctx, stack, depth, evaluateExpression) =>
|
|
|
500
500
|
if (depth >= MAX_DEPTH) return;
|
|
501
501
|
const bindings = importBindingsFor(node.getSourceFile());
|
|
502
502
|
if (!bindings.size) return;
|
|
503
|
-
const references =
|
|
504
|
-
if (
|
|
503
|
+
const references = (0, _bamboocss_ts_ast.getDescendantsOfKind)(node, _bamboocss_ts_ast.SyntaxKind.Identifier);
|
|
504
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(node)) references.unshift(node);
|
|
505
505
|
if (!references.length) return;
|
|
506
506
|
let environment;
|
|
507
507
|
for (const reference of references) {
|
|
@@ -572,8 +572,8 @@ const evaluateNodeUncached = (node, stack, ctx, depth, dependencyEntry) => {
|
|
|
572
572
|
let options = {
|
|
573
573
|
policy: { ...POLICY },
|
|
574
574
|
...ctx.getEvaluateOptions?.(node, stack),
|
|
575
|
-
node
|
|
576
|
-
typescript:
|
|
575
|
+
node,
|
|
576
|
+
typescript: _bamboocss_ts_ast.ts
|
|
577
577
|
};
|
|
578
578
|
let imported = depth > 0 ? importedEnvironmentFor(node, ctx, stack, depth, safeEvaluateNode) : void 0;
|
|
579
579
|
if (imported) {
|
|
@@ -630,22 +630,22 @@ const safeEvaluateNode = (node, stack, ctx, depth = 0) => {
|
|
|
630
630
|
//#endregion
|
|
631
631
|
//#region src/find-identifier-value-declaration.ts
|
|
632
632
|
function isScope(node) {
|
|
633
|
-
return
|
|
633
|
+
return _bamboocss_ts_ast.Node.isFunctionDeclaration(node) || _bamboocss_ts_ast.Node.isFunctionExpression(node) || _bamboocss_ts_ast.Node.isArrowFunction(node) || _bamboocss_ts_ast.Node.isSourceFile(node);
|
|
634
634
|
}
|
|
635
635
|
function getDeclarationFor(node, stack, ctx) {
|
|
636
|
-
const parent = node.
|
|
636
|
+
const parent = node.parent;
|
|
637
637
|
if (!parent) return;
|
|
638
638
|
const declarationStack = [];
|
|
639
639
|
let declaration;
|
|
640
|
-
if ((
|
|
640
|
+
if ((_bamboocss_ts_ast.Node.isVariableDeclaration(parent) || _bamboocss_ts_ast.Node.isParameterDeclaration(parent) || _bamboocss_ts_ast.Node.isFunctionDeclaration(parent) || _bamboocss_ts_ast.Node.isEnumDeclaration(parent) || _bamboocss_ts_ast.Node.isBindingElement(parent)) && parent.name == node) {
|
|
641
641
|
declarationStack.push(parent);
|
|
642
642
|
declaration = parent;
|
|
643
|
-
} else if (
|
|
643
|
+
} else if (_bamboocss_ts_ast.Node.isImportSpecifier(parent) && ((0, _bamboocss_ts_ast.nameNodeOf)(parent) == node || (0, _bamboocss_ts_ast.getAliasNode)(parent) == node)) {
|
|
644
644
|
if (ctx.flags?.skipTraverseFiles) return;
|
|
645
|
-
const sourceFile = getModuleSpecifierSourceFile(parent.
|
|
645
|
+
const sourceFile = getModuleSpecifierSourceFile(parent.parent?.parent?.parent, ctx);
|
|
646
646
|
if (sourceFile) {
|
|
647
647
|
const exportStack = [parent, sourceFile];
|
|
648
|
-
const maybeVar = getExportedVarDeclarationWithName(
|
|
648
|
+
const maybeVar = getExportedVarDeclarationWithName((0, _bamboocss_ts_ast.nameNodeOf)(parent)?.getText() ?? "", sourceFile, exportStack, ctx);
|
|
649
649
|
if (maybeVar) {
|
|
650
650
|
declarationStack.push(...exportStack.concat(maybeVar));
|
|
651
651
|
declaration = maybeVar;
|
|
@@ -656,8 +656,8 @@ function getDeclarationFor(node, stack, ctx) {
|
|
|
656
656
|
return declaration;
|
|
657
657
|
}
|
|
658
658
|
const getInnermostScope = (from) => {
|
|
659
|
-
let scope = from.
|
|
660
|
-
while (scope && !isScope(scope)) scope = scope.
|
|
659
|
+
let scope = from.parent;
|
|
660
|
+
while (scope && !isScope(scope)) scope = scope.parent;
|
|
661
661
|
return scope;
|
|
662
662
|
};
|
|
663
663
|
/**
|
|
@@ -671,8 +671,8 @@ const getInnermostScope = (from) => {
|
|
|
671
671
|
*/
|
|
672
672
|
const declarationIndexes = /* @__PURE__ */ new WeakMap();
|
|
673
673
|
const isDeclarationName = (node, parent) => {
|
|
674
|
-
if (
|
|
675
|
-
return
|
|
674
|
+
if (_bamboocss_ts_ast.Node.isVariableDeclaration(parent) || _bamboocss_ts_ast.Node.isParameterDeclaration(parent) || _bamboocss_ts_ast.Node.isFunctionDeclaration(parent) || _bamboocss_ts_ast.Node.isEnumDeclaration(parent) || _bamboocss_ts_ast.Node.isBindingElement(parent)) return parent.name == node;
|
|
675
|
+
return _bamboocss_ts_ast.Node.isImportSpecifier(parent) && ((0, _bamboocss_ts_ast.nameNodeOf)(parent) == node || (0, _bamboocss_ts_ast.getAliasNode)(parent) == node);
|
|
676
676
|
};
|
|
677
677
|
/**
|
|
678
678
|
* Walk a scope once, so that every later lookup inside it is a map read.
|
|
@@ -683,19 +683,19 @@ const isDeclarationName = (node, parent) => {
|
|
|
683
683
|
* ts-morph charges for wrapping each node — it measured ~10% of extraction on its own.
|
|
684
684
|
*/
|
|
685
685
|
const declarationIndexFor = (scope) => {
|
|
686
|
-
const cached = declarationIndexes.get(scope
|
|
686
|
+
const cached = declarationIndexes.get(scope);
|
|
687
687
|
if (cached) return cached;
|
|
688
688
|
const index = /* @__PURE__ */ new Map();
|
|
689
|
-
|
|
690
|
-
if (!
|
|
691
|
-
const parent = node.
|
|
689
|
+
(0, _bamboocss_ts_ast.forEachDescendant)(scope, (node) => {
|
|
690
|
+
if (!_bamboocss_ts_ast.Node.isIdentifier(node)) return;
|
|
691
|
+
const parent = node.parent;
|
|
692
692
|
if (!parent || !isDeclarationName(node, parent)) return;
|
|
693
693
|
const name = node.getText();
|
|
694
694
|
const declared = index.get(name);
|
|
695
695
|
if (declared) declared.push(node);
|
|
696
696
|
else index.set(name, [node]);
|
|
697
697
|
});
|
|
698
|
-
declarationIndexes.set(scope
|
|
698
|
+
declarationIndexes.set(scope, index);
|
|
699
699
|
return index;
|
|
700
700
|
};
|
|
701
701
|
function findIdentifierValueDeclaration(identifier, stack, ctx, visitedsWithStack = /* @__PURE__ */ new Map()) {
|
|
@@ -714,11 +714,11 @@ function findIdentifierValueDeclaration(identifier, stack, ctx, visitedsWithStac
|
|
|
714
714
|
const declarationStack = [candidate];
|
|
715
715
|
const maybeDeclaration = getDeclarationFor(candidate, declarationStack, ctx);
|
|
716
716
|
if (!maybeDeclaration) continue;
|
|
717
|
-
if (
|
|
718
|
-
const initializer = maybeDeclaration.
|
|
719
|
-
const typeNode = maybeDeclaration.
|
|
717
|
+
if (_bamboocss_ts_ast.Node.isParameterDeclaration(maybeDeclaration)) {
|
|
718
|
+
const initializer = maybeDeclaration.initializer;
|
|
719
|
+
const typeNode = maybeDeclaration.type;
|
|
720
720
|
if (initializer) innerStack.push(...declarationStack.concat(initializer));
|
|
721
|
-
else if (typeNode &&
|
|
721
|
+
else if (typeNode && _bamboocss_ts_ast.Node.isTypeLiteralNode(typeNode)) innerStack.push(...declarationStack.concat(typeNode));
|
|
722
722
|
else return;
|
|
723
723
|
stack.push(...innerStack);
|
|
724
724
|
return maybeDeclaration;
|
|
@@ -727,41 +727,41 @@ function findIdentifierValueDeclaration(identifier, stack, ctx, visitedsWithStac
|
|
|
727
727
|
stack.push(...innerStack);
|
|
728
728
|
return maybeDeclaration;
|
|
729
729
|
}
|
|
730
|
-
} while (scope && !
|
|
730
|
+
} while (scope && !_bamboocss_ts_ast.Node.isSourceFile(scope) && count < 100);
|
|
731
731
|
}
|
|
732
732
|
//#endregion
|
|
733
733
|
//#region src/get-property-name.ts
|
|
734
734
|
const getPropertyName = (property, stack, ctx) => {
|
|
735
735
|
if (!property) return;
|
|
736
|
-
if (
|
|
737
|
-
const node = unwrapExpression(property.
|
|
738
|
-
if (
|
|
739
|
-
if (
|
|
740
|
-
const expression = node.
|
|
736
|
+
if (_bamboocss_ts_ast.Node.isPropertyAssignment(property)) {
|
|
737
|
+
const node = unwrapExpression(property.name);
|
|
738
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(node)) return box.from(node.getText(), node, stack);
|
|
739
|
+
if (_bamboocss_ts_ast.Node.isComputedPropertyName(node)) {
|
|
740
|
+
const expression = node.expression;
|
|
741
741
|
stack.push(expression);
|
|
742
742
|
return maybePropName(expression, stack, ctx);
|
|
743
743
|
}
|
|
744
|
-
if (
|
|
744
|
+
if (_bamboocss_ts_ast.Node.isStringLiteral(node) || _bamboocss_ts_ast.Node.isNumericLiteral(node)) return box.from((0, _bamboocss_ts_ast.getLiteralText)(node), node, stack);
|
|
745
745
|
}
|
|
746
|
-
if (
|
|
747
|
-
const name =
|
|
746
|
+
if (_bamboocss_ts_ast.Node.isShorthandPropertyAssignment(property)) {
|
|
747
|
+
const name = (0, _bamboocss_ts_ast.getName)(property);
|
|
748
748
|
if (name != null) return box.from(name, property, stack);
|
|
749
749
|
}
|
|
750
|
-
if (
|
|
751
|
-
const node = unwrapExpression(property.
|
|
752
|
-
if (
|
|
753
|
-
if (
|
|
754
|
-
const expression = node.
|
|
750
|
+
if (_bamboocss_ts_ast.Node.isGetAccessorDeclaration(property)) {
|
|
751
|
+
const node = unwrapExpression(property.name);
|
|
752
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(node)) return box.from(node.getText(), node, stack);
|
|
753
|
+
if (_bamboocss_ts_ast.Node.isComputedPropertyName(node)) {
|
|
754
|
+
const expression = node.expression;
|
|
755
755
|
stack.push(expression);
|
|
756
756
|
return maybePropName(expression, stack, ctx);
|
|
757
757
|
}
|
|
758
|
-
if (
|
|
758
|
+
if (_bamboocss_ts_ast.Node.isStringLiteral(node) || _bamboocss_ts_ast.Node.isNumericLiteral(node)) return box.from((0, _bamboocss_ts_ast.getLiteralText)(node), node, stack);
|
|
759
759
|
}
|
|
760
760
|
};
|
|
761
761
|
//#endregion
|
|
762
762
|
//#region src/get-object-literal-expression-prop-pairs.ts
|
|
763
763
|
const getObjectLiteralExpressionPropPairs = (expression, expressionStack, ctx, matchProp) => {
|
|
764
|
-
const properties = expression.
|
|
764
|
+
const properties = expression.properties;
|
|
765
765
|
if (properties.length === 0) return box.emptyObject(expression, expressionStack);
|
|
766
766
|
const extractedPropValues = [];
|
|
767
767
|
const spreadConditions = [];
|
|
@@ -770,7 +770,7 @@ const getObjectLiteralExpressionPropPairs = (expression, expressionStack, ctx, m
|
|
|
770
770
|
properties.forEach((property) => {
|
|
771
771
|
const stack = [...expressionStack];
|
|
772
772
|
stack.push(property);
|
|
773
|
-
if (
|
|
773
|
+
if (_bamboocss_ts_ast.Node.isPropertyAssignment(property) || _bamboocss_ts_ast.Node.isShorthandPropertyAssignment(property) || _bamboocss_ts_ast.Node.isGetAccessorDeclaration(property)) {
|
|
774
774
|
const propNameBox = getPropertyName(property, stack, ctx);
|
|
775
775
|
if (!propNameBox) return;
|
|
776
776
|
const propName = propNameBox.value;
|
|
@@ -779,8 +779,8 @@ const getObjectLiteralExpressionPropPairs = (expression, expressionStack, ctx, m
|
|
|
779
779
|
propName,
|
|
780
780
|
propNode: property
|
|
781
781
|
})) return;
|
|
782
|
-
if (
|
|
783
|
-
const initializer = property.
|
|
782
|
+
if (_bamboocss_ts_ast.Node.isShorthandPropertyAssignment(property)) {
|
|
783
|
+
const initializer = property.name;
|
|
784
784
|
stack.push(initializer);
|
|
785
785
|
const maybeValue = maybeBoxNode(initializer, stack, ctx);
|
|
786
786
|
if (maybeValue) {
|
|
@@ -789,12 +789,12 @@ const getObjectLiteralExpressionPropPairs = (expression, expressionStack, ctx, m
|
|
|
789
789
|
}
|
|
790
790
|
}
|
|
791
791
|
let init;
|
|
792
|
-
if (
|
|
793
|
-
const body = property.
|
|
794
|
-
init =
|
|
795
|
-
} else init =
|
|
792
|
+
if (_bamboocss_ts_ast.Node.isGetAccessorDeclaration(property)) {
|
|
793
|
+
const body = property.body;
|
|
794
|
+
init = body !== void 0 && _bamboocss_ts_ast.Node.isBlock(body) ? body.statements.at(-1) : void 0;
|
|
795
|
+
} else init = (0, _bamboocss_ts_ast.childOf)(property, "initializer");
|
|
796
796
|
if (!init) return;
|
|
797
|
-
const initializer = unwrapExpression((
|
|
797
|
+
const initializer = unwrapExpression((_bamboocss_ts_ast.Node.isReturnStatement(init) ? init.expression : void 0) ?? init);
|
|
798
798
|
stack.push(initializer);
|
|
799
799
|
const maybeValue = maybeBoxNode(initializer, stack, ctx);
|
|
800
800
|
if (maybeValue) {
|
|
@@ -802,8 +802,8 @@ const getObjectLiteralExpressionPropPairs = (expression, expressionStack, ctx, m
|
|
|
802
802
|
return;
|
|
803
803
|
}
|
|
804
804
|
}
|
|
805
|
-
if (
|
|
806
|
-
const initializer = unwrapExpression(property.
|
|
805
|
+
if (_bamboocss_ts_ast.Node.isSpreadAssignment(property)) {
|
|
806
|
+
const initializer = unwrapExpression(property.expression);
|
|
807
807
|
stack.push(initializer);
|
|
808
808
|
const maybeObject = maybeBoxNode(initializer, stack, ctx, matchProp);
|
|
809
809
|
if (!maybeObject) return;
|
|
@@ -858,11 +858,11 @@ const clearBoxNodeCache = () => {
|
|
|
858
858
|
hasCachedEntries = false;
|
|
859
859
|
};
|
|
860
860
|
let hasCachedEntries = false;
|
|
861
|
-
const isPlusSyntax = (op) => op ===
|
|
862
|
-
const isLogicalSyntax = (op) => op ===
|
|
863
|
-
const isOperationSyntax = (op) => op ===
|
|
861
|
+
const isPlusSyntax = (op) => op === _bamboocss_ts_ast.ts.SyntaxKind.PlusToken;
|
|
862
|
+
const isLogicalSyntax = (op) => op === _bamboocss_ts_ast.ts.SyntaxKind.BarBarToken || op === _bamboocss_ts_ast.ts.SyntaxKind.QuestionQuestionToken || op === _bamboocss_ts_ast.ts.SyntaxKind.AmpersandAmpersandToken || op === _bamboocss_ts_ast.ts.SyntaxKind.EqualsEqualsEqualsToken || op === _bamboocss_ts_ast.ts.SyntaxKind.EqualsEqualsToken || op === _bamboocss_ts_ast.ts.SyntaxKind.ExclamationEqualsEqualsToken || op === _bamboocss_ts_ast.ts.SyntaxKind.ExclamationEqualsToken || op === _bamboocss_ts_ast.ts.SyntaxKind.GreaterThanEqualsToken || op === _bamboocss_ts_ast.ts.SyntaxKind.GreaterThanToken || op === _bamboocss_ts_ast.ts.SyntaxKind.LessThanEqualsToken || op === _bamboocss_ts_ast.ts.SyntaxKind.LessThanToken || op === _bamboocss_ts_ast.ts.SyntaxKind.InstanceOfKeyword || op === _bamboocss_ts_ast.ts.SyntaxKind.InKeyword;
|
|
863
|
+
const isOperationSyntax = (op) => op === _bamboocss_ts_ast.ts.SyntaxKind.AsteriskToken || op === _bamboocss_ts_ast.ts.SyntaxKind.SlashToken || op === _bamboocss_ts_ast.ts.SyntaxKind.PercentToken || op === _bamboocss_ts_ast.ts.SyntaxKind.AsteriskAsteriskToken || op === _bamboocss_ts_ast.ts.SyntaxKind.MinusToken;
|
|
864
864
|
const canReturnWhenTrueInLogicalExpression = (op) => {
|
|
865
|
-
return op ===
|
|
865
|
+
return op === _bamboocss_ts_ast.ts.SyntaxKind.BarBarToken || op === _bamboocss_ts_ast.ts.SyntaxKind.QuestionQuestionToken;
|
|
866
866
|
};
|
|
867
867
|
function maybeBoxNode(node, stack, ctx, matchProp) {
|
|
868
868
|
const cached = getCached(node);
|
|
@@ -883,76 +883,76 @@ function maybeBoxNodeUncached(node, stack, ctx, matchProp, dependencyEntry) {
|
|
|
883
883
|
hasCachedEntries = true;
|
|
884
884
|
return value;
|
|
885
885
|
};
|
|
886
|
-
if (
|
|
887
|
-
const value = trimWhitespace(
|
|
886
|
+
if (_bamboocss_ts_ast.Node.isStringLiteral(node) || _bamboocss_ts_ast.Node.isNoSubstitutionTemplateLiteral(node)) {
|
|
887
|
+
const value = trimWhitespace((0, _bamboocss_ts_ast.stringLiteralValue)(node));
|
|
888
888
|
return cache(box.literal(value, node, stack));
|
|
889
889
|
}
|
|
890
|
-
if (
|
|
891
|
-
if (
|
|
892
|
-
const value =
|
|
890
|
+
if (_bamboocss_ts_ast.Node.isObjectLiteralExpression(node)) return cache(getObjectLiteralExpressionPropPairs(node, stack, ctx, matchProp));
|
|
891
|
+
if (_bamboocss_ts_ast.Node.isTrueLiteral(node) || _bamboocss_ts_ast.Node.isFalseLiteral(node)) {
|
|
892
|
+
const value = (0, _bamboocss_ts_ast.literalValueOf)(node);
|
|
893
893
|
return cache(box.literal(value, node, stack));
|
|
894
894
|
}
|
|
895
|
-
if (
|
|
896
|
-
const value =
|
|
895
|
+
if (_bamboocss_ts_ast.Node.isNumericLiteral(node)) {
|
|
896
|
+
const value = (0, _bamboocss_ts_ast.literalValueOf)(node);
|
|
897
897
|
return cache(box.literal(value, node, stack));
|
|
898
898
|
}
|
|
899
|
-
if (
|
|
900
|
-
if (
|
|
901
|
-
const operand = node.
|
|
902
|
-
const operator = node.
|
|
899
|
+
if (_bamboocss_ts_ast.Node.isNullLiteral(node)) return cache(box.literal(null, node, stack));
|
|
900
|
+
if (_bamboocss_ts_ast.Node.isPrefixUnaryExpression(node)) {
|
|
901
|
+
const operand = node.operand;
|
|
902
|
+
const operator = node.operator;
|
|
903
903
|
const boxNode = maybeBoxNode(operand, stack, ctx);
|
|
904
904
|
if (!box.isNumberLiteral(boxNode)) return;
|
|
905
|
-
return cache(operator ===
|
|
905
|
+
return cache(operator === _bamboocss_ts_ast.ts.SyntaxKind.MinusToken ? box.literal(-Number(boxNode.value), node, stack) : boxNode);
|
|
906
906
|
}
|
|
907
|
-
if (
|
|
908
|
-
const boxNodes = node.
|
|
907
|
+
if (_bamboocss_ts_ast.Node.isArrayLiteralExpression(node)) {
|
|
908
|
+
const boxNodes = node.elements.map((element) => {
|
|
909
909
|
return maybeBoxNode(element, stack, ctx) ?? cache(box.unresolvable(element, stack));
|
|
910
910
|
});
|
|
911
911
|
return cache(box.array(boxNodes, node, stack));
|
|
912
912
|
}
|
|
913
|
-
if (
|
|
913
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(node)) {
|
|
914
914
|
if (node.getText() === "undefined") return cache(box.literal(void 0, node, stack));
|
|
915
915
|
return cache(maybeIdentifierValue(node, stack, ctx));
|
|
916
916
|
}
|
|
917
|
-
if (
|
|
918
|
-
if (
|
|
917
|
+
if (_bamboocss_ts_ast.Node.isTemplateHead(node)) return cache(box.literal((0, _bamboocss_ts_ast.getLiteralText)(node), node, stack));
|
|
918
|
+
if (_bamboocss_ts_ast.Node.isTemplateExpression(node)) {
|
|
919
919
|
const value = maybeTemplateStringValue(node, stack, ctx);
|
|
920
920
|
return cache(box.literal(value, node, stack));
|
|
921
921
|
}
|
|
922
|
-
if (
|
|
923
|
-
if (
|
|
924
|
-
if (
|
|
925
|
-
if (
|
|
922
|
+
if (_bamboocss_ts_ast.Node.isTaggedTemplateExpression(node)) return cache(maybeBoxNode(node.template, stack, ctx));
|
|
923
|
+
if (_bamboocss_ts_ast.Node.isElementAccessExpression(node)) return cache(getElementAccessedExpressionValue(node, stack, ctx));
|
|
924
|
+
if (_bamboocss_ts_ast.Node.isPropertyAccessExpression(node)) return cache(getPropertyAccessedExpressionValue(node, [], stack, ctx));
|
|
925
|
+
if (_bamboocss_ts_ast.Node.isConditionalExpression(node)) {
|
|
926
926
|
if (ctx.flags?.skipConditions) return cache(box.unresolvable(node, stack));
|
|
927
|
-
const condExpr = unwrapExpression(node.
|
|
928
|
-
const condBoxNode = (
|
|
927
|
+
const condExpr = unwrapExpression(node.condition);
|
|
928
|
+
const condBoxNode = (_bamboocss_ts_ast.Node.isIdentifier(condExpr) ? maybeBoxNode(condExpr, [], ctx) : safeEvaluateNode(condExpr, stack, ctx)) ?? box.unresolvable(condExpr, stack);
|
|
929
929
|
const condValue = isBoxNode(condBoxNode) ? condBoxNode : box.from(condBoxNode, node, stack);
|
|
930
930
|
if (box.isEmptyInitializer(condValue)) return;
|
|
931
|
-
const isFromDefaultBinding = condValue.getStack().some((node) =>
|
|
931
|
+
const isFromDefaultBinding = condValue.getStack().some((node) => _bamboocss_ts_ast.Node.isBindingElement(node));
|
|
932
932
|
if (box.isUnresolvable(condValue) || box.isConditional(condValue) || isFromDefaultBinding) return cache(maybeResolveConditionalExpression({
|
|
933
|
-
whenTrueExpr: unwrapExpression(node.
|
|
934
|
-
whenFalseExpr: unwrapExpression(node.
|
|
933
|
+
whenTrueExpr: unwrapExpression(node.whenTrue),
|
|
934
|
+
whenFalseExpr: unwrapExpression(node.whenFalse),
|
|
935
935
|
node,
|
|
936
936
|
stack
|
|
937
937
|
}, ctx));
|
|
938
938
|
if (condValue.value) {
|
|
939
|
-
const whenTrueExpr = unwrapExpression(node.
|
|
939
|
+
const whenTrueExpr = unwrapExpression(node.whenTrue);
|
|
940
940
|
return cache(maybeBoxNode(whenTrueExpr, [...stack], ctx) ?? box.unresolvable(whenTrueExpr, stack));
|
|
941
941
|
}
|
|
942
|
-
return cache(maybeBoxNode(unwrapExpression(node.
|
|
942
|
+
return cache(maybeBoxNode(unwrapExpression(node.whenFalse), [...stack], ctx) ?? box.unresolvable(node, stack));
|
|
943
943
|
}
|
|
944
|
-
if (
|
|
944
|
+
if (_bamboocss_ts_ast.Node.isCallExpression(node)) {
|
|
945
945
|
if (ctx.tokens) {
|
|
946
|
-
const expr = node.
|
|
946
|
+
const expr = node.expression;
|
|
947
947
|
let fnName = "";
|
|
948
948
|
let isValueMethod = false;
|
|
949
|
-
if (
|
|
950
|
-
else if (
|
|
949
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(expr)) fnName = expr.getText();
|
|
950
|
+
else if (_bamboocss_ts_ast.Node.isPropertyAccessExpression(expr)) if ((0, _bamboocss_ts_ast.getName)(expr) === "value") {
|
|
951
951
|
isValueMethod = true;
|
|
952
|
-
fnName = expr.
|
|
952
|
+
fnName = expr.expression.getText();
|
|
953
953
|
} else fnName = expr.getText();
|
|
954
954
|
if (ctx.tokens.isTokenFn ? ctx.tokens.isTokenFn(fnName) : fnName === "token") {
|
|
955
|
-
const tokenPathArg = node.
|
|
955
|
+
const tokenPathArg = node.arguments[0];
|
|
956
956
|
const tokenPath = tokenPathArg ? literalStringOf(tokenPathArg, stack, ctx) : void 0;
|
|
957
957
|
if (tokenPath !== void 0) {
|
|
958
958
|
const resolvedValue = isValueMethod ? ctx.tokens.view.get(tokenPath) : ctx.tokens.view.getVar(tokenPath);
|
|
@@ -964,8 +964,8 @@ function maybeBoxNodeUncached(node, stack, ctx, matchProp, dependencyEntry) {
|
|
|
964
964
|
if (!value) return;
|
|
965
965
|
return cache(box.from(value, node, stack));
|
|
966
966
|
}
|
|
967
|
-
if (
|
|
968
|
-
const operatorKind = node.
|
|
967
|
+
if (_bamboocss_ts_ast.Node.isBinaryExpression(node)) {
|
|
968
|
+
const operatorKind = node.operatorToken.kind;
|
|
969
969
|
if (isPlusSyntax(operatorKind)) {
|
|
970
970
|
const value = tryComputingPlusTokenBinaryExpressionToString(node, stack, ctx) ?? safeEvaluateNode(node, stack, ctx);
|
|
971
971
|
if (!value) return;
|
|
@@ -973,8 +973,8 @@ function maybeBoxNodeUncached(node, stack, ctx, matchProp, dependencyEntry) {
|
|
|
973
973
|
return cache(box.from(value, node, stack));
|
|
974
974
|
}
|
|
975
975
|
if (isLogicalSyntax(operatorKind)) return cache(maybeResolveConditionalExpression({
|
|
976
|
-
whenTrueExpr: unwrapExpression(node.
|
|
977
|
-
whenFalseExpr: unwrapExpression(node.
|
|
976
|
+
whenTrueExpr: unwrapExpression(node.left),
|
|
977
|
+
whenFalseExpr: unwrapExpression(node.right),
|
|
978
978
|
node,
|
|
979
979
|
stack,
|
|
980
980
|
canReturnWhenTrue: canReturnWhenTrueInLogicalExpression(operatorKind)
|
|
@@ -991,7 +991,7 @@ function maybeBoxNodeUncached(node, stack, ctx, matchProp, dependencyEntry) {
|
|
|
991
991
|
* Returning `undefined` leaves the call unresolved, exactly as before.
|
|
992
992
|
*/
|
|
993
993
|
function literalStringOf(node, stack, ctx) {
|
|
994
|
-
if (
|
|
994
|
+
if (_bamboocss_ts_ast.Node.isStringLiteral(node)) return (0, _bamboocss_ts_ast.stringLiteralValue)(node);
|
|
995
995
|
const resolved = onlyStringLiteral(maybeBoxNode(node, stack, ctx));
|
|
996
996
|
return resolved && typeof resolved.value === "string" ? resolved.value : void 0;
|
|
997
997
|
}
|
|
@@ -1015,7 +1015,7 @@ const maybeResolveConditionalExpression = ({ whenTrueExpr, whenFalseExpr, node,
|
|
|
1015
1015
|
const whenTrueValue = maybeBoxNode(whenTrueExpr, stack, ctx);
|
|
1016
1016
|
const whenFalseValue = maybeBoxNode(whenFalseExpr, stack, ctx);
|
|
1017
1017
|
if (canReturnWhenTrue && whenTrueValue && !box.isUnresolvable(whenTrueValue)) return whenTrueValue;
|
|
1018
|
-
if (
|
|
1018
|
+
if (_bamboocss_ts_ast.Node.isBinaryExpression(node) && node.operatorToken.kind === _bamboocss_ts_ast.ts.SyntaxKind.AmpersandAmpersandToken && whenTrueValue && whenFalseValue && box.isLiteral(whenTrueValue) && whenTrueValue.value === true) return whenFalseValue;
|
|
1019
1019
|
if (!whenTrueValue && !whenFalseValue) return;
|
|
1020
1020
|
if (whenTrueValue && !whenFalseValue) return whenTrueValue;
|
|
1021
1021
|
if (!whenTrueValue && whenFalseValue) return whenFalseValue;
|
|
@@ -1026,18 +1026,18 @@ const maybeResolveConditionalExpression = ({ whenTrueExpr, whenFalseExpr, node,
|
|
|
1026
1026
|
};
|
|
1027
1027
|
const findProperty = (node, propName, _stack, ctx) => {
|
|
1028
1028
|
const stack = [..._stack];
|
|
1029
|
-
if (
|
|
1030
|
-
const name = node.
|
|
1031
|
-
if (
|
|
1029
|
+
if (_bamboocss_ts_ast.Node.isPropertyAssignment(node)) {
|
|
1030
|
+
const name = node.name;
|
|
1031
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(name) && name.getText() === propName) {
|
|
1032
1032
|
stack.push(name);
|
|
1033
1033
|
return node;
|
|
1034
1034
|
}
|
|
1035
|
-
if (
|
|
1035
|
+
if (_bamboocss_ts_ast.Node.isStringLiteral(name) && (0, _bamboocss_ts_ast.getLiteralText)(name) === propName) {
|
|
1036
1036
|
stack.push(name);
|
|
1037
|
-
return
|
|
1037
|
+
return (0, _bamboocss_ts_ast.getLiteralText)(name);
|
|
1038
1038
|
}
|
|
1039
|
-
if (
|
|
1040
|
-
const expression = unwrapExpression(name.
|
|
1039
|
+
if (_bamboocss_ts_ast.Node.isComputedPropertyName(name)) {
|
|
1040
|
+
const expression = unwrapExpression(name.expression);
|
|
1041
1041
|
const computedPropNameBox = maybePropName(expression, stack, ctx);
|
|
1042
1042
|
if (!computedPropNameBox) return;
|
|
1043
1043
|
if (String(computedPropNameBox.value) === propName) {
|
|
@@ -1046,9 +1046,9 @@ const findProperty = (node, propName, _stack, ctx) => {
|
|
|
1046
1046
|
}
|
|
1047
1047
|
}
|
|
1048
1048
|
}
|
|
1049
|
-
if (
|
|
1050
|
-
const name = node.
|
|
1051
|
-
if (
|
|
1049
|
+
if (_bamboocss_ts_ast.Node.isShorthandPropertyAssignment(node)) {
|
|
1050
|
+
const name = node.name;
|
|
1051
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(name) && name.getText() === propName) {
|
|
1052
1052
|
stack.push(name);
|
|
1053
1053
|
return node;
|
|
1054
1054
|
}
|
|
@@ -1057,53 +1057,54 @@ const findProperty = (node, propName, _stack, ctx) => {
|
|
|
1057
1057
|
const getObjectLiteralPropValue = (initializer, accessList, _stack, ctx) => {
|
|
1058
1058
|
const stack = [..._stack];
|
|
1059
1059
|
const propName = accessList.pop();
|
|
1060
|
-
const property =
|
|
1060
|
+
const property = (0, _bamboocss_ts_ast.getProperty)(initializer, propName) ?? initializer.properties.find((p) => findProperty(p, propName, stack, ctx));
|
|
1061
1061
|
if (!property) return;
|
|
1062
1062
|
stack.push(property);
|
|
1063
|
-
if (
|
|
1064
|
-
const propInit = property.
|
|
1063
|
+
if (_bamboocss_ts_ast.Node.isPropertyAssignment(property)) {
|
|
1064
|
+
const propInit = property.initializer;
|
|
1065
1065
|
if (!propInit) return;
|
|
1066
|
-
if (
|
|
1066
|
+
if (_bamboocss_ts_ast.Node.isObjectLiteralExpression(propInit)) {
|
|
1067
1067
|
if (accessList.length > 0) return getObjectLiteralPropValue(propInit, accessList, stack, ctx);
|
|
1068
1068
|
return maybeBoxNode(propInit, stack, ctx);
|
|
1069
1069
|
}
|
|
1070
1070
|
const maybePropValue = maybeBoxNode(propInit, stack, ctx);
|
|
1071
1071
|
if (maybePropValue) return maybePropValue;
|
|
1072
1072
|
}
|
|
1073
|
-
if (
|
|
1074
|
-
const identifier = property.
|
|
1073
|
+
if (_bamboocss_ts_ast.Node.isShorthandPropertyAssignment(property)) {
|
|
1074
|
+
const identifier = property.name;
|
|
1075
1075
|
if (accessList.length > 0) return maybePropIdentifierValue(identifier, accessList, stack, ctx);
|
|
1076
1076
|
const maybePropValue = maybeBoxNode(identifier, stack, ctx);
|
|
1077
1077
|
if (maybePropValue) return maybePropValue;
|
|
1078
1078
|
}
|
|
1079
1079
|
};
|
|
1080
1080
|
const maybeTemplateStringValue = (template, stack, ctx) => {
|
|
1081
|
-
const head = template.
|
|
1082
|
-
const tail = template.
|
|
1081
|
+
const head = template.head;
|
|
1082
|
+
const tail = template.templateSpans;
|
|
1083
1083
|
const headValue = maybeStringLiteral(head, stack, ctx);
|
|
1084
1084
|
if (!headValue) return;
|
|
1085
1085
|
const tailValues = tail.map((t) => {
|
|
1086
|
-
const
|
|
1086
|
+
const expression = t.expression;
|
|
1087
|
+
const propBox = maybePropName(expression, stack, ctx);
|
|
1087
1088
|
if (!propBox) return;
|
|
1088
|
-
const literal = t.
|
|
1089
|
-
return propBox.value +
|
|
1089
|
+
const literal = t.literal;
|
|
1090
|
+
return propBox.value + (0, _bamboocss_ts_ast.getLiteralText)(literal);
|
|
1090
1091
|
});
|
|
1091
1092
|
if (tailValues.every(isNotNullish)) return headValue.value + tailValues.join("");
|
|
1092
1093
|
};
|
|
1093
1094
|
const maybeBindingElementValue = (def, stack, propName, ctx) => {
|
|
1094
|
-
const parent = def.
|
|
1095
|
+
const parent = def.parent;
|
|
1095
1096
|
if (!parent) return;
|
|
1096
|
-
const grandParent = parent.
|
|
1097
|
+
const grandParent = parent.parent;
|
|
1097
1098
|
if (!grandParent) return;
|
|
1098
|
-
if (
|
|
1099
|
-
const index =
|
|
1099
|
+
if (_bamboocss_ts_ast.Node.isArrayBindingPattern(parent)) {
|
|
1100
|
+
const index = (0, _bamboocss_ts_ast.getChildIndex)(parent);
|
|
1100
1101
|
if (Number.isNaN(index)) return;
|
|
1101
|
-
if (
|
|
1102
|
-
const init = grandParent.
|
|
1102
|
+
if (_bamboocss_ts_ast.Node.isVariableDeclaration(grandParent)) {
|
|
1103
|
+
const init = grandParent.initializer;
|
|
1103
1104
|
if (!init) return;
|
|
1104
1105
|
const initializer = unwrapExpression(init);
|
|
1105
|
-
if (!
|
|
1106
|
-
const element = initializer.
|
|
1106
|
+
if (!_bamboocss_ts_ast.Node.isArrayLiteralExpression(initializer)) return;
|
|
1107
|
+
const element = initializer.elements[index + 1];
|
|
1107
1108
|
if (!element) return;
|
|
1108
1109
|
const innerStack = [
|
|
1109
1110
|
...stack,
|
|
@@ -1122,27 +1123,27 @@ const maybeBindingElementValue = (def, stack, propName, ctx) => {
|
|
|
1122
1123
|
return propValue;
|
|
1123
1124
|
}
|
|
1124
1125
|
}
|
|
1125
|
-
if (
|
|
1126
|
+
if (_bamboocss_ts_ast.Node.isObjectBindingPattern(parent)) {}
|
|
1126
1127
|
};
|
|
1127
1128
|
function maybePropDefinitionValue(def, accessList, _stack, ctx) {
|
|
1128
1129
|
const propName = accessList.at(-1);
|
|
1129
|
-
if (
|
|
1130
|
-
const init = def.
|
|
1130
|
+
if (_bamboocss_ts_ast.Node.isVariableDeclaration(def)) {
|
|
1131
|
+
const init = def.initializer;
|
|
1131
1132
|
if (!init) {
|
|
1132
|
-
const type = def.
|
|
1133
|
+
const type = def.type;
|
|
1133
1134
|
if (!type) return;
|
|
1134
|
-
if (
|
|
1135
|
+
if (_bamboocss_ts_ast.Node.isTypeLiteralNode(type)) {
|
|
1135
1136
|
if (accessList.length > 0) {
|
|
1136
1137
|
const stack = [..._stack];
|
|
1137
1138
|
stack.push(type);
|
|
1138
1139
|
let propName = accessList.pop();
|
|
1139
|
-
let typeProp =
|
|
1140
|
-
let typeLiteral = typeProp
|
|
1141
|
-
while (typeProp && accessList.length > 0 && typeLiteral &&
|
|
1140
|
+
let typeProp = (0, _bamboocss_ts_ast.getProperty)(type, propName);
|
|
1141
|
+
let typeLiteral = typeProp && (0, _bamboocss_ts_ast.childOf)(typeProp, "type");
|
|
1142
|
+
while (typeProp && accessList.length > 0 && typeLiteral && _bamboocss_ts_ast.Node.isTypeLiteralNode(typeLiteral)) {
|
|
1142
1143
|
stack.push(typeProp, typeLiteral);
|
|
1143
1144
|
propName = accessList.pop();
|
|
1144
|
-
typeProp =
|
|
1145
|
-
typeLiteral = typeProp
|
|
1145
|
+
typeProp = (0, _bamboocss_ts_ast.getProperty)(typeLiteral, propName);
|
|
1146
|
+
typeLiteral = typeProp && (0, _bamboocss_ts_ast.childOf)(typeProp, "type");
|
|
1146
1147
|
}
|
|
1147
1148
|
if (!typeLiteral) return;
|
|
1148
1149
|
const typeValue = getTypeNodeValue(typeLiteral, stack, ctx);
|
|
@@ -1155,16 +1156,16 @@ function maybePropDefinitionValue(def, accessList, _stack, ctx) {
|
|
|
1155
1156
|
return;
|
|
1156
1157
|
}
|
|
1157
1158
|
const initializer = unwrapExpression(init);
|
|
1158
|
-
if (
|
|
1159
|
+
if (_bamboocss_ts_ast.Node.isObjectLiteralExpression(initializer)) {
|
|
1159
1160
|
const propValue = getObjectLiteralPropValue(initializer, accessList, _stack, ctx);
|
|
1160
1161
|
if (!propValue) return;
|
|
1161
1162
|
_stack.push(initializer);
|
|
1162
1163
|
return propValue;
|
|
1163
1164
|
}
|
|
1164
|
-
if (
|
|
1165
|
+
if (_bamboocss_ts_ast.Node.isArrayLiteralExpression(initializer)) {
|
|
1165
1166
|
const index = Number(propName);
|
|
1166
1167
|
if (Number.isNaN(index)) return;
|
|
1167
|
-
const element = initializer.
|
|
1168
|
+
const element = initializer.elements[index];
|
|
1168
1169
|
if (!element) return;
|
|
1169
1170
|
_stack.push(initializer);
|
|
1170
1171
|
const boxed = maybeBoxNode(element, _stack, ctx);
|
|
@@ -1173,14 +1174,14 @@ function maybePropDefinitionValue(def, accessList, _stack, ctx) {
|
|
|
1173
1174
|
const maybeValue = maybeBoxNode(initializer, [..._stack, initializer], ctx);
|
|
1174
1175
|
if (maybeValue) return maybeValue;
|
|
1175
1176
|
}
|
|
1176
|
-
if (
|
|
1177
|
+
if (_bamboocss_ts_ast.Node.isBindingElement(def)) {
|
|
1177
1178
|
const value = maybeBindingElementValue(def, _stack, propName, ctx);
|
|
1178
1179
|
if (value) return value;
|
|
1179
1180
|
}
|
|
1180
|
-
if (
|
|
1181
|
-
const member =
|
|
1181
|
+
if (_bamboocss_ts_ast.Node.isEnumDeclaration(def)) {
|
|
1182
|
+
const member = (0, _bamboocss_ts_ast.getMember)(def, propName);
|
|
1182
1183
|
if (!member) return;
|
|
1183
|
-
const initializer =
|
|
1184
|
+
const initializer = (0, _bamboocss_ts_ast.childOf)(member, "initializer");
|
|
1184
1185
|
if (!initializer) return;
|
|
1185
1186
|
const maybeValue = maybeBoxNode(initializer, [..._stack, initializer], ctx);
|
|
1186
1187
|
if (maybeValue) return maybeValue;
|
|
@@ -1200,9 +1201,9 @@ const getTypeLiteralNodePropValue = (type, propName, stack, ctx) => {
|
|
|
1200
1201
|
if (map === null) return;
|
|
1201
1202
|
if (map?.has(propName)) return map.get(propName);
|
|
1202
1203
|
}
|
|
1203
|
-
const prop = type.
|
|
1204
|
-
if (
|
|
1205
|
-
const propType = prop.
|
|
1204
|
+
const prop = type.members.find((member) => _bamboocss_ts_ast.Node.isPropertySignatureDeclaration(member) && (0, _bamboocss_ts_ast.getName)(member) === propName);
|
|
1205
|
+
if (prop !== void 0 && _bamboocss_ts_ast.Node.isPropertySignatureDeclaration(prop) && (0, _bamboocss_ts_ast.isReadonly)(prop)) {
|
|
1206
|
+
const propType = prop.type;
|
|
1206
1207
|
if (!propType) {
|
|
1207
1208
|
typeLiteralCache.set(type, null);
|
|
1208
1209
|
return;
|
|
@@ -1217,29 +1218,28 @@ const getTypeLiteralNodePropValue = (type, propName, stack, ctx) => {
|
|
|
1217
1218
|
typeLiteralCache.set(type, null);
|
|
1218
1219
|
};
|
|
1219
1220
|
function getNameLiteral(wrapper) {
|
|
1220
|
-
if (
|
|
1221
|
+
if (_bamboocss_ts_ast.Node.isStringLiteral(wrapper)) return (0, _bamboocss_ts_ast.getLiteralText)(wrapper);
|
|
1221
1222
|
return wrapper.getText();
|
|
1222
1223
|
}
|
|
1223
1224
|
const typeNodeCache = /* @__PURE__ */ new WeakMap();
|
|
1224
1225
|
const getTypeNodeValue = (type, stack, ctx) => {
|
|
1225
1226
|
if (typeNodeCache.has(type)) return typeNodeCache.get(type);
|
|
1226
|
-
if (
|
|
1227
|
-
const literal = type.
|
|
1228
|
-
if (
|
|
1229
|
-
const result =
|
|
1227
|
+
if (_bamboocss_ts_ast.Node.isLiteralTypeNode(type)) {
|
|
1228
|
+
const literal = type.literal;
|
|
1229
|
+
if (_bamboocss_ts_ast.Node.isStringLiteral(literal)) {
|
|
1230
|
+
const result = (0, _bamboocss_ts_ast.getLiteralText)(literal);
|
|
1230
1231
|
typeNodeCache.set(type, result);
|
|
1231
1232
|
return result;
|
|
1232
1233
|
}
|
|
1233
1234
|
}
|
|
1234
|
-
if (
|
|
1235
|
-
const members = type.
|
|
1236
|
-
if (!members.some((member) => !
|
|
1235
|
+
if (_bamboocss_ts_ast.Node.isTypeLiteralNode(type)) {
|
|
1236
|
+
const members = type.members;
|
|
1237
|
+
if (!members.some((member) => !_bamboocss_ts_ast.Node.isPropertySignatureDeclaration(member) || !(0, _bamboocss_ts_ast.isReadonly)(member))) {
|
|
1237
1238
|
const entries = members.map((member) => {
|
|
1238
|
-
const nameNode = member.
|
|
1239
|
-
const nameText = nameNode.getText();
|
|
1239
|
+
const nameNode = member.name;
|
|
1240
1240
|
const name = getNameLiteral(nameNode);
|
|
1241
1241
|
if (!name) return;
|
|
1242
|
-
return [name, getTypeLiteralNodePropValue(type,
|
|
1242
|
+
return [name, getTypeLiteralNodePropValue(type, name, stack, ctx)];
|
|
1243
1243
|
}).filter(isNotNullish);
|
|
1244
1244
|
const result = Object.fromEntries(entries);
|
|
1245
1245
|
typeNodeCache.set(type, result);
|
|
@@ -1249,16 +1249,16 @@ const getTypeNodeValue = (type, stack, ctx) => {
|
|
|
1249
1249
|
typeNodeCache.set(type, void 0);
|
|
1250
1250
|
};
|
|
1251
1251
|
const maybeDefinitionValue = (def, stack, ctx) => {
|
|
1252
|
-
if (
|
|
1253
|
-
const propNameNode = def.
|
|
1252
|
+
if (_bamboocss_ts_ast.Node.isShorthandPropertyAssignment(def)) {
|
|
1253
|
+
const propNameNode = def.name;
|
|
1254
1254
|
return maybePropIdentifierValue(propNameNode, [propNameNode.getText()], stack, ctx);
|
|
1255
1255
|
}
|
|
1256
|
-
if (
|
|
1257
|
-
const init = def.
|
|
1256
|
+
if (_bamboocss_ts_ast.Node.isVariableDeclaration(def)) {
|
|
1257
|
+
const init = def.initializer;
|
|
1258
1258
|
if (!init) {
|
|
1259
|
-
const type = def.
|
|
1259
|
+
const type = def.type;
|
|
1260
1260
|
if (!type) return;
|
|
1261
|
-
if (
|
|
1261
|
+
if (_bamboocss_ts_ast.Node.isTypeLiteralNode(type)) {
|
|
1262
1262
|
stack.push(type);
|
|
1263
1263
|
const maybeTypeValue = getTypeNodeValue(type, stack, ctx);
|
|
1264
1264
|
if (isNotNullish(maybeTypeValue)) return box.from(maybeTypeValue, def, stack);
|
|
@@ -1269,12 +1269,12 @@ const maybeDefinitionValue = (def, stack, ctx) => {
|
|
|
1269
1269
|
const maybeValue = maybeBoxNode(initializer, [...stack, initializer], ctx);
|
|
1270
1270
|
if (maybeValue) return maybeValue;
|
|
1271
1271
|
}
|
|
1272
|
-
if (
|
|
1273
|
-
const init = def.
|
|
1272
|
+
if (_bamboocss_ts_ast.Node.isBindingElement(def)) {
|
|
1273
|
+
const init = def.initializer;
|
|
1274
1274
|
if (!init) {
|
|
1275
|
-
const nameNode = def.
|
|
1276
|
-
const propName = nameNode
|
|
1277
|
-
const value = maybeBindingElementValue(def, [...stack, nameNode], propName, ctx);
|
|
1275
|
+
const nameNode = def.propertyName ?? def.name;
|
|
1276
|
+
const propName = nameNode?.getText() ?? "";
|
|
1277
|
+
const value = maybeBindingElementValue(def, [...stack, nameNode].filter(Boolean), propName, ctx);
|
|
1278
1278
|
if (value) return value;
|
|
1279
1279
|
return box.unresolvable(def, stack);
|
|
1280
1280
|
}
|
|
@@ -1284,11 +1284,11 @@ const maybeDefinitionValue = (def, stack, ctx) => {
|
|
|
1284
1284
|
}
|
|
1285
1285
|
};
|
|
1286
1286
|
const getExportedVarDeclarationWithName = (varName, sourceFile, stack, ctx, visited = /* @__PURE__ */ new Set()) => {
|
|
1287
|
-
ctx.recordExportRead?.(
|
|
1288
|
-
const key = `${
|
|
1287
|
+
ctx.recordExportRead?.((0, _bamboocss_ts_ast.pathOf)(sourceFile), varName);
|
|
1288
|
+
const key = `${(0, _bamboocss_ts_ast.pathOf)(sourceFile)}:${varName}`;
|
|
1289
1289
|
if (visited.has(key)) return;
|
|
1290
1290
|
visited.add(key);
|
|
1291
|
-
const maybeVar =
|
|
1291
|
+
const maybeVar = (0, _bamboocss_ts_ast.getVariableDeclaration)(sourceFile, varName);
|
|
1292
1292
|
if (maybeVar) return maybeVar;
|
|
1293
1293
|
const exportDeclaration = resolveVarDeclarationFromExportWithName(varName, sourceFile, stack, ctx, visited);
|
|
1294
1294
|
if (!exportDeclaration) return;
|
|
@@ -1304,9 +1304,9 @@ const getExportedVarDeclarationWithName = (varName, sourceFile, stack, ctx, visi
|
|
|
1304
1304
|
* module does export and resolves names it does not.
|
|
1305
1305
|
*/
|
|
1306
1306
|
const resolveExportedName = (name, exportDeclaration) => {
|
|
1307
|
-
const namedExports =
|
|
1307
|
+
const namedExports = (0, _bamboocss_ts_ast.getNamedExports)(exportDeclaration);
|
|
1308
1308
|
if (namedExports.length === 0) return name;
|
|
1309
|
-
for (const namedExport of namedExports) if ((
|
|
1309
|
+
for (const namedExport of namedExports) if ((((0, _bamboocss_ts_ast.getAliasNode)(namedExport) ?? (0, _bamboocss_ts_ast.nameNodeOf)(namedExport))?.getText() ?? "") === name) return (0, _bamboocss_ts_ast.nameNodeOf)(namedExport)?.getText();
|
|
1310
1310
|
};
|
|
1311
1311
|
/**
|
|
1312
1312
|
* Faster than declaration.getModuleSpecifierSourceFile()
|
|
@@ -1318,20 +1318,20 @@ const resolveExportedName = (name, exportDeclaration) => {
|
|
|
1318
1318
|
* @see https://github.com/dsherret/ts-morph/blob/42d811ed9a5177fc678a5bfec4923a2048124fe0/packages/ts-morph/src/compiler/ast/module/ExportDeclaration.ts#L160
|
|
1319
1319
|
*/
|
|
1320
1320
|
const getModuleSpecifierSourceFile = (declaration, ctx) => {
|
|
1321
|
-
const moduleName =
|
|
1321
|
+
const moduleName = (0, _bamboocss_ts_ast.getModuleSpecifierValue)(declaration);
|
|
1322
1322
|
if (!moduleName) return;
|
|
1323
1323
|
const sourceFile = ctx.resolveModule?.(moduleName, declaration.getSourceFile());
|
|
1324
|
-
if (sourceFile) recordModuleDependency(ctx,
|
|
1324
|
+
if (sourceFile) recordModuleDependency(ctx, (0, _bamboocss_ts_ast.pathOf)(sourceFile));
|
|
1325
1325
|
return sourceFile;
|
|
1326
1326
|
};
|
|
1327
1327
|
function resolveVarDeclarationFromExportWithName(symbolName, sourceFile, stack, ctx, visited) {
|
|
1328
|
-
for (const exportDeclaration of
|
|
1328
|
+
for (const exportDeclaration of (0, _bamboocss_ts_ast.getExportDeclarations)(sourceFile)) {
|
|
1329
1329
|
const exportStack = [exportDeclaration];
|
|
1330
1330
|
const sourceName = resolveExportedName(symbolName, exportDeclaration);
|
|
1331
1331
|
if (sourceName === void 0) continue;
|
|
1332
1332
|
const maybeFile = getModuleSpecifierSourceFile(exportDeclaration, ctx);
|
|
1333
1333
|
if (!maybeFile) {
|
|
1334
|
-
const localVar =
|
|
1334
|
+
const localVar = (0, _bamboocss_ts_ast.getVariableDeclaration)(sourceFile, sourceName);
|
|
1335
1335
|
if (localVar) {
|
|
1336
1336
|
stack.push(...exportStack.concat(localVar));
|
|
1337
1337
|
return localVar;
|
|
@@ -1356,16 +1356,16 @@ const maybeIdentifierValue = (identifier, _stack, ctx) => {
|
|
|
1356
1356
|
return box.unresolvable(identifier, stack);
|
|
1357
1357
|
};
|
|
1358
1358
|
const tryComputingPlusTokenBinaryExpressionToString = (node, stack, ctx) => {
|
|
1359
|
-
const left = unwrapExpression(node.
|
|
1360
|
-
const right = unwrapExpression(node.
|
|
1359
|
+
const left = unwrapExpression(node.left);
|
|
1360
|
+
const right = unwrapExpression(node.right);
|
|
1361
1361
|
const leftValue = maybePropName(left, stack, ctx);
|
|
1362
1362
|
const rightValue = maybePropName(right, stack, ctx);
|
|
1363
1363
|
if (!leftValue || !rightValue) return;
|
|
1364
1364
|
if (isNotNullish(leftValue.value) && isNotNullish(rightValue.value)) return box.literal(String(leftValue.value) + String(rightValue.value), node, stack);
|
|
1365
1365
|
};
|
|
1366
1366
|
const getElementAccessedExpressionValue = (expression, _stack, ctx) => {
|
|
1367
|
-
const elementAccessed = unwrapExpression(expression.
|
|
1368
|
-
const argExpr = expression.
|
|
1367
|
+
const elementAccessed = unwrapExpression(expression.expression);
|
|
1368
|
+
const argExpr = expression.argumentExpression;
|
|
1369
1369
|
if (!argExpr) return;
|
|
1370
1370
|
const arg = unwrapExpression(argExpr);
|
|
1371
1371
|
const stack = [
|
|
@@ -1374,28 +1374,28 @@ const getElementAccessedExpressionValue = (expression, _stack, ctx) => {
|
|
|
1374
1374
|
arg
|
|
1375
1375
|
];
|
|
1376
1376
|
const argLiteral = maybePropName(arg, stack, ctx);
|
|
1377
|
-
if (
|
|
1377
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(elementAccessed) && argLiteral) {
|
|
1378
1378
|
if (!isNotNullish(argLiteral.value)) return;
|
|
1379
1379
|
return maybePropIdentifierValue(elementAccessed, [argLiteral.value.toString()], stack, ctx);
|
|
1380
1380
|
}
|
|
1381
|
-
if (
|
|
1382
|
-
if (arg.
|
|
1381
|
+
if (_bamboocss_ts_ast.Node.isBinaryExpression(arg)) {
|
|
1382
|
+
if (arg.operatorToken.kind !== _bamboocss_ts_ast.ts.SyntaxKind.PlusToken) return;
|
|
1383
1383
|
const propName = tryComputingPlusTokenBinaryExpressionToString(arg, stack, ctx) ?? maybePropName(arg, stack, ctx);
|
|
1384
|
-
if (propName &&
|
|
1384
|
+
if (propName && _bamboocss_ts_ast.Node.isIdentifier(elementAccessed)) {
|
|
1385
1385
|
if (!isNotNullish(propName.value)) return;
|
|
1386
1386
|
return maybePropIdentifierValue(elementAccessed, [propName.value.toString()], stack, ctx);
|
|
1387
1387
|
}
|
|
1388
1388
|
}
|
|
1389
|
-
if (
|
|
1389
|
+
if (_bamboocss_ts_ast.Node.isTemplateExpression(arg)) {
|
|
1390
1390
|
const propName = maybeTemplateStringValue(arg, stack, ctx);
|
|
1391
|
-
if (propName &&
|
|
1391
|
+
if (propName && _bamboocss_ts_ast.Node.isIdentifier(elementAccessed)) return maybePropIdentifierValue(elementAccessed, [propName], stack, ctx);
|
|
1392
1392
|
}
|
|
1393
|
-
if (
|
|
1393
|
+
if (_bamboocss_ts_ast.Node.isObjectLiteralExpression(elementAccessed) && argLiteral) {
|
|
1394
1394
|
if (!isNotNullish(argLiteral.value)) return;
|
|
1395
1395
|
return getObjectLiteralPropValue(elementAccessed, [argLiteral.value.toString()], stack, ctx);
|
|
1396
1396
|
}
|
|
1397
|
-
if (
|
|
1398
|
-
if (
|
|
1397
|
+
if (_bamboocss_ts_ast.Node.isPropertyAccessExpression(arg)) return getPropertyAccessedExpressionValue(arg, [], stack, ctx);
|
|
1398
|
+
if (_bamboocss_ts_ast.Node.isPropertyAccessExpression(elementAccessed) && argLiteral && isNotNullish(argLiteral.value)) {
|
|
1399
1399
|
const propRefValue = getPropertyAccessedExpressionValue(elementAccessed, [], stack, ctx);
|
|
1400
1400
|
if (!propRefValue) return box.unresolvable(elementAccessed, stack);
|
|
1401
1401
|
const propName = argLiteral.value.toString();
|
|
@@ -1413,11 +1413,11 @@ const getElementAccessedExpressionValue = (expression, _stack, ctx) => {
|
|
|
1413
1413
|
}
|
|
1414
1414
|
return box.unresolvable(elementAccessed, stack);
|
|
1415
1415
|
}
|
|
1416
|
-
if (
|
|
1416
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(elementAccessed) && _bamboocss_ts_ast.Node.isElementAccessExpression(arg)) {
|
|
1417
1417
|
const propName = getElementAccessedExpressionValue(arg, stack, ctx);
|
|
1418
1418
|
if (typeof propName === "string" && isNotNullish(propName)) return maybePropIdentifierValue(elementAccessed, [propName], stack, ctx);
|
|
1419
1419
|
}
|
|
1420
|
-
if (
|
|
1420
|
+
if (_bamboocss_ts_ast.Node.isElementAccessExpression(elementAccessed) && argLiteral && isNotNullish(argLiteral.value)) {
|
|
1421
1421
|
const identifier = getElementAccessedExpressionValue(elementAccessed, stack, ctx);
|
|
1422
1422
|
if (isObject(identifier)) {
|
|
1423
1423
|
const argValue = argLiteral.value.toString();
|
|
@@ -1429,18 +1429,18 @@ const getElementAccessedExpressionValue = (expression, _stack, ctx) => {
|
|
|
1429
1429
|
}
|
|
1430
1430
|
}
|
|
1431
1431
|
}
|
|
1432
|
-
if (
|
|
1433
|
-
if (
|
|
1432
|
+
if (_bamboocss_ts_ast.Node.isArrayLiteralExpression(elementAccessed) && argLiteral) return getArrayElementValueAtIndex(elementAccessed, Number(argLiteral.value), stack, ctx);
|
|
1433
|
+
if (_bamboocss_ts_ast.Node.isConditionalExpression(arg)) {
|
|
1434
1434
|
if (ctx.flags?.skipConditions) return box.unresolvable(arg, stack);
|
|
1435
1435
|
const propName = maybePropName(arg, stack, ctx);
|
|
1436
1436
|
if (isNotNullish(propName) && isNotNullish(propName.value)) {
|
|
1437
|
-
if (
|
|
1437
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(elementAccessed)) return maybePropIdentifierValue(elementAccessed, [propName.value.toString()], stack, ctx);
|
|
1438
1438
|
}
|
|
1439
|
-
const whenTrueExpr = unwrapExpression(arg.
|
|
1440
|
-
const whenFalseExpr = unwrapExpression(arg.
|
|
1439
|
+
const whenTrueExpr = unwrapExpression(arg.whenTrue);
|
|
1440
|
+
const whenFalseExpr = unwrapExpression(arg.whenFalse);
|
|
1441
1441
|
const whenTrueValue = maybePropName(whenTrueExpr, stack, ctx);
|
|
1442
1442
|
const whenFalseValue = maybePropName(whenFalseExpr, stack, ctx);
|
|
1443
|
-
if (
|
|
1443
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(elementAccessed)) {
|
|
1444
1444
|
const whenTrueResolved = whenTrueValue && isNotNullish(whenTrueValue.value) ? maybePropIdentifierValue(elementAccessed, [whenTrueValue.value.toString()], stack, ctx) : void 0;
|
|
1445
1445
|
const whenFalseResolved = whenFalseValue && isNotNullish(whenFalseValue.value) ? maybePropIdentifierValue(elementAccessed, [whenFalseValue.value.toString()], stack, ctx) : void 0;
|
|
1446
1446
|
if (!whenTrueResolved && !whenFalseResolved) return;
|
|
@@ -1451,27 +1451,27 @@ const getElementAccessedExpressionValue = (expression, _stack, ctx) => {
|
|
|
1451
1451
|
}
|
|
1452
1452
|
};
|
|
1453
1453
|
const getArrayElementValueAtIndex = (array, index, stack, ctx) => {
|
|
1454
|
-
const element = array.
|
|
1454
|
+
const element = array.elements[index];
|
|
1455
1455
|
if (!element) return;
|
|
1456
1456
|
const value = maybeBoxNode(element, stack, ctx);
|
|
1457
1457
|
if (isNotNullish(value)) return value;
|
|
1458
1458
|
};
|
|
1459
1459
|
const getPropertyAccessedExpressionValue = (expression, _accessList, stack, ctx) => {
|
|
1460
|
-
const propName =
|
|
1461
|
-
const elementAccessed = unwrapExpression(expression.
|
|
1462
|
-
const accessList = _accessList.concat(propName);
|
|
1460
|
+
const propName = (0, _bamboocss_ts_ast.getName)(expression);
|
|
1461
|
+
const elementAccessed = unwrapExpression(expression.expression);
|
|
1462
|
+
const accessList = _accessList.concat(String(propName));
|
|
1463
1463
|
stack.push(elementAccessed);
|
|
1464
|
-
if (
|
|
1465
|
-
if (
|
|
1466
|
-
if (
|
|
1464
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(elementAccessed)) return maybePropIdentifierValue(elementAccessed, accessList, stack, ctx);
|
|
1465
|
+
if (_bamboocss_ts_ast.Node.isPropertyAccessExpression(elementAccessed)) return getPropertyAccessedExpressionValue(elementAccessed, accessList, stack, ctx);
|
|
1466
|
+
if (_bamboocss_ts_ast.Node.isElementAccessExpression(elementAccessed)) {
|
|
1467
1467
|
const leftElementAccessed = getElementAccessedExpressionValue(elementAccessed, stack, ctx);
|
|
1468
1468
|
if (!leftElementAccessed) return;
|
|
1469
1469
|
if (box.isObject(leftElementAccessed)) {
|
|
1470
|
-
const propValue = leftElementAccessed.value[propName];
|
|
1470
|
+
const propValue = leftElementAccessed.value[String(propName)];
|
|
1471
1471
|
return box.from(propValue, expression, stack);
|
|
1472
1472
|
}
|
|
1473
1473
|
if (box.isMap(leftElementAccessed)) {
|
|
1474
|
-
const propValue = leftElementAccessed.value.get(propName);
|
|
1474
|
+
const propValue = leftElementAccessed.value.get(propName ?? "");
|
|
1475
1475
|
return box.from(propValue, expression, stack);
|
|
1476
1476
|
}
|
|
1477
1477
|
}
|
|
@@ -1480,8 +1480,8 @@ const getPropertyAccessedExpressionValue = (expression, _accessList, stack, ctx)
|
|
|
1480
1480
|
//#region src/call-expression.ts
|
|
1481
1481
|
const trueFn = () => true;
|
|
1482
1482
|
const extractCallExpressionArguments = (node, ctx, matchProp = trueFn, matchArg = trueFn) => {
|
|
1483
|
-
const fnArguments = node.
|
|
1484
|
-
const fnName = node.
|
|
1483
|
+
const fnArguments = node.arguments;
|
|
1484
|
+
const fnName = node.expression.getText();
|
|
1485
1485
|
if (fnArguments.length === 0) return box.array([], node, []);
|
|
1486
1486
|
return box.array(fnArguments.map((argument, index) => {
|
|
1487
1487
|
const argNode = unwrapExpression(argument);
|
|
@@ -1578,9 +1578,9 @@ const collectImports = (sourceFile) => {
|
|
|
1578
1578
|
const resolveBundledNamespaceMod = (node) => {
|
|
1579
1579
|
if (!node) return;
|
|
1580
1580
|
const expression = unwrapExpression(node);
|
|
1581
|
-
if (
|
|
1582
|
-
const callee = unwrapExpression(expression.
|
|
1583
|
-
if (!
|
|
1581
|
+
if (_bamboocss_ts_ast.Node.isCallExpression(expression)) {
|
|
1582
|
+
const callee = unwrapExpression(expression.expression);
|
|
1583
|
+
if (!_bamboocss_ts_ast.Node.isIdentifier(callee)) return;
|
|
1584
1584
|
const calleeName = callee.getText();
|
|
1585
1585
|
if (/requirejsxdevruntime/i.test(calleeName)) return "react/jsx-dev-runtime";
|
|
1586
1586
|
if (/requirejsxruntime/i.test(calleeName)) return "react/jsx-runtime";
|
|
@@ -1588,70 +1588,70 @@ const collectImports = (sourceFile) => {
|
|
|
1588
1588
|
}
|
|
1589
1589
|
};
|
|
1590
1590
|
const bundledCandidates = mayHoldBundledOutput(sourceFile.getFullText());
|
|
1591
|
-
(bundledCandidates ?
|
|
1592
|
-
const callee = unwrapExpression(
|
|
1593
|
-
if (!
|
|
1594
|
-
const [idArg, factoryArg] =
|
|
1595
|
-
if (!
|
|
1596
|
-
if (!
|
|
1597
|
-
const factoryText = factoryArg.
|
|
1598
|
-
if (factoryText.includes("\"Fragment\"") && factoryText.includes("\"jsx\"") && factoryText.includes("\"jsxs\"") && factoryText.includes("module.exports")) parcelRuntimeModuleIds.set(
|
|
1591
|
+
(bundledCandidates ? (0, _bamboocss_ts_ast.getDescendantsOfKind)(sourceFile, _bamboocss_ts_ast.SyntaxKind.CallExpression) : []).forEach((callExpression) => {
|
|
1592
|
+
const callee = unwrapExpression((0, _bamboocss_ts_ast.childOf)(callExpression, "expression"));
|
|
1593
|
+
if (!_bamboocss_ts_ast.Node.isIdentifier(callee) || callee.getText() !== "parcelRegister") return;
|
|
1594
|
+
const [idArg, factoryArg] = (0, _bamboocss_ts_ast.childOf)(callExpression, "arguments") ?? [];
|
|
1595
|
+
if (!_bamboocss_ts_ast.Node.isStringLiteral(idArg)) return;
|
|
1596
|
+
if (!_bamboocss_ts_ast.Node.isArrowFunction(factoryArg) && !_bamboocss_ts_ast.Node.isFunctionExpression(factoryArg)) return;
|
|
1597
|
+
const factoryText = factoryArg.body.getText();
|
|
1598
|
+
if (factoryText.includes("\"Fragment\"") && factoryText.includes("\"jsx\"") && factoryText.includes("\"jsxs\"") && factoryText.includes("module.exports")) parcelRuntimeModuleIds.set((0, _bamboocss_ts_ast.stringLiteralValue)(idArg), "react/jsx-runtime");
|
|
1599
1599
|
});
|
|
1600
|
-
|
|
1601
|
-
const mod =
|
|
1600
|
+
(0, _bamboocss_ts_ast.getImportDeclarations)(sourceFile).forEach((declaration) => {
|
|
1601
|
+
const mod = (0, _bamboocss_ts_ast.getModuleSpecifierValue)(declaration);
|
|
1602
1602
|
if (!mod) return;
|
|
1603
|
-
const defaultImport =
|
|
1603
|
+
const defaultImport = (0, _bamboocss_ts_ast.getDefaultImport)(declaration);
|
|
1604
1604
|
if (defaultImport) defaultImports.set(defaultImport.getText(), mod);
|
|
1605
|
-
const namespaceImport =
|
|
1605
|
+
const namespaceImport = (0, _bamboocss_ts_ast.getNamespaceImport)(declaration);
|
|
1606
1606
|
if (namespaceImport) namespace.set(namespaceImport.getText(), mod);
|
|
1607
|
-
|
|
1608
|
-
const importedName =
|
|
1609
|
-
const alias =
|
|
1610
|
-
named.set(alias, {
|
|
1611
|
-
importedName,
|
|
1607
|
+
(0, _bamboocss_ts_ast.getNamedImports)(declaration).forEach((specifier) => {
|
|
1608
|
+
const importedName = (0, _bamboocss_ts_ast.nameNodeOf)(specifier)?.getText();
|
|
1609
|
+
const alias = (0, _bamboocss_ts_ast.getAliasNode)(specifier)?.getText() || importedName;
|
|
1610
|
+
named.set(alias ?? "", {
|
|
1611
|
+
importedName: importedName ?? "",
|
|
1612
1612
|
mod
|
|
1613
1613
|
});
|
|
1614
1614
|
});
|
|
1615
1615
|
});
|
|
1616
|
-
|
|
1617
|
-
if (!
|
|
1618
|
-
const variableName =
|
|
1619
|
-
const initializer =
|
|
1620
|
-
const bundledImport = resolveBundledHelperImport(variableName, initializer);
|
|
1621
|
-
if (bundledImport) bundledNamed.set(variableName, bundledImport);
|
|
1622
|
-
let mod = getBundledRuntimeModFromName(variableName) ?? resolveBundledNamespaceMod(initializer);
|
|
1623
|
-
if (!mod && initializer &&
|
|
1624
|
-
const callee = unwrapExpression(initializer.
|
|
1625
|
-
const [firstArg] = initializer.
|
|
1626
|
-
if (
|
|
1616
|
+
(0, _bamboocss_ts_ast.getVariableDeclarations)(sourceFile).forEach((declaration) => {
|
|
1617
|
+
if (!_bamboocss_ts_ast.Node.isIdentifier((0, _bamboocss_ts_ast.nameNodeOf)(declaration))) return;
|
|
1618
|
+
const variableName = (0, _bamboocss_ts_ast.getName)(declaration);
|
|
1619
|
+
const initializer = (0, _bamboocss_ts_ast.childOf)(declaration, "initializer");
|
|
1620
|
+
const bundledImport = resolveBundledHelperImport(variableName ?? "", initializer);
|
|
1621
|
+
if (bundledImport) bundledNamed.set(variableName ?? "", bundledImport);
|
|
1622
|
+
let mod = getBundledRuntimeModFromName(variableName ?? "") ?? resolveBundledNamespaceMod(initializer);
|
|
1623
|
+
if (!mod && initializer && _bamboocss_ts_ast.Node.isCallExpression(initializer)) {
|
|
1624
|
+
const callee = unwrapExpression(initializer.expression);
|
|
1625
|
+
const [firstArg] = initializer.arguments;
|
|
1626
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(callee) && callee.getText() === "parcelRequire" && _bamboocss_ts_ast.Node.isStringLiteral(firstArg)) mod = parcelRuntimeModuleIds.get((0, _bamboocss_ts_ast.stringLiteralValue)(firstArg));
|
|
1627
1627
|
}
|
|
1628
|
-
if (!mod && initializer &&
|
|
1629
|
-
const propertyNames = new Set(initializer.
|
|
1630
|
-
if (
|
|
1628
|
+
if (!mod && initializer && _bamboocss_ts_ast.Node.isObjectLiteralExpression(initializer)) {
|
|
1629
|
+
const propertyNames = new Set(initializer.properties.map((property) => {
|
|
1630
|
+
if (_bamboocss_ts_ast.Node.isPropertyAssignment(property)) return (0, _bamboocss_ts_ast.getName)(property);
|
|
1631
1631
|
}).filter(Boolean));
|
|
1632
1632
|
if (propertyNames.has("jsx") && propertyNames.has("Fragment")) mod = "preact/jsx-runtime";
|
|
1633
1633
|
}
|
|
1634
1634
|
if (!mod) return;
|
|
1635
|
-
bundledNamespace.set(variableName, mod);
|
|
1635
|
+
bundledNamespace.set(variableName ?? "", mod);
|
|
1636
1636
|
});
|
|
1637
|
-
(bundledCandidates ?
|
|
1638
|
-
const bundledImport = resolveBundledHelperImport(
|
|
1639
|
-
if (!bundledImport || !
|
|
1640
|
-
bundledNamed.set(
|
|
1637
|
+
(bundledCandidates ? (0, _bamboocss_ts_ast.getDescendantsOfKind)(sourceFile, _bamboocss_ts_ast.SyntaxKind.FunctionDeclaration) : []).forEach((declaration) => {
|
|
1638
|
+
const bundledImport = resolveBundledHelperImport((0, _bamboocss_ts_ast.getName)(declaration) ?? "", declaration);
|
|
1639
|
+
if (!bundledImport || !(0, _bamboocss_ts_ast.getName)(declaration)) return;
|
|
1640
|
+
bundledNamed.set((0, _bamboocss_ts_ast.getName)(declaration), bundledImport);
|
|
1641
1641
|
});
|
|
1642
1642
|
const resolveBundledAliasImport = (node) => {
|
|
1643
1643
|
if (!node) return;
|
|
1644
1644
|
const expression = unwrapExpression(node);
|
|
1645
|
-
if (
|
|
1646
|
-
if (
|
|
1647
|
-
if (
|
|
1645
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(expression)) return bundledNamed.get(expression.getText());
|
|
1646
|
+
if (_bamboocss_ts_ast.Node.isConditionalExpression(expression)) return resolveBundledAliasImport(expression.whenTrue) ?? resolveBundledAliasImport(expression.whenFalse);
|
|
1647
|
+
if (_bamboocss_ts_ast.Node.isBinaryExpression(expression) && expression.operatorToken.kind === _bamboocss_ts_ast.SyntaxKind.CommaToken) return resolveBundledAliasImport(expression.right);
|
|
1648
1648
|
};
|
|
1649
|
-
|
|
1650
|
-
if (!
|
|
1651
|
-
if (bundledNamed.has(
|
|
1652
|
-
const bundledAlias = resolveBundledAliasImport(
|
|
1649
|
+
(0, _bamboocss_ts_ast.getVariableDeclarations)(sourceFile).forEach((declaration) => {
|
|
1650
|
+
if (!_bamboocss_ts_ast.Node.isIdentifier((0, _bamboocss_ts_ast.nameNodeOf)(declaration))) return;
|
|
1651
|
+
if (bundledNamed.has((0, _bamboocss_ts_ast.getName)(declaration) ?? "")) return;
|
|
1652
|
+
const bundledAlias = resolveBundledAliasImport((0, _bamboocss_ts_ast.childOf)(declaration, "initializer"));
|
|
1653
1653
|
if (!bundledAlias) return;
|
|
1654
|
-
bundledNamed.set(
|
|
1654
|
+
bundledNamed.set((0, _bamboocss_ts_ast.getName)(declaration) ?? "", bundledAlias);
|
|
1655
1655
|
});
|
|
1656
1656
|
return {
|
|
1657
1657
|
named,
|
|
@@ -1669,8 +1669,8 @@ const normalizeTagName = (text) => {
|
|
|
1669
1669
|
const getTagName = (node) => {
|
|
1670
1670
|
if (!node) return;
|
|
1671
1671
|
const expression = unwrapExpression(node);
|
|
1672
|
-
if (
|
|
1673
|
-
if (
|
|
1672
|
+
if (_bamboocss_ts_ast.Node.isStringLiteral(expression) || _bamboocss_ts_ast.Node.isNoSubstitutionTemplateLiteral(expression)) return (0, _bamboocss_ts_ast.literalValueOf)(expression);
|
|
1673
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(expression) || _bamboocss_ts_ast.Node.isPropertyAccessExpression(expression) || _bamboocss_ts_ast.Node.isElementAccessExpression(expression)) return normalizeTagName(expression.getText());
|
|
1674
1674
|
};
|
|
1675
1675
|
const isQwikMod = (mod) => mod.includes("qwik");
|
|
1676
1676
|
const getArgsAt = (...indices) => (args) => indices.map((index) => args[index]).filter(Boolean);
|
|
@@ -1749,11 +1749,11 @@ const runtimeProfiles = [
|
|
|
1749
1749
|
*/
|
|
1750
1750
|
const findLocalDeclaration = (identifier) => {
|
|
1751
1751
|
const name = identifier.getText();
|
|
1752
|
-
for (let scope = identifier.
|
|
1753
|
-
if (!
|
|
1754
|
-
const variable =
|
|
1752
|
+
for (let scope = identifier.parent; scope; scope = scope.parent) {
|
|
1753
|
+
if (!_bamboocss_ts_ast.Node.isStatement(scope)) continue;
|
|
1754
|
+
const variable = (0, _bamboocss_ts_ast.getVariableDeclaration)(scope, name);
|
|
1755
1755
|
if (variable) return variable;
|
|
1756
|
-
const fn = scope.
|
|
1756
|
+
const fn = ((0, _bamboocss_ts_ast.childOf)(scope, "statements") ?? []).find((statement) => _bamboocss_ts_ast.is.isFunctionDeclaration(statement) && (0, _bamboocss_ts_ast.getName)(statement) === name);
|
|
1757
1757
|
if (fn) return fn;
|
|
1758
1758
|
}
|
|
1759
1759
|
};
|
|
@@ -1761,7 +1761,7 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1761
1761
|
const imports = collectImports(sourceFile);
|
|
1762
1762
|
const normalizeCallee = (node) => {
|
|
1763
1763
|
const expression = unwrapExpression(node);
|
|
1764
|
-
if (
|
|
1764
|
+
if (_bamboocss_ts_ast.Node.isBinaryExpression(expression) && expression.operatorToken.kind === _bamboocss_ts_ast.SyntaxKind.CommaToken) return normalizeCallee(expression.right);
|
|
1765
1765
|
return expression;
|
|
1766
1766
|
};
|
|
1767
1767
|
const localDefinitionCache = /* @__PURE__ */ new Map();
|
|
@@ -1772,7 +1772,7 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1772
1772
|
const resolveLocalAlias = (aliasNode) => {
|
|
1773
1773
|
if (!aliasNode) return;
|
|
1774
1774
|
const expression = unwrapExpression(aliasNode);
|
|
1775
|
-
if (
|
|
1775
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(expression)) {
|
|
1776
1776
|
const imported = imports.bundledNamed.get(expression.getText());
|
|
1777
1777
|
if (imported) return {
|
|
1778
1778
|
mod: imported.mod,
|
|
@@ -1780,13 +1780,13 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1780
1780
|
};
|
|
1781
1781
|
return resolveIdentifierDefinition(expression);
|
|
1782
1782
|
}
|
|
1783
|
-
if (
|
|
1784
|
-
if (
|
|
1783
|
+
if (_bamboocss_ts_ast.Node.isConditionalExpression(expression)) return resolveLocalAlias(expression.whenTrue) ?? resolveLocalAlias(expression.whenFalse);
|
|
1784
|
+
if (_bamboocss_ts_ast.Node.isBinaryExpression(expression) && expression.operatorToken.kind === _bamboocss_ts_ast.SyntaxKind.CommaToken) return resolveLocalAlias(expression.right);
|
|
1785
1785
|
};
|
|
1786
1786
|
const declaration = findLocalDeclaration(identifier);
|
|
1787
1787
|
if (!declaration) return;
|
|
1788
|
-
if (
|
|
1789
|
-
const imported = resolveBundledHelperImport(
|
|
1788
|
+
if (_bamboocss_ts_ast.Node.isFunctionDeclaration(declaration)) {
|
|
1789
|
+
const imported = resolveBundledHelperImport((0, _bamboocss_ts_ast.getName)(declaration) ?? name, declaration);
|
|
1790
1790
|
if (!imported) return;
|
|
1791
1791
|
const resolved = {
|
|
1792
1792
|
mod: imported.mod,
|
|
@@ -1795,18 +1795,18 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1795
1795
|
localDefinitionCache.set(name, resolved);
|
|
1796
1796
|
return resolved;
|
|
1797
1797
|
}
|
|
1798
|
-
const directImport = resolveBundledHelperImport(
|
|
1798
|
+
const directImport = resolveBundledHelperImport((0, _bamboocss_ts_ast.getName)(declaration) ?? "", (0, _bamboocss_ts_ast.childOf)(declaration, "initializer"));
|
|
1799
1799
|
const aliasImport = directImport ? {
|
|
1800
1800
|
mod: directImport.mod,
|
|
1801
1801
|
importedName: directImport.importedName
|
|
1802
|
-
} : resolveLocalAlias(
|
|
1802
|
+
} : resolveLocalAlias((0, _bamboocss_ts_ast.childOf)(declaration, "initializer"));
|
|
1803
1803
|
if (!aliasImport) return;
|
|
1804
1804
|
localDefinitionCache.set(name, aliasImport);
|
|
1805
1805
|
return aliasImport;
|
|
1806
1806
|
};
|
|
1807
1807
|
const resolveCallee = (node) => {
|
|
1808
1808
|
const expression = normalizeCallee(node);
|
|
1809
|
-
if (
|
|
1809
|
+
if (_bamboocss_ts_ast.Node.isIdentifier(expression)) {
|
|
1810
1810
|
const imported = imports.named.get(expression.getText()) ?? imports.bundledNamed.get(expression.getText());
|
|
1811
1811
|
if (imported) return {
|
|
1812
1812
|
mod: imported.mod,
|
|
@@ -1814,37 +1814,41 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1814
1814
|
};
|
|
1815
1815
|
return resolveIdentifierDefinition(expression);
|
|
1816
1816
|
}
|
|
1817
|
-
if (
|
|
1818
|
-
const target = normalizeCallee(expression.
|
|
1819
|
-
if (!
|
|
1817
|
+
if (_bamboocss_ts_ast.Node.isPropertyAccessExpression(expression)) {
|
|
1818
|
+
const target = normalizeCallee(expression.expression);
|
|
1819
|
+
if (!_bamboocss_ts_ast.Node.isIdentifier(target)) return;
|
|
1820
1820
|
const targetName = target.getText();
|
|
1821
1821
|
const mod = imports.default.get(targetName) ?? imports.namespace.get(targetName) ?? imports.bundledNamespace.get(targetName);
|
|
1822
1822
|
if (!mod) return;
|
|
1823
1823
|
return {
|
|
1824
1824
|
mod,
|
|
1825
|
-
importedName:
|
|
1825
|
+
importedName: (0, _bamboocss_ts_ast.getName)(expression)
|
|
1826
1826
|
};
|
|
1827
1827
|
}
|
|
1828
1828
|
};
|
|
1829
1829
|
const isMergePropsCall = (node) => {
|
|
1830
|
-
if (!
|
|
1831
|
-
const resolved = resolveCallee(node.
|
|
1830
|
+
if (!_bamboocss_ts_ast.Node.isCallExpression(node)) return false;
|
|
1831
|
+
const resolved = resolveCallee(node.expression);
|
|
1832
1832
|
if (!resolved) return false;
|
|
1833
1833
|
return resolved.importedName === "mergeProps" && (solidMods.has(resolved.mod) || vueMods.has(resolved.mod));
|
|
1834
1834
|
};
|
|
1835
1835
|
const getCallInfo = (node) => {
|
|
1836
|
-
const resolved = resolveCallee(node.
|
|
1836
|
+
const resolved = resolveCallee(node.expression);
|
|
1837
1837
|
if (!resolved) return;
|
|
1838
|
-
const args = node.
|
|
1838
|
+
const args = node.arguments.map((arg) => unwrapExpression(arg));
|
|
1839
1839
|
const tagName = getTagName(args[0]);
|
|
1840
1840
|
if (!tagName) return;
|
|
1841
1841
|
const baseInfo = {
|
|
1842
1842
|
tagName,
|
|
1843
|
-
isFactory: tagName.includes(".")
|
|
1843
|
+
isFactory: String(tagName).includes(".")
|
|
1844
1844
|
};
|
|
1845
|
-
for (const profile of runtimeProfiles) if (profile.matches(
|
|
1845
|
+
for (const profile of runtimeProfiles) if (profile.matches({
|
|
1846
|
+
...resolved,
|
|
1847
|
+
importedName: resolved.importedName ?? ""
|
|
1848
|
+
})) return {
|
|
1846
1849
|
framework: profile.framework,
|
|
1847
1850
|
...baseInfo,
|
|
1851
|
+
tagName: String(baseInfo.tagName),
|
|
1848
1852
|
propNodes: profile.getPropNodes(args)
|
|
1849
1853
|
};
|
|
1850
1854
|
};
|
|
@@ -1856,18 +1860,18 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1856
1860
|
//#endregion
|
|
1857
1861
|
//#region src/jsx-attribute.ts
|
|
1858
1862
|
const extractJsxAttribute = (jsxAttribute, ctx) => {
|
|
1859
|
-
const initializer = jsxAttribute.
|
|
1863
|
+
const initializer = jsxAttribute.initializer;
|
|
1860
1864
|
const stack = [jsxAttribute, initializer];
|
|
1861
1865
|
if (!initializer) {
|
|
1862
|
-
const nameNode = jsxAttribute.
|
|
1866
|
+
const nameNode = jsxAttribute.name;
|
|
1863
1867
|
return box.emptyInitializer(nameNode, stack);
|
|
1864
1868
|
}
|
|
1865
|
-
if (
|
|
1866
|
-
const literalText =
|
|
1869
|
+
if (_bamboocss_ts_ast.Node.isStringLiteral(initializer)) {
|
|
1870
|
+
const literalText = (0, _bamboocss_ts_ast.getLiteralText)(initializer);
|
|
1867
1871
|
return box.literal(trimWhitespace(literalText), initializer, stack);
|
|
1868
1872
|
}
|
|
1869
|
-
if (
|
|
1870
|
-
const expr = initializer.
|
|
1873
|
+
if (_bamboocss_ts_ast.Node.isJsxExpression(initializer)) {
|
|
1874
|
+
const expr = initializer.expression;
|
|
1871
1875
|
if (!expr) return;
|
|
1872
1876
|
const expression = unwrapExpression(expr);
|
|
1873
1877
|
if (!expression) return;
|
|
@@ -1879,7 +1883,7 @@ const extractJsxAttribute = (jsxAttribute, ctx) => {
|
|
|
1879
1883
|
//#endregion
|
|
1880
1884
|
//#region src/jsx-spread-attribute.ts
|
|
1881
1885
|
const extractJsxSpreadAttributeValues = (node, ctx, matchProp) => {
|
|
1882
|
-
return maybeBoxNode(unwrapExpression(node.
|
|
1886
|
+
return maybeBoxNode(unwrapExpression(node.expression), [], ctx, matchProp);
|
|
1883
1887
|
};
|
|
1884
1888
|
//#endregion
|
|
1885
1889
|
//#region src/object-like-to-map.ts
|
|
@@ -1894,8 +1898,8 @@ const objectLikeToMap = (maybeObject, node) => {
|
|
|
1894
1898
|
};
|
|
1895
1899
|
//#endregion
|
|
1896
1900
|
//#region src/extract.ts
|
|
1897
|
-
const isImportOrExport = (node) =>
|
|
1898
|
-
const isJsxElement = (node) =>
|
|
1901
|
+
const isImportOrExport = (node) => _bamboocss_ts_ast.Node.isImportDeclaration(node) || _bamboocss_ts_ast.Node.isExportDeclaration(node);
|
|
1902
|
+
const isJsxElement = (node) => _bamboocss_ts_ast.Node.isJsxOpeningElement(node) || _bamboocss_ts_ast.Node.isJsxSelfClosingElement(node);
|
|
1899
1903
|
const extract = ({ ast, ...ctx }) => {
|
|
1900
1904
|
const { components, functions } = ctx;
|
|
1901
1905
|
const compiledJsx = createCompiledJsxContext(ast);
|
|
@@ -1948,12 +1952,12 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
1948
1952
|
const processCompiledPropSource = (componentNode, component, boxByProp, propNode, matchProp) => {
|
|
1949
1953
|
const expression = unwrapExpression(propNode);
|
|
1950
1954
|
const stack = [componentNode, expression];
|
|
1951
|
-
if (
|
|
1955
|
+
if (_bamboocss_ts_ast.Node.isObjectLiteralExpression(expression)) {
|
|
1952
1956
|
processComponentBoxNode(component, boxByProp, expression, getObjectLiteralExpressionPropPairs(expression, stack, ctx, matchProp), matchProp, true);
|
|
1953
1957
|
return;
|
|
1954
1958
|
}
|
|
1955
|
-
if (
|
|
1956
|
-
expression.
|
|
1959
|
+
if (_bamboocss_ts_ast.Node.isCallExpression(expression) && compiledJsx.isMergePropsCall(expression)) {
|
|
1960
|
+
expression.arguments.forEach((arg) => {
|
|
1957
1961
|
processCompiledPropSource(componentNode, component, boxByProp, arg, matchProp);
|
|
1958
1962
|
});
|
|
1959
1963
|
return;
|
|
@@ -1962,13 +1966,10 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
1962
1966
|
if (!maybeValue) return;
|
|
1963
1967
|
processComponentBoxNode(component, boxByProp, expression, maybeValue, matchProp, true);
|
|
1964
1968
|
};
|
|
1965
|
-
|
|
1966
|
-
if (isImportOrExport(node))
|
|
1967
|
-
traversal.skip();
|
|
1968
|
-
return;
|
|
1969
|
-
}
|
|
1969
|
+
(0, _bamboocss_ts_ast.forEachDescendant)(ast, (node) => {
|
|
1970
|
+
if (isImportOrExport(node)) return _bamboocss_ts_ast.SKIP;
|
|
1970
1971
|
if (components) {
|
|
1971
|
-
if (
|
|
1972
|
+
if (_bamboocss_ts_ast.Node.isJsxOpeningElement(node) || _bamboocss_ts_ast.Node.isJsxSelfClosingElement(node)) {
|
|
1972
1973
|
const componentNode = node;
|
|
1973
1974
|
const componentName = getComponentName(componentNode);
|
|
1974
1975
|
const isFactory = componentName.includes(".");
|
|
@@ -1979,8 +1980,8 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
1979
1980
|
})) return;
|
|
1980
1981
|
ensureComponent(componentNode, componentName);
|
|
1981
1982
|
}
|
|
1982
|
-
if (
|
|
1983
|
-
const componentNode =
|
|
1983
|
+
if (_bamboocss_ts_ast.Node.isJsxSpreadAttribute(node)) {
|
|
1984
|
+
const componentNode = (0, _bamboocss_ts_ast.getFirstAncestor)(node, isJsxElement);
|
|
1984
1985
|
const component = componentByNode.get(componentNode);
|
|
1985
1986
|
if (!componentNode || !component) return;
|
|
1986
1987
|
const componentName = getComponentName(componentNode);
|
|
@@ -1996,13 +1997,13 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
1996
1997
|
processComponentBoxNode(component, boxByProp, node, spreadNode, matchProp);
|
|
1997
1998
|
return;
|
|
1998
1999
|
}
|
|
1999
|
-
if (
|
|
2000
|
-
const componentNode =
|
|
2000
|
+
if (_bamboocss_ts_ast.Node.isJsxAttribute(node)) {
|
|
2001
|
+
const componentNode = (0, _bamboocss_ts_ast.getFirstAncestor)(node, isJsxElement);
|
|
2001
2002
|
const component = componentByNode.get(componentNode);
|
|
2002
2003
|
if (!componentNode || !component) return;
|
|
2003
2004
|
const componentName = getComponentName(componentNode);
|
|
2004
2005
|
const boxByProp = byName.get(componentName).nodesByProp;
|
|
2005
|
-
const propName = node.
|
|
2006
|
+
const propName = node.name.getText();
|
|
2006
2007
|
if (!components.matchProp({
|
|
2007
2008
|
tagNode: componentNode,
|
|
2008
2009
|
tagName: componentName,
|
|
@@ -2013,7 +2014,7 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
2013
2014
|
if (!maybeBox) return;
|
|
2014
2015
|
addComponentProp(component, boxByProp, propName, maybeBox);
|
|
2015
2016
|
}
|
|
2016
|
-
if (
|
|
2017
|
+
if (_bamboocss_ts_ast.Node.isCallExpression(node)) {
|
|
2017
2018
|
const compiledCall = compiledJsx.getCallInfo(node);
|
|
2018
2019
|
if (compiledCall) {
|
|
2019
2020
|
const { tagName, isFactory, propNodes } = compiledCall;
|
|
@@ -2035,9 +2036,9 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
2035
2036
|
}
|
|
2036
2037
|
}
|
|
2037
2038
|
}
|
|
2038
|
-
if (functions &&
|
|
2039
|
-
const expr = node.
|
|
2040
|
-
const fnName =
|
|
2039
|
+
if (functions && _bamboocss_ts_ast.Node.isCallExpression(node)) {
|
|
2040
|
+
const expr = node.expression;
|
|
2041
|
+
const fnName = _bamboocss_ts_ast.Node.isCallExpression(expr) ? expr.expression.getText() : expr.getText();
|
|
2041
2042
|
if (!functions.matchFn({
|
|
2042
2043
|
fnNode: node,
|
|
2043
2044
|
fnName
|
|
@@ -2083,7 +2084,7 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
2083
2084
|
componentByNode.forEach((parentRef, componentNode) => {
|
|
2084
2085
|
const component = componentByNode.get(componentNode);
|
|
2085
2086
|
if (!component) return;
|
|
2086
|
-
if (
|
|
2087
|
+
if (_bamboocss_ts_ast.Node.isCallExpression(componentNode) && component.props.size === 0 && component.conditionals.length === 0) return;
|
|
2087
2088
|
const query = {
|
|
2088
2089
|
name: parentRef.name,
|
|
2089
2090
|
box: box.map(component.props, componentNode, [])
|
|
@@ -2101,18 +2102,18 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
2101
2102
|
//#region src/jsx-element-props.ts
|
|
2102
2103
|
const isObjectLike = (node) => box.isObject(node) || box.isMap(node);
|
|
2103
2104
|
const extractJsxElementProps = (node, ctx) => {
|
|
2104
|
-
const tagName = node.
|
|
2105
|
-
const jsxAttributes =
|
|
2105
|
+
const tagName = node.tagName.getText();
|
|
2106
|
+
const jsxAttributes = (0, _bamboocss_ts_ast.childOf)(node, "attributes")?.properties ?? [];
|
|
2106
2107
|
const props = /* @__PURE__ */ new Map();
|
|
2107
2108
|
jsxAttributes.forEach((attrNode) => {
|
|
2108
|
-
if (
|
|
2109
|
-
const nameNode = attrNode.
|
|
2109
|
+
if (_bamboocss_ts_ast.Node.isJsxAttribute(attrNode)) {
|
|
2110
|
+
const nameNode = attrNode.name;
|
|
2110
2111
|
const maybeValue = extractJsxAttribute(attrNode, ctx);
|
|
2111
2112
|
if (!maybeValue) return;
|
|
2112
2113
|
props.set(nameNode.getText(), maybeValue);
|
|
2113
2114
|
return;
|
|
2114
2115
|
}
|
|
2115
|
-
if (
|
|
2116
|
+
if (_bamboocss_ts_ast.Node.isJsxSpreadAttribute(attrNode)) {
|
|
2116
2117
|
const maybeValue = extractJsxSpreadAttributeValues(attrNode, ctx, () => true);
|
|
2117
2118
|
if (!isObjectLike(maybeValue)) return;
|
|
2118
2119
|
if (box.isMap(maybeValue)) maybeValue.value.forEach((value, propName) => {
|
|
@@ -2160,7 +2161,7 @@ const getLiteralValue = (node, ctx) => {
|
|
|
2160
2161
|
}));
|
|
2161
2162
|
const last = node.getStack().at(-1);
|
|
2162
2163
|
const maybeIndex = Number(path[path.length - 1]);
|
|
2163
|
-
if (last &&
|
|
2164
|
+
if (last && _bamboocss_ts_ast.Node.isArrayLiteralExpression(last) && !Number.isNaN(maybeIndex)) {
|
|
2164
2165
|
const sliced = path.slice(0, -1);
|
|
2165
2166
|
if (whenTrue) ctx.conditions.push(makeObjAt(sliced, makeArrayWithValueAt(maybeIndex, whenTrue)));
|
|
2166
2167
|
if (whenFalse) ctx.conditions.push(makeObjAt(sliced, makeArrayWithValueAt(maybeIndex, whenFalse)));
|