webpipe-js 2.0.26 → 2.0.28

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
@@ -29,6 +29,7 @@ __export(index_exports, {
29
29
  formatTags: () => formatTags,
30
30
  formatWhen: () => formatWhen,
31
31
  getPipelineRanges: () => getPipelineRanges,
32
+ getTestLetVariableRanges: () => getTestLetVariableRanges,
32
33
  getVariableRanges: () => getVariableRanges,
33
34
  parseProgram: () => parseProgram,
34
35
  parseProgramWithDiagnostics: () => parseProgramWithDiagnostics,
@@ -55,6 +56,7 @@ var Parser = class {
55
56
  this.diagnostics = [];
56
57
  this.pipelineRanges = /* @__PURE__ */ new Map();
57
58
  this.variableRanges = /* @__PURE__ */ new Map();
59
+ this.testLetVariableRanges = /* @__PURE__ */ new Map();
58
60
  this.text = text;
59
61
  this.len = text.length;
60
62
  }
@@ -67,6 +69,9 @@ var Parser = class {
67
69
  getVariableRanges() {
68
70
  return new Map(this.variableRanges);
69
71
  }
72
+ getTestLetVariableRanges() {
73
+ return new Map(this.testLetVariableRanges);
74
+ }
70
75
  report(message, start, end, severity) {
71
76
  this.diagnostics.push({ message, start, end, severity });
72
77
  }
@@ -1053,25 +1058,38 @@ var Parser = class {
1053
1058
  parseLetBinding() {
1054
1059
  this.expect("let");
1055
1060
  this.skipInlineSpaces();
1061
+ const nameStart = this.pos;
1056
1062
  const name = this.parseIdentifier();
1063
+ const nameEnd = this.pos;
1064
+ this.testLetVariableRanges.set(name, { start: nameStart, end: nameEnd });
1057
1065
  this.skipInlineSpaces();
1058
1066
  this.expect("=");
1059
1067
  this.skipInlineSpaces();
1068
+ let format;
1060
1069
  const value = (() => {
1061
1070
  const bt = this.tryParse(() => this.parseBacktickString());
1062
- if (bt !== null) return bt;
1071
+ if (bt !== null) {
1072
+ format = "backtick";
1073
+ return bt;
1074
+ }
1063
1075
  const qt = this.tryParse(() => this.parseQuotedString());
1064
- if (qt !== null) return qt;
1076
+ if (qt !== null) {
1077
+ format = "quoted";
1078
+ return qt;
1079
+ }
1065
1080
  if (this.text.startsWith("null", this.pos)) {
1066
1081
  this.pos += 4;
1082
+ format = "bare";
1067
1083
  return "null";
1068
1084
  }
1069
1085
  if (this.text.startsWith("true", this.pos)) {
1070
1086
  this.pos += 4;
1087
+ format = "bare";
1071
1088
  return "true";
1072
1089
  }
1073
1090
  if (this.text.startsWith("false", this.pos)) {
1074
1091
  this.pos += 5;
1092
+ format = "bare";
1075
1093
  return "false";
1076
1094
  }
1077
1095
  const num = this.tryParse(() => {
@@ -1085,10 +1103,13 @@ var Parser = class {
1085
1103
  }
1086
1104
  return digits;
1087
1105
  });
1088
- if (num !== null) return num;
1106
+ if (num !== null) {
1107
+ format = "bare";
1108
+ return num;
1109
+ }
1089
1110
  throw new Error("let value");
1090
1111
  })();
1091
- return [name, value];
1112
+ return [name, value, format];
1092
1113
  }
1093
1114
  parseIt() {
1094
1115
  this.skipSpaces();
@@ -1256,6 +1277,11 @@ function getVariableRanges(text) {
1256
1277
  parser.parseProgram();
1257
1278
  return parser.getVariableRanges();
1258
1279
  }
1280
+ function getTestLetVariableRanges(text) {
1281
+ const parser = new Parser(text);
1282
+ parser.parseProgram();
1283
+ return parser.getTestLetVariableRanges();
1284
+ }
1259
1285
  var ParseFailure = class extends Error {
1260
1286
  constructor(message, at) {
1261
1287
  super(message);
@@ -1377,13 +1403,8 @@ function printTest(test) {
1377
1403
  });
1378
1404
  lines.push(` when ${formatWhen(test.when)}`);
1379
1405
  if (test.variables) {
1380
- test.variables.forEach(([name, value]) => {
1381
- const formattedValue = (() => {
1382
- if (value.startsWith("`") || value.startsWith('"')) return value;
1383
- if (value === "true" || value === "false" || /^\d+$/.test(value)) return value;
1384
- if (value.includes("{") || value.includes("[") || value.includes("\n")) return `\`${value}\``;
1385
- return `"${value}"`;
1386
- })();
1406
+ test.variables.forEach(([name, value, format]) => {
1407
+ const formattedValue = format === "quoted" ? `"${value}"` : format === "backtick" ? `\`${value}\`` : value;
1387
1408
  lines.push(` let ${name} = ${formattedValue}`);
1388
1409
  });
1389
1410
  }
@@ -1421,6 +1442,13 @@ function printDescribe(describe) {
1421
1442
  } else {
1422
1443
  lines.push(describeLine);
1423
1444
  }
1445
+ if (describe.variables && describe.variables.length > 0) {
1446
+ describe.variables.forEach(([name, value, format]) => {
1447
+ const formattedValue = format === "quoted" ? `"${value}"` : format === "backtick" ? `\`${value}\`` : value;
1448
+ lines.push(` let ${name} = ${formattedValue}`);
1449
+ });
1450
+ lines.push("");
1451
+ }
1424
1452
  describe.mocks.forEach((mock) => {
1425
1453
  lines.push(printMock(mock));
1426
1454
  });
@@ -1642,6 +1670,7 @@ function formatWhen(when) {
1642
1670
  formatTags,
1643
1671
  formatWhen,
1644
1672
  getPipelineRanges,
1673
+ getTestLetVariableRanges,
1645
1674
  getVariableRanges,
1646
1675
  parseProgram,
1647
1676
  parseProgramWithDiagnostics,
package/dist/index.d.cts CHANGED
@@ -88,6 +88,7 @@ interface Pipeline {
88
88
  steps: PipelineStep[];
89
89
  }
90
90
  type ConfigType = 'backtick' | 'quoted' | 'identifier';
91
+ type LetValueFormat = 'quoted' | 'backtick' | 'bare';
91
92
  interface Tag {
92
93
  name: string;
93
94
  negated: boolean;
@@ -149,7 +150,7 @@ type ResultBranchType = {
149
150
  };
150
151
  interface Describe {
151
152
  name: string;
152
- variables: Array<[string, string]>;
153
+ variables: Array<[string, string, LetValueFormat]>;
153
154
  mocks: Mock[];
154
155
  tests: It[];
155
156
  lineNumber?: number;
@@ -163,7 +164,7 @@ interface It {
163
164
  name: string;
164
165
  mocks: Mock[];
165
166
  when: When;
166
- variables?: Array<[string, string]>;
167
+ variables?: Array<[string, string, LetValueFormat]>;
167
168
  input?: string;
168
169
  body?: string;
169
170
  headers?: string;
@@ -224,6 +225,10 @@ declare function getVariableRanges(text: string): Map<string, {
224
225
  start: number;
225
226
  end: number;
226
227
  }>;
228
+ declare function getTestLetVariableRanges(text: string): Map<string, {
229
+ start: number;
230
+ end: number;
231
+ }>;
227
232
  declare function printRoute(route: Route): string;
228
233
  declare function printConfig(config: Config): string;
229
234
  declare function printPipeline(pipeline: NamedPipeline): string;
@@ -246,4 +251,4 @@ declare function formatTagExpr(expr: TagExpr): string;
246
251
  declare function formatPipelineRef(ref: PipelineRef): string[];
247
252
  declare function formatWhen(when: When): string;
248
253
 
249
- export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type It, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printVariable };
254
+ export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type It, type LetValueFormat, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printVariable };
package/dist/index.d.ts CHANGED
@@ -88,6 +88,7 @@ interface Pipeline {
88
88
  steps: PipelineStep[];
89
89
  }
90
90
  type ConfigType = 'backtick' | 'quoted' | 'identifier';
91
+ type LetValueFormat = 'quoted' | 'backtick' | 'bare';
91
92
  interface Tag {
92
93
  name: string;
93
94
  negated: boolean;
@@ -149,7 +150,7 @@ type ResultBranchType = {
149
150
  };
150
151
  interface Describe {
151
152
  name: string;
152
- variables: Array<[string, string]>;
153
+ variables: Array<[string, string, LetValueFormat]>;
153
154
  mocks: Mock[];
154
155
  tests: It[];
155
156
  lineNumber?: number;
@@ -163,7 +164,7 @@ interface It {
163
164
  name: string;
164
165
  mocks: Mock[];
165
166
  when: When;
166
- variables?: Array<[string, string]>;
167
+ variables?: Array<[string, string, LetValueFormat]>;
167
168
  input?: string;
168
169
  body?: string;
169
170
  headers?: string;
@@ -224,6 +225,10 @@ declare function getVariableRanges(text: string): Map<string, {
224
225
  start: number;
225
226
  end: number;
226
227
  }>;
228
+ declare function getTestLetVariableRanges(text: string): Map<string, {
229
+ start: number;
230
+ end: number;
231
+ }>;
227
232
  declare function printRoute(route: Route): string;
228
233
  declare function printConfig(config: Config): string;
229
234
  declare function printPipeline(pipeline: NamedPipeline): string;
@@ -246,4 +251,4 @@ declare function formatTagExpr(expr: TagExpr): string;
246
251
  declare function formatPipelineRef(ref: PipelineRef): string[];
247
252
  declare function formatWhen(when: When): string;
248
253
 
249
- export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type It, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printVariable };
254
+ export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type It, type LetValueFormat, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printVariable };
package/dist/index.mjs CHANGED
@@ -5,6 +5,7 @@ var Parser = class {
5
5
  this.diagnostics = [];
6
6
  this.pipelineRanges = /* @__PURE__ */ new Map();
7
7
  this.variableRanges = /* @__PURE__ */ new Map();
8
+ this.testLetVariableRanges = /* @__PURE__ */ new Map();
8
9
  this.text = text;
9
10
  this.len = text.length;
10
11
  }
@@ -17,6 +18,9 @@ var Parser = class {
17
18
  getVariableRanges() {
18
19
  return new Map(this.variableRanges);
19
20
  }
21
+ getTestLetVariableRanges() {
22
+ return new Map(this.testLetVariableRanges);
23
+ }
20
24
  report(message, start, end, severity) {
21
25
  this.diagnostics.push({ message, start, end, severity });
22
26
  }
@@ -1003,25 +1007,38 @@ var Parser = class {
1003
1007
  parseLetBinding() {
1004
1008
  this.expect("let");
1005
1009
  this.skipInlineSpaces();
1010
+ const nameStart = this.pos;
1006
1011
  const name = this.parseIdentifier();
1012
+ const nameEnd = this.pos;
1013
+ this.testLetVariableRanges.set(name, { start: nameStart, end: nameEnd });
1007
1014
  this.skipInlineSpaces();
1008
1015
  this.expect("=");
1009
1016
  this.skipInlineSpaces();
1017
+ let format;
1010
1018
  const value = (() => {
1011
1019
  const bt = this.tryParse(() => this.parseBacktickString());
1012
- if (bt !== null) return bt;
1020
+ if (bt !== null) {
1021
+ format = "backtick";
1022
+ return bt;
1023
+ }
1013
1024
  const qt = this.tryParse(() => this.parseQuotedString());
1014
- if (qt !== null) return qt;
1025
+ if (qt !== null) {
1026
+ format = "quoted";
1027
+ return qt;
1028
+ }
1015
1029
  if (this.text.startsWith("null", this.pos)) {
1016
1030
  this.pos += 4;
1031
+ format = "bare";
1017
1032
  return "null";
1018
1033
  }
1019
1034
  if (this.text.startsWith("true", this.pos)) {
1020
1035
  this.pos += 4;
1036
+ format = "bare";
1021
1037
  return "true";
1022
1038
  }
1023
1039
  if (this.text.startsWith("false", this.pos)) {
1024
1040
  this.pos += 5;
1041
+ format = "bare";
1025
1042
  return "false";
1026
1043
  }
1027
1044
  const num = this.tryParse(() => {
@@ -1035,10 +1052,13 @@ var Parser = class {
1035
1052
  }
1036
1053
  return digits;
1037
1054
  });
1038
- if (num !== null) return num;
1055
+ if (num !== null) {
1056
+ format = "bare";
1057
+ return num;
1058
+ }
1039
1059
  throw new Error("let value");
1040
1060
  })();
1041
- return [name, value];
1061
+ return [name, value, format];
1042
1062
  }
1043
1063
  parseIt() {
1044
1064
  this.skipSpaces();
@@ -1206,6 +1226,11 @@ function getVariableRanges(text) {
1206
1226
  parser.parseProgram();
1207
1227
  return parser.getVariableRanges();
1208
1228
  }
1229
+ function getTestLetVariableRanges(text) {
1230
+ const parser = new Parser(text);
1231
+ parser.parseProgram();
1232
+ return parser.getTestLetVariableRanges();
1233
+ }
1209
1234
  var ParseFailure = class extends Error {
1210
1235
  constructor(message, at) {
1211
1236
  super(message);
@@ -1327,13 +1352,8 @@ function printTest(test) {
1327
1352
  });
1328
1353
  lines.push(` when ${formatWhen(test.when)}`);
1329
1354
  if (test.variables) {
1330
- test.variables.forEach(([name, value]) => {
1331
- const formattedValue = (() => {
1332
- if (value.startsWith("`") || value.startsWith('"')) return value;
1333
- if (value === "true" || value === "false" || /^\d+$/.test(value)) return value;
1334
- if (value.includes("{") || value.includes("[") || value.includes("\n")) return `\`${value}\``;
1335
- return `"${value}"`;
1336
- })();
1355
+ test.variables.forEach(([name, value, format]) => {
1356
+ const formattedValue = format === "quoted" ? `"${value}"` : format === "backtick" ? `\`${value}\`` : value;
1337
1357
  lines.push(` let ${name} = ${formattedValue}`);
1338
1358
  });
1339
1359
  }
@@ -1371,6 +1391,13 @@ function printDescribe(describe) {
1371
1391
  } else {
1372
1392
  lines.push(describeLine);
1373
1393
  }
1394
+ if (describe.variables && describe.variables.length > 0) {
1395
+ describe.variables.forEach(([name, value, format]) => {
1396
+ const formattedValue = format === "quoted" ? `"${value}"` : format === "backtick" ? `\`${value}\`` : value;
1397
+ lines.push(` let ${name} = ${formattedValue}`);
1398
+ });
1399
+ lines.push("");
1400
+ }
1374
1401
  describe.mocks.forEach((mock) => {
1375
1402
  lines.push(printMock(mock));
1376
1403
  });
@@ -1591,6 +1618,7 @@ export {
1591
1618
  formatTags,
1592
1619
  formatWhen,
1593
1620
  getPipelineRanges,
1621
+ getTestLetVariableRanges,
1594
1622
  getVariableRanges,
1595
1623
  parseProgram,
1596
1624
  parseProgramWithDiagnostics,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.26",
3
+ "version": "2.0.28",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",