UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

46 lines (44 loc) 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ts = require("typescript"); const errors = require("./../../errors"); const utils_1 = require("./../../utils"); const callBaseFill_1 = require("./../callBaseFill"); function AmbientableNode(Base) { return class extends Base { hasDeclareKeyword() { return this.getDeclareKeyword() != null; } getDeclareKeywordOrThrow() { return errors.throwIfNullOrUndefined(this.getDeclareKeyword(), "Expected to find a declare keyword."); } getDeclareKeyword() { return this.getFirstModifierByKind(ts.SyntaxKind.DeclareKeyword); } isAmbient() { const isThisAmbient = (this.getCombinedModifierFlags() & ts.ModifierFlags.Ambient) === ts.ModifierFlags.Ambient; if (isThisAmbient || utils_1.TypeGuards.isInterfaceDeclaration(this) || utils_1.TypeGuards.isTypeAliasDeclaration(this)) return true; let topParent = this; for (const parent of this.getAncestors()) { topParent = parent; // store the top parent for later const modifierFlags = parent.getCombinedModifierFlags(); if (modifierFlags & ts.ModifierFlags.Ambient) return true; } return utils_1.TypeGuards.isSourceFile(topParent) && topParent.isDeclarationFile(); } toggleDeclareKeyword(value) { this.toggleModifier("declare", value); return this; } fill(structure) { callBaseFill_1.callBaseFill(Base.prototype, this, structure); if (structure.hasDeclareKeyword != null) this.toggleDeclareKeyword(structure.hasDeclareKeyword); return this; } }; } exports.AmbientableNode = AmbientableNode; //# sourceMappingURL=AmbientableNode.js.map