@immense/vue-pom-generator 1.0.90 → 1.0.91

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
@@ -4670,6 +4670,251 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
4670
4670
  }
4671
4671
  });
4672
4672
  }
4673
+ function writeNavigationValue(writer, input, name) {
4674
+ writer.write(input.identifier);
4675
+ if (input.optional) {
4676
+ writer.write("?.");
4677
+ }
4678
+ writer.write(`[${JSON.stringify(name)}]`);
4679
+ }
4680
+ function writeFilteredNavigationRecord(writer, variableName, input, names) {
4681
+ writer.write(`const ${variableName} = `);
4682
+ if (!input || names.length === 0) {
4683
+ writer.write("{};").newLine();
4684
+ return;
4685
+ }
4686
+ writer.write("Object.fromEntries([");
4687
+ names.forEach((name, index) => {
4688
+ if (index > 0) {
4689
+ writer.write(", ");
4690
+ }
4691
+ writer.write(`[${JSON.stringify(name)}, `);
4692
+ writeNavigationValue(writer, input, name);
4693
+ writer.write("]");
4694
+ });
4695
+ writer.write("].filter(([, value]) => value !== undefined));").newLine();
4696
+ }
4697
+ function writeUnpartitionedRouteParams(writer, input) {
4698
+ writer.write("const routeParams = ");
4699
+ if (!input) {
4700
+ writer.write("{};").newLine();
4701
+ return;
4702
+ }
4703
+ writer.write("Object.fromEntries(Object.entries(");
4704
+ writer.write(input.identifier);
4705
+ if (input.optional) {
4706
+ writer.write(" ?? {}");
4707
+ }
4708
+ writer.write(").filter(([, v]) => v !== undefined));").newLine();
4709
+ }
4710
+ function writeRouterTargetType(writer, includeQuery) {
4711
+ writer.write("{ name: string; params: Record<string, unknown>");
4712
+ if (includeQuery) {
4713
+ writer.write("; query: Record<string, unknown>");
4714
+ }
4715
+ writer.write(" }");
4716
+ }
4717
+ function writeRouterType(writer, includeQuery) {
4718
+ writer.write(`{ ${router.POM_ROUTER_GLOBAL_NAME}?: { push: (to: `);
4719
+ writeRouterTargetType(writer, includeQuery);
4720
+ writer.write(") => Promise<unknown>; resolve: (to: ");
4721
+ writeRouterTargetType(writer, includeQuery);
4722
+ writer.write(") => { href: string } } }");
4723
+ }
4724
+ function writeRouterBinding(writer, includeQuery) {
4725
+ writer.write("{ name, params");
4726
+ if (includeQuery) {
4727
+ writer.write(", query");
4728
+ }
4729
+ writer.write(" }");
4730
+ }
4731
+ function writeRouterTarget(writer, writeName, includeQuery, paramsExpression, queryExpression) {
4732
+ writer.write("{ name: ");
4733
+ writeName(writer);
4734
+ writer.write(`, params: ${paramsExpression}`);
4735
+ if (includeQuery) {
4736
+ writer.write(`, query: ${queryExpression}`);
4737
+ }
4738
+ writer.write(" }");
4739
+ }
4740
+ function requireNavigationInput(input, context) {
4741
+ if (!input) {
4742
+ throw new Error(`${context} requires a navigation input.`);
4743
+ }
4744
+ return input;
4745
+ }
4746
+ function writeParametrizedRouteSelector(writer, input, pathParamNames) {
4747
+ writer.write(`const useParametrizedRoute = ${input.identifier} !== undefined && [`);
4748
+ pathParamNames.forEach((name, index) => {
4749
+ if (index > 0) {
4750
+ writer.write(", ");
4751
+ }
4752
+ writer.write(JSON.stringify(name));
4753
+ });
4754
+ writer.write(`].some(key => Object.prototype.hasOwnProperty.call(${input.identifier}, key));`).newLine();
4755
+ }
4756
+ function writeSelectionPrelude(writer, selection, input, pathParamNames) {
4757
+ if (selection.kind === "dual" && selection.selectBy === "path-param-presence") {
4758
+ writeParametrizedRouteSelector(
4759
+ writer,
4760
+ requireNavigationInput(input, "Path-param route selection"),
4761
+ pathParamNames
4762
+ );
4763
+ }
4764
+ }
4765
+ function writeSelectedTarget(writer, selection, input) {
4766
+ if (selection.kind === "single") {
4767
+ writer.write(JSON.stringify(selection.target));
4768
+ return;
4769
+ }
4770
+ if (selection.selectBy === "path-param-presence") {
4771
+ writer.write("useParametrizedRoute");
4772
+ } else {
4773
+ writer.write(requireNavigationInput(input, "Input-presence route selection").identifier);
4774
+ }
4775
+ writer.write(` ? ${JSON.stringify(selection.parametrizedTarget)} : ${JSON.stringify(selection.paramlessTarget)}`);
4776
+ }
4777
+ function createRouterNavigationWriter(options) {
4778
+ return (writer) => {
4779
+ writeSelectionPrelude(writer, options.routeName, options.input, options.pathParamNames);
4780
+ const writeRouteName = (nameWriter) => writeSelectedTarget(nameWriter, options.routeName, options.input);
4781
+ const includeQuery = options.queryNames.length > 0;
4782
+ if (includeQuery) {
4783
+ writeFilteredNavigationRecord(writer, "routeParams", options.input, options.pathParamNames);
4784
+ writeFilteredNavigationRecord(writer, "routeQuery", options.input, options.queryNames);
4785
+ } else {
4786
+ writeUnpartitionedRouteParams(writer, options.input);
4787
+ }
4788
+ writer.writeLine(
4789
+ `const isCold = await this.page.evaluate(() => typeof (globalThis as { ${router.POM_ROUTER_GLOBAL_NAME}?: unknown }).${router.POM_ROUTER_GLOBAL_NAME} === "undefined");`
4790
+ );
4791
+ writer.writeLine("if (isCold) {");
4792
+ writer.indent(() => {
4793
+ writer.writeLine('await this.page.goto("/", { waitUntil: "commit" });');
4794
+ writer.writeLine(
4795
+ `await this.page.waitForFunction(() => typeof (globalThis as { ${router.POM_ROUTER_GLOBAL_NAME}?: unknown }).${router.POM_ROUTER_GLOBAL_NAME} !== "undefined", { timeout: 15000 });`
4796
+ );
4797
+ writer.write("const href = await this.page.evaluate((");
4798
+ writeRouterBinding(writer, includeQuery);
4799
+ writer.write(") => (globalThis as ");
4800
+ writeRouterType(writer, includeQuery);
4801
+ writer.write(`).${router.POM_ROUTER_GLOBAL_NAME}?.resolve(`);
4802
+ writeRouterBinding(writer, includeQuery);
4803
+ writer.write(")?.href, ");
4804
+ writeRouterTarget(writer, writeRouteName, includeQuery, "routeParams", "routeQuery");
4805
+ writer.write(");").newLine();
4806
+ writer.writeLine("if (href) {");
4807
+ writer.indent(() => {
4808
+ writer.writeLine('await this.page.goto(href, { waitUntil: "domcontentloaded" });');
4809
+ });
4810
+ writer.writeLine("}");
4811
+ });
4812
+ writer.writeLine("} else {");
4813
+ writer.indent(() => {
4814
+ writer.write("await this.page.evaluate(async (");
4815
+ writeRouterBinding(writer, includeQuery);
4816
+ writer.write(") => {").newLine();
4817
+ writer.indent(() => {
4818
+ writer.write("await (globalThis as ");
4819
+ writeRouterType(writer, includeQuery);
4820
+ writer.write(`).${router.POM_ROUTER_GLOBAL_NAME}?.push(`);
4821
+ writeRouterBinding(writer, includeQuery);
4822
+ writer.write(");").newLine();
4823
+ });
4824
+ writer.write("}, ");
4825
+ writeRouterTarget(writer, writeRouteName, includeQuery, "routeParams", "routeQuery");
4826
+ writer.write(");").newLine();
4827
+ });
4828
+ writer.writeLine("}");
4829
+ };
4830
+ }
4831
+ function writePathParamAssignments(writer, input, pathParams) {
4832
+ for (const param of pathParams) {
4833
+ const token = getParamToken(param.name);
4834
+ if (param.optional) {
4835
+ writer.write("targetUrl = ");
4836
+ writeNavigationValue(writer, input, param.name);
4837
+ writer.write(` === undefined ? targetUrl.replaceAll(${JSON.stringify(`/${token}`)}, "") : targetUrl.replaceAll(${JSON.stringify(token)}, String(`);
4838
+ writeNavigationValue(writer, input, param.name);
4839
+ writer.write("));").newLine();
4840
+ } else {
4841
+ writer.write(`targetUrl = targetUrl.replaceAll(${JSON.stringify(token)}, String(`);
4842
+ writeNavigationValue(writer, input, param.name);
4843
+ writer.write("));").newLine();
4844
+ }
4845
+ }
4846
+ }
4847
+ function writeQueryString(writer, input, queryNames) {
4848
+ if (queryNames.length === 0) {
4849
+ return;
4850
+ }
4851
+ writer.writeLine("const routeQuery = new URLSearchParams();");
4852
+ for (const queryName of queryNames) {
4853
+ writer.write("if (");
4854
+ writeNavigationValue(writer, input, queryName);
4855
+ writer.write(" !== undefined) {").newLine();
4856
+ writer.indent(() => {
4857
+ writer.write(`routeQuery.set(${JSON.stringify(queryName)}, String(`);
4858
+ writeNavigationValue(writer, input, queryName);
4859
+ writer.write("));").newLine();
4860
+ });
4861
+ writer.writeLine("}");
4862
+ }
4863
+ writer.writeLine("const routeQueryString = routeQuery.toString();");
4864
+ writer.writeLine("if (routeQueryString) {");
4865
+ writer.indent(() => {
4866
+ writer.writeLine("targetUrl += `?${routeQueryString}`;");
4867
+ });
4868
+ writer.writeLine("}");
4869
+ }
4870
+ function writeRuntimeUrlNavigation(writer) {
4871
+ writer.writeLine(
4872
+ "const runtimeEnv = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env;"
4873
+ );
4874
+ writer.writeLine(
4875
+ "const runtimeBaseUrl = runtimeEnv?.PLAYWRIGHT_RUNTIME_BASE_URL ?? runtimeEnv?.PLAYWRIGHT_TEST_BASE_URL ?? runtimeEnv?.VITE_PLAYWRIGHT_BASE_URL;"
4876
+ );
4877
+ writer.writeLine("const resolvedUrl = runtimeBaseUrl ? new URL(targetUrl, runtimeBaseUrl).toString() : targetUrl;");
4878
+ writer.writeLine("await this.page.goto(resolvedUrl);");
4879
+ }
4880
+ function createUrlNavigationWriter(options) {
4881
+ return (writer) => {
4882
+ writeSelectionPrelude(writer, options.routeTemplate, options.input, options.pathParams.map((param) => param.name));
4883
+ if (options.routeTemplate.kind === "single") {
4884
+ writer.write(`let targetUrl = ${JSON.stringify(options.routeTemplate.target)};`).newLine();
4885
+ } else {
4886
+ writer.write("const template = ");
4887
+ writeSelectedTarget(writer, options.routeTemplate, options.input);
4888
+ writer.write(";").newLine();
4889
+ writer.writeLine("let targetUrl = template;");
4890
+ }
4891
+ if (options.pathParams.length > 0) {
4892
+ const input = requireNavigationInput(options.input, "URL navigation with path params");
4893
+ if (options.routeTemplate.kind === "dual") {
4894
+ writer.write("if (");
4895
+ writer.write(input.identifier);
4896
+ if (options.routeTemplate.selectBy === "path-param-presence") {
4897
+ writer.write(" && useParametrizedRoute");
4898
+ }
4899
+ writer.write(") {").newLine();
4900
+ writer.indent(() => {
4901
+ writePathParamAssignments(writer, input, options.pathParams);
4902
+ });
4903
+ writer.writeLine("}");
4904
+ } else {
4905
+ writePathParamAssignments(writer, input, options.pathParams);
4906
+ }
4907
+ }
4908
+ if (options.queryNames.length > 0) {
4909
+ writeQueryString(
4910
+ writer,
4911
+ requireNavigationInput(options.input, "URL navigation with query params"),
4912
+ options.queryNames
4913
+ );
4914
+ }
4915
+ writeRuntimeUrlNavigation(writer);
4916
+ };
4917
+ }
4673
4918
  const GENERATED_GITATTRIBUTES_BLOCK_START = "# BEGIN vue-pom-generator generated files";
