@bamboocss/extractor 1.28.1 → 1.30.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 -16
- package/dist/index.mjs +22 -16
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -756,24 +756,17 @@ 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
|
-
else if (ts_morph.Node.isPropertyAccessExpression(expr)) {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
fnName = exprName.getText();
|
|
766
|
-
isVarMethod = propertyName === "var";
|
|
767
|
-
}
|
|
768
|
-
}
|
|
761
|
+
else if (ts_morph.Node.isPropertyAccessExpression(expr)) if (expr.getName() === "value") {
|
|
762
|
+
isValueMethod = true;
|
|
763
|
+
fnName = expr.getExpression().getText();
|
|
764
|
+
} else fnName = expr.getText();
|
|
769
765
|
if (ctx.tokens.isTokenFn ? ctx.tokens.isTokenFn(fnName) : fnName === "token") {
|
|
770
|
-
const
|
|
771
|
-
const
|
|
772
|
-
if (
|
|
773
|
-
const
|
|
774
|
-
const fallbackArg = args[1];
|
|
775
|
-
const fallbackValue = fallbackArg && ts_morph.Node.isStringLiteral(fallbackArg) ? fallbackArg.getLiteralValue() : void 0;
|
|
776
|
-
const resolvedValue = isVarMethod ? ctx.tokens.view.getVar(tokenPath, fallbackValue) : ctx.tokens.view.get(tokenPath, fallbackValue);
|
|
766
|
+
const tokenPathArg = node.getArguments()[0];
|
|
767
|
+
const tokenPath = tokenPathArg ? literalStringOf(tokenPathArg, stack, ctx) : void 0;
|
|
768
|
+
if (tokenPath !== void 0) {
|
|
769
|
+
const resolvedValue = isValueMethod ? ctx.tokens.view.get(tokenPath) : ctx.tokens.view.getVar(tokenPath);
|
|
777
770
|
if (resolvedValue) return cache(box.literal(resolvedValue, node, stack));
|
|
778
771
|
}
|
|
779
772
|
}
|
|
@@ -800,6 +793,19 @@ function maybeBoxNode(node, stack, ctx, matchProp) {
|
|
|
800
793
|
if (isOperationSyntax(operatorKind)) return cache(box.literal(safeEvaluateNode(node, stack, ctx), node, stack));
|
|
801
794
|
}
|
|
802
795
|
}
|
|
796
|
+
/**
|
|
797
|
+
* An argument's value, when it resolves to a string.
|
|
798
|
+
*
|
|
799
|
+
* A string literal is the common case and answered without recursing. Anything else goes back
|
|
800
|
+
* through `maybeBoxNode`, which is what follows a constant, a template literal or an imported
|
|
801
|
+
* value to its literal — the same resolution every other extracted value already gets.
|
|
802
|
+
* Returning `undefined` leaves the call unresolved, exactly as before.
|
|
803
|
+
*/
|
|
804
|
+
function literalStringOf(node, stack, ctx) {
|
|
805
|
+
if (ts_morph.Node.isStringLiteral(node)) return node.getLiteralValue();
|
|
806
|
+
const resolved = onlyStringLiteral(maybeBoxNode(node, stack, ctx));
|
|
807
|
+
return resolved && typeof resolved.value === "string" ? resolved.value : void 0;
|
|
808
|
+
}
|
|
803
809
|
const onlyStringLiteral = (boxNode) => {
|
|
804
810
|
if (!boxNode) return;
|
|
805
811
|
if (isBoxNode(boxNode) && box.isLiteral(boxNode) && typeof boxNode.value === "string") return boxNode;
|
package/dist/index.mjs
CHANGED
|
@@ -755,24 +755,17 @@ 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
|
-
else if (Node.isPropertyAccessExpression(expr)) {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
fnName = exprName.getText();
|
|
765
|
-
isVarMethod = propertyName === "var";
|
|
766
|
-
}
|
|
767
|
-
}
|
|
760
|
+
else if (Node.isPropertyAccessExpression(expr)) if (expr.getName() === "value") {
|
|
761
|
+
isValueMethod = true;
|
|
762
|
+
fnName = expr.getExpression().getText();
|
|
763
|
+
} else fnName = expr.getText();
|
|
768
764
|
if (ctx.tokens.isTokenFn ? ctx.tokens.isTokenFn(fnName) : fnName === "token") {
|
|
769
|
-
const
|
|
770
|
-
const
|
|
771
|
-
if (
|
|
772
|
-
const
|
|
773
|
-
const fallbackArg = args[1];
|
|
774
|
-
const fallbackValue = fallbackArg && Node.isStringLiteral(fallbackArg) ? fallbackArg.getLiteralValue() : void 0;
|
|
775
|
-
const resolvedValue = isVarMethod ? ctx.tokens.view.getVar(tokenPath, fallbackValue) : ctx.tokens.view.get(tokenPath, fallbackValue);
|
|
765
|
+
const tokenPathArg = node.getArguments()[0];
|
|
766
|
+
const tokenPath = tokenPathArg ? literalStringOf(tokenPathArg, stack, ctx) : void 0;
|
|
767
|
+
if (tokenPath !== void 0) {
|
|
768
|
+
const resolvedValue = isValueMethod ? ctx.tokens.view.get(tokenPath) : ctx.tokens.view.getVar(tokenPath);
|
|
776
769
|
if (resolvedValue) return cache(box.literal(resolvedValue, node, stack));
|
|
777
770
|
}
|
|
778
771
|
}
|
|
@@ -799,6 +792,19 @@ function maybeBoxNode(node, stack, ctx, matchProp) {
|
|
|
799
792
|
if (isOperationSyntax(operatorKind)) return cache(box.literal(safeEvaluateNode(node, stack, ctx), node, stack));
|
|
800
793
|
}
|
|
801
794
|
}
|
|
795
|
+
/**
|
|
796
|
+
* An argument's value, when it resolves to a string.
|
|
797
|
+
*
|
|
798
|
+
* A string literal is the common case and answered without recursing. Anything else goes back
|
|
799
|
+
* through `maybeBoxNode`, which is what follows a constant, a template literal or an imported
|
|
800
|
+
* value to its literal — the same resolution every other extracted value already gets.
|
|
801
|
+
* Returning `undefined` leaves the call unresolved, exactly as before.
|
|
802
|
+
*/
|
|
803
|
+
function literalStringOf(node, stack, ctx) {
|
|
804
|
+
if (Node.isStringLiteral(node)) return node.getLiteralValue();
|
|
805
|
+
const resolved = onlyStringLiteral(maybeBoxNode(node, stack, ctx));
|
|
806
|
+
return resolved && typeof resolved.value === "string" ? resolved.value : void 0;
|
|
807
|
+
}
|
|
802
808
|
const onlyStringLiteral = (boxNode) => {
|
|
803
809
|
if (!boxNode) return;
|
|
804
810
|
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.30.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.30.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsdown src/index.ts --format=cjs,esm --shims --dts",
|