@pandacss/compiler 2.0.0-beta.4 → 2.0.0-beta.6
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/binding.cjs +52 -52
- package/dist/chunk-VRB2SXJJ.js +1029 -0
- package/dist/index.d.ts +69 -10
- package/dist/index.js +5 -1
- package/dist/loader.js +1 -1
- package/package.json +19 -15
- package/dist/chunk-H22MKDJV.js +0 -530
package/dist/chunk-H22MKDJV.js
DELETED
|
@@ -1,530 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import {
|
|
3
|
-
assertProjectHooks,
|
|
4
|
-
assertProjectCallbacks,
|
|
5
|
-
getTokenCategoryValues,
|
|
6
|
-
makeBuildInfoApi as makeBuildInfoApi2,
|
|
7
|
-
mergeCallbacks,
|
|
8
|
-
mergeHooks,
|
|
9
|
-
prepareCompilerConfig
|
|
10
|
-
} from "@pandacss/compiler-shared";
|
|
11
|
-
|
|
12
|
-
// src/callbacks.ts
|
|
13
|
-
import {
|
|
14
|
-
createPatternHelpers,
|
|
15
|
-
createTransformArgs,
|
|
16
|
-
getPatternDefaultValueRefsByTransformId,
|
|
17
|
-
mergePatternDefaultValues
|
|
18
|
-
} from "@pandacss/compiler-shared";
|
|
19
|
-
function registerCallbacks(project, callbacks, hooks, tokenDictionary) {
|
|
20
|
-
const utilityTransforms = callbacks["utility.transform"];
|
|
21
|
-
const hasUtilityTransforms = !!utilityTransforms && Object.keys(utilityTransforms).length > 0;
|
|
22
|
-
const patternTransforms = callbacks["pattern.transform"];
|
|
23
|
-
const hasPatternTransforms = !!patternTransforms && Object.keys(patternTransforms).length > 0;
|
|
24
|
-
const config = project.config();
|
|
25
|
-
const patternDefaultValues = callbacks["pattern.defaultValues"];
|
|
26
|
-
const patternDefaultValueRefs = config && patternDefaultValues ? getPatternDefaultValueRefsByTransformId(config) : /* @__PURE__ */ new Map();
|
|
27
|
-
if (hasPatternTransforms && !project.registerPatternTransform) {
|
|
28
|
-
throw new Error("Native project does not support pattern.transform callbacks");
|
|
29
|
-
}
|
|
30
|
-
if (project.registerPatternTransform && patternTransforms) {
|
|
31
|
-
for (const [id, callback] of Object.entries(patternTransforms)) {
|
|
32
|
-
const defaultValueId = patternDefaultValueRefs.get(id);
|
|
33
|
-
const defaultValue = defaultValueId ? patternDefaultValues?.[defaultValueId] : void 0;
|
|
34
|
-
project.registerPatternTransform(id, (props) => {
|
|
35
|
-
const input = props;
|
|
36
|
-
const nextProps = defaultValue ? mergePatternDefaultValues(defaultValue(input), input) : input;
|
|
37
|
-
return callback(nextProps, createPatternHelpers());
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (hasUtilityTransforms && !project.registerUtilityTransform) {
|
|
42
|
-
throw new Error("Native project does not support utility.transform callbacks");
|
|
43
|
-
}
|
|
44
|
-
if (project.registerUtilityTransform && utilityTransforms) {
|
|
45
|
-
for (const [id, callback] of Object.entries(utilityTransforms)) {
|
|
46
|
-
project.registerUtilityTransform(id, (resolved, original) => {
|
|
47
|
-
return callback(resolved, createTransformArgs(original, tokenDictionary));
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const sourceTransforms = hooks?.["parser:before"];
|
|
52
|
-
if (sourceTransforms?.length && !project.registerSourceTransform) {
|
|
53
|
-
throw new Error("Native project does not support parser:before callbacks");
|
|
54
|
-
}
|
|
55
|
-
if (project.registerSourceTransform && sourceTransforms) {
|
|
56
|
-
for (const hook of sourceTransforms) {
|
|
57
|
-
const callback = callbacks["parser:before"]?.[hook.id];
|
|
58
|
-
if (!callback) continue;
|
|
59
|
-
project.registerSourceTransform(hook.id, hook.filter, (filePath, content) => {
|
|
60
|
-
const result = callback({ filePath: String(filePath), content: String(content), original: String(content) });
|
|
61
|
-
if (isPromiseLike(result)) {
|
|
62
|
-
throw new Error(`parser:before callback \`${hook.id}\` must be synchronous`);
|
|
63
|
-
}
|
|
64
|
-
return typeof result === "string" ? result : void 0;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function isPromiseLike(value) {
|
|
70
|
-
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// src/fallback.ts
|
|
74
|
-
import { makeBuildInfoApi } from "@pandacss/compiler-shared";
|
|
75
|
-
var FallbackExtractor = class {
|
|
76
|
-
extract() {
|
|
77
|
-
return { calls: [], jsx: [], diagnostics: [] };
|
|
78
|
-
}
|
|
79
|
-
extractDebug() {
|
|
80
|
-
return { imports: [], matched: [], calls: [], jsx: [], diagnostics: [] };
|
|
81
|
-
}
|
|
82
|
-
matchImports() {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
var FallbackCompiler = class _FallbackCompiler {
|
|
87
|
-
static fromConfig() {
|
|
88
|
-
return new _FallbackCompiler();
|
|
89
|
-
}
|
|
90
|
-
config() {
|
|
91
|
-
return {};
|
|
92
|
-
}
|
|
93
|
-
extractFileSource() {
|
|
94
|
-
return { calls: [], jsx: [], diagnostics: [] };
|
|
95
|
-
}
|
|
96
|
-
parseFile(path) {
|
|
97
|
-
return { path, cssCalls: 0, cvaCalls: 0, svaCalls: 0, jsxUsages: 0, diagnostics: [] };
|
|
98
|
-
}
|
|
99
|
-
parseFileSource(path) {
|
|
100
|
-
return { path, cssCalls: 0, cvaCalls: 0, svaCalls: 0, jsxUsages: 0, diagnostics: [] };
|
|
101
|
-
}
|
|
102
|
-
refreshFile() {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
refreshFileSource() {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
removeFile() {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
clear() {
|
|
112
|
-
}
|
|
113
|
-
scan() {
|
|
114
|
-
return [];
|
|
115
|
-
}
|
|
116
|
-
realpath(path) {
|
|
117
|
-
return path;
|
|
118
|
-
}
|
|
119
|
-
resolvePath(path, cwd) {
|
|
120
|
-
if (!cwd || path.startsWith("/")) return path;
|
|
121
|
-
return `${cwd.replace(/\/$/, "")}/${path}`;
|
|
122
|
-
}
|
|
123
|
-
joinPath(parts) {
|
|
124
|
-
return parts.filter(Boolean).join("/");
|
|
125
|
-
}
|
|
126
|
-
dirname(path) {
|
|
127
|
-
const index = path.lastIndexOf("/");
|
|
128
|
-
return index <= 0 ? "" : path.slice(0, index);
|
|
129
|
-
}
|
|
130
|
-
isSourceFile() {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
parseFiles(_paths) {
|
|
134
|
-
return [];
|
|
135
|
-
}
|
|
136
|
-
layers() {
|
|
137
|
-
return { reset: "reset", base: "base", tokens: "tokens", recipes: "recipes", utilities: "utilities" };
|
|
138
|
-
}
|
|
139
|
-
hasLayerDeclaration() {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
spec() {
|
|
143
|
-
return {
|
|
144
|
-
conditions: { keys: [], breakpoints: [], containers: [] },
|
|
145
|
-
tokens: { categories: {}, colorPalettes: [], values: {}, deprecated: {} },
|
|
146
|
-
utilities: { properties: {}, shorthands: {}, deprecated: {} },
|
|
147
|
-
patterns: {},
|
|
148
|
-
recipes: {},
|
|
149
|
-
slotRecipes: {},
|
|
150
|
-
propertyOrder: []
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
sources() {
|
|
154
|
-
return [];
|
|
155
|
-
}
|
|
156
|
-
inspectFileSource() {
|
|
157
|
-
return { usages: [], diagnostics: [], calls: [], jsx: [], tokenRefs: [], componentEntries: [], styleEntries: [] };
|
|
158
|
-
}
|
|
159
|
-
resolveUtilityValue() {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
suggestTokens() {
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
writeArtifacts(_options) {
|
|
166
|
-
return [];
|
|
167
|
-
}
|
|
168
|
-
writeCss(options) {
|
|
169
|
-
return emptyWriteCssResult(options.outfile);
|
|
170
|
-
}
|
|
171
|
-
writeLayerCss(options) {
|
|
172
|
-
return emptyWriteCssResult(options.outfile);
|
|
173
|
-
}
|
|
174
|
-
writeSplitCss(options) {
|
|
175
|
-
return emptyWriteFilesResult(options.outdir ?? "");
|
|
176
|
-
}
|
|
177
|
-
isEmpty() {
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
atoms() {
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
recipes() {
|
|
184
|
-
return [];
|
|
185
|
-
}
|
|
186
|
-
slotRecipes() {
|
|
187
|
-
return [];
|
|
188
|
-
}
|
|
189
|
-
encodedRecipes() {
|
|
190
|
-
return { base: [], variants: [], atomic: [] };
|
|
191
|
-
}
|
|
192
|
-
staticPatternAtoms() {
|
|
193
|
-
return { atoms: [], diagnostics: [] };
|
|
194
|
-
}
|
|
195
|
-
getFile() {
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
fileManifest() {
|
|
199
|
-
return [];
|
|
200
|
-
}
|
|
201
|
-
summary() {
|
|
202
|
-
return { filesProcessed: 0, atomCount: 0, recipeCount: 0, slotRecipeCount: 0 };
|
|
203
|
-
}
|
|
204
|
-
compile() {
|
|
205
|
-
return emptyCompileOutput();
|
|
206
|
-
}
|
|
207
|
-
getLayerCss(_options) {
|
|
208
|
-
return emptyCompileOutput();
|
|
209
|
-
}
|
|
210
|
-
getSplitCss(_options) {
|
|
211
|
-
return [];
|
|
212
|
-
}
|
|
213
|
-
buildInfo = fallbackBuildInfo;
|
|
214
|
-
generateArtifacts() {
|
|
215
|
-
return [];
|
|
216
|
-
}
|
|
217
|
-
generateArtifact() {
|
|
218
|
-
return void 0;
|
|
219
|
-
}
|
|
220
|
-
generateAffectedArtifacts() {
|
|
221
|
-
return [];
|
|
222
|
-
}
|
|
223
|
-
diagnostics() {
|
|
224
|
-
return [];
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
var fallback = {
|
|
228
|
-
startTracing() {
|
|
229
|
-
return false;
|
|
230
|
-
},
|
|
231
|
-
flushTracing() {
|
|
232
|
-
},
|
|
233
|
-
shutdownTracing() {
|
|
234
|
-
return false;
|
|
235
|
-
},
|
|
236
|
-
compile() {
|
|
237
|
-
return emptyCompileOutput();
|
|
238
|
-
},
|
|
239
|
-
scanImports() {
|
|
240
|
-
return { imports: [], diagnostics: [] };
|
|
241
|
-
},
|
|
242
|
-
matchImports() {
|
|
243
|
-
return [];
|
|
244
|
-
},
|
|
245
|
-
extractCalls() {
|
|
246
|
-
return { calls: [], diagnostics: [] };
|
|
247
|
-
},
|
|
248
|
-
extractJsx() {
|
|
249
|
-
return { jsx: [], diagnostics: [] };
|
|
250
|
-
},
|
|
251
|
-
extract() {
|
|
252
|
-
return { calls: [], jsx: [], diagnostics: [] };
|
|
253
|
-
},
|
|
254
|
-
extractDebug() {
|
|
255
|
-
return { imports: [], matched: [], calls: [], jsx: [], diagnostics: [] };
|
|
256
|
-
},
|
|
257
|
-
Extractor: FallbackExtractor,
|
|
258
|
-
Compiler: FallbackCompiler
|
|
259
|
-
};
|
|
260
|
-
var fallbackBuildInfo = makeBuildInfoApi({
|
|
261
|
-
serializeBuildInfo: () => ({
|
|
262
|
-
schemaVersion: -1,
|
|
263
|
-
panda: "",
|
|
264
|
-
configFingerprint: "",
|
|
265
|
-
strings: [],
|
|
266
|
-
atoms: [],
|
|
267
|
-
modules: {}
|
|
268
|
-
}),
|
|
269
|
-
applyBuildInfo: () => false,
|
|
270
|
-
buildInfoSchemaVersion: () => -1,
|
|
271
|
-
configFingerprint: () => ""
|
|
272
|
-
});
|
|
273
|
-
function emptyCompileOutput() {
|
|
274
|
-
return {
|
|
275
|
-
css: "",
|
|
276
|
-
manifest: { files: [], tokens: [] },
|
|
277
|
-
layerRanges: {},
|
|
278
|
-
diagnostics: []
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
function emptyWriteCssResult(path) {
|
|
282
|
-
return {
|
|
283
|
-
path,
|
|
284
|
-
...emptyCompileOutput()
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
function emptyWriteFilesResult(root) {
|
|
288
|
-
return {
|
|
289
|
-
root,
|
|
290
|
-
paths: [],
|
|
291
|
-
files: []
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// src/load-binary.ts
|
|
296
|
-
import { existsSync, readFileSync } from "fs";
|
|
297
|
-
import { createRequire } from "module";
|
|
298
|
-
import { join } from "path";
|
|
299
|
-
import { fileURLToPath } from "url";
|
|
300
|
-
var bindingUrl = new URL("../binding.cjs", import.meta.url);
|
|
301
|
-
function loadNativeBinding() {
|
|
302
|
-
const bindingPath = resolveBindingPath();
|
|
303
|
-
if (!bindingPath) return void 0;
|
|
304
|
-
const require2 = createRequire(bindingPath);
|
|
305
|
-
return require2(bindingPath);
|
|
306
|
-
}
|
|
307
|
-
function resolveBindingPath() {
|
|
308
|
-
if (bindingUrl.protocol === "file:") {
|
|
309
|
-
const bindingPath = fileURLToPath(bindingUrl);
|
|
310
|
-
if (existsSync(bindingPath)) return bindingPath;
|
|
311
|
-
}
|
|
312
|
-
return fallbackBindingPaths().find((path) => existsSync(path));
|
|
313
|
-
}
|
|
314
|
-
function fallbackBindingPaths() {
|
|
315
|
-
const cwd = process.cwd();
|
|
316
|
-
const paths = [join(cwd, "packages/compiler/binding.cjs")];
|
|
317
|
-
if (isCompilerPackageRoot(cwd)) {
|
|
318
|
-
paths.unshift(join(cwd, "binding.cjs"));
|
|
319
|
-
}
|
|
320
|
-
return paths;
|
|
321
|
-
}
|
|
322
|
-
function isCompilerPackageRoot(cwd) {
|
|
323
|
-
try {
|
|
324
|
-
const packageJson = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
|
|
325
|
-
return packageJson.name === "@pandacss/compiler";
|
|
326
|
-
} catch {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// src/driver.ts
|
|
332
|
-
import {
|
|
333
|
-
BaseDriver
|
|
334
|
-
} from "@pandacss/compiler-shared";
|
|
335
|
-
import { diffConfig, loadConfig } from "@pandacss/config";
|
|
336
|
-
async function createNodeDriver(options) {
|
|
337
|
-
const loaded = await loadConfig({ cwd: options.cwd, file: options.configPath });
|
|
338
|
-
if (options.include?.length) loaded.config.include = options.include;
|
|
339
|
-
return new NodeDriver(options, loaded);
|
|
340
|
-
}
|
|
341
|
-
var NodeDriver = class extends BaseDriver {
|
|
342
|
-
#options;
|
|
343
|
-
#loaded;
|
|
344
|
-
constructor(options, loaded) {
|
|
345
|
-
super(buildFromConfig(loaded));
|
|
346
|
-
this.#options = options;
|
|
347
|
-
this.#loaded = loaded;
|
|
348
|
-
}
|
|
349
|
-
get config() {
|
|
350
|
-
return this.#loaded.config;
|
|
351
|
-
}
|
|
352
|
-
get configPath() {
|
|
353
|
-
return this.#loaded.path;
|
|
354
|
-
}
|
|
355
|
-
get configDependencies() {
|
|
356
|
-
return this.#loaded.dependencies;
|
|
357
|
-
}
|
|
358
|
-
async reload() {
|
|
359
|
-
const next = await loadConfig({ cwd: this.#options.cwd, file: this.#options.configPath });
|
|
360
|
-
if (this.#options.include?.length) next.config.include = this.#options.include;
|
|
361
|
-
const diff = diffConfig(this.#loaded, next);
|
|
362
|
-
if (diff.hasChanged) {
|
|
363
|
-
this.#loaded = next;
|
|
364
|
-
this.setCompiler(buildFromConfig(next));
|
|
365
|
-
}
|
|
366
|
-
return diff;
|
|
367
|
-
}
|
|
368
|
-
applyChange(change) {
|
|
369
|
-
if (change.kind === "unlink") {
|
|
370
|
-
return this.compiler.removeFile(change.path);
|
|
371
|
-
}
|
|
372
|
-
if (change.kind === "change") {
|
|
373
|
-
if (change.content == null) {
|
|
374
|
-
if (this.compiler.refreshFile(change.path)) return true;
|
|
375
|
-
this.compiler.parseFile(change.path);
|
|
376
|
-
return true;
|
|
377
|
-
}
|
|
378
|
-
if (this.compiler.refreshFileSource(change.path, change.content)) return true;
|
|
379
|
-
this.compiler.parseFileSource(change.path, change.content);
|
|
380
|
-
return true;
|
|
381
|
-
}
|
|
382
|
-
if (change.content == null) {
|
|
383
|
-
this.compiler.parseFile(change.path);
|
|
384
|
-
return true;
|
|
385
|
-
}
|
|
386
|
-
this.compiler.parseFileSource(change.path, change.content);
|
|
387
|
-
return true;
|
|
388
|
-
}
|
|
389
|
-
getOutdir(outdir) {
|
|
390
|
-
return this.compiler.resolvePath(this.getConfiguredOutdir(outdir));
|
|
391
|
-
}
|
|
392
|
-
codegen(options) {
|
|
393
|
-
const outdir = this.getOutdir(options?.outdir);
|
|
394
|
-
const cwd = options?.cwd ?? this.#options.cwd;
|
|
395
|
-
const prepareHooks = this.#loaded.hostHooks?.["codegen:prepare"] ?? [];
|
|
396
|
-
const doneHooks = this.#loaded.hostHooks?.["codegen:done"] ?? [];
|
|
397
|
-
const files = prepareHooks.length > 0 ? this.codegenWithPrepareHooks(prepareHooks, outdir, cwd, options) : super.codegen(options);
|
|
398
|
-
for (const entry of doneHooks) {
|
|
399
|
-
const handler = resolveHookHandler(entry.value, "codegen:done");
|
|
400
|
-
handler({ files, outdir, cwd });
|
|
401
|
-
}
|
|
402
|
-
return files;
|
|
403
|
-
}
|
|
404
|
-
codegenWithPrepareHooks(hooks, outdir, cwd, options) {
|
|
405
|
-
let artifacts = this.compiler.generateArtifacts(toGenerateArtifactOptions(options));
|
|
406
|
-
for (const entry of hooks) {
|
|
407
|
-
const handler = resolveHookHandler(entry.value, "codegen:prepare");
|
|
408
|
-
const next = handler({ artifacts, outdir, cwd });
|
|
409
|
-
if (next !== void 0) {
|
|
410
|
-
if (!Array.isArray(next)) {
|
|
411
|
-
throw new Error("Invalid codegen:prepare hook result. Expected an artifact array or undefined.");
|
|
412
|
-
}
|
|
413
|
-
artifacts = next;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
return this.compiler.writeArtifacts({
|
|
417
|
-
outdir,
|
|
418
|
-
cwd,
|
|
419
|
-
forceImportExtension: options?.forceImportExtension,
|
|
420
|
-
artifacts
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
isConfigFile(file) {
|
|
424
|
-
const target = this.compiler.realpath(file);
|
|
425
|
-
const configPath = this.compiler.realpath(this.#loaded.path);
|
|
426
|
-
if (configPath === target) return true;
|
|
427
|
-
return this.#loaded.dependencies.some((dependency) => {
|
|
428
|
-
const dependencyPath = this.compiler.resolvePath(dependency, this.#options.cwd);
|
|
429
|
-
return this.compiler.realpath(dependencyPath) === target;
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
function resolveHookHandler(value, name) {
|
|
434
|
-
if (typeof value === "function") return value;
|
|
435
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
436
|
-
throw new Error(`Invalid ${name} hook. Expected a function or { filter, handler }.`);
|
|
437
|
-
}
|
|
438
|
-
const handler = value.handler;
|
|
439
|
-
if (typeof handler !== "function") {
|
|
440
|
-
throw new Error(`Invalid ${name} hook. Expected a function or { filter, handler }.`);
|
|
441
|
-
}
|
|
442
|
-
return handler;
|
|
443
|
-
}
|
|
444
|
-
function buildFromConfig(loaded) {
|
|
445
|
-
return createCompilerFromSnapshot({ config: loaded.config, callbacks: loaded.callbacks, hooks: loaded.hooks });
|
|
446
|
-
}
|
|
447
|
-
function toGenerateArtifactOptions(options) {
|
|
448
|
-
return options?.forceImportExtension === void 0 ? void 0 : { forceImportExtension: options.forceImportExtension };
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// src/index.ts
|
|
452
|
-
var binding = loadNativeBinding() ?? fallback;
|
|
453
|
-
var nativeCompilerFromConfig = "fromConfig" in binding.Compiler && typeof binding.Compiler.fromConfig === "function" ? binding.Compiler.fromConfig.bind(binding.Compiler) : void 0;
|
|
454
|
-
function compile(input) {
|
|
455
|
-
return binding.compile(input);
|
|
456
|
-
}
|
|
457
|
-
function startTracing(options) {
|
|
458
|
-
return binding.startTracing?.(options) ?? false;
|
|
459
|
-
}
|
|
460
|
-
function flushTracing() {
|
|
461
|
-
binding.flushTracing?.();
|
|
462
|
-
}
|
|
463
|
-
function shutdownTracing() {
|
|
464
|
-
return binding.shutdownTracing?.() ?? false;
|
|
465
|
-
}
|
|
466
|
-
function createCompiler(config, options) {
|
|
467
|
-
return build(config, options?.callbacks ?? {}, options);
|
|
468
|
-
}
|
|
469
|
-
function createCompilerFromSnapshot(snapshot, options) {
|
|
470
|
-
const callbacks = mergeCallbacks(snapshot.callbacks, options?.callbacks);
|
|
471
|
-
const hooks = mergeHooks(snapshot.hooks, options?.hooks);
|
|
472
|
-
return build(snapshot.config, callbacks, { ...options, hooks });
|
|
473
|
-
}
|
|
474
|
-
function getBindingInfo() {
|
|
475
|
-
return {
|
|
476
|
-
native: binding !== fallback
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
function build(config, callbacks, options) {
|
|
480
|
-
assertProjectCallbacks(config, callbacks);
|
|
481
|
-
assertProjectHooks(options?.hooks, callbacks);
|
|
482
|
-
if (!nativeCompilerFromConfig) {
|
|
483
|
-
throw new Error("createCompiler is not available in this binding");
|
|
484
|
-
}
|
|
485
|
-
const prepared = prepareCompilerConfig(config);
|
|
486
|
-
const compiler = nativeCompilerFromConfig(prepared, toNativeOptions(options), createUtilityValuesCallbacks(callbacks));
|
|
487
|
-
registerCallbacks(compiler, callbacks, options?.hooks, compiler.token_dictionary?.());
|
|
488
|
-
attachBuildInfo(compiler);
|
|
489
|
-
return compiler;
|
|
490
|
-
}
|
|
491
|
-
function attachBuildInfo(compiler) {
|
|
492
|
-
Object.defineProperty(compiler, "buildInfo", {
|
|
493
|
-
enumerable: false,
|
|
494
|
-
configurable: true,
|
|
495
|
-
get() {
|
|
496
|
-
const api = makeBuildInfoApi2(compiler);
|
|
497
|
-
Object.defineProperty(compiler, "buildInfo", {
|
|
498
|
-
value: api,
|
|
499
|
-
enumerable: false,
|
|
500
|
-
configurable: true
|
|
501
|
-
});
|
|
502
|
-
return api;
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
function toNativeOptions(options) {
|
|
507
|
-
if (!options || options.crossFile === void 0) return void 0;
|
|
508
|
-
return { crossFile: options.crossFile };
|
|
509
|
-
}
|
|
510
|
-
function createUtilityValuesCallbacks(callbacks) {
|
|
511
|
-
const utilityValues = callbacks["utility.values"];
|
|
512
|
-
if (!utilityValues || Object.keys(utilityValues).length === 0) return void 0;
|
|
513
|
-
return Object.fromEntries(
|
|
514
|
-
Object.entries(utilityValues).map(([id, callback]) => [
|
|
515
|
-
id,
|
|
516
|
-
(tokenDictionary) => callback((category) => getTokenCategoryValues(category, tokenDictionary))
|
|
517
|
-
])
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
export {
|
|
522
|
-
createNodeDriver,
|
|
523
|
-
compile,
|
|
524
|
-
startTracing,
|
|
525
|
-
flushTracing,
|
|
526
|
-
shutdownTracing,
|
|
527
|
-
createCompiler,
|
|
528
|
-
createCompilerFromSnapshot,
|
|
529
|
-
getBindingInfo
|
|
530
|
-
};
|