@plumeria/unplugin 18.3.13 → 18.3.15

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 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' ||
@@ -289,6 +301,13 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
289
301
  mergedCreateTable[rootId] !== undefined ||
290
302
  mergedVariantsTable[rootId] !== undefined);
291
303
  if (!isPlumeriaStyle) {
304
+ const origin = rootId ? localImports[rootId] : undefined;
305
+ const failure = origin
306
+ ? (0, utils_1.resolveFileError)(origin.actualPath, origin.importedName)
307
+ : undefined;
308
+ if (failure) {
309
+ throwCompilationError(`Plumeria: ${failure.message} (${path.basename(failure.filePath)})`);
310
+ }
292
311
  throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(node)}" is not supported.`, node);
293
312
  }
294
313
  }
@@ -334,13 +353,18 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
334
353
  node: statement,
335
354
  });
336
355
  }
356
+ else if (statement?.type === 'CallExpression') {
357
+ const fn = componentFunctionOf(statement);
358
+ if (fn)
359
+ components.push({ name: 'default', node: fn });
360
+ }
337
361
  else if (utils_1.t.isVariableDeclaration(statement)) {
338
362
  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
- }
363
+ if (!utils_1.t.isIdentifier(decl.id))
364
+ continue;
365
+ const fn = componentFunctionOf(decl.init);
366
+ if (fn)
367
+ components.push({ name: decl.id.value, node: fn });
344
368
  }
345
369
  }
346
370
  }
@@ -862,12 +886,18 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
862
886
  if (isFunctionNode(statement)) {
863
887
  addFirstParamName(statement);
864
888
  }
889
+ else if (statement?.type === 'CallExpression') {
890
+ const fn = componentFunctionOf(statement);
891
+ if (fn)
892
+ addFirstParamName(fn);
893
+ }
865
894
  else if (utils_1.t.isVariableDeclaration(statement)) {
866
895
  for (const decl of statement.declarations) {
867
896
  if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
868
897
  continue;
869
- if (isFunctionNode(decl.init))
870
- addFirstParamName(decl.init);
898
+ const fn = componentFunctionOf(decl.init);
899
+ if (fn)
900
+ addFirstParamName(fn);
871
901
  }
872
902
  }
873
903
  }
package/dist/core.mjs CHANGED
@@ -2,7 +2,7 @@ import { createFilter } from '@rollup/pluginutils';
2
2
  import { parseSync } from '@swc/core';
3
3
  import * as path from 'path';
4
4
  import { applyCssValue, genBase36Hash, exceptionCamelCase, camelToKebabCase, isAtRule, } from 'zss-engine';
5
- import { traverse, collectReferenceIdentifiers, getStyleRecords, getStateWeights, collectLocalConsts, objectExpressionToObject, t, getRootIdentifier, extractOndemandStyles, deepMerge, scanAll, resolveImportPath, getLeadingCommentLength, optimizer, themeHashOf, getFileDependencies, resolveExport, resolveComponentKey, resolveThemeSelector, DEFAULT_STYLE_PROP, } from '@plumeria/utils';
5
+ import { traverse, collectReferenceIdentifiers, getStyleRecords, getStateWeights, collectLocalConsts, objectExpressionToObject, t, getRootIdentifier, extractOndemandStyles, deepMerge, scanAll, resolveFileError, resolveImportPath, getLeadingCommentLength, optimizer, themeHashOf, getFileDependencies, resolveExport, resolveComponentKey, resolveThemeSelector, DEFAULT_STYLE_PROP, } from '@plumeria/utils';
6
6
  export const TARGET_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
7
7
  export const EXTENSION_PATTERN = /\.(ts|tsx|js|jsx)$/;
8
8
  const unwrapExport = (node) => {
@@ -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' ||
@@ -253,6 +265,13 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
253
265
  mergedCreateTable[rootId] !== undefined ||
254
266
  mergedVariantsTable[rootId] !== undefined);
255
267
  if (!isPlumeriaStyle) {
268
+ const origin = rootId ? localImports[rootId] : undefined;
269
+ const failure = origin
270
+ ? resolveFileError(origin.actualPath, origin.importedName)
271
+ : undefined;
272
+ if (failure) {
273
+ throwCompilationError(`Plumeria: ${failure.message} (${path.basename(failure.filePath)})`);
274
+ }
256
275
  throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(node)}" is not supported.`, node);
257
276
  }
258
277
  }
@@ -298,13 +317,18 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
298
317
  node: statement,
299
318
  });
300
319
  }
320
+ else if (statement?.type === 'CallExpression') {
321
+ const fn = componentFunctionOf(statement);
322
+ if (fn)
323
+ components.push({ name: 'default', node: fn });
324
+ }
301
325
  else if (t.isVariableDeclaration(statement)) {
302
326
  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
- }
327
+ if (!t.isIdentifier(decl.id))
328
+ continue;
329
+ const fn = componentFunctionOf(decl.init);
330
+ if (fn)
331
+ components.push({ name: decl.id.value, node: fn });
308
332
  }
309
333
  }
310
334
  }
@@ -826,12 +850,18 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
826
850
  if (isFunctionNode(statement)) {
827
851
  addFirstParamName(statement);
828
852
  }
853
+ else if (statement?.type === 'CallExpression') {
854
+ const fn = componentFunctionOf(statement);
855
+ if (fn)
856
+ addFirstParamName(fn);
857
+ }
829
858
  else if (t.isVariableDeclaration(statement)) {
830
859
  for (const decl of statement.declarations) {
831
860
  if (!t.isIdentifier(decl.id) || !decl.init)
832
861
  continue;
833
- if (isFunctionNode(decl.init))
834
- addFirstParamName(decl.init);
862
+ const fn = componentFunctionOf(decl.init);
863
+ if (fn)
864
+ addFirstParamName(fn);
835
865
  }
836
866
  }
837
867
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/unplugin",
3
- "version": "18.3.13",
3
+ "version": "18.3.15",
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.13"
97
+ "@plumeria/utils": "^18.3.15"
98
98
  },
99
99
  "devDependencies": {
100
100
  "@swc/core": "1.15.47",