@plumeria/compiler 8.0.2 → 9.0.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 +41 -72
  2. package/package.json +4 -3
package/dist/index.js CHANGED
@@ -1,23 +1,55 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
5
35
  Object.defineProperty(exports, "__esModule", { value: true });
6
36
  exports.compileCSS = compileCSS;
7
37
  const core_1 = require("@swc/core");
8
38
  const zss_engine_1 = require("zss-engine");
9
- const fs_1 = __importDefault(require("fs"));
39
+ const fs = __importStar(require("fs"));
40
+ const rs = __importStar(require("@rust-gear/glob"));
10
41
  const utils_1 = require("@plumeria/utils");
11
42
  const utils_2 = require("@plumeria/utils");
12
43
  function compileCSS(options) {
13
44
  const { include, exclude, cwd = process.cwd() } = options;
14
45
  const allSheets = new Set();
15
- const files = fs_1.default.globSync(include, {
46
+ const files = rs.globSync(include, {
16
47
  cwd,
17
48
  exclude: exclude,
18
49
  });
50
+ const scannedTables = (0, utils_1.scanAll)();
19
51
  const processFile = (filePath) => {
20
- const source = fs_1.default.readFileSync(filePath, 'utf-8');
52
+ const source = fs.readFileSync(filePath, 'utf-8');
21
53
  const extractedSheets = [];
22
54
  const ast = (0, core_1.parseSync)(source, {
23
55
  syntax: 'typescript',
@@ -28,7 +60,6 @@ function compileCSS(options) {
28
60
  const sourceBuffer = Buffer.from(source, 'utf-8');
29
61
  const leadingBytes = Buffer.byteLength(source.slice(0, leadingLen), 'utf-8');
30
62
  const baseByteOffset = ast.span.start - leadingBytes;
31
- const scannedTables = (0, utils_1.scanAll)();
32
63
  const localConsts = (0, utils_1.collectLocalConsts)(ast);
33
64
  const resourcePath = filePath;
34
65
  const importMap = {};
@@ -157,7 +188,7 @@ function compileCSS(options) {
157
188
  const objectName = callee.object.value;
158
189
  const propertyName = callee.property.value;
159
190
  const alias = plumeriaAliases[objectName];
160
- if (alias === 'NAMESPACE' || objectName === 'css')
191
+ if (alias === 'NAMESPACE')
161
192
  propName = propertyName;
162
193
  }
163
194
  else if (utils_1.t.isIdentifier(callee)) {
@@ -165,15 +196,6 @@ function compileCSS(options) {
165
196
  if (originalName)
166
197
  propName = originalName;
167
198
  }
168
- let localVariantName;
169
- if (!propName && utils_1.t.isIdentifier(callee)) {
170
- const varName = callee.value;
171
- if (localCreateStyles[varName] &&
172
- localCreateStyles[varName].type === 'variant') {
173
- localVariantName = varName;
174
- propName = 'props';
175
- }
176
- }
177
199
  if (propName) {
178
200
  const args = node.arguments;
179
201
  const extractStylesFromExpression = (expression) => {
@@ -240,9 +262,8 @@ function compileCSS(options) {
240
262
  const records = (0, utils_1.getStyleRecords)(style);
241
263
  records.forEach((r) => extractedSheets.push(r.sheet));
242
264
  };
243
- if (propName === 'props') {
265
+ if (propName === 'use') {
244
266
  const conditionals = [];
245
- let groupIdCounter = 0;
246
267
  let baseStyle = {};
247
268
  const resolveStyleObject = (expression) => {
248
269
  const styles = extractStylesFromExpression(expression);
@@ -252,57 +273,6 @@ function compileCSS(options) {
252
273
  };
253
274
  for (const arg of args) {
254
275
  const expr = arg.expression;
255
- let handledAsObjectArg = false;
256
- if (localVariantName && utils_1.t.isObjectExpression(expr)) {
257
- const variantObj = localCreateStyles[localVariantName].obj;
258
- if (variantObj) {
259
- const props = expr.properties;
260
- if (variantObj.base && typeof variantObj.base === 'object') {
261
- baseStyle = (0, utils_1.deepMerge)(baseStyle, variantObj.base);
262
- }
263
- const variantsMap = (variantObj.variants ||
264
- variantObj);
265
- for (const prop of props) {
266
- let groupName;
267
- let valueExpression;
268
- if (prop.type === 'KeyValueProperty' &&
269
- prop.key.type === 'Identifier') {
270
- groupName = prop.key.value;
271
- valueExpression = prop.value;
272
- }
273
- else if (prop.type === 'Identifier') {
274
- groupName = prop.value;
275
- valueExpression = prop;
276
- }
277
- if (groupName && valueExpression && variantsMap[groupName]) {
278
- const groupVariants = variantsMap[groupName];
279
- if (!groupVariants || typeof groupVariants !== 'object')
280
- continue;
281
- const currentGroupId = ++groupIdCounter;
282
- if (valueExpression.type === 'StringLiteral') {
283
- if (groupVariants[valueExpression.value]) {
284
- baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariants[valueExpression.value]);
285
- }
286
- continue;
287
- }
288
- Object.entries(groupVariants).forEach(([optionName, style]) => {
289
- conditionals.push({
290
- test: valueExpression,
291
- truthy: style,
292
- falsy: {},
293
- groupId: currentGroupId,
294
- groupName: groupName,
295
- valueName: optionName,
296
- varName: localVariantName,
297
- });
298
- });
299
- }
300
- }
301
- handledAsObjectArg = true;
302
- }
303
- }
304
- if (handledAsObjectArg)
305
- continue;
306
276
  const getSource = (node) => sourceBuffer
307
277
  .subarray(node.span.start - baseByteOffset, node.span.end - baseByteOffset)
308
278
  .toString('utf-8');
@@ -407,8 +377,7 @@ function compileCSS(options) {
407
377
  if (utils_1.t.isMemberExpression(callee) &&
408
378
  utils_1.t.isIdentifier(callee.object) &&
409
379
  utils_1.t.isIdentifier(callee.property)) {
410
- if (callee.object.value === 'css' ||
411
- plumeriaAliases[callee.object.value] === 'NAMESPACE')
380
+ if (plumeriaAliases[callee.object.value] === 'NAMESPACE')
412
381
  pName = callee.property.value;
413
382
  }
414
383
  else if (utils_1.t.isIdentifier(callee) && plumeriaAliases[callee.value]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "8.0.2",
3
+ "version": "9.0.0",
4
4
  "description": "Plumeria swc based compiler for statically extracting css",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -21,10 +21,11 @@
21
21
  "dist/"
22
22
  ],
23
23
  "dependencies": {
24
- "@plumeria/utils": "^8.0.2"
24
+ "@plumeria/utils": "^9.0.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@swc/core": "1.15.8",
27
+ "@rust-gear/glob": "0.2.8",
28
+ "@swc/core": "1.15.18",
28
29
  "zss-engine": "2.2.4"
29
30
  },
30
31
  "publishConfig": {