@plumeria/unplugin 18.2.2 → 18.2.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 +94 -44
- package/dist/core.mjs +94 -44
- package/package.json +2 -2
package/dist/core.js
CHANGED
|
@@ -250,6 +250,33 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
250
250
|
addDependency(parentFile);
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
|
+
const components = [];
|
|
254
|
+
for (const node of ast.body) {
|
|
255
|
+
const statement = utils_1.t.isExportDeclaration(node) ? node.declaration : node;
|
|
256
|
+
if (statement.type === 'FunctionDeclaration' && statement.identifier) {
|
|
257
|
+
components.push({
|
|
258
|
+
name: statement.identifier.value,
|
|
259
|
+
node: statement,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
else if (utils_1.t.isVariableDeclaration(statement)) {
|
|
263
|
+
for (const decl of statement.declarations) {
|
|
264
|
+
if (utils_1.t.isIdentifier(decl.id) &&
|
|
265
|
+
(decl.init?.type === 'ArrowFunctionExpression' ||
|
|
266
|
+
decl.init?.type === 'FunctionExpression')) {
|
|
267
|
+
components.push({ name: decl.id.value, node: decl.init });
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const appliedStyleProps = new Set();
|
|
273
|
+
const markStylePropApplied = (name, at) => {
|
|
274
|
+
const owner = components.find((c) => at.span.start >= c.node.span.start &&
|
|
275
|
+
at.span.start <= c.node.span.end);
|
|
276
|
+
if (owner) {
|
|
277
|
+
appliedStyleProps.add(`${owner.name}:${name}`);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
253
280
|
const extractedSheets = [];
|
|
254
281
|
const addSheet = (sheet) => {
|
|
255
282
|
if (!extractedSheets.includes(sheet)) {
|
|
@@ -1165,56 +1192,68 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1165
1192
|
else if (node.type === 'ParenthesisExpression') {
|
|
1166
1193
|
return collectConditions(node.expression, currentTestStrings, argOrder);
|
|
1167
1194
|
}
|
|
1195
|
+
if (pushPropPossibilities(node, currentTestStrings))
|
|
1196
|
+
return true;
|
|
1168
1197
|
assertResolvable(node);
|
|
1169
1198
|
return false;
|
|
1170
1199
|
};
|
|
1171
|
-
|
|
1172
|
-
const
|
|
1173
|
-
|
|
1174
|
-
(
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
propPossibilities =
|
|
1187
|
-
scannedTables.componentPropsTable?.[key]?.[varName];
|
|
1188
|
-
break;
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
if (propPossibilities && propPossibilities.length > 0) {
|
|
1193
|
-
const currentGroupId = ++groupIdCounter;
|
|
1194
|
-
const currentOrder = sourceOrder++;
|
|
1195
|
-
const uniqueEntries = [];
|
|
1196
|
-
propPossibilities.forEach((entry) => {
|
|
1197
|
-
if (!uniqueEntries.some((x) => x.key === entry.key)) {
|
|
1198
|
-
uniqueEntries.push(entry);
|
|
1199
|
-
}
|
|
1200
|
-
});
|
|
1201
|
-
uniqueEntries.forEach((entry) => {
|
|
1202
|
-
conditionals.push({
|
|
1203
|
-
test: expr,
|
|
1204
|
-
testLHS,
|
|
1205
|
-
testString: `${testLHS} === ${JSON.stringify(entry.key)}`,
|
|
1206
|
-
truthy: entry.styleObj,
|
|
1207
|
-
falsy: {},
|
|
1208
|
-
groupId: currentGroupId,
|
|
1209
|
-
order: currentOrder,
|
|
1210
|
-
groupName: undefined,
|
|
1211
|
-
valueName: entry.key,
|
|
1212
|
-
varName,
|
|
1213
|
-
});
|
|
1214
|
-
});
|
|
1200
|
+
const pushPropPossibilities = (expr, gates) => {
|
|
1201
|
+
const isParamMember = utils_1.t.isMemberExpression(expr) &&
|
|
1202
|
+
utils_1.t.isIdentifier(expr.object) &&
|
|
1203
|
+
componentParamNames.has(expr.object.value) &&
|
|
1204
|
+
utils_1.t.isIdentifier(expr.property);
|
|
1205
|
+
if (!utils_1.t.isIdentifier(expr) && !isParamMember)
|
|
1206
|
+
return false;
|
|
1207
|
+
const varName = utils_1.t.isIdentifier(expr)
|
|
1208
|
+
? expr.value
|
|
1209
|
+
: expr.property.value;
|
|
1210
|
+
const source = utils_1.t.isIdentifier(expr) ? varName : getSource(expr);
|
|
1211
|
+
markStylePropApplied(varName, expr);
|
|
1212
|
+
let possibilities;
|
|
1213
|
+
for (const key of Object.keys(scannedTables.componentPropsTable || {})) {
|
|
1214
|
+
if (!key.startsWith(`${resourcePath}-`))
|
|
1215
1215
|
continue;
|
|
1216
|
+
if (scannedTables.componentPropsTable?.[key]?.[varName]) {
|
|
1217
|
+
possibilities = scannedTables.componentPropsTable[key][varName];
|
|
1218
|
+
break;
|
|
1216
1219
|
}
|
|
1217
1220
|
}
|
|
1221
|
+
if (!possibilities || possibilities.length === 0)
|
|
1222
|
+
return false;
|
|
1223
|
+
const testLHS = gates.length
|
|
1224
|
+
? `((${gates.join(' && ')}) ? ${source} : "")`
|
|
1225
|
+
: source;
|
|
1226
|
+
const currentGroupId = ++groupIdCounter;
|
|
1227
|
+
const currentOrder = sourceOrder++;
|
|
1228
|
+
const seen = new Set();
|
|
1229
|
+
const pushOption = (valueName, style) => {
|
|
1230
|
+
conditionals.push({
|
|
1231
|
+
test: expr,
|
|
1232
|
+
testLHS,
|
|
1233
|
+
testString: `${testLHS} === ${JSON.stringify(valueName)}`,
|
|
1234
|
+
truthy: style,
|
|
1235
|
+
falsy: {},
|
|
1236
|
+
groupId: currentGroupId,
|
|
1237
|
+
order: currentOrder,
|
|
1238
|
+
groupName: undefined,
|
|
1239
|
+
valueName,
|
|
1240
|
+
varName,
|
|
1241
|
+
});
|
|
1242
|
+
};
|
|
1243
|
+
possibilities.forEach((entry) => {
|
|
1244
|
+
if (seen.has(entry.key))
|
|
1245
|
+
return;
|
|
1246
|
+
seen.add(entry.key);
|
|
1247
|
+
pushOption(entry.key, entry.styleObj);
|
|
1248
|
+
});
|
|
1249
|
+
if (gates.length)
|
|
1250
|
+
pushOption('', {});
|
|
1251
|
+
return true;
|
|
1252
|
+
};
|
|
1253
|
+
for (const arg of args) {
|
|
1254
|
+
const expr = arg.expression;
|
|
1255
|
+
if (pushPropPossibilities(expr, []))
|
|
1256
|
+
continue;
|
|
1218
1257
|
if (utils_1.t.isCallExpression(expr) && utils_1.t.isIdentifier(expr.callee)) {
|
|
1219
1258
|
const varName = expr.callee.value;
|
|
1220
1259
|
const uniqueKey = `${resourcePath}-${varName}`;
|
|
@@ -2049,6 +2088,17 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2049
2088
|
}
|
|
2050
2089
|
},
|
|
2051
2090
|
});
|
|
2091
|
+
for (const { name, node } of components) {
|
|
2092
|
+
const props = scannedTables.componentPropsTable?.[`${resourcePath}-${name}`];
|
|
2093
|
+
for (const propName of Object.keys(props ?? {})) {
|
|
2094
|
+
if (appliedStyleProps.has(`${name}:${propName}`)) {
|
|
2095
|
+
continue;
|
|
2096
|
+
}
|
|
2097
|
+
throwCompilationError(`Plumeria: "${propName}" is a style received through a prop but is never applied ` +
|
|
2098
|
+
`to ${styleProp} or css.use() here. Apply it on an element this component renders; ` +
|
|
2099
|
+
`a style prop cannot be passed on to another component.`, node);
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2052
2102
|
const buildExportedInit = (info) => {
|
|
2053
2103
|
const keys = Object.keys(info.obj);
|
|
2054
2104
|
if (!isDev || keys.length === 0) {
|
package/dist/core.mjs
CHANGED
|
@@ -214,6 +214,33 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
214
214
|
addDependency(parentFile);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
+
const components = [];
|
|
218
|
+
for (const node of ast.body) {
|
|
219
|
+
const statement = t.isExportDeclaration(node) ? node.declaration : node;
|
|
220
|
+
if (statement.type === 'FunctionDeclaration' && statement.identifier) {
|
|
221
|
+
components.push({
|
|
222
|
+
name: statement.identifier.value,
|
|
223
|
+
node: statement,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
else if (t.isVariableDeclaration(statement)) {
|
|
227
|
+
for (const decl of statement.declarations) {
|
|
228
|
+
if (t.isIdentifier(decl.id) &&
|
|
229
|
+
(decl.init?.type === 'ArrowFunctionExpression' ||
|
|
230
|
+
decl.init?.type === 'FunctionExpression')) {
|
|
231
|
+
components.push({ name: decl.id.value, node: decl.init });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const appliedStyleProps = new Set();
|
|
237
|
+
const markStylePropApplied = (name, at) => {
|
|
238
|
+
const owner = components.find((c) => at.span.start >= c.node.span.start &&
|
|
239
|
+
at.span.start <= c.node.span.end);
|
|
240
|
+
if (owner) {
|
|
241
|
+
appliedStyleProps.add(`${owner.name}:${name}`);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
217
244
|
const extractedSheets = [];
|
|
218
245
|
const addSheet = (sheet) => {
|
|
219
246
|
if (!extractedSheets.includes(sheet)) {
|
|
@@ -1129,56 +1156,68 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1129
1156
|
else if (node.type === 'ParenthesisExpression') {
|
|
1130
1157
|
return collectConditions(node.expression, currentTestStrings, argOrder);
|
|
1131
1158
|
}
|
|
1159
|
+
if (pushPropPossibilities(node, currentTestStrings))
|
|
1160
|
+
return true;
|
|
1132
1161
|
assertResolvable(node);
|
|
1133
1162
|
return false;
|
|
1134
1163
|
};
|
|
1135
|
-
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
propPossibilities =
|
|
1151
|
-
scannedTables.componentPropsTable?.[key]?.[varName];
|
|
1152
|
-
break;
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
if (propPossibilities && propPossibilities.length > 0) {
|
|
1157
|
-
const currentGroupId = ++groupIdCounter;
|
|
1158
|
-
const currentOrder = sourceOrder++;
|
|
1159
|
-
const uniqueEntries = [];
|
|
1160
|
-
propPossibilities.forEach((entry) => {
|
|
1161
|
-
if (!uniqueEntries.some((x) => x.key === entry.key)) {
|
|
1162
|
-
uniqueEntries.push(entry);
|
|
1163
|
-
}
|
|
1164
|
-
});
|
|
1165
|
-
uniqueEntries.forEach((entry) => {
|
|
1166
|
-
conditionals.push({
|
|
1167
|
-
test: expr,
|
|
1168
|
-
testLHS,
|
|
1169
|
-
testString: `${testLHS} === ${JSON.stringify(entry.key)}`,
|
|
1170
|
-
truthy: entry.styleObj,
|
|
1171
|
-
falsy: {},
|
|
1172
|
-
groupId: currentGroupId,
|
|
1173
|
-
order: currentOrder,
|
|
1174
|
-
groupName: undefined,
|
|
1175
|
-
valueName: entry.key,
|
|
1176
|
-
varName,
|
|
1177
|
-
});
|
|
1178
|
-
});
|
|
1164
|
+
const pushPropPossibilities = (expr, gates) => {
|
|
1165
|
+
const isParamMember = t.isMemberExpression(expr) &&
|
|
1166
|
+
t.isIdentifier(expr.object) &&
|
|
1167
|
+
componentParamNames.has(expr.object.value) &&
|
|
1168
|
+
t.isIdentifier(expr.property);
|
|
1169
|
+
if (!t.isIdentifier(expr) && !isParamMember)
|
|
1170
|
+
return false;
|
|
1171
|
+
const varName = t.isIdentifier(expr)
|
|
1172
|
+
? expr.value
|
|
1173
|
+
: expr.property.value;
|
|
1174
|
+
const source = t.isIdentifier(expr) ? varName : getSource(expr);
|
|
1175
|
+
markStylePropApplied(varName, expr);
|
|
1176
|
+
let possibilities;
|
|
1177
|
+
for (const key of Object.keys(scannedTables.componentPropsTable || {})) {
|
|
1178
|
+
if (!key.startsWith(`${resourcePath}-`))
|
|
1179
1179
|
continue;
|
|
1180
|
+
if (scannedTables.componentPropsTable?.[key]?.[varName]) {
|
|
1181
|
+
possibilities = scannedTables.componentPropsTable[key][varName];
|
|
1182
|
+
break;
|
|
1180
1183
|
}
|
|
1181
1184
|
}
|
|
1185
|
+
if (!possibilities || possibilities.length === 0)
|
|
1186
|
+
return false;
|
|
1187
|
+
const testLHS = gates.length
|
|
1188
|
+
? `((${gates.join(' && ')}) ? ${source} : "")`
|
|
1189
|
+
: source;
|
|
1190
|
+
const currentGroupId = ++groupIdCounter;
|
|
1191
|
+
const currentOrder = sourceOrder++;
|
|
1192
|
+
const seen = new Set();
|
|
1193
|
+
const pushOption = (valueName, style) => {
|
|
1194
|
+
conditionals.push({
|
|
1195
|
+
test: expr,
|
|
1196
|
+
testLHS,
|
|
1197
|
+
testString: `${testLHS} === ${JSON.stringify(valueName)}`,
|
|
1198
|
+
truthy: style,
|
|
1199
|
+
falsy: {},
|
|
1200
|
+
groupId: currentGroupId,
|
|
1201
|
+
order: currentOrder,
|
|
1202
|
+
groupName: undefined,
|
|
1203
|
+
valueName,
|
|
1204
|
+
varName,
|
|
1205
|
+
});
|
|
1206
|
+
};
|
|
1207
|
+
possibilities.forEach((entry) => {
|
|
1208
|
+
if (seen.has(entry.key))
|
|
1209
|
+
return;
|
|
1210
|
+
seen.add(entry.key);
|
|
1211
|
+
pushOption(entry.key, entry.styleObj);
|
|
1212
|
+
});
|
|
1213
|
+
if (gates.length)
|
|
1214
|
+
pushOption('', {});
|
|
1215
|
+
return true;
|
|
1216
|
+
};
|
|
1217
|
+
for (const arg of args) {
|
|
1218
|
+
const expr = arg.expression;
|
|
1219
|
+
if (pushPropPossibilities(expr, []))
|
|
1220
|
+
continue;
|
|
1182
1221
|
if (t.isCallExpression(expr) && t.isIdentifier(expr.callee)) {
|
|
1183
1222
|
const varName = expr.callee.value;
|
|
1184
1223
|
const uniqueKey = `${resourcePath}-${varName}`;
|
|
@@ -2013,6 +2052,17 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
2013
2052
|
}
|
|
2014
2053
|
},
|
|
2015
2054
|
});
|
|
2055
|
+
for (const { name, node } of components) {
|
|
2056
|
+
const props = scannedTables.componentPropsTable?.[`${resourcePath}-${name}`];
|
|
2057
|
+
for (const propName of Object.keys(props ?? {})) {
|
|
2058
|
+
if (appliedStyleProps.has(`${name}:${propName}`)) {
|
|
2059
|
+
continue;
|
|
2060
|
+
}
|
|
2061
|
+
throwCompilationError(`Plumeria: "${propName}" is a style received through a prop but is never applied ` +
|
|
2062
|
+
`to ${styleProp} or css.use() here. Apply it on an element this component renders; ` +
|
|
2063
|
+
`a style prop cannot be passed on to another component.`, node);
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2016
2066
|
const buildExportedInit = (info) => {
|
|
2017
2067
|
const keys = Object.keys(info.obj);
|
|
2018
2068
|
if (!isDev || keys.length === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/unplugin",
|
|
3
|
-
"version": "18.2.
|
|
3
|
+
"version": "18.2.4",
|
|
4
4
|
"description": "Universal Plumeria plugin for various build tools",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"dependencies": {
|
|
90
90
|
"@rollup/pluginutils": "^5.4.0",
|
|
91
91
|
"unplugin": "^3.0.0",
|
|
92
|
-
"@plumeria/utils": "^18.2.
|
|
92
|
+
"@plumeria/utils": "^18.2.4"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@swc/core": "1.15.47",
|