@plumeria/compiler 18.3.11 → 18.3.12

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 +40 -29
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -41,6 +41,18 @@ const path = __importStar(require("path"));
41
41
  const rs = __importStar(require("@rust-gear/glob"));
42
42
  const utils_1 = require("@plumeria/utils");
43
43
  const utils_2 = require("@plumeria/utils");
44
+ const unwrapExport = (node) => {
45
+ if (node?.type === 'ExportDeclaration')
46
+ return node.declaration;
47
+ if (node?.type === 'ExportDefaultDeclaration')
48
+ return node.decl;
49
+ if (node?.type === 'ExportDefaultExpression')
50
+ return node.expression;
51
+ return node;
52
+ };
53
+ const isFunctionNode = (node) => node?.type === 'FunctionDeclaration' ||
54
+ node?.type === 'FunctionExpression' ||
55
+ node?.type === 'ArrowFunctionExpression';
44
56
  const isStaticArgValue = (node) => node.type === 'StringLiteral' ||
45
57
  node.type === 'NumericLiteral' ||
46
58
  node.type === 'BooleanLiteral' ||
@@ -426,41 +438,40 @@ function compileCSS(options) {
426
438
  localStyleAliases,
427
439
  };
428
440
  const componentParamNames = new Set();
429
- for (const node of ast.body) {
430
- let declarations = [];
431
- if (node.type === 'VariableDeclaration') {
432
- declarations = node.declarations;
441
+ const addFirstParamName = (fn) => {
442
+ const p = fn.params[0];
443
+ if (utils_1.t.isIdentifier(p)) {
444
+ componentParamNames.add(p.value);
433
445
  }
434
- else if (node.type === 'ExportDeclaration' &&
435
- node.declaration.type === 'VariableDeclaration') {
436
- declarations = node.declaration.declarations;
446
+ else if (typeof p === 'object' &&
447
+ p !== null &&
448
+ 'pat' in p &&
449
+ utils_1.t.isIdentifier(p.pat)) {
450
+ componentParamNames.add(p.pat.value);
437
451
  }
438
- for (const decl of declarations) {
439
- if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
440
- continue;
441
- const init = decl.init;
442
- if (init.type !== 'ArrowFunctionExpression' &&
443
- init.type !== 'FunctionExpression')
444
- continue;
445
- if (init.params.length > 0) {
446
- const p = init.params[0];
447
- if (utils_1.t.isIdentifier(p)) {
448
- componentParamNames.add(p.value);
449
- }
450
- else if (typeof p === 'object' &&
451
- p !== null &&
452
- 'pat' in p &&
453
- utils_1.t.isIdentifier(p.pat)) {
454
- componentParamNames.add(p.pat.value);
455
- }
452
+ };
453
+ for (const node of ast.body) {
454
+ const statement = unwrapExport(node);
455
+ if (isFunctionNode(statement)) {
456
+ addFirstParamName(statement);
457
+ }
458
+ else if (utils_1.t.isVariableDeclaration(statement)) {
459
+ for (const decl of statement.declarations) {
460
+ if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
461
+ continue;
462
+ if (isFunctionNode(decl.init))
463
+ addFirstParamName(decl.init);
456
464
  }
457
465
  }
458
466
  }
459
467
  const components = [];
460
468
  for (const node of ast.body) {
461
- const statement = utils_1.t.isExportDeclaration(node) ? node.declaration : node;
462
- if (statement.type === 'FunctionDeclaration' && statement.identifier) {
463
- components.push({ name: statement.identifier.value, node: statement });
469
+ const statement = unwrapExport(node);
470
+ if (isFunctionNode(statement)) {
471
+ components.push({
472
+ name: statement.identifier?.value ?? 'default',
473
+ node: statement,
474
+ });
464
475
  }
465
476
  else if (utils_1.t.isVariableDeclaration(statement)) {
466
477
  for (const decl of statement.declarations) {
@@ -797,7 +808,7 @@ function compileCSS(options) {
797
808
  if (entries)
798
809
  propPossibilities.push(...entries);
799
810
  }
800
- else {
811
+ if (propPossibilities.length === 0) {
801
812
  const filePrefix = `${resourcePath}-`;
802
813
  for (const key of Object.keys(ctx.scannedTables.componentPropsTable || {})) {
803
814
  if (!key.startsWith(filePrefix))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "18.3.11",
3
+ "version": "18.3.12",
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.11"
24
+ "@plumeria/utils": "^18.3.12"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@rust-gear/glob": "1.1.1",