@plumeria/unplugin 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 (3) hide show
  1. package/dist/core.js +39 -29
  2. package/dist/core.mjs +39 -29
  3. package/package.json +2 -2
package/dist/core.js CHANGED
@@ -41,6 +41,18 @@ const zss_engine_1 = require("zss-engine");
41
41
  const utils_1 = require("@plumeria/utils");
42
42
  exports.TARGET_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
43
43
  exports.EXTENSION_PATTERN = /\.(ts|tsx|js|jsx)$/;
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' ||
@@ -315,10 +327,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
315
327
  }
316
328
  const components = [];
317
329
  for (const node of ast.body) {
318
- const statement = utils_1.t.isExportDeclaration(node) ? node.declaration : node;
319
- if (statement.type === 'FunctionDeclaration' && statement.identifier) {
330
+ const statement = unwrapExport(node);
331
+ if (isFunctionNode(statement)) {
320
332
  components.push({
321
- name: statement.identifier.value,
333
+ name: statement.identifier?.value ?? 'default',
322
334
  node: statement,
323
335
  });
324
336
  }
@@ -836,30 +848,26 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
836
848
  });
837
849
  const jsxOpeningElementMap = new Map();
838
850
  const componentParamNames = new Set();
839
- for (const node of ast.body) {
840
- let declarations = [];
841
- if (utils_1.t.isVariableDeclaration(node)) {
842
- declarations = node.declarations;
851
+ const addFirstParamName = (fn) => {
852
+ const p = fn.params[0];
853
+ if (utils_1.t.isIdentifier(p)) {
854
+ componentParamNames.add(p.value);
843
855
  }
844
- else if (utils_1.t.isExportDeclaration(node) &&
845
- utils_1.t.isVariableDeclaration(node.declaration)) {
846
- declarations = node.declaration.declarations;
856
+ else if (p?.pat && utils_1.t.isIdentifier(p.pat)) {
857
+ componentParamNames.add(p.pat.value);
847
858
  }
848
- for (const decl of declarations) {
849
- if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
850
- continue;
851
- const init = decl.init;
852
- if (init.type !== 'ArrowFunctionExpression' &&
853
- init.type !== 'FunctionExpression')
854
- continue;
855
- if (init.params.length > 0) {
856
- const p = init.params[0];
857
- if (utils_1.t.isIdentifier(p)) {
858
- componentParamNames.add(p.value);
859
- }
860
- else if (p.pat && utils_1.t.isIdentifier(p.pat)) {
861
- componentParamNames.add(p.pat.value);
862
- }
859
+ };
860
+ for (const node of ast.body) {
861
+ const statement = unwrapExport(node);
862
+ if (isFunctionNode(statement)) {
863
+ addFirstParamName(statement);
864
+ }
865
+ else if (utils_1.t.isVariableDeclaration(statement)) {
866
+ for (const decl of statement.declarations) {
867
+ if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
868
+ continue;
869
+ if (isFunctionNode(decl.init))
870
+ addFirstParamName(decl.init);
863
871
  }
864
872
  }
865
873
  }
@@ -1270,14 +1278,16 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1270
1278
  ? scannedTables.componentPropsTable?.[`${resourcePath}-${owner}`]?.[varName]
1271
1279
  : undefined;
1272
1280
  if (!possibilities) {
1281
+ const candidates = [];
1273
1282
  for (const key of Object.keys(scannedTables.componentPropsTable || {})) {
1274
1283
  if (!key.startsWith(`${resourcePath}-`))
1275
1284
  continue;
1276
- if (scannedTables.componentPropsTable?.[key]?.[varName]) {
1277
- possibilities = scannedTables.componentPropsTable[key][varName];
1278
- break;
1279
- }
1285
+ const entries = scannedTables.componentPropsTable?.[key]?.[varName];
1286
+ if (entries)
1287
+ candidates.push(...entries);
1280
1288
  }
1289
+ if (candidates.length > 0)
1290
+ possibilities = candidates;
1281
1291
  }
1282
1292
  if (!possibilities || possibilities.length === 0)
1283
1293
  return false;
package/dist/core.mjs CHANGED
@@ -5,6 +5,18 @@ import { applyCssValue, genBase36Hash, exceptionCamelCase, camelToKebabCase, isA
5
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';
6
6
  export const TARGET_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
7
7
  export const EXTENSION_PATTERN = /\.(ts|tsx|js|jsx)$/;
8
+ const unwrapExport = (node) => {
9
+ if (node?.type === 'ExportDeclaration')
10
+ return node.declaration;
11
+ if (node?.type === 'ExportDefaultDeclaration')
12
+ return node.decl;
13
+ if (node?.type === 'ExportDefaultExpression')
14
+ return node.expression;
15
+ return node;
16
+ };
17
+ const isFunctionNode = (node) => node?.type === 'FunctionDeclaration' ||
18
+ node?.type === 'FunctionExpression' ||
19
+ node?.type === 'ArrowFunctionExpression';
8
20
  const isStaticArgValue = (node) => node.type === 'StringLiteral' ||
9
21
  node.type === 'NumericLiteral' ||
10
22
  node.type === 'BooleanLiteral' ||
@@ -279,10 +291,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
279
291
  }
280
292
  const components = [];
281
293
  for (const node of ast.body) {
282
- const statement = t.isExportDeclaration(node) ? node.declaration : node;
283
- if (statement.type === 'FunctionDeclaration' && statement.identifier) {
294
+ const statement = unwrapExport(node);
295
+ if (isFunctionNode(statement)) {
284
296
  components.push({
285
- name: statement.identifier.value,
297
+ name: statement.identifier?.value ?? 'default',
286
298
  node: statement,
287
299
  });
288
300
  }
@@ -800,30 +812,26 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
800
812
  });
801
813
  const jsxOpeningElementMap = new Map();
802
814
  const componentParamNames = new Set();
803
- for (const node of ast.body) {
804
- let declarations = [];
805
- if (t.isVariableDeclaration(node)) {
806
- declarations = node.declarations;
815
+ const addFirstParamName = (fn) => {
816
+ const p = fn.params[0];
817
+ if (t.isIdentifier(p)) {
818
+ componentParamNames.add(p.value);
807
819
  }
808
- else if (t.isExportDeclaration(node) &&
809
- t.isVariableDeclaration(node.declaration)) {
810
- declarations = node.declaration.declarations;
820
+ else if (p?.pat && t.isIdentifier(p.pat)) {
821
+ componentParamNames.add(p.pat.value);
811
822
  }
812
- for (const decl of declarations) {
813
- if (!t.isIdentifier(decl.id) || !decl.init)
814
- continue;
815
- const init = decl.init;
816
- if (init.type !== 'ArrowFunctionExpression' &&
817
- init.type !== 'FunctionExpression')
818
- continue;
819
- if (init.params.length > 0) {
820
- const p = init.params[0];
821
- if (t.isIdentifier(p)) {
822
- componentParamNames.add(p.value);
823
- }
824
- else if (p.pat && t.isIdentifier(p.pat)) {
825
- componentParamNames.add(p.pat.value);
826
- }
823
+ };
824
+ for (const node of ast.body) {
825
+ const statement = unwrapExport(node);
826
+ if (isFunctionNode(statement)) {
827
+ addFirstParamName(statement);
828
+ }
829
+ else if (t.isVariableDeclaration(statement)) {
830
+ for (const decl of statement.declarations) {
831
+ if (!t.isIdentifier(decl.id) || !decl.init)
832
+ continue;
833
+ if (isFunctionNode(decl.init))
834
+ addFirstParamName(decl.init);
827
835
  }
828
836
  }
829
837
  }
@@ -1234,14 +1242,16 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1234
1242
  ? scannedTables.componentPropsTable?.[`${resourcePath}-${owner}`]?.[varName]
1235
1243
  : undefined;
1236
1244
  if (!possibilities) {
1245
+ const candidates = [];
1237
1246
  for (const key of Object.keys(scannedTables.componentPropsTable || {})) {
1238
1247
  if (!key.startsWith(`${resourcePath}-`))
1239
1248
  continue;
1240
- if (scannedTables.componentPropsTable?.[key]?.[varName]) {
1241
- possibilities = scannedTables.componentPropsTable[key][varName];
1242
- break;
1243
- }
1249
+ const entries = scannedTables.componentPropsTable?.[key]?.[varName];
1250
+ if (entries)
1251
+ candidates.push(...entries);
1244
1252
  }
1253
+ if (candidates.length > 0)
1254
+ possibilities = candidates;
1245
1255
  }
1246
1256
  if (!possibilities || possibilities.length === 0)
1247
1257
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/unplugin",
3
- "version": "18.3.11",
3
+ "version": "18.3.13",
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.11"
97
+ "@plumeria/utils": "^18.3.13"
98
98
  },
99
99
  "devDependencies": {
100
100
  "@swc/core": "1.15.47",