4674
4919
  const GENERATED_GITATTRIBUTES_BLOCK_END = "# END vue-pom-generator generated files";
4675
4920
  const VUE_POM_GENERATOR_ERROR_PREFIX = "[vue-pom-generator]";
@@ -4800,7 +5045,7 @@ async function getRouteMetaByComponent(projectRoot, routerEntry, routerType, opt
4800
5045
  const map = /* @__PURE__ */ new Map();
4801
5046
  for (const entry of routeMetaEntries) {
4802
5047
  const list = map.get(entry.componentName) ?? [];
4803
- list.push({ name: entry.name, template: entry.pathTemplate, params: entry.params });
5048
+ list.push({ name: entry.name, template: entry.pathTemplate, params: entry.params, query: entry.query });
4804
5049
  map.set(entry.componentName, list);
4805
5050
  }
4806
5051
  const dedupeRoutes = (entries) => {
@@ -4839,8 +5084,37 @@ function generateRouteProperty(routeMeta) {
4839
5084
  })
4840
5085
  ];
4841
5086
  }
4842
- function buildParamTypeString(params) {
4843
- return `{ ${params.map((p) => `${p.name}${p.optional ? "?" : ""}: string | number`).join("; ")} }`;
5087
+ function formatNavigationFieldName(name) {
5088
+ return /^[$a-z_][$\w]*$/i.test(name) ? name : JSON.stringify(name);
5089
+ }
5090
+ function buildNavigationTypeString(route, requiredOptionalParamName) {
5091
+ const pathFields = route.params.map((param) => {
5092
+ const forcePresent = param.optional && param.name === requiredOptionalParamName;
5093
+ return `${formatNavigationFieldName(param.name)}${param.optional && !forcePresent ? "?" : ""}: string | number${forcePresent ? " | undefined" : ""}`;
5094
+ });
5095
+ const pathNames = new Set(route.params.map((param) => param.name));
5096
+ const queryFields = route.query.filter((query) => !pathNames.has(query)).map((query) => `${formatNavigationFieldName(query)}?: string | number`);
5097
+ return `{ ${[...pathFields, ...queryFields].join("; ")} }`;
5098
+ }
5099
+ function buildParametrizedRouteSelectionTypeString(route) {
5100
+ if (route.params.some((param) => !param.optional)) {
5101
+ return buildNavigationTypeString(route);
5102
+ }
5103
+ return route.params.map((param) => buildNavigationTypeString(route, param.name)).join(" | ");
5104
+ }
5105
+ function buildImplementationNavigationTypeString(routes) {
5106
+ const fields = /* @__PURE__ */ new Map();
5107
+ for (const route of routes) {
5108
+ for (const param of route.params) {
5109
+ fields.set(param.name, true);
5110
+ }
5111
+ for (const query of route.query) {
5112
+ if (!fields.has(query)) {
5113
+ fields.set(query, true);
5114
+ }
5115
+ }
5116
+ }
5117
+ return `{ ${Array.from(fields.keys()).map((name) => `${formatNavigationFieldName(name)}?: string | number`).join("; ")} }`;
4844
5118
  }
4845
5119
  function chooseParamlessRoute(routes) {
4846
5120
  const paramless = routes.filter((r) => r.params.length === 0);
@@ -4854,31 +5128,12 @@ function chooseParametrizedRoute(routes) {
4854
5128
  return null;
4855
5129
  return parametrized.slice().sort((a, b) => a.params.length - b.params.length || a.template.length - b.template.length || a.template.localeCompare(b.template))[0];
4856
5130
  }
4857
- const GOTO_RUNTIME_LINES = [
4858
- "const runtimeEnv = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env;",
4859
- "const runtimeBaseUrl = runtimeEnv?.PLAYWRIGHT_RUNTIME_BASE_URL ?? runtimeEnv?.PLAYWRIGHT_TEST_BASE_URL ?? runtimeEnv?.VITE_PLAYWRIGHT_BASE_URL;",
4860
- "const resolvedUrl = runtimeBaseUrl ? new URL(targetUrl, runtimeBaseUrl).toString() : targetUrl;",
4861
- "await this.page.goto(resolvedUrl);"
4862
- ];
4863
- const ROUTER_GLOBAL_NAME = router.POM_ROUTER_GLOBAL_NAME;
4864
- const pushBlock = (routeNameExpr, paramsExpr, nullable) => {
4865
- const routerType = `{ ${ROUTER_GLOBAL_NAME}?: { push: (to: { name: string; params: Record<string, unknown> }) => Promise<unknown>; resolve: (to: { name: string; params: Record<string, unknown> }) => { href: string } } }`;
4866
- const routeParamsLine = paramsExpr === "undefined" ? "const routeParams = {};" : nullable ? `const routeParams = Object.fromEntries(Object.entries(${paramsExpr} ?? {}).filter(([, v]) => v !== undefined));` : `const routeParams = Object.fromEntries(Object.entries(${paramsExpr}).filter(([, v]) => v !== undefined));`;
4867
- return [
4868
- routeParamsLine,
4869
- `const isCold = await this.page.evaluate(() => typeof (globalThis as { ${ROUTER_GLOBAL_NAME}?: unknown }).${ROUTER_GLOBAL_NAME} === "undefined");`,
4870
- `if (isCold) {`,
4871
- ` await this.page.goto("/", { waitUntil: "commit" });`,
4872
- ` await this.page.waitForFunction(() => typeof (globalThis as { ${ROUTER_GLOBAL_NAME}?: unknown }).${ROUTER_GLOBAL_NAME} !== "undefined", { timeout: 15000 });`,
4873
- ` const href = await this.page.evaluate(({ name, params }) => (globalThis as ${routerType}).${ROUTER_GLOBAL_NAME}?.resolve({ name, params })?.href, { name: ${routeNameExpr}, params: routeParams });`,
4874
- ` if (href) { await this.page.goto(href, { waitUntil: "domcontentloaded" }); }`,
4875
- `} else {`,
4876
- ` await this.page.evaluate(async ({ name, params }) => {`,
4877
- ` await (globalThis as ${routerType}).${ROUTER_GLOBAL_NAME}?.push({ name, params });`,
4878
- ` }, { name: ${routeNameExpr}, params: routeParams });`,
4879
- `}`
4880
- ];
4881
- };
5131
+ function requireRouteName(route) {
5132
+ if (route.name === null) {
5133
+ throw new VuePomGeneratorError(`Named navigation requires a route name for template "${route.template}".`);
5134
+ }
5135
+ return route.name;
5136
+ }
4882
5137
  function generateGoToMethod(componentName, routeMeta) {
4883
5138
  if (!routeMeta) {
4884
5139
  return [
@@ -4906,29 +5161,30 @@ function generateGoToMethod(componentName, routeMeta) {
4906
5161
  })
4907
5162
  ];
4908
5163
  }
4909
- const paramStatements = (entry) => {
4910
- const lines = [];
4911
- for (const param of entry.params) {
4912
- const token = getParamToken(param.name);
4913
- if (param.optional) {
4914
- lines.push(`targetUrl = params.${param.name} === undefined ? targetUrl.replaceAll(${JSON.stringify(`/${token}`)}, "") : targetUrl.replaceAll(${JSON.stringify(token)}, String(params.${param.name}));`);
4915
- } else {
4916
- lines.push(`targetUrl = targetUrl.replaceAll(${JSON.stringify(token)}, String(params.${param.name}));`);
4917
- }
4918
- }
4919
- return lines;
4920
- };
4921
5164
  if (hasParamless && !hasParametrized) {
4922
5165
  const route = paramless;
5166
+ const hasQuery2 = route.query.length > 0;
5167
+ const paramType2 = buildNavigationTypeString(route);
4923
5168
  return [
4924
5169
  createClassMethod({
4925
5170
  name: "goTo",
4926
5171
  isAsync: true,
4927
- statements: route.name !== null ? pushBlock(JSON.stringify(route.name), "undefined", false) : [`const targetUrl = ${JSON.stringify(route.template)};`, ...GOTO_RUNTIME_LINES]
5172
+ parameters: hasQuery2 ? [{ name: "params", type: paramType2, hasQuestionToken: true }] : [],
5173
+ statements: route.name !== null ? createRouterNavigationWriter({
5174
+ routeName: { kind: "single", target: route.name },
5175
+ input: hasQuery2 ? { identifier: "params", optional: true } : void 0,
5176
+ pathParamNames: [],
5177
+ queryNames: route.query
5178
+ }) : createUrlNavigationWriter({
5179
+ routeTemplate: { kind: "single", target: route.template },
5180
+ input: hasQuery2 ? { identifier: "params", optional: true } : void 0,
5181
+ pathParams: [],
5182
+ queryNames: route.query
5183
+ })
4928
5184
  })
4929
5185
  ];
4930
5186
  }
4931
- const paramType = buildParamTypeString(parametrized.params);
5187
+ const paramType = buildNavigationTypeString(parametrized);
4932
5188
  if (hasParametrized && !hasParamless) {
4933
5189
  const route = parametrized;
4934
5190
  const allOptional = route.params.every((p) => p.optional);
@@ -4937,34 +5193,61 @@ function generateGoToMethod(componentName, routeMeta) {
4937
5193
  name: "goTo",
4938
5194
  isAsync: true,
4939
5195
  parameters: [{ name: "params", type: paramType, hasQuestionToken: allOptional }],
4940
- statements: route.name !== null ? pushBlock(JSON.stringify(route.name), "params", allOptional) : [`let targetUrl = ${JSON.stringify(route.template)};`, ...paramStatements(route), ...GOTO_RUNTIME_LINES]
5196
+ statements: route.name !== null ? createRouterNavigationWriter({
5197
+ routeName: { kind: "single", target: route.name },
5198
+ input: { identifier: "params", optional: allOptional },
5199
+ pathParamNames: route.params.map((param) => param.name),
5200
+ queryNames: route.query
5201
+ }) : createUrlNavigationWriter({
5202
+ routeTemplate: { kind: "single", target: route.template },
5203
+ input: { identifier: "params", optional: allOptional },
5204
+ pathParams: route.params,
5205
+ queryNames: route.query
5206
+ })
4941
5207
  })
4942
5208
  ];
4943
5209
  }
