class Noir::JSParser

Overview

JSParser is a simple parser for JavaScript route-related patterns

Defined in:

miniparsers/js_parser.cr

Constant Summary

HTTP_CLIENT_RECEIVERS = Set {"request", "axios", "superagent", "supertest", "got", "needle", "unirest", "ky", "phin", "chai"}

Pre-scan tokens to identify router variables Routers are identified by:

  1. Assignment from express.Router(): const router = express.Router()
  2. 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 as router.get(path, handler) — an identifier, a verb, a path-ish first argument and a second argument — so route_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's test/*.js alone 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 named api or client may well be one, so neither is listed.

Constructors

Instance Method Summary

Constructor Detail

def self.new(source : String) #

[View source]

Instance Method Detail

def detect_framework : Symbol #

[View source]
def hit_max_iterations? : Bool #

[View source]
def parse_routes : Array(JSRoutePattern) #

[View source]