Skip to content

Commit

Permalink
Revert "look at whether the variable was mutated or reassigned instead"
Browse files Browse the repository at this point in the history
This reverts commit 73586aa.
  • Loading branch information
benmccann committed Jul 10, 2023
1 parent 73586aa commit 9d3562b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
19 changes: 16 additions & 3 deletions packages/svelte/src/compiler/compile/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,12 +770,25 @@ export default class Component {
if (name[0] === '$') {
return this.error(/** @type {any} */ (node), compiler_errors.illegal_declaration);
}
const { type } = node;
const writable =
node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let');

let immutable = false;
if (node.type === 'VariableDeclaration' && node.kind === 'const') {
immutable = true;
for (const declaration of node.declarations) {
if (declaration.init.type !== 'Literal') {
immutable = false;
}
}
}

this.add_var(node, {
name,
initialised: instance_scope.initialised_declarations.has(name),
imported: type.startsWith('Import'),
writable: type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let')
imported: node.type.startsWith('Import'),
writable,
immutable
});
this.node_for_declaration.set(name, node);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ export default class Expression {
.forEach((name) => dependencies.add(name));
}
} else {
if (!lazy) {
const variable = component.var_lookup.get(name);
if (!variable || !variable.imported || variable.mutated || variable.reassigned) {
dependencies.add(name);
}
if (!lazy && !component.var_lookup.get(name)?.immutable) {
dependencies.add(name);
}
component.add_reference(node, name);
component.warn_if_undefined(name, nodes[0], template_scope, owner);
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/src/compiler/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ export interface Var {
writable?: boolean;

// used internally, but not exposed
immutable?: boolean;
global?: boolean;
internal?: boolean; // event handlers, bindings
initialised?: boolean;
Expand Down

0 comments on commit 9d3562b

Please sign in to comment.