webpipe-js 2.0.32 → 2.0.33

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/index.cjs CHANGED
@@ -512,6 +512,8 @@ var Parser = class {
512
512
  this.expect("|>");
513
513
  this.skipInlineSpaces();
514
514
  const name = this.parseIdentifier();
515
+ const args = this.parseInlineArgs();
516
+ this.skipInlineSpaces();
515
517
  this.expect(":");
516
518
  this.skipInlineSpaces();
517
519
  const { config, configType } = this.parseStepConfig();
@@ -519,7 +521,7 @@ var Parser = class {
519
521
  const parsedJoinTargets = name === "join" ? this.parseJoinTaskNames(config) : void 0;
520
522
  this.skipWhitespaceOnly();
521
523
  const end = this.pos;
522
- return { kind: "Regular", name, config, configType, condition, parsedJoinTargets, start, end };
524
+ return { kind: "Regular", name, args, config, configType, condition, parsedJoinTargets, start, end };
523
525
  }
524
526
  /**
525
527
  * Parse optional step condition (tag expression after the config)
@@ -573,6 +575,129 @@ var Parser = class {
573
575
  }
574
576
  return names;
575
577
  }
578
+ /**
579
+ * Split argument content by commas while respecting nesting depth and strings
580
+ * Example: `"url", {a:1, b:2}` -> [`"url"`, `{a:1, b:2}`]
581
+ */
582
+ splitBalancedArgs(content) {
583
+ const args = [];
584
+ let current = "";
585
+ let depth = 0;
586
+ let inString = false;
587
+ let stringChar = "";
588
+ let escapeNext = false;
589
+ for (let i = 0; i < content.length; i++) {
590
+ const ch = content[i];
591
+ if (escapeNext) {
592
+ current += ch;
593
+ escapeNext = false;
594
+ continue;
595
+ }
596
+ if (ch === "\\" && inString) {
597
+ current += ch;
598
+ escapeNext = true;
599
+ continue;
600
+ }
601
+ if ((ch === '"' || ch === "`") && !inString) {
602
+ inString = true;
603
+ stringChar = ch;
604
+ current += ch;
605
+ continue;
606
+ }
607
+ if (ch === stringChar && inString) {
608
+ inString = false;
609
+ stringChar = "";
610
+ current += ch;
611
+ continue;
612
+ }
613
+ if (inString) {
614
+ current += ch;
615
+ continue;
616
+ }
617
+ if (ch === "(" || ch === "[" || ch === "{") {
618
+ depth++;
619
+ current += ch;
620
+ } else if (ch === ")" || ch === "]" || ch === "}") {
621
+ depth--;
622
+ current += ch;
623
+ } else if (ch === "," && depth === 0) {
624
+ args.push(current.trim());
625
+ current = "";
626
+ } else {
627
+ current += ch;
628
+ }
629
+ }
630
+ if (current.trim().length > 0) {
631
+ args.push(current.trim());
632
+ }
633
+ return args;
634
+ }
635
+ /**
636
+ * Parse inline arguments: middleware(arg1, arg2) or middleware[arg1, arg2]
637
+ * Returns the array of argument strings and advances position past the closing bracket
638
+ */
639
+ parseInlineArgs() {
640
+ const trimmedStart = this.pos;
641
+ this.skipInlineSpaces();
642
+ const ch = this.cur();
643
+ if (ch !== "(" && ch !== "[") {
644
+ this.pos = trimmedStart;
645
+ return [];
646
+ }
647
+ const openChar = ch;
648
+ const closeChar = openChar === "(" ? ")" : "]";
649
+ this.pos++;
650
+ let depth = 1;
651
+ let inString = false;
652
+ let stringChar = "";
653
+ let escapeNext = false;
654
+ const contentStart = this.pos;
655
+ while (!this.eof() && depth > 0) {
656
+ const c = this.cur();
657
+ if (escapeNext) {
658
+ this.pos++;
659
+ escapeNext = false;
660
+ continue;
661
+ }
662
+ if (c === "\\" && inString) {
663
+ this.pos++;
664
+ escapeNext = true;
665
+ continue;
666
+ }
667
+ if ((c === '"' || c === "`") && !inString) {
668
+ inString = true;
669
+ stringChar = c;
670
+ this.pos++;
671
+ continue;
672
+ }
673
+ if (c === stringChar && inString) {
674
+ inString = false;
675
+ stringChar = "";
676
+ this.pos++;
677
+ continue;
678
+ }
679
+ if (!inString) {
680
+ if (c === openChar) {
681
+ depth++;
682
+ } else if (c === closeChar) {
683
+ depth--;
684
+ if (depth === 0) {
685
+ break;
686
+ }
687
+ }
688
+ }
689
+ this.pos++;
690
+ }
691
+ if (depth !== 0) {
692
+ throw new ParseFailure(`unclosed ${openChar}`, contentStart);
693
+ }
694
+ const argsContent = this.text.slice(contentStart, this.pos);
695
+ this.pos++;
696
+ if (argsContent.trim().length === 0) {
697
+ return [];
698
+ }
699
+ return this.splitBalancedArgs(argsContent);
700
+ }
576
701
  parseResultStep() {
577
702
  this.skipWhitespaceOnly();
578
703
  const start = this.pos;
@@ -1641,9 +1766,10 @@ function formatConfigValue(value) {
1641
1766
  }
1642
1767
  function formatPipelineStep(step, indent = " ") {
1643
1768
  if (step.kind === "Regular") {
1769
+ const argsPart = step.args.length > 0 ? `(${step.args.join(", ")})` : "";
1644
1770
  const configPart = formatStepConfig(step.config, step.configType);
1645
1771
  const conditionPart = step.condition ? " " + formatTagExpr(step.condition) : "";
1646
- return `${indent}|> ${step.name}: ${configPart}${conditionPart}`;
1772
+ return `${indent}|> ${step.name}${argsPart}: ${configPart}${conditionPart}`;
1647
1773
  } else if (step.kind === "Result") {
1648
1774
  const lines = [`${indent}|> result`];
1649
1775
  step.branches.forEach((branch) => {
package/dist/index.d.cts CHANGED
@@ -143,6 +143,7 @@ type TagExpr = {
143
143
  type PipelineStep = {
144
144
  kind: 'Regular';
145
145
  name: string;
146
+ args: string[];
146
147
  config: string;
147
148
  configType: ConfigType;
148
149
  condition?: TagExpr;
package/dist/index.d.ts CHANGED
@@ -143,6 +143,7 @@ type TagExpr = {
143
143
  type PipelineStep = {
144
144
  kind: 'Regular';
145
145
  name: string;
146
+ args: string[];
146
147
  config: string;
147
148
  configType: ConfigType;
148
149
  condition?: TagExpr;
package/dist/index.mjs CHANGED
@@ -460,6 +460,8 @@ var Parser = class {
460
460
  this.expect("|>");
461
461
  this.skipInlineSpaces();
462
462
  const name = this.parseIdentifier();
463
+ const args = this.parseInlineArgs();
464
+ this.skipInlineSpaces();
463
465
  this.expect(":");
464
466
  this.skipInlineSpaces();
465
467
  const { config, configType } = this.parseStepConfig();
@@ -467,7 +469,7 @@ var Parser = class {
467
469
  const parsedJoinTargets = name === "join" ? this.parseJoinTaskNames(config) : void 0;
468
470
  this.skipWhitespaceOnly();
469
471
  const end = this.pos;
470
- return { kind: "Regular", name, config, configType, condition, parsedJoinTargets, start, end };
472
+ return { kind: "Regular", name, args, config, configType, condition, parsedJoinTargets, start, end };
471
473
  }
472
474
  /**
473
475
  * Parse optional step condition (tag expression after the config)
@@ -521,6 +523,129 @@ var Parser = class {
521
523
  }
522
524
  return names;
523
525
  }
526
+ /**
527
+ * Split argument content by commas while respecting nesting depth and strings
528
+ * Example: `"url", {a:1, b:2}` -> [`"url"`, `{a:1, b:2}`]
529
+ */
530
+ splitBalancedArgs(content) {
531
+ const args = [];
532
+ let current = "";
533
+ let depth = 0;
534
+ let inString = false;
535
+ let stringChar = "";
536
+ let escapeNext = false;
537
+ for (let i = 0; i < content.length; i++) {
538
+ const ch = content[i];
539
+ if (escapeNext) {
540
+ current += ch;
541
+ escapeNext = false;
542
+ continue;
543
+ }
544
+ if (ch === "\\" && inString) {
545
+ current += ch;
546
+ escapeNext = true;
547
+ continue;
548
+ }
549
+ if ((ch === '"' || ch === "`") && !inString) {
550
+ inString = true;
551
+ stringChar = ch;
552
+ current += ch;
553
+ continue;
554
+ }
555
+ if (ch === stringChar && inString) {
556
+ inString = false;
557
+ stringChar = "";
558
+ current += ch;
559
+ continue;
560
+ }
561
+ if (inString) {
562
+ current += ch;
563
+ continue;
564
+ }
565
+ if (ch === "(" || ch === "[" || ch === "{") {
566
+ depth++;
567
+ current += ch;
568
+ } else if (ch === ")" || ch === "]" || ch === "}") {
569
+ depth--;
570
+ current += ch;
571
+ } else if (ch === "," && depth === 0) {
572
+ args.push(current.trim());
573
+ current = "";
574
+ } else {
575
+ current += ch;
576
+ }
577
+ }
578
+ if (current.trim().length > 0) {
579
+ args.push(current.trim());
580
+ }
581
+ return args;
582
+ }
583
+ /**
584
+ * Parse inline arguments: middleware(arg1, arg2) or middleware[arg1, arg2]
585
+ * Returns the array of argument strings and advances position past the closing bracket
586
+ */
587
+ parseInlineArgs() {
588
+ const trimmedStart = this.pos;
589
+ this.skipInlineSpaces();
590
+ const ch = this.cur();
591
+ if (ch !== "(" && ch !== "[") {
592
+ this.pos = trimmedStart;
593
+ return [];
594
+ }
595
+ const openChar = ch;
596
+ const closeChar = openChar === "(" ? ")" : "]";
597
+ this.pos++;
598
+ let depth = 1;
599
+ let inString = false;
600
+ let stringChar = "";
601
+ let escapeNext = false;
602
+ const contentStart = this.pos;
603
+ while (!this.eof() && depth > 0) {
604
+ const c = this.cur();
605
+ if (escapeNext) {
606
+ this.pos++;
607
+ escapeNext = false;
608
+ continue;
609
+ }
610
+ if (c === "\\" && inString) {
611
+ this.pos++;
612
+ escapeNext = true;
613
+ continue;
614
+ }
615
+ if ((c === '"' || c === "`") && !inString) {
616
+ inString = true;
617
+ stringChar = c;
618
+ this.pos++;
619
+ continue;
620
+ }
621
+ if (c === stringChar && inString) {
622
+ inString = false;
623
+ stringChar = "";
624
+ this.pos++;
625
+ continue;
626
+ }
627
+ if (!inString) {
628
+ if (c === openChar) {
629
+ depth++;
630
+ } else if (c === closeChar) {
631
+ depth--;
632
+ if (depth === 0) {
633
+ break;
634
+ }
635
+ }
636
+ }
637
+ this.pos++;
638
+ }
639
+ if (depth !== 0) {
640
+ throw new ParseFailure(`unclosed ${openChar}`, contentStart);
641
+ }
642
+ const argsContent = this.text.slice(contentStart, this.pos);
643
+ this.pos++;
644
+ if (argsContent.trim().length === 0) {
645
+ return [];
646
+ }
647
+ return this.splitBalancedArgs(argsContent);
648
+ }
524
649
  parseResultStep() {
525
650
  this.skipWhitespaceOnly();
526
651
  const start = this.pos;
@@ -1589,9 +1714,10 @@ function formatConfigValue(value) {
1589
1714
  }
1590
1715
  function formatPipelineStep(step, indent = " ") {
1591
1716
  if (step.kind === "Regular") {
1717
+ const argsPart = step.args.length > 0 ? `(${step.args.join(", ")})` : "";
1592
1718
  const configPart = formatStepConfig(step.config, step.configType);
1593
1719
  const conditionPart = step.condition ? " " + formatTagExpr(step.condition) : "";
1594
- return `${indent}|> ${step.name}: ${configPart}${conditionPart}`;
1720
+ return `${indent}|> ${step.name}${argsPart}: ${configPart}${conditionPart}`;
1595
1721
  } else if (step.kind === "Result") {
1596
1722
  const lines = [`${indent}|> result`];
1597
1723
  step.branches.forEach((branch) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.32",
3
+ "version": "2.0.33",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",