JavaScript & TypeScript
1. Supported Versions & File Extensions
Section titled “1. Supported Versions & File Extensions”- 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 usByteString SIMDJS/TS BSlexer (Small ~85 LOC,RQ7);1.76 msfull 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:
usingandawait usingdeclarations synthesize deterministic disposal exit blocks (Symbol.dispose/Symbol.asyncDispose) and cleanup edges (CondException "*") inF_CF. - Barrel Export Resolution (
WholeRepoGraph):export { foo } from './bar'andexport * from './sub're-exports resolve across modules inF_WCGandF_WDF, avoiding false name-only matches. - Two-Token Lookahead Regex vs. Division: Disambiguates
/regex/flagsliterals 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), CommonJSrequire/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”varHoisting vs.let/constBlock Scoping (canonicalizeAlphaModuleForLang):varbindings hoist to the enclosing function scope, whilelet,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 viamakeUnion/makeIntersection, while ordered tuple types[A, B](TypeTuple) andreadonlymutability (Mutability) stay order- and mutability-sensitive inF_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, andinferdistributions fall back to normalized structural AST tokens insideF_Trather than invokingtsc. - Dynamic Evaluation & Proxies:
eval(),new Function(),Proxytraps, and computed dynamicimport(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.