Skip to content

JavaScript & TypeScript

  • Language Standards: ECMAScript 2024 (ES2024) and TypeScript 5.2+
  • Recognized Extensions: .js, .jsx, .mjs, .cjs, .ts, .tsx, .d.ts
  • Stdin Flags: -l javascript (js), -l typescript (ts)
  • Measured Throughput (v0.4.0): 137.3 us ByteString SIMD JS/TS BS lexer (Small ~85 LOC, RQ7); 1.76 ms full TypeScript pipeline (~100 LOC, RQ2)

2. Supported Constructs & Barrel Resolution

Section titled “2. Supported Constructs & Barrel Resolution”

Canontra’s pure-Haskell ByteString-native JS/TS frontend (Canontra.Parser.JS) supports:

  • TypeScript 5.2 Explicit Resource Management: using and await using declarations synthesize deterministic disposal exit blocks (Symbol.dispose / Symbol.asyncDispose) and cleanup edges (CondException "*") in F_CF.
  • Barrel Export Resolution (WholeRepoGraph): export { foo } from './bar' and export * from './sub' re-exports resolve across modules in F_WCG and F_WDF, avoiding false name-only matches.
  • Two-Token Lookahead Regex vs. Division: Disambiguates /regex/flags literals from / division operators after closing braces }, ), or identifiers.
  • Automatic Semicolon Insertion (ASI): Deterministic ASI handling across return, throw, break, continue, and postfix operators.
  • Modules & Declarations: ESM import/export (named, default, namespace, re-exports), CommonJS require/module.exports, arrow functions, classes, async/await, destructuring, JSX/TSX fragments, interface, type, enum, and generic constraints.

3. Language-Specific Alpha Scoping & F_T Rules

Section titled “3. Language-Specific Alpha Scoping & F_T Rules”
  • var Hoisting vs. let/const Block Scoping (canonicalizeAlphaModuleForLang): var bindings hoist to the enclosing function scope, while let, const, for..of/for..in, catch (err), and closure parameters stay block-scoped under @v<depth>.<ordinal>.
  • Flattened Unions & Ordered Tuples: Nested TypeScript unions and intersections ((A | B) | (C | A)) flatten, deduplicate, and sort via makeUnion/makeIntersection, while ordered tuple types [A, B] (TypeTuple) and readonly mutability (Mutability) stay order- and mutability-sensitive in F_T.
  • Generic Normalization & Record Sorting: Generic type parameters (interface Store<K, V>) map to positional variables (α0, α1); object and interface fields ({ b: string; a: number }) sort canonically by field name.

4. Unsupported & Conservative-Fallback Constructs

Section titled “4. Unsupported & Conservative-Fallback Constructs”
  • Type-Level Programming: Complex conditional types (T extends U ? X : Y), recursive template literal types, and infer distributions fall back to normalized structural AST tokens inside F_T rather than invoking tsc.
  • Dynamic Evaluation & Proxies: eval(), new Function(), Proxy traps, and computed dynamic import(expr) are hashed literally without guessing call targets.
  • Experimental vs. Stage 3 Decorators: Both syntaxes are preserved as declaration metadata in F2; compile-time reflection side effects are not executed.