Parent: #496 Related: #493, #473, #460, #461, #536
Problem
Parser.parseTemplate and Parser.parseTaggedTemplate append every ordinary byte of every cooked template quasi into arena-owned ArrayList storage. Untagged templates then duplicate the completed buffer again in concatStr. Wide generated templates, bundles, JSX-style transpiler output, and tagged DSL inputs therefore pay avoidable per-byte growth, copying, and retained parse-arena bytes even when a quasi contains no escape and is already a stable slice of the Context-owned source.
Scope
- Add parser-only growth rows for 1K/2K/4K ordinary untagged templates, plus escaped and tagged 4K controls with frozen source construction, structural checks, warmup, and timed parse boundary.
- Borrow cooked untagged and tagged quasi slices when no normalization or escape decoding is required.
- On the first escape, materialize owned cooked storage and append ordinary spans in batches.
- Preserve raw tagged-template slices, one-more-quasi-than-expression shape, substitution parsing context, CR/CRLF normalization, line continuations, WTF-8/lone-surrogate behavior, invalid tagged escapes (
cooked === undefined), early errors for invalid untagged escapes, and exact source lifetime.
Security and correctness
- No borrowed slice may outlive the Context-owned source or normalized arena backing.
- Escaped decoding and normalization must remain OOM-propagating and failure-atomic.
- Attacker-width template text must not create hidden quadratic copying or unbounded global caches.
- Do not special-case benchmark text, skip tagged/raw semantics, weaken escape validation, or defer syntax errors.
Acceptance
- Benchmark source and structural checks land before parser changes.
- AST pointer/lifetime witnesses prove ordinary cooked quasis borrow stable backing; escaped/normalized quasis own exact decoded bytes.
- 1K/2K/4K ordinary rows show bounded near-linear work and materially lower allocation/instruction cost versus the exact parent; escaped/tagged controls remain semantically exact.
- Lexer/parser/frontend suites, untagged/tagged/invalid-escape/line-normalization tests, OOM diagnostics, forced execution paths, full units, and affected test262 template-literal subtrees pass with no regressions.