* @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)
| 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); |
no test coverage detected