class

Analyzer::Javascript::JavascriptEngine

Inherits Analyzer < FileHelper < Reference < Object

Constants

DEFAULT_EXPORT_RE = /^[ \t]*export\s+default\b/m

A route module's page component (SolidStart, Qwik City). Line-anchored without consuming earlier lines, so line_for_match lands on it.

DEFAULT_EXTENSIONS = [".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"]

Default extension set for JavaScript/TypeScript source files. Analyzers with a different filter (e.g. Nitro adds .mts, NestJS JS only uses .js/.jsx) pass their own list to parallel_file_scan.

This list mirrors what the JS detectors declare in extensions: (.js .mjs .cjs .jsx .ts .mts .cts .tsx). It has to: detection and analysis read the same tree, so any extension a detector accepts but this list omits produces a project that detects fine and then yields zero endpoints, with nothing logged and nothing for --strict to report. .mjs/.cjs were exactly that hole — an ESM Express app (app.mjs) detected as js_express and returned no routes. Analyzers that pass their own list (koa, hapi, sails, adonisjs, elysia, feathers, ...) already spelled .mjs/.cjs out by hand; the six that relied on this default (express, fastify, hono, restify, apollo, graphql_yoga, plus socketio) silently did not.

EXPORT_BRACE_RES = FILE_ROUTE_METHODS.map do |m| {m, /export\s+\{\s*[^}]*\b#{m}\b[^}]*\}/} end.to_h
EXPORT_CONST_RES = FILE_ROUTE_METHODS.map do |m| {m, /export\s+(?:const|let|var)\s+#{m}\b\s*(?::[^=]+)?=/} end.to_h
EXPORT_FUNCTION_RES = FILE_ROUTE_METHODS.map do |m| {m, /export\s+(?:async\s+)?function\s+#{m}\b/} end.to_h

Compiled once per verb — interpolated regex literals would otherwise be rebuilt (full PCRE2 compile) for every method on every file.

FALLBACK_API_METHODS = ["GET", "POST", "PUT", "DELETE", "PATCH"]

Lowest-cost defaults for endpoints whose handler doesn't advertise its verbs explicitly. Mirrors the Next.js fallback.

FILE_ROUTE_METHODS = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]

Verb-named exports of a file-routed API module (Astro, SvelteKit).

FILE_ROUTE_PARAM_RE = /\[+(?:\.{3})?(\w+)(?:=\w+)?\]+/

Route-directory segments → URL for the src/routes/ conventions (SvelteKit, SolidStart, Qwik City): (group) segments are hidden and every param group normalizes to {name}, in place, so static text around it survives (foo-[id], @[user]): [id] [id=int] [...rest] [[opt]] [[opt=int]] [[...rest]]

JS_PROJECT_ROOT_MARKERS = ["package.json", "next.config.js", "next.config.ts", "next.config.mjs", "next.config.cjs", "svelte.config.js", "svelte.config.ts", "svelte.config.mjs", "svelte.config.cjs"]
TEST_PROJECT_PATH_RE = /\/(?:tests?|__tests__|e2e|e2e-tests|fixtures?)(?:\/|\z)/