class

Analyzer::Javascript::Express

Inherits Analyzer::Javascript::ExpressConstants < Analyzer::Javascript::JavascriptEngine < Analyzer < FileHelper < Reference < Object

Constants

EXPRESS_SOURCE_RE = Regex.union("require('express')", "require(\"express\")", "from 'express'", "from \"express\"", "express()", "express.Router(")

Precompiled once — a single PCRE2-JIT scan replaces six naive String#includes? substring scans over the whole file content. Regex.union auto-escapes each literal, so this is provably equivalent to the OR-of-includes? it replaces.

MAX_CHAIN_METHOD_DISTANCE = 1000

Constants for method chaining detection

MAX_CHAIN_SEARCH_DISTANCE = 5000
PACKAGE_SERVING_GET_RE = /\A(?:express\s*\.\s*static|serveStatic|serveIndex)\s*\(|\AswaggerUi\s*\.\s*(?:serve\b|setup\s*\()/

Deliberate exception to "no name lists": package-provided serving factories (swaggerUi.serve, express.static, serveIndex, …) have no definition in the scan to read, and register a GET route at the mount path (or GET + POST for GraphQL / Apollo middleware) rather than all seven methods.

PACKAGE_SERVING_GRAPHQL_RE = /\A(?:graphqlHTTP|createHandler|(?:[A-Za-z_$][\w$]*\s*\.\s*)?expressMiddleware)\s*\(/
USE_PATH_RE = /\b[A-Za-z_$][\w$]*\.use\s*\(\s*(?:['"]([^'"]+)['"]|`([^`]+)`)\s*,/

Class methods

tech_name
Source

Instance methods

analyze
Source
line_to_endpoint(line : String, router_detected : Bool = false) : Endpoint
Source
line_to_endpoint_multiline(line : String, next_line : String, router_detected : Bool = false) : Endpoint

Helper method to handle multi-line route definitions

Source
line_to_param(line : String) : Param
Source
tech

Instance-side view of the same declaration. The per-file rescues live on this base class, which has no way to name the analyzer that is running inside them, so a skipped file could not be attributed to a tech. Deriving it from analyzer_for keeps the name written exactly once.

Source