Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HTTP Usability: Router + improved exec
Adds a Hono-style
Routerclass and makesre.exec()work correctly for runtime-constructed regex patterns (previously fell back to a hardcoded group count of 9).What's new
Router(src/router.ts)Express/Hono-style router that compiles all routes into a single combined regex at first dispatch. Supports
:paramsegments and*wildcards.Routermethods:get,post,put,delete,all,notFound,handle,compileContextAPI:c.req.param(name)— URL paramc.req.header(name)— request headerc.req.method,.path,.body,.contentTypec.status(code)— chainablec.header(name, value)— chainablec.text(body)/c.json(body)/c.html(body)/c.redirect(url)HTTP utilities (
src/http-utils.ts)re.exec()now works for runtime-constructed patternsPreviously
execon anew RegExp(str)pattern used a hardcoded group count of 9. Now it readsre_nsubfrom the compiled regex at runtime viacs_regex_exec_dyninc_bridges/regex-bridge.c— correct for any pattern regardless of how it was constructed.Native compiler: lambda type propagation fix
Fixed a bug in
src/parser-native/transformer.tswhere lambda parameters passed to class methods didn't get types propagated from the call site. This caused router handler callbacks ((c: Context) => HttpResponse) to fail in the native compiler.Files changed
src/router.tssrc/http-utils.tsc_bridges/regex-bridge.ccs_regex_exec_dynsrc/codegen/types/objects/regex.tsgenerateRegexExecDynsrc/codegen/expressions/method-calls.tsexecthrough dynamic C bridge, remove static group countsrc/codegen/expressions/calls.tssrc/parser-native/transformer.tstests/fixtures/network/router-params.tstests/fixtures/regex/regex-exec-dynamic.tsTest plan
npm test— router-params and regex-exec-dynamic fixtures passnpm run verify— full self-hosting chain passeschad run examples/http-server.ts— param routes respond correctly