@plumeria/turbopack-loader 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/index.js +91 -44
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -238,6 +238,30 @@ async function loader(source) {
|
|
|
238
238
|
this.addDependency(parentFile);
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
+
const components = [];
|
|
242
|
+
for (const node of ast.body) {
|
|
243
|
+
const statement = utils_1.t.isExportDeclaration(node) ? node.declaration : node;
|
|
244
|
+
if (statement.type === 'FunctionDeclaration' && statement.identifier) {
|
|
245
|
+
components.push({ name: statement.identifier.value, node: statement });
|
|
246
|
+
}
|
|
247
|
+
else if (utils_1.t.isVariableDeclaration(statement)) {
|
|
248
|
+
for (const decl of statement.declarations) {
|
|
249
|
+
if (utils_1.t.isIdentifier(decl.id) &&
|
|
250
|
+
(decl.init?.type === 'ArrowFunctionExpression' ||
|
|
251
|
+
decl.init?.type === 'FunctionExpression')) {
|
|
252
|
+
components.push({ name: decl.id.value, node: decl.init });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const appliedStyleProps = new Set();
|
|
258
|
+
const markStylePropApplied = (name, at) => {
|
|
259
|
+
const owner = components.find((c) => at.span.start >= c.node.span.start &&
|
|
260
|
+
at.span.start <= c.node.span.end);
|
|
261
|
+
if (owner) {
|
|
262
|
+
appliedStyleProps.add(`${owner.name}:${name}`);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
241
265
|
const extractedSheets = [];
|
|
242
266
|
const addSheet = (sheet) => {
|
|
243
267
|
if (!extractedSheets.includes(sheet)) {
|
|
@@ -1147,56 +1171,68 @@ async function loader(source) {
|
|
|
1147
1171
|
else if (node.type === 'ParenthesisExpression') {
|
|
1148
1172
|
return collectConditions(node.expression, currentTestStrings, argOrder);
|
|
1149
1173
|
}
|
|
1174
|
+
if (pushPropPossibilities(node, currentTestStrings))
|
|
1175
|
+
return true;
|
|
1150
1176
|
assertResolvable(node);
|
|
1151
1177
|
return false;
|
|
1152
1178
|
};
|
|
1153
|
-
|
|
1154
|
-
const
|
|
1155
|
-
|
|
1156
|
-
(
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
propPossibilities =
|
|
1169
|
-
scannedTables.componentPropsTable?.[key]?.[varName];
|
|
1170
|
-
break;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
if (propPossibilities && propPossibilities.length > 0) {
|
|
1175
|
-
const currentGroupId = ++groupIdCounter;
|
|
1176
|
-
const currentOrder = sourceOrder++;
|
|
1177
|
-
const uniqueEntries = [];
|
|
1178
|
-
propPossibilities.forEach((entry) => {
|
|
1179
|
-
if (!uniqueEntries.some((x) => x.key === entry.key)) {
|
|
1180
|
-
uniqueEntries.push(entry);
|
|
1181
|
-
}
|
|
1182
|
-
});
|
|
1183
|
-
uniqueEntries.forEach((entry) => {
|
|
1184
|
-
conditionals.push({
|
|
1185
|
-
test: expr,
|
|
1186
|
-
testLHS,
|
|
1187
|
-
testString: `${testLHS} === ${JSON.stringify(entry.key)}`,
|
|
1188
|
-
truthy: entry.styleObj,
|
|
1189
|
-
falsy: {},
|
|
1190
|
-
groupId: currentGroupId,
|
|
1191
|
-
order: currentOrder,
|
|
1192
|
-
groupName: undefined,
|
|
1193
|
-
valueName: entry.key,
|
|
1194
|
-
varName,
|
|
1195
|
-
});
|
|
1196
|
-
});
|
|
1179
|
+
const pushPropPossibilities = (expr, gates) => {
|
|
1180
|
+
const isParamMember = utils_1.t.isMemberExpression(expr) &&
|
|
1181
|
+
utils_1.t.isIdentifier(expr.object) &&
|
|
1182
|
+
componentParamNames.has(expr.object.value) &&
|
|
1183
|
+
utils_1.t.isIdentifier(expr.property);
|
|
1184
|
+
if (!utils_1.t.isIdentifier(expr) && !isParamMember)
|
|
1185
|
+
return false;
|
|
1186
|
+
const varName = utils_1.t.isIdentifier(expr)
|
|
1187
|
+
? expr.value
|
|
1188
|
+
: expr.property.value;
|
|
1189
|
+
const source = utils_1.t.isIdentifier(expr) ? varName : getSource(expr);
|
|
1190
|
+
markStylePropApplied(varName, expr);
|
|
1191
|
+
let possibilities;
|
|
1192
|
+
for (const key of Object.keys(scannedTables.componentPropsTable || {})) {
|
|
1193
|
+
if (!key.startsWith(`${resourcePath}-`))
|
|
1197
1194
|
continue;
|
|
1195
|
+
if (scannedTables.componentPropsTable?.[key]?.[varName]) {
|
|
1196
|
+
possibilities = scannedTables.componentPropsTable[key][varName];
|
|
1197
|
+
break;
|
|
1198
1198
|
}
|
|
1199
1199
|
}
|
|
1200
|
+
if (!possibilities || possibilities.length === 0)
|
|
1201
|
+
return false;
|
|
1202
|
+
const testLHS = gates.length
|
|
1203
|
+
? `((${gates.join(' && ')}) ? ${source} : "")`
|
|
1204
|
+
: source;
|
|
1205
|
+
const currentGroupId = ++groupIdCounter;
|
|
1206
|
+
const currentOrder = sourceOrder++;
|
|
1207
|
+
const seen = new Set();
|
|
1208
|
+
const pushOption = (valueName, style) => {
|
|
1209
|
+
conditionals.push({
|
|
1210
|
+
test: expr,
|
|
1211
|
+
testLHS,
|
|
1212
|
+
testString: `${testLHS} === ${JSON.stringify(valueName)}`,
|
|
1213
|
+
truthy: style,
|
|
1214
|
+
falsy: {},
|
|
1215
|
+
groupId: currentGroupId,
|
|
1216
|
+
order: currentOrder,
|
|
1217
|
+
groupName: undefined,
|
|
1218
|
+
valueName,
|
|
1219
|
+
varName,
|
|
1220
|
+
});
|
|
1221
|
+
};
|
|
1222
|
+
possibilities.forEach((entry) => {
|
|
1223
|
+
if (seen.has(entry.key))
|
|
1224
|
+
return;
|
|
1225
|
+
seen.add(entry.key);
|
|
1226
|
+
pushOption(entry.key, entry.styleObj);
|
|
1227
|
+
});
|
|
1228
|
+
if (gates.length)
|
|
1229
|
+
pushOption('', {});
|
|
1230
|
+
return true;
|
|
1231
|
+
};
|
|
1232
|
+
for (const arg of args) {
|
|
1233
|
+
const expr = arg.expression;
|
|
1234
|
+
if (pushPropPossibilities(expr, []))
|
|
1235
|
+
continue;
|
|
1200
1236
|
if (utils_1.t.isCallExpression(expr) && utils_1.t.isIdentifier(expr.callee)) {
|
|
1201
1237
|
const varName = expr.callee.value;
|
|
1202
1238
|
const uniqueKey = `${resourcePath}-${varName}`;
|
|
@@ -2033,6 +2069,17 @@ async function loader(source) {
|
|
|
2033
2069
|
}
|
|
2034
2070
|
},
|
|
2035
2071
|
});
|
|
2072
|
+
for (const { name, node } of components) {
|
|
2073
|
+
const props = scannedTables.componentPropsTable?.[`${resourcePath}-${name}`];
|
|
2074
|
+
for (const propName of Object.keys(props ?? {})) {
|
|
2075
|
+
if (appliedStyleProps.has(`${name}:${propName}`)) {
|
|
2076
|
+
continue;
|
|
2077
|
+
}
|
|
2078
|
+
throwCompilationError(`Plumeria: "${propName}" is a style received through a prop but is never applied ` +
|
|
2079
|
+
`to ${styleProp} or css.use() here. Apply it on an element this component renders; ` +
|
|
2080
|
+
`a style prop cannot be passed on to another component.`, node);
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2036
2083
|
const buildExportedInit = (info) => {
|
|
2037
2084
|
const keys = Object.keys(info.obj);
|
|
2038
2085
|
if (isProduction || keys.length === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "18.2.
|
|
3
|
+
"version": "18.2.4",
|
|
4
4
|
"description": "Plumeria Turbopack-loader",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"zero-virtual.css"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@plumeria/
|
|
26
|
-
"@plumeria/
|
|
25
|
+
"@plumeria/utils": "^18.2.4",
|
|
26
|
+
"@plumeria/compiler": "^18.2.4"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@swc/core": "1.15.47",
|