release the source once it has parsed

goodbye-acorn
Nic 2 weeks ago
parent 415e67170f
commit 092ada80c2

@ -111,11 +111,9 @@ export function parse(template, loose = false, erase = false) {
regex_lang_attribute.lastIndex = 0; regex_lang_attribute.lastIndex = 0;
const ts = match_lang?.[2] === 'ts'; const ts = match_lang?.[2] === 'ts';
/** @type {Parsed<AST.Root>} */ // the answer is plain objects that owe the source nothing, so the source is released as soon as
let answer; // it has parsed: left to the collector it costs more to finalize than a small component to parse
try { const source = new Source(trimmed, {
answer = /** @type {any} */ (
new Source(trimmed, {
host: grammar, host: grammar,
sourceType: 'module', sourceType: 'module',
typescript: ts && (erase ? 'erase' : true), typescript: ts && (erase ? 'erase' : true),
@ -126,11 +124,16 @@ export function parse(template, loose = false, erase = false) {
parenthesized: true, parenthesized: true,
// a script may export what the component declares elsewhere // a script may export what the component declares elsewhere
allowUndeclaredExports: true allowUndeclaredExports: true
}) });
).parse(); /** @type {Parsed<AST.Root>} */
let answer;
try {
answer = /** @type {any} */ (source.parse());
} catch (error) { } catch (error) {
if (!(error instanceof SyntaxError)) throw error; if (!(error instanceof SyntaxError)) throw error;
throw_error(/** @type {any} */ (error), trimmed); throw_error(/** @type {any} */ (error), trimmed);
} finally {
source[Symbol.dispose]();
} }
unsupported(answer.typescript); unsupported(answer.typescript);

Loading…
Cancel
Save