Skip to content
8 changes: 3 additions & 5 deletions packages/svelte/src/compiler/compile/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,14 +770,12 @@ export default class Component {
if (name[0] === '$') {
return this.error(/** @type {any} */ (node), compiler_errors.illegal_declaration);
}
const writable =
node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let');
const imported = node.type.startsWith('Import');
const { type } = node;
this.add_var(node, {
name,
initialised: instance_scope.initialised_declarations.has(name),
writable,
imported
imported: type.startsWith('Import'),
writable: type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let')
});
this.node_for_declaration.set(name, node);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/compile/internal_exports.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions packages/svelte/src/compiler/compile/nodes/shared/Expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default class Expression {

/** @type {Array<import('estree').Node | import('estree').Node[]>} */
declarations = [];
/** */

/** @type {boolean} */
uses_context = false;

/** @type {import('estree').Node} */
Expand Down Expand Up @@ -129,7 +130,10 @@ export default class Expression {
}
} else {
if (!lazy) {
dependencies.add(name);
const variable = component.var_lookup.get(name);
if (!variable || !variable.imported || variable.mutated || variable.reassigned) {
dependencies.add(name);
}
}
component.add_reference(node, name);
component.warn_if_undefined(name, nodes[0], template_scope, owner);
Expand Down Expand Up @@ -231,6 +235,8 @@ export default class Expression {
if (this.manipulated) return this.manipulated;
const { component, declarations, scope_map: map, template_scope, owner } = this;
let scope = this.scope;

/** @type {import('estree').FunctionExpression | import('estree').ArrowFunctionExpression | null} */
let function_expression;

/** @type {Set<string>} */
Expand Down