UNPKG

estree-toolkit

Version:

Traverser, scope tracker, and more tools for working with ESTree AST

51 lines (50 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GlobalBinding = exports.Binding = void 0; class BaseBinding { constructor() { this.references = []; this.constantViolations = []; } addReference(path) { this.references.push(path); } // Splice is performance intensive, I guess it wouldn't matter for small // arrays, anyway someone's hardly gonna use this remove* methods removeReference(path) { const idx = this.references.findIndex((x) => x === path); if (idx > -1) this.references.splice(idx, 1); } addConstantViolation(path) { this.constantViolations.push(path); } removeConstantViolation(path) { const idx = this.constantViolations.findIndex((x) => x === path); if (idx > -1) this.constantViolations.splice(idx, 1); } } class Binding extends BaseBinding { constructor(data) { super(); this.kind = data.kind; this.name = data.name; this.scope = data.scope; this.identifierPath = data.identifierPath; this.path = data.path; } get constant() { return this.constantViolations.length === 0; } } exports.Binding = Binding; class GlobalBinding extends BaseBinding { constructor(data) { super(); this.kind = 'global'; this.constant = false; this.name = data.name; } } exports.GlobalBinding = GlobalBinding;