Skip to content

Commit

Permalink
Merge pull request peggyjs#543 from hildjj/overload
Browse files Browse the repository at this point in the history
Overload
  • Loading branch information
hildjj authored Aug 20, 2024
2 parents 7a8fd86 + 7537108 commit 74186b2
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 262 deletions.
11 changes: 10 additions & 1 deletion bin/peggy-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,24 @@ class PeggyCLI extends Command {
const types = /** @type {Record<string, string>|undefined} */(
this.progOptions.returnTypes
) || {};
const resultTypes = new Set();
for (const sr of startRules) {
const typ = types[sr] || "any";
resultTypes.add(typ);
out.write(`
declare function ParseFunction<Options extends ParseOptions<"${sr}">>(
input: string,
options?: Options,
): ${types[sr] || "any"};
): ${typ};
`);
}

out.write(`
declare function ParseFunction<Options extends ParseOptions<StartRuleNames>>(
input: string,
options?: Options,
): ${[...resultTypes].join(" | ")};
`);
await /** @type {Promise<void>} */(new Promise((resolve, reject) => {
out.close(er => {
if (er) {
Expand Down
2 changes: 1 addition & 1 deletion docs/js/test-bundle.min.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@
"@rollup/plugin-typescript": "^11.1.6",
"@types/chai": "^4.3.11",
"@types/jest": "^29.5.12",
"@types/node": "^22.1.0",
"@types/node": "^22.4.1",
"chai": "^4.3.11",
"chai-like": "^1.1.1",
"copyfiles": "^2.4.1",
"eslint": "^9.8.0",
"eslint": "^9.9.0",
"eslint-plugin-compat": "6.0.0",
"eslint-plugin-mocha": "10.5.0",
"express": "4.19.2",
"glob": "^11.0.0",
"jest": "^29.7.0",
"rimraf": "^6.0.1",
"rollup": "^4.20.0",
"rollup": "^4.21.0",
"rollup-plugin-ignore": "1.0.10",
"source-map": "^0.8.0-beta.0",
"terser": "^5.31.3",
"terser": "^5.31.6",
"ts-jest": "^29.2.4",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"typescript-eslint": "8.0.1"
"typescript-eslint": "8.2.0"
},
"dependencies": {
"@peggyjs/from-mem": "1.3.4",
Expand All @@ -89,7 +89,7 @@
"browserslist": [
"defaults, maintained node versions, not op_mini all"
],
"packageManager": "pnpm@9.6.0",
"packageManager": "pnpm@9.7.1",
"engines": {
"node": ">=18"
}
Expand Down
Loading

0 comments on commit 74186b2

Please sign in to comment.