4944
5210
  const paramlessRoute = paramless;
4945
5211
  const parametrizedRoute = parametrized;
4946
5212
  const usePush = paramlessRoute.name !== null && parametrizedRoute.name !== null;
5213
+ const paramlessType = buildNavigationTypeString(paramlessRoute);
5214
+ const parametrizedOverloadType = buildParametrizedRouteSelectionTypeString(parametrizedRoute);
5215
+ const queryNames = Array.from(/* @__PURE__ */ new Set([...paramlessRoute.query, ...parametrizedRoute.query]));
5216
+ const hasQuery = queryNames.length > 0;
5217
+ const implementationType = hasQuery ? buildImplementationNavigationTypeString([paramlessRoute, parametrizedRoute]) : paramType;
4947
5218
  return [
4948
5219
  createClassMethod({
4949
5220
  name: "goTo",
4950
5221
  isAsync: true,
4951
5222
  overloads: [
4952
- { parameters: [], returnType: "Promise<void>" },
4953
- { parameters: [{ name: "params", type: paramType }], returnType: "Promise<void>" }
5223
+ {
5224
+ parameters: paramlessRoute.query.length ? [{ name: "params", type: paramlessType, hasQuestionToken: true }] : [],
5225
+ returnType: "Promise<void>"
5226
+ },
5227
+ { parameters: [{ name: "params", type: parametrizedOverloadType }], returnType: "Promise<void>" }
4954
5228
  ],
4955
- parameters: [{ name: "params", type: paramType, hasQuestionToken: true }],
4956
- statements: usePush ? pushBlock(
4957
- `params ? ${JSON.stringify(parametrizedRoute.name)} : ${JSON.stringify(paramlessRoute.name)}`,
4958
- "params",
4959
- true
4960
- ) : [
4961
- `const template = params ? ${JSON.stringify(parametrizedRoute.template)} : ${JSON.stringify(paramlessRoute.template)};`,
4962
- "let targetUrl = template;",
4963
- `if (params) {`,
4964
- ...paramStatements(parametrizedRoute).map((line) => ` ${line}`),
4965
- "}",
4966
- ...GOTO_RUNTIME_LINES
4967
- ]
5229
+ parameters: [{ name: "params", type: implementationType, hasQuestionToken: true }],
5230
+ statements: usePush ? createRouterNavigationWriter({
5231
+ routeName: {
5232
+ kind: "dual",
5233
+ parametrizedTarget: requireRouteName(parametrizedRoute),
5234
+ paramlessTarget: requireRouteName(paramlessRoute),
5235
+ selectBy: hasQuery ? "path-param-presence" : "input-presence"
5236
+ },
5237
+ input: { identifier: "params", optional: true },
5238
+ pathParamNames: parametrizedRoute.params.map((param) => param.name),
5239
+ queryNames: hasQuery ? queryNames : []
5240
+ }) : createUrlNavigationWriter({
5241
+ routeTemplate: {
5242
+ kind: "dual",
5243
+ parametrizedTarget: parametrizedRoute.template,
5244
+ paramlessTarget: paramlessRoute.template,
5245
+ selectBy: hasQuery ? "path-param-presence" : "input-presence"
5246
+ },
5247
+ input: { identifier: "params", optional: true },
5248
+ pathParams: parametrizedRoute.params,
5249
+ queryNames: hasQuery ? queryNames : []
5250
+ })
4968
5251
  })
4969
5252
  ];
4970
5253
  }