@plumeria/compiler 3.0.0 → 3.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 +64 -46
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -77,56 +77,63 @@ async function compile(options) {
77
77
  utils_1.t.isIdentifier(callee.object, { name: 'css' }) &&
78
78
  utils_1.t.isIdentifier(callee.property)) {
79
79
  const args = node.arguments;
80
- if (callee.property.value === 'props') {
81
- const merged = {};
82
- let allStatic = true;
83
- args.forEach((arg) => {
84
- const expr = arg.expression;
85
- if (utils_1.t.isObjectExpression(expr)) {
86
- const obj = (0, utils_1.objectExpressionToObject)(expr, utils_1.tables.staticTable, utils_1.tables.keyframesHashTable, utils_1.tables.viewTransitionHashTable, utils_1.tables.themeTable);
87
- if (obj) {
88
- Object.assign(merged, obj);
89
- }
90
- else {
91
- allStatic = false;
92
- }
93
- }
94
- else if (utils_1.t.isMemberExpression(expr)) {
95
- if (utils_1.t.isIdentifier(expr.object) &&
96
- utils_1.t.isIdentifier(expr.property)) {
97
- const varName = expr.object.value;
98
- const propName = expr.property.value;
99
- const styleSet = localCreateStyles[varName];
100
- if (styleSet && styleSet[propName]) {
101
- Object.assign(merged, styleSet[propName]);
102
- }
103
- else {
104
- allStatic = false;
105
- }
106
- }
107
- else {
108
- allStatic = false;
80
+ const extractStylesFromExpression = (expr) => {
81
+ const results = [];
82
+ if (utils_1.t.isObjectExpression(expr)) {
83
+ const obj = (0, utils_1.objectExpressionToObject)(expr, utils_1.tables.staticTable, utils_1.tables.keyframesHashTable, utils_1.tables.viewTransitionHashTable, utils_1.tables.themeTable);
84
+ if (obj)
85
+ results.push(obj);
86
+ }
87
+ else if (utils_1.t.isMemberExpression(expr)) {
88
+ if (utils_1.t.isIdentifier(expr.object) &&
89
+ utils_1.t.isIdentifier(expr.property)) {
90
+ const varName = expr.object.value;
91
+ const propName = expr.property.value;
92
+ const styleSet = localCreateStyles[varName];
93
+ if (styleSet && styleSet[propName]) {
94
+ results.push(styleSet[propName]);
109
95
  }
110
96
  }
111
- else if (utils_1.t.isIdentifier(expr)) {
112
- const obj = localCreateStyles[expr.value];
113
- if (obj) {
114
- Object.assign(merged, obj);
115
- }
116
- else {
117
- allStatic = false;
97
+ else if (utils_1.t.isIdentifier(expr.object) &&
98
+ expr.property.type === 'Computed') {
99
+ const varName = expr.object.value;
100
+ const styleSet = localCreateStyles[varName];
101
+ if (styleSet) {
102
+ Object.values(styleSet).forEach((s) => results.push(s));
118
103
  }
119
104
  }
120
- else {
121
- allStatic = false;
105
+ }
106
+ else if (utils_1.t.isIdentifier(expr)) {
107
+ const obj = localCreateStyles[expr.value];
108
+ if (obj) {
109
+ results.push(obj);
122
110
  }
123
- });
124
- if (allStatic && Object.keys(merged).length > 0) {
125
- (0, utils_1.extractOndemandStyles)(merged, extractedSheets);
126
- const hash = (0, zss_engine_1.genBase36Hash)(merged, 1, 8);
127
- const records = (0, utils_1.getStyleRecords)(hash, merged, 1);
128
- records.forEach((r) => extractedSheets.push(r.sheet));
129
111
  }
112
+ else if (utils_1.t.isConditionalExpression(expr)) {
113
+ results.push(...extractStylesFromExpression(expr.consequent));
114
+ results.push(...extractStylesFromExpression(expr.alternate));
115
+ }
116
+ else if (utils_1.t.isBinaryExpression(expr) &&
117
+ (expr.operator === '&&' ||
118
+ expr.operator === '||' ||
119
+ expr.operator === '??')) {
120
+ results.push(...extractStylesFromExpression(expr.left));
121
+ results.push(...extractStylesFromExpression(expr.right));
122
+ }
123
+ return results;
124
+ };
125
+ const processStyle = (style) => {
126
+ (0, utils_1.extractOndemandStyles)(style, extractedSheets);
127
+ const hash = (0, zss_engine_1.genBase36Hash)(style, 1, 8);
128
+ const records = (0, utils_1.getStyleRecords)(hash, style, 1);
129
+ records.forEach((r) => extractedSheets.push(r.sheet));
130
+ };
131
+ if (callee.property.value === 'props') {
132
+ args.forEach((arg) => {
133
+ const expr = arg.expression;
134
+ const styles = extractStylesFromExpression(expr);
135
+ styles.forEach((s) => processStyle(s));
136
+ });
130
137
  }
131
138
  else if (callee.property.value === 'keyframes' &&
132
139
  args.length > 0 &&
@@ -152,7 +159,15 @@ async function compile(options) {
152
159
  }
153
160
  },
154
161
  });
155
- return extractedSheets;
162
+ const uniqueSheets = [];
163
+ const seen = new Set();
164
+ for (let i = extractedSheets.length - 1; i >= 0; i--) {
165
+ if (!seen.has(extractedSheets[i])) {
166
+ seen.add(extractedSheets[i]);
167
+ uniqueSheets.unshift(extractedSheets[i]);
168
+ }
169
+ }
170
+ return uniqueSheets;
156
171
  };
157
172
  const files = fs_1.default.globSync(pattern, {
158
173
  cwd,
@@ -160,7 +175,10 @@ async function compile(options) {
160
175
  });
161
176
  files.forEach((file) => {
162
177
  const sheets = processFile(file);
163
- sheets.forEach((sheet) => allSheets.add(sheet));
178
+ sheets.forEach((sheet) => {
179
+ allSheets.delete(sheet);
180
+ allSheets.add(sheet);
181
+ });
164
182
  });
165
183
  const outputPath = path_1.default.resolve(cwd, output);
166
184
  const css = Array.from(allSheets).join('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Plumeria swc based compiler",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -27,12 +27,12 @@
27
27
  "lightningcss": "^1.30.2",
28
28
  "postcss": "^8.5.6",
29
29
  "postcss-combine-media-query": "^2.1.0",
30
- "@plumeria/utils": "^3.0.0"
30
+ "@plumeria/utils": "^3.1.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@swc/core": "1.15.2",
34
34
  "zss-engine": "2.1.2",
35
- "@plumeria/core": "^3.0.0"
35
+ "@plumeria/core": "^3.1.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public",