UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

41 lines (39 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ts = require("typescript"); const callBaseFill_1 = require("./../callBaseFill"); function AmbientableNode(Base) { return class extends Base { hasDeclareKeyword() { return this.getDeclareKeyword() != null; } getDeclareKeyword() { return this.getFirstModifierByKind(ts.SyntaxKind.DeclareKeyword); } isAmbient() { const isThisAmbient = (this.getCombinedModifierFlags() & ts.ModifierFlags.Ambient) === ts.ModifierFlags.Ambient; if (isThisAmbient || this.isInterfaceDeclaration() || this.isTypeAliasDeclaration()) return true; let topParent = this; for (const parent of this.getParents()) { topParent = parent; // store the top parent for later const modifierFlags = parent.getCombinedModifierFlags(); if (modifierFlags & ts.ModifierFlags.Ambient) return true; } return topParent.isSourceFile() && 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