@plumeria/compiler 18.5.1 → 18.5.3
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.js +23 -33
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -91,11 +91,10 @@ const destructuredPropAliases = (fn) => {
|
|
|
91
91
|
if (pattern?.type !== 'ObjectPattern')
|
|
92
92
|
return aliases;
|
|
93
93
|
for (const item of pattern.properties ?? []) {
|
|
94
|
-
if (item.type !== 'KeyValuePatternProperty'
|
|
95
|
-
item.type !== 'AssignmentPatternProperty')
|
|
94
|
+
if (item.type !== 'KeyValuePatternProperty')
|
|
96
95
|
continue;
|
|
96
|
+
const local = unwrapPatternDefault(item.value);
|
|
97
97
|
const key = item.key;
|
|
98
|
-
const local = unwrapPatternDefault(item.value) ?? key;
|
|
99
98
|
if (!utils_1.t.isIdentifier(local))
|
|
100
99
|
continue;
|
|
101
100
|
if (!utils_1.t.isIdentifier(key) && !utils_1.t.isStringLiteral(key))
|
|
@@ -109,6 +108,11 @@ const destructuredPropAliases = (fn) => {
|
|
|
109
108
|
const sourceOf = (node, sourceBuffer, baseByteOffset) => sourceBuffer
|
|
110
109
|
.subarray(node.span.start - baseByteOffset, node.span.end - baseByteOffset)
|
|
111
110
|
.toString('utf-8');
|
|
111
|
+
const isNoOpStyle = (node) => utils_1.t.isNullLiteral(node) ||
|
|
112
|
+
(utils_1.t.isBooleanLiteral(node) && node.value === false) ||
|
|
113
|
+
(utils_1.t.isIdentifier(node) && node.value === 'undefined');
|
|
114
|
+
const propDefaultError = (source, fileName) => new Error(`[plumeria] A style prop default must be a defined style: "${source}". ` +
|
|
115
|
+
`Apply a conditional or dynamic style where the element is styled. (${fileName})`);
|
|
112
116
|
const spreadStyleError = (source, fileName) => new Error(`[plumeria] Spread elements in a style array are not supported: "...${source}". ` +
|
|
113
117
|
`List each style explicitly. (${fileName})`);
|
|
114
118
|
const isStaticArgValue = (node) => node.type === 'StringLiteral' ||
|
|
@@ -125,7 +129,6 @@ const dynamicTablesOf = (ctx) => ({
|
|
|
125
129
|
createHashTable: ctx.mergedCreateTable,
|
|
126
130
|
createStaticHashTable: ctx.mergedCreateStaticHashTable,
|
|
127
131
|
createStaticObjectTable: ctx.scannedTables.createStaticObjectTable,
|
|
128
|
-
variantsHashTable: ctx.mergedVariantsTable,
|
|
129
132
|
});
|
|
130
133
|
function extractStylesFromExpression(expression, ctx) {
|
|
131
134
|
let expr = expression;
|
|
@@ -266,7 +269,6 @@ function compileCSS(options) {
|
|
|
266
269
|
const viewTransitionImportMap = {};
|
|
267
270
|
const createImportMap = {};
|
|
268
271
|
const createFunctionImportMap = {};
|
|
269
|
-
const variantsImportMap = {};
|
|
270
272
|
const createThemeImportMap = {};
|
|
271
273
|
const createStaticImportMap = {};
|
|
272
274
|
const plumeriaAliases = {};
|
|
@@ -322,9 +324,6 @@ function compileCSS(options) {
|
|
|
322
324
|
scannedTables.createHashTable[uniqueKey];
|
|
323
325
|
if (scannedTables.createFunctionTable[uniqueKey])
|
|
324
326
|
createFunctionImportMap[localName] = (0, utils_1.styleFunctionsOf)(scannedTables.createFunctionTable[uniqueKey]);
|
|
325
|
-
if (scannedTables.variantsHashTable[uniqueKey])
|
|
326
|
-
variantsImportMap[localName] =
|
|
327
|
-
scannedTables.variantsHashTable[uniqueKey];
|
|
328
327
|
if (scannedTables.createThemeHashTable[uniqueKey])
|
|
329
328
|
createThemeImportMap[localName] =
|
|
330
329
|
scannedTables.createThemeHashTable[uniqueKey];
|
|
@@ -406,17 +405,6 @@ function compileCSS(options) {
|
|
|
406
405
|
for (const key of Object.keys(createImportMap)) {
|
|
407
406
|
mergedCreateTable[key] = createImportMap[key];
|
|
408
407
|
}
|
|
409
|
-
const mergedVariantsTable = {};
|
|
410
|
-
for (const key of Object.keys(scannedTables.variantsHashTable)) {
|
|
411
|
-
mergedVariantsTable[key] = scannedTables.variantsHashTable[key];
|
|
412
|
-
if (key.startsWith(`${resourcePath}-`)) {
|
|
413
|
-
const varName = key.slice(resourcePath.length + 1);
|
|
414
|
-
mergedVariantsTable[varName] = scannedTables.variantsHashTable[key];
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
for (const key of Object.keys(variantsImportMap)) {
|
|
418
|
-
mergedVariantsTable[key] = variantsImportMap[key];
|
|
419
|
-
}
|
|
420
408
|
const ctx = {
|
|
421
409
|
resourcePath,
|
|
422
410
|
mergedStaticTable,
|
|
@@ -425,7 +413,6 @@ function compileCSS(options) {
|
|
|
425
413
|
mergedCreateThemeHashTable,
|
|
426
414
|
mergedCreateStaticHashTable,
|
|
427
415
|
mergedCreateTable,
|
|
428
|
-
mergedVariantsTable,
|
|
429
416
|
scannedTables,
|
|
430
417
|
createFunctionImportMap,
|
|
431
418
|
localCreateStyles: {},
|
|
@@ -547,7 +534,7 @@ function compileCSS(options) {
|
|
|
547
534
|
return merged;
|
|
548
535
|
}
|
|
549
536
|
if (utils_1.t.isObjectExpression(expr)) {
|
|
550
|
-
return (0, utils_1.objectExpressionToObject)(expr, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable
|
|
537
|
+
return (0, utils_1.objectExpressionToObject)(expr, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
551
538
|
}
|
|
552
539
|
else if (utils_1.t.isMemberExpression(expr) &&
|
|
553
540
|
utils_1.t.isIdentifier(expr.object) &&
|
|
@@ -606,8 +593,7 @@ function compileCSS(options) {
|
|
|
606
593
|
const rootId = (0, utils_1.getRootIdentifier)(node);
|
|
607
594
|
const isPlumeriaStyle = rootId &&
|
|
608
595
|
(ctx.localCreateStyles[rootId] !== undefined ||
|
|
609
|
-
ctx.mergedCreateTable[rootId] !== undefined
|
|
610
|
-
ctx.mergedVariantsTable[rootId] !== undefined);
|
|
596
|
+
ctx.mergedCreateTable[rootId] !== undefined);
|
|
611
597
|
if (!isPlumeriaStyle) {
|
|
612
598
|
const origin = rootId ? localImports[rootId] : undefined;
|
|
613
599
|
const failure = origin
|
|
@@ -664,7 +650,7 @@ function compileCSS(options) {
|
|
|
664
650
|
properties: argExpr.properties.filter((prop) => prop.type === 'Identifier' ||
|
|
665
651
|
(prop.type === 'KeyValueProperty' &&
|
|
666
652
|
isStaticArgValue(prop.value))),
|
|
667
|
-
}, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable
|
|
653
|
+
}, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
668
654
|
if (func.named) {
|
|
669
655
|
const argExpr = callArgs[0]?.expression;
|
|
670
656
|
if (callArgs.length > 1 ||
|
|
@@ -760,8 +746,12 @@ function compileCSS(options) {
|
|
|
760
746
|
}
|
|
761
747
|
}
|
|
762
748
|
const fallback = owner && propDefaults.get(owner)?.get(propName);
|
|
763
|
-
if (fallback)
|
|
764
|
-
|
|
749
|
+
if (fallback && !isNoOpStyle((0, utils_1.unwrapExpression)(fallback))) {
|
|
750
|
+
const style = resolveStyleObject(fallback);
|
|
751
|
+
if (!style)
|
|
752
|
+
throw propDefaultError(getSource(fallback), path.basename(resourcePath));
|
|
753
|
+
processStyle(style);
|
|
754
|
+
}
|
|
765
755
|
if (possibilities.length > 0) {
|
|
766
756
|
const uniqueEntries = [];
|
|
767
757
|
possibilities.forEach((entry) => {
|
|
@@ -917,14 +907,14 @@ function compileCSS(options) {
|
|
|
917
907
|
else if (propName === 'keyframes' &&
|
|
918
908
|
args.length > 0 &&
|
|
919
909
|
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
920
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable
|
|
910
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
921
911
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
922
912
|
ctx.scannedTables.keyframesObjectTable[hash] = obj;
|
|
923
913
|
}
|
|
924
914
|
else if (propName === 'viewTransition' &&
|
|
925
915
|
args.length > 0 &&
|
|
926
916
|
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
927
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable
|
|
917
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
928
918
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
929
919
|
ctx.scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
930
920
|
}
|
|
@@ -941,7 +931,7 @@ function compileCSS(options) {
|
|
|
941
931
|
throw new Error(`[plumeria] Unsupported at-rule: "${selector}". createTheme only supports ` +
|
|
942
932
|
`nesting at-rules such as @media, @container, @supports, @layer, and @scope. (${path.basename(resourcePath)})`);
|
|
943
933
|
}
|
|
944
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[1].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable
|
|
934
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[1].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
945
935
|
const hash = (0, utils_1.themeHashOf)(selector, obj);
|
|
946
936
|
ctx.scannedTables.createThemeObjectTable[hash] = obj;
|
|
947
937
|
if (ctx.scannedTables.createThemeSelectorTable) {
|
|
@@ -951,7 +941,7 @@ function compileCSS(options) {
|
|
|
951
941
|
else if (propName === 'createStatic' &&
|
|
952
942
|
args.length > 0 &&
|
|
953
943
|
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
954
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable
|
|
944
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
955
945
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
956
946
|
ctx.scannedTables.createStaticObjectTable[hash] = obj;
|
|
957
947
|
}
|
|
@@ -1001,7 +991,7 @@ function compileCSS(options) {
|
|
|
1001
991
|
? ctx.scannedTables.createAtomicMapTable[ctx.mergedCreateThemeHashTable[name]]
|
|
1002
992
|
: undefined);
|
|
1003
993
|
if (pName === 'create') {
|
|
1004
|
-
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,
|
|
994
|
+
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, resolveVariable);
|
|
1005
995
|
if (obj) {
|
|
1006
996
|
const styleFunctions = (0, utils_1.styleFunctionsOf)(arg);
|
|
1007
997
|
ctx.localCreateStyles[node.id.value] = {
|
|
@@ -1022,7 +1012,7 @@ function compileCSS(options) {
|
|
|
1022
1012
|
throw new Error(`[plumeria] Unsupported at-rule: "${selector}". createTheme only supports ` +
|
|
1023
1013
|
`nesting at-rules such as @media, @container, @supports, @layer, and @scope. (${path.basename(resourcePath)})`);
|
|
1024
1014
|
}
|
|
1025
|
-
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
|
|
1015
|
+
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);
|
|
1026
1016
|
const hash = (0, utils_1.themeHashOf)(selector, obj);
|
|
1027
1017
|
const uKey = `${resourcePath}-${node.id.value}`;
|
|
1028
1018
|
ctx.scannedTables.createThemeHashTable[uKey] = hash;
|
|
@@ -1043,7 +1033,7 @@ function compileCSS(options) {
|
|
|
1043
1033
|
};
|
|
1044
1034
|
}
|
|
1045
1035
|
else if (pName === 'createStatic') {
|
|
1046
|
-
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
|
|
1036
|
+
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);
|
|
1047
1037
|
if (obj) {
|
|
1048
1038
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
1049
1039
|
const uKey = `${resourcePath}-${node.id.value}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "18.5.
|
|
3
|
+
"version": "18.5.3",
|
|
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": "^18.5.
|
|
24
|
+
"@plumeria/utils": "^18.5.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@rust-gear/glob": "1.1.1",
|