@plumeria/compiler 16.4.2 → 17.0.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.d.ts +1 -0
- package/dist/index.js +39 -103
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -138,7 +138,7 @@ function extractStylesFromExpression(expression, ctx) {
|
|
|
138
138
|
return results;
|
|
139
139
|
}
|
|
140
140
|
function compileCSS(options) {
|
|
141
|
-
const { include, exclude, cwd = process.cwd() } = options;
|
|
141
|
+
const { include, exclude, cwd = process.cwd(), styleProp = utils_1.DEFAULT_STYLE_PROP, } = options;
|
|
142
142
|
const allSheets = new Set();
|
|
143
143
|
const files = rs.globSync(include, {
|
|
144
144
|
cwd,
|
|
@@ -370,7 +370,6 @@ function compileCSS(options) {
|
|
|
370
370
|
}
|
|
371
371
|
});
|
|
372
372
|
const conditionals = [];
|
|
373
|
-
let groupIdCounter = 0;
|
|
374
373
|
let baseStyle = {};
|
|
375
374
|
const resolveStyleObject = (expr) => {
|
|
376
375
|
if (utils_1.t.isObjectExpression(expr)) {
|
|
@@ -378,9 +377,18 @@ function compileCSS(options) {
|
|
|
378
377
|
}
|
|
379
378
|
else if (utils_1.t.isMemberExpression(expr) &&
|
|
380
379
|
utils_1.t.isIdentifier(expr.object) &&
|
|
381
|
-
utils_1.t.isIdentifier(expr.property)) {
|
|
380
|
+
(utils_1.t.isIdentifier(expr.property) || expr.property.type === 'Computed')) {
|
|
382
381
|
const varName = expr.object.value;
|
|
383
|
-
|
|
382
|
+
let propName;
|
|
383
|
+
if (expr.property.type === 'Computed') {
|
|
384
|
+
const keyExpr = expr.property.expression;
|
|
385
|
+
if (!utils_1.t.isStringLiteral(keyExpr))
|
|
386
|
+
return null;
|
|
387
|
+
propName = keyExpr.value;
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
propName = expr.property.value;
|
|
391
|
+
}
|
|
384
392
|
const styleInfo = ctx.localCreateStyles[varName];
|
|
385
393
|
if (styleInfo && styleInfo.type === 'create') {
|
|
386
394
|
const style = styleInfo.obj[propName];
|
|
@@ -562,81 +570,7 @@ function compileCSS(options) {
|
|
|
562
570
|
}
|
|
563
571
|
}
|
|
564
572
|
if (utils_1.t.isCallExpression(expr)) {
|
|
565
|
-
if (utils_1.t.
|
|
566
|
-
const varName = expr.callee.value;
|
|
567
|
-
const styleInfo = ctx.localCreateStyles[varName];
|
|
568
|
-
if (styleInfo && styleInfo.type === 'variant') {
|
|
569
|
-
const variantObj = styleInfo.obj;
|
|
570
|
-
const callArgs = expr.arguments;
|
|
571
|
-
if (callArgs.length === 1 && !callArgs[0].spread) {
|
|
572
|
-
const argExpr = callArgs[0].expression;
|
|
573
|
-
if (argExpr.type === 'ObjectExpression') {
|
|
574
|
-
for (const prop of argExpr.properties) {
|
|
575
|
-
let groupName;
|
|
576
|
-
let valExpr;
|
|
577
|
-
if (prop.type === 'KeyValueProperty' &&
|
|
578
|
-
prop.key.type === 'Identifier') {
|
|
579
|
-
groupName = prop.key.value;
|
|
580
|
-
valExpr = prop.value;
|
|
581
|
-
}
|
|
582
|
-
else if (prop.type === 'Identifier') {
|
|
583
|
-
groupName = prop.value;
|
|
584
|
-
valExpr = prop;
|
|
585
|
-
}
|
|
586
|
-
if (groupName && valExpr) {
|
|
587
|
-
const groupVariants = variantObj[groupName];
|
|
588
|
-
if (!groupVariants)
|
|
589
|
-
continue;
|
|
590
|
-
const currentGroupId = ++groupIdCounter;
|
|
591
|
-
const valSource = getSource(valExpr);
|
|
592
|
-
if (valExpr.type === 'StringLiteral') {
|
|
593
|
-
const groupVariantsAsObj = groupVariants;
|
|
594
|
-
if (groupVariantsAsObj[valExpr.value])
|
|
595
|
-
baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariantsAsObj[valExpr.value]);
|
|
596
|
-
continue;
|
|
597
|
-
}
|
|
598
|
-
Object.entries(groupVariants).forEach(([optionName, style]) => {
|
|
599
|
-
conditionals.push({
|
|
600
|
-
test: valExpr,
|
|
601
|
-
testLHS: valSource,
|
|
602
|
-
testString: `${valSource} === '${optionName}'`,
|
|
603
|
-
truthy: style,
|
|
604
|
-
falsy: {},
|
|
605
|
-
groupId: currentGroupId,
|
|
606
|
-
groupName,
|
|
607
|
-
valueName: optionName,
|
|
608
|
-
varName,
|
|
609
|
-
});
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
continue;
|
|
614
|
-
}
|
|
615
|
-
const argSource = getSource(argExpr);
|
|
616
|
-
if (utils_1.t.isStringLiteral(argExpr)) {
|
|
617
|
-
if (variantObj[argExpr.value])
|
|
618
|
-
baseStyle = (0, utils_1.deepMerge)(baseStyle, variantObj[argExpr.value]);
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
const currentGroupId = ++groupIdCounter;
|
|
622
|
-
Object.entries(variantObj).forEach(([key, style]) => {
|
|
623
|
-
conditionals.push({
|
|
624
|
-
test: argExpr,
|
|
625
|
-
testLHS: argSource,
|
|
626
|
-
testString: `${argSource} === '${key}'`,
|
|
627
|
-
truthy: style,
|
|
628
|
-
falsy: {},
|
|
629
|
-
groupId: currentGroupId,
|
|
630
|
-
groupName: undefined,
|
|
631
|
-
valueName: key,
|
|
632
|
-
varName,
|
|
633
|
-
});
|
|
634
|
-
});
|
|
635
|
-
continue;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
else if (utils_1.t.isMemberExpression(expr.callee)) {
|
|
573
|
+
if (utils_1.t.isMemberExpression(expr.callee)) {
|
|
640
574
|
const callee = expr.callee;
|
|
641
575
|
if (utils_1.t.isIdentifier(callee.object) &&
|
|
642
576
|
utils_1.t.isIdentifier(callee.property)) {
|
|
@@ -840,17 +774,6 @@ function compileCSS(options) {
|
|
|
840
774
|
};
|
|
841
775
|
}
|
|
842
776
|
}
|
|
843
|
-
else if (pName === 'variants') {
|
|
844
|
-
const obj = (0, utils_1.objectExpressionToObject)(arg, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable, ctx.mergedVariantsTable, resolveVariable);
|
|
845
|
-
if (obj) {
|
|
846
|
-
const { hashMap } = (0, utils_1.processVariants)(obj);
|
|
847
|
-
ctx.localCreateStyles[node.id.value] = {
|
|
848
|
-
type: 'variant',
|
|
849
|
-
obj,
|
|
850
|
-
hashMap,
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
777
|
else if (pName === 'createTheme') {
|
|
855
778
|
let selector = '';
|
|
856
779
|
const selectorExpr = init.arguments[0].expression;
|
|
@@ -914,23 +837,36 @@ function compileCSS(options) {
|
|
|
914
837
|
if (!processedNodes.has(path.node))
|
|
915
838
|
processCall(path.node);
|
|
916
839
|
},
|
|
917
|
-
|
|
840
|
+
JSXOpeningElement({ node }) {
|
|
918
841
|
if (node.name.type !== 'Identifier')
|
|
919
842
|
return;
|
|
920
|
-
const
|
|
921
|
-
if (
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
843
|
+
const tagName = node.name.value;
|
|
844
|
+
if (tagName[0] !== tagName[0].toUpperCase())
|
|
845
|
+
return;
|
|
846
|
+
node.attributes.forEach((attr) => {
|
|
847
|
+
if (attr.type !== 'JSXAttribute')
|
|
848
|
+
return;
|
|
849
|
+
if (attr.name.type !== 'Identifier')
|
|
850
|
+
return;
|
|
851
|
+
if (attr.name.value === styleProp)
|
|
852
|
+
return;
|
|
853
|
+
const value = attr.value;
|
|
854
|
+
if (!value || value.type !== 'JSXExpressionContainer')
|
|
855
|
+
return;
|
|
856
|
+
if (value.expression.type === 'JSXEmptyExpression')
|
|
857
|
+
return;
|
|
858
|
+
let expr = value.expression;
|
|
859
|
+
if (utils_1.t.isIdentifier(expr) && localStyleAliases[expr.value]) {
|
|
860
|
+
expr = localStyleAliases[expr.value];
|
|
931
861
|
}
|
|
862
|
+
extractStylesFromExpression(expr, ctx).forEach(processStyle);
|
|
863
|
+
});
|
|
864
|
+
},
|
|
865
|
+
JSXAttribute({ node }) {
|
|
866
|
+
if (node.name.type !== 'Identifier')
|
|
867
|
+
return;
|
|
868
|
+
if (node.name.value !== styleProp)
|
|
932
869
|
return;
|
|
933
|
-
}
|
|
934
870
|
if (!node.value || node.value.type !== 'JSXExpressionContainer')
|
|
935
871
|
return;
|
|
936
872
|
if (node.value.expression.type === 'JSXEmptyExpression')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"description": "Plumeria swc based compiler for statically extracting css",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist/"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@plumeria/utils": "^
|
|
24
|
+
"@plumeria/utils": "^17.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@rust-gear/glob": "1.1.0",
|