@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/README.md +30 -10
- package/RELEASE_NOTES.md +22 -72
- package/class-generation/index.ts +124 -107
- package/dist/class-generation/index.d.ts +1 -0
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/index.cjs +341 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +341 -58
- package/dist/index.mjs.map +1 -1
- package/dist/route-navigation-codegen.d.ts +38 -0
- package/dist/route-navigation-codegen.d.ts.map +1 -0
- package/dist/router-bridge.d.ts +1 -0
- package/dist/router-bridge.d.ts.map +1 -1
- package/dist/router.cjs.map +1 -1
- package/dist/router.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4629,6 +4629,251 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
|
|
|
4629
4629
|
}
|
|
4630
4630
|
});
|
|
4631
4631
|
}
|
|
4632
|
+
function writeNavigationValue(writer, input, name) {
|
|
4633
|
+
writer.write(input.identifier);
|
|
4634
|
+
if (input.optional) {
|
|
4635
|
+
writer.write("?.");
|
|
4636
|
+
}
|
|
4637
|
+
writer.write(`[${JSON.stringify(name)}]`);
|
|
4638
|
+
}
|
|
4639
|
+
function writeFilteredNavigationRecord(writer, variableName, input, names) {
|
|
4640
|
+
writer.write(`const ${variableName} = `);
|
|
4641
|
+
if (!input || names.length === 0) {
|
|
4642
|
+
writer.write("{};").newLine();
|
|
4643
|
+
return;
|
|
4644
|
+
}
|
|
4645
|
+
writer.write("Object.fromEntries([");
|
|
4646
|
+
names.forEach((name, index) => {
|
|
4647
|
+
if (index > 0) {
|
|
4648
|
+
writer.write(", ");
|
|
4649
|
+
}
|
|
4650
|
+
writer.write(`[${JSON.stringify(name)}, `);
|
|
4651
|
+
writeNavigationValue(writer, input, name);
|
|
4652
|
+
writer.write("]");
|
|
4653
|
+
});
|
|
4654
|
+
writer.write("].filter(([, value]) => value !== undefined));").newLine();
|
|
4655
|
+
}
|
|
4656
|
+
function writeUnpartitionedRouteParams(writer, input) {
|
|
4657
|
+
writer.write("const routeParams = ");
|
|
4658
|
+
if (!input) {
|
|
4659
|
+
writer.write("{};").newLine();
|
|
4660
|
+
return;
|
|
4661
|
+
}
|
|
4662
|
+
writer.write("Object.fromEntries(Object.entries(");
|
|
4663
|
+
writer.write(input.identifier);
|
|
4664
|
+
if (input.optional) {
|
|
4665
|
+
writer.write(" ?? {}");
|
|
4666
|
+
}
|
|
4667
|
+
writer.write(").filter(([, v]) => v !== undefined));").newLine();
|
|
4668
|
+
}
|
|
4669
|
+
function writeRouterTargetType(writer, includeQuery) {
|
|
4670
|
+
writer.write("{ name: string; params: Record<string, unknown>");
|
|
4671
|
+
if (includeQuery) {
|
|
4672
|
+
writer.write("; query: Record<string, unknown>");
|
|
4673
|
+
}
|
|
4674
|
+
writer.write(" }");
|
|
4675
|
+
}
|
|
4676
|
+
function writeRouterType(writer, includeQuery) {
|
|
4677
|
+
writer.write(`{ ${POM_ROUTER_GLOBAL_NAME}?: { push: (to: `);
|
|
4678
|
+
writeRouterTargetType(writer, includeQuery);
|
|
4679
|
+
writer.write(") => Promise<unknown>; resolve: (to: ");
|
|
4680
|
+
writeRouterTargetType(writer, includeQuery);
|
|
4681
|
+
writer.write(") => { href: string } } }");
|
|
4682
|
+
}
|
|
4683
|
+
function writeRouterBinding(writer, includeQuery) {
|
|
4684
|
+
writer.write("{ name, params");
|
|
4685
|
+
if (includeQuery) {
|
|
4686
|
+
writer.write(", query");
|
|
4687
|
+
}
|
|
4688
|
+
writer.write(" }");
|
|
4689
|
+
}
|
|
4690
|
+
function writeRouterTarget(writer, writeName, includeQuery, paramsExpression, queryExpression) {
|
|
4691
|
+
writer.write("{ name: ");
|
|
4692
|
+
writeName(writer);
|
|
4693
|
+
writer.write(`, params: ${paramsExpression}`);
|
|
4694
|
+
if (includeQuery) {
|
|
4695
|
+
writer.write(`, query: ${queryExpression}`);
|
|
4696
|
+
}
|
|
4697
|
+
writer.write(" }");
|
|
4698
|
+
}
|
|
4699
|
+
function requireNavigationInput(input, context) {
|
|
4700
|
+
if (!input) {
|
|
4701
|
+
throw new Error(`${context} requires a navigation input.`);
|
|
4702
|
+
}
|
|
4703
|
+
return input;
|
|
4704
|
+
}
|
|
4705
|
+
function writeParametrizedRouteSelector(writer, input, pathParamNames) {
|
|
4706
|
+
writer.write(`const useParametrizedRoute = ${input.identifier} !== undefined && [`);
|
|
4707
|
+
pathParamNames.forEach((name, index) => {
|
|
4708
|
+
if (index > 0) {
|
|
4709
|
+
writer.write(", ");
|
|
4710
|
+
}
|
|
4711
|
+
writer.write(JSON.stringify(name));
|
|
4712
|
+
});
|
|
4713
|
+
writer.write(`].some(key => Object.prototype.hasOwnProperty.call(${input.identifier}, key));`).newLine();
|
|
4714
|
+
}
|
|
4715
|
+
function writeSelectionPrelude(writer, selection, input, pathParamNames) {
|
|
4716
|
+
if (selection.kind === "dual" && selection.selectBy === "path-param-presence") {
|
|
4717
|
+
writeParametrizedRouteSelector(
|
|
4718
|
+
writer,
|
|
4719
|
+
requireNavigationInput(input, "Path-param route selection"),
|
|
4720
|
+
pathParamNames
|
|
4721
|
+
);
|
|
4722
|
+
}
|
|
4723
|
+
}
|
|
4724
|
+
function writeSelectedTarget(writer, selection, input) {
|
|
4725
|
+
if (selection.kind === "single") {
|
|
4726
|
+
writer.write(JSON.stringify(selection.target));
|
|
4727
|
+
return;
|
|
4728
|
+
}
|
|
4729
|
+
if (selection.selectBy === "path-param-presence") {
|
|
4730
|
+
writer.write("useParametrizedRoute");
|
|
4731
|
+
} else {
|
|
4732
|
+
writer.write(requireNavigationInput(input, "Input-presence route selection").identifier);
|
|
4733
|
+
}
|
|
4734
|
+
writer.write(` ? ${JSON.stringify(selection.parametrizedTarget)} : ${JSON.stringify(selection.paramlessTarget)}`);
|
|
4735
|
+
}
|
|
4736
|
+
function createRouterNavigationWriter(options) {
|
|
4737
|
+
return (writer) => {
|
|
4738
|
+
writeSelectionPrelude(writer, options.routeName, options.input, options.pathParamNames);
|
|
4739
|
+
const writeRouteName = (nameWriter) => writeSelectedTarget(nameWriter, options.routeName, options.input);
|
|
4740
|
+
const includeQuery = options.queryNames.length > 0;
|
|
4741
|
+
if (includeQuery) {
|
|
4742
|
+
writeFilteredNavigationRecord(writer, "routeParams", options.input, options.pathParamNames);
|
|
4743
|
+
writeFilteredNavigationRecord(writer, "routeQuery", options.input, options.queryNames);
|
|
4744
|
+
} else {
|
|
4745
|
+
writeUnpartitionedRouteParams(writer, options.input);
|
|
4746
|
+
}
|
|
4747
|
+
writer.writeLine(
|
|
4748
|
+
`const isCold = await this.page.evaluate(() => typeof (globalThis as { ${POM_ROUTER_GLOBAL_NAME}?: unknown }).${POM_ROUTER_GLOBAL_NAME} === "undefined");`
|
|
4749
|
+
);
|
|
4750
|
+
writer.writeLine("if (isCold) {");
|
|
4751
|
+
writer.indent(() => {
|
|
4752
|
+
writer.writeLine('await this.page.goto("/", { waitUntil: "commit" });');
|
|
4753
|
+
writer.writeLine(
|
|
4754
|
+
`await this.page.waitForFunction(() => typeof (globalThis as { ${POM_ROUTER_GLOBAL_NAME}?: unknown }).${POM_ROUTER_GLOBAL_NAME} !== "undefined", { timeout: 15000 });`
|
|
4755
|
+
);
|
|
4756
|
+
writer.write("const href = await this.page.evaluate((");
|
|
4757
|
+
writeRouterBinding(writer, includeQuery);
|
|
4758
|
+
writer.write(") => (globalThis as ");
|
|
4759
|
+
writeRouterType(writer, includeQuery);
|
|
4760
|
+
writer.write(`).${POM_ROUTER_GLOBAL_NAME}?.resolve(`);
|
|
4761
|
+
writeRouterBinding(writer, includeQuery);
|
|
4762
|
+
writer.write(")?.href, ");
|
|
4763
|
+
writeRouterTarget(writer, writeRouteName, includeQuery, "routeParams", "routeQuery");
|
|
4764
|
+
writer.write(");").newLine();
|
|
4765
|
+
writer.writeLine("if (href) {");
|
|
4766
|
+
writer.indent(() => {
|
|
4767
|
+
writer.writeLine('await this.page.goto(href, { waitUntil: "domcontentloaded" });');
|
|
4768
|
+
});
|
|
4769
|
+
writer.writeLine("}");
|
|
4770
|
+
});
|
|
4771
|
+
writer.writeLine("} else {");
|
|
4772
|
+
writer.indent(() => {
|
|
4773
|
+
writer.write("await this.page.evaluate(async (");
|
|
4774
|
+
writeRouterBinding(writer, includeQuery);
|
|
4775
|
+
writer.write(") => {").newLine();
|
|
4776
|
+
writer.indent(() => {
|
|
4777
|
+
writer.write("await (globalThis as ");
|
|
4778
|
+
writeRouterType(writer, includeQuery);
|
|
4779
|
+
writer.write(`).${POM_ROUTER_GLOBAL_NAME}?.push(`);
|
|
4780
|
+
writeRouterBinding(writer, includeQuery);
|
|
4781
|
+
writer.write(");").newLine();
|
|
4782
|
+
});
|
|
4783
|
+
writer.write("}, ");
|
|
4784
|
+
writeRouterTarget(writer, writeRouteName, includeQuery, "routeParams", "routeQuery");
|
|
4785
|
+
writer.write(");").newLine();
|
|
4786
|
+
});
|
|
4787
|
+
writer.writeLine("}");
|
|
4788
|
+
};
|
|
4789
|
+
}
|
|
4790
|
+
function writePathParamAssignments(writer, input, pathParams) {
|
|
4791
|
+
for (const param of pathParams) {
|
|
4792
|
+
const token = getParamToken(param.name);
|
|
4793
|
+
if (param.optional) {
|
|
4794
|
+
writer.write("targetUrl = ");
|
|
4795
|
+
writeNavigationValue(writer, input, param.name);
|
|
4796
|
+
writer.write(` === undefined ? targetUrl.replaceAll(${JSON.stringify(`/${token}`)}, "") : targetUrl.replaceAll(${JSON.stringify(token)}, String(`);
|
|
4797
|
+
writeNavigationValue(writer, input, param.name);
|
|
4798
|
+
writer.write("));").newLine();
|
|
4799
|
+
} else {
|
|
4800
|
+
writer.write(`targetUrl = targetUrl.replaceAll(${JSON.stringify(token)}, String(`);
|
|
4801
|
+
writeNavigationValue(writer, input, param.name);
|
|
4802
|
+
writer.write("));").newLine();
|
|
4803
|
+
}
|
|
4804
|
+
}
|
|
4805
|
+
}
|
|
4806
|
+
function writeQueryString(writer, input, queryNames) {
|
|
4807
|
+
if (queryNames.length === 0) {
|
|
4808
|
+
return;
|
|
4809
|
+
}
|
|
4810
|
+
writer.writeLine("const routeQuery = new URLSearchParams();");
|
|
4811
|
+
for (const queryName of queryNames) {
|
|
4812
|
+
writer.write("if (");
|
|
4813
|
+
writeNavigationValue(writer, input, queryName);
|
|
4814
|
+
writer.write(" !== undefined) {").newLine();
|
|
4815
|
+
writer.indent(() => {
|
|
4816
|
+
writer.write(`routeQuery.set(${JSON.stringify(queryName)}, String(`);
|
|
4817
|
+
writeNavigationValue(writer, input, queryName);
|
|
4818
|
+
writer.write("));").newLine();
|
|
4819
|
+
});
|
|
4820
|
+
writer.writeLine("}");
|
|
4821
|
+
}
|
|
4822
|
+
writer.writeLine("const routeQueryString = routeQuery.toString();");
|
|
4823
|
+
writer.writeLine("if (routeQueryString) {");
|
|
4824
|
+
writer.indent(() => {
|
|
4825
|
+
writer.writeLine("targetUrl += `?${routeQueryString}`;");
|
|
4826
|
+
});
|
|
4827
|
+
writer.writeLine("}");
|
|
4828
|
+
}
|
|
4829
|
+
function writeRuntimeUrlNavigation(writer) {
|
|
4830
|
+
writer.writeLine(
|
|
4831
|
+
"const runtimeEnv = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env;"
|
|
4832
|
+
);
|
|
4833
|
+
writer.writeLine(
|
|
4834
|
+
"const runtimeBaseUrl = runtimeEnv?.PLAYWRIGHT_RUNTIME_BASE_URL ?? runtimeEnv?.PLAYWRIGHT_TEST_BASE_URL ?? runtimeEnv?.VITE_PLAYWRIGHT_BASE_URL;"
|
|
4835
|
+
);
|
|
4836
|
+
writer.writeLine("const resolvedUrl = runtimeBaseUrl ? new URL(targetUrl, runtimeBaseUrl).toString() : targetUrl;");
|
|
4837
|
+
writer.writeLine("await this.page.goto(resolvedUrl);");
|
|
4838
|
+
}
|
|
4839
|
+
function createUrlNavigationWriter(options) {
|
|
4840
|
+
return (writer) => {
|
|
4841
|
+
writeSelectionPrelude(writer, options.routeTemplate, options.input, options.pathParams.map((param) => param.name));
|
|
4842
|
+
if (options.routeTemplate.kind === "single") {
|
|
4843
|
+
writer.write(`let targetUrl = ${JSON.stringify(options.routeTemplate.target)};`).newLine();
|
|
4844
|
+
} else {
|
|
4845
|
+
writer.write("const template = ");
|
|
4846
|
+
writeSelectedTarget(writer, options.routeTemplate, options.input);
|
|
4847
|
+
writer.write(";").newLine();
|
|
4848
|
+
writer.writeLine("let targetUrl = template;");
|
|
4849
|
+
}
|
|
4850
|
+
if (options.pathParams.length > 0) {
|
|
4851
|
+
const input = requireNavigationInput(options.input, "URL navigation with path params");
|
|
4852
|
+
if (options.routeTemplate.kind === "dual") {
|
|
4853
|
+
writer.write("if (");
|
|
4854
|
+
writer.write(input.identifier);
|
|
4855
|
+
if (options.routeTemplate.selectBy === "path-param-presence") {
|
|
4856
|
+
writer.write(" && useParametrizedRoute");
|
|
4857
|
+
}
|
|
4858
|
+
writer.write(") {").newLine();
|
|
4859
|
+
writer.indent(() => {
|
|
4860
|
+
writePathParamAssignments(writer, input, options.pathParams);
|
|
4861
|
+
});
|
|
4862
|
+
writer.writeLine("}");
|
|
4863
|
+
} else {
|
|
4864
|
+
writePathParamAssignments(writer, input, options.pathParams);
|
|
4865
|
+
}
|
|
4866
|
+
}
|
|
4867
|
+
if (options.queryNames.length > 0) {
|
|
4868
|
+
writeQueryString(
|
|
4869
|
+
writer,
|
|
4870
|
+
requireNavigationInput(options.input, "URL navigation with query params"),
|
|
4871
|
+
options.queryNames
|
|
4872
|
+
);
|
|
4873
|
+
}
|
|
4874
|
+
writeRuntimeUrlNavigation(writer);
|
|
4875
|
+
};
|
|
4876
|
+
}
|
|
4632
4877
|
const GENERATED_GITATTRIBUTES_BLOCK_START = "# BEGIN vue-pom-generator generated files";
|
|
4633
4878
|
const GENERATED_GITATTRIBUTES_BLOCK_END = "# END vue-pom-generator generated files";
|
|
4634
4879
|
const VUE_POM_GENERATOR_ERROR_PREFIX = "[vue-pom-generator]";
|
|
@@ -4759,7 +5004,7 @@ async function getRouteMetaByComponent(projectRoot, routerEntry, routerType, opt
|
|
|
4759
5004
|
const map = /* @__PURE__ */ new Map();
|
|
4760
5005
|
for (const entry of routeMetaEntries) {
|
|
4761
5006
|
const list = map.get(entry.componentName) ?? [];
|
|
4762
|
-
list.push({ name: entry.name, template: entry.pathTemplate, params: entry.params });
|
|
5007
|
+
list.push({ name: entry.name, template: entry.pathTemplate, params: entry.params, query: entry.query });
|
|
4763
5008
|
map.set(entry.componentName, list);
|
|
4764
5009
|
}
|
|
4765
5010
|
const dedupeRoutes = (entries) => {
|
|
@@ -4798,8 +5043,37 @@ function generateRouteProperty(routeMeta) {
|
|
|
4798
5043
|
})
|
|
4799
5044
|
];
|
|
4800
5045
|
}
|
|
4801
|
-
function
|
|
4802
|
-
return
|
|
5046
|
+
function formatNavigationFieldName(name) {
|
|
5047
|
+
return /^[$a-z_][$\w]*$/i.test(name) ? name : JSON.stringify(name);
|
|
5048
|
+
}
|
|
5049
|
+
function buildNavigationTypeString(route, requiredOptionalParamName) {
|
|
5050
|
+
const pathFields = route.params.map((param) => {
|
|
5051
|
+
const forcePresent = param.optional && param.name === requiredOptionalParamName;
|
|
5052
|
+
return `${formatNavigationFieldName(param.name)}${param.optional && !forcePresent ? "?" : ""}: string | number${forcePresent ? " | undefined" : ""}`;
|
|
5053
|
+
});
|
|
5054
|
+
const pathNames = new Set(route.params.map((param) => param.name));
|
|
5055
|
+
const queryFields = route.query.filter((query) => !pathNames.has(query)).map((query) => `${formatNavigationFieldName(query)}?: string | number`);
|
|
5056
|
+
return `{ ${[...pathFields, ...queryFields].join("; ")} }`;
|
|
5057
|
+
}
|
|
5058
|
+
function buildParametrizedRouteSelectionTypeString(route) {
|
|
5059
|
+
if (route.params.some((param) => !param.optional)) {
|
|
5060
|
+
return buildNavigationTypeString(route);
|
|
5061
|
+
}
|
|
5062
|
+
return route.params.map((param) => buildNavigationTypeString(route, param.name)).join(" | ");
|
|
5063
|
+
}
|
|
5064
|
+
function buildImplementationNavigationTypeString(routes) {
|
|
5065
|
+
const fields = /* @__PURE__ */ new Map();
|
|
5066
|
+
for (const route of routes) {
|
|
5067
|
+
for (const param of route.params) {
|
|
5068
|
+
fields.set(param.name, true);
|
|
5069
|
+
}
|
|
5070
|
+
for (const query of route.query) {
|
|
5071
|
+
if (!fields.has(query)) {
|
|
5072
|
+
fields.set(query, true);
|
|
5073
|
+
}
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
5076
|
+
return `{ ${Array.from(fields.keys()).map((name) => `${formatNavigationFieldName(name)}?: string | number`).join("; ")} }`;
|
|
4803
5077
|
}
|
|
4804
5078
|
function chooseParamlessRoute(routes) {
|
|
4805
5079
|
const paramless = routes.filter((r) => r.params.length === 0);
|
|
@@ -4813,31 +5087,12 @@ function chooseParametrizedRoute(routes) {
|
|
|
4813
5087
|
return null;
|
|
4814
5088
|
return parametrized.slice().sort((a, b) => a.params.length - b.params.length || a.template.length - b.template.length || a.template.localeCompare(b.template))[0];
|
|
4815
5089
|
}
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
const ROUTER_GLOBAL_NAME = POM_ROUTER_GLOBAL_NAME;
|
|
4823
|
-
const pushBlock = (routeNameExpr, paramsExpr, nullable) => {
|
|
4824
|
-
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 } } }`;
|
|
4825
|
-
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));`;
|
|
4826
|
-
return [
|
|
4827
|
-
routeParamsLine,
|
|
4828
|
-
`const isCold = await this.page.evaluate(() => typeof (globalThis as { ${ROUTER_GLOBAL_NAME}?: unknown }).${ROUTER_GLOBAL_NAME} === "undefined");`,
|
|
4829
|
-
`if (isCold) {`,
|
|
4830
|
-
` await this.page.goto("/", { waitUntil: "commit" });`,
|
|
4831
|
-
` await this.page.waitForFunction(() => typeof (globalThis as { ${ROUTER_GLOBAL_NAME}?: unknown }).${ROUTER_GLOBAL_NAME} !== "undefined", { timeout: 15000 });`,
|
|
4832
|
-
` const href = await this.page.evaluate(({ name, params }) => (globalThis as ${routerType}).${ROUTER_GLOBAL_NAME}?.resolve({ name, params })?.href, { name: ${routeNameExpr}, params: routeParams });`,
|
|
4833
|
-
` if (href) { await this.page.goto(href, { waitUntil: "domcontentloaded" }); }`,
|
|
4834
|
-
`} else {`,
|
|
4835
|
-
` await this.page.evaluate(async ({ name, params }) => {`,
|
|
4836
|
-
` await (globalThis as ${routerType}).${ROUTER_GLOBAL_NAME}?.push({ name, params });`,
|
|
4837
|
-
` }, { name: ${routeNameExpr}, params: routeParams });`,
|
|
4838
|
-
`}`
|
|
4839
|
-
];
|
|
4840
|
-
};
|
|
5090
|
+
function requireRouteName(route) {
|
|
5091
|
+
if (route.name === null) {
|
|
5092
|
+
throw new VuePomGeneratorError(`Named navigation requires a route name for template "${route.template}".`);
|
|
5093
|
+
}
|
|
5094
|
+
return route.name;
|
|
5095
|
+
}
|
|
4841
5096
|
function generateGoToMethod(componentName, routeMeta) {
|
|
4842
5097
|
if (!routeMeta) {
|
|
4843
5098
|
return [
|
|
@@ -4865,29 +5120,30 @@ function generateGoToMethod(componentName, routeMeta) {
|
|
|
4865
5120
|
})
|
|
4866
5121
|
];
|
|
4867
5122
|
}
|
|
4868
|
-
const paramStatements = (entry) => {
|
|
4869
|
-
const lines = [];
|
|
4870
|
-
for (const param of entry.params) {
|
|
4871
|
-
const token = getParamToken(param.name);
|
|
4872
|
-
if (param.optional) {
|
|
4873
|
-
lines.push(`targetUrl = params.${param.name} === undefined ? targetUrl.replaceAll(${JSON.stringify(`/${token}`)}, "") : targetUrl.replaceAll(${JSON.stringify(token)}, String(params.${param.name}));`);
|
|
4874
|
-
} else {
|
|
4875
|
-
lines.push(`targetUrl = targetUrl.replaceAll(${JSON.stringify(token)}, String(params.${param.name}));`);
|
|
4876
|
-
}
|
|
4877
|
-
}
|
|
4878
|
-
return lines;
|
|
4879
|
-
};
|
|
4880
5123
|
if (hasParamless && !hasParametrized) {
|
|
4881
5124
|
const route = paramless;
|
|
5125
|
+
const hasQuery2 = route.query.length > 0;
|
|
5126
|
+
const paramType2 = buildNavigationTypeString(route);
|
|
4882
5127
|
return [
|
|
4883
5128
|
createClassMethod({
|
|
4884
5129
|
name: "goTo",
|
|
4885
5130
|
isAsync: true,
|
|
4886
|
-
|
|
5131
|
+
parameters: hasQuery2 ? [{ name: "params", type: paramType2, hasQuestionToken: true }] : [],
|
|
5132
|
+
statements: route.name !== null ? createRouterNavigationWriter({
|
|
5133
|
+
routeName: { kind: "single", target: route.name },
|
|
5134
|
+
input: hasQuery2 ? { identifier: "params", optional: true } : void 0,
|
|
5135
|
+
pathParamNames: [],
|
|
5136
|
+
queryNames: route.query
|
|
5137
|
+
}) : createUrlNavigationWriter({
|
|
5138
|
+
routeTemplate: { kind: "single", target: route.template },
|
|
5139
|
+
input: hasQuery2 ? { identifier: "params", optional: true } : void 0,
|
|
5140
|
+
pathParams: [],
|
|
5141
|
+
queryNames: route.query
|
|
5142
|
+
})
|
|
4887
5143
|
})
|
|
4888
5144
|
];
|
|
4889
5145
|
}
|
|
4890
|
-
const paramType =
|
|
5146
|
+
const paramType = buildNavigationTypeString(parametrized);
|
|
4891
5147
|
if (hasParametrized && !hasParamless) {
|
|
4892
5148
|
const route = parametrized;
|
|
4893
5149
|
const allOptional = route.params.every((p) => p.optional);
|
|
@@ -4896,34 +5152,61 @@ function generateGoToMethod(componentName, routeMeta) {
|
|
|
4896
5152
|
name: "goTo",
|
|
4897
5153
|
isAsync: true,
|
|
4898
5154
|
parameters: [{ name: "params", type: paramType, hasQuestionToken: allOptional }],
|
|
4899
|
-
statements: route.name !== null ?
|
|
5155
|
+
statements: route.name !== null ? createRouterNavigationWriter({
|
|
5156
|
+
routeName: { kind: "single", target: route.name },
|
|
5157
|
+
input: { identifier: "params", optional: allOptional },
|
|
5158
|
+
pathParamNames: route.params.map((param) => param.name),
|
|
5159
|
+
queryNames: route.query
|
|
5160
|
+
}) : createUrlNavigationWriter({
|
|
5161
|
+
routeTemplate: { kind: "single", target: route.template },
|
|
5162
|
+
input: { identifier: "params", optional: allOptional },
|
|
5163
|
+
pathParams: route.params,
|
|
5164
|
+
queryNames: route.query
|
|
5165
|
+
})
|
|
4900
5166
|
})
|
|
4901
5167
|
];
|
|
4902
5168
|
}
|
|
4903
5169
|
const paramlessRoute = paramless;
|
|
4904
5170
|
const parametrizedRoute = parametrized;
|
|
4905
5171
|
const usePush = paramlessRoute.name !== null && parametrizedRoute.name !== null;
|
|
5172
|
+
const paramlessType = buildNavigationTypeString(paramlessRoute);
|
|
5173
|
+
const parametrizedOverloadType = buildParametrizedRouteSelectionTypeString(parametrizedRoute);
|
|
5174
|
+
const queryNames = Array.from(/* @__PURE__ */ new Set([...paramlessRoute.query, ...parametrizedRoute.query]));
|
|
5175
|
+
const hasQuery = queryNames.length > 0;
|
|
5176
|
+
const implementationType = hasQuery ? buildImplementationNavigationTypeString([paramlessRoute, parametrizedRoute]) : paramType;
|
|
4906
5177
|
return [
|
|
4907
5178
|
createClassMethod({
|
|
4908
5179
|
name: "goTo",
|
|
4909
5180
|
isAsync: true,
|
|
4910
5181
|
overloads: [
|
|
4911
|
-
{
|
|
4912
|
-
|
|
5182
|
+
{
|
|
5183
|
+
parameters: paramlessRoute.query.length ? [{ name: "params", type: paramlessType, hasQuestionToken: true }] : [],
|
|
5184
|
+
returnType: "Promise<void>"
|
|
5185
|
+
},
|
|
5186
|
+
{ parameters: [{ name: "params", type: parametrizedOverloadType }], returnType: "Promise<void>" }
|
|
4913
5187
|
],
|
|
4914
|
-
parameters: [{ name: "params", type:
|
|
4915
|
-
statements: usePush ?
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
5188
|
+
parameters: [{ name: "params", type: implementationType, hasQuestionToken: true }],
|
|
5189
|
+
statements: usePush ? createRouterNavigationWriter({
|
|
5190
|
+
routeName: {
|
|
5191
|
+
kind: "dual",
|
|
5192
|
+
parametrizedTarget: requireRouteName(parametrizedRoute),
|
|
5193
|
+
paramlessTarget: requireRouteName(paramlessRoute),
|
|
5194
|
+
selectBy: hasQuery ? "path-param-presence" : "input-presence"
|
|
5195
|
+
},
|
|
5196
|
+
input: { identifier: "params", optional: true },
|
|
5197
|
+
pathParamNames: parametrizedRoute.params.map((param) => param.name),
|
|
5198
|
+
queryNames: hasQuery ? queryNames : []
|
|
5199
|
+
}) : createUrlNavigationWriter({
|
|
5200
|
+
routeTemplate: {
|
|
5201
|
+
kind: "dual",
|
|
5202
|
+
parametrizedTarget: parametrizedRoute.template,
|
|
5203
|
+
paramlessTarget: paramlessRoute.template,
|
|
5204
|
+
selectBy: hasQuery ? "path-param-presence" : "input-presence"
|
|
5205
|
+
},
|
|
5206
|
+
input: { identifier: "params", optional: true },
|
|
5207
|
+
pathParams: parametrizedRoute.params,
|
|
5208
|
+
queryNames: hasQuery ? queryNames : []
|
|
5209
|
+
})
|
|
4927
5210
|
})
|
|
4928
5211
|
];
|
|
4929
5212
|
}
|