diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index 4b64b24ee0..40d4978451 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -5,10 +5,10 @@ import * as assert from '../../utils/assert.js'; import { extract_identifiers, extract_paths, - get_call_expression, is_event_attribute, is_text_attribute, - object + object, + unwrap_ts_expression } from '../../utils/ast.js'; import * as b from '../../utils/builders.js'; import { ReservedKeywords, Runes, SVGElements } from '../constants.js'; @@ -661,8 +661,8 @@ const runes_scope_js_tweaker = { /** @type {import('./types').Visitors} */ const runes_scope_tweaker = { VariableDeclarator(node, { state }) { - const init = get_call_expression(node); - if (init === null) return; + const init = unwrap_ts_expression(node.init); + if (!init || init.type !== 'CallExpression') return; if (get_rune(init, state.scope) === null) return; const callee = init.callee; diff --git a/packages/svelte/src/compiler/utils/ast.js b/packages/svelte/src/compiler/utils/ast.js index 241d74a04e..28a56d7c4a 100644 --- a/packages/svelte/src/compiler/utils/ast.js +++ b/packages/svelte/src/compiler/utils/ast.js @@ -266,23 +266,6 @@ function _extract_paths(assignments = [], param, expression, update_expression) return assignments; } -/** - * If the init of the declarator is a call expression, returns it. - * - * @param {import('estree').VariableDeclarator} node - */ -export function get_call_expression(node) { - let init = node.init; - if (init) { - init = unwrap_ts_expression(init); - if (init.type === 'CallExpression') { - return init; - } - } - - return null; -} - /** * The Acorn TS plugin defines `foo!` as a `TSNonNullExpression` node, and * `foo as Bar` as a `TSAsExpression` node. This function unwraps those.