@plumeria/unplugin 18.5.2 → 18.5.4
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 +112 -71
- package/dist/core.mjs +112 -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,39 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
566
552
|
}
|
|
567
553
|
};
|
|
568
554
|
const replacements = [];
|
|
555
|
+
const deferredSources = [];
|
|
556
|
+
const deferRange = (start, end) => {
|
|
557
|
+
const token = `__plumeria_preserved_${deferredSources.length}__`;
|
|
558
|
+
deferredSources.push({ token, start, end });
|
|
559
|
+
return token;
|
|
560
|
+
};
|
|
561
|
+
const deferSource = (node) => deferRange(node.span.start - baseByteOffset, node.span.end - baseByteOffset);
|
|
562
|
+
const deferProperty = (property) => {
|
|
563
|
+
const node = property;
|
|
564
|
+
const range = node.spread && node.arguments
|
|
565
|
+
? { start: node.spread.start, end: node.arguments.span.end }
|
|
566
|
+
: node.span
|
|
567
|
+
? { start: node.span.start, end: node.span.end }
|
|
568
|
+
: node.key && node.value
|
|
569
|
+
? { start: node.key.span.start, end: node.value.span.end }
|
|
570
|
+
: null;
|
|
571
|
+
return range
|
|
572
|
+
? deferRange(range.start - baseByteOffset, range.end - baseByteOffset)
|
|
573
|
+
: null;
|
|
574
|
+
};
|
|
569
575
|
const dynamicFnCalls = [];
|
|
570
576
|
const processedDecls = new Set();
|
|
577
|
+
const separatelyExported = new Set();
|
|
578
|
+
for (const statement of ast.body) {
|
|
579
|
+
if (statement.type !== 'ExportNamedDeclaration' || statement.source)
|
|
580
|
+
continue;
|
|
581
|
+
for (const specifier of statement.specifiers) {
|
|
582
|
+
if (specifier.type === 'ExportSpecifier' &&
|
|
583
|
+
utils_1.t.isIdentifier(specifier.orig)) {
|
|
584
|
+
separatelyExported.add(specifier.orig.value);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
571
588
|
const idSpans = new Set();
|
|
572
589
|
const excludedSpans = new Set();
|
|
573
590
|
const referenceIdents = (0, utils_1.collectReferenceIdentifiers)(ast);
|
|
@@ -647,7 +664,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
647
664
|
}
|
|
648
665
|
if (propName === 'create' &&
|
|
649
666
|
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
|
|
667
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
651
668
|
if (obj) {
|
|
652
669
|
const hashMap = {};
|
|
653
670
|
Object.entries(obj).forEach(([key, style]) => {
|
|
@@ -697,7 +714,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
697
714
|
if (selector.startsWith('@') && !(0, zss_engine_1.isAtRule)(selector)) {
|
|
698
715
|
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
699
716
|
}
|
|
700
|
-
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
717
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
701
718
|
const hash = (0, utils_1.themeHashOf)(selector, obj);
|
|
702
719
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
703
720
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
@@ -735,7 +752,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
735
752
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
736
753
|
idSpans.add(node.id.span.start);
|
|
737
754
|
}
|
|
738
|
-
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
755
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
739
756
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
740
757
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
741
758
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
@@ -817,7 +834,9 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
817
834
|
if (processedDecls.has(node))
|
|
818
835
|
return;
|
|
819
836
|
node.declarations.forEach((decl) => {
|
|
820
|
-
registerStyle(decl, node.span,
|
|
837
|
+
registerStyle(decl, node.span, node.declarations.length > 1 ||
|
|
838
|
+
(utils_1.t.isIdentifier(decl.id) &&
|
|
839
|
+
separatelyExported.has(decl.id.value)));
|
|
821
840
|
checkStyleAliasAssignment(decl);
|
|
822
841
|
});
|
|
823
842
|
},
|
|
@@ -850,7 +869,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
850
869
|
if (propName === 'keyframes' && args.length > 0) {
|
|
851
870
|
const expr = args[0].expression;
|
|
852
871
|
if (utils_1.t.isObjectExpression(expr)) {
|
|
853
|
-
const obj = (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
872
|
+
const obj = (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
854
873
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
855
874
|
scannedTables.keyframesObjectTable[hash] = obj;
|
|
856
875
|
replacements.push({
|
|
@@ -863,7 +882,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
863
882
|
else if (propName === 'viewTransition' &&
|
|
864
883
|
args.length > 0 &&
|
|
865
884
|
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
|
|
885
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
867
886
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
868
887
|
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
869
888
|
replacements.push({
|
|
@@ -884,7 +903,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
884
903
|
if (selector.startsWith('@') && !(0, zss_engine_1.isAtRule)(selector)) {
|
|
885
904
|
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
886
905
|
}
|
|
887
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
906
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
888
907
|
const hash = (0, utils_1.themeHashOf)(selector, obj);
|
|
889
908
|
scannedTables.createThemeObjectTable[hash] = obj;
|
|
890
909
|
if (scannedTables.createThemeSelectorTable) {
|
|
@@ -894,14 +913,14 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
894
913
|
else if (propName === 'createStatic' &&
|
|
895
914
|
args.length > 0 &&
|
|
896
915
|
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
|
|
916
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
898
917
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
899
918
|
scannedTables.createStaticObjectTable[hash] = obj;
|
|
900
919
|
}
|
|
901
920
|
else if (propName === 'create' &&
|
|
902
921
|
args.length > 0 &&
|
|
903
922
|
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
|
|
923
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
905
924
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
906
925
|
scannedTables.createObjectTable[hash] = obj;
|
|
907
926
|
}
|
|
@@ -957,9 +976,22 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
957
976
|
const end = node.span.end - baseByteOffset;
|
|
958
977
|
return sourceBuffer.subarray(start, end).toString('utf-8');
|
|
959
978
|
};
|
|
979
|
+
const isVisibleReference = (expr) => {
|
|
980
|
+
if (utils_1.t.isIdentifier(expr))
|
|
981
|
+
return referenceIdents.references.has(expr.span.start);
|
|
982
|
+
if (utils_1.t.isMemberExpression(expr))
|
|
983
|
+
return isVisibleReference(expr.object);
|
|
984
|
+
if (utils_1.t.isCallExpression(expr) &&
|
|
985
|
+
expr.callee.type !== 'Super' &&
|
|
986
|
+
expr.callee.type !== 'Import')
|
|
987
|
+
return isVisibleReference(expr.callee);
|
|
988
|
+
return true;
|
|
989
|
+
};
|
|
960
990
|
const resolveStyleObject = (expr) => {
|
|
961
991
|
expr = (0, utils_1.unwrapExpression)(expr);
|
|
962
992
|
expr = resolveLocalStyleAlias(localStyleAliases, expr);
|
|
993
|
+
if (!isVisibleReference(expr))
|
|
994
|
+
return null;
|
|
963
995
|
if (expr.type === 'ArrayExpression') {
|
|
964
996
|
let merged = {};
|
|
965
997
|
for (const element of expr.elements ?? []) {
|
|
@@ -975,7 +1007,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
975
1007
|
return merged;
|
|
976
1008
|
}
|
|
977
1009
|
if (utils_1.t.isObjectExpression(expr)) {
|
|
978
|
-
return (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
1010
|
+
return (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
979
1011
|
}
|
|
980
1012
|
else if (utils_1.t.isMemberExpression(expr) &&
|
|
981
1013
|
utils_1.t.isIdentifier(expr.object) &&
|
|
@@ -1018,9 +1050,6 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1018
1050
|
const styleInfo = localCreateStyles[varName];
|
|
1019
1051
|
if (styleInfo?.obj)
|
|
1020
1052
|
return styleInfo.obj;
|
|
1021
|
-
const vHash = mergedVariantsTable[varName];
|
|
1022
|
-
if (vHash)
|
|
1023
|
-
return scannedTables.variantsObjectTable[vHash];
|
|
1024
1053
|
}
|
|
1025
1054
|
return null;
|
|
1026
1055
|
};
|
|
@@ -1059,6 +1088,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1059
1088
|
const callee = expr.callee;
|
|
1060
1089
|
if (!utils_1.t.isIdentifier(callee.object) || !utils_1.t.isIdentifier(callee.property))
|
|
1061
1090
|
return null;
|
|
1091
|
+
if (!isVisibleReference(callee.object))
|
|
1092
|
+
return null;
|
|
1062
1093
|
const styleInfo = localCreateStyles[callee.object.value];
|
|
1063
1094
|
const func = styleInfo?.functions?.[callee.property.value] ??
|
|
1064
1095
|
createFunctionImportMap[callee.object.value]?.[callee.property.value];
|
|
@@ -1075,7 +1106,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1075
1106
|
properties: argExpr.properties.filter((prop) => prop.type === 'Identifier' ||
|
|
1076
1107
|
(prop.type === 'KeyValueProperty' &&
|
|
1077
1108
|
isStaticArgValue(prop.value))),
|
|
1078
|
-
}, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
1109
|
+
}, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
1079
1110
|
if (func.named) {
|
|
1080
1111
|
const argExpr = callArgs[0]?.expression;
|
|
1081
1112
|
if (callArgs.length > 1 ||
|
|
@@ -1199,6 +1230,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1199
1230
|
utils_1.t.isStringLiteral(node.property.expression)) {
|
|
1200
1231
|
return null;
|
|
1201
1232
|
}
|
|
1233
|
+
if (!isVisibleReference(node.object))
|
|
1234
|
+
return null;
|
|
1202
1235
|
const varName = node.object.value;
|
|
1203
1236
|
const obj = resolveCreateObject(varName);
|
|
1204
1237
|
return obj
|
|
@@ -1299,6 +1332,15 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1299
1332
|
node = resolveLocalStyleAlias(localStyleAliases, node);
|
|
1300
1333
|
if (isNoOpStyle(node))
|
|
1301
1334
|
return true;
|
|
1335
|
+
if (node.type === 'ArrayExpression') {
|
|
1336
|
+
return node.elements.every((element) => {
|
|
1337
|
+
if (!element)
|
|
1338
|
+
return true;
|
|
1339
|
+
if (element.spread)
|
|
1340
|
+
throwCompilationError(spreadStyleMessage(getSource(element.expression)), element.expression);
|
|
1341
|
+
return collectConditions(element.expression, currentTestStrings, argOrder);
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1302
1344
|
let branchStyle = resolveStyleObject(node);
|
|
1303
1345
|
if (!branchStyle) {
|
|
1304
1346
|
const dynamic = resolveDynamicCall(node);
|
|
@@ -1351,14 +1393,13 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1351
1393
|
return true;
|
|
1352
1394
|
}
|
|
1353
1395
|
}
|
|
1354
|
-
collectConditions(node.consequent, [...currentTestStrings, `(${testSource})`], argOrder);
|
|
1355
|
-
collectConditions(node.alternate, [...currentTestStrings, `!(${testSource})`], argOrder);
|
|
1356
|
-
return
|
|
1396
|
+
const consequentHandled = collectConditions(node.consequent, [...currentTestStrings, `(${testSource})`], argOrder);
|
|
1397
|
+
const alternateHandled = collectConditions(node.alternate, [...currentTestStrings, `!(${testSource})`], argOrder);
|
|
1398
|
+
return consequentHandled && alternateHandled;
|
|
1357
1399
|
}
|
|
1358
1400
|
else if (node.type === 'BinaryExpression' &&
|
|
1359
1401
|
node.operator === '&&') {
|
|
1360
|
-
collectConditions(node.right, [...currentTestStrings, `(${getSource(node.left)})`], argOrder);
|
|
1361
|
-
return true;
|
|
1402
|
+
return collectConditions(node.right, [...currentTestStrings, `(${getSource(node.left)})`], argOrder);
|
|
1362
1403
|
}
|
|
1363
1404
|
else if (node.type === 'ParenthesisExpression') {
|
|
1364
1405
|
return collectConditions(node.expression, currentTestStrings, argOrder);
|
|
@@ -1489,14 +1530,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1489
1530
|
continue;
|
|
1490
1531
|
if (utils_1.t.isCallExpression(expr) && utils_1.t.isIdentifier(expr.callee)) {
|
|
1491
1532
|
const varName = expr.callee.value;
|
|
1492
|
-
const uniqueKey = `${resourcePath}-${varName}`;
|
|
1493
1533
|
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)
|
|
1534
|
+
if (isVisibleReference(expr) && localCreateStyles[varName]?.obj)
|
|
1500
1535
|
variantObj = localCreateStyles[varName].obj;
|
|
1501
1536
|
if (variantObj) {
|
|
1502
1537
|
const callArgs = expr.arguments;
|
|
@@ -1600,14 +1635,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1600
1635
|
}
|
|
1601
1636
|
else if (utils_1.t.isIdentifier(expr)) {
|
|
1602
1637
|
const varName = expr.value;
|
|
1603
|
-
const uniqueKey = `${resourcePath}-${varName}`;
|
|
1604
1638
|
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)
|
|
1639
|
+
if (isVisibleReference(expr) && localCreateStyles[varName]?.obj)
|
|
1611
1640
|
variantObj = localCreateStyles[varName].obj;
|
|
1612
1641
|
if (variantObj) {
|
|
1613
1642
|
Object.entries(variantObj).forEach(([groupName, groupVariants]) => {
|
|
@@ -1637,7 +1666,9 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1637
1666
|
utils_1.t.isIdentifier(expr.object) &&
|
|
1638
1667
|
expr.property.type === 'Computed') {
|
|
1639
1668
|
const varName = expr.object.value;
|
|
1640
|
-
const styleObj =
|
|
1669
|
+
const styleObj = isVisibleReference(expr)
|
|
1670
|
+
? resolveCreateObject(varName)
|
|
1671
|
+
: null;
|
|
1641
1672
|
if (styleObj) {
|
|
1642
1673
|
const dynExpr = expr.property.expression;
|
|
1643
1674
|
const dynSource = getSource(dynExpr);
|
|
@@ -1966,6 +1997,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1966
1997
|
});
|
|
1967
1998
|
},
|
|
1968
1999
|
MemberExpression({ node }) {
|
|
2000
|
+
if (!isVisibleReference(node))
|
|
2001
|
+
return;
|
|
1969
2002
|
if (utils_1.t.isIdentifier(node.object) &&
|
|
1970
2003
|
(utils_1.t.isIdentifier(node.property) || node.property.type === 'Computed')) {
|
|
1971
2004
|
const varName = node.object.value;
|
|
@@ -2234,7 +2267,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2234
2267
|
const expr = node.value.expression;
|
|
2235
2268
|
const args = expr.type === 'ArrayExpression'
|
|
2236
2269
|
? expr.elements
|
|
2237
|
-
.filter((el) => el
|
|
2270
|
+
.filter((el) => el != null)
|
|
2238
2271
|
.map((el) => {
|
|
2239
2272
|
if (el.spread)
|
|
2240
2273
|
throwCompilationError(spreadStyleMessage(getSource(el.expression)), el.expression);
|
|
@@ -2267,13 +2300,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2267
2300
|
existingClassExpr = JSON.stringify(classNameAttr.value.value);
|
|
2268
2301
|
}
|
|
2269
2302
|
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')})`;
|
|
2303
|
+
existingClassExpr = `(${deferSource(classNameAttr.value.expression)})`;
|
|
2277
2304
|
}
|
|
2278
2305
|
}
|
|
2279
2306
|
const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
|
|
@@ -2288,22 +2315,22 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2288
2315
|
});
|
|
2289
2316
|
if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
|
|
2290
2317
|
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
2318
|
if (innerExpr.type === 'ObjectExpression') {
|
|
2297
|
-
const
|
|
2298
|
-
|
|
2299
|
-
|
|
2319
|
+
for (const property of innerExpr.properties) {
|
|
2320
|
+
const token = deferProperty(property);
|
|
2321
|
+
if (token)
|
|
2322
|
+
existingStyleParts.push(token);
|
|
2323
|
+
}
|
|
2300
2324
|
}
|
|
2301
2325
|
else {
|
|
2302
|
-
existingStyleExpr = `...(${
|
|
2326
|
+
existingStyleExpr = `...(${deferSource(innerExpr)})`;
|
|
2303
2327
|
}
|
|
2304
2328
|
}
|
|
2305
2329
|
}
|
|
2306
2330
|
const { classParts, isOptimizable, baseStyle, dynamicVars, propVarSpreads, } = buildClassParts(args, dynamicClassParts, existingClassExpr, true);
|
|
2331
|
+
if (!isOptimizable) {
|
|
2332
|
+
throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(expr)}" is not supported.`, expr);
|
|
2333
|
+
}
|
|
2307
2334
|
const styleParts = [
|
|
2308
2335
|
...existingStyleParts,
|
|
2309
2336
|
...foldDynamicVars(dynamicVars),
|
|
@@ -2442,6 +2469,20 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2442
2469
|
`so it cannot be passed through another prop or read as a value.`, call);
|
|
2443
2470
|
}
|
|
2444
2471
|
});
|
|
2472
|
+
for (const deferred of deferredSources) {
|
|
2473
|
+
let cursor = deferred.start;
|
|
2474
|
+
const pieces = [];
|
|
2475
|
+
for (const replacement of [...replacements].sort((a, b) => a.start - b.start || b.end - a.end)) {
|
|
2476
|
+
if (replacement.start < cursor || replacement.end > deferred.end)
|
|
2477
|
+
continue;
|
|
2478
|
+
pieces.push(sourceBuffer.subarray(cursor, replacement.start).toString('utf-8'), replacement.content);
|
|
2479
|
+
cursor = replacement.end;
|
|
2480
|
+
}
|
|
2481
|
+
pieces.push(sourceBuffer.subarray(cursor, deferred.end).toString('utf-8'));
|
|
2482
|
+
const content = pieces.join('');
|
|
2483
|
+
for (const replacement of replacements)
|
|
2484
|
+
replacement.content = replacement.content.replaceAll(deferred.token, content);
|
|
2485
|
+
}
|
|
2445
2486
|
const buffer = Buffer.from(source);
|
|
2446
2487
|
let offset = 0;
|
|
2447
2488
|
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,39 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
530
516
|
}
|
|
531
517
|
};
|
|
532
518
|
const replacements = [];
|
|
519
|
+
const deferredSources = [];
|
|
520
|
+
const deferRange = (start, end) => {
|
|
521
|
+
const token = `__plumeria_preserved_${deferredSources.length}__`;
|
|
522
|
+
deferredSources.push({ token, start, end });
|
|
523
|
+
return token;
|
|
524
|
+
};
|
|
525
|
+
const deferSource = (node) => deferRange(node.span.start - baseByteOffset, node.span.end - baseByteOffset);
|
|
526
|
+
const deferProperty = (property) => {
|
|
527
|
+
const node = property;
|
|
528
|
+
const range = node.spread && node.arguments
|
|
529
|
+
? { start: node.spread.start, end: node.arguments.span.end }
|
|
530
|
+
: node.span
|
|
531
|
+
? { start: node.span.start, end: node.span.end }
|
|
532
|
+
: node.key && node.value
|
|
533
|
+
? { start: node.key.span.start, end: node.value.span.end }
|
|
534
|
+
: null;
|
|
535
|
+
return range
|
|
536
|
+
? deferRange(range.start - baseByteOffset, range.end - baseByteOffset)
|
|
537
|
+
: null;
|
|
538
|
+
};
|
|
533
539
|
const dynamicFnCalls = [];
|
|
534
540
|
const processedDecls = new Set();
|
|
541
|
+
const separatelyExported = new Set();
|
|
542
|
+
for (const statement of ast.body) {
|
|
543
|
+
if (statement.type !== 'ExportNamedDeclaration' || statement.source)
|
|
544
|
+
continue;
|
|
545
|
+
for (const specifier of statement.specifiers) {
|
|
546
|
+
if (specifier.type === 'ExportSpecifier' &&
|
|
547
|
+
t.isIdentifier(specifier.orig)) {
|
|
548
|
+
separatelyExported.add(specifier.orig.value);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
535
552
|
const idSpans = new Set();
|
|
536
553
|
const excludedSpans = new Set();
|
|
537
554
|
const referenceIdents = collectReferenceIdentifiers(ast);
|
|
@@ -611,7 +628,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
611
628
|
}
|
|
612
629
|
if (propName === 'create' &&
|
|
613
630
|
t.isObjectExpression(init.arguments[0].expression)) {
|
|
614
|
-
const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
631
|
+
const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
615
632
|
if (obj) {
|
|
616
633
|
const hashMap = {};
|
|
617
634
|
Object.entries(obj).forEach(([key, style]) => {
|
|
@@ -661,7 +678,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
661
678
|
if (selector.startsWith('@') && !isAtRule(selector)) {
|
|
662
679
|
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
663
680
|
}
|
|
664
|
-
const obj = objectExpressionToObject(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
681
|
+
const obj = objectExpressionToObject(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
665
682
|
const hash = themeHashOf(selector, obj);
|
|
666
683
|
if (t.isIdentifier(node.id)) {
|
|
667
684
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
@@ -699,7 +716,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
699
716
|
if (t.isIdentifier(node.id)) {
|
|
700
717
|
idSpans.add(node.id.span.start);
|
|
701
718
|
}
|
|
702
|
-
const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
719
|
+
const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
703
720
|
const hash = genBase36Hash(obj, 1, 8);
|
|
704
721
|
if (t.isIdentifier(node.id)) {
|
|
705
722
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
@@ -781,7 +798,9 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
781
798
|
if (processedDecls.has(node))
|
|
782
799
|
return;
|
|
783
800
|
node.declarations.forEach((decl) => {
|
|
784
|
-
registerStyle(decl, node.span,
|
|
801
|
+
registerStyle(decl, node.span, node.declarations.length > 1 ||
|
|
802
|
+
(t.isIdentifier(decl.id) &&
|
|
803
|
+
separatelyExported.has(decl.id.value)));
|
|
785
804
|
checkStyleAliasAssignment(decl);
|
|
786
805
|
});
|
|
787
806
|
},
|
|
@@ -814,7 +833,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
814
833
|
if (propName === 'keyframes' && args.length > 0) {
|
|
815
834
|
const expr = args[0].expression;
|
|
816
835
|
if (t.isObjectExpression(expr)) {
|
|
817
|
-
const obj = objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
836
|
+
const obj = objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
818
837
|
const hash = genBase36Hash(obj, 1, 8);
|
|
819
838
|
scannedTables.keyframesObjectTable[hash] = obj;
|
|
820
839
|
replacements.push({
|
|
@@ -827,7 +846,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
827
846
|
else if (propName === 'viewTransition' &&
|
|
828
847
|
args.length > 0 &&
|
|
829
848
|
t.isObjectExpression(args[0].expression)) {
|
|
830
|
-
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
849
|
+
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
831
850
|
const hash = genBase36Hash(obj, 1, 8);
|
|
832
851
|
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
833
852
|
replacements.push({
|
|
@@ -848,7 +867,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
848
867
|
if (selector.startsWith('@') && !isAtRule(selector)) {
|
|
849
868
|
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
850
869
|
}
|
|
851
|
-
const obj = objectExpressionToObject(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
870
|
+
const obj = objectExpressionToObject(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
852
871
|
const hash = themeHashOf(selector, obj);
|
|
853
872
|
scannedTables.createThemeObjectTable[hash] = obj;
|
|
854
873
|
if (scannedTables.createThemeSelectorTable) {
|
|
@@ -858,14 +877,14 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
858
877
|
else if (propName === 'createStatic' &&
|
|
859
878
|
args.length > 0 &&
|
|
860
879
|
t.isObjectExpression(args[0].expression)) {
|
|
861
|
-
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
880
|
+
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
862
881
|
const hash = genBase36Hash(obj, 1, 8);
|
|
863
882
|
scannedTables.createStaticObjectTable[hash] = obj;
|
|
864
883
|
}
|
|
865
884
|
else if (propName === 'create' &&
|
|
866
885
|
args.length > 0 &&
|
|
867
886
|
t.isObjectExpression(args[0].expression)) {
|
|
868
|
-
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
887
|
+
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
869
888
|
const hash = genBase36Hash(obj, 1, 8);
|
|
870
889
|
scannedTables.createObjectTable[hash] = obj;
|
|
871
890
|
}
|
|
@@ -921,9 +940,22 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
921
940
|
const end = node.span.end - baseByteOffset;
|
|
922
941
|
return sourceBuffer.subarray(start, end).toString('utf-8');
|
|
923
942
|
};
|
|
943
|
+
const isVisibleReference = (expr) => {
|
|
944
|
+
if (t.isIdentifier(expr))
|
|
945
|
+
return referenceIdents.references.has(expr.span.start);
|
|
946
|
+
if (t.isMemberExpression(expr))
|
|
947
|
+
return isVisibleReference(expr.object);
|
|
948
|
+
if (t.isCallExpression(expr) &&
|
|
949
|
+
expr.callee.type !== 'Super' &&
|
|
950
|
+
expr.callee.type !== 'Import')
|
|
951
|
+
return isVisibleReference(expr.callee);
|
|
952
|
+
return true;
|
|
953
|
+
};
|
|
924
954
|
const resolveStyleObject = (expr) => {
|
|
925
955
|
expr = unwrapExpression(expr);
|
|
926
956
|
expr = resolveLocalStyleAlias(localStyleAliases, expr);
|
|
957
|
+
if (!isVisibleReference(expr))
|
|
958
|
+
return null;
|
|
927
959
|
if (expr.type === 'ArrayExpression') {
|
|
928
960
|
let merged = {};
|
|
929
961
|
for (const element of expr.elements ?? []) {
|
|
@@ -939,7 +971,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
939
971
|
return merged;
|
|
940
972
|
}
|
|
941
973
|
if (t.isObjectExpression(expr)) {
|
|
942
|
-
return objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
974
|
+
return objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
943
975
|
}
|
|
944
976
|
else if (t.isMemberExpression(expr) &&
|
|
945
977
|
t.isIdentifier(expr.object) &&
|
|
@@ -982,9 +1014,6 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
982
1014
|
const styleInfo = localCreateStyles[varName];
|
|
983
1015
|
if (styleInfo?.obj)
|
|
984
1016
|
return styleInfo.obj;
|
|
985
|
-
const vHash = mergedVariantsTable[varName];
|
|
986
|
-
if (vHash)
|
|
987
|
-
return scannedTables.variantsObjectTable[vHash];
|
|
988
1017
|
}
|
|
989
1018
|
return null;
|
|
990
1019
|
};
|
|
@@ -1023,6 +1052,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1023
1052
|
const callee = expr.callee;
|
|
1024
1053
|
if (!t.isIdentifier(callee.object) || !t.isIdentifier(callee.property))
|
|
1025
1054
|
return null;
|
|
1055
|
+
if (!isVisibleReference(callee.object))
|
|
1056
|
+
return null;
|
|
1026
1057
|
const styleInfo = localCreateStyles[callee.object.value];
|
|
1027
1058
|
const func = styleInfo?.functions?.[callee.property.value] ??
|
|
1028
1059
|
createFunctionImportMap[callee.object.value]?.[callee.property.value];
|
|
@@ -1039,7 +1070,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1039
1070
|
properties: argExpr.properties.filter((prop) => prop.type === 'Identifier' ||
|
|
1040
1071
|
(prop.type === 'KeyValueProperty' &&
|
|
1041
1072
|
isStaticArgValue(prop.value))),
|
|
1042
|
-
}, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable
|
|
1073
|
+
}, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable);
|
|
1043
1074
|
if (func.named) {
|
|
1044
1075
|
const argExpr = callArgs[0]?.expression;
|
|
1045
1076
|
if (callArgs.length > 1 ||
|
|
@@ -1163,6 +1194,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1163
1194
|
t.isStringLiteral(node.property.expression)) {
|
|
1164
1195
|
return null;
|
|
1165
1196
|
}
|
|
1197
|
+
if (!isVisibleReference(node.object))
|
|
1198
|
+
return null;
|
|
1166
1199
|
const varName = node.object.value;
|
|
1167
1200
|
const obj = resolveCreateObject(varName);
|
|
1168
1201
|
return obj
|
|
@@ -1263,6 +1296,15 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1263
1296
|
node = resolveLocalStyleAlias(localStyleAliases, node);
|
|
1264
1297
|
if (isNoOpStyle(node))
|
|
1265
1298
|
return true;
|
|
1299
|
+
if (node.type === 'ArrayExpression') {
|
|
1300
|
+
return node.elements.every((element) => {
|
|
1301
|
+
if (!element)
|
|
1302
|
+
return true;
|
|
1303
|
+
if (element.spread)
|
|
1304
|
+
throwCompilationError(spreadStyleMessage(getSource(element.expression)), element.expression);
|
|
1305
|
+
return collectConditions(element.expression, currentTestStrings, argOrder);
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1266
1308
|
let branchStyle = resolveStyleObject(node);
|
|
1267
1309
|
if (!branchStyle) {
|
|
1268
1310
|
const dynamic = resolveDynamicCall(node);
|
|
@@ -1315,14 +1357,13 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1315
1357
|
return true;
|
|
1316
1358
|
}
|
|
1317
1359
|
}
|
|
1318
|
-
collectConditions(node.consequent, [...currentTestStrings, `(${testSource})`], argOrder);
|
|
1319
|
-
collectConditions(node.alternate, [...currentTestStrings, `!(${testSource})`], argOrder);
|
|
1320
|
-
return
|
|
1360
|
+
const consequentHandled = collectConditions(node.consequent, [...currentTestStrings, `(${testSource})`], argOrder);
|
|
1361
|
+
const alternateHandled = collectConditions(node.alternate, [...currentTestStrings, `!(${testSource})`], argOrder);
|
|
1362
|
+
return consequentHandled && alternateHandled;
|
|
1321
1363
|
}
|
|
1322
1364
|
else if (node.type === 'BinaryExpression' &&
|
|
1323
1365
|
node.operator === '&&') {
|
|
1324
|
-
collectConditions(node.right, [...currentTestStrings, `(${getSource(node.left)})`], argOrder);
|
|
1325
|
-
return true;
|
|
1366
|
+
return collectConditions(node.right, [...currentTestStrings, `(${getSource(node.left)})`], argOrder);
|
|
1326
1367
|
}
|
|
1327
1368
|
else if (node.type === 'ParenthesisExpression') {
|
|
1328
1369
|
return collectConditions(node.expression, currentTestStrings, argOrder);
|
|
@@ -1453,14 +1494,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1453
1494
|
continue;
|
|
1454
1495
|
if (t.isCallExpression(expr) && t.isIdentifier(expr.callee)) {
|
|
1455
1496
|
const varName = expr.callee.value;
|
|
1456
|
-
const uniqueKey = `${resourcePath}-${varName}`;
|
|
1457
1497
|
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)
|
|
1498
|
+
if (isVisibleReference(expr) && localCreateStyles[varName]?.obj)
|
|
1464
1499
|
variantObj = localCreateStyles[varName].obj;
|
|
1465
1500
|
if (variantObj) {
|
|
1466
1501
|
const callArgs = expr.arguments;
|
|
@@ -1564,14 +1599,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1564
1599
|
}
|
|
1565
1600
|
else if (t.isIdentifier(expr)) {
|
|
1566
1601
|
const varName = expr.value;
|
|
1567
|
-
const uniqueKey = `${resourcePath}-${varName}`;
|
|
1568
1602
|
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)
|
|
1603
|
+
if (isVisibleReference(expr) && localCreateStyles[varName]?.obj)
|
|
1575
1604
|
variantObj = localCreateStyles[varName].obj;
|
|
1576
1605
|
if (variantObj) {
|
|
1577
1606
|
Object.entries(variantObj).forEach(([groupName, groupVariants]) => {
|
|
@@ -1601,7 +1630,9 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1601
1630
|
t.isIdentifier(expr.object) &&
|
|
1602
1631
|
expr.property.type === 'Computed') {
|
|
1603
1632
|
const varName = expr.object.value;
|
|
1604
|
-
const styleObj =
|
|
1633
|
+
const styleObj = isVisibleReference(expr)
|
|
1634
|
+
? resolveCreateObject(varName)
|
|
1635
|
+
: null;
|
|
1605
1636
|
if (styleObj) {
|
|
1606
1637
|
const dynExpr = expr.property.expression;
|
|
1607
1638
|
const dynSource = getSource(dynExpr);
|
|
@@ -1930,6 +1961,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1930
1961
|
});
|
|
1931
1962
|
},
|
|
1932
1963
|
MemberExpression({ node }) {
|
|
1964
|
+
if (!isVisibleReference(node))
|
|
1965
|
+
return;
|
|
1933
1966
|
if (t.isIdentifier(node.object) &&
|
|
1934
1967
|
(t.isIdentifier(node.property) || node.property.type === 'Computed')) {
|
|
1935
1968
|
const varName = node.object.value;
|
|
@@ -2198,7 +2231,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2198
2231
|
const expr = node.value.expression;
|
|
2199
2232
|
const args = expr.type === 'ArrayExpression'
|
|
2200
2233
|
? expr.elements
|
|
2201
|
-
.filter((el) => el
|
|
2234
|
+
.filter((el) => el != null)
|
|
2202
2235
|
.map((el) => {
|
|
2203
2236
|
if (el.spread)
|
|
2204
2237
|
throwCompilationError(spreadStyleMessage(getSource(el.expression)), el.expression);
|
|
@@ -2231,13 +2264,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2231
2264
|
existingClassExpr = JSON.stringify(classNameAttr.value.value);
|
|
2232
2265
|
}
|
|
2233
2266
|
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')})`;
|
|
2267
|
+
existingClassExpr = `(${deferSource(classNameAttr.value.expression)})`;
|
|
2241
2268
|
}
|
|
2242
2269
|
}
|
|
2243
2270
|
const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
|
|
@@ -2252,22 +2279,22 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2252
2279
|
});
|
|
2253
2280
|
if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
|
|
2254
2281
|
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
2282
|
if (innerExpr.type === 'ObjectExpression') {
|
|
2261
|
-
const
|
|
2262
|
-
|
|
2263
|
-
|
|
2283
|
+
for (const property of innerExpr.properties) {
|
|
2284
|
+
const token = deferProperty(property);
|
|
2285
|
+
if (token)
|
|
2286
|
+
existingStyleParts.push(token);
|
|
2287
|
+
}
|
|
2264
2288
|
}
|
|
2265
2289
|
else {
|
|
2266
|
-
existingStyleExpr = `...(${
|
|
2290
|
+
existingStyleExpr = `...(${deferSource(innerExpr)})`;
|
|
2267
2291
|
}
|
|
2268
2292
|
}
|
|
2269
2293
|
}
|
|
2270
2294
|
const { classParts, isOptimizable, baseStyle, dynamicVars, propVarSpreads, } = buildClassParts(args, dynamicClassParts, existingClassExpr, true);
|
|
2295
|
+
if (!isOptimizable) {
|
|
2296
|
+
throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(expr)}" is not supported.`, expr);
|
|
2297
|
+
}
|
|
2271
2298
|
const styleParts = [
|
|
2272
2299
|
...existingStyleParts,
|
|
2273
2300
|
...foldDynamicVars(dynamicVars),
|
|
@@ -2406,6 +2433,20 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2406
2433
|
`so it cannot be passed through another prop or read as a value.`, call);
|
|
2407
2434
|
}
|
|
2408
2435
|
});
|
|
2436
|
+
for (const deferred of deferredSources) {
|
|
2437
|
+
let cursor = deferred.start;
|
|
2438
|
+
const pieces = [];
|
|
2439
|
+
for (const replacement of [...replacements].sort((a, b) => a.start - b.start || b.end - a.end)) {
|
|
2440
|
+
if (replacement.start < cursor || replacement.end > deferred.end)
|
|
2441
|
+
continue;
|
|
2442
|
+
pieces.push(sourceBuffer.subarray(cursor, replacement.start).toString('utf-8'), replacement.content);
|
|
2443
|
+
cursor = replacement.end;
|
|
2444
|
+
}
|
|
2445
|
+
pieces.push(sourceBuffer.subarray(cursor, deferred.end).toString('utf-8'));
|
|
2446
|
+
const content = pieces.join('');
|
|
2447
|
+
for (const replacement of replacements)
|
|
2448
|
+
replacement.content = replacement.content.replaceAll(deferred.token, content);
|
|
2449
|
+
}
|
|
2409
2450
|
const buffer = Buffer.from(source);
|
|
2410
2451
|
let offset = 0;
|
|
2411
2452
|
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.4",
|
|
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.4"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"@swc/core": "1.15.47",
|