parseman 0.28.0 → 0.29.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/compiler/codegen.d.ts +23 -0
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts +20 -8
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/index.cjs +109 -2
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +109 -2
- package/dist/index.js.map +3 -3
- package/dist/language-service/index.cjs.map +2 -2
- package/dist/language-service/index.js.map +2 -2
- package/dist/plugin/index.cjs +110 -3
- package/dist/plugin/index.cjs.map +3 -3
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +110 -3
- package/dist/plugin/index.js.map +3 -3
- package/package.json +1 -1
|
@@ -7,6 +7,21 @@
|
|
|
7
7
|
* object allocation per node.
|
|
8
8
|
*/
|
|
9
9
|
import type { Combinator, FirstSet, ParseResult, ParseContext, ParseError } from '../types.ts';
|
|
10
|
+
/**
|
|
11
|
+
* A rule's LEADING first-set as a fuse-resolvable recipe: the concrete leading
|
|
12
|
+
* chars (literals/regex reached through the nullable prefix) kept SEPARATE from the
|
|
13
|
+
* leading rule-REFERENCE names. `fusedBody()` resolves the ref names against the
|
|
14
|
+
* WINNING rules (a fixpoint) and unions the concrete part, so a composed grammar
|
|
15
|
+
* gets the same first-char dispatch a monolithic compile would — WITHOUT baking a
|
|
16
|
+
* referenced rule's first-set (which a compose override could later widen). Kept
|
|
17
|
+
* conservative: an unknown/opaque construct contributes its shallow `_meta.firstSet`
|
|
18
|
+
* (never an under-approximation, so dispatch never drops a valid parse).
|
|
19
|
+
*/
|
|
20
|
+
export type FirstSetRecipe = {
|
|
21
|
+
concrete: FirstSet;
|
|
22
|
+
refs: string[];
|
|
23
|
+
};
|
|
24
|
+
export declare function leadingFirstSetRecipe(p: Combinator<unknown>, seen?: Set<Combinator<unknown>>): FirstSetRecipe;
|
|
10
25
|
import { type GrammarCoveragePlan } from './grammar-coverage-ids.ts';
|
|
11
26
|
/**
|
|
12
27
|
* Runtime prelude helper for the structural-node capture gate. Answers "does the
|
|
@@ -110,6 +125,14 @@ export type LinkablePieces = {
|
|
|
110
125
|
* emitted for rule-ref choice arms — sound under compose override.
|
|
111
126
|
*/
|
|
112
127
|
firstSets: Map<string, FirstSet>;
|
|
128
|
+
/**
|
|
129
|
+
* Per-rule LEADING first-set recipe (concrete chars + leading ref names).
|
|
130
|
+
* `fusedBody()` fixpoint-resolves the ref names over the WINNING rules so a
|
|
131
|
+
* `sequence(ref, …)`-led arm/node dispatches on the ref's real first char —
|
|
132
|
+
* matching a monolithic compile — instead of degrading to always-try because
|
|
133
|
+
* the ref baked `any`. Optional for back-compat with hand-built pieces.
|
|
134
|
+
*/
|
|
135
|
+
firstSetRecipes?: Map<string, FirstSetRecipe>;
|
|
113
136
|
deps: Map<string, string[]>;
|
|
114
137
|
needsEmptyTl: boolean;
|
|
115
138
|
needsHostReads: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/compiler/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAa,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAA4B,MAAM,aAAa,CAAA;AAKnI,OAAO,EAAoB,KAAK,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAsBtF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,uTAC0R,CAAA;AActT,8EAA8E;AAC9E,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAI7C;AAkeD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,MAAM,CAQlE;AAcD,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,GAAG,I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H,cAAc,GAAG,IAAI,CA8MvB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LinkablePieces } from './codegen.ts';
|
|
2
|
-
import type { BuildHost, Combinator, CstCollapsePredicate } from '../types.ts';
|
|
2
|
+
import type { BuildHost, Combinator, CstCollapsePredicate, ParseContext, ParseResult } from '../types.ts';
|
|
3
3
|
export declare function linkable(rulesMap: Record<string, Combinator<unknown>>, ns?: string, trivia?: Combinator<unknown>): LinkablePieces;
|
|
4
4
|
export type CstBuildHostOptions = {
|
|
5
5
|
/**
|
|
@@ -26,13 +26,15 @@ export declare function cstBuildHost(type: string, children: ReadonlyArray<unkno
|
|
|
26
26
|
start: number;
|
|
27
27
|
end: number;
|
|
28
28
|
}, rawChildren?: ReadonlyArray<unknown>, triviaLog?: readonly number[], state?: unknown): unknown;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
/**
|
|
30
|
+
* A fused function receives the full ParseContext through `run()`. Direct
|
|
31
|
+
* callers historically supplied a plain context object, so keep that usage
|
|
32
|
+
* valid while making the function assignable to the public `Runnable` type.
|
|
33
|
+
* Generated code treats optional framework fields as absent when they are not
|
|
34
|
+
* provided, matching the interpreter's normal defaults.
|
|
35
|
+
*/
|
|
36
|
+
export type FusedRule = (input: string, pos: number, ctx: ParseContext | Record<string, unknown>) => ParseResult<unknown> & {
|
|
37
|
+
readonly value?: unknown;
|
|
36
38
|
};
|
|
37
39
|
/**
|
|
38
40
|
* Restrict a grammar/artifact to `names` plus their transitive rule-dependency
|
|
@@ -48,6 +50,16 @@ export declare function pick(grammar: LinkablePieces | Record<string, Combinator
|
|
|
48
50
|
* compose override order). Shared by `pick()` (runtime) and the macro's build-time
|
|
49
51
|
* `pick(...)` handling, so à-la-carte selection is identical on both paths. */
|
|
50
52
|
export declare function pickPieces(pieces: LinkablePieces[], names: string[]): LinkablePieces[];
|
|
53
|
+
/**
|
|
54
|
+
* Build the fused-closure body (shared by the runtime `fuseRules` and the
|
|
55
|
+
* build-time `emitFusedSource`). Returns the closure body (which reads `_env`
|
|
56
|
+
* for any non-inlined callbacks) and the `_env` to bind. In macro mode callbacks
|
|
57
|
+
* are inlined from source, so `_env` is empty and the body is fully static.
|
|
58
|
+
*/
|
|
59
|
+
export declare function fusedBody(pieces: LinkablePieces[]): {
|
|
60
|
+
body: string;
|
|
61
|
+
env: Record<string, unknown>;
|
|
62
|
+
};
|
|
51
63
|
/** Fuse at RUNTIME (via `new Function`) — used by `compose()` when not compiled
|
|
52
64
|
* by the macro (like `compile()`). The macro path uses `emitFusedSource` instead. */
|
|
53
65
|
export declare function fuseRules(pieces: LinkablePieces[]): Record<string, FusedRule>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../../src/compiler/linker.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../../src/compiler/linker.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,cAAc,CAAA;AAElE,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,oBAAoB,EAAY,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAanH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC7C,EAAE,CAAC,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAC3B,cAAc,CAIhB;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,GAAG,oBAAoB,CAAA;CAC9D,CAAA;AAyBD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,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BAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAMhE;AAyCD;uEACuE;AACvE,MAAM,MAAM,OAAO,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAA;AAyBhD;;gFAEgF;AAChF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,CAEvH;AAED;qEACqE;AACrE,wBAAgB,gBAAgB,CAC9B,CAAC,EAAE,cAAc,GAAG,OAAO,EAC3B,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAC5B,gBAAgB,UAAQ,GACvB,cAAc,CAQhB;AA0ED,wBAAgB,OAAO,CACrB,KAAK,EAAE,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACrD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAoB3B;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACtD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAE3B"}
|
package/dist/index.cjs
CHANGED
|
@@ -4239,6 +4239,61 @@ function tryInlineDestructureTransform(src, valueVars) {
|
|
|
4239
4239
|
}
|
|
4240
4240
|
|
|
4241
4241
|
// src/compiler/codegen.ts
|
|
4242
|
+
function leadingFirstSetRecipe(p, seen = /* @__PURE__ */ new Set()) {
|
|
4243
|
+
if (seen.has(p)) return { concrete: empty(), refs: [] };
|
|
4244
|
+
seen.add(p);
|
|
4245
|
+
const d = p._def;
|
|
4246
|
+
const rec = (c) => leadingFirstSetRecipe(c, seen);
|
|
4247
|
+
const merge2 = (a, b) => ({ concrete: union(a.concrete, b.concrete), refs: [...a.refs, ...b.refs] });
|
|
4248
|
+
switch (d.tag) {
|
|
4249
|
+
case "lazy": {
|
|
4250
|
+
const name = p._ruleName;
|
|
4251
|
+
if (name !== void 0) return { concrete: empty(), refs: [name] };
|
|
4252
|
+
try {
|
|
4253
|
+
return rec(d.thunk());
|
|
4254
|
+
} catch {
|
|
4255
|
+
return { concrete: any(), refs: [] };
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
case "literal":
|
|
4259
|
+
case "regex":
|
|
4260
|
+
case "keywords":
|
|
4261
|
+
return { concrete: p._meta.firstSet, refs: [] };
|
|
4262
|
+
case "choice": {
|
|
4263
|
+
let out = { concrete: empty(), refs: [] };
|
|
4264
|
+
for (const arm of d.parsers) out = merge2(out, rec(arm));
|
|
4265
|
+
return out;
|
|
4266
|
+
}
|
|
4267
|
+
case "sequence": {
|
|
4268
|
+
let out = { concrete: empty(), refs: [] };
|
|
4269
|
+
for (const term of d.parsers) {
|
|
4270
|
+
out = merge2(out, rec(term));
|
|
4271
|
+
if (!matchesEmpty(term)) return out;
|
|
4272
|
+
}
|
|
4273
|
+
return out;
|
|
4274
|
+
}
|
|
4275
|
+
case "oneOrMore":
|
|
4276
|
+
case "many":
|
|
4277
|
+
case "optional":
|
|
4278
|
+
case "transform":
|
|
4279
|
+
case "label":
|
|
4280
|
+
case "field":
|
|
4281
|
+
case "trivia":
|
|
4282
|
+
case "token":
|
|
4283
|
+
case "leaf":
|
|
4284
|
+
case "node":
|
|
4285
|
+
case "grammar":
|
|
4286
|
+
case "expect":
|
|
4287
|
+
return rec(d.parser);
|
|
4288
|
+
case "sepBy":
|
|
4289
|
+
return rec(d.parser);
|
|
4290
|
+
case "skip":
|
|
4291
|
+
return rec(d.main);
|
|
4292
|
+
// not / scanTo / guard / withCtx / recover / unknown → shallow set (safe).
|
|
4293
|
+
default:
|
|
4294
|
+
return { concrete: p._meta.firstSet, refs: [] };
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4242
4297
|
var HOST_READS_DECL = "const _hostReads = (b, n) => { if (b === undefined) return false; let s; try { s = Function.prototype.toString.call(b) } catch (e) { return true } if (/\\barguments\\b/.test(s)) return true; const m = /^[^(]*\\(([\\s\\S]*?)\\)/.exec(s); if (m && /\\.\\.\\.|=/.test(m[1])) return true; return b.length > n }";
|
|
4243
4298
|
var _loweringSink = null;
|
|
4244
4299
|
function v(ctx, prefix = "_v") {
|
|
@@ -5285,6 +5340,13 @@ function emitMany(def, ctx, pos) {
|
|
|
5285
5340
|
itemPos = npV;
|
|
5286
5341
|
}
|
|
5287
5342
|
}
|
|
5343
|
+
if (!ctx.recovery && !ctx.coverage && !failsAtStart(def.parser) && needsFirstSetGuard(def.parser)) {
|
|
5344
|
+
const lcV = v(ctx, "_lc");
|
|
5345
|
+
stmts.push(
|
|
5346
|
+
`${ind(ctx)}const ${lcV} = ${itemPos} < input.length ? (input.codePointAt(${itemPos}) ?? -1) : -1`,
|
|
5347
|
+
`${ind(ctx)}if (!(${firstSetCond(lcV, def.parser._meta.firstSet)})) { ${rollback}break }`
|
|
5348
|
+
);
|
|
5349
|
+
}
|
|
5288
5350
|
const { stmts: iterStmts, okVar: iterOk, valVar: iterVal, endVar: iterEnd } = emitFallible(def.parser, ctx, itemPos, true);
|
|
5289
5351
|
stmts.push(...iterStmts);
|
|
5290
5352
|
if (ctx.recovery) {
|
|
@@ -5335,8 +5397,19 @@ function emitAttempt(p, def, ctx, pos) {
|
|
|
5335
5397
|
const rollback = `if (_ctx._cstLeaves) _ctx._cstLeaves.length = ${leaves}; if (_ctx._cstRawChildren) _ctx._cstRawChildren.length = ${raw}; if (_ctx._cstTriviaLog) _ctx._cstTriviaLog.length = ${trivia2}; if (_ctx._triviaLog) _ctx._triviaLog.length = ${log}; if (_ctx._fields) _ctx._fields.length = ${fields}; if (_ctx._errors) _ctx._errors.length = ${errors}`;
|
|
5336
5398
|
const traceId = ctx.coverage?.plan.attempts.get(p);
|
|
5337
5399
|
const traceRollback = traceId === void 0 ? "" : ` _ctx._grammarTrace?.write({ id: ${JSON.stringify(traceId)}, phase: 'rollback', offset: ${pos} });`;
|
|
5400
|
+
const preGuard = [];
|
|
5401
|
+
if (!ctx.recovery && !ctx.coverage && needsFirstSetGuard(def.parser)) {
|
|
5402
|
+
const gcV = v(ctx, "_agc");
|
|
5403
|
+
const gExp = armStaticExpected(ctx, def.parser);
|
|
5404
|
+
const gFail = ctx.failLabel ? `{ _ctx._fe = ${pos};${ctx.recordFail ? ` _ctx._fx = ${gExp};` : ""} break ${ctx.failLabel} }` : `{ _ctx._fe = ${pos}; ${failReturnArr(gExp, pos)} }`;
|
|
5405
|
+
preGuard.push(
|
|
5406
|
+
`${ind(ctx)}const ${gcV} = ${pos} < input.length ? (input.codePointAt(${pos}) ?? -1) : -1`,
|
|
5407
|
+
`${ind(ctx)}if (!(${firstSetCond(gcV, def.parser._meta.firstSet)})) ${gFail}`
|
|
5408
|
+
);
|
|
5409
|
+
}
|
|
5338
5410
|
return {
|
|
5339
5411
|
stmts: [
|
|
5412
|
+
...preGuard,
|
|
5340
5413
|
`${ind(ctx)}const ${leaves} = _ctx._cstLeaves?.length ?? 0, ${raw} = _ctx._cstRawChildren?.length ?? 0, ${trivia2} = _ctx._cstTriviaLog?.length ?? 0, ${log} = _ctx._triviaLog?.length ?? 0, ${fields} = _ctx._fields?.length ?? 0, ${errors} = _ctx._errors?.length ?? 0`,
|
|
5341
5414
|
...inner.stmts,
|
|
5342
5415
|
...emitIfFail(ctx, `!${inner.okVar}`, `{ ${rollback};${traceRollback} _ctx._fe = ${pos}; ${propagateFailBody(ctx)} }`)
|
|
@@ -5716,7 +5789,18 @@ ${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRec
|
|
|
5716
5789
|
const saveTrivia = needsTriviaFrame ? `, ${st} = _ctx.captureTrivia, ${stl} = _ctx._cstTriviaLog${smk ? `, ${smk} = _ctx._triviaCaptureMask` : ""}` : "";
|
|
5717
5790
|
const installTrivia = needsTriviaFrame ? `; _ctx.captureTrivia = ${capTLv ?? "false"}; _ctx._cstTriviaLog = ${innerTl}${smk ? `; _ctx._triviaCaptureMask = ${capTLv} && _ctx.build !== undefined && _ctx.build._parsemanTriviaKinds !== undefined ? _ctx.build._parsemanTriviaKinds(${JSON.stringify(def.type)}) : ${smk}` : ""}` : "";
|
|
5718
5791
|
const restoreTrivia = needsTriviaFrame ? `; _ctx.captureTrivia = ${st}; _ctx._cstTriviaLog = ${stl}${smk ? `; _ctx._triviaCaptureMask = ${smk}` : ""}` : "";
|
|
5792
|
+
const preGuard = [];
|
|
5793
|
+
if (!ctx.recovery && !ctx.coverage && (capturesChildren || structural) && needsFirstSetGuard(def.parser)) {
|
|
5794
|
+
const gcV = v(ctx, "_ngc");
|
|
5795
|
+
const gExp = armStaticExpected(ctx, def.parser);
|
|
5796
|
+
const gFail = ctx.failLabel ? ctx.recordFail ? `{ _ctx._fe = ${pos}; _ctx._fx = ${gExp}; break ${ctx.failLabel} }` : `break ${ctx.failLabel}` : failReturnArr(gExp, pos);
|
|
5797
|
+
preGuard.push(
|
|
5798
|
+
`${i}const ${gcV} = ${pos} < input.length ? (input.codePointAt(${pos}) ?? -1) : -1`,
|
|
5799
|
+
`${i}if (!(${firstSetCond(gcV, def.parser._meta.firstSet)})) ${gFail}`
|
|
5800
|
+
);
|
|
5801
|
+
}
|
|
5719
5802
|
const stmts = [
|
|
5803
|
+
...preGuard,
|
|
5720
5804
|
profHoist,
|
|
5721
5805
|
allocStmt,
|
|
5722
5806
|
`${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren${saveTrivia}${sf ? `, ${sf} = _ctx._fields` : ""}`,
|
|
@@ -6633,6 +6717,7 @@ function compileLinkable(ruleMapArg, ns, opts) {
|
|
|
6633
6717
|
].join("\n")));
|
|
6634
6718
|
}
|
|
6635
6719
|
const firstSets = /* @__PURE__ */ new Map();
|
|
6720
|
+
const firstSetRecipes = /* @__PURE__ */ new Map();
|
|
6636
6721
|
for (const [key, rule] of ruleMap) {
|
|
6637
6722
|
let resolved = rule;
|
|
6638
6723
|
const d = rule._def;
|
|
@@ -6644,6 +6729,7 @@ function compileLinkable(ruleMapArg, ns, opts) {
|
|
|
6644
6729
|
}
|
|
6645
6730
|
}
|
|
6646
6731
|
firstSets.set(key, canMatchEmptyAtStart(resolved) ? { kind: "any" } : resolved._meta.firstSet);
|
|
6732
|
+
firstSetRecipes.set(key, canMatchEmptyAtStart(resolved) ? { concrete: any(), refs: [] } : leadingFirstSetRecipe(resolved));
|
|
6647
6733
|
}
|
|
6648
6734
|
return {
|
|
6649
6735
|
ns,
|
|
@@ -6652,6 +6738,7 @@ function compileLinkable(ruleMapArg, ns, opts) {
|
|
|
6652
6738
|
ruleFns,
|
|
6653
6739
|
wrappers,
|
|
6654
6740
|
firstSets,
|
|
6741
|
+
firstSetRecipes,
|
|
6655
6742
|
deps: ruleDependencies(ruleMap),
|
|
6656
6743
|
needsEmptyTl: !!ctx.needsEmptyTl,
|
|
6657
6744
|
needsHostReads: !!ctx.needsHostReads,
|
|
@@ -7287,10 +7374,30 @@ function fusedBody(pieces) {
|
|
|
7287
7374
|
];
|
|
7288
7375
|
const wrapperEntries = [...winner].map(([k, p]) => `${JSON.stringify(k)}: ${p.wrappers.get(k)}`);
|
|
7289
7376
|
const rawBody = [...lines, "return {", wrapperEntries.join(",\n"), "}"].join("\n");
|
|
7290
|
-
const
|
|
7377
|
+
const ANY2 = { kind: "any" };
|
|
7378
|
+
const recipes = /* @__PURE__ */ new Map();
|
|
7379
|
+
const shallow = /* @__PURE__ */ new Map();
|
|
7291
7380
|
for (const [k, p] of winner) {
|
|
7381
|
+
const r = p.firstSetRecipes?.get(k);
|
|
7382
|
+
if (r) recipes.set(k, r);
|
|
7292
7383
|
const fs = p.firstSets?.get(k);
|
|
7293
|
-
if (fs)
|
|
7384
|
+
if (fs) shallow.set(k, fs);
|
|
7385
|
+
}
|
|
7386
|
+
const finalFS = /* @__PURE__ */ new Map();
|
|
7387
|
+
for (const [k] of winner) finalFS.set(k, recipes.get(k)?.concrete ?? shallow.get(k) ?? ANY2);
|
|
7388
|
+
for (let iter = 0; iter <= recipes.size; iter++) {
|
|
7389
|
+
let changed = false;
|
|
7390
|
+
for (const [k, r] of recipes) {
|
|
7391
|
+
let fs = r.concrete;
|
|
7392
|
+
for (const ref2 of r.refs) {
|
|
7393
|
+
fs = union(fs, recipes.has(ref2) || shallow.has(ref2) ? finalFS.get(ref2) ?? ANY2 : ANY2);
|
|
7394
|
+
}
|
|
7395
|
+
if (JSON.stringify(finalFS.get(k)) !== JSON.stringify(fs)) {
|
|
7396
|
+
finalFS.set(k, fs);
|
|
7397
|
+
changed = true;
|
|
7398
|
+
}
|
|
7399
|
+
}
|
|
7400
|
+
if (!changed) break;
|
|
7294
7401
|
}
|
|
7295
7402
|
const body = rawBody.replace(
|
|
7296
7403
|
// Rule name + code-point var are both JS identifiers (rule names are validated
|