@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
25 lines • 832 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.define = define;
const identifier_1 = require("./identifier");
/**
* Define an identifier in the environment, possibly as a super assignment.
* This recalculates the level
*/
function define(definition, superAssign, { level, current }) {
const newEnv = superAssign ? current.defineSuper(definition) : current.define(definition);
return {
level: identifier_1.Identifier.getNamespace(definition.name) === undefined ? level : recalculateLevel(newEnv),
current: newEnv,
};
}
function recalculateLevel(env) {
let level = 0;
let current = env;
while (current.parent && !current.parent.builtInEnv) {
level++;
current = current.parent;
}
return level;
}
//# sourceMappingURL=define.js.map