From 092ada80c26134114be372edd3956411f9b3edcf Mon Sep 17 00:00:00 2001 From: Nic <162764842+Nic-Polumeyv@users.noreply.github.com> Date: Tue, 15 Sep 2026 15:36:20 -0400 Subject: [PATCH] release the source once it has parsed --- .../src/compiler/phases/1-parse/index.js | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/svelte/src/compiler/phases/1-parse/index.js b/packages/svelte/src/compiler/phases/1-parse/index.js index 523aa210df..3a95bb2b08 100644 --- a/packages/svelte/src/compiler/phases/1-parse/index.js +++ b/packages/svelte/src/compiler/phases/1-parse/index.js @@ -111,26 +111,29 @@ export function parse(template, loose = false, erase = false) { regex_lang_attribute.lastIndex = 0; const ts = match_lang?.[2] === 'ts'; + // the answer is plain objects that owe the source nothing, so the source is released as soon as + // it has parsed: left to the collector it costs more to finalize than a small component to parse + const source = new Source(trimmed, { + host: grammar, + sourceType: 'module', + typescript: ts && (erase ? 'erase' : true), + comments: true, + locations: true, + scopes: true, + errorRecovery: loose, + parenthesized: true, + // a script may export what the component declares elsewhere + allowUndeclaredExports: true + }); /** @type {Parsed} */ let answer; try { - answer = /** @type {any} */ ( - new Source(trimmed, { - host: grammar, - sourceType: 'module', - typescript: ts && (erase ? 'erase' : true), - comments: true, - locations: true, - scopes: true, - errorRecovery: loose, - parenthesized: true, - // a script may export what the component declares elsewhere - allowUndeclaredExports: true - }) - ).parse(); + answer = /** @type {any} */ (source.parse()); } catch (error) { if (!(error instanceof SyntaxError)) throw error; throw_error(/** @type {any} */ (error), trimmed); + } finally { + source[Symbol.dispose](); } unsupported(answer.typescript);