UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

58 lines (56 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ts = require("typescript"); const callBaseFill_1 = require("./../callBaseFill"); const Scope_1 = require("./../common/Scope"); function ScopeableNode(Base) { return class extends Base { getScope() { return getScopeForNode(this); } setScope(scope) { setScopeForNode(this, scope); return this; } hasScopeKeyword() { return this.getScope() != null; } fill(structure) { callBaseFill_1.callBaseFill(Base.prototype, this, structure); if (structure.scope != null) this.setScope(structure.scope); return this; } }; } exports.ScopeableNode = ScopeableNode; /** * Gets the scope for a node. * @internal * @param node - Node to check for. */ function getScopeForNode(node) { const modifierFlags = node.getCombinedModifierFlags(); if ((modifierFlags & ts.ModifierFlags.Private) !== 0) return Scope_1.Scope.Private; else if ((modifierFlags & ts.ModifierFlags.Protected) !== 0) return Scope_1.Scope.Protected; else if ((modifierFlags & ts.ModifierFlags.Public) !== 0) return Scope_1.Scope.Public; else return undefined; } exports.getScopeForNode = getScopeForNode; /** * Sets the scope for a node. * @internal * @param node - Node to set the scope for. * @param scope - Scope to be set to. */ function setScopeForNode(node, scope) { node.toggleModifier("public", scope === Scope_1.Scope.Public); // always be explicit with scope node.toggleModifier("protected", scope === Scope_1.Scope.Protected); node.toggleModifier("private", scope === Scope_1.Scope.Private); } exports.setScopeForNode = setScopeForNode; //# sourceMappingURL=ScopeableNode.js.map