@plumeria/turbopack-loader 18.3.11 → 18.3.13

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 +42 -29
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -79,6 +79,18 @@ const ensureProductionCss = (virtualFilePath, options) => {
79
79
  }
80
80
  return productionCss;
81
81
  };
82
+ const unwrapExport = (node) => {
83
+ if (node?.type === 'ExportDeclaration')
84
+ return node.declaration;
85
+ if (node?.type === 'ExportDefaultDeclaration')
86
+ return node.decl;
87
+ if (node?.type === 'ExportDefaultExpression')
88
+ return node.expression;
89
+ return node;
90
+ };
91
+ const isFunctionNode = (node) => node?.type === 'FunctionDeclaration' ||
92
+ node?.type === 'FunctionExpression' ||
93
+ node?.type === 'ArrowFunctionExpression';
82
94
  const isStaticArgValue = (node) => node.type === 'StringLiteral' ||
83
95
  node.type === 'NumericLiteral' ||
84
96
  node.type === 'BooleanLiteral' ||
@@ -303,9 +315,12 @@ async function loader(source) {
303
315
  }
304
316
  const components = [];
305
317
  for (const node of ast.body) {
306
- const statement = utils_1.t.isExportDeclaration(node) ? node.declaration : node;
307
- if (statement.type === 'FunctionDeclaration' && statement.identifier) {
308
- components.push({ name: statement.identifier.value, node: statement });
318
+ const statement = unwrapExport(node);
319
+ if (isFunctionNode(statement)) {
320
+ components.push({
321
+ name: statement.identifier?.value ?? 'default',
322
+ node: statement,
323
+ });
309
324
  }
310
325
  else if (utils_1.t.isVariableDeclaration(statement)) {
311
326
  for (const decl of statement.declarations) {
@@ -819,30 +834,26 @@ async function loader(source) {
819
834
  });
820
835
  const jsxOpeningElementMap = new Map();
821
836
  const componentParamNames = new Set();
822
- for (const node of ast.body) {
823
- let declarations = [];
824
- if (utils_1.t.isVariableDeclaration(node)) {
825
- declarations = node.declarations;
837
+ const addFirstParamName = (fn) => {
838
+ const p = fn.params[0];
839
+ if (utils_1.t.isIdentifier(p)) {
840
+ componentParamNames.add(p.value);
826
841
  }
827
- else if (utils_1.t.isExportDeclaration(node) &&
828
- utils_1.t.isVariableDeclaration(node.declaration)) {
829
- declarations = node.declaration.declarations;
842
+ else if (p?.pat && utils_1.t.isIdentifier(p.pat)) {
843
+ componentParamNames.add(p.pat.value);
830
844
  }
831
- for (const decl of declarations) {
832
- if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
833
- continue;
834
- const init = decl.init;
835
- if (init.type !== 'ArrowFunctionExpression' &&
836
- init.type !== 'FunctionExpression')
837
- continue;
838
- if (init.params.length > 0) {
839
- const p = init.params[0];
840
- if (utils_1.t.isIdentifier(p)) {
841
- componentParamNames.add(p.value);
842
- }
843
- else if (p.pat && utils_1.t.isIdentifier(p.pat)) {
844
- componentParamNames.add(p.pat.value);
845
- }
845
+ };
846
+ for (const node of ast.body) {
847
+ const statement = unwrapExport(node);
848
+ if (isFunctionNode(statement)) {
849
+ addFirstParamName(statement);
850
+ }
851
+ else if (utils_1.t.isVariableDeclaration(statement)) {
852
+ for (const decl of statement.declarations) {
853
+ if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
854
+ continue;
855
+ if (isFunctionNode(decl.init))
856
+ addFirstParamName(decl.init);
846
857
  }
847
858
  }
848
859
  }
@@ -1249,14 +1260,16 @@ async function loader(source) {
1249
1260
  ? scannedTables.componentPropsTable?.[`${resourcePath}-${owner}`]?.[varName]
1250
1261
  : undefined;
1251
1262
  if (!possibilities) {
1263
+ const candidates = [];
1252
1264
  for (const key of Object.keys(scannedTables.componentPropsTable || {})) {
1253
1265
  if (!key.startsWith(`${resourcePath}-`))
1254
1266
  continue;
1255
- if (scannedTables.componentPropsTable?.[key]?.[varName]) {
1256
- possibilities = scannedTables.componentPropsTable[key][varName];
1257
- break;
1258
- }
1267
+ const entries = scannedTables.componentPropsTable?.[key]?.[varName];
1268
+ if (entries)
1269
+ candidates.push(...entries);
1259
1270
  }
1271
+ if (candidates.length > 0)
1272
+ possibilities = candidates;
1260
1273
  }
1261
1274
  if (!possibilities || possibilities.length === 0)
1262
1275
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "18.3.11",
3
+ "version": "18.3.13",
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.3.11",
33
- "@plumeria/utils": "^18.3.11"
32
+ "@plumeria/compiler": "^18.3.13",
33
+ "@plumeria/utils": "^18.3.13"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@swc/core": "1.15.47",