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