@plumeria/compiler 15.1.3 → 16.1.0

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 +78 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -130,6 +130,7 @@ function compileCSS(options) {
130
130
  const createThemeImportMap = {};
131
131
  const createStaticImportMap = {};
132
132
  const plumeriaAliases = {};
133
+ const localImports = {};
133
134
  (0, utils_1.traverse)(ast, {
134
135
  ImportDeclaration({ node }) {
135
136
  const sourcePath = node.source.value;
@@ -158,6 +159,7 @@ function compileCSS(options) {
158
159
  : specifier.local.value;
159
160
  const localName = specifier.local.value;
160
161
  const uniqueKey = `${actualPath}-${importedName}`;
162
+ localImports[localName] = { actualPath, importedName };
161
163
  if (scannedTables.staticTable[uniqueKey])
162
164
  importMap[localName] = scannedTables.staticTable[uniqueKey];
163
165
  if (scannedTables.keyframesHashTable[uniqueKey])
@@ -277,6 +279,37 @@ function compileCSS(options) {
277
279
  sourceBuffer,
278
280
  baseByteOffset,
279
281
  };
282
+ const componentParamNames = new Set();
283
+ for (const node of ast.body) {
284
+ let declarations = [];
285
+ if (node.type === 'VariableDeclaration') {
286
+ declarations = node.declarations;
287
+ }
288
+ else if (node.type === 'ExportDeclaration' &&
289
+ node.declaration.type === 'VariableDeclaration') {
290
+ declarations = node.declaration.declarations;
291
+ }
292
+ for (const decl of declarations) {
293
+ if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
294
+ continue;
295
+ const init = decl.init;
296
+ if (init.type !== 'ArrowFunctionExpression' &&
297
+ init.type !== 'FunctionExpression')
298
+ continue;
299
+ if (init.params.length > 0) {
300
+ const p = init.params[0];
301
+ if (utils_1.t.isIdentifier(p)) {
302
+ componentParamNames.add(p.value);
303
+ }
304
+ else if (typeof p === 'object' &&
305
+ p !== null &&
306
+ 'pat' in p &&
307
+ utils_1.t.isIdentifier(p.pat)) {
308
+ componentParamNames.add(p.pat.value);
309
+ }
310
+ }
311
+ }
312
+ }
280
313
  const processStyle = (style) => {
281
314
  (0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
282
315
  const records = (0, utils_1.getStyleRecords)(style);
@@ -423,6 +456,39 @@ function compileCSS(options) {
423
456
  for (const arg of args) {
424
457
  checkFunctionKey(arg.expression);
425
458
  const expr = arg.expression;
459
+ if (utils_1.t.isIdentifier(expr) ||
460
+ (utils_1.t.isMemberExpression(expr) &&
461
+ utils_1.t.isIdentifier(expr.object) &&
462
+ componentParamNames.has(expr.object.value) &&
463
+ utils_1.t.isIdentifier(expr.property))) {
464
+ const varName = utils_1.t.isIdentifier(expr)
465
+ ? expr.value
466
+ : expr.property.value;
467
+ let propPossibilities;
468
+ for (const key of Object.keys(ctx.scannedTables.componentPropsTable || {})) {
469
+ if (key.startsWith(`${resourcePath}-`)) {
470
+ if (ctx.scannedTables.componentPropsTable?.[key]?.[varName]) {
471
+ propPossibilities =
472
+ ctx.scannedTables.componentPropsTable?.[key]?.[varName];
473
+ break;
474
+ }
475
+ }
476
+ }
477
+ if (propPossibilities && propPossibilities.length > 0) {
478
+ const uniqueEntries = [];
479
+ propPossibilities.forEach((entry) => {
480
+ if (!uniqueEntries.some((x) => x.index === entry.index)) {
481
+ uniqueEntries.push(entry);
482
+ }
483
+ });
484
+ uniqueEntries.forEach((entry) => {
485
+ if (entry.styleObj && Object.keys(entry.styleObj).length > 0) {
486
+ processStyle(entry.styleObj);
487
+ }
488
+ });
489
+ continue;
490
+ }
491
+ }
426
492
  if (utils_1.t.isCallExpression(expr)) {
427
493
  if (utils_1.t.isIdentifier(expr.callee)) {
428
494
  const varName = expr.callee.value;
@@ -766,8 +832,19 @@ function compileCSS(options) {
766
832
  processCall(path.node);
767
833
  },
768
834
  JSXAttribute({ node }) {
769
- if (node.name.value !== 'styleName')
835
+ if (node.name.type !== 'Identifier')
770
836
  return;
837
+ const attrName = node.name.value;
838
+ if (attrName !== 'styleName') {
839
+ if (node.value &&
840
+ node.value.type === 'JSXExpressionContainer' &&
841
+ node.value.expression.type !== 'JSXEmptyExpression') {
842
+ const expr = node.value.expression;
843
+ const styles = extractStylesFromExpression(expr, ctx);
844
+ styles.forEach(processStyle);
845
+ }
846
+ return;
847
+ }
771
848
  if (!node.value || node.value.type !== 'JSXExpressionContainer')
772
849
  return;
773
850
  if (node.value.expression.type === 'JSXEmptyExpression')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "15.1.3",
3
+ "version": "16.1.0",
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": "^15.1.3"
24
+ "@plumeria/utils": "^16.1.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@rust-gear/glob": "1.0.0",