@plumeria/compiler 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.
Files changed (2) hide show
  1. package/dist/index.js +37 -8
  2. package/package.json +2 -2
package/dist/index.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' ||
@@ -455,12 +467,18 @@ function compileCSS(options) {
455
467
  if (isFunctionNode(statement)) {
456
468
  addFirstParamName(statement);
457
469
  }
470
+ else if (statement?.type === 'CallExpression') {
471
+ const fn = componentFunctionOf(statement);
472
+ if (fn)
473
+ addFirstParamName(fn);
474
+ }
458
475
  else if (utils_1.t.isVariableDeclaration(statement)) {
459
476
  for (const decl of statement.declarations) {
460
477
  if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
461
478
  continue;
462
- if (isFunctionNode(decl.init))
463
- addFirstParamName(decl.init);
479
+ const fn = componentFunctionOf(decl.init);
480
+ if (fn)
481
+ addFirstParamName(fn);
464
482
  }
465
483
  }
466
484
  }
@@ -473,13 +491,18 @@ function compileCSS(options) {
473
491
  node: statement,
474
492
  });
475
493
  }
494
+ else if (statement?.type === 'CallExpression') {
495
+ const fn = componentFunctionOf(statement);
496
+ if (fn)
497
+ components.push({ name: 'default', node: fn });
498
+ }
476
499
  else if (utils_1.t.isVariableDeclaration(statement)) {
477
500
  for (const decl of statement.declarations) {
478
- if (utils_1.t.isIdentifier(decl.id) &&
479
- (decl.init?.type === 'ArrowFunctionExpression' ||
480
- decl.init?.type === 'FunctionExpression')) {
481
- components.push({ name: decl.id.value, node: decl.init });
482
- }
501
+ if (!utils_1.t.isIdentifier(decl.id))
502
+ continue;
503
+ const fn = componentFunctionOf(decl.init);
504
+ if (fn)
505
+ components.push({ name: decl.id.value, node: fn });
483
506
  }
484
507
  }
485
508
  }
@@ -565,7 +588,13 @@ function compileCSS(options) {
565
588
  ctx.mergedCreateTable[rootId] !== undefined ||
566
589
  ctx.mergedVariantsTable[rootId] !== undefined);
567
590
  if (!isPlumeriaStyle) {
568
- throw new Error(`[plumeria] Dynamic or unresolvable style object "${getSource(node)}" is not supported. (${path.basename(resourcePath)})`);
591
+ const origin = rootId ? localImports[rootId] : undefined;
592
+ const failure = origin
593
+ ? (0, utils_1.resolveFileError)(origin.actualPath, origin.importedName)
594
+ : undefined;
595
+ throw new Error(failure
596
+ ? `[plumeria] ${failure.message} (${path.basename(failure.filePath)})`
597
+ : `[plumeria] Dynamic or unresolvable style object "${getSource(node)}" is not supported. (${path.basename(resourcePath)})`);
569
598
  }
570
599
  }
571
600
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "18.3.13",
3
+ "version": "18.3.15",
4
4
  "description": "Plumeria swc based compiler for statically extracting css",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -21,7 +21,7 @@
21
21
  "dist/"
22
22
  ],
23
23
  "dependencies": {
24
- "@plumeria/utils": "^18.3.13"
24
+ "@plumeria/utils": "^18.3.15"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@rust-gear/glob": "1.1.1",