@plumeria/unplugin 18.5.2 → 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/core.js +102 -71
- package/dist/core.mjs +102 -71
- package/package.json +2 -2
package/dist/core.js
CHANGED
|
@@ -245,10 +245,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
245
245
|
utils_1.t.isFunctionExpression(node)) {
|
|
246
246
|
const rootId = (0, utils_1.getRootIdentifier)(node);
|
|
247
247
|
const isPlumeriaStyle = rootId &&
|
|
248
|
+
isVisibleReference(node) &&
|
|
248
249
|
((localCreateStyles[rootId] !== undefined &&
|
|
249
250
|
localCreateStyles[rootId].type !== 'constant') ||
|
|
250
|
-
mergedCreateTable[rootId] !== undefined
|
|
251
|
-
mergedVariantsTable[rootId] !== undefined);
|
|
251
|
+
mergedCreateTable[rootId] !== undefined);
|
|
252
252
|
if (!isPlumeriaStyle) {
|
|
253
253
|
const origin = rootId ? localImports[rootId] : undefined;
|
|
254
254
|
const failure = origin
|
|
@@ -261,6 +261,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
};
|
|
264
|
+
const scannedTables = (0, utils_1.scanAll)();
|
|
265
|
+
const ownFailure = (0, utils_1.resolveFileError)(baseId, '');
|
|
266
|
+
if (ownFailure)
|
|
267
|
+
throwCompilationError(`Plumeria: ${ownFailure.message}`);
|
|
264
268
|
for (const node of ast.body) {
|
|
265
269
|
if (node.type === 'ImportDeclaration') {
|
|
266
270
|
const sourcePath = node.source.value;
|
|
@@ -274,7 +278,6 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
274
278
|
}
|
|
275
279
|
}
|
|
276
280
|
}
|
|
277
|
-
const scannedTables = (0, utils_1.scanAll)();
|
|
278
281
|
if (scannedTables.componentPropsTable) {
|
|
279
282
|
const parentFiles = new Set();
|
|
280
283
|
for (const compKey of Object.keys(scannedTables.componentPropsTable)) {
|
|
@@ -372,7 +375,6 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
372
375
|
const viewTransitionImportMap = {};
|
|
373
376
|
const createImportMap = {};
|
|
374
377
|
const createFunctionImportMap = {};
|
|
375
|
-
const variantsImportMap = {};
|
|
376
378
|
const createThemeImportMap = {};
|
|
377
379
|
const createStaticImportMap = {};
|
|
378
380
|
const plumeriaAliases = {};
|
|
@@ -439,10 +441,6 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
439
441
|
if (scannedTables.createFunctionTable[uniqueKey]) {
|
|
440
442
|
createFunctionImportMap[localName] = (0, utils_1.styleFunctionsOf)(scannedTables.createFunctionTable[uniqueKey]);
|
|
441
443
|
}
|
|
442
|
-
if (scannedTables.variantsHashTable[uniqueKey]) {
|
|
443
|
-
variantsImportMap[localName] =
|
|
444
|
-
scannedTables.variantsHashTable[uniqueKey];
|
|
445
|
-
}
|
|
446
444
|
if (scannedTables.createThemeHashTable[uniqueKey]) {
|
|
447
445
|
createThemeImportMap[localName] =
|
|
448
446
|
scannedTables.createThemeHashTable[uniqueKey];
|
|
@@ -501,17 +499,6 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
501
499
|
for (const key of Object.keys(createImportMap)) {
|
|
502
500
|
mergedCreateTable[key] = createImportMap[key];
|
|
503
501
|
}
|
|
504
|
-
const mergedVariantsTable = {};
|
|
505
|
-
for (const key of Object.keys(scannedTables.variantsHashTable)) {
|
|
506
|
-
mergedVariantsTable[key] = scannedTables.variantsHashTable[key];
|
|
507
|
-
if (key.startsWith(`${resourcePath}-`)) {
|
|
508
|
-
const varName = key.slice(resourcePath.length + 1);
|
|
509
|
-
mergedVariantsTable[varName] = scannedTables.variantsHashTable[key];
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
for (const key of Object.keys(variantsImportMap)) {
|
|
513
|
-
mergedVariantsTable[key] = variantsImportMap[key];
|
|
514
|
-
}
|
|
515
502
|
const mergedCreateThemeHashTable = {};
|
|
516
503
|
for (const key of Object.keys(scannedTables.createThemeHashTable)) {
|
|
517
504
|
mergedCreateThemeHashTable[key] =
|
|
@@ -546,7 +533,6 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
546
533
|
createHashTable: mergedCreateTable,
|
|
547
534
|
createStaticHashTable: mergedCreateStaticHashTable,
|
|
548
535
|
createStaticObjectTable: scannedTables.createStaticObjectTable,
|
|
549
|
-
variantsHashTable: mergedVariantsTable,
|
|
550
536
|
};
|
|
551
537
|
const localCreateStyles = {};
|
|
552
538
|
const localStyleAliases = {};
|
|
@@ -566,8 +552,30 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
566
552
|
}
|
|
567
553
|
};
|
|
568
554
|
const replacements = [];
|
|
555
|
+
const deferredSources = [];
|
|
556
|
+
const deferSource = (node, stripObject = false) => {
|
|
557
|
+
const token = `__plumeria_preserved_${deferredSources.length}__`;
|
|
558
|
+
deferredSources.push({
|
|
559
|
+
token,
|
|
560
|
+
start: node.span.start - baseByteOffset,
|
|
561
|
+
end: node.span.end - baseByteOffset,
|
|
562
|
+
stripObject,
|
|
563
|
+
});
|
|
564
|
+
return token;
|
|
565
|
+
};
|
|
569
566
|
const dynamicFnCalls = [];
|
|
570
567
|
const processedDecls = new Set();
|
|
568
|
+
const separatelyExported = new Set();
|
|
569
|
+
for (const statement of ast.body) {
|
|
570
|
+
if (statement.type !== 'ExportNamedDeclaration' || statement.source)
|
|
571
|
+
continue;
|
|
572
|
+
for (const specifier of statement.specifiers) {
|
|
573
|
+
if (specifier.type === 'ExportSpecifier' &&
|
|
574
|
+
utils_1.t.isIdentifier(specifier.orig)) {
|
|
575
|
+
separatelyExported.add(specifier.orig.value);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
571
579
|
const idSpans = new Set();
|
|
572
580
|
const excludedSpans = new Set();
|
|
573
581
|
const referenceIdents = (0, utils_1.collectReferenceIdentifiers)(ast);
|
|
@@ -647,7 +655,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
647
655
|
}
|
|
648
656
|
if (propName === 'create' &&
|
|
649
657
|
utils_1.t.isObjectExpression(init.arguments[0].expression)) {
|
|
650
|
-
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
658
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
651
659
|
if (obj) {
|
|
652
660
|
const hashMap = {};
|
|
653
661
|
Object.entries(obj).forEach(([key, style]) => {
|
|
@@ -697,7 +705,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
697
705
|
if (selector.startsWith('@') && !(0, zss_engine_1.isAtRule)(selector)) {
|
|
698
706
|
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
699
707
|
}
|
|
700
|
-
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
708
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
701
709
|
const hash = (0, utils_1.themeHashOf)(selector, obj);
|
|
702
710
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
703
711
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
@@ -735,7 +743,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
735
743
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
736
744
|
idSpans.add(node.id.span.start);
|
|
737
745
|
}
|
|
738
|
-
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
746
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
739
747
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
740
748
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
741
749
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
@@ -817,7 +825,9 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
817
825
|
if (processedDecls.has(node))
|
|
818
826
|
return;
|
|
819
827
|
node.declarations.forEach((decl) => {
|
|
820
|
-
registerStyle(decl, node.span,
|
|
828
|
+
registerStyle(decl, node.span, node.declarations.length > 1 ||
|
|
829
|
+
(utils_1.t.isIdentifier(decl.id) &&
|
|
830
|
+
separatelyExported.has(decl.id.value)));
|
|
821
831
|
checkStyleAliasAssignment(decl);
|
|
822
832
|
});
|
|
823
833
|
},
|
|
@@ -850,7 +860,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
850
860
|
if (propName === 'keyframes' && args.length > 0) {
|
|
851
861
|
const expr = args[0].expression;
|
|
852
862
|
if (utils_1.t.isObjectExpression(expr)) {
|
|
853
|
-
const obj = (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
863
|
+
const obj = (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
854
864
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
855
865
|
scannedTables.keyframesObjectTable[hash] = obj;
|
|
856
866
|
replacements.push({
|
|
@@ -863,7 +873,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
863
873
|
else if (propName === 'viewTransition' &&
|
|
864
874
|
args.length > 0 &&
|
|
865
875
|
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
866
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
876
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
867
877
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
868
878
|
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
869
879
|
replacements.push({
|
|
@@ -884,7 +894,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
884
894
|
if (selector.startsWith('@') && !(0, zss_engine_1.isAtRule)(selector)) {
|
|
885
895
|
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
886
896
|
}
|
|
887
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
897
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
888
898
|
const hash = (0, utils_1.themeHashOf)(selector, obj);
|
|
889
899
|
scannedTables.createThemeObjectTable[hash] = obj;
|
|
890
900
|
if (scannedTables.createThemeSelectorTable) {
|
|
@@ -894,14 +904,14 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
894
904
|
else if (propName === 'createStatic' &&
|
|
895
905
|
args.length > 0 &&
|
|
896
906
|
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
897
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
907
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
898
908
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
899
909
|
scannedTables.createStaticObjectTable[hash] = obj;
|
|
900
910
|
}
|
|
901
911
|
else if (propName === 'create' &&
|
|
902
912
|
args.length > 0 &&
|
|
903
913
|
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
904
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
914
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
905
915
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
906
916
|
scannedTables.createObjectTable[hash] = obj;
|
|
907
917
|
}
|
|
@@ -957,9 +967,22 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
957
967
|
const end = node.span.end - baseByteOffset;
|
|
958
968
|
return sourceBuffer.subarray(start, end).toString('utf-8');
|
|
959
969
|
};
|
|
970
|
+
const isVisibleReference = (expr) => {
|
|
971
|
+
if (utils_1.t.isIdentifier(expr))
|
|
972
|
+
return referenceIdents.references.has(expr.span.start);
|
|
973
|
+
if (utils_1.t.isMemberExpression(expr))
|
|
974
|
+
return isVisibleReference(expr.object);
|
|
975
|
+
if (utils_1.t.isCallExpression(expr) &&
|
|
976
|
+
expr.callee.type !== 'Super' &&
|
|
977
|
+
expr.callee.type !== 'Import')
|
|
978
|
+
return isVisibleReference(expr.callee);
|
|
979
|
+
return true;
|
|
980
|
+
};
|
|
960
981
|
const resolveStyleObject = (expr) => {
|
|
961
982
|
expr = (0, utils_1.unwrapExpression)(expr);
|
|
962
983
|
expr = resolveLocalStyleAlias(localStyleAliases, expr);
|
|
984
|
+
if (!isVisibleReference(expr))
|
|
985
|
+
return null;
|
|
963
986
|
if (expr.type === 'ArrayExpression') {
|
|
964
987
|
let merged = {};
|
|
965
988
|
for (const element of expr.elements ?? []) {
|
|
@@ -975,7 +998,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
975
998
|
return merged;
|
|
976
999
|
}
|
|
977
1000
|
if (utils_1.t.isObjectExpression(expr)) {
|
|
978
|
-
return (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
1001
|
+
return (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
979
1002
|
}
|
|
980
1003
|
else if (utils_1.t.isMemberExpression(expr) &&
|
|
981
1004
|
utils_1.t.isIdentifier(expr.object) &&
|
|
@@ -1018,9 +1041,6 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1018
1041
|
const styleInfo = localCreateStyles[varName];
|
|
1019
1042
|
if (styleInfo?.obj)
|
|
1020
1043
|
return styleInfo.obj;
|
|
1021
|
-
const vHash = mergedVariantsTable[varName];
|
|
1022
|
-
if (vHash)
|
|
1023
|
-
return scannedTables.variantsObjectTable[vHash];
|
|
1024
1044
|
}
|
|
1025
1045
|
return null;
|
|
1026
1046
|
};
|
|
@@ -1059,6 +1079,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1059
1079
|
const callee = expr.callee;
|
|
1060
1080
|
if (!utils_1.t.isIdentifier(callee.object) || !utils_1.t.isIdentifier(callee.property))
|
|
1061
1081
|
return null;
|
|
1082
|
+
if (!isVisibleReference(callee.object))
|
|
1083
|
+
return null;
|
|
1062
1084
|
const styleInfo = localCreateStyles[callee.object.value];
|
|
1063
1085
|
const func = styleInfo?.functions?.[callee.property.value] ??
|
|
1064
1086
|
createFunctionImportMap[callee.object.value]?.[callee.property.value];
|
|
@@ -1075,7 +1097,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1075
1097
|
properties: argExpr.properties.filter((prop) => prop.type === 'Identifier' ||
|
|
1076
1098
|
(prop.type === 'KeyValueProperty' &&
|
|
1077
1099
|
isStaticArgValue(prop.value))),
|
|
1078
|
-
}, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
1100
|
+
}, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
1079
1101
|
if (func.named) {
|
|
1080
1102
|
const argExpr = callArgs[0]?.expression;
|
|
1081
1103
|
if (callArgs.length > 1 ||
|
|
@@ -1199,6 +1221,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1199
1221
|
utils_1.t.isStringLiteral(node.property.expression)) {
|
|
1200
1222
|
return null;
|
|
1201
1223
|
}
|
|
1224
|
+
if (!isVisibleReference(node.object))
|
|
1225
|
+
return null;
|
|
1202
1226
|
const varName = node.object.value;
|
|
1203
1227
|
const obj = resolveCreateObject(varName);
|
|
1204
1228
|
return obj
|
|
@@ -1299,6 +1323,15 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1299
1323
|
node = resolveLocalStyleAlias(localStyleAliases, node);
|
|
1300
1324
|
if (isNoOpStyle(node))
|
|
1301
1325
|
return true;
|
|
1326
|
+
if (node.type === 'ArrayExpression') {
|
|
1327
|
+
return node.elements.every((element) => {
|
|
1328
|
+
if (!element)
|
|
1329
|
+
return true;
|
|
1330
|
+
if (element.spread)
|
|
1331
|
+
throwCompilationError(spreadStyleMessage(getSource(element.expression)), element.expression);
|
|
1332
|
+
return collectConditions(element.expression, currentTestStrings, argOrder);
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1302
1335
|
let branchStyle = resolveStyleObject(node);
|
|
1303
1336
|
if (!branchStyle) {
|
|
1304
1337
|
const dynamic = resolveDynamicCall(node);
|
|
@@ -1351,14 +1384,13 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1351
1384
|
return true;
|
|
1352
1385
|
}
|
|
1353
1386
|
}
|
|
1354
|
-
collectConditions(node.consequent, [...currentTestStrings, `(${testSource})`], argOrder);
|
|
1355
|
-
collectConditions(node.alternate, [...currentTestStrings, `!(${testSource})`], argOrder);
|
|
1356
|
-
return
|
|
1387
|
+
const consequentHandled = collectConditions(node.consequent, [...currentTestStrings, `(${testSource})`], argOrder);
|
|
1388
|
+
const alternateHandled = collectConditions(node.alternate, [...currentTestStrings, `!(${testSource})`], argOrder);
|
|
1389
|
+
return consequentHandled && alternateHandled;
|
|
1357
1390
|
}
|
|
1358
1391
|
else if (node.type === 'BinaryExpression' &&
|
|
1359
1392
|
node.operator === '&&') {
|
|
1360
|
-
collectConditions(node.right, [...currentTestStrings, `(${getSource(node.left)})`], argOrder);
|
|
1361
|
-
return true;
|
|
1393
|
+
return collectConditions(node.right, [...currentTestStrings, `(${getSource(node.left)})`], argOrder);
|
|
1362
1394
|
}
|
|
1363
1395
|
else if (node.type === 'ParenthesisExpression') {
|
|
1364
1396
|
return collectConditions(node.expression, currentTestStrings, argOrder);
|
|
@@ -1489,14 +1521,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1489
1521
|
continue;
|
|
1490
1522
|
if (utils_1.t.isCallExpression(expr) && utils_1.t.isIdentifier(expr.callee)) {
|
|
1491
1523
|
const varName = expr.callee.value;
|
|
1492
|
-
const uniqueKey = `${resourcePath}-${varName}`;
|
|
1493
1524
|
let variantObj;
|
|
1494
|
-
|
|
1495
|
-
if (!hash)
|
|
1496
|
-
hash = mergedVariantsTable[varName];
|
|
1497
|
-
if (hash && scannedTables.variantsObjectTable[hash])
|
|
1498
|
-
variantObj = scannedTables.variantsObjectTable[hash];
|
|
1499
|
-
if (!variantObj && localCreateStyles[varName]?.obj)
|
|
1525
|
+
if (isVisibleReference(expr) && localCreateStyles[varName]?.obj)
|
|
1500
1526
|
variantObj = localCreateStyles[varName].obj;
|
|
1501
1527
|
if (variantObj) {
|
|
1502
1528
|
const callArgs = expr.arguments;
|
|
@@ -1600,14 +1626,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1600
1626
|
}
|
|
1601
1627
|
else if (utils_1.t.isIdentifier(expr)) {
|
|
1602
1628
|
const varName = expr.value;
|
|
1603
|
-
const uniqueKey = `${resourcePath}-${varName}`;
|
|
1604
1629
|
let variantObj;
|
|
1605
|
-
|
|
1606
|
-
if (!hash)
|
|
1607
|
-
hash = mergedVariantsTable[varName];
|
|
1608
|
-
if (hash && scannedTables.variantsObjectTable[hash])
|
|
1609
|
-
variantObj = scannedTables.variantsObjectTable[hash];
|
|
1610
|
-
if (!variantObj && localCreateStyles[varName]?.obj)
|
|
1630
|
+
if (isVisibleReference(expr) && localCreateStyles[varName]?.obj)
|
|
1611
1631
|
variantObj = localCreateStyles[varName].obj;
|
|
1612
1632
|
if (variantObj) {
|
|
1613
1633
|
Object.entries(variantObj).forEach(([groupName, groupVariants]) => {
|
|
@@ -1637,7 +1657,9 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1637
1657
|
utils_1.t.isIdentifier(expr.object) &&
|
|
1638
1658
|
expr.property.type === 'Computed') {
|
|
1639
1659
|
const varName = expr.object.value;
|
|
1640
|
-
const styleObj =
|
|
1660
|
+
const styleObj = isVisibleReference(expr)
|
|
1661
|
+
? resolveCreateObject(varName)
|
|
1662
|
+
: null;
|
|
1641
1663
|
if (styleObj) {
|
|
1642
1664
|
const dynExpr = expr.property.expression;
|
|
1643
1665
|
const dynSource = getSource(dynExpr);
|
|
@@ -1966,6 +1988,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1966
1988
|
});
|
|
1967
1989
|
},
|
|
1968
1990
|
MemberExpression({ node }) {
|
|
1991
|
+
if (!isVisibleReference(node))
|
|
1992
|
+
return;
|
|
1969
1993
|
if (utils_1.t.isIdentifier(node.object) &&
|
|
1970
1994
|
(utils_1.t.isIdentifier(node.property) || node.property.type === 'Computed')) {
|
|
1971
1995
|
const varName = node.object.value;
|
|
@@ -2234,7 +2258,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2234
2258
|
const expr = node.value.expression;
|
|
2235
2259
|
const args = expr.type === 'ArrayExpression'
|
|
2236
2260
|
? expr.elements
|
|
2237
|
-
.filter((el) => el
|
|
2261
|
+
.filter((el) => el != null)
|
|
2238
2262
|
.map((el) => {
|
|
2239
2263
|
if (el.spread)
|
|
2240
2264
|
throwCompilationError(spreadStyleMessage(getSource(el.expression)), el.expression);
|
|
@@ -2267,13 +2291,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2267
2291
|
existingClassExpr = JSON.stringify(classNameAttr.value.value);
|
|
2268
2292
|
}
|
|
2269
2293
|
else if (classNameAttr.value?.type === 'JSXExpressionContainer') {
|
|
2270
|
-
|
|
2271
|
-
baseByteOffset;
|
|
2272
|
-
const end = classNameAttr.value.expression.span.end -
|
|
2273
|
-
baseByteOffset;
|
|
2274
|
-
existingClassExpr = `(${sourceBuffer
|
|
2275
|
-
.subarray(start, end)
|
|
2276
|
-
.toString('utf-8')})`;
|
|
2294
|
+
existingClassExpr = `(${deferSource(classNameAttr.value.expression)})`;
|
|
2277
2295
|
}
|
|
2278
2296
|
}
|
|
2279
2297
|
const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
|
|
@@ -2288,22 +2306,19 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2288
2306
|
});
|
|
2289
2307
|
if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
|
|
2290
2308
|
const innerExpr = styleAttrExisting.value?.expression;
|
|
2291
|
-
const start = innerExpr.span.start - baseByteOffset;
|
|
2292
|
-
const end = innerExpr.span.end - baseByteOffset;
|
|
2293
|
-
const innerSource = sourceBuffer
|
|
2294
|
-
.subarray(start, end)
|
|
2295
|
-
.toString('utf-8');
|
|
2296
2309
|
if (innerExpr.type === 'ObjectExpression') {
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
existingStyleParts.push(stripped);
|
|
2310
|
+
if (innerExpr.properties.length > 0)
|
|
2311
|
+
existingStyleParts.push(deferSource(innerExpr, true));
|
|
2300
2312
|
}
|
|
2301
2313
|
else {
|
|
2302
|
-
existingStyleExpr = `...(${
|
|
2314
|
+
existingStyleExpr = `...(${deferSource(innerExpr)})`;
|
|
2303
2315
|
}
|
|
2304
2316
|
}
|
|
2305
2317
|
}
|
|
2306
2318
|
const { classParts, isOptimizable, baseStyle, dynamicVars, propVarSpreads, } = buildClassParts(args, dynamicClassParts, existingClassExpr, true);
|
|
2319
|
+
if (!isOptimizable) {
|
|
2320
|
+
throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(expr)}" is not supported.`, expr);
|
|
2321
|
+
}
|
|
2307
2322
|
const styleParts = [
|
|
2308
2323
|
...existingStyleParts,
|
|
2309
2324
|
...foldDynamicVars(dynamicVars),
|
|
@@ -2442,6 +2457,22 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2442
2457
|
`so it cannot be passed through another prop or read as a value.`, call);
|
|
2443
2458
|
}
|
|
2444
2459
|
});
|
|
2460
|
+
for (const deferred of deferredSources) {
|
|
2461
|
+
let cursor = deferred.start;
|
|
2462
|
+
const pieces = [];
|
|
2463
|
+
for (const replacement of [...replacements].sort((a, b) => a.start - b.start || b.end - a.end)) {
|
|
2464
|
+
if (replacement.start < cursor || replacement.end > deferred.end)
|
|
2465
|
+
continue;
|
|
2466
|
+
pieces.push(sourceBuffer.subarray(cursor, replacement.start).toString('utf-8'), replacement.content);
|
|
2467
|
+
cursor = replacement.end;
|
|
2468
|
+
}
|
|
2469
|
+
pieces.push(sourceBuffer.subarray(cursor, deferred.end).toString('utf-8'));
|
|
2470
|
+
let content = pieces.join('');
|
|
2471
|
+
if (deferred.stripObject)
|
|
2472
|
+
content = content.slice(1, -1).trim();
|
|
2473
|
+
for (const replacement of replacements)
|
|
2474
|
+
replacement.content = replacement.content.replaceAll(deferred.token, content);
|
|
2475
|
+
}
|
|
2445
2476
|
const buffer = Buffer.from(source);
|
|
2446
2477
|
let offset = 0;
|
|
2447
2478
|
const parts = [];
|
package/dist/core.mjs
CHANGED
|
@@ -209,10 +209,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
209
209
|
t.isFunctionExpression(node)) {
|
|
210
210
|
const rootId = getRootIdentifier(node);
|
|
211
211
|
const isPlumeriaStyle = rootId &&
|
|
212
|
+
isVisibleReference(node) &&
|
|
212
213
|
((localCreateStyles[rootId] !== undefined &&
|
|
213
214
|
localCreateStyles[rootId].type !== 'constant') ||
|
|
214
|
-
mergedCreateTable[rootId] !== undefined
|
|
215
|
-
mergedVariantsTable[rootId] !== undefined);
|
|
215
|
+
mergedCreateTable[rootId] !== undefined);
|
|
216
216
|
if (!isPlumeriaStyle) {
|
|
217
217
|
const origin = rootId ? localImports[rootId] : undefined;
|
|
218
218
|
const failure = origin
|
|
@@ -225,6 +225,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
};
|
|
228
|
+
const scannedTables = scanAll();
|
|
229
|
+
const ownFailure = resolveFileError(baseId, '');
|
|
230
|
+
if (ownFailure)
|
|
231
|
+
throwCompilationError(`Plumeria: ${ownFailure.message}`);
|
|
228
232
|
for (const node of ast.body) {
|
|
229
233
|
if (node.type === 'ImportDeclaration') {
|
|
230
234
|
const sourcePath = node.source.value;
|
|
@@ -238,7 +242,6 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
238
242
|
}
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
|
-
const scannedTables = scanAll();
|
|
242
245
|
if (scannedTables.componentPropsTable) {
|
|
243
246
|
const parentFiles = new Set();
|
|
244
247
|
for (const compKey of Object.keys(scannedTables.componentPropsTable)) {
|
|
@@ -336,7 +339,6 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
336
339
|
const viewTransitionImportMap = {};
|
|
337
340
|
const createImportMap = {};
|
|
338
341
|
const createFunctionImportMap = {};
|
|
339
|
-
const variantsImportMap = {};
|
|
340
342
|
const createThemeImportMap = {};
|
|
341
343
|
const createStaticImportMap = {};
|
|
342
344
|
const plumeriaAliases = {};
|
|
@@ -403,10 +405,6 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
403
405
|
if (scannedTables.createFunctionTable[uniqueKey]) {
|
|
404
406
|
createFunctionImportMap[localName] = styleFunctionsOf(scannedTables.createFunctionTable[uniqueKey]);
|
|
405
407
|
}
|
|
406
|
-
if (scannedTables.variantsHashTable[uniqueKey]) {
|
|
407
|
-
variantsImportMap[localName] =
|
|
408
|
-
scannedTables.variantsHashTable[uniqueKey];
|
|
409
|
-
}
|
|
410
408
|
if (scannedTables.createThemeHashTable[uniqueKey]) {
|
|
411
409
|
createThemeImportMap[localName] =
|
|
412
410
|
scannedTables.createThemeHashTable[uniqueKey];
|
|
@@ -465,17 +463,6 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
465
463
|
for (const key of Object.keys(createImportMap)) {
|
|
466
464
|
mergedCreateTable[key] = createImportMap[key];
|
|
467
465
|
}
|
|
468
|
-
const mergedVariantsTable = {};
|
|
469
|
-
for (const key of Object.keys(scannedTables.variantsHashTable)) {
|
|
470
|
-
mergedVariantsTable[key] = scannedTables.variantsHashTable[key];
|
|
471
|
-
if (key.startsWith(`${resourcePath}-`)) {
|
|
472
|
-
const varName = key.slice(resourcePath.length + 1);
|
|
473
|
-
mergedVariantsTable[varName] = scannedTables.variantsHashTable[key];
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
for (const key of Object.keys(variantsImportMap)) {
|
|
477
|
-
mergedVariantsTable[key] = variantsImportMap[key];
|
|
478
|
-
}
|
|
479
466
|
const mergedCreateThemeHashTable = {};
|
|
480
467
|
for (const key of Object.keys(scannedTables.createThemeHashTable)) {
|
|
481
468
|
mergedCreateThemeHashTable[key] =
|
|
@@ -510,7 +497,6 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
510
497
|
createHashTable: mergedCreateTable,
|
|
511
498
|
createStaticHashTable: mergedCreateStaticHashTable,
|
|
512
499
|
createStaticObjectTable: scannedTables.createStaticObjectTable,
|
|
513
|
-
variantsHashTable: mergedVariantsTable,
|
|
514
500
|
};
|
|
515
501
|
const localCreateStyles = {};
|
|
516
502
|
const localStyleAliases = {};
|
|
@@ -530,8 +516,30 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
530
516
|
}
|
|
531
517
|
};
|
|
532
518
|
const replacements = [];
|
|
519
|
+
const deferredSources = [];
|
|
520
|
+
const deferSource = (node, stripObject = false) => {
|
|
521
|
+
const token = `__plumeria_preserved_${deferredSources.length}__`;
|
|
522
|
+
deferredSources.push({
|
|
523
|
+
token,
|
|
524
|
+
start: node.span.start - baseByteOffset,
|
|
525
|
+
end: node.span.end - baseByteOffset,
|
|
526
|
+
stripObject,
|
|
527
|
+
});
|
|
528
|
+
return token;
|
|
529
|
+
};
|
|
533
530
|
const dynamicFnCalls = [];
|
|
534
531
|
const processedDecls = new Set();
|
|
532
|
+
const separatelyExported = new Set();
|
|
533
|
+
for (const statement of ast.body) {
|
|
534
|
+
if (statement.type !== 'ExportNamedDeclaration' || statement.source)
|
|
535
|
+
continue;
|
|
536
|
+
for (const specifier of statement.specifiers) {
|
|
537
|
+
if (specifier.type === 'ExportSpecifier' &&
|
|
538
|
+
t.isIdentifier(specifier.orig)) {
|
|
539
|
+
separatelyExported.add(specifier.orig.value);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
535
543
|
const idSpans = new Set();
|
|
536
544
|
const excludedSpans = new Set();
|
|
537
545
|
const referenceIdents = collectReferenceIdentifiers(ast);
|
|
@@ -611,7 +619,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
611
619
|
}
|
|
612
620
|
if (propName === 'create' &&
|
|
613
621
|
t.isObjectExpression(init.arguments[0].expression)) {
|
|
614
|
-
const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
622
|
+
const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
615
623
|
if (obj) {
|
|
616
624
|
const hashMap = {};
|
|
617
625
|
Object.entries(obj).forEach(([key, style]) => {
|
|
@@ -661,7 +669,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
661
669
|
if (selector.startsWith('@') && !isAtRule(selector)) {
|
|
662
670
|
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
663
671
|
}
|
|
664
|
-
const obj = objectExpressionToObject(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
672
|
+
const obj = objectExpressionToObject(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
665
673
|
const hash = themeHashOf(selector, obj);
|
|
666
674
|
if (t.isIdentifier(node.id)) {
|
|
667
675
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
@@ -699,7 +707,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
699
707
|
if (t.isIdentifier(node.id)) {
|
|
700
708
|
idSpans.add(node.id.span.start);
|
|
701
709
|
}
|
|
702
|
-
const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
710
|
+
const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
703
711
|
const hash = genBase36Hash(obj, 1, 8);
|
|
704
712
|
if (t.isIdentifier(node.id)) {
|
|
705
713
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
@@ -781,7 +789,9 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
781
789
|
if (processedDecls.has(node))
|
|
782
790
|
return;
|
|
783
791
|
node.declarations.forEach((decl) => {
|
|
784
|
-
registerStyle(decl, node.span,
|
|
792
|
+
registerStyle(decl, node.span, node.declarations.length > 1 ||
|
|
793
|
+
(t.isIdentifier(decl.id) &&
|
|
794
|
+
separatelyExported.has(decl.id.value)));
|
|
785
795
|
checkStyleAliasAssignment(decl);
|
|
786
796
|
});
|
|
787
797
|
},
|
|
@@ -814,7 +824,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
814
824
|
if (propName === 'keyframes' && args.length > 0) {
|
|
815
825
|
const expr = args[0].expression;
|
|
816
826
|
if (t.isObjectExpression(expr)) {
|
|
817
|
-
const obj = objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
827
|
+
const obj = objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
818
828
|
const hash = genBase36Hash(obj, 1, 8);
|
|
819
829
|
scannedTables.keyframesObjectTable[hash] = obj;
|
|
820
830
|
replacements.push({
|
|
@@ -827,7 +837,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
827
837
|
else if (propName === 'viewTransition' &&
|
|
828
838
|
args.length > 0 &&
|
|
829
839
|
t.isObjectExpression(args[0].expression)) {
|
|
830
|
-
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
840
|
+
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
831
841
|
const hash = genBase36Hash(obj, 1, 8);
|
|
832
842
|
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
833
843
|
replacements.push({
|
|
@@ -848,7 +858,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
848
858
|
if (selector.startsWith('@') && !isAtRule(selector)) {
|
|
849
859
|
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
850
860
|
}
|
|
851
|
-
const obj = objectExpressionToObject(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
861
|
+
const obj = objectExpressionToObject(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
852
862
|
const hash = themeHashOf(selector, obj);
|
|
853
863
|
scannedTables.createThemeObjectTable[hash] = obj;
|
|
854
864
|
if (scannedTables.createThemeSelectorTable) {
|
|
@@ -858,14 +868,14 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
858
868
|
else if (propName === 'createStatic' &&
|
|
859
869
|
args.length > 0 &&
|
|
860
870
|
t.isObjectExpression(args[0].expression)) {
|
|
861
|
-
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
871
|
+
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
862
872
|
const hash = genBase36Hash(obj, 1, 8);
|
|
863
873
|
scannedTables.createStaticObjectTable[hash] = obj;
|
|
864
874
|
}
|
|
865
875
|
else if (propName === 'create' &&
|
|
866
876
|
args.length > 0 &&
|
|
867
877
|
t.isObjectExpression(args[0].expression)) {
|
|
868
|
-
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
878
|
+
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
869
879
|
const hash = genBase36Hash(obj, 1, 8);
|
|
870
880
|
scannedTables.createObjectTable[hash] = obj;
|
|
871
881
|
}
|
|
@@ -921,9 +931,22 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
921
931
|
const end = node.span.end - baseByteOffset;
|
|
922
932
|
return sourceBuffer.subarray(start, end).toString('utf-8');
|
|
923
933
|
};
|
|
934
|
+
const isVisibleReference = (expr) => {
|
|
935
|
+
if (t.isIdentifier(expr))
|
|
936
|
+
return referenceIdents.references.has(expr.span.start);
|
|
937
|
+
if (t.isMemberExpression(expr))
|
|
938
|
+
return isVisibleReference(expr.object);
|
|
939
|
+
if (t.isCallExpression(expr) &&
|
|
940
|
+
expr.callee.type !== 'Super' &&
|
|
941
|
+
expr.callee.type !== 'Import')
|
|
942
|
+
return isVisibleReference(expr.callee);
|
|
943
|
+
return true;
|
|
944
|
+
};
|
|
924
945
|
const resolveStyleObject = (expr) => {
|
|
925
946
|
expr = unwrapExpression(expr);
|
|
926
947
|
expr = resolveLocalStyleAlias(localStyleAliases, expr);
|
|
948
|
+
if (!isVisibleReference(expr))
|
|
949
|
+
return null;
|
|
927
950
|
if (expr.type === 'ArrayExpression') {
|
|
928
951
|
let merged = {};
|
|
929
952
|
for (const element of expr.elements ?? []) {
|
|
@@ -939,7 +962,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
939
962
|
return merged;
|
|
940
963
|
}
|
|
941
964
|
if (t.isObjectExpression(expr)) {
|
|
942
|
-
return objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
965
|
+
return objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
943
966
|
}
|
|
944
967
|
else if (t.isMemberExpression(expr) &&
|
|
945
968
|
t.isIdentifier(expr.object) &&
|
|
@@ -982,9 +1005,6 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
982
1005
|
const styleInfo = localCreateStyles[varName];
|
|
983
1006
|
if (styleInfo?.obj)
|
|
984
1007
|
return styleInfo.obj;
|
|
985
|
-
const vHash = mergedVariantsTable[varName];
|
|
986
|
-
if (vHash)
|
|
987
|
-
return scannedTables.variantsObjectTable[vHash];
|
|
988
1008
|
}
|
|
989
1009
|
return null;
|
|
990
1010
|
};
|
|
@@ -1023,6 +1043,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1023
1043
|
const callee = expr.callee;
|
|
1024
1044
|
if (!t.isIdentifier(callee.object) || !t.isIdentifier(callee.property))
|
|
1025
1045
|
return null;
|
|
1046
|
+
if (!isVisibleReference(callee.object))
|
|
1047
|
+
return null;
|
|
1026
1048
|
const styleInfo = localCreateStyles[callee.object.value];
|
|
1027
1049
|
const func = styleInfo?.functions?.[callee.property.value] ??
|
|
1028
1050
|
createFunctionImportMap[callee.object.value]?.[callee.property.value];
|
|
@@ -1039,7 +1061,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1039
1061
|
properties: argExpr.properties.filter((prop) => prop.type === 'Identifier' ||
|
|
1040
1062
|
(prop.type === 'KeyValueProperty' &&
|
|
1041
1063
|
isStaticArgValue(prop.value))),
|
|
1042
|
-
}, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
1064
|
+
}, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
1043
1065
|
if (func.named) {
|
|
1044
1066
|
const argExpr = callArgs[0]?.expression;
|
|
1045
1067
|
if (callArgs.length > 1 ||
|
|
@@ -1163,6 +1185,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1163
1185
|
t.isStringLiteral(node.property.expression)) {
|
|
1164
1186
|
return null;
|
|
1165
1187
|
}
|
|
1188
|
+
if (!isVisibleReference(node.object))
|
|
1189
|
+
return null;
|
|
1166
1190
|
const varName = node.object.value;
|
|
1167
1191
|
const obj = resolveCreateObject(varName);
|
|
1168
1192
|
return obj
|
|
@@ -1263,6 +1287,15 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1263
1287
|
node = resolveLocalStyleAlias(localStyleAliases, node);
|
|
1264
1288
|
if (isNoOpStyle(node))
|
|
1265
1289
|
return true;
|
|
1290
|
+
if (node.type === 'ArrayExpression') {
|
|
1291
|
+
return node.elements.every((element) => {
|
|
1292
|
+
if (!element)
|
|
1293
|
+
return true;
|
|
1294
|
+
if (element.spread)
|
|
1295
|
+
throwCompilationError(spreadStyleMessage(getSource(element.expression)), element.expression);
|
|
1296
|
+
return collectConditions(element.expression, currentTestStrings, argOrder);
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1266
1299
|
let branchStyle = resolveStyleObject(node);
|
|
1267
1300
|
if (!branchStyle) {
|
|
1268
1301
|
const dynamic = resolveDynamicCall(node);
|
|
@@ -1315,14 +1348,13 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1315
1348
|
return true;
|
|
1316
1349
|
}
|
|
1317
1350
|
}
|
|
1318
|
-
collectConditions(node.consequent, [...currentTestStrings, `(${testSource})`], argOrder);
|
|
1319
|
-
collectConditions(node.alternate, [...currentTestStrings, `!(${testSource})`], argOrder);
|
|
1320
|
-
return
|
|
1351
|
+
const consequentHandled = collectConditions(node.consequent, [...currentTestStrings, `(${testSource})`], argOrder);
|
|
1352
|
+
const alternateHandled = collectConditions(node.alternate, [...currentTestStrings, `!(${testSource})`], argOrder);
|
|
1353
|
+
return consequentHandled && alternateHandled;
|
|
1321
1354
|
}
|
|
1322
1355
|
else if (node.type === 'BinaryExpression' &&
|
|
1323
1356
|
node.operator === '&&') {
|
|
1324
|
-
collectConditions(node.right, [...currentTestStrings, `(${getSource(node.left)})`], argOrder);
|
|
1325
|
-
return true;
|
|
1357
|
+
return collectConditions(node.right, [...currentTestStrings, `(${getSource(node.left)})`], argOrder);
|
|
1326
1358
|
}
|
|
1327
1359
|
else if (node.type === 'ParenthesisExpression') {
|
|
1328
1360
|
return collectConditions(node.expression, currentTestStrings, argOrder);
|
|
@@ -1453,14 +1485,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1453
1485
|
continue;
|
|
1454
1486
|
if (t.isCallExpression(expr) && t.isIdentifier(expr.callee)) {
|
|
1455
1487
|
const varName = expr.callee.value;
|
|
1456
|
-
const uniqueKey = `${resourcePath}-${varName}`;
|
|
1457
1488
|
let variantObj;
|
|
1458
|
-
|
|
1459
|
-
if (!hash)
|
|
1460
|
-
hash = mergedVariantsTable[varName];
|
|
1461
|
-
if (hash && scannedTables.variantsObjectTable[hash])
|
|
1462
|
-
variantObj = scannedTables.variantsObjectTable[hash];
|
|
1463
|
-
if (!variantObj && localCreateStyles[varName]?.obj)
|
|
1489
|
+
if (isVisibleReference(expr) && localCreateStyles[varName]?.obj)
|
|
1464
1490
|
variantObj = localCreateStyles[varName].obj;
|
|
1465
1491
|
if (variantObj) {
|
|
1466
1492
|
const callArgs = expr.arguments;
|
|
@@ -1564,14 +1590,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1564
1590
|
}
|
|
1565
1591
|
else if (t.isIdentifier(expr)) {
|
|
1566
1592
|
const varName = expr.value;
|
|
1567
|
-
const uniqueKey = `${resourcePath}-${varName}`;
|
|
1568
1593
|
let variantObj;
|
|
1569
|
-
|
|
1570
|
-
if (!hash)
|
|
1571
|
-
hash = mergedVariantsTable[varName];
|
|
1572
|
-
if (hash && scannedTables.variantsObjectTable[hash])
|
|
1573
|
-
variantObj = scannedTables.variantsObjectTable[hash];
|
|
1574
|
-
if (!variantObj && localCreateStyles[varName]?.obj)
|
|
1594
|
+
if (isVisibleReference(expr) && localCreateStyles[varName]?.obj)
|
|
1575
1595
|
variantObj = localCreateStyles[varName].obj;
|
|
1576
1596
|
if (variantObj) {
|
|
1577
1597
|
Object.entries(variantObj).forEach(([groupName, groupVariants]) => {
|
|
@@ -1601,7 +1621,9 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1601
1621
|
t.isIdentifier(expr.object) &&
|
|
1602
1622
|
expr.property.type === 'Computed') {
|
|
1603
1623
|
const varName = expr.object.value;
|
|
1604
|
-
const styleObj =
|
|
1624
|
+
const styleObj = isVisibleReference(expr)
|
|
1625
|
+
? resolveCreateObject(varName)
|
|
1626
|
+
: null;
|
|
1605
1627
|
if (styleObj) {
|
|
1606
1628
|
const dynExpr = expr.property.expression;
|
|
1607
1629
|
const dynSource = getSource(dynExpr);
|
|
@@ -1930,6 +1952,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1930
1952
|
});
|
|
1931
1953
|
},
|
|
1932
1954
|
MemberExpression({ node }) {
|
|
1955
|
+
if (!isVisibleReference(node))
|
|
1956
|
+
return;
|
|
1933
1957
|
if (t.isIdentifier(node.object) &&
|
|
1934
1958
|
(t.isIdentifier(node.property) || node.property.type === 'Computed')) {
|
|
1935
1959
|
const varName = node.object.value;
|
|
@@ -2198,7 +2222,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2198
2222
|
const expr = node.value.expression;
|
|
2199
2223
|
const args = expr.type === 'ArrayExpression'
|
|
2200
2224
|
? expr.elements
|
|
2201
|
-
.filter((el) => el
|
|
2225
|
+
.filter((el) => el != null)
|
|
2202
2226
|
.map((el) => {
|
|
2203
2227
|
if (el.spread)
|
|
2204
2228
|
throwCompilationError(spreadStyleMessage(getSource(el.expression)), el.expression);
|
|
@@ -2231,13 +2255,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2231
2255
|
existingClassExpr = JSON.stringify(classNameAttr.value.value);
|
|
2232
2256
|
}
|
|
2233
2257
|
else if (classNameAttr.value?.type === 'JSXExpressionContainer') {
|
|
2234
|
-
|
|
2235
|
-
baseByteOffset;
|
|
2236
|
-
const end = classNameAttr.value.expression.span.end -
|
|
2237
|
-
baseByteOffset;
|
|
2238
|
-
existingClassExpr = `(${sourceBuffer
|
|
2239
|
-
.subarray(start, end)
|
|
2240
|
-
.toString('utf-8')})`;
|
|
2258
|
+
existingClassExpr = `(${deferSource(classNameAttr.value.expression)})`;
|
|
2241
2259
|
}
|
|
2242
2260
|
}
|
|
2243
2261
|
const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
|
|
@@ -2252,22 +2270,19 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2252
2270
|
});
|
|
2253
2271
|
if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
|
|
2254
2272
|
const innerExpr = styleAttrExisting.value?.expression;
|
|
2255
|
-
const start = innerExpr.span.start - baseByteOffset;
|
|
2256
|
-
const end = innerExpr.span.end - baseByteOffset;
|
|
2257
|
-
const innerSource = sourceBuffer
|
|
2258
|
-
.subarray(start, end)
|
|
2259
|
-
.toString('utf-8');
|
|
2260
2273
|
if (innerExpr.type === 'ObjectExpression') {
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
existingStyleParts.push(stripped);
|
|
2274
|
+
if (innerExpr.properties.length > 0)
|
|
2275
|
+
existingStyleParts.push(deferSource(innerExpr, true));
|
|
2264
2276
|
}
|
|
2265
2277
|
else {
|
|
2266
|
-
existingStyleExpr = `...(${
|
|
2278
|
+
existingStyleExpr = `...(${deferSource(innerExpr)})`;
|
|
2267
2279
|
}
|
|
2268
2280
|
}
|
|
2269
2281
|
}
|
|
2270
2282
|
const { classParts, isOptimizable, baseStyle, dynamicVars, propVarSpreads, } = buildClassParts(args, dynamicClassParts, existingClassExpr, true);
|
|
2283
|
+
if (!isOptimizable) {
|
|
2284
|
+
throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(expr)}" is not supported.`, expr);
|
|
2285
|
+
}
|
|
2271
2286
|
const styleParts = [
|
|
2272
2287
|
...existingStyleParts,
|
|
2273
2288
|
...foldDynamicVars(dynamicVars),
|
|
@@ -2406,6 +2421,22 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2406
2421
|
`so it cannot be passed through another prop or read as a value.`, call);
|
|
2407
2422
|
}
|
|
2408
2423
|
});
|
|
2424
|
+
for (const deferred of deferredSources) {
|
|
2425
|
+
let cursor = deferred.start;
|
|
2426
|
+
const pieces = [];
|
|
2427
|
+
for (const replacement of [...replacements].sort((a, b) => a.start - b.start || b.end - a.end)) {
|
|
2428
|
+
if (replacement.start < cursor || replacement.end > deferred.end)
|
|
2429
|
+
continue;
|
|
2430
|
+
pieces.push(sourceBuffer.subarray(cursor, replacement.start).toString('utf-8'), replacement.content);
|
|
2431
|
+
cursor = replacement.end;
|
|
2432
|
+
}
|
|
2433
|
+
pieces.push(sourceBuffer.subarray(cursor, deferred.end).toString('utf-8'));
|
|
2434
|
+
let content = pieces.join('');
|
|
2435
|
+
if (deferred.stripObject)
|
|
2436
|
+
content = content.slice(1, -1).trim();
|
|
2437
|
+
for (const replacement of replacements)
|
|
2438
|
+
replacement.content = replacement.content.replaceAll(deferred.token, content);
|
|
2439
|
+
}
|
|
2409
2440
|
const buffer = Buffer.from(source);
|
|
2410
2441
|
let offset = 0;
|
|
2411
2442
|
const parts = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/unplugin",
|
|
3
|
-
"version": "18.5.
|
|
3
|
+
"version": "18.5.3",
|
|
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.3"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"@swc/core": "1.15.47",
|