| 22 | } |
| 23 | |
| 24 | class Scope implements AttachedScope { |
| 25 | parent?: AttachedScope; |
| 26 | isBlockScope: boolean; |
| 27 | declarations: { [key: string]: boolean }; |
| 28 | |
| 29 | constructor(options: ScopeOptions = {}) { |
| 30 | this.parent = options.parent; |
| 31 | this.isBlockScope = !!options.block; |
| 32 | |
| 33 | this.declarations = Object.create(null); |
| 34 | |
| 35 | if (options.params) { |
| 36 | options.params.forEach((param) => { |
| 37 | extractAssignedNames(param).forEach((name) => { |
| 38 | this.declarations[name] = true; |
| 39 | }); |
| 40 | }); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | addDeclaration(node: estree.Node, isBlockDeclaration: boolean, isVar: boolean): void { |
| 45 | if (!isBlockDeclaration && this.isBlockScope) { |
| 46 | // it's a `var` or function node, and this |
| 47 | // is a block scope, so we need to go up |
| 48 | this.parent!.addDeclaration(node, isBlockDeclaration, isVar); |
| 49 | } else if ((node as any).id) { |
| 50 | extractAssignedNames((node as any).id).forEach((name) => { |
| 51 | this.declarations[name] = true; |
| 52 | }); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | contains(name: string): boolean { |
| 57 | return this.declarations[name] || (this.parent ? this.parent.contains(name) : false); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | const attachScopes: AttachScopes = function attachScopes(ast, propertyName = 'scope') { |
| 62 | let scope = new Scope(); |
nothing calls this directly
no outgoing calls
no test coverage detected