How to use esrecurse - 10 common examples

To help you get started, we’ve selected a few esrecurse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sx1989827 / DOClever / Desktop / node_modules / escope / src / referencer.js View on Github external
var visitor = new PatternVisitor(options, rootPattern, callback);
    visitor.visit(rootPattern);

    // Process the right hand nodes recursively.
    if (referencer != null) {
        visitor.rightHandNodes.forEach(referencer.visit, referencer);
    }
}

// Importing ImportDeclaration.
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-moduledeclarationinstantiation
// https://github.com/estree/estree/blob/master/es6.md#importdeclaration
// FIXME: Now, we don't create module environment, because the context is
// implementation dependent.

class Importer extends esrecurse.Visitor {
    constructor(declaration, referencer) {
        super(null, referencer.options);
        this.declaration = declaration;
        this.referencer = referencer;
    }

    visitImport(id, specifier) {
        this.referencer.visitPattern(id, (pattern) => {
            this.referencer.currentScope().__define(pattern,
                new Definition(
                    Variable.ImportBinding,
                    pattern,
                    specifier,
                    this.declaration,
                    null,
                    null
github aduranil / django-channels-react-multiplayer / frontend / node_modules / eslint-scope / lib / referencer.js View on Github external
visitor.visit(rootPattern);

    // Process the right hand nodes recursively.
    if (referencer !== null && referencer !== undefined) {
        visitor.rightHandNodes.forEach(referencer.visit, referencer);
    }
}

// Importing ImportDeclaration.
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-moduledeclarationinstantiation
// https://github.com/estree/estree/blob/master/es6.md#importdeclaration
// FIXME: Now, we don't create module environment, because the context is
// implementation dependent.

class Importer extends esrecurse.Visitor {
    constructor(declaration, referencer) {
        super(null, referencer.options);
        this.declaration = declaration;
        this.referencer = referencer;
    }

    visitImport(id, specifier) {
        this.referencer.visitPattern(id, pattern => {
            this.referencer.currentScope().__define(pattern,
                new Definition(
                    Variable.ImportBinding,
                    pattern,
                    specifier,
                    this.declaration,
                    null,
                    null
github graalvm / graaljs / tools / eslint / node_modules / eslint-scope / lib / referencer.js View on Github external
visitor.visit(rootPattern);

    // Process the right hand nodes recursively.
    if (referencer !== null && referencer !== undefined) {
        visitor.rightHandNodes.forEach(referencer.visit, referencer);
    }
}

// Importing ImportDeclaration.
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-moduledeclarationinstantiation
// https://github.com/estree/estree/blob/master/es6.md#importdeclaration
// FIXME: Now, we don't create module environment, because the context is
// implementation dependent.

class Importer extends esrecurse.Visitor {
    constructor(declaration, referencer) {
        super(null, referencer.options);
        this.declaration = declaration;
        this.referencer = referencer;
    }

    visitImport(id, specifier) {
        this.referencer.visitPattern(id, pattern => {
            this.referencer.currentScope().__define(pattern,
                new Definition(
                    Variable.ImportBinding,
                    pattern,
                    specifier,
                    this.declaration,
                    null,
                    null
github sx1989827 / DOClever / node_modules / eslint-scope / lib / referencer.js View on Github external
visitor.visit(rootPattern);

    // Process the right hand nodes recursively.
    if (referencer !== null && referencer !== undefined) {
        visitor.rightHandNodes.forEach(referencer.visit, referencer);
    }
}

// Importing ImportDeclaration.
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-moduledeclarationinstantiation
// https://github.com/estree/estree/blob/master/es6.md#importdeclaration
// FIXME: Now, we don't create module environment, because the context is
// implementation dependent.

class Importer extends esrecurse.Visitor {
    constructor(declaration, referencer) {
        super(null, referencer.options);
        this.declaration = declaration;
        this.referencer = referencer;
    }

    visitImport(id, specifier) {
        this.referencer.visitPattern(id, pattern => {
            this.referencer.currentScope().__define(pattern,
                new Definition(
                    Variable.ImportBinding,
                    pattern,
                    specifier,
                    this.declaration,
                    null,
                    null
github graalvm / graaljs / tools / node_modules / eslint / node_modules / eslint-scope / lib / referencer.js View on Github external
visitor.visit(rootPattern);

    // Process the right hand nodes recursively.
    if (referencer !== null && referencer !== undefined) {
        visitor.rightHandNodes.forEach(referencer.visit, referencer);
    }
}

// Importing ImportDeclaration.
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-moduledeclarationinstantiation
// https://github.com/estree/estree/blob/master/es6.md#importdeclaration
// FIXME: Now, we don't create module environment, because the context is
// implementation dependent.

class Importer extends esrecurse.Visitor {
    constructor(declaration, referencer) {
        super(null, referencer.options);
        this.declaration = declaration;
        this.referencer = referencer;
    }

    visitImport(id, specifier) {
        this.referencer.visitPattern(id, pattern => {
            this.referencer.currentScope().__define(pattern,
                new Definition(
                    Variable.ImportBinding,
                    pattern,
                    specifier,
                    this.declaration,
                    null,
                    null
github vincentdchan / webpack-deep-scope-analysis-plugin / packages / deep-scope-analyser / src / referencer.ts View on Github external
public ImportSpecifier(node: ESTree.ImportSpecifier) {
    const local = node.local;

    this.visitImport(local, node);
    const importId = new ImportIdentifierInfo(
      local.name,
      node.imported.name,
      this.declaration.source.value as string,
      ImportType.Identifier,
    );
    this.moduleScope.importManager.addImportId(importId);
  }
}

// Referencing variables and creating bindings.
export class Referencer extends esrecurse.Visitor {
  public parent: Referencer | null = null;
  public isInnerMethodDefinition: boolean = false;
  public exportingSource: string | null = null;
  public isExportingFromLocal: boolean = false;

  public constructor(
    public readonly options: esrecurse.VisitorOption,
    public readonly scopeManager: ScopeManager,
  ) {
    super(undefined, options);
  }

  get currentScope() {
    return this.scopeManager.__currentScope;
  }
github graalvm / graaljs / tools / node_modules / eslint / node_modules / eslint-scope / lib / referencer.js View on Github external
this.visitImport(local, node);
    }

    ImportSpecifier(node) {
        const local = (node.local || node.id);

        if (node.name) {
            this.visitImport(node.name, node);
        } else {
            this.visitImport(local, node);
        }
    }
}

// Referencing variables and creating bindings.
class Referencer extends esrecurse.Visitor {
    constructor(options, scopeManager) {
        super(null, options);
        this.options = options;
        this.scopeManager = scopeManager;
        this.parent = null;
        this.isInnerMethodDefinition = false;
    }

    currentScope() {
        return this.scopeManager.__currentScope;
    }

    close(node) {
        while (this.currentScope() && node === this.currentScope().block) {
            this.scopeManager.__currentScope = this.currentScope().__close(this.scopeManager);
        }
github sx1989827 / DOClever / node_modules / eslint-scope / lib / referencer.js View on Github external
this.visitImport(local, node);
    }

    ImportSpecifier(node) {
        const local = (node.local || node.id);

        if (node.name) {
            this.visitImport(node.name, node);
        } else {
            this.visitImport(local, node);
        }
    }
}

// Referencing variables and creating bindings.
class Referencer extends esrecurse.Visitor {
    constructor(options, scopeManager) {
        super(null, options);
        this.options = options;
        this.scopeManager = scopeManager;
        this.parent = null;
        this.isInnerMethodDefinition = false;
    }

    currentScope() {
        return this.scopeManager.__currentScope;
    }

    close(node) {
        while (this.currentScope() && node === this.currentScope().block) {
            this.scopeManager.__currentScope = this.currentScope().__close(this.scopeManager);
        }
github angelozerr / tern.java / core / ternjs / node_modules / tern-eslint / node_modules / eslint / node_modules / escope / src / pattern-visitor.js View on Github external
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import { Syntax } from 'estraverse';
import esrecurse from 'esrecurse';

function getLast(xs) {
    return xs[xs.length - 1] || null;
}

export default class PatternVisitor extends esrecurse.Visitor {
    static isPattern(node) {
        var nodeType = node.type;
        return (
            nodeType === Syntax.Identifier ||
            nodeType === Syntax.ObjectPattern ||
            nodeType === Syntax.ArrayPattern ||
            nodeType === Syntax.SpreadElement ||
            nodeType === Syntax.RestElement ||
            nodeType === Syntax.AssignmentPattern
        );
    }

    constructor(options, rootPattern, callback) {
        super(null, options);
        this.rootPattern = rootPattern;
        this.callback = callback;
github vincentdchan / webpack-deep-scope-analysis-plugin / packages / deep-scope-analyser / src / patternVisitor.ts View on Github external
export type AssignmentType =
  | ESTree.AssignmentPattern
  | ESTree.AssignmentExpression;

export interface ICallbackOption {
  topLevel: boolean;
  rest: boolean;
  assignments: AssignmentType[];
}

export type PatternVisitorCallback = (
  id: ESTree.Identifier,
  option: ICallbackOption,
) => void;

export class PatternVisitor extends esrecurse.Visitor {
  public static isPattern(node: ESTree.Node) {
    const nodeType = node.type;

    return (
      nodeType === Syntax.Identifier ||
      nodeType === Syntax.ObjectPattern ||
      nodeType === Syntax.ArrayPattern ||
      nodeType === Syntax.SpreadElement ||
      nodeType === Syntax.RestElement ||
      nodeType === Syntax.AssignmentPattern
    );
  }

  public rootPattern: any;
  public callback: PatternVisitorCallback;
  public assignments: AssignmentType[];

esrecurse

ECMAScript AST recursive visitor

BSD-2-Clause
Latest version published 4 years ago

Package Health Score

71 / 100
Full package analysis

Popular esrecurse functions