Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/svelte/src/compiler/compile/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,12 +772,23 @@ export default class Component {
}
const writable =
node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let');
const imported = node.type.startsWith('Import');

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

this.add_var(node, {
name,
initialised: instance_scope.initialised_declarations.has(name),
imported: node.type.startsWith('Import'),
writable,
imported
immutable
});
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.

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 @@ -128,7 +129,7 @@ export default class Expression {
.forEach((name) => dependencies.add(name));
}
} else {
if (!lazy) {
if (!lazy && !component.var_lookup.get(name)?.immutable) {
dependencies.add(name);
}
component.add_reference(node, name);
Expand Down Expand Up @@ -231,6 +232,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
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