parseman 0.27.0 → 0.27.1

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.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Return lexical reads that cannot cross an artifact boundary. This is an Oxc
3
+ * AST binding check, never a source-text heuristic: property names and plain
4
+ * object keys are not lexical reads. The result becomes inert metadata on the
5
+ * macro-produced node and is enforced later by the runtime IR re-lowerer.
6
+ */
7
+ export declare function directBuilderUnsupportedBindings(src: string): string[];
8
+ //# sourceMappingURL=direct-builder-static.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-builder-static.d.ts","sourceRoot":"","sources":["../../src/plugin/direct-builder-static.ts"],"names":[],"mappings":"AA8BA;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAiEtE"}
@@ -1 +1 @@
1
- {"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/plugin/evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,UAAU,EAAE,IAAI,EAMjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AA2E7C,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB,CAAA;AACD,MAAM,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AAM3C,KAAK,gBAAgB,GAAG;IAAE,GAAG,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAA;AA4dhE,0EAA0E;AAC1E,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,MAAM,GACZ,gBAAgB,GAAG,IAAI,CAUzB;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAC1B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,EAAE,GACtB,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAE5B;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,MAAM,GACZ,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI,CAM9B;AAiED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,UAAU,EACvB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EAAE,GACrB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAqGzC;AAED,oEAAoE;AACpE,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;CAAE,CAAA;AAQlF;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,KAAK,GACX,YAAY,GAAG,IAAI,CAQrB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,EACpB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,GACX,OAAO,CAoBT;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAcnF"}
1
+ {"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/plugin/evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,UAAU,EAAE,IAAI,EAMjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AA4E7C,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB,CAAA;AACD,MAAM,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AAM3C,KAAK,gBAAgB,GAAG;IAAE,GAAG,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAA;AAiehE,0EAA0E;AAC1E,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,MAAM,GACZ,gBAAgB,GAAG,IAAI,CAUzB;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAC1B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,EAAE,GACtB,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAE5B;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,MAAM,GACZ,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI,CAM9B;AAiED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,UAAU,EACvB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EAAE,GACrB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAqGzC;AAED,oEAAoE;AACpE,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;CAAE,CAAA;AAQlF;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,KAAK,GACX,YAAY,GAAG,IAAI,CAQrB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,EACpB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,GACX,OAAO,CAoBT;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAcnF"}
@@ -36,7 +36,7 @@ __export(plugin_exports, {
36
36
  module.exports = __toCommonJS(plugin_exports);
37
37
  var fs = __toESM(require("node:fs"), 1);
38
38
  var import_unplugin = require("unplugin");
39
- var import_oxc_parser = require("oxc-parser");
39
+ var import_oxc_parser2 = require("oxc-parser");
40
40
  var import_oxc_resolver = require("oxc-resolver");
41
41
  var import_magic_string = __toESM(require("magic-string"), 1);
42
42
 
@@ -1509,6 +1509,12 @@ function scanTrivia(input, cur, ctx) {
1509
1509
  const tr = triviaP.parse(input, cur, { trackLines: ctx.trackLines, state: ctx.state });
1510
1510
  return { end: tr.ok ? tr.span.end : cur, commit: NOOP_COMMIT };
1511
1511
  }
1512
+ function consumeTrivia(input, cur, ctx) {
1513
+ if (!needsDeferredTriviaCommit(ctx)) return advanceTrivia(input, cur, ctx);
1514
+ const scan = scanTrivia(input, cur, ctx);
1515
+ scan.commit();
1516
+ return scan.end;
1517
+ }
1512
1518
  function fastTriviaScanner(trivia2) {
1513
1519
  const cached = fastTriviaCache.get(trivia2);
1514
1520
  if (cached !== void 0) return cached;
@@ -2301,6 +2307,49 @@ function parserHasTriviaSite(p, seen = /* @__PURE__ */ new Set()) {
2301
2307
  return true;
2302
2308
  }
2303
2309
  }
2310
+ function parserEnablesTriviaCapture(p, seen = /* @__PURE__ */ new Set()) {
2311
+ if (seen.has(p)) return false;
2312
+ seen.add(p);
2313
+ const d = p._def;
2314
+ switch (d.tag) {
2315
+ case "grammar":
2316
+ return d.captureTrivia === true || parserEnablesTriviaCapture(d.parser, seen);
2317
+ case "node":
2318
+ return false;
2319
+ case "sequence":
2320
+ case "choice":
2321
+ return d.parsers.some((x) => parserEnablesTriviaCapture(x, seen));
2322
+ case "sepBy":
2323
+ return parserEnablesTriviaCapture(d.parser, seen) || parserEnablesTriviaCapture(d.separator, seen);
2324
+ case "skip":
2325
+ return parserEnablesTriviaCapture(d.main, seen) || parserEnablesTriviaCapture(d.skipped, seen);
2326
+ case "scanTo":
2327
+ return parserEnablesTriviaCapture(d.sentinel, seen) || d.skip.some((x) => parserEnablesTriviaCapture(x, seen));
2328
+ case "recover":
2329
+ return parserEnablesTriviaCapture(d.parser, seen) || parserEnablesTriviaCapture(d.sentinel, seen);
2330
+ case "many":
2331
+ case "oneOrMore":
2332
+ case "optional":
2333
+ case "transform":
2334
+ case "trivia":
2335
+ case "token":
2336
+ case "label":
2337
+ case "field":
2338
+ case "expect":
2339
+ case "withCtx":
2340
+ case "not":
2341
+ return parserEnablesTriviaCapture(d.parser, seen);
2342
+ case "lazy": {
2343
+ try {
2344
+ return parserEnablesTriviaCapture(d.thunk(), seen);
2345
+ } catch {
2346
+ return false;
2347
+ }
2348
+ }
2349
+ default:
2350
+ return false;
2351
+ }
2352
+ }
2304
2353
  function buildFieldMap(captures) {
2305
2354
  if (!captures?.length) return void 0;
2306
2355
  const out = {};
@@ -2338,11 +2387,13 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
2338
2387
  };
2339
2388
  const unwrap = opts?.unwrap === true;
2340
2389
  const collapse = opts?.collapse === true;
2390
+ const captureTrivia = opts?.captureTrivia === true;
2391
+ const trailingTrivia = opts?.trailingTrivia === true;
2341
2392
  if (unwrap && collapse) {
2342
2393
  throw new Error("node() options cannot set both unwrap and collapse");
2343
2394
  }
2344
- const def = unwrap || collapse ? { ...baseDef, ...unwrap ? { unwrap: true } : {}, ...collapse ? { collapse: true } : {} } : baseDef;
2345
- const capturesTrivia = build ? buildReadsTrivia(def) : true;
2395
+ const def = unwrap || collapse || captureTrivia || trailingTrivia ? { ...baseDef, ...unwrap ? { unwrap: true } : {}, ...collapse ? { collapse: true } : {}, ...captureTrivia ? { captureTrivia: true } : {}, ...trailingTrivia ? { trailingTrivia: true } : {} } : baseDef;
2396
+ const capturesTrivia = captureTrivia || trailingTrivia || (build ? buildReadsTrivia(def) : true);
2346
2397
  const clonesState = build ? buildReadsState(def) : true;
2347
2398
  const capturesFields = parserHasOwnFields(combinator) && (build ? buildReadsFields(def) : true);
2348
2399
  return {
@@ -2358,7 +2409,11 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
2358
2409
  ctx._triviaCaptureMask = ctx.build._parsemanTriviaKinds(def.type);
2359
2410
  }
2360
2411
  if (!capturesTrivia) ctx.captureTrivia = false;
2361
- const r = combinator.parse(input, pos, ctx);
2412
+ let r = combinator.parse(input, pos, ctx);
2413
+ if (r.ok && trailingTrivia && ctx.trivia) {
2414
+ const end = consumeTrivia(input, r.span.end, ctx);
2415
+ r = { ...r, span: { start: r.span.start, end } };
2416
+ }
2362
2417
  const fields = capturesFields ? buildFieldMap(ctx._fields) : void 0;
2363
2418
  ctx._fields = savedFields;
2364
2419
  ctx._triviaCaptureMask = savedMask;
@@ -2366,8 +2421,9 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
2366
2421
  if (!r.ok) return r;
2367
2422
  const st = clonesState && ctx.state !== void 0 ? Object.assign({}, ctx.state) : void 0;
2368
2423
  const nodeType = def.type ?? missingInferredType();
2369
- const built = unwrap && children.length === 1 ? unwrapChild(children[0]) : collapse && children.length === 1 ? children[0] : !build && ctx.build?._parsemanCstCollapse && children.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children[0], children, rawChildren) ? children[0] : build ? build(children, fields, r.span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children, fields, r.span, rawChildren, triviaLog, st) : { _tag: "node", type: nodeType, span: { start: r.span.start, end: r.span.end }, state: st ?? null, children };
2370
- const rawEntry = isCstChild(built) ? built : { _tag: "leaf", value: typeof built === "string" ? built : "", span: r.span };
2424
+ const cstOutput = ctx.build?._parsemanCstOutput === true;
2425
+ const built = unwrap && children.length === 1 ? unwrapChild(children[0]) : collapse && children.length === 1 ? children[0] : !build && ctx.build?._parsemanCstCollapse && children.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children[0], children, rawChildren) ? children[0] : build ? cstOutput && ctx.build ? ctx.build(nodeType, children, fields, r.span, rawChildren, triviaLog, st) : build(children, fields, r.span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children, fields, r.span, rawChildren, triviaLog, st) : { _tag: "node", type: nodeType, span: { start: r.span.start, end: r.span.end }, state: st ?? null, children };
2426
+ const rawEntry = isCstChild(built) ? built : { _tag: "leaf", value: typeof built === "string" ? built : typeof built === "object" && built !== null ? input.slice(r.span.start, r.span.end) : "", span: r.span };
2371
2427
  if (saved.buf !== void 0 || saved.ch !== void 0) {
2372
2428
  pushCstChild(ctx, built, rawEntry);
2373
2429
  }
