Skip to content

Commit 9d3562b

Browse files
committed
Revert "look at whether the variable was mutated or reassigned instead"
This reverts commit 73586aa.
1 parent 73586aa commit 9d3562b

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,12 +770,25 @@ export default class Component {
770770
if (name[0] === '$') {
771771
return this.error(/** @type {any} */ (node), compiler_errors.illegal_declaration);
772772
}
773-
const { type } = node;
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+
774786
this.add_var(node, {
775787
name,
776788
initialised: instance_scope.initialised_declarations.has(name),
777-
imported: type.startsWith('Import'),
778-
writable: type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let')
789+
imported: node.type.startsWith('Import'),
790+
writable,
791+
immutable
779792
});
780793
this.node_for_declaration.set(name, node);
781794
});

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,8 @@ export default class Expression {
129129
.forEach((name) => dependencies.add(name));
130130
}
131131
} else {
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-
}
132+
if (!lazy && !component.var_lookup.get(name)?.immutable) {
133+
dependencies.add(name);
137134
}
138135
component.add_reference(node, name);
139136
component.warn_if_undefined(name, nodes[0], template_scope, owner);

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

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

385385
// used internally, but not exposed
386+
immutable?: boolean;
386387
global?: boolean;
387388
internal?: boolean; // event handlers, bindings
388389
initialised?: boolean;

0 commit comments

Comments
 (0)