@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.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BambooError } from "@bamboocss/shared";
|
|
2
|
-
import { Node, SyntaxKind, ts } from "ts-
|
|
2
|
+
import { Node, SKIP, SyntaxKind, childOf, forEachDescendant, getAliasNode, getChildIndex, getDefaultImport, getDescendantsOfKind, getExportDeclarations, getFirstAncestor, getImportDeclarations, getLineAndColumnAtPos, getLiteralText, getMember, getModuleSpecifierValue, getName, getNamedExports, getNamedImports, getNamespaceImport, getProperty, getVariableDeclaration, getVariableDeclarations, is, isInNodeModules, isReadonly, kindNameOf, literalValueOf, nameNodeOf, pathOf, stringLiteralValue, ts } from "@bamboocss/ts-ast";
|
|
3
3
|
import { evaluate } from "ts-evaluator";
|
|
4
4
|
//#region src/get-typeof-literal.ts
|
|
5
5
|
const getTypeOfLiteral = (value) => {
|
|
@@ -24,15 +24,15 @@ const isPrimitiveType = (value) => {
|
|
|
24
24
|
return type === "string" || type === "number" || type === "boolean" || value === null || value === void 0;
|
|
25
25
|
};
|
|
26
26
|
const unwrapExpression = (node) => {
|
|
27
|
-
if (Node.isAsExpression(node)) return unwrapExpression(node.
|
|
28
|
-
if (Node.isParenthesizedExpression(node)) return unwrapExpression(node.
|
|
29
|
-
if (Node.isNonNullExpression(node)) return unwrapExpression(node.
|
|
30
|
-
if (Node.isTypeAssertion(node)) return unwrapExpression(node.
|
|
31
|
-
if (Node.isSatisfiesExpression(node)) return unwrapExpression(node.
|
|
27
|
+
if (Node.isAsExpression(node)) return unwrapExpression(node.expression);
|
|
28
|
+
if (Node.isParenthesizedExpression(node)) return unwrapExpression(node.expression);
|
|
29
|
+
if (Node.isNonNullExpression(node)) return unwrapExpression(node.expression);
|
|
30
|
+
if (Node.isTypeAssertion(node)) return unwrapExpression(node.expression);
|
|
31
|
+
if (Node.isSatisfiesExpression(node)) return unwrapExpression(node.expression);
|
|
32
32
|
return node;
|
|
33
33
|
};
|
|
34
34
|
const getComponentName = (node) => {
|
|
35
|
-
return node.
|
|
35
|
+
return node.tagName.getText();
|
|
36
36
|
};
|
|
37
37
|
const whitespaceRegex = /\s+/g;
|
|
38
38
|
const trimWhitespace = (str) => {
|
|
@@ -43,8 +43,8 @@ const trimWhitespace = (str) => {
|
|
|
43
43
|
const getNodeRange = (node) => {
|
|
44
44
|
const src = node.getSourceFile();
|
|
45
45
|
const [startPosition, endPosition] = [node.getStart(), node.getEnd()];
|
|
46
|
-
const startInfo =
|
|
47
|
-
const endInfo =
|
|
46
|
+
const startInfo = getLineAndColumnAtPos(src, startPosition);
|
|
47
|
+
const endInfo = getLineAndColumnAtPos(src, endPosition);
|
|
48
48
|
return {
|
|
49
49
|
startPosition,
|
|
50
50
|
startLineNumber: startInfo.line,
|
|
@@ -77,7 +77,7 @@ var BoxNodeType = class {
|
|
|
77
77
|
return {
|
|
78
78
|
type: this.type,
|
|
79
79
|
value: this.value,
|
|
80
|
-
node: this.node.
|
|
80
|
+
node: kindNameOf(this.node.kind),
|
|
81
81
|
line: range.startLineNumber,
|
|
82
82
|
column: range.startColumn,
|
|
83
83
|
endLineNumber: range.endLineNumber,
|
|
@@ -445,15 +445,15 @@ const clearImportedValueCache = () => {
|
|
|
445
445
|
*/
|
|
446
446
|
const importBindingsFor = (sourceFile) => {
|
|
447
447
|
const bindings = /* @__PURE__ */ new Map();
|
|
448
|
-
for (const declaration of
|
|
449
|
-
for (const specifier of
|
|
450
|
-
const local = (
|
|
451
|
-
bindings.set(local, {
|
|
448
|
+
for (const declaration of getImportDeclarations(sourceFile)) {
|
|
449
|
+
for (const specifier of getNamedImports(declaration)) {
|
|
450
|
+
const local = (getAliasNode(specifier) ?? nameNodeOf(specifier))?.getText();
|
|
451
|
+
bindings.set(local ?? "", {
|
|
452
452
|
declaration,
|
|
453
|
-
exportedName: specifier
|
|
453
|
+
exportedName: nameNodeOf(specifier)?.getText() ?? ""
|
|
454
454
|
});
|
|
455
455
|
}
|
|
456
|
-
const defaultImport =
|
|
456
|
+
const defaultImport = getDefaultImport(declaration);
|
|
457
457
|
if (defaultImport) bindings.set(defaultImport.getText(), {
|
|
458
458
|
declaration,
|
|
459
459
|
exportedName: "default"
|
|
@@ -465,7 +465,7 @@ const importBindingsFor = (sourceFile) => {
|
|
|
465
465
|
const valueForBinding = (binding, ctx, stack, depth, evaluateExpression) => {
|
|
466
466
|
const sourceFile = getModuleSpecifierSourceFile(binding.declaration, ctx);
|
|
467
467
|
if (!sourceFile) return;
|
|
468
|
-
if (
|
|
468
|
+
if (isInNodeModules(sourceFile)) return;
|
|
469
469
|
const declaration = getExportedVarDeclarationWithName(binding.exportedName, sourceFile, stack, ctx);
|
|
470
470
|
if (!declaration) return;
|
|
471
471
|
const cached = evaluatedValues.get(declaration);
|
|
@@ -473,7 +473,7 @@ const valueForBinding = (binding, ctx, stack, depth, evaluateExpression) => {
|
|
|
473
473
|
const replayed = replayDependencyCache(cached, ctx);
|
|
474
474
|
if (replayed.hit) return { value: replayed.value };
|
|
475
475
|
}
|
|
476
|
-
const initializer = declaration.
|
|
476
|
+
const initializer = declaration.initializer;
|
|
477
477
|
if (!initializer) return;
|
|
478
478
|
const capture = beginDependencyCapture(ctx);
|
|
479
479
|
let value;
|
|
@@ -499,7 +499,7 @@ const importedEnvironmentFor = (node, ctx, stack, depth, evaluateExpression) =>
|
|
|
499
499
|
if (depth >= MAX_DEPTH) return;
|
|
500
500
|
const bindings = importBindingsFor(node.getSourceFile());
|
|
501
501
|
if (!bindings.size) return;
|
|
502
|
-
const references =
|
|
502
|
+
const references = getDescendantsOfKind(node, SyntaxKind.Identifier);
|
|
503
503
|
if (Node.isIdentifier(node)) references.unshift(node);
|
|
504
504
|
if (!references.length) return;
|
|
505
505
|
let environment;
|
|
@@ -571,7 +571,7 @@ const evaluateNodeUncached = (node, stack, ctx, depth, dependencyEntry) => {
|
|
|
571
571
|
let options = {
|
|
572
572
|
policy: { ...POLICY },
|
|
573
573
|
...ctx.getEvaluateOptions?.(node, stack),
|
|
574
|
-
node
|
|
574
|
+
node,
|
|
575
575
|
typescript: ts
|
|
576
576
|
};
|
|
577
577
|
let imported = depth > 0 ? importedEnvironmentFor(node, ctx, stack, depth, safeEvaluateNode) : void 0;
|
|
@@ -632,19 +632,19 @@ function isScope(node) {
|
|
|
632
632
|
return Node.isFunctionDeclaration(node) || Node.isFunctionExpression(node) || Node.isArrowFunction(node) || Node.isSourceFile(node);
|
|
633
633
|
}
|
|
634
634
|
function getDeclarationFor(node, stack, ctx) {
|
|
635
|
-
const parent = node.
|
|
635
|
+
const parent = node.parent;
|
|
636
636
|
if (!parent) return;
|
|
637
637
|
const declarationStack = [];
|
|
638
638
|
let declaration;
|
|
639
|
-
if ((Node.isVariableDeclaration(parent) || Node.isParameterDeclaration(parent) || Node.isFunctionDeclaration(parent) || Node.isEnumDeclaration(parent) || Node.isBindingElement(parent)) && parent.
|
|
639
|
+
if ((Node.isVariableDeclaration(parent) || Node.isParameterDeclaration(parent) || Node.isFunctionDeclaration(parent) || Node.isEnumDeclaration(parent) || Node.isBindingElement(parent)) && parent.name == node) {
|
|
640
640
|
declarationStack.push(parent);
|
|
641
641
|
declaration = parent;
|
|
642
|
-
} else if (Node.isImportSpecifier(parent) && (parent
|
|
642
|
+
} else if (Node.isImportSpecifier(parent) && (nameNodeOf(parent) == node || getAliasNode(parent) == node)) {
|
|
643
643
|
if (ctx.flags?.skipTraverseFiles) return;
|
|
644
|
-
const sourceFile = getModuleSpecifierSourceFile(parent.
|
|
644
|
+
const sourceFile = getModuleSpecifierSourceFile(parent.parent?.parent?.parent, ctx);
|
|
645
645
|
if (sourceFile) {
|
|
646
646
|
const exportStack = [parent, sourceFile];
|
|
647
|
-
const maybeVar = getExportedVarDeclarationWithName(parent
|
|
647
|
+
const maybeVar = getExportedVarDeclarationWithName(nameNodeOf(parent)?.getText() ?? "", sourceFile, exportStack, ctx);
|
|
648
648
|
if (maybeVar) {
|
|
649
649
|
declarationStack.push(...exportStack.concat(maybeVar));
|
|
650
650
|
declaration = maybeVar;
|
|
@@ -655,8 +655,8 @@ function getDeclarationFor(node, stack, ctx) {
|
|
|
655
655
|
return declaration;
|
|
656
656
|
}
|
|
657
657
|
const getInnermostScope = (from) => {
|
|
658
|
-
let scope = from.
|
|
659
|
-
while (scope && !isScope(scope)) scope = scope.
|
|
658
|
+
let scope = from.parent;
|
|
659
|
+
while (scope && !isScope(scope)) scope = scope.parent;
|
|
660
660
|
return scope;
|
|
661
661
|
};
|
|
662
662
|
/**
|
|
@@ -670,8 +670,8 @@ const getInnermostScope = (from) => {
|
|
|
670
670
|
*/
|
|
671
671
|
const declarationIndexes = /* @__PURE__ */ new WeakMap();
|
|
672
672
|
const isDeclarationName = (node, parent) => {
|
|
673
|
-
if (Node.isVariableDeclaration(parent) || Node.isParameterDeclaration(parent) || Node.isFunctionDeclaration(parent) || Node.isEnumDeclaration(parent) || Node.isBindingElement(parent)) return parent.
|
|
674
|
-
return Node.isImportSpecifier(parent) && (parent
|
|
673
|
+
if (Node.isVariableDeclaration(parent) || Node.isParameterDeclaration(parent) || Node.isFunctionDeclaration(parent) || Node.isEnumDeclaration(parent) || Node.isBindingElement(parent)) return parent.name == node;
|
|
674
|
+
return Node.isImportSpecifier(parent) && (nameNodeOf(parent) == node || getAliasNode(parent) == node);
|
|
675
675
|
};
|
|
676
676
|
/**
|
|
677
677
|
* Walk a scope once, so that every later lookup inside it is a map read.
|
|
@@ -682,19 +682,19 @@ const isDeclarationName = (node, parent) => {
|
|
|
682
682
|
* ts-morph charges for wrapping each node — it measured ~10% of extraction on its own.
|
|
683
683
|
*/
|
|
684
684
|
const declarationIndexFor = (scope) => {
|
|
685
|
-
const cached = declarationIndexes.get(scope
|
|
685
|
+
const cached = declarationIndexes.get(scope);
|
|
686
686
|
if (cached) return cached;
|
|
687
687
|
const index = /* @__PURE__ */ new Map();
|
|
688
|
-
|
|
688
|
+
forEachDescendant(scope, (node) => {
|
|
689
689
|
if (!Node.isIdentifier(node)) return;
|
|
690
|
-
const parent = node.
|
|
690
|
+
const parent = node.parent;
|
|
691
691
|
if (!parent || !isDeclarationName(node, parent)) return;
|
|
692
692
|
const name = node.getText();
|
|
693
693
|
const declared = index.get(name);
|
|
694
694
|
if (declared) declared.push(node);
|
|
695
695
|
else index.set(name, [node]);
|
|
696
696
|
});
|
|
697
|
-
declarationIndexes.set(scope
|
|
697
|
+
declarationIndexes.set(scope, index);
|
|
698
698
|
return index;
|
|
699
699
|
};
|
|
700
700
|
function findIdentifierValueDeclaration(identifier, stack, ctx, visitedsWithStack = /* @__PURE__ */ new Map()) {
|
|
@@ -714,10 +714,10 @@ function findIdentifierValueDeclaration(identifier, stack, ctx, visitedsWithStac
|
|
|
714
714
|
const maybeDeclaration = getDeclarationFor(candidate, declarationStack, ctx);
|
|
715
715
|
if (!maybeDeclaration) continue;
|
|
716
716
|
if (Node.isParameterDeclaration(maybeDeclaration)) {
|
|
717
|
-
const initializer = maybeDeclaration.
|
|
718
|
-
const typeNode = maybeDeclaration.
|
|
717
|
+
const initializer = maybeDeclaration.initializer;
|
|
718
|
+
const typeNode = maybeDeclaration.type;
|
|
719
719
|
if (initializer) innerStack.push(...declarationStack.concat(initializer));
|
|
720
|
-
else if (typeNode && Node.
|
|
720
|
+
else if (typeNode && Node.isTypeLiteralNode(typeNode)) innerStack.push(...declarationStack.concat(typeNode));
|
|
721
721
|
else return;
|
|
722
722
|
stack.push(...innerStack);
|
|
723
723
|
return maybeDeclaration;
|
|
@@ -733,34 +733,34 @@ function findIdentifierValueDeclaration(identifier, stack, ctx, visitedsWithStac
|
|
|
733
733
|
const getPropertyName = (property, stack, ctx) => {
|
|
734
734
|
if (!property) return;
|
|
735
735
|
if (Node.isPropertyAssignment(property)) {
|
|
736
|
-
const node = unwrapExpression(property.
|
|
736
|
+
const node = unwrapExpression(property.name);
|
|
737
737
|
if (Node.isIdentifier(node)) return box.from(node.getText(), node, stack);
|
|
738
738
|
if (Node.isComputedPropertyName(node)) {
|
|
739
|
-
const expression = node.
|
|
739
|
+
const expression = node.expression;
|
|
740
740
|
stack.push(expression);
|
|
741
741
|
return maybePropName(expression, stack, ctx);
|
|
742
742
|
}
|
|
743
|
-
if (Node.isStringLiteral(node) || Node.isNumericLiteral(node)) return box.from(
|
|
743
|
+
if (Node.isStringLiteral(node) || Node.isNumericLiteral(node)) return box.from(getLiteralText(node), node, stack);
|
|
744
744
|
}
|
|
745
745
|
if (Node.isShorthandPropertyAssignment(property)) {
|
|
746
|
-
const name =
|
|
746
|
+
const name = getName(property);
|
|
747
747
|
if (name != null) return box.from(name, property, stack);
|
|
748
748
|
}
|
|
749
749
|
if (Node.isGetAccessorDeclaration(property)) {
|
|
750
|
-
const node = unwrapExpression(property.
|
|
750
|
+
const node = unwrapExpression(property.name);
|
|
751
751
|
if (Node.isIdentifier(node)) return box.from(node.getText(), node, stack);
|
|
752
752
|
if (Node.isComputedPropertyName(node)) {
|
|
753
|
-
const expression = node.
|
|
753
|
+
const expression = node.expression;
|
|
754
754
|
stack.push(expression);
|
|
755
755
|
return maybePropName(expression, stack, ctx);
|
|
756
756
|
}
|
|
757
|
-
if (Node.isStringLiteral(node) || Node.isNumericLiteral(node)) return box.from(
|
|
757
|
+
if (Node.isStringLiteral(node) || Node.isNumericLiteral(node)) return box.from(getLiteralText(node), node, stack);
|
|
758
758
|
}
|
|
759
759
|
};
|
|
760
760
|
//#endregion
|
|
761
761
|
//#region src/get-object-literal-expression-prop-pairs.ts
|
|
762
762
|
const getObjectLiteralExpressionPropPairs = (expression, expressionStack, ctx, matchProp) => {
|
|
763
|
-
const properties = expression.
|
|
763
|
+
const properties = expression.properties;
|
|
764
764
|
if (properties.length === 0) return box.emptyObject(expression, expressionStack);
|
|
765
765
|
const extractedPropValues = [];
|
|
766
766
|
const spreadConditions = [];
|
|
@@ -779,7 +779,7 @@ const getObjectLiteralExpressionPropPairs = (expression, expressionStack, ctx, m
|
|
|
779
779
|
propNode: property
|
|
780
780
|
})) return;
|
|
781
781
|
if (Node.isShorthandPropertyAssignment(property)) {
|
|
782
|
-
const initializer = property.
|
|
782
|
+
const initializer = property.name;
|
|
783
783
|
stack.push(initializer);
|
|
784
784
|
const maybeValue = maybeBoxNode(initializer, stack, ctx);
|
|
785
785
|
if (maybeValue) {
|
|
@@ -789,11 +789,11 @@ const getObjectLiteralExpressionPropPairs = (expression, expressionStack, ctx, m
|
|
|
789
789
|
}
|
|
790
790
|
let init;
|
|
791
791
|
if (Node.isGetAccessorDeclaration(property)) {
|
|
792
|
-
const body = property.
|
|
793
|
-
init = Node.isBlock(body) ? body.
|
|
794
|
-
} else init = property
|
|
792
|
+
const body = property.body;
|
|
793
|
+
init = body !== void 0 && Node.isBlock(body) ? body.statements.at(-1) : void 0;
|
|
794
|
+
} else init = childOf(property, "initializer");
|
|
795
795
|
if (!init) return;
|
|
796
|
-
const initializer = unwrapExpression((Node.isReturnStatement(init) ? init.
|
|
796
|
+
const initializer = unwrapExpression((Node.isReturnStatement(init) ? init.expression : void 0) ?? init);
|
|
797
797
|
stack.push(initializer);
|
|
798
798
|
const maybeValue = maybeBoxNode(initializer, stack, ctx);
|
|
799
799
|
if (maybeValue) {
|
|
@@ -802,7 +802,7 @@ const getObjectLiteralExpressionPropPairs = (expression, expressionStack, ctx, m
|
|
|
802
802
|
}
|
|
803
803
|
}
|
|
804
804
|
if (Node.isSpreadAssignment(property)) {
|
|
805
|
-
const initializer = unwrapExpression(property.
|
|
805
|
+
const initializer = unwrapExpression(property.expression);
|
|
806
806
|
stack.push(initializer);
|
|
807
807
|
const maybeObject = maybeBoxNode(initializer, stack, ctx, matchProp);
|
|
808
808
|
if (!maybeObject) return;
|
|
@@ -883,28 +883,28 @@ function maybeBoxNodeUncached(node, stack, ctx, matchProp, dependencyEntry) {
|
|
|
883
883
|
return value;
|
|
884
884
|
};
|
|
885
885
|
if (Node.isStringLiteral(node) || Node.isNoSubstitutionTemplateLiteral(node)) {
|
|
886
|
-
const value = trimWhitespace(node
|
|
886
|
+
const value = trimWhitespace(stringLiteralValue(node));
|
|
887
887
|
return cache(box.literal(value, node, stack));
|
|
888
888
|
}
|
|
889
889
|
if (Node.isObjectLiteralExpression(node)) return cache(getObjectLiteralExpressionPropPairs(node, stack, ctx, matchProp));
|
|
890
890
|
if (Node.isTrueLiteral(node) || Node.isFalseLiteral(node)) {
|
|
891
|
-
const value = node
|
|
891
|
+
const value = literalValueOf(node);
|
|
892
892
|
return cache(box.literal(value, node, stack));
|
|
893
893
|
}
|
|
894
894
|
if (Node.isNumericLiteral(node)) {
|
|
895
|
-
const value = node
|
|
895
|
+
const value = literalValueOf(node);
|
|
896
896
|
return cache(box.literal(value, node, stack));
|
|
897
897
|
}
|
|
898
898
|
if (Node.isNullLiteral(node)) return cache(box.literal(null, node, stack));
|
|
899
899
|
if (Node.isPrefixUnaryExpression(node)) {
|
|
900
|
-
const operand = node.
|
|
901
|
-
const operator = node.
|
|
900
|
+
const operand = node.operand;
|
|
901
|
+
const operator = node.operator;
|
|
902
902
|
const boxNode = maybeBoxNode(operand, stack, ctx);
|
|
903
903
|
if (!box.isNumberLiteral(boxNode)) return;
|
|
904
904
|
return cache(operator === ts.SyntaxKind.MinusToken ? box.literal(-Number(boxNode.value), node, stack) : boxNode);
|
|
905
905
|
}
|
|
906
906
|
if (Node.isArrayLiteralExpression(node)) {
|
|
907
|
-
const boxNodes = node.
|
|
907
|
+
const boxNodes = node.elements.map((element) => {
|
|
908
908
|
return maybeBoxNode(element, stack, ctx) ?? cache(box.unresolvable(element, stack));
|
|
909
909
|
});
|
|
910
910
|
return cache(box.array(boxNodes, node, stack));
|
|
@@ -913,45 +913,45 @@ function maybeBoxNodeUncached(node, stack, ctx, matchProp, dependencyEntry) {
|
|
|
913
913
|
if (node.getText() === "undefined") return cache(box.literal(void 0, node, stack));
|
|
914
914
|
return cache(maybeIdentifierValue(node, stack, ctx));
|
|
915
915
|
}
|
|
916
|
-
if (Node.isTemplateHead(node)) return cache(box.literal(
|
|
916
|
+
if (Node.isTemplateHead(node)) return cache(box.literal(getLiteralText(node), node, stack));
|
|
917
917
|
if (Node.isTemplateExpression(node)) {
|
|
918
918
|
const value = maybeTemplateStringValue(node, stack, ctx);
|
|
919
919
|
return cache(box.literal(value, node, stack));
|
|
920
920
|
}
|
|
921
|
-
if (Node.isTaggedTemplateExpression(node)) return cache(maybeBoxNode(node.
|
|
921
|
+
if (Node.isTaggedTemplateExpression(node)) return cache(maybeBoxNode(node.template, stack, ctx));
|
|
922
922
|
if (Node.isElementAccessExpression(node)) return cache(getElementAccessedExpressionValue(node, stack, ctx));
|
|
923
923
|
if (Node.isPropertyAccessExpression(node)) return cache(getPropertyAccessedExpressionValue(node, [], stack, ctx));
|
|
924
924
|
if (Node.isConditionalExpression(node)) {
|
|
925
925
|
if (ctx.flags?.skipConditions) return cache(box.unresolvable(node, stack));
|
|
926
|
-
const condExpr = unwrapExpression(node.
|
|
926
|
+
const condExpr = unwrapExpression(node.condition);
|
|
927
927
|
const condBoxNode = (Node.isIdentifier(condExpr) ? maybeBoxNode(condExpr, [], ctx) : safeEvaluateNode(condExpr, stack, ctx)) ?? box.unresolvable(condExpr, stack);
|
|
928
928
|
const condValue = isBoxNode(condBoxNode) ? condBoxNode : box.from(condBoxNode, node, stack);
|
|
929
929
|
if (box.isEmptyInitializer(condValue)) return;
|
|
930
930
|
const isFromDefaultBinding = condValue.getStack().some((node) => Node.isBindingElement(node));
|
|
931
931
|
if (box.isUnresolvable(condValue) || box.isConditional(condValue) || isFromDefaultBinding) return cache(maybeResolveConditionalExpression({
|
|
932
|
-
whenTrueExpr: unwrapExpression(node.
|
|
933
|
-
whenFalseExpr: unwrapExpression(node.
|
|
932
|
+
whenTrueExpr: unwrapExpression(node.whenTrue),
|
|
933
|
+
whenFalseExpr: unwrapExpression(node.whenFalse),
|
|
934
934
|
node,
|
|
935
935
|
stack
|
|
936
936
|
}, ctx));
|
|
937
937
|
if (condValue.value) {
|
|
938
|
-
const whenTrueExpr = unwrapExpression(node.
|
|
938
|
+
const whenTrueExpr = unwrapExpression(node.whenTrue);
|
|
939
939
|
return cache(maybeBoxNode(whenTrueExpr, [...stack], ctx) ?? box.unresolvable(whenTrueExpr, stack));
|
|
940
940
|
}
|
|
941
|
-
return cache(maybeBoxNode(unwrapExpression(node.
|
|
941
|
+
return cache(maybeBoxNode(unwrapExpression(node.whenFalse), [...stack], ctx) ?? box.unresolvable(node, stack));
|
|
942
942
|
}
|
|
943
943
|
if (Node.isCallExpression(node)) {
|
|
944
944
|
if (ctx.tokens) {
|
|
945
|
-
const expr = node.
|
|
945
|
+
const expr = node.expression;
|
|
946
946
|
let fnName = "";
|
|
947
947
|
let isValueMethod = false;
|
|
948
948
|
if (Node.isIdentifier(expr)) fnName = expr.getText();
|
|
949
|
-
else if (Node.isPropertyAccessExpression(expr)) if (
|
|
949
|
+
else if (Node.isPropertyAccessExpression(expr)) if (getName(expr) === "value") {
|
|
950
950
|
isValueMethod = true;
|
|
951
|
-
fnName = expr.
|
|
951
|
+
fnName = expr.expression.getText();
|
|
952
952
|
} else fnName = expr.getText();
|
|
953
953
|
if (ctx.tokens.isTokenFn ? ctx.tokens.isTokenFn(fnName) : fnName === "token") {
|
|
954
|
-
const tokenPathArg = node.
|
|
954
|
+
const tokenPathArg = node.arguments[0];
|
|
955
955
|
const tokenPath = tokenPathArg ? literalStringOf(tokenPathArg, stack, ctx) : void 0;
|
|
956
956
|
if (tokenPath !== void 0) {
|
|
957
957
|
const resolvedValue = isValueMethod ? ctx.tokens.view.get(tokenPath) : ctx.tokens.view.getVar(tokenPath);
|
|
@@ -964,7 +964,7 @@ function maybeBoxNodeUncached(node, stack, ctx, matchProp, dependencyEntry) {
|
|
|
964
964
|
return cache(box.from(value, node, stack));
|
|
965
965
|
}
|
|
966
966
|
if (Node.isBinaryExpression(node)) {
|
|
967
|
-
const operatorKind = node.
|
|
967
|
+
const operatorKind = node.operatorToken.kind;
|
|
968
968
|
if (isPlusSyntax(operatorKind)) {
|
|
969
969
|
const value = tryComputingPlusTokenBinaryExpressionToString(node, stack, ctx) ?? safeEvaluateNode(node, stack, ctx);
|
|
970
970
|
if (!value) return;
|
|
@@ -972,8 +972,8 @@ function maybeBoxNodeUncached(node, stack, ctx, matchProp, dependencyEntry) {
|
|
|
972
972
|
return cache(box.from(value, node, stack));
|
|
973
973
|
}
|
|
974
974
|
if (isLogicalSyntax(operatorKind)) return cache(maybeResolveConditionalExpression({
|
|
975
|
-
whenTrueExpr: unwrapExpression(node.
|
|
976
|
-
whenFalseExpr: unwrapExpression(node.
|
|
975
|
+
whenTrueExpr: unwrapExpression(node.left),
|
|
976
|
+
whenFalseExpr: unwrapExpression(node.right),
|
|
977
977
|
node,
|
|
978
978
|
stack,
|
|
979
979
|
canReturnWhenTrue: canReturnWhenTrueInLogicalExpression(operatorKind)
|
|
@@ -990,7 +990,7 @@ function maybeBoxNodeUncached(node, stack, ctx, matchProp, dependencyEntry) {
|
|
|
990
990
|
* Returning `undefined` leaves the call unresolved, exactly as before.
|
|
991
991
|
*/
|
|
992
992
|
function literalStringOf(node, stack, ctx) {
|
|
993
|
-
if (Node.isStringLiteral(node)) return node
|
|
993
|
+
if (Node.isStringLiteral(node)) return stringLiteralValue(node);
|
|
994
994
|
const resolved = onlyStringLiteral(maybeBoxNode(node, stack, ctx));
|
|
995
995
|
return resolved && typeof resolved.value === "string" ? resolved.value : void 0;
|
|
996
996
|
}
|
|
@@ -1014,7 +1014,7 @@ const maybeResolveConditionalExpression = ({ whenTrueExpr, whenFalseExpr, node,
|
|
|
1014
1014
|
const whenTrueValue = maybeBoxNode(whenTrueExpr, stack, ctx);
|
|
1015
1015
|
const whenFalseValue = maybeBoxNode(whenFalseExpr, stack, ctx);
|
|
1016
1016
|
if (canReturnWhenTrue && whenTrueValue && !box.isUnresolvable(whenTrueValue)) return whenTrueValue;
|
|
1017
|
-
if (Node.isBinaryExpression(node) && node.
|
|
1017
|
+
if (Node.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken && whenTrueValue && whenFalseValue && box.isLiteral(whenTrueValue) && whenTrueValue.value === true) return whenFalseValue;
|
|
1018
1018
|
if (!whenTrueValue && !whenFalseValue) return;
|
|
1019
1019
|
if (whenTrueValue && !whenFalseValue) return whenTrueValue;
|
|
1020
1020
|
if (!whenTrueValue && whenFalseValue) return whenFalseValue;
|
|
@@ -1026,17 +1026,17 @@ const maybeResolveConditionalExpression = ({ whenTrueExpr, whenFalseExpr, node,
|
|
|
1026
1026
|
const findProperty = (node, propName, _stack, ctx) => {
|
|
1027
1027
|
const stack = [..._stack];
|
|
1028
1028
|
if (Node.isPropertyAssignment(node)) {
|
|
1029
|
-
const name = node.
|
|
1029
|
+
const name = node.name;
|
|
1030
1030
|
if (Node.isIdentifier(name) && name.getText() === propName) {
|
|
1031
1031
|
stack.push(name);
|
|
1032
1032
|
return node;
|
|
1033
1033
|
}
|
|
1034
|
-
if (Node.isStringLiteral(name) &&
|
|
1034
|
+
if (Node.isStringLiteral(name) && getLiteralText(name) === propName) {
|
|
1035
1035
|
stack.push(name);
|
|
1036
|
-
return
|
|
1036
|
+
return getLiteralText(name);
|
|
1037
1037
|
}
|
|
1038
1038
|
if (Node.isComputedPropertyName(name)) {
|
|
1039
|
-
const expression = unwrapExpression(name.
|
|
1039
|
+
const expression = unwrapExpression(name.expression);
|
|
1040
1040
|
const computedPropNameBox = maybePropName(expression, stack, ctx);
|
|
1041
1041
|
if (!computedPropNameBox) return;
|
|
1042
1042
|
if (String(computedPropNameBox.value) === propName) {
|
|
@@ -1046,7 +1046,7 @@ const findProperty = (node, propName, _stack, ctx) => {
|
|
|
1046
1046
|
}
|
|
1047
1047
|
}
|
|
1048
1048
|
if (Node.isShorthandPropertyAssignment(node)) {
|
|
1049
|
-
const name = node.
|
|
1049
|
+
const name = node.name;
|
|
1050
1050
|
if (Node.isIdentifier(name) && name.getText() === propName) {
|
|
1051
1051
|
stack.push(name);
|
|
1052
1052
|
return node;
|
|
@@ -1056,11 +1056,11 @@ const findProperty = (node, propName, _stack, ctx) => {
|
|
|
1056
1056
|
const getObjectLiteralPropValue = (initializer, accessList, _stack, ctx) => {
|
|
1057
1057
|
const stack = [..._stack];
|
|
1058
1058
|
const propName = accessList.pop();
|
|
1059
|
-
const property =
|
|
1059
|
+
const property = getProperty(initializer, propName) ?? initializer.properties.find((p) => findProperty(p, propName, stack, ctx));
|
|
1060
1060
|
if (!property) return;
|
|
1061
1061
|
stack.push(property);
|
|
1062
1062
|
if (Node.isPropertyAssignment(property)) {
|
|
1063
|
-
const propInit = property.
|
|
1063
|
+
const propInit = property.initializer;
|
|
1064
1064
|
if (!propInit) return;
|
|
1065
1065
|
if (Node.isObjectLiteralExpression(propInit)) {
|
|
1066
1066
|
if (accessList.length > 0) return getObjectLiteralPropValue(propInit, accessList, stack, ctx);
|
|
@@ -1070,39 +1070,40 @@ const getObjectLiteralPropValue = (initializer, accessList, _stack, ctx) => {
|
|
|
1070
1070
|
if (maybePropValue) return maybePropValue;
|
|
1071
1071
|
}
|
|
1072
1072
|
if (Node.isShorthandPropertyAssignment(property)) {
|
|
1073
|
-
const identifier = property.
|
|
1073
|
+
const identifier = property.name;
|
|
1074
1074
|
if (accessList.length > 0) return maybePropIdentifierValue(identifier, accessList, stack, ctx);
|
|
1075
1075
|
const maybePropValue = maybeBoxNode(identifier, stack, ctx);
|
|
1076
1076
|
if (maybePropValue) return maybePropValue;
|
|
1077
1077
|
}
|
|
1078
1078
|
};
|
|
1079
1079
|
const maybeTemplateStringValue = (template, stack, ctx) => {
|
|
1080
|
-
const head = template.
|
|
1081
|
-
const tail = template.
|
|
1080
|
+
const head = template.head;
|
|
1081
|
+
const tail = template.templateSpans;
|
|
1082
1082
|
const headValue = maybeStringLiteral(head, stack, ctx);
|
|
1083
1083
|
if (!headValue) return;
|
|
1084
1084
|
const tailValues = tail.map((t) => {
|
|
1085
|
-
const
|
|
1085
|
+
const expression = t.expression;
|
|
1086
|
+
const propBox = maybePropName(expression, stack, ctx);
|
|
1086
1087
|
if (!propBox) return;
|
|
1087
|
-
const literal = t.
|
|
1088
|
-
return propBox.value +
|
|
1088
|
+
const literal = t.literal;
|
|
1089
|
+
return propBox.value + getLiteralText(literal);
|
|
1089
1090
|
});
|
|
1090
1091
|
if (tailValues.every(isNotNullish)) return headValue.value + tailValues.join("");
|
|
1091
1092
|
};
|
|
1092
1093
|
const maybeBindingElementValue = (def, stack, propName, ctx) => {
|
|
1093
|
-
const parent = def.
|
|
1094
|
+
const parent = def.parent;
|
|
1094
1095
|
if (!parent) return;
|
|
1095
|
-
const grandParent = parent.
|
|
1096
|
+
const grandParent = parent.parent;
|
|
1096
1097
|
if (!grandParent) return;
|
|
1097
1098
|
if (Node.isArrayBindingPattern(parent)) {
|
|
1098
|
-
const index =
|
|
1099
|
+
const index = getChildIndex(parent);
|
|
1099
1100
|
if (Number.isNaN(index)) return;
|
|
1100
1101
|
if (Node.isVariableDeclaration(grandParent)) {
|
|
1101
|
-
const init = grandParent.
|
|
1102
|
+
const init = grandParent.initializer;
|
|
1102
1103
|
if (!init) return;
|
|
1103
1104
|
const initializer = unwrapExpression(init);
|
|
1104
1105
|
if (!Node.isArrayLiteralExpression(initializer)) return;
|
|
1105
|
-
const element = initializer.
|
|
1106
|
+
const element = initializer.elements[index + 1];
|
|
1106
1107
|
if (!element) return;
|
|
1107
1108
|
const innerStack = [
|
|
1108
1109
|
...stack,
|
|
@@ -1126,22 +1127,22 @@ const maybeBindingElementValue = (def, stack, propName, ctx) => {
|
|
|
1126
1127
|
function maybePropDefinitionValue(def, accessList, _stack, ctx) {
|
|
1127
1128
|
const propName = accessList.at(-1);
|
|
1128
1129
|
if (Node.isVariableDeclaration(def)) {
|
|
1129
|
-
const init = def.
|
|
1130
|
+
const init = def.initializer;
|
|
1130
1131
|
if (!init) {
|
|
1131
|
-
const type = def.
|
|
1132
|
+
const type = def.type;
|
|
1132
1133
|
if (!type) return;
|
|
1133
|
-
if (Node.
|
|
1134
|
+
if (Node.isTypeLiteralNode(type)) {
|
|
1134
1135
|
if (accessList.length > 0) {
|
|
1135
1136
|
const stack = [..._stack];
|
|
1136
1137
|
stack.push(type);
|
|
1137
1138
|
let propName = accessList.pop();
|
|
1138
|
-
let typeProp =
|
|
1139
|
-
let typeLiteral = typeProp
|
|
1140
|
-
while (typeProp && accessList.length > 0 && typeLiteral && Node.
|
|
1139
|
+
let typeProp = getProperty(type, propName);
|
|
1140
|
+
let typeLiteral = typeProp && childOf(typeProp, "type");
|
|
1141
|
+
while (typeProp && accessList.length > 0 && typeLiteral && Node.isTypeLiteralNode(typeLiteral)) {
|
|
1141
1142
|
stack.push(typeProp, typeLiteral);
|
|
1142
1143
|
propName = accessList.pop();
|
|
1143
|
-
typeProp =
|
|
1144
|
-
typeLiteral = typeProp
|
|
1144
|
+
typeProp = getProperty(typeLiteral, propName);
|
|
1145
|
+
typeLiteral = typeProp && childOf(typeProp, "type");
|
|
1145
1146
|
}
|
|
1146
1147
|
if (!typeLiteral) return;
|
|
1147
1148
|
const typeValue = getTypeNodeValue(typeLiteral, stack, ctx);
|
|
@@ -1163,7 +1164,7 @@ function maybePropDefinitionValue(def, accessList, _stack, ctx) {
|
|
|
1163
1164
|
if (Node.isArrayLiteralExpression(initializer)) {
|
|
1164
1165
|
const index = Number(propName);
|
|
1165
1166
|
if (Number.isNaN(index)) return;
|
|
1166
|
-
const element = initializer.
|
|
1167
|
+
const element = initializer.elements[index];
|
|
1167
1168
|
if (!element) return;
|
|
1168
1169
|
_stack.push(initializer);
|
|
1169
1170
|
const boxed = maybeBoxNode(element, _stack, ctx);
|
|
@@ -1177,9 +1178,9 @@ function maybePropDefinitionValue(def, accessList, _stack, ctx) {
|
|
|
1177
1178
|
if (value) return value;
|
|
1178
1179
|
}
|
|
1179
1180
|
if (Node.isEnumDeclaration(def)) {
|
|
1180
|
-
const member =
|
|
1181
|
+
const member = getMember(def, propName);
|
|
1181
1182
|
if (!member) return;
|
|
1182
|
-
const initializer = member
|
|
1183
|
+
const initializer = childOf(member, "initializer");
|
|
1183
1184
|
if (!initializer) return;
|
|
1184
1185
|
const maybeValue = maybeBoxNode(initializer, [..._stack, initializer], ctx);
|
|
1185
1186
|
if (maybeValue) return maybeValue;
|
|
@@ -1199,9 +1200,9 @@ const getTypeLiteralNodePropValue = (type, propName, stack, ctx) => {
|
|
|
1199
1200
|
if (map === null) return;
|
|
1200
1201
|
if (map?.has(propName)) return map.get(propName);
|
|
1201
1202
|
}
|
|
1202
|
-
const prop = type.
|
|
1203
|
-
if (Node.
|
|
1204
|
-
const propType = prop.
|
|
1203
|
+
const prop = type.members.find((member) => Node.isPropertySignatureDeclaration(member) && getName(member) === propName);
|
|
1204
|
+
if (prop !== void 0 && Node.isPropertySignatureDeclaration(prop) && isReadonly(prop)) {
|
|
1205
|
+
const propType = prop.type;
|
|
1205
1206
|
if (!propType) {
|
|
1206
1207
|
typeLiteralCache.set(type, null);
|
|
1207
1208
|
return;
|
|
@@ -1216,29 +1217,28 @@ const getTypeLiteralNodePropValue = (type, propName, stack, ctx) => {
|
|
|
1216
1217
|
typeLiteralCache.set(type, null);
|
|
1217
1218
|
};
|
|
1218
1219
|
function getNameLiteral(wrapper) {
|
|
1219
|
-
if (Node.isStringLiteral(wrapper)) return
|
|
1220
|
+
if (Node.isStringLiteral(wrapper)) return getLiteralText(wrapper);
|
|
1220
1221
|
return wrapper.getText();
|
|
1221
1222
|
}
|
|
1222
1223
|
const typeNodeCache = /* @__PURE__ */ new WeakMap();
|
|
1223
1224
|
const getTypeNodeValue = (type, stack, ctx) => {
|
|
1224
1225
|
if (typeNodeCache.has(type)) return typeNodeCache.get(type);
|
|
1225
1226
|
if (Node.isLiteralTypeNode(type)) {
|
|
1226
|
-
const literal = type.
|
|
1227
|
+
const literal = type.literal;
|
|
1227
1228
|
if (Node.isStringLiteral(literal)) {
|
|
1228
|
-
const result =
|
|
1229
|
+
const result = getLiteralText(literal);
|
|
1229
1230
|
typeNodeCache.set(type, result);
|
|
1230
1231
|
return result;
|
|
1231
1232
|
}
|
|
1232
1233
|
}
|
|
1233
|
-
if (Node.
|
|
1234
|
-
const members = type.
|
|
1235
|
-
if (!members.some((member) => !Node.
|
|
1234
|
+
if (Node.isTypeLiteralNode(type)) {
|
|
1235
|
+
const members = type.members;
|
|
1236
|
+
if (!members.some((member) => !Node.isPropertySignatureDeclaration(member) || !isReadonly(member))) {
|
|
1236
1237
|
const entries = members.map((member) => {
|
|
1237
|
-
const nameNode = member.
|
|
1238
|
-
const nameText = nameNode.getText();
|
|
1238
|
+
const nameNode = member.name;
|
|
1239
1239
|
const name = getNameLiteral(nameNode);
|
|
1240
1240
|
if (!name) return;
|
|
1241
|
-
return [name, getTypeLiteralNodePropValue(type,
|
|
1241
|
+
return [name, getTypeLiteralNodePropValue(type, name, stack, ctx)];
|
|
1242
1242
|
}).filter(isNotNullish);
|
|
1243
1243
|
const result = Object.fromEntries(entries);
|
|
1244
1244
|
typeNodeCache.set(type, result);
|
|
@@ -1249,15 +1249,15 @@ const getTypeNodeValue = (type, stack, ctx) => {
|
|
|
1249
1249
|
};
|
|
1250
1250
|
const maybeDefinitionValue = (def, stack, ctx) => {
|
|
1251
1251
|
if (Node.isShorthandPropertyAssignment(def)) {
|
|
1252
|
-
const propNameNode = def.
|
|
1252
|
+
const propNameNode = def.name;
|
|
1253
1253
|
return maybePropIdentifierValue(propNameNode, [propNameNode.getText()], stack, ctx);
|
|
1254
1254
|
}
|
|
1255
1255
|
if (Node.isVariableDeclaration(def)) {
|
|
1256
|
-
const init = def.
|
|
1256
|
+
const init = def.initializer;
|
|
1257
1257
|
if (!init) {
|
|
1258
|
-
const type = def.
|
|
1258
|
+
const type = def.type;
|
|
1259
1259
|
if (!type) return;
|
|
1260
|
-
if (Node.
|
|
1260
|
+
if (Node.isTypeLiteralNode(type)) {
|
|
1261
1261
|
stack.push(type);
|
|
1262
1262
|
const maybeTypeValue = getTypeNodeValue(type, stack, ctx);
|
|
1263
1263
|
if (isNotNullish(maybeTypeValue)) return box.from(maybeTypeValue, def, stack);
|
|
@@ -1269,11 +1269,11 @@ const maybeDefinitionValue = (def, stack, ctx) => {
|
|
|
1269
1269
|
if (maybeValue) return maybeValue;
|
|
1270
1270
|
}
|
|
1271
1271
|
if (Node.isBindingElement(def)) {
|
|
1272
|
-
const init = def.
|
|
1272
|
+
const init = def.initializer;
|
|
1273
1273
|
if (!init) {
|
|
1274
|
-
const nameNode = def.
|
|
1275
|
-
const propName = nameNode
|
|
1276
|
-
const value = maybeBindingElementValue(def, [...stack, nameNode], propName, ctx);
|
|
1274
|
+
const nameNode = def.propertyName ?? def.name;
|
|
1275
|
+
const propName = nameNode?.getText() ?? "";
|
|
1276
|
+
const value = maybeBindingElementValue(def, [...stack, nameNode].filter(Boolean), propName, ctx);
|
|
1277
1277
|
if (value) return value;
|
|
1278
1278
|
return box.unresolvable(def, stack);
|
|
1279
1279
|
}
|
|
@@ -1283,11 +1283,11 @@ const maybeDefinitionValue = (def, stack, ctx) => {
|
|
|
1283
1283
|
}
|
|
1284
1284
|
};
|
|
1285
1285
|
const getExportedVarDeclarationWithName = (varName, sourceFile, stack, ctx, visited = /* @__PURE__ */ new Set()) => {
|
|
1286
|
-
ctx.recordExportRead?.(sourceFile
|
|
1287
|
-
const key = `${sourceFile
|
|
1286
|
+
ctx.recordExportRead?.(pathOf(sourceFile), varName);
|
|
1287
|
+
const key = `${pathOf(sourceFile)}:${varName}`;
|
|
1288
1288
|
if (visited.has(key)) return;
|
|
1289
1289
|
visited.add(key);
|
|
1290
|
-
const maybeVar =
|
|
1290
|
+
const maybeVar = getVariableDeclaration(sourceFile, varName);
|
|
1291
1291
|
if (maybeVar) return maybeVar;
|
|
1292
1292
|
const exportDeclaration = resolveVarDeclarationFromExportWithName(varName, sourceFile, stack, ctx, visited);
|
|
1293
1293
|
if (!exportDeclaration) return;
|
|
@@ -1303,9 +1303,9 @@ const getExportedVarDeclarationWithName = (varName, sourceFile, stack, ctx, visi
|
|
|
1303
1303
|
* module does export and resolves names it does not.
|
|
1304
1304
|
*/
|
|
1305
1305
|
const resolveExportedName = (name, exportDeclaration) => {
|
|
1306
|
-
const namedExports =
|
|
1306
|
+
const namedExports = getNamedExports(exportDeclaration);
|
|
1307
1307
|
if (namedExports.length === 0) return name;
|
|
1308
|
-
for (const namedExport of namedExports) if ((
|
|
1308
|
+
for (const namedExport of namedExports) if (((getAliasNode(namedExport) ?? nameNodeOf(namedExport))?.getText() ?? "") === name) return nameNodeOf(namedExport)?.getText();
|
|
1309
1309
|
};
|
|
1310
1310
|
/**
|
|
1311
1311
|
* Faster than declaration.getModuleSpecifierSourceFile()
|
|
@@ -1317,20 +1317,20 @@ const resolveExportedName = (name, exportDeclaration) => {
|
|
|
1317
1317
|
* @see https://github.com/dsherret/ts-morph/blob/42d811ed9a5177fc678a5bfec4923a2048124fe0/packages/ts-morph/src/compiler/ast/module/ExportDeclaration.ts#L160
|
|
1318
1318
|
*/
|
|
1319
1319
|
const getModuleSpecifierSourceFile = (declaration, ctx) => {
|
|
1320
|
-
const moduleName =
|
|
1320
|
+
const moduleName = getModuleSpecifierValue(declaration);
|
|
1321
1321
|
if (!moduleName) return;
|
|
1322
1322
|
const sourceFile = ctx.resolveModule?.(moduleName, declaration.getSourceFile());
|
|
1323
|
-
if (sourceFile) recordModuleDependency(ctx, sourceFile
|
|
1323
|
+
if (sourceFile) recordModuleDependency(ctx, pathOf(sourceFile));
|
|
1324
1324
|
return sourceFile;
|
|
1325
1325
|
};
|
|
1326
1326
|
function resolveVarDeclarationFromExportWithName(symbolName, sourceFile, stack, ctx, visited) {
|
|
1327
|
-
for (const exportDeclaration of
|
|
1327
|
+
for (const exportDeclaration of getExportDeclarations(sourceFile)) {
|
|
1328
1328
|
const exportStack = [exportDeclaration];
|
|
1329
1329
|
const sourceName = resolveExportedName(symbolName, exportDeclaration);
|
|
1330
1330
|
if (sourceName === void 0) continue;
|
|
1331
1331
|
const maybeFile = getModuleSpecifierSourceFile(exportDeclaration, ctx);
|
|
1332
1332
|
if (!maybeFile) {
|
|
1333
|
-
const localVar =
|
|
1333
|
+
const localVar = getVariableDeclaration(sourceFile, sourceName);
|
|
1334
1334
|
if (localVar) {
|
|
1335
1335
|
stack.push(...exportStack.concat(localVar));
|
|
1336
1336
|
return localVar;
|
|
@@ -1355,16 +1355,16 @@ const maybeIdentifierValue = (identifier, _stack, ctx) => {
|
|
|
1355
1355
|
return box.unresolvable(identifier, stack);
|
|
1356
1356
|
};
|
|
1357
1357
|
const tryComputingPlusTokenBinaryExpressionToString = (node, stack, ctx) => {
|
|
1358
|
-
const left = unwrapExpression(node.
|
|
1359
|
-
const right = unwrapExpression(node.
|
|
1358
|
+
const left = unwrapExpression(node.left);
|
|
1359
|
+
const right = unwrapExpression(node.right);
|
|
1360
1360
|
const leftValue = maybePropName(left, stack, ctx);
|
|
1361
1361
|
const rightValue = maybePropName(right, stack, ctx);
|
|
1362
1362
|
if (!leftValue || !rightValue) return;
|
|
1363
1363
|
if (isNotNullish(leftValue.value) && isNotNullish(rightValue.value)) return box.literal(String(leftValue.value) + String(rightValue.value), node, stack);
|
|
1364
1364
|
};
|
|
1365
1365
|
const getElementAccessedExpressionValue = (expression, _stack, ctx) => {
|
|
1366
|
-
const elementAccessed = unwrapExpression(expression.
|
|
1367
|
-
const argExpr = expression.
|
|
1366
|
+
const elementAccessed = unwrapExpression(expression.expression);
|
|
1367
|
+
const argExpr = expression.argumentExpression;
|
|
1368
1368
|
if (!argExpr) return;
|
|
1369
1369
|
const arg = unwrapExpression(argExpr);
|
|
1370
1370
|
const stack = [
|
|
@@ -1378,7 +1378,7 @@ const getElementAccessedExpressionValue = (expression, _stack, ctx) => {
|
|
|
1378
1378
|
return maybePropIdentifierValue(elementAccessed, [argLiteral.value.toString()], stack, ctx);
|
|
1379
1379
|
}
|
|
1380
1380
|
if (Node.isBinaryExpression(arg)) {
|
|
1381
|
-
if (arg.
|
|
1381
|
+
if (arg.operatorToken.kind !== ts.SyntaxKind.PlusToken) return;
|
|
1382
1382
|
const propName = tryComputingPlusTokenBinaryExpressionToString(arg, stack, ctx) ?? maybePropName(arg, stack, ctx);
|
|
1383
1383
|
if (propName && Node.isIdentifier(elementAccessed)) {
|
|
1384
1384
|
if (!isNotNullish(propName.value)) return;
|
|
@@ -1435,8 +1435,8 @@ const getElementAccessedExpressionValue = (expression, _stack, ctx) => {
|
|
|
1435
1435
|
if (isNotNullish(propName) && isNotNullish(propName.value)) {
|
|
1436
1436
|
if (Node.isIdentifier(elementAccessed)) return maybePropIdentifierValue(elementAccessed, [propName.value.toString()], stack, ctx);
|
|
1437
1437
|
}
|
|
1438
|
-
const whenTrueExpr = unwrapExpression(arg.
|
|
1439
|
-
const whenFalseExpr = unwrapExpression(arg.
|
|
1438
|
+
const whenTrueExpr = unwrapExpression(arg.whenTrue);
|
|
1439
|
+
const whenFalseExpr = unwrapExpression(arg.whenFalse);
|
|
1440
1440
|
const whenTrueValue = maybePropName(whenTrueExpr, stack, ctx);
|
|
1441
1441
|
const whenFalseValue = maybePropName(whenFalseExpr, stack, ctx);
|
|
1442
1442
|
if (Node.isIdentifier(elementAccessed)) {
|
|
@@ -1450,15 +1450,15 @@ const getElementAccessedExpressionValue = (expression, _stack, ctx) => {
|
|
|
1450
1450
|
}
|
|
1451
1451
|
};
|
|
1452
1452
|
const getArrayElementValueAtIndex = (array, index, stack, ctx) => {
|
|
1453
|
-
const element = array.
|
|
1453
|
+
const element = array.elements[index];
|
|
1454
1454
|
if (!element) return;
|
|
1455
1455
|
const value = maybeBoxNode(element, stack, ctx);
|
|
1456
1456
|
if (isNotNullish(value)) return value;
|
|
1457
1457
|
};
|
|
1458
1458
|
const getPropertyAccessedExpressionValue = (expression, _accessList, stack, ctx) => {
|
|
1459
|
-
const propName =
|
|
1460
|
-
const elementAccessed = unwrapExpression(expression.
|
|
1461
|
-
const accessList = _accessList.concat(propName);
|
|
1459
|
+
const propName = getName(expression);
|
|
1460
|
+
const elementAccessed = unwrapExpression(expression.expression);
|
|
1461
|
+
const accessList = _accessList.concat(String(propName));
|
|
1462
1462
|
stack.push(elementAccessed);
|
|
1463
1463
|
if (Node.isIdentifier(elementAccessed)) return maybePropIdentifierValue(elementAccessed, accessList, stack, ctx);
|
|
1464
1464
|
if (Node.isPropertyAccessExpression(elementAccessed)) return getPropertyAccessedExpressionValue(elementAccessed, accessList, stack, ctx);
|
|
@@ -1466,11 +1466,11 @@ const getPropertyAccessedExpressionValue = (expression, _accessList, stack, ctx)
|
|
|
1466
1466
|
const leftElementAccessed = getElementAccessedExpressionValue(elementAccessed, stack, ctx);
|
|
1467
1467
|
if (!leftElementAccessed) return;
|
|
1468
1468
|
if (box.isObject(leftElementAccessed)) {
|
|
1469
|
-
const propValue = leftElementAccessed.value[propName];
|
|
1469
|
+
const propValue = leftElementAccessed.value[String(propName)];
|
|
1470
1470
|
return box.from(propValue, expression, stack);
|
|
1471
1471
|
}
|
|
1472
1472
|
if (box.isMap(leftElementAccessed)) {
|
|
1473
|
-
const propValue = leftElementAccessed.value.get(propName);
|
|
1473
|
+
const propValue = leftElementAccessed.value.get(propName ?? "");
|
|
1474
1474
|
return box.from(propValue, expression, stack);
|
|
1475
1475
|
}
|
|
1476
1476
|
}
|
|
@@ -1479,8 +1479,8 @@ const getPropertyAccessedExpressionValue = (expression, _accessList, stack, ctx)
|
|
|
1479
1479
|
//#region src/call-expression.ts
|
|
1480
1480
|
const trueFn = () => true;
|
|
1481
1481
|
const extractCallExpressionArguments = (node, ctx, matchProp = trueFn, matchArg = trueFn) => {
|
|
1482
|
-
const fnArguments = node.
|
|
1483
|
-
const fnName = node.
|
|
1482
|
+
const fnArguments = node.arguments;
|
|
1483
|
+
const fnName = node.expression.getText();
|
|
1484
1484
|
if (fnArguments.length === 0) return box.array([], node, []);
|
|
1485
1485
|
return box.array(fnArguments.map((argument, index) => {
|
|
1486
1486
|
const argNode = unwrapExpression(argument);
|
|
@@ -1578,7 +1578,7 @@ const collectImports = (sourceFile) => {
|
|
|
1578
1578
|
if (!node) return;
|
|
1579
1579
|
const expression = unwrapExpression(node);
|
|
1580
1580
|
if (Node.isCallExpression(expression)) {
|
|
1581
|
-
const callee = unwrapExpression(expression.
|
|
1581
|
+
const callee = unwrapExpression(expression.expression);
|
|
1582
1582
|
if (!Node.isIdentifier(callee)) return;
|
|
1583
1583
|
const calleeName = callee.getText();
|
|
1584
1584
|
if (/requirejsxdevruntime/i.test(calleeName)) return "react/jsx-dev-runtime";
|
|
@@ -1587,70 +1587,70 @@ const collectImports = (sourceFile) => {
|
|
|
1587
1587
|
}
|
|
1588
1588
|
};
|
|
1589
1589
|
const bundledCandidates = mayHoldBundledOutput(sourceFile.getFullText());
|
|
1590
|
-
(bundledCandidates ?
|
|
1591
|
-
const callee = unwrapExpression(callExpression
|
|
1590
|
+
(bundledCandidates ? getDescendantsOfKind(sourceFile, SyntaxKind.CallExpression) : []).forEach((callExpression) => {
|
|
1591
|
+
const callee = unwrapExpression(childOf(callExpression, "expression"));
|
|
1592
1592
|
if (!Node.isIdentifier(callee) || callee.getText() !== "parcelRegister") return;
|
|
1593
|
-
const [idArg, factoryArg] = callExpression
|
|
1593
|
+
const [idArg, factoryArg] = childOf(callExpression, "arguments") ?? [];
|
|
1594
1594
|
if (!Node.isStringLiteral(idArg)) return;
|
|
1595
1595
|
if (!Node.isArrowFunction(factoryArg) && !Node.isFunctionExpression(factoryArg)) return;
|
|
1596
|
-
const factoryText = factoryArg.
|
|
1597
|
-
if (factoryText.includes("\"Fragment\"") && factoryText.includes("\"jsx\"") && factoryText.includes("\"jsxs\"") && factoryText.includes("module.exports")) parcelRuntimeModuleIds.set(idArg
|
|
1596
|
+
const factoryText = factoryArg.body.getText();
|
|
1597
|
+
if (factoryText.includes("\"Fragment\"") && factoryText.includes("\"jsx\"") && factoryText.includes("\"jsxs\"") && factoryText.includes("module.exports")) parcelRuntimeModuleIds.set(stringLiteralValue(idArg), "react/jsx-runtime");
|
|
1598
1598
|
});
|
|
1599
|
-
|
|
1600
|
-
const mod =
|
|
1599
|
+
getImportDeclarations(sourceFile).forEach((declaration) => {
|
|
1600
|
+
const mod = getModuleSpecifierValue(declaration);
|
|
1601
1601
|
if (!mod) return;
|
|
1602
|
-
const defaultImport =
|
|
1602
|
+
const defaultImport = getDefaultImport(declaration);
|
|
1603
1603
|
if (defaultImport) defaultImports.set(defaultImport.getText(), mod);
|
|
1604
|
-
const namespaceImport =
|
|
1604
|
+
const namespaceImport = getNamespaceImport(declaration);
|
|
1605
1605
|
if (namespaceImport) namespace.set(namespaceImport.getText(), mod);
|
|
1606
|
-
|
|
1607
|
-
const importedName = specifier
|
|
1608
|
-
const alias =
|
|
1609
|
-
named.set(alias, {
|
|
1610
|
-
importedName,
|
|
1606
|
+
getNamedImports(declaration).forEach((specifier) => {
|
|
1607
|
+
const importedName = nameNodeOf(specifier)?.getText();
|
|
1608
|
+
const alias = getAliasNode(specifier)?.getText() || importedName;
|
|
1609
|
+
named.set(alias ?? "", {
|
|
1610
|
+
importedName: importedName ?? "",
|
|
1611
1611
|
mod
|
|
1612
1612
|
});
|
|
1613
1613
|
});
|
|
1614
1614
|
});
|
|
1615
|
-
|
|
1616
|
-
if (!Node.isIdentifier(declaration
|
|
1617
|
-
const variableName =
|
|
1618
|
-
const initializer = declaration
|
|
1619
|
-
const bundledImport = resolveBundledHelperImport(variableName, initializer);
|
|
1620
|
-
if (bundledImport) bundledNamed.set(variableName, bundledImport);
|
|
1621
|
-
let mod = getBundledRuntimeModFromName(variableName) ?? resolveBundledNamespaceMod(initializer);
|
|
1615
|
+
getVariableDeclarations(sourceFile).forEach((declaration) => {
|
|
1616
|
+
if (!Node.isIdentifier(nameNodeOf(declaration))) return;
|
|
1617
|
+
const variableName = getName(declaration);
|
|
1618
|
+
const initializer = childOf(declaration, "initializer");
|
|
1619
|
+
const bundledImport = resolveBundledHelperImport(variableName ?? "", initializer);
|
|
1620
|
+
if (bundledImport) bundledNamed.set(variableName ?? "", bundledImport);
|
|
1621
|
+
let mod = getBundledRuntimeModFromName(variableName ?? "") ?? resolveBundledNamespaceMod(initializer);
|
|
1622
1622
|
if (!mod && initializer && Node.isCallExpression(initializer)) {
|
|
1623
|
-
const callee = unwrapExpression(initializer.
|
|
1624
|
-
const [firstArg] = initializer.
|
|
1625
|
-
if (Node.isIdentifier(callee) && callee.getText() === "parcelRequire" && Node.isStringLiteral(firstArg)) mod = parcelRuntimeModuleIds.get(firstArg
|
|
1623
|
+
const callee = unwrapExpression(initializer.expression);
|
|
1624
|
+
const [firstArg] = initializer.arguments;
|
|
1625
|
+
if (Node.isIdentifier(callee) && callee.getText() === "parcelRequire" && Node.isStringLiteral(firstArg)) mod = parcelRuntimeModuleIds.get(stringLiteralValue(firstArg));
|
|
1626
1626
|
}
|
|
1627
1627
|
if (!mod && initializer && Node.isObjectLiteralExpression(initializer)) {
|
|
1628
|
-
const propertyNames = new Set(initializer.
|
|
1629
|
-
if (Node.isPropertyAssignment(property)) return
|
|
1628
|
+
const propertyNames = new Set(initializer.properties.map((property) => {
|
|
1629
|
+
if (Node.isPropertyAssignment(property)) return getName(property);
|
|
1630
1630
|
}).filter(Boolean));
|
|
1631
1631
|
if (propertyNames.has("jsx") && propertyNames.has("Fragment")) mod = "preact/jsx-runtime";
|
|
1632
1632
|
}
|
|
1633
1633
|
if (!mod) return;
|
|
1634
|
-
bundledNamespace.set(variableName, mod);
|
|
1634
|
+
bundledNamespace.set(variableName ?? "", mod);
|
|
1635
1635
|
});
|
|
1636
|
-
(bundledCandidates ?
|
|
1637
|
-
const bundledImport = resolveBundledHelperImport(
|
|
1638
|
-
if (!bundledImport || !
|
|
1639
|
-
bundledNamed.set(
|
|
1636
|
+
(bundledCandidates ? getDescendantsOfKind(sourceFile, SyntaxKind.FunctionDeclaration) : []).forEach((declaration) => {
|
|
1637
|
+
const bundledImport = resolveBundledHelperImport(getName(declaration) ?? "", declaration);
|
|
1638
|
+
if (!bundledImport || !getName(declaration)) return;
|
|
1639
|
+
bundledNamed.set(getName(declaration), bundledImport);
|
|
1640
1640
|
});
|
|
1641
1641
|
const resolveBundledAliasImport = (node) => {
|
|
1642
1642
|
if (!node) return;
|
|
1643
1643
|
const expression = unwrapExpression(node);
|
|
1644
1644
|
if (Node.isIdentifier(expression)) return bundledNamed.get(expression.getText());
|
|
1645
|
-
if (Node.isConditionalExpression(expression)) return resolveBundledAliasImport(expression.
|
|
1646
|
-
if (Node.isBinaryExpression(expression) && expression.
|
|
1645
|
+
if (Node.isConditionalExpression(expression)) return resolveBundledAliasImport(expression.whenTrue) ?? resolveBundledAliasImport(expression.whenFalse);
|
|
1646
|
+
if (Node.isBinaryExpression(expression) && expression.operatorToken.kind === SyntaxKind.CommaToken) return resolveBundledAliasImport(expression.right);
|
|
1647
1647
|
};
|
|
1648
|
-
|
|
1649
|
-
if (!Node.isIdentifier(declaration
|
|
1650
|
-
if (bundledNamed.has(
|
|
1651
|
-
const bundledAlias = resolveBundledAliasImport(declaration
|
|
1648
|
+
getVariableDeclarations(sourceFile).forEach((declaration) => {
|
|
1649
|
+
if (!Node.isIdentifier(nameNodeOf(declaration))) return;
|
|
1650
|
+
if (bundledNamed.has(getName(declaration) ?? "")) return;
|
|
1651
|
+
const bundledAlias = resolveBundledAliasImport(childOf(declaration, "initializer"));
|
|
1652
1652
|
if (!bundledAlias) return;
|
|
1653
|
-
bundledNamed.set(
|
|
1653
|
+
bundledNamed.set(getName(declaration) ?? "", bundledAlias);
|
|
1654
1654
|
});
|
|
1655
1655
|
return {
|
|
1656
1656
|
named,
|
|
@@ -1668,7 +1668,7 @@ const normalizeTagName = (text) => {
|
|
|
1668
1668
|
const getTagName = (node) => {
|
|
1669
1669
|
if (!node) return;
|
|
1670
1670
|
const expression = unwrapExpression(node);
|
|
1671
|
-
if (Node.isStringLiteral(expression) || Node.isNoSubstitutionTemplateLiteral(expression)) return expression
|
|
1671
|
+
if (Node.isStringLiteral(expression) || Node.isNoSubstitutionTemplateLiteral(expression)) return literalValueOf(expression);
|
|
1672
1672
|
if (Node.isIdentifier(expression) || Node.isPropertyAccessExpression(expression) || Node.isElementAccessExpression(expression)) return normalizeTagName(expression.getText());
|
|
1673
1673
|
};
|
|
1674
1674
|
const isQwikMod = (mod) => mod.includes("qwik");
|
|
@@ -1748,11 +1748,11 @@ const runtimeProfiles = [
|
|
|
1748
1748
|
*/
|
|
1749
1749
|
const findLocalDeclaration = (identifier) => {
|
|
1750
1750
|
const name = identifier.getText();
|
|
1751
|
-
for (let scope = identifier.
|
|
1752
|
-
if (!Node.
|
|
1753
|
-
const variable =
|
|
1751
|
+
for (let scope = identifier.parent; scope; scope = scope.parent) {
|
|
1752
|
+
if (!Node.isStatement(scope)) continue;
|
|
1753
|
+
const variable = getVariableDeclaration(scope, name);
|
|
1754
1754
|
if (variable) return variable;
|
|
1755
|
-
const fn = scope.
|
|
1755
|
+
const fn = (childOf(scope, "statements") ?? []).find((statement) => is.isFunctionDeclaration(statement) && getName(statement) === name);
|
|
1756
1756
|
if (fn) return fn;
|
|
1757
1757
|
}
|
|
1758
1758
|
};
|
|
@@ -1760,7 +1760,7 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1760
1760
|
const imports = collectImports(sourceFile);
|
|
1761
1761
|
const normalizeCallee = (node) => {
|
|
1762
1762
|
const expression = unwrapExpression(node);
|
|
1763
|
-
if (Node.isBinaryExpression(expression) && expression.
|
|
1763
|
+
if (Node.isBinaryExpression(expression) && expression.operatorToken.kind === SyntaxKind.CommaToken) return normalizeCallee(expression.right);
|
|
1764
1764
|
return expression;
|
|
1765
1765
|
};
|
|
1766
1766
|
const localDefinitionCache = /* @__PURE__ */ new Map();
|
|
@@ -1779,13 +1779,13 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1779
1779
|
};
|
|
1780
1780
|
return resolveIdentifierDefinition(expression);
|
|
1781
1781
|
}
|
|
1782
|
-
if (Node.isConditionalExpression(expression)) return resolveLocalAlias(expression.
|
|
1783
|
-
if (Node.isBinaryExpression(expression) && expression.
|
|
1782
|
+
if (Node.isConditionalExpression(expression)) return resolveLocalAlias(expression.whenTrue) ?? resolveLocalAlias(expression.whenFalse);
|
|
1783
|
+
if (Node.isBinaryExpression(expression) && expression.operatorToken.kind === SyntaxKind.CommaToken) return resolveLocalAlias(expression.right);
|
|
1784
1784
|
};
|
|
1785
1785
|
const declaration = findLocalDeclaration(identifier);
|
|
1786
1786
|
if (!declaration) return;
|
|
1787
1787
|
if (Node.isFunctionDeclaration(declaration)) {
|
|
1788
|
-
const imported = resolveBundledHelperImport(
|
|
1788
|
+
const imported = resolveBundledHelperImport(getName(declaration) ?? name, declaration);
|
|
1789
1789
|
if (!imported) return;
|
|
1790
1790
|
const resolved = {
|
|
1791
1791
|
mod: imported.mod,
|
|
@@ -1794,11 +1794,11 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1794
1794
|
localDefinitionCache.set(name, resolved);
|
|
1795
1795
|
return resolved;
|
|
1796
1796
|
}
|
|
1797
|
-
const directImport = resolveBundledHelperImport(
|
|
1797
|
+
const directImport = resolveBundledHelperImport(getName(declaration) ?? "", childOf(declaration, "initializer"));
|
|
1798
1798
|
const aliasImport = directImport ? {
|
|
1799
1799
|
mod: directImport.mod,
|
|
1800
1800
|
importedName: directImport.importedName
|
|
1801
|
-
} : resolveLocalAlias(declaration
|
|
1801
|
+
} : resolveLocalAlias(childOf(declaration, "initializer"));
|
|
1802
1802
|
if (!aliasImport) return;
|
|
1803
1803
|
localDefinitionCache.set(name, aliasImport);
|
|
1804
1804
|
return aliasImport;
|
|
@@ -1814,36 +1814,40 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1814
1814
|
return resolveIdentifierDefinition(expression);
|
|
1815
1815
|
}
|
|
1816
1816
|
if (Node.isPropertyAccessExpression(expression)) {
|
|
1817
|
-
const target = normalizeCallee(expression.
|
|
1817
|
+
const target = normalizeCallee(expression.expression);
|
|
1818
1818
|
if (!Node.isIdentifier(target)) return;
|
|
1819
1819
|
const targetName = target.getText();
|
|
1820
1820
|
const mod = imports.default.get(targetName) ?? imports.namespace.get(targetName) ?? imports.bundledNamespace.get(targetName);
|
|
1821
1821
|
if (!mod) return;
|
|
1822
1822
|
return {
|
|
1823
1823
|
mod,
|
|
1824
|
-
importedName:
|
|
1824
|
+
importedName: getName(expression)
|
|
1825
1825
|
};
|
|
1826
1826
|
}
|
|
1827
1827
|
};
|
|
1828
1828
|
const isMergePropsCall = (node) => {
|
|
1829
1829
|
if (!Node.isCallExpression(node)) return false;
|
|
1830
|
-
const resolved = resolveCallee(node.
|
|
1830
|
+
const resolved = resolveCallee(node.expression);
|
|
1831
1831
|
if (!resolved) return false;
|
|
1832
1832
|
return resolved.importedName === "mergeProps" && (solidMods.has(resolved.mod) || vueMods.has(resolved.mod));
|
|
1833
1833
|
};
|
|
1834
1834
|
const getCallInfo = (node) => {
|
|
1835
|
-
const resolved = resolveCallee(node.
|
|
1835
|
+
const resolved = resolveCallee(node.expression);
|
|
1836
1836
|
if (!resolved) return;
|
|
1837
|
-
const args = node.
|
|
1837
|
+
const args = node.arguments.map((arg) => unwrapExpression(arg));
|
|
1838
1838
|
const tagName = getTagName(args[0]);
|
|
1839
1839
|
if (!tagName) return;
|
|
1840
1840
|
const baseInfo = {
|
|
1841
1841
|
tagName,
|
|
1842
|
-
isFactory: tagName.includes(".")
|
|
1842
|
+
isFactory: String(tagName).includes(".")
|
|
1843
1843
|
};
|
|
1844
|
-
for (const profile of runtimeProfiles) if (profile.matches(
|
|
1844
|
+
for (const profile of runtimeProfiles) if (profile.matches({
|
|
1845
|
+
...resolved,
|
|
1846
|
+
importedName: resolved.importedName ?? ""
|
|
1847
|
+
})) return {
|
|
1845
1848
|
framework: profile.framework,
|
|
1846
1849
|
...baseInfo,
|
|
1850
|
+
tagName: String(baseInfo.tagName),
|
|
1847
1851
|
propNodes: profile.getPropNodes(args)
|
|
1848
1852
|
};
|
|
1849
1853
|
};
|
|
@@ -1855,18 +1859,18 @@ const createCompiledJsxContext = (sourceFile) => {
|
|
|
1855
1859
|
//#endregion
|
|
1856
1860
|
//#region src/jsx-attribute.ts
|
|
1857
1861
|
const extractJsxAttribute = (jsxAttribute, ctx) => {
|
|
1858
|
-
const initializer = jsxAttribute.
|
|
1862
|
+
const initializer = jsxAttribute.initializer;
|
|
1859
1863
|
const stack = [jsxAttribute, initializer];
|
|
1860
1864
|
if (!initializer) {
|
|
1861
|
-
const nameNode = jsxAttribute.
|
|
1865
|
+
const nameNode = jsxAttribute.name;
|
|
1862
1866
|
return box.emptyInitializer(nameNode, stack);
|
|
1863
1867
|
}
|
|
1864
1868
|
if (Node.isStringLiteral(initializer)) {
|
|
1865
|
-
const literalText =
|
|
1869
|
+
const literalText = getLiteralText(initializer);
|
|
1866
1870
|
return box.literal(trimWhitespace(literalText), initializer, stack);
|
|
1867
1871
|
}
|
|
1868
1872
|
if (Node.isJsxExpression(initializer)) {
|
|
1869
|
-
const expr = initializer.
|
|
1873
|
+
const expr = initializer.expression;
|
|
1870
1874
|
if (!expr) return;
|
|
1871
1875
|
const expression = unwrapExpression(expr);
|
|
1872
1876
|
if (!expression) return;
|
|
@@ -1878,7 +1882,7 @@ const extractJsxAttribute = (jsxAttribute, ctx) => {
|
|
|
1878
1882
|
//#endregion
|
|
1879
1883
|
//#region src/jsx-spread-attribute.ts
|
|
1880
1884
|
const extractJsxSpreadAttributeValues = (node, ctx, matchProp) => {
|
|
1881
|
-
return maybeBoxNode(unwrapExpression(node.
|
|
1885
|
+
return maybeBoxNode(unwrapExpression(node.expression), [], ctx, matchProp);
|
|
1882
1886
|
};
|
|
1883
1887
|
//#endregion
|
|
1884
1888
|
//#region src/object-like-to-map.ts
|
|
@@ -1952,7 +1956,7 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
1952
1956
|
return;
|
|
1953
1957
|
}
|
|
1954
1958
|
if (Node.isCallExpression(expression) && compiledJsx.isMergePropsCall(expression)) {
|
|
1955
|
-
expression.
|
|
1959
|
+
expression.arguments.forEach((arg) => {
|
|
1956
1960
|
processCompiledPropSource(componentNode, component, boxByProp, arg, matchProp);
|
|
1957
1961
|
});
|
|
1958
1962
|
return;
|
|
@@ -1961,11 +1965,8 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
1961
1965
|
if (!maybeValue) return;
|
|
1962
1966
|
processComponentBoxNode(component, boxByProp, expression, maybeValue, matchProp, true);
|
|
1963
1967
|
};
|
|
1964
|
-
|
|
1965
|
-
if (isImportOrExport(node))
|
|
1966
|
-
traversal.skip();
|
|
1967
|
-
return;
|
|
1968
|
-
}
|
|
1968
|
+
forEachDescendant(ast, (node) => {
|
|
1969
|
+
if (isImportOrExport(node)) return SKIP;
|
|
1969
1970
|
if (components) {
|
|
1970
1971
|
if (Node.isJsxOpeningElement(node) || Node.isJsxSelfClosingElement(node)) {
|
|
1971
1972
|
const componentNode = node;
|
|
@@ -1979,7 +1980,7 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
1979
1980
|
ensureComponent(componentNode, componentName);
|
|
1980
1981
|
}
|
|
1981
1982
|
if (Node.isJsxSpreadAttribute(node)) {
|
|
1982
|
-
const componentNode =
|
|
1983
|
+
const componentNode = getFirstAncestor(node, isJsxElement);
|
|
1983
1984
|
const component = componentByNode.get(componentNode);
|
|
1984
1985
|
if (!componentNode || !component) return;
|
|
1985
1986
|
const componentName = getComponentName(componentNode);
|
|
@@ -1996,12 +1997,12 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
1996
1997
|
return;
|
|
1997
1998
|
}
|
|
1998
1999
|
if (Node.isJsxAttribute(node)) {
|
|
1999
|
-
const componentNode =
|
|
2000
|
+
const componentNode = getFirstAncestor(node, isJsxElement);
|
|
2000
2001
|
const component = componentByNode.get(componentNode);
|
|
2001
2002
|
if (!componentNode || !component) return;
|
|
2002
2003
|
const componentName = getComponentName(componentNode);
|
|
2003
2004
|
const boxByProp = byName.get(componentName).nodesByProp;
|
|
2004
|
-
const propName = node.
|
|
2005
|
+
const propName = node.name.getText();
|
|
2005
2006
|
if (!components.matchProp({
|
|
2006
2007
|
tagNode: componentNode,
|
|
2007
2008
|
tagName: componentName,
|
|
@@ -2035,8 +2036,8 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
2035
2036
|
}
|
|
2036
2037
|
}
|
|
2037
2038
|
if (functions && Node.isCallExpression(node)) {
|
|
2038
|
-
const expr = node.
|
|
2039
|
-
const fnName = Node.isCallExpression(expr) ? expr.
|
|
2039
|
+
const expr = node.expression;
|
|
2040
|
+
const fnName = Node.isCallExpression(expr) ? expr.expression.getText() : expr.getText();
|
|
2040
2041
|
if (!functions.matchFn({
|
|
2041
2042
|
fnNode: node,
|
|
2042
2043
|
fnName
|
|
@@ -2100,12 +2101,12 @@ const extract = ({ ast, ...ctx }) => {
|
|
|
2100
2101
|
//#region src/jsx-element-props.ts
|
|
2101
2102
|
const isObjectLike = (node) => box.isObject(node) || box.isMap(node);
|
|
2102
2103
|
const extractJsxElementProps = (node, ctx) => {
|
|
2103
|
-
const tagName = node.
|
|
2104
|
-
const jsxAttributes = node
|
|
2104
|
+
const tagName = node.tagName.getText();
|
|
2105
|
+
const jsxAttributes = childOf(node, "attributes")?.properties ?? [];
|
|
2105
2106
|
const props = /* @__PURE__ */ new Map();
|
|
2106
2107
|
jsxAttributes.forEach((attrNode) => {
|
|
2107
2108
|
if (Node.isJsxAttribute(attrNode)) {
|
|
2108
|
-
const nameNode = attrNode.
|
|
2109
|
+
const nameNode = attrNode.name;
|
|
2109
2110
|
const maybeValue = extractJsxAttribute(attrNode, ctx);
|
|
2110
2111
|
if (!maybeValue) return;
|
|
2111
2112
|
props.set(nameNode.getText(), maybeValue);
|