@plumeria/unplugin 18.3.12 → 18.3.14

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 (3) hide show
  1. package/dist/core.js +36 -11
  2. package/dist/core.mjs +36 -11
  3. package/package.json +2 -2
package/dist/core.js CHANGED
@@ -53,6 +53,18 @@ const unwrapExport = (node) => {
53
53
  const isFunctionNode = (node) => node?.type === 'FunctionDeclaration' ||
54
54
  node?.type === 'FunctionExpression' ||
55
55
  node?.type === 'ArrowFunctionExpression';
56
+ const componentFunctionOf = (node) => {
57
+ if (isFunctionNode(node))
58
+ return node;
59
+ if (node?.type === 'CallExpression') {
60
+ for (const arg of node.arguments ?? []) {
61
+ const fn = componentFunctionOf(arg.expression);
62
+ if (fn)
63
+ return fn;
64
+ }
65
+ }
66
+ return undefined;
67
+ };
56
68
  const isStaticArgValue = (node) => node.type === 'StringLiteral' ||
57
69
  node.type === 'NumericLiteral' ||
58
70
  node.type === 'BooleanLiteral' ||
@@ -334,13 +346,18 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
334
346
  node: statement,
335
347
  });
336
348
  }
349
+ else if (statement?.type === 'CallExpression') {
350
+ const fn = componentFunctionOf(statement);
351
+ if (fn)
352
+ components.push({ name: 'default', node: fn });
353
+ }
337
354
  else if (utils_1.t.isVariableDeclaration(statement)) {
338
355
  for (const decl of statement.declarations) {
339
- if (utils_1.t.isIdentifier(decl.id) &&
340
- (decl.init?.type === 'ArrowFunctionExpression' ||
341
- decl.init?.type === 'FunctionExpression')) {
342
- components.push({ name: decl.id.value, node: decl.init });
343
- }
356
+ if (!utils_1.t.isIdentifier(decl.id))
357
+ continue;
358
+ const fn = componentFunctionOf(decl.init);
359
+ if (fn)
360
+ components.push({ name: decl.id.value, node: fn });
344
361
  }
345
362
  }
346
363
  }
@@ -862,12 +879,18 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
862
879
  if (isFunctionNode(statement)) {
863
880
  addFirstParamName(statement);
864
881
  }
882
+ else if (statement?.type === 'CallExpression') {
883
+ const fn = componentFunctionOf(statement);
884
+ if (fn)
885
+ addFirstParamName(fn);
886
+ }
865
887
  else if (utils_1.t.isVariableDeclaration(statement)) {
866
888
  for (const decl of statement.declarations) {
867
889
  if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
868
890
  continue;
869
- if (isFunctionNode(decl.init))
870
- addFirstParamName(decl.init);
891
+ const fn = componentFunctionOf(decl.init);
892
+ if (fn)
893
+ addFirstParamName(fn);
871
894
  }
872
895
  }
873
896
  }
@@ -1278,14 +1301,16 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1278
1301
  ? scannedTables.componentPropsTable?.[`${resourcePath}-${owner}`]?.[varName]
1279
1302
  : undefined;
1280
1303
  if (!possibilities) {
1304
+ const candidates = [];
1281
1305
  for (const key of Object.keys(scannedTables.componentPropsTable || {})) {
1282
1306
  if (!key.startsWith(`${resourcePath}-`))
1283
1307
  continue;
1284
- if (scannedTables.componentPropsTable?.[key]?.[varName]) {
1285
- possibilities = scannedTables.componentPropsTable[key][varName];
1286
- break;
1287
- }
1308
+ const entries = scannedTables.componentPropsTable?.[key]?.[varName];
1309
+ if (entries)
1310
+ candidates.push(...entries);
1288
1311
  }
1312
+ if (candidates.length > 0)
1313
+ possibilities = candidates;
1289
1314
  }
1290
1315
  if (!possibilities || possibilities.length === 0)
1291
1316
  return false;
