<commit_before>/*
 * scope.js
 *
 * Created by <NAME>.
 * Copyright 2013, <NAME>.
 *
 * Additional work by <NAME>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the MIT license (http://opensource.org/licenses/MIT).
 */

"use strict";

var utils = require("./utils");

var statementNodeTypes = utils.arrayToHash([
        "ExpressionStatement",
        "VariableDeclaration",
        "LabeledStatement",
        "BreakStatement",
        "ContinueStatement",
        "ReturnStatement",
        "DebuggerStatement",
        "IVarDeclaration",
        "ThrowStatement",
        "GlobalStatement",
        "ClassStatement"
    ]),

    parentNodeTypes = utils.arrayToHash([
        "Program",
        "WhileStatement",
        "DoWhileStatement",
        "ForStatement",
        "ForInit",
        "ForInStatement",
        "BlockStatement",
        "WithStatement",
        "IfStatement",
        "ElseIfStatement",
        "SwitchStatement",
        "ClassDeclaration",
        "ProtocolDeclaration",
        "MethodDeclaration",
        "FunctionDeclaration",
        "FunctionExpression"
    ]);


var Scope = function(parent, properties)
{
    this.vars = Object.create(null);

    if (properties)
        this.mergeWith(properties);

    this.parent = parent;

    if (parent)
        this.compiler = parent.compiler;

    this.conditionalWarningList = [];
    this.statementNodes = [];
    this.parentNodes = [];
};

module.exports = Scope;

Scope.prototype.toString = function()
{
    return this.ivars ? "ivars: " + JSON.stringify(this.ivars) : "<No ivars>";
};

Scope.prototype.compiler = function()
{
    return this.compiler;
};

Scope.prototype.rootScope = function()
{
    var self = this;

    while (self.parent)
        self = self.parent;

    return self;
};

Scope.prototype.isRootScope = function()
{
    return !this.parent;
};

Scope.prototype.isLocalScope = function()
{
    return !!this.parent;
};

Scope.prototype.currentClassName = function()
{
    var self = this;<commit_msg>Cache the root scope<commit_after>/*
 * scope.js
 *
 * Created by <NAME>.
 * Copyright 2013, <NAME>.
 *
 * Additional work by <NAME>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the MIT license (http://opensource.org/licenses/MIT).
 */

"use strict";

var utils = require("./utils");

var statementNodeTypes = utils.arrayToHash([
        "ExpressionStatement",
        "VariableDeclaration",
        "LabeledStatement",
        "BreakStatement",
        "ContinueStatement",
        "ReturnStatement",
        "DebuggerStatement",
        "IVarDeclaration",
        "ThrowStatement",
        "GlobalStatement",
        "ClassStatement"
    ]),

    parentNodeTypes = utils.arrayToHash([
        "Program",
        "WhileStatement",
        "DoWhileStatement",
        "ForStatement",
        "ForInit",
        "ForInStatement",
        "BlockStatement",
        "WithStatement",
        "IfStatement",
        "ElseIfStatement",
        "SwitchStatement",
        "ClassDeclaration",
        "ProtocolDeclaration",
        "MethodDeclaration",
        "FunctionDeclaration",
        "FunctionExpression"
    ]);


var Scope = function(parent, properties)
{
    this.vars = Object.create(null);

    if (properties)
        this.mergeWith(properties);

    this.parent = parent;

    if (parent)
    {
        this.compiler = parent.compiler;

        var self = this;

        while (self.parent)
            self = self.parent;

        this.root = self;
    }
    else
        this.root = this;

    this.statementNodes = [];
    this.parentNodes = [];
};

module.exports = Scope;

Scope.prototype.toString = function()
{
    return this.ivars ? "ivars: " + JSON.stringify(this.ivars) : "<No ivars>";
};

Scope.prototype.getCompiler = function()
{
    return this.compiler;
};

Scope.prototype.rootScope = function()
{
    return this.root;
};

Scope.prototype.isRootScope = function()
{
    return !this.parent;
};

Scope.prototype.isLocalScope = function()
{
    return !!this.parent;
};

Scope.prototype.currentClassName = function()
{
    var self = this;
{'fraction_non_alphanumeric': 0.13036184998801822, 'fraction_numerical': 0.001917086029235562, 'mean_word_length': 2.5463041631265932, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1589476', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1173, 'n_words': 256}