Skip to content

Commit 73586aa

Browse files
committed
look at whether the variable was mutated or reassigned instead
1 parent a0393b2 commit 73586aa

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

packages/svelte/src/compiler/compile/Component.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -770,25 +770,12 @@ export default class Component {
770770
if (name[0] === '$') {
771771
return this.error(/** @type {any} */ (node), compiler_errors.illegal_declaration);
772772
}
773-
const writable =
774-
node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let');
775-
776-
let immutable = false;
777-
if (node.type === 'VariableDeclaration' && node.kind === 'const') {
778-
immutable = true;
779-
for (const declaration of node.declarations) {
780-
if (declaration.init.type !== 'Literal') {
781-
immutable = false;
782-
}
783-
}
784-
}
785-
773+
const { type } = node;
786774
this.add_var(node, {
787775
name,
788776
initialised: instance_scope.initialised_declarations.has(name),
789-
imported: node.type.startsWith('Import'),
790-
writable,
791-
immutable
777+
imported: type.startsWith('Import'),
778+
writable: type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let')
792779
});
793780
this.node_for_declaration.set(name, node);
794781
});

packages/svelte/src/compiler/compile/nodes/shared/Expression.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ export default class Expression {
129129
.forEach((name) => dependencies.add(name));
130130
}
131131
} else {
132-
if (!lazy && !component.var_lookup.get(name)?.immutable) {
133-
dependencies.add(name);
132+
if (!lazy) {
133+
const variable = component.var_lookup.get(name);
134+
if (!variable || !variable.imported || variable.mutated || variable.reassigned) {
135+
dependencies.add(name);
136+
}
134137
}
135138
component.add_reference(node, name);
136139
component.warn_if_undefined(name, nodes[0], template_scope, owner);

packages/svelte/src/compiler/interfaces.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ export interface Var {
383383
writable?: boolean;
384384

385385
// used internally, but not exposed
386-
immutable?: boolean;
387386
global?: boolean;
388387
internal?: boolean; // event handlers, bindings
389388
initialised?: boolean;

0 commit comments

Comments
 (0)