package/dist/core.mjs CHANGED
@@ -17,6 +17,18 @@ const unwrapExport = (node) => {
17
17
  const isFunctionNode = (node) => node?.type === 'FunctionDeclaration' ||
18
18
  node?.type === 'FunctionExpression' ||
19
19
  node?.type === 'ArrowFunctionExpression';
20
+ const componentFunctionOf = (node) => {
21
+ if (isFunctionNode(node))
22
+ return node;
23
+ if (node?.type === 'CallExpression') {
24
+ for (const arg of node.arguments ?? []) {
25
+ const fn = componentFunctionOf(arg.expression);
26
+ if (fn)
27
+ return fn;
28
+ }
29
+ }
30
+ return undefined;
31
+ };
20
32
  const isStaticArgValue = (node) => node.type === 'StringLiteral' ||
21
33
  node.type === 'NumericLiteral' ||
22
34
  node.type === 'BooleanLiteral' ||
@@ -298,13 +310,18 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
298
310
  node: statement,
299
311
  });
300
312
  }
313
+ else if (statement?.type === 'CallExpression') {
314
+ const fn = componentFunctionOf(statement);
315
+ if (fn)
316
+ components.push({ name: 'default', node: fn });
317
+ }
301
318
  else if (t.isVariableDeclaration(statement)) {
302
319
  for (const decl of statement.declarations) {
303
- if (t.isIdentifier(decl.id) &&
304
- (decl.init?.type === 'ArrowFunctionExpression' ||
305
- decl.init?.type === 'FunctionExpression')) {
306
- components.push({ name: decl.id.value, node: decl.init });
307
- }
320
+ if (!t.isIdentifier(decl.id))
321
+ continue;
322
+ const fn = componentFunctionOf(decl.init);
323
+ if (fn)
324
+ components.push({ name: decl.id.value, node: fn });
308
325
  }
309
326
  }
310
327
  }
@@ -826,12 +843,18 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
826
843
  if (isFunctionNode(statement)) {
827
844
  addFirstParamName(statement);
828
845
  }
846
+ else if (statement?.type === 'CallExpression') {
847
+ const fn = componentFunctionOf(statement);
848
+ if (fn)
849
+ addFirstParamName(fn);
850
+ }
829
851
  else if (t.isVariableDeclaration(statement)) {
830
852
  for (const decl of statement.declarations) {
831
853
  if (!t.isIdentifier(decl.id) || !decl.init)
832
854
  continue;
833
- if (isFunctionNode(decl.init))
834
- addFirstParamName(decl.init);
855
+ const fn = componentFunctionOf(decl.init);
856
+ if (fn)
857
+ addFirstParamName(fn);
835
858
  }
836
859
  }
837
860
  }
@@ -1242,14 +1265,16 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1242
1265
  ? scannedTables.componentPropsTable?.[`${resourcePath}-${owner}`]?.[varName]
1243
1266
  : undefined;
1244
1267
  if (!possibilities) {
1268
+ const candidates = [];
1245
1269
  for (const key of Object.keys(scannedTables.componentPropsTable || {})) {
1246
1270
  if (!key.startsWith(`${resourcePath}-`))
1247
1271
  continue;
1248
- if (scannedTables.componentPropsTable?.[key]?.[varName]) {
1249
- possibilities = scannedTables.componentPropsTable[key][varName];
1250
- break;
1251
- }
1272
+ const entries = scannedTables.componentPropsTable?.[key]?.[varName];
1273
+ if (entries)
1274
+ candidates.push(...entries);
1252
1275
  }
1276
+ if (candidates.length > 0)
1277
+ possibilities = candidates;
1253
1278
  }
1254
1279
  if (!possibilities || possibilities.length === 0)
1255
1280
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/unplugin",
3
- "version": "18.3.12",
3
+ "version": "18.3.14",
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.3.12"
97
+ "@plumeria/utils": "^18.3.14"
98
98
  },
99
99
  "devDependencies": {
100
100
  "@swc/core": "1.15.47",