Documentation
¶
Overview ¶
Package jsresolve answers, from JavaScript or TypeScript source bytes alone, the three questions the `reference-resolves` falsifier asks of a web citation (FPK-V0-018): does an import on the cited line carry a given specifier, does an identifier sit on the cited line, and does a blob declare a name at top level. It mirrors what goImportsAtLine, goIdentifierAtLine, and goDeclaresAtTopLevel (cmd/corvint/prove.go) do for Go with go/parser, and what internal/liveverify/pyresolve does for Python.
The tokenizer is a deliberate, line-tracking copy of the lexer in internal/contextindex/webimports.go, which the index uses to make the claim: comments produce no tokens, a `'`/`"` literal ends at its line, and a template literal is one token with its substitutions consumed. One lexing rule goes past the index: a `/` after a regexOpeners punctuator that closes on its line reads as a regular-expression literal, so a backtick or quote inside it opens nothing; every other `/` reads as division. That lexer is unexported and carries no line numbers, and the falsifier must never call the index that made the row, so the copy is the smaller dependency. The one addition over the index's specifier walk is `require("x")`, which the index never records; accepting it here only widens what a row can PASS on, never what the index claims.
No parser is involved. The accepted false positives are the lexer's own for a regular-expression literal read as division (after a word, `)`, `]`, `}`, `+`, `-`, `!`, `<`, or `>`): a quote inside it opens a string that was never there (bounded to its line), a backtick opens a template, and an identifier inside it counts as an occurrence.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeclaresAtTopLevel ¶
DeclaresAtTopLevel reports whether the source declares `name` outside every brace, bracket, and parenthesis as `function name`, `class name`, `const|let|var name`, any of those after `export` or `export default`, or a name listed in a top-level `export { ... }` clause. A declaration keyword counts only at a statement start: after nothing, `;`, `}`, a line terminator, or `export`/`default`/`async`, so `const x = function name() {}` declares `x` and not `name`.
func IdentifierAtLine ¶
IdentifierAtLine reports whether a word token spelled `name` sits on `line`. It is occurrence, not binding: a property access or a same-named local counts, a comment or string does not.
Types ¶
type Import ¶
Import is one module-naming statement: the 1-based line its keyword sits on, the line its specifier literal sits on (the same line unless the clause wraps), and the specifier as written.