@plumeria/turbopack-loader 18.4.1 → 18.4.2

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.
Files changed (2) hide show
  1. package/dist/index.js +49 -10
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -105,12 +105,37 @@ const componentFunctionOf = (node) => {
105
105
  }
106
106
  return undefined;
107
107
  };
108
+ const unwrapPatternDefault = (pattern) => pattern?.type === 'AssignmentPattern' ? pattern.left : pattern;
109
+ const destructuredPropAliases = (fn) => {
110
+ const aliases = new Map();
111
+ const first = fn.params[0];
112
+ const pattern = unwrapPatternDefault(first?.pat ?? first);
113
+ if (pattern?.type !== 'ObjectPattern')
114
+ return aliases;
115
+ for (const item of pattern.properties ?? []) {
116
+ if (item.type !== 'KeyValuePatternProperty')
117
+ continue;
118
+ const local = unwrapPatternDefault(item.value);
119
+ const key = item.key;
120
+ if (!utils_1.t.isIdentifier(local))
121
+ continue;
122
+ if (!utils_1.t.isIdentifier(key) && !utils_1.t.isStringLiteral(key))
123
+ continue;
124
+ const name = String(key.value);
125
+ if (name !== local.value)
126
+ aliases.set(local.value, name);
127
+ }
128
+ return aliases;
129
+ };
108
130
  const isStaticArgValue = (node) => node.type === 'StringLiteral' ||
109
131
  node.type === 'NumericLiteral' ||
110
132
  node.type === 'BooleanLiteral' ||
111
133
  (node.type === 'TemplateLiteral' && node.expressions.length === 0) ||
112
134
  utils_1.t.isIdentifier(node) ||
113
135
  utils_1.t.isMemberExpression(node);
136
+ const isNoOpStyle = (node) => utils_1.t.isNullLiteral(node) ||
137
+ (utils_1.t.isBooleanLiteral(node) && node.value === false) ||
138
+ (utils_1.t.isIdentifier(node) && node.value === 'undefined');
114
139
  const foldDynamicVars = (vars) => {
115
140
  const grouped = new Map();
116
141
  [...vars]
@@ -237,18 +262,22 @@ async function loader(source) {
237
262
  }
238
263
  }
239
264
  const components = [];
265
+ const propAliases = new Map();
266
+ const addComponent = (name, fn) => {
267
+ components.push({ name, node: fn });
268
+ const aliases = destructuredPropAliases(fn);
269
+ if (aliases.size > 0)
270
+ propAliases.set(name, aliases);
271
+ };
240
272
  for (const node of ast.body) {
241
273
  const statement = unwrapExport(node);
242
274
  if (isFunctionNode(statement)) {
243
- components.push({
244
- name: statement.identifier?.value ?? 'default',
245
- node: statement,
246
- });
275
+ addComponent(statement.identifier?.value ?? 'default', statement);
247
276
  }
248
277
  else if (statement?.type === 'CallExpression') {
249
278
  const fn = componentFunctionOf(statement);
250
279
  if (fn)
251
- components.push({ name: 'default', node: fn });
280
+ addComponent('default', fn);
252
281
  }
253
282
  else if (utils_1.t.isVariableDeclaration(statement)) {
254
283
  for (const decl of statement.declarations) {
@@ -256,7 +285,7 @@ async function loader(source) {
256
285
  continue;
257
286
  const fn = componentFunctionOf(decl.init);
258
287
  if (fn)
259
- components.push({ name: decl.id.value, node: fn });
288
+ addComponent(decl.id.value, fn);
260
289
  }
261
290
  }
262
291
  }
@@ -1105,6 +1134,8 @@ async function loader(source) {
1105
1134
  return buildDecision(node, prefix, off, { n: 0 }, scoped);
1106
1135
  };
1107
1136
  const collectConditions = (node, currentTestStrings = [], argOrder) => {
1137
+ if (isNoOpStyle(node))
1138
+ return true;
1108
1139
  let branchStyle = resolveStyleObject(node);
1109
1140
  if (!branchStyle) {
1110
1141
  const dynamic = resolveDynamicCall(node);
@@ -1184,17 +1215,20 @@ async function loader(source) {
1184
1215
  ? expr.value
1185
1216
  : expr.property.value;
1186
1217
  const source = utils_1.t.isIdentifier(expr) ? varName : getSource(expr);
1187
- markStylePropApplied(varName, expr);
1188
1218
  const owner = ownerComponentOf(expr);
1219
+ const propName = (utils_1.t.isIdentifier(expr) && owner
1220
+ ? propAliases.get(owner)?.get(varName)
1221
+ : undefined) ?? varName;
1222
+ markStylePropApplied(propName, expr);
1189
1223
  let possibilities = owner
1190
- ? scannedTables.componentPropsTable?.[`${resourcePath}-${owner}`]?.[varName]
1224
+ ? scannedTables.componentPropsTable?.[`${resourcePath}-${owner}`]?.[propName]
1191
1225
  : undefined;
1192
1226
  if (!possibilities) {
1193
1227
  const candidates = [];
1194
1228
  for (const key of Object.keys(scannedTables.componentPropsTable || {})) {
1195
1229
  if (!key.startsWith(`${resourcePath}-`))
1196
1230
  continue;
1197
- const entries = scannedTables.componentPropsTable?.[key]?.[varName];
1231
+ const entries = scannedTables.componentPropsTable?.[key]?.[propName];
1198
1232
  if (entries)
1199
1233
  candidates.push(...entries);
1200
1234
  }
@@ -1249,6 +1283,8 @@ async function loader(source) {
1249
1283
  };
1250
1284
  for (const arg of args) {
1251
1285
  const expr = arg.expression;
1286
+ if (isNoOpStyle(expr))
1287
+ continue;
1252
1288
  if (pushPropPossibilities(expr, []))
1253
1289
  continue;
1254
1290
  if (utils_1.t.isCallExpression(expr) && utils_1.t.isIdentifier(expr.callee)) {
@@ -2073,10 +2109,13 @@ async function loader(source) {
2073
2109
  });
2074
2110
  }
2075
2111
  else {
2112
+ const keptClass = existingClassExpr
2113
+ ? `className={${existingClassExpr}}`
2114
+ : '';
2076
2115
  replacements.push({
2077
2116
  start: node.span.start - baseByteOffset,
2078
2117
  end: node.span.end - baseByteOffset,
2079
- content: styleAttr || '',
2118
+ content: `${keptClass}${styleAttr}`,
2080
2119
  });
2081
2120
  }
2082
2121
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "18.4.1",
3
+ "version": "18.4.2",
4
4
  "description": "Plumeria Turbopack-loader",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -29,8 +29,8 @@
29
29
  "zero-virtual.css"
30
30
  ],
31
31
  "dependencies": {
32
- "@plumeria/compiler": "^18.4.1",
33
- "@plumeria/utils": "^18.4.1"
32
+ "@plumeria/compiler": "^18.4.2",
33
+ "@plumeria/utils": "^18.4.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@swc/core": "1.15.47",