LANG-javascript: Remaining work after PR #1640 scope-resolution parity
Tracking issue for the JavaScript scope-resolution gaps that PR #1640 (feat/javascript-scope-resolution-ring3) intentionally left out of scope.
Parent: #928 (LANG-javascript migration). Related: #909 (RFC scope resolution).
Context
PR #1640 shipped the JavaScript scope-resolution path as a scope-aware approximation of ECMAScript name lookup. Integration tests pass under REGISTRY_PRIMARY_JAVASCRIPT=1 (the default since JavaScript was added to MIGRATED_LANGUAGES), but several documented divergences from full ECMAScript semantics remain.
Note on the spec reference: @kratos linked
https://pdfa.org/resource/iso-21757-ecmascript/, which is ISO 21757 — ECMAScript for PDF (JavaScript scripting in PDF documents). The resolver targets ECMA-262 (the ECMAScript Language Specification, §9 Executable Code and Execution Contexts, §15 Functions and Classes, §16.2 Modules). Both specs share the same language core; the PDF annex adds PDF-specific host objects. This tracking issue is anchored to ECMA-262 clause numbers throughout.
Each item below is independently scoped.
ECMA-262 conformance posture
GitNexus's JavaScript resolver is not a conforming ECMA-262 implementation. It is a graph-safe under-approximation of ECMAScript name lookup with the same failure-mode preference as the C++ resolver:
When in doubt, suppress (emit zero edges) rather than guess (emit a possibly-wrong edge).
This matters for downstream consumers (impact analysis, refactor safety) that rely on the graph not lying — false negatives are recoverable by re-reading the source; false positives silently mislead.
Target language version
The resolver targets ECMAScript 2022 (13th Edition) class semantics, module system, and optional chaining. Older ES5 prototype-chain patterns are partially supported via synthesizeConstructorFieldBindings (JSDoc @type + new Y() inference in constructors); gaps are listed below.
Where the resolver matches ECMA-262 (implemented in PR #1640)
| Construct | ECMA-262 clause | Implementation |
|---|---|---|
| Module scope | §16.2 Module Environment Records | (program) @scope.module (query.ts) |
| Class scope | §15.7.4 Class Evaluation | (class_declaration), (class) @scope.class |
| Function scope | §10.2 Function Environment Records | All @scope.function node types |
var declarations |
§14.3.2 var Statement | (variable_declaration) |
let/const declarations |
§14.3.1 Lexical Declarations | (lexical_declaration) |
| Named function declarations | §15.2 Function Definitions | (function_declaration) |
| Generator function declarations | §15.5 Generator Functions | (generator_function_declaration) |
| Arrow function expressions | §15.3 Arrow Functions | (arrow_function) |
| Function expressions | §15.2.3 Function Expressions | (function_expression) |
| Class methods | §15.7.1 Method Definitions | (method_definition) |
| Class field definitions | §15.7.3 Class Fields | (field_definition) |
this receiver binding |
§9.4.1 GetThisBinding | synthesizeTsReceiverBinding in captures.ts |
super call resolution |
§15.7.5.1 MakeSuperPropertyReference | isSuperReceiver regex in scope-resolver.ts |
| ESM named / default / namespace imports | §16.2.2 ImportDeclaration | (import_statement) + splitImportStatement |
| ESM named re-exports | §16.2.3.6 ExportDeclaration | (export_statement source:) |
Dynamic import() |
§13.3.10 ImportCall | (call_expression function: (import)) |
CJS require() — named, namespace, side-effect |
Node.js (outside ECMA-262) | synthesizeCjsImports |
Member call obj.m() |
§13.3.4 CallExpression | @reference.call.member |
Free call fn() |
§13.3.4 CallExpression | @reference.call.free |
Constructor call new T() / new ns.T() |
§13.3.5 new Operator |
@reference.call.constructor |
Member write obj.f = v |
§13.15 Assignment Operators | @reference.write.member |
Compound assignment obj.f += v |
§13.15 Assignment Operators | augmented @reference.write.member |
Member read obj.f (non-call context) |
§13.3.3 MemberExpression | @reference.read.member |
instanceof type narrowing |
§13.10.2 InstanceofOperator | synthesizeInstanceofNarrowings |
JSDoc @param {T} n type binding |
de-facto (JSDoc) | synthesizeJsDocBindings |
JSDoc @returns {T} type binding |
de-facto (JSDoc) | synthesizeJsDocBindings |
JSDoc @type {T} on constructor fields |
de-facto (JSDoc) | synthesizeConstructorFieldBindings |
Constructor this.X = new Y() field inference |
§15.7.5 Class Instance Creation | synthesizeConstructorFieldBindings |
Object destructuring binding const { x } = obj |
§14.3.3 Destructuring Binding Patterns | synthesizeDestructuringBindings |
| Array destructuring for-of Map tuples | §14.3.3 + §14.7.5.2 for-in-of | synthesizeForOfMapTupleBindings |
for...of iteration variable |
§14.7.5 The for-in-of-Statement | @type-binding.alias (for_in_statement) |
await expression call unwrapping |
§15.8 Async Functions | (await_expression (...)) patterns |
| Class inheritance (EXTENDS edges) | §15.7.4 ClassHeritage | MRO via buildMro in scope-resolver.ts |
| JSX component references | JSX spec (Meta / TC39 proposal) | JSX query suffix in query.ts |
| HOC-wrapped declarations (React, etc.) | de-facto | HOC patterns in query.ts |
| Arity counting + literal type inference | de-facto | computeTsArityMetadata + inferArgType |
Where the resolver intentionally diverges (open, independently scoped)
| Divergence | ECMA-262 clause | Notes |
|---|---|---|
ES5 prototype-chain assignment T.prototype.m = fn |
§10.1.1 Property Access | Pre-ES6 OOP pattern. Requires detecting X.prototype.Y = function/arrow assignments and retroactively binding them as methods on class X. Not emitted — edges suppressed. |
Private class fields #field reads / writes |
§15.7.3.1 ClassElementName | private_property_identifier not matched by query (only property_identifier is). All #field access edges are suppressed. |
Parameter destructuring fn({ x, y }) |
§15.1.3 FormalParameters | Destructured parameters don't establish per-name type bindings; JSDoc @param {T} name is required for member calls on destructured args. |
Block scopes for let/const |
§9.1 Lexical Environment | Block scopes inside if/for/while/switch are not modeled; variables tracked at the nearest function scope. Does not suppress edges — only shadow-variable disambiguation is lost. |
Class static initialization blocks static { } |
§15.7.3.3 ClassStaticBlock | Not modeled as a scope or tracked as declarations. |
| Generator / async-generator return types | §15.5.1 GeneratorBody, §15.8.7 AsyncGeneratorBody | function* return type (Iterator/AsyncIterator) not modeled. JSDoc @returns still works for explicit annotation. |
Tagged template literals tag`...` |
§13.2.8 TaggedTemplate | Not captured as @reference.call.free; calls suppressed. |
with statement scope injection |
§14.11 The with Statement | Intentionally not supported (deprecated in strict mode; runtime-only semantics). |
eval scope injection |
§19.2.1 eval() | Not supported. Dynamic scope injection cannot be analyzed statically. |
Computed property access obj[expr] |
§13.3.3 MemberExpression | Not resolved; expr is a runtime value. Only string-literal shorthand names are tracked. |
Symbol.* well-known symbol keys |
§6.1.5.1 Well-Known Symbols | Not tracked as named properties (e.g. [Symbol.iterator]() is not emitted as a method declaration). |
Mixin patterns Object.assign(T.prototype, M) |
§19.1.2.1 Object.assign | Cannot be resolved statically. |
Cross-cutting limitations
- No JSDoc
@typedef—/** @typedef {Object} TypeName */is a common pattern for defining object shapes; currently not synthesized as a class-like declaration. - No JSDoc
@typeonlet/constdeclarations —/** @type {User} */ const u = getUser()is not synthesized (only@paramand@returnsare today). - Union types in JSDoc —
/** @returns {User|null} */is partially handled (the resolver strips|null), but multi-member unions ({User|Admin}) only use the first branch. - No
@extends/@implementsJSDoc — JSDoc class hierarchy annotations used in pre-ES6 prototype-based code are not synthesized as EXTENDS/IMPLEMENTS edges.
Verification
# Run the full JavaScript integration suite in both modes:
REGISTRY_PRIMARY_JAVASCRIPT=0 npx vitest run test/integration/resolvers/javascript.test.ts
REGISTRY_PRIMARY_JAVASCRIPT=1 npx vitest run test/integration/resolvers/javascript.test.tsSource: abhigyanpatwari/GitNexus