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AAC;AAElB,QAAA,kBAAkB,GAEuD,cAAc,CAAC;AAErG,YAAY","sourcesContent":["import * as spec from '@jsii/spec';\nimport * as ts from 'typescript';\n\n/**\n * This module provides typed method that can be used to access TypeScript Nodes\n * that are externally related to jsii assembly entities. This is backed by a\n * `WeakMap` so that attached metadata can be garbage collected once the note\n * they have been related to is no longer reachable.\n *\n * Methods have distinctive names based on the assembly node type they work with\n * because of how TypeScript does structural - and not nominal - type checking,\n * maling it impossible to use function overrides without having small\n * interfaces excessively match all types (e.g: spec.EnumMember is largely\n * equivalent to \"anything that has a name\").\n */\nconst STORAGE = new WeakMap<any, ts.Node>();\n\n//#region Attaching nodes\n\nconst setter = <T>(object: T, node: ts.Node | undefined): T => {\n return setRelatedNode(object, node);\n};\n\nexport function setRelatedNode<T, N extends ts.Node = ts.Node>(object: T, node: N | undefined) {\n if (node != null) {\n STORAGE.set(object, node);\n }\n return object;\n}\n\nexport const setClassRelatedNode: (object: spec.ClassType, node: ts.ClassDeclaration | undefined) => spec.ClassType =\n setter;\n\nexport const setEnumRelatedNode: (object: spec.EnumType, node: ts.EnumDeclaration | undefined) => spec.EnumType =\n setter;\n\nexport const setInterfaceRelatedNode: (\n object: spec.InterfaceType,\n node: ts.InterfaceDeclaration | undefined,\n) => spec.InterfaceType = setter;\n\nexport const setMethodRelatedNode: <T extends ts.MethodDeclaration | ts.MethodSignature>(\n object: spec.Method,\n node: T | undefined,\n) => spec.Method = setter;\n\nexport const setParameterRelatedNode: (\n object: spec.Parameter,\n node: ts.ParameterDeclaration | undefined,\n) => spec.Parameter = setter;\n\nexport const setPropertyRelatedNode: (\n object: spec.Property,\n node:\n | ts.AccessorDeclaration\n | ts.ParameterPropertyDeclaration\n | ts.PropertyDeclaration\n | ts.PropertySignature\n | undefined,\n) => spec.Parameter = setter;\n\n//#endregion\n\n//#region Inspecting attached nodes\n\nexport function getRelatedNode<T extends ts.Node = ts.Node>(object: any): T | undefined {\n return STORAGE.get(object) as T;\n}\n\nexport const getClassRelatedNode: (object: spec.ClassType) => ts.ClassDeclaration | undefined = getRelatedNode;\n\nexport const getClassOrInterfaceRelatedNode: (\n object: spec.ClassType | spec.InterfaceType,\n) => ts.ClassDeclaration | ts.InterfaceDeclaration | undefined = getRelatedNode;\n\nexport const getEnumRelatedNode: (object: spec.EnumType) => ts.EnumDeclaration | undefined = getRelatedNode;\n\nexport const getInterfaceRelatedNode: (object: spec.InterfaceType) => ts.InterfaceDeclaration | undefined =\n getRelatedNode;\n\nexport const getMethodRelatedNode: (object: spec.Method) => ts.MethodDeclaration | ts.MethodSignature | undefined =\n STORAGE.get.bind(STORAGE) as any;\n\nexport const getParameterRelatedNode: (\n object: spec.Parameter,\n) =>\n | ts.AccessorDeclaration\n | ts.ParameterPropertyDeclaration\n | ts.PropertyDeclaration\n | ts.PropertySignature\n | undefined = getRelatedNode;\n\nexport const getPropertyRelatedNode: (\n object: spec.Parameter,\n) =>\n | ts.AccessorDeclaration\n | ts.ParameterPropertyDeclaration\n | ts.PropertyDeclaration\n | ts.PropertySignature\n | undefined = getRelatedNode;\n\nexport const getTypeRelatedNode: (\n object: spec.Type,\n) => ts.ClassDeclaration | ts.EnumDeclaration | ts.InterfaceDeclaration | undefined = getRelatedNode;\n\n//#endregion\n"]}
\No newline at end of file