@plumeria/utils 19.12.0 → 19.13.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.
- package/dist/compile.d.ts +2 -0
- package/dist/compile.js +149 -22
- package/dist/constValue.js +2 -1
- package/dist/parser.d.ts +2 -0
- package/dist/parser.js +20 -5
- package/dist/sourceCache.d.ts +2 -0
- package/dist/sourceCache.js +62 -0
- package/dist/transform.d.ts +0 -2
- package/dist/transform.js +5 -17
- package/package.json +1 -1
package/dist/compile.d.ts
CHANGED
package/dist/compile.js
CHANGED
|
@@ -36,7 +36,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.compileCSS = compileCSS;
|
|
37
37
|
const core_1 = require("@swc/core");
|
|
38
38
|
const zss_engine_1 = require("zss-engine");
|
|
39
|
-
const
|
|
39
|
+
const sourceCache_1 = require("./sourceCache");
|
|
40
|
+
const parser_1 = require("./parser");
|
|
40
41
|
const path = __importStar(require("path"));
|
|
41
42
|
const rs = __importStar(require("@rust-gear/glob"));
|
|
42
43
|
const index_1 = require("./index");
|
|
@@ -236,19 +237,99 @@ function extractStylesFromExpression(expression, ctx) {
|
|
|
236
237
|
}
|
|
237
238
|
return results;
|
|
238
239
|
}
|
|
240
|
+
const writtenTableNames = [
|
|
241
|
+
'createThemeHashTable',
|
|
242
|
+
'createThemeObjectTable',
|
|
243
|
+
'createThemeSelectorTable',
|
|
244
|
+
'createStaticHashTable',
|
|
245
|
+
'createStaticObjectTable',
|
|
246
|
+
'keyframesObjectTable',
|
|
247
|
+
'viewTransitionObjectTable',
|
|
248
|
+
'createAtomicMapTable',
|
|
249
|
+
];
|
|
250
|
+
const createWrites = (tables) => Object.fromEntries(writtenTableNames.map((name) => [name, Object.create(tables[name])]));
|
|
251
|
+
const readTables = (tables, writes) => ({
|
|
252
|
+
...tables,
|
|
253
|
+
...writes,
|
|
254
|
+
});
|
|
255
|
+
const snapshotWrites = (writes) => Object.fromEntries(writtenTableNames.map((name) => [name, { ...writes[name] }]));
|
|
256
|
+
const applyWrites = (tables, writes) => {
|
|
257
|
+
for (const name of writtenTableNames) {
|
|
258
|
+
Object.assign(tables[name], writes[name]);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const sheetCache = new Map();
|
|
262
|
+
let sheetCacheContext = '';
|
|
263
|
+
let sheetGlobals = '';
|
|
239
264
|
function compileCSS(options) {
|
|
240
265
|
const { include, exclude, cwd = process.cwd(), styleProp = index_1.DEFAULT_STYLE_PROP, } = options;
|
|
241
266
|
const propertyPolicy = (0, index_1.resolvePropertyPolicy)(options);
|
|
242
267
|
const allSheets = new Set();
|
|
243
|
-
const files =
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const
|
|
268
|
+
const files = options.files ??
|
|
269
|
+
rs.globSync(include, {
|
|
270
|
+
cwd,
|
|
271
|
+
exclude: exclude,
|
|
272
|
+
sort: true,
|
|
273
|
+
});
|
|
274
|
+
const tables = (0, index_1.scanOverlay)(cwd, styleProp);
|
|
275
|
+
const context = JSON.stringify([
|
|
276
|
+
path.resolve(cwd),
|
|
277
|
+
styleProp,
|
|
278
|
+
propertyPolicy,
|
|
279
|
+
]);
|
|
280
|
+
const globals = JSON.stringify([
|
|
281
|
+
tables.createThemeHashTable,
|
|
282
|
+
tables.createThemeObjectTable,
|
|
283
|
+
tables.createThemeSelectorTable,
|
|
284
|
+
tables.keyframesObjectTable,
|
|
285
|
+
tables.viewTransitionObjectTable,
|
|
286
|
+
].map((table) => {
|
|
287
|
+
const flat = {};
|
|
288
|
+
for (const key in table)
|
|
289
|
+
flat[key] = table[key];
|
|
290
|
+
return flat;
|
|
291
|
+
}));
|
|
292
|
+
if (sheetCacheContext !== context || sheetGlobals !== globals)
|
|
293
|
+
sheetCache.clear();
|
|
294
|
+
for (const [file, entry] of sheetCache) {
|
|
295
|
+
if (entry.revision !== 0 && (0, parser_1.compilationRevision)(file) === 0)
|
|
296
|
+
sheetCache.delete(file);
|
|
297
|
+
}
|
|
298
|
+
sheetCacheContext = context;
|
|
299
|
+
sheetGlobals = globals;
|
|
300
|
+
const scope = JSON.stringify([
|
|
301
|
+
include,
|
|
302
|
+
exclude,
|
|
303
|
+
options.files,
|
|
304
|
+
options.sources,
|
|
305
|
+
Object.keys(options.sources ?? {}).length
|
|
306
|
+
? (0, parser_1.compilationGeneration)()
|
|
307
|
+
: undefined,
|
|
308
|
+
]);
|
|
309
|
+
const stamps = new Map();
|
|
310
|
+
const stampOf = (file) => {
|
|
311
|
+
if (!stamps.has(file)) {
|
|
312
|
+
try {
|
|
313
|
+
stamps.set(file, (0, sourceCache_1.sourceStamp)(file));
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
stamps.set(file, undefined);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return stamps.get(file);
|
|
320
|
+
};
|
|
321
|
+
let imports = new Set();
|
|
322
|
+
const propsByFile = new Map();
|
|
323
|
+
for (const [key, props] of Object.entries(tables.componentPropsTable ?? {})) {
|
|
324
|
+
const file = key.slice(0, key.lastIndexOf('-'));
|
|
325
|
+
const entries = propsByFile.get(file) ?? [];
|
|
326
|
+
entries.push([key, props]);
|
|
327
|
+
propsByFile.set(file, entries);
|
|
328
|
+
}
|
|
329
|
+
const processFile = (filePath, writes) => {
|
|
330
|
+
const scannedTables = readTables(tables, writes);
|
|
250
331
|
const resourcePath = path.resolve(cwd, filePath);
|
|
251
|
-
const source =
|
|
332
|
+
const source = options.sources?.[resourcePath] ?? (0, sourceCache_1.readSource)(resourcePath);
|
|
252
333
|
const extractedSheets = [];
|
|
253
334
|
const ast = (0, core_1.parseSync)(source, {
|
|
254
335
|
syntax: 'typescript',
|
|
@@ -293,6 +374,7 @@ function compileCSS(options) {
|
|
|
293
374
|
}
|
|
294
375
|
const actualPath = (0, index_1.resolveImportPath)(sourcePath, resourcePath);
|
|
295
376
|
if (actualPath) {
|
|
377
|
+
imports.add(actualPath);
|
|
296
378
|
node.specifiers.forEach((specifier) => {
|
|
297
379
|
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
298
380
|
localImports[specifier.local.value] = {
|
|
@@ -923,14 +1005,14 @@ function compileCSS(options) {
|
|
|
923
1005
|
index_1.t.isObjectExpression(args[0].expression)) {
|
|
924
1006
|
const obj = (0, index_1.objectExpressionToObject)(args[0].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
925
1007
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
926
|
-
|
|
1008
|
+
writes.keyframesObjectTable[hash] = obj;
|
|
927
1009
|
}
|
|
928
1010
|
else if (propName === 'viewTransition' &&
|
|
929
1011
|
args.length > 0 &&
|
|
930
1012
|
index_1.t.isObjectExpression(args[0].expression)) {
|
|
931
1013
|
const obj = (0, index_1.objectExpressionToObject)(args[0].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
932
1014
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
933
|
-
|
|
1015
|
+
writes.viewTransitionObjectTable[hash] = obj;
|
|
934
1016
|
}
|
|
935
1017
|
else if (propName === 'createTheme' &&
|
|
936
1018
|
args.length >= 2 &&
|
|
@@ -947,9 +1029,9 @@ function compileCSS(options) {
|
|
|
947
1029
|
}
|
|
948
1030
|
const obj = (0, index_1.objectExpressionToObject)(args[1].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
949
1031
|
const hash = (0, index_1.themeHashOf)(selector, obj);
|
|
950
|
-
|
|
1032
|
+
writes.createThemeObjectTable[hash] = obj;
|
|
951
1033
|
if (ctx.scannedTables.createThemeSelectorTable) {
|
|
952
|
-
|
|
1034
|
+
writes.createThemeSelectorTable[hash] = selector;
|
|
953
1035
|
}
|
|
954
1036
|
}
|
|
955
1037
|
else if (propName === 'createStatic' &&
|
|
@@ -957,7 +1039,7 @@ function compileCSS(options) {
|
|
|
957
1039
|
index_1.t.isObjectExpression(args[0].expression)) {
|
|
958
1040
|
const obj = (0, index_1.objectExpressionToObject)(args[0].expression, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
959
1041
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
960
|
-
|
|
1042
|
+
writes.createStaticObjectTable[hash] = obj;
|
|
961
1043
|
}
|
|
962
1044
|
}
|
|
963
1045
|
};
|
|
@@ -1030,10 +1112,10 @@ function compileCSS(options) {
|
|
|
1030
1112
|
const obj = (0, index_1.objectExpressionToObject)(arg, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable);
|
|
1031
1113
|
const hash = (0, index_1.themeHashOf)(selector, obj);
|
|
1032
1114
|
const uKey = `${resourcePath}-${node.id.value}`;
|
|
1033
|
-
|
|
1034
|
-
|
|
1115
|
+
writes.createThemeHashTable[uKey] = hash;
|
|
1116
|
+
writes.createThemeObjectTable[hash] = obj;
|
|
1035
1117
|
if (ctx.scannedTables.createThemeSelectorTable) {
|
|
1036
|
-
|
|
1118
|
+
writes.createThemeSelectorTable[hash] = selector;
|
|
1037
1119
|
}
|
|
1038
1120
|
const themeHashMap = {};
|
|
1039
1121
|
for (const [key, value] of Object.entries(obj)) {
|
|
@@ -1041,7 +1123,7 @@ function compileCSS(options) {
|
|
|
1041
1123
|
const atomicHash = (0, zss_engine_1.genBase36Hash)({ _theme: hash, [key]: value }, 1, 8);
|
|
1042
1124
|
themeHashMap[key] = `var(--${atomicHash}-${cssVarName})`;
|
|
1043
1125
|
}
|
|
1044
|
-
|
|
1126
|
+
writes.createAtomicMapTable[hash] = themeHashMap;
|
|
1045
1127
|
ctx.localCreateStyles[node.id.value] = {
|
|
1046
1128
|
type: 'create',
|
|
1047
1129
|
obj: ctx.scannedTables.createAtomicMapTable[hash],
|
|
@@ -1052,8 +1134,8 @@ function compileCSS(options) {
|
|
|
1052
1134
|
if (obj) {
|
|
1053
1135
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
1054
1136
|
const uKey = `${resourcePath}-${node.id.value}`;
|
|
1055
|
-
|
|
1056
|
-
|
|
1137
|
+
writes.createStaticHashTable[uKey] = hash;
|
|
1138
|
+
writes.createStaticObjectTable[hash] = obj;
|
|
1057
1139
|
ctx.mergedCreateStaticHashTable[node.id.value] = hash;
|
|
1058
1140
|
}
|
|
1059
1141
|
}
|
|
@@ -1145,9 +1227,54 @@ function compileCSS(options) {
|
|
|
1145
1227
|
});
|
|
1146
1228
|
return extractedSheets;
|
|
1147
1229
|
};
|
|
1230
|
+
const closures = new Map();
|
|
1231
|
+
const closureOf = (file) => {
|
|
1232
|
+
let closure = closures.get(file);
|
|
1233
|
+
if (!closure) {
|
|
1234
|
+
closure = [file, ...(0, parser_1.getFileDependencies)(file)].map((dependency) => [dependency, stampOf(dependency)]);
|
|
1235
|
+
closures.set(file, closure);
|
|
1236
|
+
}
|
|
1237
|
+
return closure;
|
|
1238
|
+
};
|
|
1239
|
+
const verified = new Map();
|
|
1240
|
+
const isFresh = (closure) => {
|
|
1241
|
+
let fresh = verified.get(closure);
|
|
1242
|
+
if (fresh === undefined) {
|
|
1243
|
+
fresh = closure.every(([file, stamp]) => stampOf(file) === stamp);
|
|
1244
|
+
verified.set(closure, fresh);
|
|
1245
|
+
}
|
|
1246
|
+
return fresh;
|
|
1247
|
+
};
|
|
1148
1248
|
for (const file of files) {
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1249
|
+
const resource = path.resolve(cwd, file);
|
|
1250
|
+
const key = JSON.stringify([
|
|
1251
|
+
scope,
|
|
1252
|
+
stampOf(resource),
|
|
1253
|
+
(0, parser_1.compilationRevision)(resource),
|
|
1254
|
+
propsByFile.get(resource),
|
|
1255
|
+
]);
|
|
1256
|
+
let cached = sheetCache.get(resource);
|
|
1257
|
+
if (cached?.key !== key || !cached.dependencies.every(isFresh)) {
|
|
1258
|
+
imports = new Set();
|
|
1259
|
+
const writes = createWrites(tables);
|
|
1260
|
+
try {
|
|
1261
|
+
const sheets = processFile(file, writes);
|
|
1262
|
+
cached = {
|
|
1263
|
+
key,
|
|
1264
|
+
revision: (0, parser_1.compilationRevision)(resource),
|
|
1265
|
+
sheets,
|
|
1266
|
+
writes: snapshotWrites(writes),
|
|
1267
|
+
dependencies: [...imports].map(closureOf),
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
catch (error) {
|
|
1271
|
+
sheetCache.delete(resource);
|
|
1272
|
+
throw error;
|
|
1273
|
+
}
|
|
1274
|
+
sheetCache.set(resource, cached);
|
|
1275
|
+
}
|
|
1276
|
+
applyWrites(tables, cached.writes);
|
|
1277
|
+
for (const sheet of cached.sheets) {
|
|
1151
1278
|
allSheets.add(sheet);
|
|
1152
1279
|
}
|
|
1153
1280
|
}
|
package/dist/constValue.js
CHANGED
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.resolveExportValue = resolveExportValue;
|
|
37
|
+
const sourceCache_1 = require("./sourceCache");
|
|
37
38
|
const fs = __importStar(require("fs"));
|
|
38
39
|
const core_1 = require("@swc/core");
|
|
39
40
|
const parser_1 = require("./parser");
|
|
@@ -44,7 +45,7 @@ function readConstFile(filePath) {
|
|
|
44
45
|
const cached = constFileCache.get(filePath);
|
|
45
46
|
if (cached && cached.mtimeMs === mtimeMs)
|
|
46
47
|
return cached;
|
|
47
|
-
const ast = (0, core_1.parseSync)(
|
|
48
|
+
const ast = (0, core_1.parseSync)((0, sourceCache_1.readSource)(filePath), {
|
|
48
49
|
syntax: 'typescript',
|
|
49
50
|
tsx: true,
|
|
50
51
|
target: 'es2022',
|
package/dist/parser.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export declare function resolveFileError(actualPath: string, importedName: strin
|
|
|
52
52
|
filePath: string;
|
|
53
53
|
message: string;
|
|
54
54
|
} | undefined;
|
|
55
|
+
export declare function compilationGeneration(): number;
|
|
56
|
+
export declare function compilationRevision(file: string): number;
|
|
55
57
|
export declare function fileTableKeys(filePath: string, tableName: string): ReadonlySet<string> | undefined;
|
|
56
58
|
export declare function scanOverlay(scanCwd?: string, styleProp?: string): Tables;
|
|
57
59
|
export declare function scanAll(scanCwd?: string, styleProp?: string): Tables;
|
package/dist/parser.js
CHANGED
|
@@ -44,6 +44,8 @@ exports.collectLocalConsts = collectLocalConsts;
|
|
|
44
44
|
exports.readsParams = readsParams;
|
|
45
45
|
exports.resolveThemeSelector = resolveThemeSelector;
|
|
46
46
|
exports.resolveFileError = resolveFileError;
|
|
47
|
+
exports.compilationGeneration = compilationGeneration;
|
|
48
|
+
exports.compilationRevision = compilationRevision;
|
|
47
49
|
exports.fileTableKeys = fileTableKeys;
|
|
48
50
|
exports.scanOverlay = scanOverlay;
|
|
49
51
|
exports.scanAll = scanAll;
|
|
@@ -51,6 +53,7 @@ exports.getFileDependencies = getFileDependencies;
|
|
|
51
53
|
exports.resolveExport = resolveExport;
|
|
52
54
|
exports.extractOndemandStyles = extractOndemandStyles;
|
|
53
55
|
exports.deepMerge = deepMerge;
|
|
56
|
+
const sourceCache_1 = require("./sourceCache");
|
|
54
57
|
const createTheme_1 = require("./createTheme");
|
|
55
58
|
const core_1 = require("@swc/core");
|
|
56
59
|
const path = __importStar(require("path"));
|
|
@@ -1107,6 +1110,13 @@ const detachedOverlayTables = new Set([
|
|
|
1107
1110
|
]);
|
|
1108
1111
|
let overlayScan = false;
|
|
1109
1112
|
let tablesGeneration = 0;
|
|
1113
|
+
const compileRevisions = new Map();
|
|
1114
|
+
function compilationGeneration() {
|
|
1115
|
+
return tablesGeneration;
|
|
1116
|
+
}
|
|
1117
|
+
function compilationRevision(file) {
|
|
1118
|
+
return compileRevisions.get(file) ?? 0;
|
|
1119
|
+
}
|
|
1110
1120
|
let overlayBaseGeneration = -1;
|
|
1111
1121
|
let overlayBase;
|
|
1112
1122
|
function layerTables(source, detached) {
|
|
@@ -1391,6 +1401,10 @@ function runScan(scanCwd, styleProp) {
|
|
|
1391
1401
|
return snapshotTables();
|
|
1392
1402
|
}
|
|
1393
1403
|
tablesGeneration++;
|
|
1404
|
+
for (const file of invalidated)
|
|
1405
|
+
compileRevisions.set(file, tablesGeneration);
|
|
1406
|
+
for (const file of deletedFiles)
|
|
1407
|
+
compileRevisions.delete(file);
|
|
1394
1408
|
for (const fp of deletedFiles) {
|
|
1395
1409
|
const cached = fileCache[fp];
|
|
1396
1410
|
if (cached)
|
|
@@ -1410,7 +1424,7 @@ function runScan(scanCwd, styleProp) {
|
|
|
1410
1424
|
for (const filePath of uncachedFiles) {
|
|
1411
1425
|
try {
|
|
1412
1426
|
const stats = fs.statSync(filePath);
|
|
1413
|
-
const source =
|
|
1427
|
+
const source = (0, sourceCache_1.readSource)(filePath);
|
|
1414
1428
|
if (!(0, stylePropFilter_1.needsCompile)(source, styleProp, filePath)) {
|
|
1415
1429
|
updateDependencyEdges(filePath, fileCache[filePath]?.dependencies, undefined);
|
|
1416
1430
|
fileCache[filePath] = {
|
|
@@ -2493,7 +2507,7 @@ function resolveExport(filePath, exportName, visited = new Set()) {
|
|
|
2493
2507
|
if ((!fileCache[filePath]?.exports ||
|
|
2494
2508
|
fileCache[filePath].exportsMtimeMs !== stats.mtimeMs) &&
|
|
2495
2509
|
stats.isFile()) {
|
|
2496
|
-
const source =
|
|
2510
|
+
const source = (0, sourceCache_1.readSource)(filePath);
|
|
2497
2511
|
const ast = (0, core_1.parseSync)(source, {
|
|
2498
2512
|
syntax: 'typescript',
|
|
2499
2513
|
tsx: true,
|
|
@@ -2623,9 +2637,10 @@ function extractOndemandStyles(obj, addSheet, t) {
|
|
|
2623
2637
|
}
|
|
2624
2638
|
}
|
|
2625
2639
|
if (usedVariables.size > 0) {
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
.
|
|
2640
|
+
const themeNames = [];
|
|
2641
|
+
for (const name in t.createThemeHashTable)
|
|
2642
|
+
themeNames.push(name);
|
|
2643
|
+
themeNames.sort().forEach((themeVarName) => {
|
|
2629
2644
|
const hash = t.createThemeHashTable[themeVarName];
|
|
2630
2645
|
const definition = t.createThemeObjectTable[hash];
|
|
2631
2646
|
const selector = t.createThemeSelectorTable[hash];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.sourceStamp = sourceStamp;
|
|
37
|
+
exports.readSource = readSource;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const sources = new Map();
|
|
40
|
+
const LIMIT = 4096;
|
|
41
|
+
function sourceStamp(file) {
|
|
42
|
+
const stat = fs.statSync(file);
|
|
43
|
+
return `${stat.mtimeMs}:${stat.ctimeMs}:${stat.size}`;
|
|
44
|
+
}
|
|
45
|
+
function readSource(file) {
|
|
46
|
+
let stamp;
|
|
47
|
+
try {
|
|
48
|
+
stamp = sourceStamp(file);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
sources.delete(file);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
const cached = sources.get(file);
|
|
55
|
+
if (cached?.stamp === stamp)
|
|
56
|
+
return cached.source;
|
|
57
|
+
const source = fs.readFileSync(file, 'utf8');
|
|
58
|
+
if (sources.size >= LIMIT)
|
|
59
|
+
sources.delete(sources.keys().next().value);
|
|
60
|
+
sources.set(file, { stamp, source });
|
|
61
|
+
return source;
|
|
62
|
+
}
|
package/dist/transform.d.ts
CHANGED
|
@@ -8,11 +8,9 @@ export type TransformEnv = {
|
|
|
8
8
|
classProp?: string;
|
|
9
9
|
propertyPolicy: PropertyPolicy | undefined;
|
|
10
10
|
isDev: boolean;
|
|
11
|
-
collectOndemandSheets: boolean;
|
|
12
11
|
addDependency: (depPath: string) => void;
|
|
13
12
|
};
|
|
14
13
|
export type TransformOutput = {
|
|
15
14
|
code: string;
|
|
16
|
-
sheets: string[];
|
|
17
15
|
};
|
|
18
16
|
export declare const transformSource: (env: TransformEnv) => Promise<TransformOutput>;
|
package/dist/transform.js
CHANGED
|
@@ -181,7 +181,7 @@ const foldDynamicVars = (vars) => {
|
|
|
181
181
|
});
|
|
182
182
|
};
|
|
183
183
|
const transformSource = async (env) => {
|
|
184
|
-
const { source, root, styleProp, propertyPolicy, isDev,
|
|
184
|
+
const { source, root, styleProp, propertyPolicy, isDev, addDependency } = env;
|
|
185
185
|
const classProp = env.classProp ?? 'className';
|
|
186
186
|
const id = env.moduleId;
|
|
187
187
|
const resourcePath = env.moduleId;
|
|
@@ -335,20 +335,7 @@ const transformSource = async (env) => {
|
|
|
335
335
|
appliedStyleProps.add(`${owner}:${name}`);
|
|
336
336
|
}
|
|
337
337
|
};
|
|
338
|
-
const
|
|
339
|
-
const addSheet = (sheet) => {
|
|
340
|
-
extractedSheets.add(sheet);
|
|
341
|
-
};
|
|
342
|
-
const processStyleRecords = (style, weights) => {
|
|
343
|
-
const records = (0, create_1.getStyleRecords)(style, weights);
|
|
344
|
-
if (collectOndemandSheets) {
|
|
345
|
-
(0, parser_1.extractOndemandStyles)(style, addSheet, scannedTables);
|
|
346
|
-
records.forEach((r) => {
|
|
347
|
-
addSheet(r.sheet);
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
return records;
|
|
351
|
-
};
|
|
338
|
+
const processStyleRecords = (style, weights) => (0, create_1.getStyleRecords)(style, weights);
|
|
352
339
|
const localConsts = (0, parser_1.collectLocalConsts)(ast);
|
|
353
340
|
const localConstNodes = (0, parser_1.collectLocalConstNodes)(ast);
|
|
354
341
|
const importMap = {};
|
|
@@ -1588,7 +1575,8 @@ const transformSource = async (env) => {
|
|
|
1588
1575
|
continue;
|
|
1589
1576
|
if (parser_1.t.isMemberExpression(expr) &&
|
|
1590
1577
|
parser_1.t.isIdentifier(expr.object) &&
|
|
1591
|
-
expr.property.type === 'Computed'
|
|
1578
|
+
expr.property.type === 'Computed' &&
|
|
1579
|
+
expr.property.expression.type !== 'StringLiteral') {
|
|
1592
1580
|
const varName = expr.object.value;
|
|
1593
1581
|
const styleObj = isVisibleReference(expr)
|
|
1594
1582
|
? resolveCreateObject(varName)
|
|
@@ -2463,6 +2451,6 @@ const transformSource = async (env) => {
|
|
|
2463
2451
|
});
|
|
2464
2452
|
parts.push(sourceBuffer.subarray(offset));
|
|
2465
2453
|
const transformedSource = Buffer.concat(parts).toString();
|
|
2466
|
-
return { code: transformedSource
|
|
2454
|
+
return { code: transformedSource };
|
|
2467
2455
|
};
|
|
2468
2456
|
exports.transformSource = transformSource;
|