@plumeria/unplugin 18.5.0 → 18.5.2
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/core.js +146 -15
- package/dist/core.mjs +146 -15
- package/package.json +2 -2
package/dist/core.js
CHANGED
|
@@ -87,6 +87,28 @@ const destructuredPropAliases = (fn) => {
|
|
|
87
87
|
}
|
|
88
88
|
return aliases;
|
|
89
89
|
};
|
|
90
|
+
const propDefaultMessage = (source) => `Plumeria: A style prop default must be a defined style: "${source}". ` +
|
|
91
|
+
`Apply a conditional or dynamic style where the element is styled.`;
|
|
92
|
+
const spreadStyleMessage = (source) => `Plumeria: Spread elements in a style array are not supported: "...${source}". ` +
|
|
93
|
+
`List each style explicitly.`;
|
|
94
|
+
const resolveLocalStyleAlias = (aliases, expression) => {
|
|
95
|
+
let current = expression;
|
|
96
|
+
const seen = new Set();
|
|
97
|
+
while (utils_1.t.isIdentifier(current)) {
|
|
98
|
+
const name = current.value;
|
|
99
|
+
if (seen.has(name))
|
|
100
|
+
break;
|
|
101
|
+
seen.add(name);
|
|
102
|
+
const candidates = aliases[name];
|
|
103
|
+
if (!candidates || candidates.length === 0)
|
|
104
|
+
break;
|
|
105
|
+
const candidate = candidates.find((candidate) => candidate.context === current.ctxt);
|
|
106
|
+
if (!candidate)
|
|
107
|
+
break;
|
|
108
|
+
current = candidate.expression;
|
|
109
|
+
}
|
|
110
|
+
return current;
|
|
111
|
+
};
|
|
90
112
|
const isStaticArgValue = (node) => node.type === 'StringLiteral' ||
|
|
91
113
|
node.type === 'NumericLiteral' ||
|
|
92
114
|
node.type === 'BooleanLiteral' ||
|
|
@@ -273,11 +295,32 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
273
295
|
}
|
|
274
296
|
const components = [];
|
|
275
297
|
const propAliases = new Map();
|
|
298
|
+
const propDefaults = new Map();
|
|
299
|
+
const declaredProps = new Map();
|
|
276
300
|
const addComponent = (name, fn) => {
|
|
277
301
|
components.push({ name, node: fn });
|
|
302
|
+
const first = fn.params[0];
|
|
303
|
+
const pattern = unwrapPatternDefault(first?.pat ?? first);
|
|
304
|
+
const defaults = new Map();
|
|
305
|
+
for (const item of pattern?.properties ?? []) {
|
|
306
|
+
if (item.type === 'AssignmentPatternProperty' && item.value)
|
|
307
|
+
defaults.set(item.key.value, item.value);
|
|
308
|
+
if (item.type === 'KeyValuePatternProperty' &&
|
|
309
|
+
item.value?.type === 'AssignmentPattern')
|
|
310
|
+
defaults.set(item.key.value, item.value.right);
|
|
311
|
+
}
|
|
312
|
+
propDefaults.set(name, defaults);
|
|
278
313
|
const aliases = destructuredPropAliases(fn);
|
|
279
314
|
if (aliases.size > 0)
|
|
280
315
|
propAliases.set(name, aliases);
|
|
316
|
+
const declared = new Set();
|
|
317
|
+
for (const item of pattern?.properties ?? []) {
|
|
318
|
+
const key = item.key;
|
|
319
|
+
if (utils_1.t.isIdentifier(key) || utils_1.t.isStringLiteral(key))
|
|
320
|
+
declared.add(String(key.value));
|
|
321
|
+
}
|
|
322
|
+
if (declared.size > 0)
|
|
323
|
+
declaredProps.set(name, declared);
|
|
281
324
|
};
|
|
282
325
|
for (const node of ast.body) {
|
|
283
326
|
const statement = unwrapExport(node);
|
|
@@ -510,12 +553,15 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
510
553
|
const checkStyleAliasAssignment = (decl) => {
|
|
511
554
|
if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
|
|
512
555
|
return;
|
|
513
|
-
const init = decl.init;
|
|
556
|
+
const init = (0, utils_1.unwrapExpression)(decl.init);
|
|
514
557
|
if (utils_1.t.isMemberExpression(init) && utils_1.t.isIdentifier(init.object)) {
|
|
515
558
|
const objName = init.object.value;
|
|
516
559
|
if (localCreateStyles[objName] !== undefined ||
|
|
517
560
|
mergedCreateTable[objName] !== undefined) {
|
|
518
|
-
localStyleAliases[decl.id.value]
|
|
561
|
+
(localStyleAliases[decl.id.value] ??= []).push({
|
|
562
|
+
expression: init,
|
|
563
|
+
context: decl.id.ctxt,
|
|
564
|
+
});
|
|
519
565
|
}
|
|
520
566
|
}
|
|
521
567
|
};
|
|
@@ -865,12 +911,17 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
865
911
|
const jsxOpeningElementMap = new Map();
|
|
866
912
|
const componentParamNames = new Set();
|
|
867
913
|
const addFirstParamName = (fn) => {
|
|
868
|
-
const
|
|
914
|
+
const first = fn.params[0];
|
|
915
|
+
const p = unwrapPatternDefault(first?.pat ?? first);
|
|
869
916
|
if (utils_1.t.isIdentifier(p)) {
|
|
870
917
|
componentParamNames.add(p.value);
|
|
871
918
|
}
|
|
872
|
-
else if (p?.
|
|
873
|
-
|
|
919
|
+
else if (p?.type === 'ObjectPattern') {
|
|
920
|
+
for (const item of p.properties) {
|
|
921
|
+
if (item.type === 'RestElement' && utils_1.t.isIdentifier(item.argument)) {
|
|
922
|
+
componentParamNames.add(item.argument.value);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
874
925
|
}
|
|
875
926
|
};
|
|
876
927
|
for (const node of ast.body) {
|
|
@@ -908,6 +959,21 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
908
959
|
};
|
|
909
960
|
const resolveStyleObject = (expr) => {
|
|
910
961
|
expr = (0, utils_1.unwrapExpression)(expr);
|
|
962
|
+
expr = resolveLocalStyleAlias(localStyleAliases, expr);
|
|
963
|
+
if (expr.type === 'ArrayExpression') {
|
|
964
|
+
let merged = {};
|
|
965
|
+
for (const element of expr.elements ?? []) {
|
|
966
|
+
if (!element)
|
|
967
|
+
continue;
|
|
968
|
+
if (element.spread)
|
|
969
|
+
throwCompilationError(spreadStyleMessage(getSource(element.expression)), element.expression);
|
|
970
|
+
const style = resolveStyleObject(element.expression);
|
|
971
|
+
if (!style)
|
|
972
|
+
return null;
|
|
973
|
+
merged = (0, utils_1.deepMerge)(merged, style);
|
|
974
|
+
}
|
|
975
|
+
return merged;
|
|
976
|
+
}
|
|
911
977
|
if (utils_1.t.isObjectExpression(expr)) {
|
|
912
978
|
return (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
913
979
|
}
|
|
@@ -967,6 +1033,26 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
967
1033
|
return Boolean(localCreateStyles[callee.object.value]?.functions?.[callee.property.value] ??
|
|
968
1034
|
createFunctionImportMap[callee.object.value]?.[callee.property.value]);
|
|
969
1035
|
};
|
|
1036
|
+
const carriesStyleReference = (expression) => {
|
|
1037
|
+
const node = (0, utils_1.unwrapExpression)(expression);
|
|
1038
|
+
if (node.type === 'ArrayExpression')
|
|
1039
|
+
return node.elements.some((element) => !!element && carriesStyleReference(element.expression));
|
|
1040
|
+
if (isStyleFunctionCall(node))
|
|
1041
|
+
return true;
|
|
1042
|
+
if (utils_1.t.isObjectExpression(node))
|
|
1043
|
+
return false;
|
|
1044
|
+
return resolveStyleObject(node) !== null;
|
|
1045
|
+
};
|
|
1046
|
+
const assertNoStyleArraySpread = (expression) => {
|
|
1047
|
+
const node = (0, utils_1.unwrapExpression)(expression);
|
|
1048
|
+
if (node.type !== 'ArrayExpression')
|
|
1049
|
+
return;
|
|
1050
|
+
const spread = node.elements.find((element) => element?.spread);
|
|
1051
|
+
if (!spread)
|
|
1052
|
+
return;
|
|
1053
|
+
if (carriesStyleReference(node))
|
|
1054
|
+
throwCompilationError(spreadStyleMessage(getSource(spread.expression)), spread.expression);
|
|
1055
|
+
};
|
|
970
1056
|
const resolveDynamicCall = (expr, forceRuntime = false) => {
|
|
971
1057
|
if (!utils_1.t.isCallExpression(expr) || !utils_1.t.isMemberExpression(expr.callee))
|
|
972
1058
|
return null;
|
|
@@ -982,6 +1068,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
982
1068
|
if (callArgs.some((a) => a.spread))
|
|
983
1069
|
return null;
|
|
984
1070
|
const tempStaticTable = { ...mergedStaticTable };
|
|
1071
|
+
const providedParams = new Set();
|
|
985
1072
|
const runtime = [];
|
|
986
1073
|
const resolveObjectArg = (argExpr) => (0, utils_1.objectExpressionToObject)({
|
|
987
1074
|
...argExpr,
|
|
@@ -1018,8 +1105,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1018
1105
|
}
|
|
1019
1106
|
if (!forceRuntime &&
|
|
1020
1107
|
isStaticArgValue(source) &&
|
|
1021
|
-
argObj[key] !== undefined)
|
|
1108
|
+
argObj[key] !== undefined) {
|
|
1022
1109
|
tempStaticTable[local] = argObj[key];
|
|
1110
|
+
providedParams.add(local);
|
|
1111
|
+
}
|
|
1023
1112
|
else
|
|
1024
1113
|
runtime.push({ param: local, source });
|
|
1025
1114
|
});
|
|
@@ -1030,8 +1119,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1030
1119
|
return null;
|
|
1031
1120
|
const argObj = resolveObjectArg(callArgs[0].expression) ?? {};
|
|
1032
1121
|
func.params.forEach((p) => {
|
|
1033
|
-
if (argObj[p] !== undefined)
|
|
1122
|
+
if (argObj[p] !== undefined) {
|
|
1034
1123
|
tempStaticTable[p] = argObj[p];
|
|
1124
|
+
providedParams.add(p);
|
|
1125
|
+
}
|
|
1035
1126
|
});
|
|
1036
1127
|
}
|
|
1037
1128
|
else {
|
|
@@ -1042,7 +1133,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1042
1133
|
runtime.push({ param: p, source: callArg.expression });
|
|
1043
1134
|
});
|
|
1044
1135
|
}
|
|
1045
|
-
const resolved = (0, utils_1.resolveDynamicStyle)(func, runtime.map(({ param }) => param), tempStaticTable, dynamicStyleTables);
|
|
1136
|
+
const resolved = (0, utils_1.resolveDynamicStyle)(func, runtime.map(({ param }) => param), tempStaticTable, dynamicStyleTables, providedParams);
|
|
1046
1137
|
if (!resolved)
|
|
1047
1138
|
return null;
|
|
1048
1139
|
const { style, varGroups } = resolved;
|
|
@@ -1080,10 +1171,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1080
1171
|
};
|
|
1081
1172
|
const buildClassParts = (args, dynamicClassParts = [], existingClass = '', isStyleProp = false) => {
|
|
1082
1173
|
args.forEach((arg) => {
|
|
1083
|
-
|
|
1084
|
-
if (utils_1.t.isIdentifier(expr) && localStyleAliases[expr.value]) {
|
|
1085
|
-
arg.expression = localStyleAliases[expr.value];
|
|
1086
|
-
}
|
|
1174
|
+
arg.expression = resolveLocalStyleAlias(localStyleAliases, arg.expression);
|
|
1087
1175
|
});
|
|
1088
1176
|
const conditionals = [];
|
|
1089
1177
|
const dynamicVars = [];
|
|
@@ -1208,6 +1296,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1208
1296
|
};
|
|
1209
1297
|
const collectConditions = (node, currentTestStrings = [], argOrder) => {
|
|
1210
1298
|
node = (0, utils_1.unwrapExpression)(node);
|
|
1299
|
+
node = resolveLocalStyleAlias(localStyleAliases, node);
|
|
1211
1300
|
if (isNoOpStyle(node))
|
|
1212
1301
|
return true;
|
|
1213
1302
|
let branchStyle = resolveStyleObject(node);
|
|
@@ -1286,6 +1375,12 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1286
1375
|
utils_1.t.isIdentifier(expr.property);
|
|
1287
1376
|
if (!utils_1.t.isIdentifier(expr) && !isParamMember)
|
|
1288
1377
|
return false;
|
|
1378
|
+
const paramObject = isParamMember
|
|
1379
|
+
? expr.object.value
|
|
1380
|
+
: undefined;
|
|
1381
|
+
const isPropsMember = Boolean(paramObject &&
|
|
1382
|
+
localCreateStyles[paramObject] === undefined &&
|
|
1383
|
+
mergedCreateTable[paramObject] === undefined);
|
|
1289
1384
|
const varName = utils_1.t.isIdentifier(expr)
|
|
1290
1385
|
? expr.value
|
|
1291
1386
|
: expr.property.value;
|
|
@@ -1310,8 +1405,38 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1310
1405
|
if (candidates.length > 0)
|
|
1311
1406
|
possibilities = candidates;
|
|
1312
1407
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1408
|
+
const fallback = owner && propDefaults.get(owner)?.get(propName);
|
|
1409
|
+
if (fallback && !isNoOpStyle((0, utils_1.unwrapExpression)(fallback))) {
|
|
1410
|
+
const style = resolveStyleObject(fallback);
|
|
1411
|
+
if (!style)
|
|
1412
|
+
throwCompilationError(propDefaultMessage(getSource(fallback)), fallback);
|
|
1413
|
+
const atoms = {};
|
|
1414
|
+
(0, utils_1.getStyleRecords)(style).forEach((record) => {
|
|
1415
|
+
atoms[record.key] = record.hash;
|
|
1416
|
+
});
|
|
1417
|
+
const key = (0, zss_engine_1.genBase36Hash)(Object.values(atoms).join(' '), 1, 8);
|
|
1418
|
+
possibilities = [
|
|
1419
|
+
...(possibilities ?? []),
|
|
1420
|
+
{ key, styleObj: style },
|
|
1421
|
+
];
|
|
1422
|
+
const span = fallback.span;
|
|
1423
|
+
for (let index = replacements.length - 1; index >= 0; index--) {
|
|
1424
|
+
const replacement = replacements[index];
|
|
1425
|
+
if (replacement.start >= span.start - baseByteOffset &&
|
|
1426
|
+
replacement.end <= span.end - baseByteOffset)
|
|
1427
|
+
replacements.splice(index, 1);
|
|
1428
|
+
}
|
|
1429
|
+
excludeSubtreeSpans(fallback);
|
|
1430
|
+
replacements.push({
|
|
1431
|
+
start: span.start - baseByteOffset,
|
|
1432
|
+
end: span.end - baseByteOffset,
|
|
1433
|
+
content: JSON.stringify(key),
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
if (!possibilities || possibilities.length === 0) {
|
|
1437
|
+
return Boolean(isPropsMember ||
|
|
1438
|
+
(owner && declaredProps.get(owner)?.has(propName)));
|
|
1439
|
+
}
|
|
1315
1440
|
const carriesVars = possibilities.some((entry) => entry.hasVars);
|
|
1316
1441
|
if (carriesVars && !isStyleProp) {
|
|
1317
1442
|
throwCompilationError(`Plumeria: "${varName}" carries a dynamic function key, and css.use() returns only a class name. ` +
|
|
@@ -2027,6 +2152,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2027
2152
|
}
|
|
2028
2153
|
}
|
|
2029
2154
|
if (compKey) {
|
|
2155
|
+
if (node.value?.type === 'JSXExpressionContainer')
|
|
2156
|
+
assertNoStyleArraySpread(node.value.expression);
|
|
2030
2157
|
const list = scannedTables.componentPropsTable?.[compKey]?.[attrName];
|
|
2031
2158
|
if (list &&
|
|
2032
2159
|
node.value &&
|
|
@@ -2108,7 +2235,11 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2108
2235
|
const args = expr.type === 'ArrayExpression'
|
|
2109
2236
|
? expr.elements
|
|
2110
2237
|
.filter((el) => el !== undefined)
|
|
2111
|
-
.map((el) =>
|
|
2238
|
+
.map((el) => {
|
|
2239
|
+
if (el.spread)
|
|
2240
|
+
throwCompilationError(spreadStyleMessage(getSource(el.expression)), el.expression);
|
|
2241
|
+
return { expression: el.expression };
|
|
2242
|
+
})
|
|
2112
2243
|
: [{ expression: expr }];
|
|
2113
2244
|
const dynamicClassParts = [];
|
|
2114
2245
|
const existingStyleParts = [];
|
package/dist/core.mjs
CHANGED
|
@@ -51,6 +51,28 @@ const destructuredPropAliases = (fn) => {
|
|
|
51
51
|
}
|
|
52
52
|
return aliases;
|
|
53
53
|
};
|
|
54
|
+
const propDefaultMessage = (source) => `Plumeria: A style prop default must be a defined style: "${source}". ` +
|
|
55
|
+
`Apply a conditional or dynamic style where the element is styled.`;
|
|
56
|
+
const spreadStyleMessage = (source) => `Plumeria: Spread elements in a style array are not supported: "...${source}". ` +
|
|
57
|
+
`List each style explicitly.`;
|
|
58
|
+
const resolveLocalStyleAlias = (aliases, expression) => {
|
|
59
|
+
let current = expression;
|
|
60
|
+
const seen = new Set();
|
|
61
|
+
while (t.isIdentifier(current)) {
|
|
62
|
+
const name = current.value;
|
|
63
|
+
if (seen.has(name))
|
|
64
|
+
break;
|
|
65
|
+
seen.add(name);
|
|
66
|
+
const candidates = aliases[name];
|
|
67
|
+
if (!candidates || candidates.length === 0)
|
|
68
|
+
break;
|
|
69
|
+
const candidate = candidates.find((candidate) => candidate.context === current.ctxt);
|
|
70
|
+
if (!candidate)
|
|
71
|
+
break;
|
|
72
|
+
current = candidate.expression;
|
|
73
|
+
}
|
|
74
|
+
return current;
|
|
75
|
+
};
|
|
54
76
|
const isStaticArgValue = (node) => node.type === 'StringLiteral' ||
|
|
55
77
|
node.type === 'NumericLiteral' ||
|
|
56
78
|
node.type === 'BooleanLiteral' ||
|
|
@@ -237,11 +259,32 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
237
259
|
}
|
|
238
260
|
const components = [];
|
|
239
261
|
const propAliases = new Map();
|
|
262
|
+
const propDefaults = new Map();
|
|
263
|
+
const declaredProps = new Map();
|
|
240
264
|
const addComponent = (name, fn) => {
|
|
241
265
|
components.push({ name, node: fn });
|
|
266
|
+
const first = fn.params[0];
|
|
267
|
+
const pattern = unwrapPatternDefault(first?.pat ?? first);
|
|
268
|
+
const defaults = new Map();
|
|
269
|
+
for (const item of pattern?.properties ?? []) {
|
|
270
|
+
if (item.type === 'AssignmentPatternProperty' && item.value)
|
|
271
|
+
defaults.set(item.key.value, item.value);
|
|
272
|
+
if (item.type === 'KeyValuePatternProperty' &&
|
|
273
|
+
item.value?.type === 'AssignmentPattern')
|
|
274
|
+
defaults.set(item.key.value, item.value.right);
|
|
275
|
+
}
|
|
276
|
+
propDefaults.set(name, defaults);
|
|
242
277
|
const aliases = destructuredPropAliases(fn);
|
|
243
278
|
if (aliases.size > 0)
|
|
244
279
|
propAliases.set(name, aliases);
|
|
280
|
+
const declared = new Set();
|
|
281
|
+
for (const item of pattern?.properties ?? []) {
|
|
282
|
+
const key = item.key;
|
|
283
|
+
if (t.isIdentifier(key) || t.isStringLiteral(key))
|
|
284
|
+
declared.add(String(key.value));
|
|
285
|
+
}
|
|
286
|
+
if (declared.size > 0)
|
|
287
|
+
declaredProps.set(name, declared);
|
|
245
288
|
};
|
|
246
289
|
for (const node of ast.body) {
|
|
247
290
|
const statement = unwrapExport(node);
|
|
@@ -474,12 +517,15 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
474
517
|
const checkStyleAliasAssignment = (decl) => {
|
|
475
518
|
if (!t.isIdentifier(decl.id) || !decl.init)
|
|
476
519
|
return;
|
|
477
|
-
const init = decl.init;
|
|
520
|
+
const init = unwrapExpression(decl.init);
|
|
478
521
|
if (t.isMemberExpression(init) && t.isIdentifier(init.object)) {
|
|
479
522
|
const objName = init.object.value;
|
|
480
523
|
if (localCreateStyles[objName] !== undefined ||
|
|
481
524
|
mergedCreateTable[objName] !== undefined) {
|
|
482
|
-
localStyleAliases[decl.id.value]
|
|
525
|
+
(localStyleAliases[decl.id.value] ??= []).push({
|
|
526
|
+
expression: init,
|
|
527
|
+
context: decl.id.ctxt,
|
|
528
|
+
});
|
|
483
529
|
}
|
|
484
530
|
}
|
|
485
531
|
};
|
|
@@ -829,12 +875,17 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
829
875
|
const jsxOpeningElementMap = new Map();
|
|
830
876
|
const componentParamNames = new Set();
|
|
831
877
|
const addFirstParamName = (fn) => {
|
|
832
|
-
const
|
|
878
|
+
const first = fn.params[0];
|
|
879
|
+
const p = unwrapPatternDefault(first?.pat ?? first);
|
|
833
880
|
if (t.isIdentifier(p)) {
|
|
834
881
|
componentParamNames.add(p.value);
|
|
835
882
|
}
|
|
836
|
-
else if (p?.
|
|
837
|
-
|
|
883
|
+
else if (p?.type === 'ObjectPattern') {
|
|
884
|
+
for (const item of p.properties) {
|
|
885
|
+
if (item.type === 'RestElement' && t.isIdentifier(item.argument)) {
|
|
886
|
+
componentParamNames.add(item.argument.value);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
838
889
|
}
|
|
839
890
|
};
|
|
840
891
|
for (const node of ast.body) {
|
|
@@ -872,6 +923,21 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
872
923
|
};
|
|
873
924
|
const resolveStyleObject = (expr) => {
|
|
874
925
|
expr = unwrapExpression(expr);
|
|
926
|
+
expr = resolveLocalStyleAlias(localStyleAliases, expr);
|
|
927
|
+
if (expr.type === 'ArrayExpression') {
|
|
928
|
+
let merged = {};
|
|
929
|
+
for (const element of expr.elements ?? []) {
|
|
930
|
+
if (!element)
|
|
931
|
+
continue;
|
|
932
|
+
if (element.spread)
|
|
933
|
+
throwCompilationError(spreadStyleMessage(getSource(element.expression)), element.expression);
|
|
934
|
+
const style = resolveStyleObject(element.expression);
|
|
935
|
+
if (!style)
|
|
936
|
+
return null;
|
|
937
|
+
merged = deepMerge(merged, style);
|
|
938
|
+
}
|
|
939
|
+
return merged;
|
|
940
|
+
}
|
|
875
941
|
if (t.isObjectExpression(expr)) {
|
|
876
942
|
return objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
877
943
|
}
|
|
@@ -931,6 +997,26 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
931
997
|
return Boolean(localCreateStyles[callee.object.value]?.functions?.[callee.property.value] ??
|
|
932
998
|
createFunctionImportMap[callee.object.value]?.[callee.property.value]);
|
|
933
999
|
};
|
|
1000
|
+
const carriesStyleReference = (expression) => {
|
|
1001
|
+
const node = unwrapExpression(expression);
|
|
1002
|
+
if (node.type === 'ArrayExpression')
|
|
1003
|
+
return node.elements.some((element) => !!element && carriesStyleReference(element.expression));
|
|
1004
|
+
if (isStyleFunctionCall(node))
|
|
1005
|
+
return true;
|
|
1006
|
+
if (t.isObjectExpression(node))
|
|
1007
|
+
return false;
|
|
1008
|
+
return resolveStyleObject(node) !== null;
|
|
1009
|
+
};
|
|
1010
|
+
const assertNoStyleArraySpread = (expression) => {
|
|
1011
|
+
const node = unwrapExpression(expression);
|
|
1012
|
+
if (node.type !== 'ArrayExpression')
|
|
1013
|
+
return;
|
|
1014
|
+
const spread = node.elements.find((element) => element?.spread);
|
|
1015
|
+
if (!spread)
|
|
1016
|
+
return;
|
|
1017
|
+
if (carriesStyleReference(node))
|
|
1018
|
+
throwCompilationError(spreadStyleMessage(getSource(spread.expression)), spread.expression);
|
|
1019
|
+
};
|
|
934
1020
|
const resolveDynamicCall = (expr, forceRuntime = false) => {
|
|
935
1021
|
if (!t.isCallExpression(expr) || !t.isMemberExpression(expr.callee))
|
|
936
1022
|
return null;
|
|
@@ -946,6 +1032,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
946
1032
|
if (callArgs.some((a) => a.spread))
|
|
947
1033
|
return null;
|
|
948
1034
|
const tempStaticTable = { ...mergedStaticTable };
|
|
1035
|
+
const providedParams = new Set();
|
|
949
1036
|
const runtime = [];
|
|
950
1037
|
const resolveObjectArg = (argExpr) => objectExpressionToObject({
|
|
951
1038
|
...argExpr,
|
|
@@ -982,8 +1069,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
982
1069
|
}
|
|
983
1070
|
if (!forceRuntime &&
|
|
984
1071
|
isStaticArgValue(source) &&
|
|
985
|
-
argObj[key] !== undefined)
|
|
1072
|
+
argObj[key] !== undefined) {
|
|
986
1073
|
tempStaticTable[local] = argObj[key];
|
|
1074
|
+
providedParams.add(local);
|
|
1075
|
+
}
|
|
987
1076
|
else
|
|
988
1077
|
runtime.push({ param: local, source });
|
|
989
1078
|
});
|
|
@@ -994,8 +1083,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
994
1083
|
return null;
|
|
995
1084
|
const argObj = resolveObjectArg(callArgs[0].expression) ?? {};
|
|
996
1085
|
func.params.forEach((p) => {
|
|
997
|
-
if (argObj[p] !== undefined)
|
|
1086
|
+
if (argObj[p] !== undefined) {
|
|
998
1087
|
tempStaticTable[p] = argObj[p];
|
|
1088
|
+
providedParams.add(p);
|
|
1089
|
+
}
|
|
999
1090
|
});
|
|
1000
1091
|
}
|
|
1001
1092
|
else {
|
|
@@ -1006,7 +1097,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1006
1097
|
runtime.push({ param: p, source: callArg.expression });
|
|
1007
1098
|
});
|
|
1008
1099
|
}
|
|
1009
|
-
const resolved = resolveDynamicStyle(func, runtime.map(({ param }) => param), tempStaticTable, dynamicStyleTables);
|
|
1100
|
+
const resolved = resolveDynamicStyle(func, runtime.map(({ param }) => param), tempStaticTable, dynamicStyleTables, providedParams);
|
|
1010
1101
|
if (!resolved)
|
|
1011
1102
|
return null;
|
|
1012
1103
|
const { style, varGroups } = resolved;
|
|
@@ -1044,10 +1135,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1044
1135
|
};
|
|
1045
1136
|
const buildClassParts = (args, dynamicClassParts = [], existingClass = '', isStyleProp = false) => {
|
|
1046
1137
|
args.forEach((arg) => {
|
|
1047
|
-
|
|
1048
|
-
if (t.isIdentifier(expr) && localStyleAliases[expr.value]) {
|
|
1049
|
-
arg.expression = localStyleAliases[expr.value];
|
|
1050
|
-
}
|
|
1138
|
+
arg.expression = resolveLocalStyleAlias(localStyleAliases, arg.expression);
|
|
1051
1139
|
});
|
|
1052
1140
|
const conditionals = [];
|
|
1053
1141
|
const dynamicVars = [];
|
|
@@ -1172,6 +1260,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1172
1260
|
};
|
|
1173
1261
|
const collectConditions = (node, currentTestStrings = [], argOrder) => {
|
|
1174
1262
|
node = unwrapExpression(node);
|
|
1263
|
+
node = resolveLocalStyleAlias(localStyleAliases, node);
|
|
1175
1264
|
if (isNoOpStyle(node))
|
|
1176
1265
|
return true;
|
|
1177
1266
|
let branchStyle = resolveStyleObject(node);
|
|
@@ -1250,6 +1339,12 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1250
1339
|
t.isIdentifier(expr.property);
|
|
1251
1340
|
if (!t.isIdentifier(expr) && !isParamMember)
|
|
1252
1341
|
return false;
|
|
1342
|
+
const paramObject = isParamMember
|
|
1343
|
+
? expr.object.value
|
|
1344
|
+
: undefined;
|
|
1345
|
+
const isPropsMember = Boolean(paramObject &&
|
|
1346
|
+
localCreateStyles[paramObject] === undefined &&
|
|
1347
|
+
mergedCreateTable[paramObject] === undefined);
|
|
1253
1348
|
const varName = t.isIdentifier(expr)
|
|
1254
1349
|
? expr.value
|
|
1255
1350
|
: expr.property.value;
|
|
@@ -1274,8 +1369,38 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1274
1369
|
if (candidates.length > 0)
|
|
1275
1370
|
possibilities = candidates;
|
|
1276
1371
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1372
|
+
const fallback = owner && propDefaults.get(owner)?.get(propName);
|
|
1373
|
+
if (fallback && !isNoOpStyle(unwrapExpression(fallback))) {
|
|
1374
|
+
const style = resolveStyleObject(fallback);
|
|
1375
|
+
if (!style)
|
|
1376
|
+
throwCompilationError(propDefaultMessage(getSource(fallback)), fallback);
|
|
1377
|
+
const atoms = {};
|
|
1378
|
+
getStyleRecords(style).forEach((record) => {
|
|
1379
|
+
atoms[record.key] = record.hash;
|
|
1380
|
+
});
|
|
1381
|
+
const key = genBase36Hash(Object.values(atoms).join(' '), 1, 8);
|
|
1382
|
+
possibilities = [
|
|
1383
|
+
...(possibilities ?? []),
|
|
1384
|
+
{ key, styleObj: style },
|
|
1385
|
+
];
|
|
1386
|
+
const span = fallback.span;
|
|
1387
|
+
for (let index = replacements.length - 1; index >= 0; index--) {
|
|
1388
|
+
const replacement = replacements[index];
|
|
1389
|
+
if (replacement.start >= span.start - baseByteOffset &&
|
|
1390
|
+
replacement.end <= span.end - baseByteOffset)
|
|
1391
|
+
replacements.splice(index, 1);
|
|
1392
|
+
}
|
|
1393
|
+
excludeSubtreeSpans(fallback);
|
|
1394
|
+
replacements.push({
|
|
1395
|
+
start: span.start - baseByteOffset,
|
|
1396
|
+
end: span.end - baseByteOffset,
|
|
1397
|
+
content: JSON.stringify(key),
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
if (!possibilities || possibilities.length === 0) {
|
|
1401
|
+
return Boolean(isPropsMember ||
|
|
1402
|
+
(owner && declaredProps.get(owner)?.has(propName)));
|
|
1403
|
+
}
|
|
1279
1404
|
const carriesVars = possibilities.some((entry) => entry.hasVars);
|
|
1280
1405
|
if (carriesVars && !isStyleProp) {
|
|
1281
1406
|
throwCompilationError(`Plumeria: "${varName}" carries a dynamic function key, and css.use() returns only a class name. ` +
|
|
@@ -1991,6 +2116,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1991
2116
|
}
|
|
1992
2117
|
}
|
|
1993
2118
|
if (compKey) {
|
|
2119
|
+
if (node.value?.type === 'JSXExpressionContainer')
|
|
2120
|
+
assertNoStyleArraySpread(node.value.expression);
|
|
1994
2121
|
const list = scannedTables.componentPropsTable?.[compKey]?.[attrName];
|
|
1995
2122
|
if (list &&
|
|
1996
2123
|
node.value &&
|
|
@@ -2072,7 +2199,11 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2072
2199
|
const args = expr.type === 'ArrayExpression'
|
|
2073
2200
|
? expr.elements
|
|
2074
2201
|
.filter((el) => el !== undefined)
|
|
2075
|
-
.map((el) =>
|
|
2202
|
+
.map((el) => {
|
|
2203
|
+
if (el.spread)
|
|
2204
|
+
throwCompilationError(spreadStyleMessage(getSource(el.expression)), el.expression);
|
|
2205
|
+
return { expression: el.expression };
|
|
2206
|
+
})
|
|
2076
2207
|
: [{ expression: expr }];
|
|
2077
2208
|
const dynamicClassParts = [];
|
|
2078
2209
|
const existingStyleParts = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/unplugin",
|
|
3
|
-
"version": "18.5.
|
|
3
|
+
"version": "18.5.2",
|
|
4
4
|
"description": "Universal Plumeria plugin for various build tools",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"dependencies": {
|
|
95
95
|
"@rollup/pluginutils": "^5.4.0",
|
|
96
96
|
"unplugin": "^3.0.0",
|
|
97
|
-
"@plumeria/utils": "^18.5.
|
|
97
|
+
"@plumeria/utils": "^18.5.2"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"@swc/core": "1.15.47",
|