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