@plumeria/unplugin 16.2.11 → 16.2.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 (3) hide show
  1. package/dist/core.js +21 -29
  2. package/dist/core.mjs +22 -30
  3. package/package.json +2 -2
package/dist/core.js CHANGED
@@ -137,6 +137,25 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
137
137
  err.stack = err.message;
138
138
  throw err;
139
139
  };
140
+ const assertResolvable = (node) => {
141
+ if (utils_1.t.isIdentifier(node) && node.value === 'undefined')
142
+ return;
143
+ if (utils_1.t.isMemberExpression(node) ||
144
+ utils_1.t.isIdentifier(node) ||
145
+ utils_1.t.isCallExpression(node) ||
146
+ utils_1.t.isArrowFunctionExpression(node) ||
147
+ utils_1.t.isFunctionExpression(node)) {
148
+ const rootId = (0, utils_1.getRootIdentifier)(node);
149
+ const isPlumeriaStyle = rootId &&
150
+ ((localCreateStyles[rootId] !== undefined &&
151
+ localCreateStyles[rootId].type !== 'constant') ||
152
+ mergedCreateTable[rootId] !== undefined ||
153
+ mergedVariantsTable[rootId] !== undefined);
154
+ if (!isPlumeriaStyle) {
155
+ throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(node)}" is not supported.`, node);
156
+ }
157
+ }
158
+ };
140
159
  for (const node of ast.body) {
141
160
  if (node.type === 'ImportDeclaration') {
142
161
  const sourcePath = node.source.value;
@@ -793,24 +812,6 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
793
812
  let groupIdCounter = 0;
794
813
  let baseStyle = {};
795
814
  let isOptimizable = true;
796
- const getRootIdentifier = (node) => {
797
- if (utils_1.t.isIdentifier(node)) {
798
- return node.value;
799
- }
800
- if (utils_1.t.isMemberExpression(node)) {
801
- return getRootIdentifier(node.object);
802
- }
803
- if (utils_1.t.isCallExpression(node)) {
804
- const callee = node.callee;
805
- if (callee.type !== 'Super' && callee.type !== 'Import') {
806
- return getRootIdentifier(callee);
807
- }
808
- }
809
- if (node.type === 'ParenthesisExpression') {
810
- return getRootIdentifier(node.expression);
811
- }
812
- return null;
813
- };
814
815
  const resolveCreateObject = (varName) => {
815
816
  const localStyle = localCreateStyles[varName];
816
817
  if (localStyle?.type === 'create')
@@ -876,6 +877,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
876
877
  else if (node.type === 'ParenthesisExpression') {
877
878
  return collectConditions(node.expression, currentTestStrings);
878
879
  }
880
+ assertResolvable(node);
879
881
  return false;
880
882
  };
881
883
  for (const arg of args) {
@@ -1082,17 +1084,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1082
1084
  const handled = collectConditions(expr);
1083
1085
  if (handled)
1084
1086
  continue;
1085
- if (utils_1.t.isMemberExpression(expr) || utils_1.t.isIdentifier(expr)) {
1086
- const rootId = getRootIdentifier(expr);
1087
- const isPlumeriaStyle = rootId &&
1088
- ((localCreateStyles[rootId] !== undefined &&
1089
- localCreateStyles[rootId].type !== 'constant') ||
1090
- mergedCreateTable[rootId] !== undefined ||
1091
- mergedVariantsTable[rootId] !== undefined);
1092
- if (!isPlumeriaStyle) {
1093
- throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(expr)}" is not supported.`, expr);
1094
- }
1095
- }
1087
+ assertResolvable(expr);
1096
1088
  isOptimizable = false;
1097
1089
  break;
1098
1090
  }
package/dist/core.mjs CHANGED
@@ -2,7 +2,7 @@ import { createFilter } from '@rollup/pluginutils';
2
2
  import { parseSync } from '@swc/core';
3
3
  import * as path from 'path';
4
4
  import { applyCssValue, genBase36Hash, exceptionCamelCase, camelToKebabCase, isAtRule, } from 'zss-engine';
5
- import { traverse, getStyleRecords, collectLocalConsts, objectExpressionToObject, t, extractOndemandStyles, deepMerge, scanAll, resolveImportPath, getLeadingCommentLength, optimizer, getFileDependencies, resolveExport, } from '@plumeria/utils';
5
+ import { traverse, getStyleRecords, collectLocalConsts, objectExpressionToObject, t, getRootIdentifier, extractOndemandStyles, deepMerge, scanAll, resolveImportPath, getLeadingCommentLength, optimizer, getFileDependencies, resolveExport, } from '@plumeria/utils';
6
6
  export const TARGET_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
7
7
  export const EXTENSION_PATTERN = /\.(ts|tsx|js|jsx)$/;
8
8
  export const unpluginFactory = (options = {}, unpluginMeta) => {
@@ -101,6 +101,25 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
101
101
  err.stack = err.message;
102
102
  throw err;
103
103
  };
104
+ const assertResolvable = (node) => {
105
+ if (t.isIdentifier(node) && node.value === 'undefined')
106
+ return;
107
+ if (t.isMemberExpression(node) ||
108
+ t.isIdentifier(node) ||
109
+ t.isCallExpression(node) ||
110
+ t.isArrowFunctionExpression(node) ||
111
+ t.isFunctionExpression(node)) {
112
+ const rootId = getRootIdentifier(node);
113
+ const isPlumeriaStyle = rootId &&
114
+ ((localCreateStyles[rootId] !== undefined &&
115
+ localCreateStyles[rootId].type !== 'constant') ||
116
+ mergedCreateTable[rootId] !== undefined ||
117
+ mergedVariantsTable[rootId] !== undefined);
118
+ if (!isPlumeriaStyle) {
119
+ throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(node)}" is not supported.`, node);
120
+ }
121
+ }
122
+ };
104
123
  for (const node of ast.body) {
105
124
  if (node.type === 'ImportDeclaration') {
106
125
  const sourcePath = node.source.value;
@@ -757,24 +776,6 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
757
776
  let groupIdCounter = 0;
758
777
  let baseStyle = {};
759
778
  let isOptimizable = true;
760
- const getRootIdentifier = (node) => {
761
- if (t.isIdentifier(node)) {
762
- return node.value;
763
- }
764
- if (t.isMemberExpression(node)) {
765
- return getRootIdentifier(node.object);
766
- }
767
- if (t.isCallExpression(node)) {
768
- const callee = node.callee;
769
- if (callee.type !== 'Super' && callee.type !== 'Import') {
770
- return getRootIdentifier(callee);
771
- }
772
- }
773
- if (node.type === 'ParenthesisExpression') {
774
- return getRootIdentifier(node.expression);
775
- }
776
- return null;
777
- };
778
779
  const resolveCreateObject = (varName) => {
779
780
  const localStyle = localCreateStyles[varName];
780
781
  if (localStyle?.type === 'create')
@@ -840,6 +841,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
840
841
  else if (node.type === 'ParenthesisExpression') {
841
842
  return collectConditions(node.expression, currentTestStrings);
842
843
  }
844
+ assertResolvable(node);
843
845
  return false;
844
846
  };
845
847
  for (const arg of args) {
@@ -1046,17 +1048,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1046
1048
  const handled = collectConditions(expr);
1047
1049
  if (handled)
1048
1050
  continue;
1049
- if (t.isMemberExpression(expr) || t.isIdentifier(expr)) {
1050
- const rootId = getRootIdentifier(expr);
1051
- const isPlumeriaStyle = rootId &&
1052
- ((localCreateStyles[rootId] !== undefined &&
1053
- localCreateStyles[rootId].type !== 'constant') ||
1054
- mergedCreateTable[rootId] !== undefined ||
1055
- mergedVariantsTable[rootId] !== undefined);
1056
- if (!isPlumeriaStyle) {
1057
- throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(expr)}" is not supported.`, expr);
1058
- }
1059
- }
1051
+ assertResolvable(expr);
1060
1052
  isOptimizable = false;
1061
1053
  break;
1062
1054
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/unplugin",
3
- "version": "16.2.11",
3
+ "version": "16.2.12",
4
4
  "description": "Universal Plumeria plugin for various build tools",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -89,7 +89,7 @@
89
89
  "dependencies": {
90
90
  "@rollup/pluginutils": "^5.4.0",
91
91
  "unplugin": "^3.0.0",
92
- "@plumeria/utils": "^16.2.11"
92
+ "@plumeria/utils": "^16.2.12"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@swc/core": "1.15.43",