@bamboocss/extractor 1.28.1 → 1.29.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 +22 -10
- package/dist/index.mjs +22 -10
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -756,24 +756,23 @@ function maybeBoxNode(node, stack, ctx, matchProp) {
|
|
|
756
756
|
if (ctx.tokens) {
|
|
757
757
|
const expr = node.getExpression();
|
|
758
758
|
let fnName = "";
|
|
759
|
-
let
|
|
759
|
+
let isValueMethod = false;
|
|
760
760
|
if (ts_morph.Node.isIdentifier(expr)) fnName = expr.getText();
|
|
761
761
|
else if (ts_morph.Node.isPropertyAccessExpression(expr)) {
|
|
762
|
-
const exprName = expr.getExpression();
|
|
763
762
|
const propertyName = expr.getName();
|
|
764
|
-
if (
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
}
|
|
763
|
+
if (propertyName === "var" || propertyName === "value") {
|
|
764
|
+
isValueMethod = propertyName === "value";
|
|
765
|
+
fnName = expr.getExpression().getText();
|
|
766
|
+
} else fnName = expr.getText();
|
|
768
767
|
}
|
|
769
768
|
if (ctx.tokens.isTokenFn ? ctx.tokens.isTokenFn(fnName) : fnName === "token") {
|
|
770
769
|
const args = node.getArguments();
|
|
771
770
|
const tokenPathArg = args[0];
|
|
772
|
-
|
|
773
|
-
|
|
771
|
+
const tokenPath = tokenPathArg ? literalStringOf(tokenPathArg, stack, ctx) : void 0;
|
|
772
|
+
if (tokenPath !== void 0) {
|
|
774
773
|
const fallbackArg = args[1];
|
|
775
|
-
const fallbackValue = fallbackArg
|
|
776
|
-
const resolvedValue =
|
|
774
|
+
const fallbackValue = fallbackArg ? literalStringOf(fallbackArg, stack, ctx) : void 0;
|
|
775
|
+
const resolvedValue = isValueMethod ? ctx.tokens.view.get(tokenPath, fallbackValue) : ctx.tokens.view.getVar(tokenPath, fallbackValue);
|
|
777
776
|
if (resolvedValue) return cache(box.literal(resolvedValue, node, stack));
|
|
778
777
|
}
|
|
779
778
|
}
|
|
@@ -800,6 +799,19 @@ function maybeBoxNode(node, stack, ctx, matchProp) {
|
|
|
800
799
|
if (isOperationSyntax(operatorKind)) return cache(box.literal(safeEvaluateNode(node, stack, ctx), node, stack));
|
|
801
800
|
}
|
|
802
801
|
}
|
|
802
|
+
/**
|
|
803
|
+
* An argument's value, when it resolves to a string.
|
|
804
|
+
*
|
|
805
|
+
* A string literal is the common case and answered without recursing. Anything else goes back
|
|
806
|
+
* through `maybeBoxNode`, which is what follows a constant, a template literal or an imported
|
|
807
|
+
* value to its literal — the same resolution every other extracted value already gets.
|
|
808
|
+
* Returning `undefined` leaves the call unresolved, exactly as before.
|
|
809
|
+
*/
|
|
810
|
+
function literalStringOf(node, stack, ctx) {
|
|
811
|
+
if (ts_morph.Node.isStringLiteral(node)) return node.getLiteralValue();
|
|
812
|
+
const resolved = onlyStringLiteral(maybeBoxNode(node, stack, ctx));
|
|
813
|
+
return resolved && typeof resolved.value === "string" ? resolved.value : void 0;
|
|
814
|
+
}
|
|
803
815
|
const onlyStringLiteral = (boxNode) => {
|
|
804
816
|
if (!boxNode) return;
|
|
805
817
|
if (isBoxNode(boxNode) && box.isLiteral(boxNode) && typeof boxNode.value === "string") return boxNode;
|
package/dist/index.mjs
CHANGED
|
@@ -755,24 +755,23 @@ function maybeBoxNode(node, stack, ctx, matchProp) {
|
|
|
755
755
|
if (ctx.tokens) {
|
|
756
756
|
const expr = node.getExpression();
|
|
757
757
|
let fnName = "";
|
|
758
|
-
let
|
|
758
|
+
let isValueMethod = false;
|
|
759
759
|
if (Node.isIdentifier(expr)) fnName = expr.getText();
|
|
760
760
|
else if (Node.isPropertyAccessExpression(expr)) {
|
|
761
|
-
const exprName = expr.getExpression();
|
|
762
761
|
const propertyName = expr.getName();
|
|
763
|
-
if (
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
}
|
|
762
|
+
if (propertyName === "var" || propertyName === "value") {
|
|
763
|
+
isValueMethod = propertyName === "value";
|
|
764
|
+
fnName = expr.getExpression().getText();
|
|
765
|
+
} else fnName = expr.getText();
|
|
767
766
|
}
|
|
768
767
|
if (ctx.tokens.isTokenFn ? ctx.tokens.isTokenFn(fnName) : fnName === "token") {
|
|
769
768
|
const args = node.getArguments();
|
|
770
769
|
const tokenPathArg = args[0];
|
|
771
|
-
|
|
772
|
-
|
|
770
|
+
const tokenPath = tokenPathArg ? literalStringOf(tokenPathArg, stack, ctx) : void 0;
|
|
771
|
+
if (tokenPath !== void 0) {
|
|
773
772
|
const fallbackArg = args[1];
|
|
774
|
-
const fallbackValue = fallbackArg
|
|
775
|
-
const resolvedValue =
|
|
773
|
+
const fallbackValue = fallbackArg ? literalStringOf(fallbackArg, stack, ctx) : void 0;
|
|
774
|
+
const resolvedValue = isValueMethod ? ctx.tokens.view.get(tokenPath, fallbackValue) : ctx.tokens.view.getVar(tokenPath, fallbackValue);
|
|
776
775
|
if (resolvedValue) return cache(box.literal(resolvedValue, node, stack));
|
|
777
776
|
}
|
|
778
777
|
}
|
|
@@ -799,6 +798,19 @@ function maybeBoxNode(node, stack, ctx, matchProp) {
|
|
|
799
798
|
if (isOperationSyntax(operatorKind)) return cache(box.literal(safeEvaluateNode(node, stack, ctx), node, stack));
|
|
800
799
|
}
|
|
801
800
|
}
|
|
801
|
+
/**
|
|
802
|
+
* An argument's value, when it resolves to a string.
|
|
803
|
+
*
|
|
804
|
+
* A string literal is the common case and answered without recursing. Anything else goes back
|
|
805
|
+
* through `maybeBoxNode`, which is what follows a constant, a template literal or an imported
|
|
806
|
+
* value to its literal — the same resolution every other extracted value already gets.
|
|
807
|
+
* Returning `undefined` leaves the call unresolved, exactly as before.
|
|
808
|
+
*/
|
|
809
|
+
function literalStringOf(node, stack, ctx) {
|
|
810
|
+
if (Node.isStringLiteral(node)) return node.getLiteralValue();
|
|
811
|
+
const resolved = onlyStringLiteral(maybeBoxNode(node, stack, ctx));
|
|
812
|
+
return resolved && typeof resolved.value === "string" ? resolved.value : void 0;
|
|
813
|
+
}
|
|
802
814
|
const onlyStringLiteral = (boxNode) => {
|
|
803
815
|
if (!boxNode) return;
|
|
804
816
|
if (isBoxNode(boxNode) && box.isLiteral(boxNode) && typeof boxNode.value === "string") return boxNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/extractor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.29.0",
|
|
4
4
|
"description": "The css extractor for css bamboo",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"ts-evaluator": "2.0.0",
|
|
37
37
|
"ts-morph": "28.0.0",
|
|
38
|
-
"@bamboocss/shared": "1.
|
|
38
|
+
"@bamboocss/shared": "1.29.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsdown src/index.ts --format=cjs,esm --shims --dts",
|