UNPKG

jsii

Version:

[![Join the chat at https://cdk.Dev](https://img.shields.io/static/v1?label=Slack&message=cdk.dev&color=brightgreen&logo=slack)](https://cdk.dev) [![All Contributors](https://img.shields.io/github/all-contributors/aws/jsii/main?label=%E2%9C%A8%20All%20Con

36 lines 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TypeTracker = void 0; const ts = require("typescript"); /** * A class that tracks the TypeScript source AST nodes for certain jsii types * * This is useful if we need to get additional information that is not currently tracked. */ class TypeTracker { constructor() { this.enums = {}; } registerEnum(fqn, decl) { this.enums[fqn] = decl; } getEnum(fqn) { const ret = this.enums[fqn]; if (!ret) { throw new Error(`No declaration was registered for enum ${fqn}`); } return ret; } getEnumMembers(fqn) { const enumDecl = this.getEnum(fqn); return Object.fromEntries(enumDecl.members.filter(ts.isEnumMember).map((mem) => [asIdentifier(mem.name).text, mem])); } } exports.TypeTracker = TypeTracker; function asIdentifier(x) { if (ts.isIdentifier(x)) { return x; } throw new Error(`Expected identifier, got ${JSON.stringify(x)}`); } //# sourceMappingURL=type-tracker.js.map