Noir::JSParser
JSParser is a simple parser for JavaScript route-related patterns
Constants
http, https and socket are also ordinary parameter names for an
app (module.exports = function registerRoutes(http) { http.get('/ping', handler) }), so for them the call shape decides (request_handler_call?).
Top-level keys of an HTTP client options bag. A Restify route spec
keeps arbitrary keys (authAction, validation, swagger, ...) on
req.route.spec, so only these disqualify one.
Pre-scan tokens to identify router variables Routers are identified by:
- Assignment from express.Router(): const router = express.Router()
- Having route methods called on them: router.get(...)
Receivers that are HTTP clients, never routers.
request.get(url, opts)in a test file has the same token shape asrouter.get(path, handler)— an identifier, a verb, a path-ish first argument and a second argument — soroute_handler_arg?cannot separate them and deliberately errs toward keeping the route. The receiver name can: none of these is ever assigned an Express/Koa/Fastify router, and NodeBB'stest/*.jsalone turns 385 such calls into routes that do not exist. Keep the list to library names that would be perverse to use for a router — a receiver namedapiorclientmay well be one (mastodon's streaming server routes onapi), so neither is listed.$/jQuery/$http/AJAXare browser clients,http/httpsthe Node modules (http.get(url, cb), k6'shttp.post(url, data)),socketsails.io's, andhttpClient/axiosInstance/axiosClientthe injected clients of generated SDKs (this.httpClient.post(...)).
Ceiling on the full prefixes one router resolves to. A diamond lattice of parallel mounts doubles the distinct paths per level; a shared router mounted under many paths stays well below it.
Ceiling on resolver calls per file. Results cut short by a cycle are not memoized, so a densely cyclic mount graph could otherwise enumerate every path; past this budget they are memoized anyway.
First parameter names of a request handler: (req, res), (request, reply), (ctx), (c). A client callback names its first parameter
after the response or the error: (res), (err, res), (data, jwr).
Receivers conventionally holding an app or router.
Tokens right before a receiver that put the call's value to use:
return this.get(…), const r = await http.post(…), a || this.get(…).
A route registration is a bare statement; a client call is consumed.
Constructors
this_receiver_ok is false for a file with no server-framework import:
there a bare this.post('/x', data) is the outbound call of an API
client class (class ProjectService extends APIService), not a route,
unless it passes an inline function or a method reference
(this_handler_arg?: Unleash's controllers this.get('/', this.getTags)
import only a local base class).
constants seeds what the file's own declarations cannot give, such as
a constant imported from another module.
Instance methods
The router nearest to router (itself first, then the routers it is
mounted on, breadth-first) for which the block holds. Only meaningful
after parse_routes.