@@ -2484,6 +2540,7 @@ function parser(opts, root) {
2484
2540
  parser: root,
2485
2541
  triviaParser: clearTrivia ? void 0 : opts.trivia ?? void 0,
2486
2542
  clearTrivia,
2543
+ ...opts.captureTrivia ? { captureTrivia: true } : {},
2487
2544
  trackLines: opts.trackLines ?? false
2488
2545
  },
2489
2546
  parse(input, pos, _ctx) {
@@ -3620,7 +3677,7 @@ function scanBranchLabeled(shape, kindIndex, mint) {
3620
3677
  ` if (${m.end} > _e) {`,
3621
3678
  ` if (_cap) {`,
3622
3679
  ` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, ${m.end}, ${kindIndex})`,
3623
- ` if (_ctx._cstTriviaLog !== undefined && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << kindIndex}))) _ctx._cstTriviaLog.push(_e, ${m.end}, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${kindIndex})`,
3680
+ ` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << kindIndex}))) _ctx._cstTriviaLog.push(_e, ${m.end}, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${kindIndex})`,
3624
3681
  ` }`,
3625
3682
  ` _e = ${m.end}`,
3626
3683
  ` continue`,
@@ -3676,7 +3733,7 @@ function analyzeTriviaFastPath(trivia2) {
3676
3733
  var CAP_RECORD = [
3677
3734
  ` if (_cap && _e > _pos) {`,
3678
3735
  ` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_pos, _e)`,
3679
- ` if (_ctx._cstTriviaLog !== undefined) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
3736
+ ` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
3680
3737
  ` }`
3681
3738
  ].join("\n");
3682
3739
  function composeFastLoop(shapes) {
@@ -3736,7 +3793,7 @@ function buildLabeledRegexTriviaFnDecl(fnName, spec, reNames) {
3736
3793
  ` const _ce = _e + _m${i}[0].length`,
3737
3794
  ` if (_cap) {`,
3738
3795
  ` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, _ce, ${k})`,
3739
- ` if (_ctx._cstTriviaLog !== undefined && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
3796
+ ` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
3740
3797
  ` }`,
3741
3798
  ` _e = _ce`,
3742
3799
  ` _matched = true`,
@@ -3774,7 +3831,7 @@ function buildLabeledRuntimeTriviaFnDecl(fnName, spec, rpStartIndex) {
3774
3831
  ` const _ce = _r${i}.span.end`,
3775
3832
  ` if (_cap) {`,
3776
3833
  ` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, _ce, ${k})`,
3777
- ` if (_ctx._cstTriviaLog !== undefined && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
3834
+ ` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
3778
3835
  ` }`,
3779
3836
  ` _e = _ce`,
3780
3837
  ` _matched = true`,
@@ -4125,7 +4182,7 @@ function ensureTriviaFn(ctx) {
4125
4182
  ` }`,
4126
4183
  ` if (_cap && _e > _pos) {`,
4127
4184
  ` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_pos, _e)`,
4128
- ` if (_ctx._cstTriviaLog !== undefined) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
4185
+ ` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
4129
4186
  ` }`,
4130
4187
  ` return _e`,
4131
4188
  `}`
@@ -5260,17 +5317,18 @@ function emitNode(def, ctx, pos) {
5260
5317
  ctx.buildSrcs.push(def.buildSrc ?? null);
5261
5318
  }
5262
5319
  const i = ind(ctx);
5263
- const capturesTrivia = mkType !== null || !structural && buildReadsTrivia(def);
5320
+ const capturesTrivia = mkType !== null || def.captureTrivia === true || def.trailingTrivia === true || !structural && buildReadsTrivia(def);
5264
5321
  const clonesState = !structural && buildReadsState(def);
5265
5322
  const hasFields = parserHasOwnFields(def.parser);
5266
5323
  const capturesFields = hasFields && !structural && buildReadsFields(def);
5324
+ const innerEnablesTriviaCapture = parserEnablesTriviaCapture(def.parser);
5267
5325
  const chV = v(ctx, "_ch");
5268
5326
  const rawV = v(ctx, "_raw");
5269
- const capTLv = structural ? v(ctx, "_ctl") : null;
5327
+ const capTLv = structural || capturesTrivia ? v(ctx, "_ctl") : null;
5270
5328
  const capSTv = structural ? v(ctx, "_cst") : null;
5271
5329
  const capFv = structural && hasFields ? v(ctx, "_cf") : null;
5272
5330
  const tlV = capturesTrivia || structural ? v(ctx, "_tl") : "_EMPTY_TL";
5273
- if (!capturesTrivia) ctx.needsEmptyTl = true;
5331
+ if (!capturesTrivia || structural) ctx.needsEmptyTl = true;
5274
5332
  const sc = v(ctx, "_sc"), sl = v(ctx, "_sl"), sr = v(ctx, "_sr"), st = v(ctx, "_st"), stl = v(ctx, "_stl");
5275
5333
  const smk = structural ? v(ctx, "_smk") : null;
5276
5334
  if (structural) ctx.needsHostReads = true;
@@ -5279,16 +5337,17 @@ function emitNode(def, ctx, pos) {
5279
5337
  const profHoist = `${i}const ${pmV} = _ctx._pmProfile, ${recV} = ${pmV}?.phase === 'recognizer', ${capV} = ${pmV}?.phase === 'capture'`;
5280
5338
  const profileRecognizer = recV;
5281
5339
  const profileCapture = capV;
5282
- const allocStmt = structural ? `${i}const ${capTLv} = !(${profileRecognizer}) && (${profileCapture} || ${hostTriviaGate}), ${capSTv} = !(${profileRecognizer} || ${profileCapture}) && (_ctx._pmCapST ??= (_ctx.build === undefined || _hostReads(_ctx.build, 6)))${capFv ? `, ${capFv} = !(${profileRecognizer}) && (${profileCapture} || (_ctx.build !== undefined && _hostReads(_ctx.build, 2)))` : ""}
5283
- ${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : [], ${tlV} = ${capTLv} ? [] : _EMPTY_TL` : capturesTrivia ? `${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : [], ${tlV} = ${profileRecognizer} ? undefined : []` : `${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : []`;
5284
- const innerTl = structural ? `${capTLv} ? ${tlV} : undefined` : capturesTrivia ? tlV : "undefined";
5340
+ const structuralCapturesTrivia = structural && (def.captureTrivia === true || def.trailingTrivia === true);
5341
+ const allocStmt = structural ? `${i}const ${capTLv} = !(${profileRecognizer}) && (${profileCapture} || ${structuralCapturesTrivia ? "true" : hostTriviaGate}), ${capSTv} = !(${profileRecognizer} || ${profileCapture}) && (_ctx._pmCapST ??= (_ctx.build === undefined || _hostReads(_ctx.build, 6)))${capFv ? `, ${capFv} = !(${profileRecognizer}) && (${profileCapture} || (_ctx.build !== undefined && _hostReads(_ctx.build, 2)))` : ""}
5342
+ ${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : [], ${tlV} = ${profileRecognizer} ? undefined : ${innerEnablesTriviaCapture ? "[]" : `${capTLv} ? [] : _EMPTY_TL`}` : capturesTrivia ? `${i}const ${capTLv} = !(${profileRecognizer}), ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : [], ${tlV} = ${profileRecognizer} ? undefined : []` : `${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : []`;
5343
+ const innerTl = structural || capturesTrivia ? structural && !innerEnablesTriviaCapture ? `${capTLv} ? ${tlV} : undefined` : tlV : "undefined";
5285
5344
  const fieldsOn = structural ? capFv ?? "false" : `${profileRecognizer} ? false : ${capturesFields ? "true" : "false"}`;
5286
5345
  const sf = hasFields ? v(ctx, "_sf") : null;
5287
5346
  const fArr = hasFields ? v(ctx, "_fa") : null;
5288
5347
  const fObj = hasFields ? v(ctx, "_fields") : "undefined";
5289
- const needsTriviaFrame = parserHasTriviaSite(def.parser);
5348
+ const needsTriviaFrame = def.trailingTrivia === true || parserHasTriviaSite(def.parser);
5290
5349
  const saveTrivia = needsTriviaFrame ? `, ${st} = _ctx.captureTrivia, ${stl} = _ctx._cstTriviaLog${smk ? `, ${smk} = _ctx._triviaCaptureMask` : ""}` : "";
5291
- const installTrivia = needsTriviaFrame ? `; _ctx.captureTrivia = true; _ctx._cstTriviaLog = ${innerTl}${smk ? `; _ctx._triviaCaptureMask = ${capTLv} && _ctx.build._parsemanTriviaKinds !== undefined ? _ctx.build._parsemanTriviaKinds(${JSON.stringify(def.type)}) : ${smk}` : ""}` : "";
5350
+ 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}` : ""}` : "";
5292
5351
  const restoreTrivia = needsTriviaFrame ? `; _ctx.captureTrivia = ${st}; _ctx._cstTriviaLog = ${stl}${smk ? `; _ctx._triviaCaptureMask = ${smk}` : ""}` : "";
5293
5352
  const stmts = [
5294
5353
  profHoist,
@@ -5296,8 +5355,13 @@ ${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRec
5296
5355
  `${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren${saveTrivia}${sf ? `, ${sf} = _ctx._fields` : ""}`,
5297
5356
  `${i}_ctx._cstChildren = ${chV}; _ctx._cstLeaves = ${chV}; _ctx._cstRawChildren = ${rawV}${installTrivia}${sf ? `; _ctx._fields = ${fieldsOn} ? [] : undefined` : ""}`
5298
5357
  ];
5299
- const { stmts: innerStmts, okVar, endVar } = emitFallible(def.parser, ctx, pos);
5358
+ const { stmts: innerStmts, okVar, endVar: innerEndVar } = emitFallible(def.parser, ctx, pos);
5359
+ const endVar = def.trailingTrivia === true && ctx.activeTrivia ? v(ctx, "_trailend") : innerEndVar;
5300
5360
  stmts.push(...innerStmts);
5361
+ if (def.trailingTrivia === true && ctx.activeTrivia) {
5362
+ const triviaFn = ensureTriviaFn(ctx);
5363
+ stmts.push(`${i}const ${endVar} = ${okVar} ? ${triviaFn}(input, ${innerEndVar}, _ctx, 1) : ${innerEndVar}`);
5364
+ }
5301
5365
  if (sf && fArr) {
5302
5366
  stmts.push(`${i}const ${fArr} = _ctx._fields`);
5303
5367
  }
@@ -5337,8 +5401,9 @@ ${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRec
5337
5401
  }
5338
5402
  const ndV = v(ctx, "_nd");
5339
5403
  const buildExpr = structural ? `{ _tag: 'node', type: ${JSON.stringify(def.type)}, span: { start: ${pos}, end: ${endVar} }, state: ${stV} ?? null, children: ${chV} }` : mkType ? emitInlineMkNodeExpr(mkType, chV, rawV, pos, endVar, tlV) : `${buildRef(ctx)}[${buildIdx}](${chV}, ${fObj}, { start: ${pos}, end: ${endVar} }, ${rawV}, ${tlV}, ${stV})`;
5340
- const ndExpr = ctx.ns || structural ? `_ctx.build !== undefined ? (_ctx._pmProfile?.phase === 'host' && _ctx._pmProfile.hostCalls++, _ctx.build(${JSON.stringify(def.type)}, ${chV}, ${fObj}, { start: ${pos}, end: ${endVar} }, ${rawV}, ${tlV}, ${stV})) : (${buildExpr})` : buildExpr;
5341
- const hostCollapseExpr = ctx.ns || structural ? `_ctx.build !== undefined && _ctx.build._parsemanCstCollapse !== undefined && ${chV}.length === 1 && ${rawV}.length === 1 && _ctx.build._parsemanCstCollapse(${JSON.stringify(def.type)}, ${chV}[0], ${chV}, ${rawV}) ? ${chV}[0] : (${ndExpr})` : ndExpr;
5404
+ const hostBuildExpr = `_ctx._pmProfile?.phase === 'host' && _ctx._pmProfile.hostCalls++, _ctx.build(${JSON.stringify(def.type)}, ${chV}, ${fObj}, { start: ${pos}, end: ${endVar} }, ${rawV}, ${tlV}, ${stV})`;
5405
+ const ndExpr = structural ? `_ctx.build !== undefined ? (${hostBuildExpr}) : (${buildExpr})` : `_ctx.build?._parsemanCstOutput === true ? (${hostBuildExpr}) : (${buildExpr})`;
5406
+ const hostCollapseExpr = structural ? `_ctx.build !== undefined && _ctx.build._parsemanCstCollapse !== undefined && ${chV}.length === 1 && ${rawV}.length === 1 && _ctx.build._parsemanCstCollapse(${JSON.stringify(def.type)}, ${chV}[0], ${chV}, ${rawV}) ? ${chV}[0] : (${ndExpr})` : ndExpr;
5342
5407
  const unwrapExpr = `${chV}.length === 1 ? (${chV}[0] !== null && typeof ${chV}[0] === 'object' && ${chV}[0]._tag === 'leaf' ? ${chV}[0].value : ${chV}[0]) : (${ndExpr})`;
5343
5408
  const collapseExpr = `${chV}.length === 1 ? ${chV}[0] : (${ndExpr})`;
5344
5409
  const finalExpr = def.unwrap ? unwrapExpr : def.collapse ? collapseExpr : hostCollapseExpr;
@@ -5346,7 +5411,7 @@ ${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRec
5346
5411
  `${i}const ${ndV} = (${profileRecognizer} || ${profileCapture}) ? undefined : (${finalExpr})`,
5347
5412
  `${i}if (!(${profileRecognizer})) {`,
5348
5413
  `${i} if (${sc}) ${sc}.push(${ndV})`,
5349
- `${i} if (${sr}) ${sr}.push((typeof ${ndV} === 'object' && ${ndV} !== null && (${ndV}._tag === 'node' || ${ndV}._tag === 'leaf' || ${ndV}._tag === 'parseError')) ? ${ndV} : { _tag: 'leaf', value: typeof ${ndV} === 'string' ? ${ndV} : '', span: { start: ${pos}, end: ${endVar} } })`,
5414
+ `${i} if (${sr}) ${sr}.push((typeof ${ndV} === 'object' && ${ndV} !== null && (${ndV}._tag === 'node' || ${ndV}._tag === 'leaf' || ${ndV}._tag === 'parseError')) ? ${ndV} : { _tag: 'leaf', value: typeof ${ndV} === 'string' ? ${ndV} : (typeof ${ndV} === 'object' && ${ndV} !== null ? input.slice(${pos}, ${endVar}) : ''), span: { start: ${pos}, end: ${endVar} } })`,
5350
5415
  `${i}}`
5351
5416
  );
5352
5417
  return { stmts, valueVar: ndV, endVar };
@@ -5589,10 +5654,19 @@ function emitDispatch(p, ctx, pos) {
5589
5654
  ctx.triviaKindLabels = def.triviaParser._meta.triviaKindLabels;
5590
5655
  }
5591
5656
  }
5657
+ const savedCapture = def.captureTrivia ? v(ctx, "_gcap") : null;
5592
5658
  const r = emit(def.parser, ctx, pos);
5593
5659
  ctx.activeTrivia = savedTrivia;
5594
5660
  ctx.triviaKindLabels = savedKindLabels;
5595
- return r;
5661
+ if (!savedCapture) return r;
5662
+ return {
5663
+ ...r,
5664
+ stmts: [
5665
+ `${ind(ctx)}const ${savedCapture} = _ctx.captureTrivia; _ctx.captureTrivia = true`,
5666
+ ...r.stmts,
5667
+ `${ind(ctx)}_ctx.captureTrivia = ${savedCapture}`
5668
+ ]
5669
+ };
5596
5670
  }
5597
5671
  case "not":
5598
5672
  return emitNot(def, ctx, pos);
@@ -6440,9 +6514,15 @@ function evalRuleMapIR(ir) {
6440
6514
  t._def.fnSrc = src;
6441
6515
  return t;
6442
6516
  };
6443
- const _nd = (type, child, src, opts) => {
6444
- const n = node(type, child, void 0, opts);
6517
+ const _nd = (type, child, src, opts, staticError) => {
6518
+ if (staticError !== void 0 && staticError.length > 0) {
6519
+ throw new Error(`IR direct node builder for ${type} must be macro-static and self-contained; unsupported binding(s): ${staticError.join(", ")}`);
6520
+ }
6521
+ const n = node(type, child, (() => {
6522
+ throw new Error("IR node build requires static re-lowering");
6523
+ }), opts);
6445
6524
  n._def.buildSrc = src;
6525
+ if (staticError !== void 0) n._def.buildStaticError = staticError;
6446
6526
  return n;
6447
6527
  };
6448
6528
  const _gch = (items) => {
@@ -6692,17 +6772,26 @@ ${body}
6692
6772
  }
6693
6773
  case "node": {
6694
6774
  if (def.build !== void 0 && def.buildSrc === void 0) throw new Unserializable("node build without buildSrc");
6695
- const opts = def.unwrap || def.collapse ? `, { ${def.unwrap ? "unwrap: true" : "collapse: true"} }` : "";
6775
+ const optEntries = [
6776
+ ...def.unwrap ? ["unwrap: true"] : [],
6777
+ ...def.collapse ? ["collapse: true"] : [],
6778
+ ...def.captureTrivia ? ["captureTrivia: true"] : [],
6779
+ ...def.trailingTrivia ? ["trailingTrivia: true"] : []
6780
+ ];
6781
+ const opts = optEntries.length > 0 ? `, { ${optEntries.join(", ")} }` : "";
6696
6782
  if (def.type === void 0) {
6697
6783
  if (def.buildSrc !== void 0) throw new Unserializable("inferred node build without inferred type");
6698
6784
  return opts ? `node(${kid(def.parser)}, undefined${opts})` : `node(${kid(def.parser)})`;
6699
6785
  }
6700
- if (def.buildSrc !== void 0) return `_nd(${JSON.stringify(def.type)}, ${kid(def.parser)}, ${JSON.stringify(def.buildSrc)}${opts})`;
6786
+ if (def.buildSrc !== void 0) {
6787
+ const staticError = def.buildStaticError === void 0 ? "" : `${opts ? "" : ", undefined"}, ${JSON.stringify(def.buildStaticError)}`;
6788
+ return `_nd(${JSON.stringify(def.type)}, ${kid(def.parser)}, ${JSON.stringify(def.buildSrc)}${opts}${staticError})`;
6789
+ }
6701
6790
  return opts ? `node(${JSON.stringify(def.type)}, ${kid(def.parser)}, undefined${opts})` : `node(${JSON.stringify(def.type)}, ${kid(def.parser)})`;
6702
6791
  }
6703
6792
  case "grammar": {
6704
6793
  const trivia2 = def.clearTrivia ? "null" : def.triviaParser ? kid(def.triviaParser) : "undefined";
6705
- return `parser({ trivia: ${trivia2}${def.trackLines ? ", trackLines: true" : ""} }, ${kid(def.parser)})`;
6794
+ return `parser({ trivia: ${trivia2}${def.captureTrivia ? ", captureTrivia: true" : ""}${def.trackLines ? ", trackLines: true" : ""} }, ${kid(def.parser)})`;
6706
6795
  }
6707
6796
  case "withCtx": {
6708
6797
  if (def.extraSrc === void 0) throw new Unserializable("withCtx without extraSrc");
@@ -6717,6 +6806,28 @@ ${body}
6717
6806
  };
6718
6807
 
6719
6808
  // src/compiler/linker.ts
6809
+ function normalizeCstCollapse(collapse) {
6810
+ if (collapse === true) return () => true;
6811
+ if (Array.isArray(collapse)) {
6812
+ const types = new Set(collapse);
6813
+ return (type) => types.has(type);
6814
+ }
6815
+ return typeof collapse === "function" ? collapse : void 0;
6816
+ }
6817
+ function buildCstNode(type, children, _fields, span, _rawChildren, _triviaLog, state) {
6818
+ return { _tag: "node", type, span: { start: span.start, end: span.end }, state: state ?? null, children: [...children] };
6819
+ }
6820
+ function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, triviaLog, state) {
6821
+ if (typeof typeOrOptions === "string") {
6822
+ return buildCstNode(typeOrOptions, children ?? [], _fields, span ?? { start: 0, end: 0 }, rawChildren, triviaLog, state);
6823
+ }
6824
+ const collapse = normalizeCstCollapse(typeOrOptions?.collapse);
6825
+ const host = (type, children2, fields, span2, rawChildren2, triviaLog2, state2) => buildCstNode(type, children2, fields, span2, rawChildren2, triviaLog2, state2);
6826
+ host._parsemanCstOutput = true;
6827
+ if (collapse) host._parsemanCstCollapse = collapse;
6828
+ return host;
6829
+ }
6830
+ cstBuildHost._parsemanCstOutput = true;
6720
6831
  function pickPieces(pieces, names) {
6721
6832
  const winner = /* @__PURE__ */ new Map();
6722
6833
  for (const pc of pieces) for (const k of pc.keys) winner.set(k, pc);
@@ -6826,6 +6937,152 @@ var { isFinite } = Number;
6826
6937
  // src/index.ts
6827
6938
  registerRegexAnalyzer(firstSetFromRegex);
6828
6939
 
6940
+ // src/plugin/direct-builder-static.ts
6941
+ var import_oxc_parser = require("oxc-parser");
6942
+ var STATIC_BUILDER_GLOBALS = /* @__PURE__ */ new Set([
6943
+ "Array",
6944
+ "Boolean",
6945
+ "Date",
6946
+ "JSON",
6947
+ "Math",
6948
+ "NaN",
6949
+ "Number",
6950
+ "Object",
6951
+ "String",
6952
+ "Infinity",
6953
+ "parseFloat",
6954
+ "parseInt",
6955
+ "undefined"
6956
+ ]);
6957
+ function astArray(value) {
6958
+ return Array.isArray(value) ? value : [];
6959
+ }
6960
+ function astChild(value) {
6961
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
6962
+ }
6963
+ function unwrapCallbackExpression(node2) {
6964
+ let current = node2;
6965
+ while (current?.type === "ParenthesizedExpression") current = astChild(current.expression) ?? void 0;
6966
+ return current;
6967
+ }
6968
+ function directBuilderUnsupportedBindings(src) {
6969
+ let init;
6970
+ try {
6971
+ const parsed = (0, import_oxc_parser.parseSync)("parseman-direct-builder.ts", `const _direct = (${src})`);
6972
+ if (parsed.errors.length > 0) return ["invalid callback source"];
6973
+ const program = parsed.program;
6974
+ const statement = program.body?.[0];
6975
+ const declaration = statement?.declarations?.[0];
6976
+ init = unwrapCallbackExpression(declaration?.init);
6977
+ } catch {
6978
+ return ["invalid callback source"];
6979
+ }
6980
+ if (init?.type !== "ArrowFunctionExpression" || !Array.isArray(init.params)) return ["unsupported callback shape"];
6981
+ const allowed = new Set(STATIC_BUILDER_GLOBALS);
6982
+ for (const param of init.params) {
6983
+ if (param.type !== "Identifier" || typeof param.name !== "string") return ["unsupported parameter pattern"];
6984
+ allowed.add(param.name);
6985
+ }
6986
+ const unsupported = /* @__PURE__ */ new Set();
6987
+ const reportUnsupportedNode = (ast) => {
6988
+ unsupported.add(`unsupported ${ast.type}`);
6989
+ };
6990
+ const read = (ast, allowedNames) => {
6991
+ if (typeof ast.name === "string" && allowedNames.has(ast.name)) return;
6992
+ unsupported.add(typeof ast.name === "string" ? ast.name : "identifier");
6993
+ };
6994
+ const expression = (node2, allowedNames) => {
6995
+ const ast = astChild(node2);
6996
+ if (!ast) return;
6997
+ switch (ast.type) {
6998
+ case "Literal":
6999
+ return;
7000
+ case "Identifier":
7001
+ read(ast, allowedNames);
7002
+ return;
7003
+ case "ParenthesizedExpression":
7004
+ case "ChainExpression":
7005
+ case "TSAsExpression":
7006
+ case "TSTypeAssertion":
7007
+ case "TSNonNullExpression":
7008
+ expression(ast.expression, allowedNames);
7009
+ return;
7010
+ case "ArrayExpression":
7011
+ for (const element of astArray(ast.elements)) expression(element, allowedNames);
7012
+ return;
7013
+ case "ObjectExpression":
7014
+ for (const property of astArray(ast.properties)) {
7015
+ if (property.type === "SpreadElement") {
7016
+ expression(property.argument, allowedNames);
7017
+ continue;
7018
+ }
7019
+ if (property.type !== "Property" || property.method === true || property.kind !== "init") {
7020
+ reportUnsupportedNode(property);
7021
+ continue;
7022
+ }
7023
+ if (property.computed === true) expression(property.key, allowedNames);
7024
+ expression(property.value, allowedNames);
7025
+ }
7026
+ return;
7027
+ case "MemberExpression":
7028
+ expression(ast.object, allowedNames);
7029
+ if (ast.computed === true) expression(ast.property, allowedNames);
7030
+ return;
7031
+ case "CallExpression":
7032
+ case "NewExpression":
7033
+ expression(ast.callee, allowedNames);
7034
+ for (const argument of astArray(ast.arguments)) expression(argument, allowedNames);
7035
+ return;
7036
+ case "UnaryExpression":
7037
+ case "UpdateExpression":
7038
+ expression(ast.argument, allowedNames);
7039
+ return;
7040
+ case "BinaryExpression":
7041
+ case "LogicalExpression":
7042
+ case "AssignmentExpression":
7043
+ expression(ast.left, allowedNames);
7044
+ expression(ast.right, allowedNames);
7045
+ return;
7046
+ case "ConditionalExpression":
7047
+ expression(ast.test, allowedNames);
7048
+ expression(ast.consequent, allowedNames);
7049
+ expression(ast.alternate, allowedNames);
7050
+ return;
7051
+ case "SequenceExpression":
7052
+ for (const value of astArray(ast.expressions)) expression(value, allowedNames);
7053
+ return;
7054
+ case "TemplateLiteral":
7055
+ for (const value of astArray(ast.expressions)) expression(value, allowedNames);
7056
+ return;
7057
+ case "SpreadElement":
7058
+ expression(ast.argument, allowedNames);
7059
+ return;
7060
+ case "ArrowFunctionExpression": {
7061
+ const nested = new Set(allowedNames);
7062
+ for (const param of astArray(ast.params)) {
7063
+ if (param.type !== "Identifier" || typeof param.name !== "string") {
7064
+ reportUnsupportedNode(param);
7065
+ continue;
7066
+ }
7067
+ nested.add(param.name);
7068
+ }
7069
+ if (astChild(ast.body)?.type === "BlockStatement") {
7070
+ reportUnsupportedNode(astChild(ast.body));
7071
+ return;
7072
+ }
7073
+ expression(ast.body, nested);
7074
+ return;
7075
+ }
7076
+ default:
7077
+ reportUnsupportedNode(ast);
7078
+ return;
7079
+ }
7080
+ };
7081
+ if (astChild(init.body)?.type === "BlockStatement") unsupported.add("unsupported BlockStatement");
7082
+ else expression(init.body, allowed);
7083
+ return [...unsupported];
7084
+ }
7085
+
6829
7086
  // src/plugin/evaluator.ts
6830
7087
  function stripTsFromSource(node2, code) {
6831
7088
  const cuts = [];
@@ -6882,6 +7139,7 @@ var SUPPORTED = {
6882
7139
  many: (...a) => many(a[0]),
6883
7140
  oneOrMore: (...a) => oneOrMore(a[0]),
6884
7141
  optional: (...a) => optional(a[0]),
7142
+ skip: (...a) => skip(a[0], a[1]),
6885
7143
  sepBy: (...a) => sepBy(a[0], a[1]),
6886
7144
  trivia: (...a) => trivia(a[0]),
6887
7145
  label: (...a) => label(a[0], a[1]),
@@ -6943,12 +7201,12 @@ function staticNodeOptions(expr) {
6943
7201
  if (p.computed) continue;
6944
7202
  const key = p.key;
6945
7203
  const name = key.type === "Identifier" ? key.name : key.type === "Literal" ? String(key.value) : void 0;
6946
- if (name === "unwrap" || name === "collapse") {
7204
+ if (name === "unwrap" || name === "collapse" || name === "captureTrivia" || name === "trailingTrivia") {
6947
7205
  const val = p.value;
6948
7206
  if ((val.type === "Literal" || val.type === "BooleanLiteral") && val.value === true) opts[name] = true;
6949
7207
  }
6950
7208
  }
6951
- return opts.unwrap || opts.collapse ? opts : void 0;
7209
+ return opts.unwrap || opts.collapse || opts.captureTrivia || opts.trailingTrivia ? opts : void 0;
6952
7210
  }
6953
7211
  function exprToCombi(node2, scope, code, mfs) {
6954
7212
  if (node2.type === "Identifier") return scopeGet(scope, node2.name, mfs);
@@ -7010,11 +7268,15 @@ function exprToCombi(node2, scope, code, mfs) {
7010
7268
  if (!isCombinator(inner)) return null;
7011
7269
  const be = buildArg;
7012
7270
  const hasBuild = be !== void 0 && be.type !== "SpreadElement" && !(be.type === "Identifier" && be.name === "undefined");
7013
- const buildSrc = hasBuild ? code.slice(be.start, be.end) : void 0;
7271
+ const buildSrc = hasBuild ? stripTsFromSource(be, code) : void 0;
7014
7272
  const opts = optsArg !== void 0 && optsArg.type !== "SpreadElement" ? staticNodeOptions(optsArg) : void 0;
7015
7273
  try {
7016
7274
  const combi = explicitType !== void 0 ? node(explicitType, inner, hasBuild ? () => null : void 0, opts) : node(inner, hasBuild ? () => null : void 0, opts);
7017
- if (combi._def.tag === "node" && buildSrc !== void 0) combi._def.buildSrc = buildSrc;
7275
+ if (combi._def.tag === "node" && buildSrc !== void 0) {
7276
+ combi._def.buildSrc = buildSrc;
7277
+ const staticError = directBuilderUnsupportedBindings(buildSrc);
7278
+ if (staticError.length > 0) combi._def.buildStaticError = staticError;
7279
+ }
7018
7280
  return combi;
7019
7281
  } catch {
7020
7282
  return null;
@@ -7107,7 +7369,7 @@ function exprToCombi(node2, scope, code, mfs) {
7107
7369
  if (code === void 0 || mfs === void 0) return null;
7108
7370
  const [predArg] = node2.arguments;
7109
7371
  if (!predArg || predArg.type === "SpreadElement") return null;
7110
- const predSrc = code.slice(predArg.start, predArg.end);
7372
+ const predSrc = stripTsFromSource(predArg, code);
7111
7373
  mfs.push(predSrc);
7112
7374
  try {
7113
7375
  const combi = guard(() => true);
@@ -7122,7 +7384,7 @@ function exprToCombi(node2, scope, code, mfs) {
7122
7384
  if (code === void 0 || mfs === void 0) return null;
7123
7385
  const [extraArg, innerArg] = node2.arguments;
7124
7386
  if (!extraArg || !innerArg || extraArg.type === "SpreadElement" || innerArg.type === "SpreadElement") return null;
7125
- const extraSrc = code.slice(extraArg.start, extraArg.end);
7387
+ const extraSrc = stripTsFromSource(extraArg, code);
7126
7388
  mfs.push(extraSrc);
7127
7389
  const inner = anyValue(innerArg, scope, code, mfs);
7128
7390
  if (!isCombinator(inner)) return null;
@@ -7458,7 +7720,7 @@ function parseModuleCached(filePath) {
7458
7720
  let parsed = null;
7459
7721
  try {
7460
7722
  const src = fs.readFileSync(filePath, "utf8");
7461
- const r = (0, import_oxc_parser.parseSync)(filePath, src);
7723
+ const r = (0, import_oxc_parser2.parseSync)(filePath, src);
7462
7724
  if (r.errors.length === 0) parsed = { body: r.program.body, src };
7463
7725
  } catch {
7464
7726
  }
@@ -7585,7 +7847,7 @@ function extractImportBindings(body) {
7585
7847
  function transformMacro(code, id, moduleAliases = /* @__PURE__ */ new Set([PARSEMAN_MODULE]), warnUnloweredRegex = false, recovery = false) {
7586
7848
  let result;
7587
7849
  try {
7588
- result = (0, import_oxc_parser.parseSync)(id, code);
7850
+ result = (0, import_oxc_parser2.parseSync)(id, code);
7589
7851
  } catch {
7590
7852
  return null;
7591
7853
  }
@@ -7623,6 +7885,7 @@ function transformMacro(code, id, moduleAliases = /* @__PURE__ */ new Set([PARSE
7623
7885
  const warnings = [];
7624
7886
  beginLoweringCapture();
7625
7887
  let anyUnresolved = false;
7888
+ let runtimeComposeFallback = false;
7626
7889
  let ruleMapHolderCounter = 0;
7627
7890
  const lineOf = (pos) => {
7628
7891
  let line = 1;
@@ -7955,7 +8218,10 @@ function transformMacro(code, id, moduleAliases = /* @__PURE__ */ new Set([PARSE
7955
8218
  }
7956
8219
  if (isComposeCall(init)) {
7957
8220
  const fused = compileComposeCall(init);
7958
- if (!fused) continue;
8221
+ if (!fused) {
8222
+ runtimeComposeFallback = true;
8223
+ continue;
8224
+ }
7959
8225
  localComposedCarried.set(varName, fused.carried);
7960
8226
  if (fused.trivia) localComposedTrivia.set(varName, fused.trivia);
7961
8227
  const replacement = exportPrefix ? withCarriedPieces(fused.replacement, fused.carried) : fused.replacement;
@@ -8055,7 +8321,7 @@ function transformMacro(code, id, moduleAliases = /* @__PURE__ */ new Set([PARSE
8055
8321
  ms.overwrite(imp.start, imp.end, stripped);
8056
8322
  }
8057
8323
  }
8058
- for (const { start, end, replacement } of [...replacements].sort((a, b) => b.start - a.start)) {
8324
+ for (const { start, end, replacement } of (runtimeComposeFallback ? [] : replacements).sort((a, b) => b.start - a.start)) {
8059
8325
  ms.overwrite(start, end, replacement);
8060
8326
  }
8061
8327
  const unlowered = endLoweringCapture();