UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

71 lines (70 loc) 2.65 kB
"use strict"; var __extends = (this && this.__extends)/* istanbul ignore next */ || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var ts = require("typescript"); var callBaseFill_1 = require("./../callBaseFill"); var Scope_1 = require("./../common/Scope"); function ScopeableNode(Base) { return /** @class */ (function (_super) { __extends(class_1, _super); function class_1() { return _super !== null && _super.apply(this, arguments) || this; } class_1.prototype.getScope = function () { return getScopeForNode(this); }; class_1.prototype.setScope = function (scope) { setScopeForNode(this, scope); return this; }; class_1.prototype.hasScopeKeyword = function () { return this.getScope() != null; }; class_1.prototype.fill = function (structure) { callBaseFill_1.callBaseFill(Base.prototype, this, structure); if (structure.scope != null) this.setScope(structure.scope); return this; }; return class_1; }(Base)); } exports.ScopeableNode = ScopeableNode; /** * Gets the scope for a node. * @internal * @param node - Node to check for. */ function getScopeForNode(node) { var 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;