UNPKG

2.4 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getTypeRelatedNode = exports.getPropertyRelatedNode = exports.getParameterRelatedNode = exports.getMethodRelatedNode = exports.getInterfaceRelatedNode = exports.getEnumRelatedNode = exports.getClassOrInterfaceRelatedNode = exports.getClassRelatedNode = exports.getRelatedNode = exports.setPropertyRelatedNode = exports.setParameterRelatedNode = exports.setMethodRelatedNode = exports.setInterfaceRelatedNode = exports.setEnumRelatedNode = exports.setClassRelatedNode = exports.setRelatedNode = void 0;
4/**
5 * This module provides typed method that can be used to access TypeScript Nodes
6 * that are externally related to jsii assembly entities. This is backed by a
7 * `WeakMap` so that attached metadata can be garbage collected once the note
8 * they have been related to is no longer reachable.
9 *
10 * Methods have distinctive names based on the assembly node type they work with
11 * because of how TypeScript does structural - and not nominal - type checking,
12 * maling it impossible to use function overrides without having small
13 * interfaces excessively match all types (e.g: spec.EnumMember is largely
14 * equivalent to "anything that has a name").
15 */
16const STORAGE = new WeakMap();
17//#region Attaching nodes
18const setter = (object, node) => {
19 return setRelatedNode(object, node);
20};
21function setRelatedNode(object, node) {
22 if (node != null) {
23 STORAGE.set(object, node);
24 }
25 return object;
26}
27exports.setRelatedNode = setRelatedNode;
28exports.setClassRelatedNode = setter;
29exports.setEnumRelatedNode = setter;
30exports.setInterfaceRelatedNode = setter;
31exports.setMethodRelatedNode = setter;
32exports.setParameterRelatedNode = setter;
33exports.setPropertyRelatedNode = setter;
34//#endregion
35//#region Inspecting attached nodes
36function getRelatedNode(object) {
37 return STORAGE.get(object);
38}
39exports.getRelatedNode = getRelatedNode;
40exports.getClassRelatedNode = getRelatedNode;
41exports.getClassOrInterfaceRelatedNode = getRelatedNode;
42exports.getEnumRelatedNode = getRelatedNode;
43exports.getInterfaceRelatedNode = getRelatedNode;
44exports.getMethodRelatedNode = STORAGE.get.bind(STORAGE);
45exports.getParameterRelatedNode = getRelatedNode;
46exports.getPropertyRelatedNode = getRelatedNode;
47exports.getTypeRelatedNode = getRelatedNode;
48//#endregion
49//# sourceMappingURL=node-bindings.js.map
\No newline at end of file