MCPcopy
hub / github.com/sveltejs/svelte / declare

Method declare

packages/svelte/src/compiler/phases/scope.js:673–700  ·  view source on GitHub ↗

* @param {Identifier} node * @param {Binding['kind']} kind * @param {DeclarationKind} declaration_kind * @param {null | Expression | FunctionDeclaration | ClassDeclaration | ImportDeclaration | AST.EachBlock | AST.SnippetBlock} initial * @returns {Binding}

(node, kind, declaration_kind, initial = null)

Source from the content-addressed store, hash-verified

671 * @returns {Binding}
672 */
673 declare(node, kind, declaration_kind, initial = null) {
674 if (this.parent) {
675 if (declaration_kind === 'var' && this.#porous) {
676 return this.parent.declare(node, kind, declaration_kind);
677 }
678
679 if (declaration_kind === 'import') {
680 return this.parent.declare(node, kind, declaration_kind, initial);
681 }
682 }
683
684 if (this.declarations.has(node.name)) {
685 const binding = this.declarations.get(node.name);
686 if (binding && binding.declaration_kind !== 'var' && declaration_kind !== 'var') {
687 // This also errors on function types, but that's arguably a good thing
688 // declaring function twice is also caught by acorn in the parse phase
689 e.declaration_duplicate(node, node.name);
690 }
691 }
692
693 const binding = new Binding(this, node, kind, declaration_kind, initial);
694
695 validate_identifier_name(binding, this.function_depth);
696
697 this.declarations.set(node.name, binding);
698 this.root.conflicts.add(node.name);
699 return binding;
700 }
701
702 child(porous = false) {
703 return new Scope(this.root, this, porous);

Callers 13

create_scopesFunction · 0.95
add_paramsFunction · 0.80
LetDirectiveFunction · 0.80
ImportDeclarationFunction · 0.80
FunctionExpressionFunction · 0.80
FunctionDeclarationFunction · 0.80
ClassDeclarationFunction · 0.80
VariableDeclarationFunction · 0.80
CatchClauseFunction · 0.80
EachBlockFunction · 0.80
AwaitBlockFunction · 0.80
SnippetBlockFunction · 0.80

Calls 5

validate_identifier_nameFunction · 0.90
setMethod · 0.65
hasMethod · 0.45
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected