@plumeria/webpack-plugin 4.1.1 → 4.1.3

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 +46 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -251,7 +251,31 @@ function loader(source) {
251
251
  }
252
252
  return false;
253
253
  };
254
+ const hasDynamicAccess = (expr) => {
255
+ if (utils_1.t.isMemberExpression(expr) && utils_1.t.isIdentifier(expr.object)) {
256
+ const info = localCreateStyles[expr.object.value];
257
+ if (info && info.hasDynamicAccess)
258
+ return true;
259
+ }
260
+ if (utils_1.t.isIdentifier(expr)) {
261
+ const info = localCreateStyles[expr.value];
262
+ if (info && info.hasDynamicAccess)
263
+ return true;
264
+ }
265
+ if (utils_1.t.isConditionalExpression(expr)) {
266
+ return (hasDynamicAccess(expr.consequent) ||
267
+ hasDynamicAccess(expr.alternate));
268
+ }
269
+ if (utils_1.t.isBinaryExpression(expr) &&
270
+ (expr.operator === '&&' ||
271
+ expr.operator === '||' ||
272
+ expr.operator === '??')) {
273
+ return hasDynamicAccess(expr.left) || hasDynamicAccess(expr.right);
274
+ }
275
+ return false;
276
+ };
254
277
  const allStatic = args.every((arg) => checkStatic(arg.expression));
278
+ const anyDynamic = args.some((arg) => hasDynamicAccess(arg.expression));
255
279
  if (allStatic && args.length > 0) {
256
280
  const merged = args.reduce((acc, arg) => {
257
281
  const expr = arg.expression;
@@ -288,6 +312,28 @@ function loader(source) {
288
312
  });
289
313
  }
290
314
  }
315
+ else if (anyDynamic) {
316
+ const processExpr = (expr) => {
317
+ if (utils_1.t.isIdentifier(expr)) {
318
+ const info = localCreateStyles[expr.value];
319
+ if (info && info.hasDynamicAccess) {
320
+ excludedSpans.add(expr.span.start);
321
+ }
322
+ }
323
+ else if (utils_1.t.isConditionalExpression(expr)) {
324
+ processExpr(expr.consequent);
325
+ processExpr(expr.alternate);
326
+ }
327
+ else if (utils_1.t.isBinaryExpression(expr) &&
328
+ (expr.operator === '&&' ||
329
+ expr.operator === '||' ||
330
+ expr.operator === '??')) {
331
+ processExpr(expr.left);
332
+ processExpr(expr.right);
333
+ }
334
+ };
335
+ args.forEach((arg) => processExpr(arg.expression));
336
+ }
291
337
  else {
292
338
  const processExpr = (expr) => {
293
339
  if (utils_1.t.isMemberExpression(expr) &&
@@ -309,7 +355,6 @@ function loader(source) {
309
355
  else if (utils_1.t.isIdentifier(expr)) {
310
356
  const info = localCreateStyles[expr.value];
311
357
  if (info) {
312
- info.hasDynamicAccess = true;
313
358
  excludedSpans.add(expr.span.start);
314
359
  replacements.push({
315
360
  start: expr.span.start - ast.span.start,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/webpack-plugin",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
4
4
  "description": "Plumeria Webpack plugin",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  "zero-virtual.css"
23
23
  ],
24
24
  "dependencies": {
25
- "@plumeria/utils": "^4.1.1"
25
+ "@plumeria/utils": "^4.1.3"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.8",