├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .npmignore ├── .npmrc ├── .vscode └── settings.json ├── AUTHORS.md ├── CopyrightNotice.txt ├── LICENSE ├── README.md ├── Reflect.ts ├── ReflectLite.ts ├── ReflectNoConflict.ts ├── docs ├── ecmarkup.css ├── ecmarkup.js ├── index.html └── spec.biblio.json ├── globals.d.ts ├── gulpfile.js ├── index.d.ts ├── no-conflict.d.ts ├── package.json ├── spec.html ├── spec └── metadata.md ├── standalone.d.ts ├── test ├── reflect-decorate.ts ├── reflect-definemetadata.ts ├── reflect-deletemetadata.ts ├── reflect-getmetadata.ts ├── reflect-getmetadatakeys.ts ├── reflect-getownmetadata.ts ├── reflect-getownmetadatakeys.ts ├── reflect-hasmetadata.ts ├── reflect-hasownmetadata.ts ├── reflect-metadata.ts ├── reflect-other.ts ├── registry.ts ├── suites.ts ├── tsconfig.json └── vm.ts ├── tsconfig-release.json └── tsconfig.json /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ "main", "release-*" ] 6 | pull_request: 7 | branches: [ "main", "release-*" ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | matrix: 15 | node-version: [10.x] 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - name: Use Node.js ${{ matrix.node-version }} 21 | uses: actions/setup-node@v3 22 | with: 23 | node-version: ${{ matrix.node-version }} 24 | 25 | - name: Build 26 | run: | 27 | npm install 28 | gulp 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | node_modules/ 3 | test/**/*.js 4 | test/**/*.js.map 5 | index.d.mts 6 | no-conflict.d.mts 7 | *.js 8 | *.js.map 9 | *.mjs 10 | *.mjs.map 11 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | node_modules 3 | out 4 | docs 5 | spec 6 | temp 7 | test 8 | typings 9 | bower.json 10 | gulpfile.js 11 | globals.d.ts 12 | Reflect.ts 13 | Reflect.js.map 14 | ReflectLite.ts 15 | ReflectLite.js.map 16 | ReflectNoConflict.ts 17 | ReflectNoConflict.js.map 18 | spec.html 19 | tsconfig.json 20 | tsconfig-release.json 21 | .github 22 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "typescript.tsdk": "node_modules/typescript/lib" 4 | } -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | reflect-metadata is authored by: 2 | * Cy Brown 3 | * Oleh Dokuka 4 | * Ron Buckton 5 | * William Buchwalter -------------------------------------------------------------------------------- /CopyrightNotice.txt: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | 3 | Version 2.0, January 2004 4 | 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 16 | 17 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 18 | 19 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 20 | 21 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 22 | 23 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 24 | 25 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 26 | 27 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 28 | 29 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 30 | 31 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 32 | 33 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 34 | 35 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 36 | 37 | You must give any other recipients of the Work or Derivative Works a copy of this License; and 38 | 39 | You must cause any modified files to carry prominent notices stating that You changed the files; and 40 | 41 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 42 | 43 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 44 | 45 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 46 | 47 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 48 | 49 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 50 | 51 | 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 52 | 53 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 54 | 55 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Metadata Reflection API 2 | 3 | NOTE: Now that both [Decorators](https://github.com/tc39/proposal-decorators) and 4 | [Decorator Metadata](https://github.com/tc39/proposal-decorator-metadata) have achieved Stage 3 within TC39, the API 5 | proposed below is no longer being considered for standardization. However, this package will continue to support 6 | projects that leverage TypeScript's legacy `--experimentalDecorators` option as some projects may not be able to migrate 7 | to use standard decorators. 8 | 9 | * [Detailed proposal][metadata-spec] 10 | 11 | ## Installation 12 | 13 | ``` 14 | npm install reflect-metadata 15 | ``` 16 | 17 | ## Usage 18 | 19 | ### ES Modules in NodeJS/Browser, TypeScript/Babel, Bundlers 20 | ```ts 21 | // - Modifies global `Reflect` object (or defines one in ES5 runtimes). 22 | // - Supports ESM and CommonJS. 23 | // - Contains internal polyfills for `Map`, `Set`, and `WeakMap` for older runtimes. 24 | import "reflect-metadata"; 25 | 26 | // - Modifies global `Reflect` object (or defines one in ES5 runtimes). 27 | // - Supports ESM and CommonJS. 28 | // - Requires runtime support for `"exports"` in `package.json`. 29 | // - Does not include internal polyfills. 30 | import "reflect-metadata/lite"; 31 | ``` 32 | 33 | ### CommonJS 34 | ```ts 35 | // - Modifies global `Reflect` object (or defines one in ES5 runtimes). 36 | // - Contains internal polyfills for `Map`, `Set`, and `WeakMap` for older runtimes. 37 | require("reflect-metadata"); 38 | 39 | // - Modifies global `Reflect` object (or defines one in ES5 runtimes). 40 | // - Requires runtime support for `"exports"` in `package.json`. 41 | // - Does not include internal polyfills. 42 | require("reflect-metadata/lite"); 43 | ``` 44 | 45 | ### In the Browser via ` 51 | 52 | 53 | 54 | 55 | ``` 56 | 57 | **Script** 58 | ```js 59 | // - Makes types available in your editor. 60 | /// 61 | 62 | ``` 63 | 64 | ## Background 65 | 66 | * Decorators add the ability to augment a class and its members as the class is defined, through a declarative syntax. 67 | * [Traceur][traceur] attaches annotations to a static property on the class. 68 | * Languages like C# (.NET), and Java support attributes or annotations that add metadata to types, along with a reflective API for reading metadata. 69 | 70 | ## Goals 71 | 72 | * A number of use cases (Composition/Dependency Injection, Runtime Type Assertions, Reflection/Mirroring, Testing) want the ability to add additional metadata to a class in a consistent manner. 73 | * A consistent approach is needed for various tools and libraries to be able to reason over metadata. 74 | * Metadata-producing decorators (nee. "Annotations") need to be generally composable with mutating decorators. 75 | * Metadata should be available not only on an object but also through a Proxy, with related traps. 76 | * Defining new metadata-producing decorators should not be arduous or over-complex for a developer. 77 | * Metadata should be consistent with other language and runtime features of ECMAScript. 78 | 79 | ## Syntax 80 | 81 | * Declarative definition of metadata: 82 | ```JavaScript 83 | class C { 84 | @Reflect.metadata(metadataKey, metadataValue) 85 | method() { 86 | } 87 | } 88 | ``` 89 | 90 | * Imperative definition of metadata: 91 | ```JavaScript 92 | Reflect.defineMetadata(metadataKey, metadataValue, C.prototype, "method"); 93 | ``` 94 | 95 | * Imperative introspection of metadata: 96 | ```JavaScript 97 | let obj = new C(); 98 | let metadataValue = Reflect.getMetadata(metadataKey, obj, "method"); 99 | ``` 100 | 101 | ## Semantics 102 | 103 | * Object has a new \[\[Metadata\]\] internal property that will contain a Map whose keys are property keys (or **undefined**) and whose values are Maps of metadata keys to metadata values. 104 | * Object will have a number of new internal methods for \[\[DefineOwnMetadata\]\], \[\[GetOwnMetadata\]\], \[\[HasOwnMetadata\]\], etc. 105 | * These internal methods can be overridden by a Proxy to support additional traps. 106 | * These internal methods will by default call a set of abstract operations to define and read metadata. 107 | * The Reflect object will expose the MOP operations to allow imperative access to metadata. 108 | * Metadata defined on class declaration *C* is stored in *C*.\[\[Metadata\]\], with **undefined** as the key. 109 | * Metadata defined on static members of class declaration *C* are stored in *C*.\[\[Metadata\]\], with the property key as the key. 110 | * Metadata defined on instance members of class declaration *C* are stored in *C*.prototype.\[\[Metadata\]\], with the property key as the key. 111 | 112 | ## API 113 | 114 | ```JavaScript 115 | // define metadata on an object or property 116 | Reflect.defineMetadata(metadataKey, metadataValue, target); 117 | Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey); 118 | 119 | // check for presence of a metadata key on the prototype chain of an object or property 120 | let result = Reflect.hasMetadata(metadataKey, target); 121 | let result = Reflect.hasMetadata(metadataKey, target, propertyKey); 122 | 123 | // check for presence of an own metadata key of an object or property 124 | let result = Reflect.hasOwnMetadata(metadataKey, target); 125 | let result = Reflect.hasOwnMetadata(metadataKey, target, propertyKey); 126 | 127 | // get metadata value of a metadata key on the prototype chain of an object or property 128 | let result = Reflect.getMetadata(metadataKey, target); 129 | let result = Reflect.getMetadata(metadataKey, target, propertyKey); 130 | 131 | // get metadata value of an own metadata key of an object or property 132 | let result = Reflect.getOwnMetadata(metadataKey, target); 133 | let result = Reflect.getOwnMetadata(metadataKey, target, propertyKey); 134 | 135 | // get all metadata keys on the prototype chain of an object or property 136 | let result = Reflect.getMetadataKeys(target); 137 | let result = Reflect.getMetadataKeys(target, propertyKey); 138 | 139 | // get all own metadata keys of an object or property 140 | let result = Reflect.getOwnMetadataKeys(target); 141 | let result = Reflect.getOwnMetadataKeys(target, propertyKey); 142 | 143 | // delete metadata from an object or property 144 | let result = Reflect.deleteMetadata(metadataKey, target); 145 | let result = Reflect.deleteMetadata(metadataKey, target, propertyKey); 146 | 147 | // apply metadata via a decorator to a constructor 148 | @Reflect.metadata(metadataKey, metadataValue) 149 | class C { 150 | // apply metadata via a decorator to a method (property) 151 | @Reflect.metadata(metadataKey, metadataValue) 152 | method() { 153 | } 154 | } 155 | ``` 156 | 157 | ## Alternatives 158 | 159 | * Use properties rather than a separate API. 160 | * Obvious downside is that this can be a lot of code: 161 | ```JavaScript 162 | function ParamTypes(...types) { 163 | return (target, propertyKey) => { 164 | const symParamTypes = Symbol.for("design:paramtypes"); 165 | if (propertyKey === undefined) { 166 | target[symParamTypes] = types; 167 | } 168 | else { 169 | const symProperties = Symbol.for("design:properties"); 170 | let properties, property; 171 | if (Object.prototype.hasOwnProperty.call(target, symProperties)) { 172 | properties = target[symProperties]; 173 | } 174 | else { 175 | properties = target[symProperties] = {}; 176 | } 177 | if (Object.prototype.hasOwnProperty.call(properties, propertyKey)) { 178 | property = properties[propertyKey]; 179 | } 180 | else { 181 | property = properties[propertyKey] = {}; 182 | } 183 | property[symParamTypes] = types; 184 | } 185 | }; 186 | } 187 | ``` 188 | 189 | ## Notes 190 | * Though it may seem counterintuitive, the methods on Reflect place the parameters for the metadata key and metadata value before the target or property key. This is due to the fact that the property key is the only optional parameter in the argument list. This also makes the methods easier to curry with Function#bind. This also helps reduce the overall footprint and complexity of a metadata-producing decorator that could target both a class or a property: 191 | 192 | ```JavaScript 193 | function ParamTypes(...types) { 194 | // as propertyKey is effectively optional, its easier to use here 195 | return (target, propertyKey) => { Reflect.defineMetadata("design:paramtypes", types, target, propertyKey); } 196 | 197 | // vs. having multiple overloads with the target and key in the front: 198 | // 199 | // return (target, propertyKey) => { 200 | // if (propertyKey === undefined) { 201 | // Reflect.defineMetadata(target, "design:paramtypes", types); 202 | // } 203 | // else { 204 | // Reflect.defineMetadata(target, propertyKey, "design:paramtypes", types); 205 | // } 206 | // } 207 | // 208 | // vs. having a different methods for the class or a property: 209 | // 210 | // return (target, propertyKey) => { 211 | // if (propertyKey === undefined) { 212 | // Reflect.defineMetadata(target, "design:paramtypes", types); 213 | // } 214 | // else { 215 | // Reflect.definePropertyMetadata(target, propertyKey, "design:paramtypes", types); 216 | // } 217 | // } 218 | } 219 | ``` 220 | 221 | * To enable experimental support for metadata decorators in your TypeScript project, you must add `"experimentalDecorators": true` to your tsconfig.json file. 222 | * To enable experimental support for auto-generated type metadata in your TypeScript project, you must add `"emitDecoratorMetadata": true` to your tsconfig.json file. 223 | * Please note that auto-generated type metadata may have issues with circular or forward references for types. 224 | 225 | ## Issues 226 | 227 | * A poorly written mutating decorator for a class constructor could cause metadata to become lost if the prototype chain is not maintained. Though, not maintaining the prototype chain in a mutating decorator for a class constructor would have other negative side effects as well. @rbuckton 228 | * This is mitigated if the mutating decorator returns a class expression that extends from the target, or returns a proxy for the decorator. @rbuckton 229 | * Metadata for a method is attached to the class (or prototype) via the property key. It would not then be available if trying to read metadata on the function of the method (e.g. "tearing-off" the method from the class). @rbuckton 230 | 231 | [metadata-spec]: https://rbuckton.github.io/reflect-metadata 232 | [traceur]: https://github.com/google/traceur-compiler -------------------------------------------------------------------------------- /docs/ecmarkup.css: -------------------------------------------------------------------------------- 1 | body { 2 | display: flex; 3 | font-size: 18px; 4 | line-height: 1.5; 5 | font-family: Cambria, Palatino Linotype, Palatino, Liberation Serif, serif; 6 | padding: 0; 7 | margin: 0; 8 | color: #111; 9 | } 10 | 11 | #spec-container { 12 | padding: 0 20px; 13 | flex-grow: 1; 14 | flex-basis: 66%; 15 | box-sizing: border-box; 16 | overflow: hidden; 17 | } 18 | 19 | body.oldtoc { 20 | margin: 0 auto; 21 | } 22 | 23 | a { 24 | text-decoration: none; 25 | color: #206ca7; 26 | } 27 | 28 | a:visited { 29 | color: #206ca7; 30 | } 31 | 32 | a:hover { 33 | text-decoration: underline; 34 | color: #239dee; 35 | } 36 | 37 | 38 | code { 39 | font-weight: bold; 40 | font-family: Consolas, Monaco, monospace; 41 | white-space: pre; 42 | } 43 | 44 | pre code { 45 | font-weight: inherit; 46 | } 47 | 48 | pre code.hljs { 49 | background-color: #fff; 50 | margin: 0; 51 | padding: 0; 52 | } 53 | 54 | ol.toc { 55 | list-style: none; 56 | padding-left: 0; 57 | } 58 | 59 | ol.toc ol.toc { 60 | padding-left: 2ex; 61 | list-style: none; 62 | } 63 | 64 | var { 65 | color: #2aa198; 66 | transition: background-color 0.25s ease; 67 | cursor: pointer; 68 | } 69 | 70 | var.referenced { 71 | background-color: #ffff33; 72 | } 73 | 74 | emu-const { 75 | font-family: sans-serif; 76 | } 77 | 78 | emu-val { 79 | font-weight: bold; 80 | } 81 | 82 | /* depth 1 */ 83 | emu-alg ol, 84 | /* depth 4 */ 85 | emu-alg ol ol ol ol, 86 | emu-alg ol.nested-thrice, 87 | emu-alg ol.nested-twice ol, 88 | emu-alg ol.nested-once ol ol { 89 | list-style-type: decimal; 90 | } 91 | 92 | /* depth 2 */ 93 | emu-alg ol ol, 94 | emu-alg ol.nested-once, 95 | /* depth 5 */ 96 | emu-alg ol ol ol ol ol, 97 | emu-alg ol.nested-four-times, 98 | emu-alg ol.nested-thrice ol, 99 | emu-alg ol.nested-twice ol ol, 100 | emu-alg ol.nested-once ol ol ol { 101 | list-style-type: lower-alpha; 102 | } 103 | 104 | /* depth 3 */ 105 | emu-alg ol ol ol, 106 | emu-alg ol.nested-twice, 107 | emu-alg ol.nested-once ol, 108 | /* depth 6 */ 109 | emu-alg ol ol ol ol ol ol, 110 | emu-alg ol.nested-lots, 111 | emu-alg ol.nested-four-times ol, 112 | emu-alg ol.nested-thrice ol ol, 113 | emu-alg ol.nested-twice ol ol ol, 114 | emu-alg ol.nested-once ol ol ol ol, 115 | /* depth 7+ */ 116 | emu-alg ol.nested-lots ol { 117 | list-style-type: lower-roman; 118 | } 119 | 120 | emu-eqn { 121 | display: block; 122 | margin-left: 4em; 123 | } 124 | 125 | emu-eqn.inline { 126 | display: inline; 127 | margin: 0; 128 | } 129 | 130 | emu-eqn div:first-child { 131 | margin-left: -2em; 132 | } 133 | 134 | emu-note { 135 | margin: 1em 0; 136 | color: #666; 137 | border-left: 5px solid #ccc; 138 | display: flex; 139 | flex-direction: row; 140 | } 141 | 142 | emu-note > span.note { 143 | flex-basis: 100px; 144 | min-width: 100px; 145 | flex-grow: 0; 146 | flex-shrink: 1; 147 | text-transform: uppercase; 148 | padding-left: 5px; 149 | } 150 | 151 | emu-note[type=editor] { 152 | border-left-color: #faa; 153 | } 154 | 155 | emu-note > div.note-contents { 156 | flex-grow: 1; 157 | flex-shrink: 1; 158 | } 159 | 160 | emu-note > div.note-contents > p:first-of-type { 161 | margin-top: 0; 162 | } 163 | 164 | emu-note > div.note-contents > p:last-of-type { 165 | margin-bottom: 0; 166 | } 167 | 168 | emu-table td code { 169 | white-space: normal; 170 | } 171 | 172 | emu-figure { 173 | display: block; 174 | } 175 | 176 | emu-example { 177 | display: block; 178 | margin: 1em 3em; 179 | } 180 | 181 | emu-example figure figcaption { 182 | margin-top: 0.5em; 183 | text-align: left; 184 | } 185 | 186 | emu-figure figure, 187 | emu-example figure, 188 | emu-table figure { 189 | display: flex; 190 | flex-direction: column; 191 | align-items: center; 192 | } 193 | 194 | emu-production { 195 | display: block; 196 | } 197 | 198 | emu-grammar[type="example"] emu-production, 199 | emu-grammar[type="definition"] emu-production { 200 | margin-top: 1em; 201 | margin-bottom: 1em; 202 | margin-left: 5ex; 203 | } 204 | 205 | emu-grammar.inline, emu-production.inline, 206 | emu-grammar.inline emu-production emu-rhs, emu-production.inline emu-rhs, 207 | emu-grammar[collapsed] emu-production emu-rhs, emu-production[collapsed] emu-rhs { 208 | display: inline; 209 | padding-left: 1ex; 210 | margin-left: 0; 211 | } 212 | 213 | emu-grammar[collapsed] emu-production, emu-production[collapsed] { 214 | margin: 0; 215 | } 216 | 217 | emu-constraints { 218 | font-size: .75em; 219 | margin-right: 1ex; 220 | } 221 | 222 | emu-gann { 223 | margin-right: 1ex; 224 | } 225 | 226 | emu-gann emu-t:last-child, 227 | emu-gann emu-gprose:last-child, 228 | emu-gann emu-nt:last-child { 229 | margin-right: 0; 230 | } 231 | 232 | emu-geq { 233 | margin-left: 1ex; 234 | font-weight: bold; 235 | } 236 | 237 | emu-oneof { 238 | font-weight: bold; 239 | margin-left: 1ex; 240 | } 241 | 242 | emu-nt { 243 | display: inline-block; 244 | font-style: italic; 245 | white-space: nowrap; 246 | text-indent: 0; 247 | } 248 | 249 | emu-nt a, emu-nt a:visited { 250 | color: #333; 251 | } 252 | 253 | emu-rhs emu-nt { 254 | margin-right: 1ex; 255 | } 256 | 257 | emu-t { 258 | display: inline-block; 259 | font-family: monospace; 260 | font-weight: bold; 261 | white-space: nowrap; 262 | text-indent: 0; 263 | } 264 | 265 | emu-production emu-t { 266 | margin-right: 1ex; 267 | } 268 | 269 | emu-rhs { 270 | display: block; 271 | padding-left: 75px; 272 | text-indent: -25px; 273 | } 274 | 275 | emu-mods { 276 | font-size: .85em; 277 | vertical-align: sub; 278 | font-style: normal; 279 | font-weight: normal; 280 | } 281 | 282 | emu-params, emu-opt { 283 | margin-right: 1ex; 284 | font-family: monospace; 285 | } 286 | 287 | emu-params, emu-constraints { 288 | color: #2aa198; 289 | } 290 | 291 | emu-opt { 292 | color: #b58900; 293 | } 294 | 295 | emu-gprose { 296 | font-size: 0.9em; 297 | font-family: Helvetica, Arial, sans-serif; 298 | } 299 | 300 | emu-production emu-gprose { 301 | margin-right: 1ex; 302 | } 303 | 304 | h1.shortname { 305 | color: #f60; 306 | font-size: 1.5em; 307 | margin: 0; 308 | } 309 | 310 | h1.version { 311 | color: #f60; 312 | font-size: 1.5em; 313 | margin: 0; 314 | } 315 | 316 | h1.title { 317 | margin-top: 0; 318 | color: #f60; 319 | } 320 | 321 | h1.first { 322 | margin-top: 0; 323 | } 324 | 325 | h1, h2, h3, h4, h5, h6 { 326 | position: relative; 327 | } 328 | 329 | h1 .secnum { 330 | text-decoration: none; 331 | margin-right: 5px; 332 | } 333 | 334 | h1 span.title { 335 | order: 2; 336 | } 337 | 338 | 339 | h1 { font-size: 2.67em; margin-top: 2em; margin-bottom: 0; line-height: 1em;} 340 | h2 { font-size: 2em; } 341 | h3 { font-size: 1.56em; } 342 | h4 { font-size: 1.25em; } 343 | h5 { font-size: 1.11em; } 344 | h6 { font-size: 1em; } 345 | 346 | h1:hover span.utils { 347 | display: block; 348 | } 349 | 350 | span.utils { 351 | font-size: 18px; 352 | line-height: 18px; 353 | display: none; 354 | position: absolute; 355 | top: 100%; 356 | left: 0; 357 | right: 0; 358 | font-weight: normal; 359 | } 360 | 361 | span.utils:before { 362 | content: "⤷"; 363 | display: inline-block; 364 | padding: 0 5px; 365 | } 366 | 367 | span.utils > * { 368 | display: inline-block; 369 | margin-right: 20px; 370 | } 371 | 372 | h1 span.utils span.anchor a, 373 | h2 span.utils span.anchor a, 374 | h3 span.utils span.anchor a, 375 | h4 span.utils span.anchor a, 376 | h5 span.utils span.anchor a, 377 | h6 span.utils span.anchor a { 378 | text-decoration: none; 379 | font-variant: small-caps; 380 | } 381 | 382 | h1 span.utils span.anchor a:hover, 383 | h2 span.utils span.anchor a:hover, 384 | h3 span.utils span.anchor a:hover, 385 | h4 span.utils span.anchor a:hover, 386 | h5 span.utils span.anchor a:hover, 387 | h6 span.utils span.anchor a:hover { 388 | color: #333; 389 | } 390 | 391 | emu-intro h1, emu-clause h1, emu-annex h1 { font-size: 2em; } 392 | emu-intro h2, emu-clause h2, emu-annex h2 { font-size: 1.56em; } 393 | emu-intro h3, emu-clause h3, emu-annex h3 { font-size: 1.25em; } 394 | emu-intro h4, emu-clause h4, emu-annex h4 { font-size: 1.11em; } 395 | emu-intro h5, emu-clause h5, emu-annex h5 { font-size: 1em; } 396 | emu-intro h6, emu-clause h6, emu-annex h6 { font-size: 0.9em; } 397 | emu-intro emu-intro h1, emu-clause emu-clause h1, emu-annex emu-annex h1 { font-size: 1.56em; } 398 | emu-intro emu-intro h2, emu-clause emu-clause h2, emu-annex emu-annex h2 { font-size: 1.25em; } 399 | emu-intro emu-intro h3, emu-clause emu-clause h3, emu-annex emu-annex h3 { font-size: 1.11em; } 400 | emu-intro emu-intro h4, emu-clause emu-clause h4, emu-annex emu-annex h4 { font-size: 1em; } 401 | emu-intro emu-intro h5, emu-clause emu-clause h5, emu-annex emu-annex h5 { font-size: 0.9em; } 402 | emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex h1 { font-size: 1.25em; } 403 | emu-intro emu-intro emu-intro h2, emu-clause emu-clause emu-clause h2, emu-annex emu-annex emu-annex h2 { font-size: 1.11em; } 404 | emu-intro emu-intro emu-intro h3, emu-clause emu-clause emu-clause h3, emu-annex emu-annex emu-annex h3 { font-size: 1em; } 405 | emu-intro emu-intro emu-intro h4, emu-clause emu-clause emu-clause h4, emu-annex emu-annex emu-annex h4 { font-size: 0.9em; } 406 | emu-intro emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex emu-annex h1 { font-size: 1.11em; } 407 | emu-intro emu-intro emu-intro emu-intro h2, emu-clause emu-clause emu-clause emu-clause h2, emu-annex emu-annex emu-annex emu-annex h2 { font-size: 1em; } 408 | emu-intro emu-intro emu-intro emu-intro h3, emu-clause emu-clause emu-clause emu-clause h3, emu-annex emu-annex emu-annex emu-annex h3 { font-size: 0.9em; } 409 | emu-intro emu-intro emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex emu-annex emu-annex h1 { font-size: 1em; } 410 | emu-intro emu-intro emu-intro emu-intro emu-intro h2, emu-clause emu-clause emu-clause emu-clause emu-clause h2, emu-annex emu-annex emu-annex emu-annex emu-annex h2 { font-size: 0.9em; } 411 | emu-intro emu-intro emu-intro emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex emu-annex emu-annex emu-annex h1 { font-size: 0.9em } 412 | 413 | emu-clause, emu-intro, emu-annex { 414 | display: block; 415 | } 416 | 417 | /* Figures and tables */ 418 | figure { display: block; margin: 1em 0 3em 0; } 419 | figure object { display: block; margin: 0 auto; } 420 | figure table.real-table { margin: 0 auto; } 421 | figure figcaption { 422 | display: block; 423 | color: #555555; 424 | font-weight: bold; 425 | text-align: center; 426 | } 427 | 428 | emu-table table { 429 | margin: 0 auto; 430 | } 431 | 432 | emu-table table, table.real-table { 433 | border-collapse: collapse; 434 | } 435 | 436 | emu-table td, emu-table th, table.real-table td, table.real-table th { 437 | border: 1px solid black; 438 | padding: 0.4em; 439 | vertical-align: baseline; 440 | } 441 | emu-table th, emu-table thead td, table.real-table th { 442 | background-color: #eeeeee; 443 | } 444 | 445 | /* Note: the left content edges of table.lightweight-table >tbody >tr >td 446 | and div.display line up. */ 447 | table.lightweight-table { 448 | border-collapse: collapse; 449 | margin: 0 0 0 1.5em; 450 | } 451 | table.lightweight-table td, table.lightweight-table th { 452 | border: none; 453 | padding: 0 0.5em; 454 | vertical-align: baseline; 455 | } 456 | 457 | /* diff styles */ 458 | ins { 459 | background-color: #e0f8e0; 460 | text-decoration: none; 461 | border-bottom: 1px solid #396; 462 | } 463 | 464 | del { 465 | background-color: #fee; 466 | } 467 | 468 | ins.block, del.block, 469 | emu-production > ins, emu-production > del, 470 | emu-grammar > ins, emu-grammar > del { 471 | display: block; 472 | } 473 | emu-rhs > ins, emu-rhs > del { 474 | display: inline; 475 | } 476 | 477 | tr.ins > td > ins { 478 | border-bottom: none; 479 | } 480 | 481 | tr.ins > td { 482 | background-color: #e0f8e0; 483 | } 484 | 485 | tr.del > td { 486 | background-color: #fee; 487 | } 488 | 489 | /* Menu Styles */ 490 | #menu-toggle { 491 | font-size: 2em; 492 | 493 | position: fixed; 494 | top: 0; 495 | left: 0; 496 | width: 1.5em; 497 | height: 1.5em; 498 | z-index: 3; 499 | visibility: hidden; 500 | color: #1567a2; 501 | background-color: #fff; 502 | 503 | line-height: 1.5em; 504 | text-align: center; 505 | -webkit-touch-callout: none; 506 | -webkit-user-select: none; 507 | -khtml-user-select: none; 508 | -moz-user-select: none; 509 | -ms-user-select: none; 510 | user-select: none;; 511 | 512 | cursor: pointer; 513 | } 514 | 515 | #menu { 516 | display: flex; 517 | flex-direction: column; 518 | width: 33%; height: 100vh; 519 | max-width: 500px; 520 | box-sizing: border-box; 521 | background-color: #ddd; 522 | overflow: hidden; 523 | transition: opacity 0.1s linear; 524 | padding: 0 5px; 525 | position: fixed; 526 | left: 0; top: 0; 527 | border-right: 2px solid #bbb; 528 | 529 | z-index: 2; 530 | } 531 | 532 | #menu-spacer { 533 | flex-basis: 33%; 534 | max-width: 500px; 535 | flex-grow: 0; 536 | flex-shrink: 0; 537 | } 538 | 539 | #menu a { 540 | color: #1567a2; 541 | } 542 | 543 | #menu.active { 544 | display: flex; 545 | opacity: 1; 546 | z-index: 2; 547 | } 548 | 549 | #menu-pins { 550 | flex-grow: 1; 551 | display: none; 552 | } 553 | 554 | #menu-pins.active { 555 | display: block; 556 | } 557 | 558 | #menu-pins-list { 559 | margin: 0; 560 | padding: 0; 561 | counter-reset: pins-counter; 562 | } 563 | 564 | #menu-pins-list > li:before { 565 | content: counter(pins-counter); 566 | counter-increment: pins-counter; 567 | display: inline-block; 568 | width: 25px; 569 | text-align: center; 570 | border: 1px solid #bbb; 571 | padding: 2px; 572 | margin: 4px; 573 | box-sizing: border-box; 574 | line-height: 1em; 575 | background-color: #ccc; 576 | border-radius: 4px; 577 | } 578 | #menu-toc > ol { 579 | padding: 0; 580 | flex-grow: 1; 581 | } 582 | 583 | #menu-toc > ol li { 584 | padding: 0; 585 | } 586 | 587 | #menu-toc > ol , #menu-toc > ol ol { 588 | list-style-type: none; 589 | margin: 0; 590 | padding: 0; 591 | } 592 | 593 | #menu-toc > ol ol { 594 | padding-left: 0.75em; 595 | } 596 | 597 | #menu-toc li { 598 | text-overflow: ellipsis; 599 | overflow: hidden; 600 | white-space: nowrap; 601 | } 602 | 603 | #menu-toc .item-toggle { 604 | display: inline-block; 605 | transform: rotate(-45deg) translate(-5px, -5px); 606 | transition: transform 0.1s ease; 607 | text-align: center; 608 | width: 20px; 609 | 610 | color: #aab; 611 | 612 | -webkit-touch-callout: none; 613 | -webkit-user-select: none; 614 | -khtml-user-select: none; 615 | -moz-user-select: none; 616 | -ms-user-select: none; 617 | user-select: none;; 618 | 619 | cursor: pointer; 620 | } 621 | 622 | #menu-toc .item-toggle-none { 623 | display: inline-block; 624 | width: 20px; 625 | } 626 | 627 | #menu-toc li.active > .item-toggle { 628 | transform: rotate(45deg) translate(-5px, -5px); 629 | } 630 | 631 | #menu-toc li > ol { 632 | display: none; 633 | } 634 | 635 | #menu-toc li.active > ol { 636 | display: block; 637 | } 638 | 639 | #menu-toc li.revealed > a { 640 | background-color: #bbb; 641 | font-weight: bold; 642 | /* 643 | background-color: #222; 644 | color: #c6d8e4; 645 | */ 646 | } 647 | 648 | #menu-toc li.revealed-leaf> a { 649 | color: #206ca7; 650 | /* 651 | background-color: #222; 652 | color: #c6d8e4; 653 | */ 654 | } 655 | 656 | #menu-toc li.revealed > .item-toggle { 657 | transform: rotate(45deg) translate(-5px, -5px); 658 | } 659 | 660 | #menu-toc li.revealed > ol { 661 | display: block; 662 | } 663 | 664 | #menu-toc li > a { 665 | padding: 2px 5px; 666 | } 667 | 668 | #menu > * { 669 | margin-bottom: 5px; 670 | } 671 | 672 | .menu-pane-header { 673 | padding: 0 5px; 674 | text-transform: uppercase; 675 | background-color: #aaa; 676 | color: #335; 677 | font-weight: bold; 678 | letter-spacing: 2px; 679 | flex-grow: 0; 680 | flex-shrink: 0; 681 | font-size: 0.8em; 682 | } 683 | 684 | #menu-toc { 685 | display: flex; 686 | flex-direction: column; 687 | width: 100%; 688 | overflow: hidden; 689 | flex-grow: 1; 690 | } 691 | 692 | #menu-toc ol.toc { 693 | overflow-x: hidden; 694 | overflow-y: auto; 695 | } 696 | 697 | #menu-search { 698 | position: relative; 699 | flex-grow: 0; 700 | flex-shrink: 0; 701 | width: 100%; 702 | 703 | display: flex; 704 | flex-direction: column; 705 | 706 | max-height: 300px; 707 | } 708 | 709 | #menu-trace-list { 710 | display: none; 711 | } 712 | 713 | #menu-search-box { 714 | box-sizing: border-box; 715 | display: block; 716 | width: 100%; 717 | margin: 5px 0 0 0; 718 | font-size: 1em; 719 | padding: 2px; 720 | background-color: #bbb; 721 | border: 1px solid #999; 722 | } 723 | 724 | #menu-search-results { 725 | overflow-x: hidden; 726 | overflow-y: auto; 727 | } 728 | 729 | li.menu-search-result-clause:before { 730 | content: 'clause'; 731 | width: 40px; 732 | display: inline-block; 733 | text-align: right; 734 | padding-right: 1ex; 735 | color: #666; 736 | font-size: 75%; 737 | } 738 | li.menu-search-result-op:before { 739 | content: 'op'; 740 | width: 40px; 741 | display: inline-block; 742 | text-align: right; 743 | padding-right: 1ex; 744 | color: #666; 745 | font-size: 75%; 746 | } 747 | 748 | li.menu-search-result-prod:before { 749 | content: 'prod'; 750 | width: 40px; 751 | display: inline-block; 752 | text-align: right; 753 | padding-right: 1ex; 754 | color: #666; 755 | font-size: 75% 756 | } 757 | 758 | 759 | li.menu-search-result-term:before { 760 | content: 'term'; 761 | width: 40px; 762 | display: inline-block; 763 | text-align: right; 764 | padding-right: 1ex; 765 | color: #666; 766 | font-size: 75% 767 | } 768 | 769 | #menu-search-results ul { 770 | padding: 0 5px; 771 | margin: 0; 772 | } 773 | 774 | #menu-search-results li { 775 | white-space: nowrap; 776 | text-overflow: ellipsis; 777 | } 778 | 779 | 780 | #menu-trace-list { 781 | counter-reset: item; 782 | margin: 0 0 0 20px; 783 | padding: 0; 784 | } 785 | #menu-trace-list li { 786 | display: block; 787 | white-space: nowrap; 788 | } 789 | 790 | #menu-trace-list li .secnum:after { 791 | content: " "; 792 | } 793 | #menu-trace-list li:before { 794 | content: counter(item) " "; 795 | background-color: #222; 796 | counter-increment: item; 797 | color: #999; 798 | width: 20px; 799 | height: 20px; 800 | line-height: 20px; 801 | display: inline-block; 802 | text-align: center; 803 | margin: 2px 4px 2px 0; 804 | } 805 | 806 | @media (max-width: 1000px) { 807 | body { 808 | margin: 0; 809 | display: block; 810 | } 811 | 812 | #menu { 813 | display: none; 814 | padding-top: 3em; 815 | width: 450px; 816 | } 817 | 818 | #menu.active { 819 | position: fixed; 820 | height: 100%; 821 | left: 0; 822 | top: 0; 823 | right: 300px; 824 | } 825 | 826 | #menu-toggle { 827 | visibility: visible; 828 | } 829 | 830 | #spec-container { 831 | padding: 0 5px; 832 | } 833 | 834 | #references-pane-spacer { 835 | display: none; 836 | } 837 | } 838 | 839 | @media only screen and (max-width: 800px) { 840 | #menu { 841 | width: 100%; 842 | } 843 | 844 | h1 .secnum:empty { 845 | margin: 0; padding: 0; 846 | } 847 | } 848 | 849 | 850 | /* Toolbox */ 851 | .toolbox { 852 | position: absolute; 853 | background: #ddd; 854 | border: 1px solid #aaa; 855 | display: none; 856 | color: #eee; 857 | padding: 5px; 858 | border-radius: 3px; 859 | } 860 | 861 | .toolbox.active { 862 | display: inline-block; 863 | } 864 | 865 | .toolbox a { 866 | text-decoration: none; 867 | padding: 0 5px; 868 | } 869 | 870 | .toolbox a:hover { 871 | text-decoration: underline; 872 | } 873 | 874 | .toolbox:after, .toolbox:before { 875 | top: 100%; 876 | left: 15px; 877 | border: solid transparent; 878 | content: " "; 879 | height: 0; 880 | width: 0; 881 | position: absolute; 882 | pointer-events: none; 883 | } 884 | 885 | .toolbox:after { 886 | border-color: rgba(0, 0, 0, 0); 887 | border-top-color: #ddd; 888 | border-width: 10px; 889 | margin-left: -10px; 890 | } 891 | .toolbox:before { 892 | border-color: rgba(204, 204, 204, 0); 893 | border-top-color: #aaa; 894 | border-width: 12px; 895 | margin-left: -12px; 896 | } 897 | 898 | #references-pane-container { 899 | position: fixed; 900 | bottom: 0; 901 | left: 0; 902 | right: 0; 903 | height: 250px; 904 | display: none; 905 | background-color: #ddd; 906 | z-index: 1; 907 | } 908 | 909 | #references-pane-table-container { 910 | overflow-x: hidden; 911 | overflow-y: auto; 912 | } 913 | 914 | #references-pane-spacer { 915 | flex-basis: 33%; 916 | max-width: 500px; 917 | } 918 | 919 | #references-pane { 920 | flex-grow: 1; 921 | overflow: hidden; 922 | display: flex; 923 | flex-direction: column; 924 | } 925 | 926 | #references-pane-container.active { 927 | display: flex; 928 | } 929 | 930 | #references-pane-close:after { 931 | content: '✖'; 932 | float: right; 933 | cursor: pointer; 934 | } 935 | 936 | #references-pane table tr td:first-child { 937 | text-align: right; 938 | padding-right: 5px; 939 | } 940 | 941 | @media print { 942 | #menu-toggle { 943 | display: none; 944 | } 945 | } 946 | -------------------------------------------------------------------------------- /docs/spec.biblio.json: -------------------------------------------------------------------------------- 1 | {"https://rbuckton.github.io/reflect-metadata":[{"type":"clause","id":"introduction","aoid":null,"title":"Metadata Proposal - ECMAScript","titleHTML":"Metadata Proposal - ECMAScript","number":"","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Metadata Proposal - ECMAScript"},{"type":"clause","id":"syntax","aoid":null,"title":"Syntax","titleHTML":"Syntax","number":"1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Syntax"},{"type":"op","aoid":"GetOrCreateMetadataMap","refId":"getorcreatemetadatamap","location":"","referencingIds":[],"key":"GetOrCreateMetadataMap"},{"type":"clause","id":"getorcreatemetadatamap","aoid":"GetOrCreateMetadataMap","title":"GetOrCreateMetadataMap ( O, P, Create )","titleHTML":"GetOrCreateMetadataMap ( O, P, Create )","number":"2.1.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":["_ref_8","_ref_17","_ref_22","_ref_42","_ref_52"],"key":"GetOrCreateMetadataMap ( O, P, Create )"},{"type":"clause","id":"operations-on-objects","aoid":null,"title":"Operations on Objects","titleHTML":"Operations on Objects","number":"2.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Operations on Objects"},{"type":"clause","id":"abstract-operations","aoid":null,"title":"Abstract Operations","titleHTML":"Abstract Operations","number":"2","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Abstract Operations"},{"type":"op","aoid":"OrdinaryHasMetadata","refId":"ordinaryhasmetadata","location":"","referencingIds":[],"key":"OrdinaryHasMetadata"},{"type":"clause","id":"ordinaryhasmetadata","aoid":"OrdinaryHasMetadata","title":"OrdinaryHasMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryHasMetadata ( MetadataKey, O, P )","number":"3.1.1.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":["_ref_3"],"key":"OrdinaryHasMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-hasmetadata","aoid":null,"title":"[[HasMetadata]] ( MetadataKey, P )","titleHTML":"[[HasMetadata]] ( MetadataKey, P )","number":"3.1.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"[[HasMetadata]] ( MetadataKey, P )"},{"type":"op","aoid":"OrdinaryHasOwnMetadata","refId":"ordinaryhasownmetadata","location":"","referencingIds":[],"key":"OrdinaryHasOwnMetadata"},{"type":"clause","id":"ordinaryhasownmetadata","aoid":"OrdinaryHasOwnMetadata","title":"OrdinaryHasOwnMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryHasOwnMetadata ( MetadataKey, O, P )","number":"3.1.2.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":["_ref_5","_ref_6","_ref_13"],"key":"OrdinaryHasOwnMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-hasownmetadata","aoid":null,"title":"[[HasOwnMetadata]] ( MetadataKey, P )","titleHTML":"[[HasOwnMetadata]] ( MetadataKey, P )","number":"3.1.2","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"[[HasOwnMetadata]] ( MetadataKey, P )"},{"type":"op","aoid":"OrdinaryGetMetadata","refId":"ordinarygetmetadata","location":"","referencingIds":[],"key":"OrdinaryGetMetadata"},{"type":"clause","id":"ordinarygetmetadata","aoid":"OrdinaryGetMetadata","title":"OrdinaryGetMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryGetMetadata ( MetadataKey, O, P )","number":"3.1.3.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":["_ref_11"],"key":"OrdinaryGetMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-getmetadata","aoid":null,"title":"[[GetMetadata]] ( MetadataKey, P )","titleHTML":"[[GetMetadata]] ( MetadataKey, P )","number":"3.1.3","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"[[GetMetadata]] ( MetadataKey, P )"},{"type":"op","aoid":"OrdinaryGetOwnMetadata","refId":"ordinarygetownmetadata","location":"","referencingIds":[],"key":"OrdinaryGetOwnMetadata"},{"type":"clause","id":"ordinarygetownmetadata","aoid":"OrdinaryGetOwnMetadata","title":"OrdinaryGetOwnMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryGetOwnMetadata ( MetadataKey, O, P )","number":"3.1.4.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":["_ref_14","_ref_15"],"key":"OrdinaryGetOwnMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-getownmetadata","aoid":null,"title":"[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )","titleHTML":"[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )","number":"3.1.4","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )"},{"type":"op","aoid":"OrdinaryDefineOwnMetadata","refId":"ordinarydefineownmetadata","location":"","referencingIds":[],"key":"OrdinaryDefineOwnMetadata"},{"type":"clause","id":"ordinarydefineownmetadata","aoid":"OrdinaryDefineOwnMetadata","title":"OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )","titleHTML":"OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )","number":"3.1.5.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":["_ref_19"],"key":"OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-defineownmetadata","aoid":null,"title":"[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )","titleHTML":"[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )","number":"3.1.5","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )"},{"type":"op","aoid":"OrdinaryMetadataKeys","refId":"ordinarymetadatakeys","location":"","referencingIds":[],"key":"OrdinaryMetadataKeys"},{"type":"clause","id":"ordinarymetadatakeys","aoid":"OrdinaryMetadataKeys","title":"OrdinaryMetadataKeys ( O, P )","titleHTML":"OrdinaryMetadataKeys ( O, P )","number":"3.1.6.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":["_ref_24"],"key":"OrdinaryMetadataKeys ( O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-metadatakeys","aoid":null,"title":"[[MetadataKeys]] ( P )","titleHTML":"[[MetadataKeys]] ( P )","number":"3.1.6","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"[[MetadataKeys]] ( P )"},{"type":"op","aoid":"OrdinaryOwnMetadataKeys","refId":"ordinaryownmetadatakeys","location":"","referencingIds":[],"key":"OrdinaryOwnMetadataKeys"},{"type":"clause","id":"ordinaryownmetadatakeys","aoid":"OrdinaryOwnMetadataKeys","title":"OrdinaryOwnMetadataKeys ( O, P )","titleHTML":"OrdinaryOwnMetadataKeys ( O, P )","number":"3.1.7.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":["_ref_26","_ref_39"],"key":"OrdinaryOwnMetadataKeys ( O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-ownmetadatakeys","aoid":null,"title":"[[OwnMetadataKeys]] ( P )","titleHTML":"[[OwnMetadataKeys]] ( P )","number":"3.1.7","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"[[OwnMetadataKeys]] ( P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-deletemetadata","aoid":null,"title":"[[DeleteMetadata]]( MetadataKey, P )","titleHTML":"[[DeleteMetadata]]( MetadataKey, P )","number":"3.1.8","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"[[DeleteMetadata]]( MetadataKey, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots","aoid":null,"title":"Ordinary Object Internal Methods and Internal Slots","titleHTML":"Ordinary Object Internal Methods and Internal Slots","number":"3.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Ordinary Object Internal Methods and Internal Slots"},{"type":"clause","id":"ordinary-and-exotic-objects-behaviors","aoid":null,"title":"Ordinary and Exotic Objects Behaviors","titleHTML":"Ordinary and Exotic Objects Behaviors","number":"3","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Ordinary and Exotic Objects Behaviors"},{"type":"clause","id":"reflect-metadatadecoratorfunctions","aoid":null,"title":"Metadata Decorator Functions","titleHTML":"Metadata Decorator Functions","number":"4.1.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Metadata Decorator Functions"},{"type":"clause","id":"reflect.metadata","aoid":null,"title":"Reflect.metadata ( metadataKey, metadataValue )","titleHTML":"Reflect.metadata ( metadataKey, metadataValue )","number":"4.1.2","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Reflect.metadata ( metadataKey, metadataValue )"},{"type":"clause","id":"reflect.definemetadata","aoid":null,"title":"Reflect.defineMetadata ( metadataKey, metadataValue, target [, propertyKey] )","titleHTML":"Reflect.defineMetadata ( metadataKey, metadataValue, target [, propertyKey] )","number":"4.1.3","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Reflect.defineMetadata ( metadataKey, metadataValue, target [, propertyKey] )"},{"type":"clause","id":"reflect.hasmetadata","aoid":null,"title":"Reflect.hasMetadata ( metadataKey, target [, propertyKey] )","titleHTML":"Reflect.hasMetadata ( metadataKey, target [, propertyKey] )","number":"4.1.4","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Reflect.hasMetadata ( metadataKey, target [, propertyKey] )"},{"type":"clause","id":"reflect.hasownmetadata","aoid":null,"title":"Reflect.hasOwnMetadata ( metadataKey, target [, propertyKey] )","titleHTML":"Reflect.hasOwnMetadata ( metadataKey, target [, propertyKey] )","number":"4.1.5","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Reflect.hasOwnMetadata ( metadataKey, target [, propertyKey] )"},{"type":"clause","id":"reflect.getmetadata","aoid":null,"title":"Reflect.getMetadata ( metadataKey, target [, propertyKey] )","titleHTML":"Reflect.getMetadata ( metadataKey, target [, propertyKey] )","number":"4.1.6","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Reflect.getMetadata ( metadataKey, target [, propertyKey] )"},{"type":"clause","id":"reflect.getownmetadata","aoid":null,"title":"Reflect.getOwnMetadata ( metadataKey, target [, propertyKey] )","titleHTML":"Reflect.getOwnMetadata ( metadataKey, target [, propertyKey] )","number":"4.1.7","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Reflect.getOwnMetadata ( metadataKey, target [, propertyKey] )"},{"type":"clause","id":"reflect.getmetadatakeys","aoid":null,"title":"Reflect.getMetadataKeys ( target [, propertyKey] )","titleHTML":"Reflect.getMetadataKeys ( target [, propertyKey] )","number":"4.1.8","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Reflect.getMetadataKeys ( target [, propertyKey] )"},{"type":"clause","id":"reflect.getownmetadatakeys","aoid":null,"title":"Reflect.getOwnMetadataKeys ( target [, propertyKey] )","titleHTML":"Reflect.getOwnMetadataKeys ( target [, propertyKey] )","number":"4.1.9","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Reflect.getOwnMetadataKeys ( target [, propertyKey] )"},{"type":"clause","id":"reflect.deletemetadata","aoid":null,"title":"Reflect.deleteMetadata ( metadataKey, target [, propertyKey] )","titleHTML":"Reflect.deleteMetadata ( metadataKey, target [, propertyKey] )","number":"4.1.10","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Reflect.deleteMetadata ( metadataKey, target [, propertyKey] )"},{"type":"clause","id":"reflect","aoid":null,"title":"The Reflect Object","titleHTML":"The Reflect Object","number":"4.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"The Reflect Object"},{"type":"clause","id":"reflection","aoid":null,"title":"Reflection","titleHTML":"Reflection","number":"4","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","referencingIds":[],"key":"Reflection"}]} -------------------------------------------------------------------------------- /globals.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (C) Microsoft. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | interface SymbolConstructor { 17 | (description?: string): symbol; 18 | for(key: string): symbol; 19 | readonly iterator: symbol; 20 | readonly toPrimitive: symbol; 21 | } 22 | 23 | declare var Symbol: SymbolConstructor; 24 | 25 | interface Iterator { 26 | next(value?: any): __IteratorResult; 27 | throw?(value: any): __IteratorResult; 28 | return?(value?: T): __IteratorResult; 29 | } 30 | 31 | type __IteratorResult = { value: T, done: false } | { value: never, done: true }; 32 | 33 | interface Iterable { 34 | [Symbol.iterator](): Iterator; 35 | } 36 | 37 | interface IterableIterator extends Iterator { 38 | [Symbol.iterator](): IterableIterator; 39 | } 40 | 41 | interface Map extends Iterable<[K, V]> { 42 | readonly size: number; 43 | has(key: K): boolean; 44 | get(key: K): V; 45 | set(key: K, value?: V): this; 46 | delete(key: K): boolean; 47 | clear(): void; 48 | keys(): IterableIterator; 49 | values(): IterableIterator; 50 | entries(): IterableIterator<[K, V]>; 51 | } 52 | 53 | interface MapConstructor { 54 | new (): Map; 55 | new (): Map; 56 | readonly prototype: Map; 57 | } 58 | 59 | interface Set extends Iterable { 60 | readonly size: number; 61 | has(value: T): boolean; 62 | add(value: T): this; 63 | delete(value: T): boolean; 64 | clear(): void; 65 | keys(): IterableIterator; 66 | values(): IterableIterator; 67 | entries(): IterableIterator<[T, T]>; 68 | } 69 | 70 | interface SetConstructor { 71 | new (): Set; 72 | new (): Set; 73 | readonly prototype: Set; 74 | } 75 | 76 | interface WeakMap { 77 | clear(): void; 78 | delete(key: K): boolean; 79 | get(key: K): V; 80 | has(key: K): boolean; 81 | set(key: K, value?: V): WeakMap; 82 | } 83 | 84 | interface WeakMapConstructor { 85 | new (): WeakMap; 86 | new (): WeakMap; 87 | readonly prototype: WeakMap; 88 | } 89 | 90 | declare var Map: MapConstructor; 91 | declare var Set: SetConstructor; 92 | declare var WeakMap: WeakMapConstructor; 93 | 94 | // NOTE: These are not actually global, just shared between the Reflect*.ts variants 95 | 96 | interface MetadataRegistry { 97 | registerProvider(provider: MetadataProvider): void; 98 | getProvider(O: object, P: string | symbol | undefined): MetadataProvider | undefined; 99 | setProvider(O: object, P: string | symbol | undefined, provider: MetadataProvider): boolean; 100 | } 101 | 102 | interface MetadataProvider { 103 | isProviderFor(O: object, P: string | symbol | undefined): boolean; 104 | OrdinaryDefineOwnMetadata(MetadataKey: any, MetadataValue: any, O: object, P: string | symbol | undefined): void; 105 | OrdinaryDeleteMetadata(MetadataKey: any, O: object, P: string | symbol | undefined): boolean; 106 | OrdinaryHasOwnMetadata(MetadataKey: any, O: object, P: string | symbol | undefined): boolean; 107 | OrdinaryGetOwnMetadata(MetadataKey: any, O: object, P: string | symbol | undefined): any; 108 | OrdinaryOwnMetadataKeys(O: object, P: string | symbol | undefined): any[]; 109 | } 110 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | const gulp = require("gulp"); 2 | const sequence = require("gulp-sequence"); 3 | const del = require("del"); 4 | const tsb = require("gulp-tsb"); 5 | const mocha = require("gulp-mocha"); 6 | const emu = require("gulp-emu"); 7 | const rename = require("gulp-rename"); 8 | const gls = require("gulp-live-server"); 9 | 10 | const debugProject = tsb.create("tsconfig.json"); 11 | const releaseProject = tsb.create("tsconfig-release.json"); 12 | const tests = tsb.create("test/tsconfig.json"); 13 | 14 | let project = debugProject; 15 | 16 | gulp.task("release", () => { project = releaseProject; }); 17 | gulp.task("clean", () => del([ 18 | "Reflect.js", 19 | "Reflect.js.map", 20 | "ReflectLite.js", 21 | "ReflectLite.js.map", 22 | "ReflectNoConflict.js", 23 | "ReflectNoConflict.js.map", 24 | "test/**/*.js", 25 | "test/**/*.js.map" 26 | ])); 27 | 28 | gulp.task("build:reflect", () => gulp 29 | .src(["globals.d.ts", "Reflect.ts", "ReflectLite.ts", "ReflectNoConflict.ts"]) 30 | .pipe(project()) 31 | .pipe(gulp.dest("."))); 32 | 33 | gulp.task("build:tests", () => gulp 34 | .src(["test/**/*.ts"]) 35 | .pipe(tests()) 36 | .pipe(gulp.dest("test"))); 37 | 38 | gulp.task("build:spec", () => gulp 39 | .src(["spec.html"]) 40 | .pipe(emu({ js: "ecmarkup.js", css: "ecmarkup.css", biblio: true })) 41 | .pipe(rename(path => { 42 | if (path.basename === "spec" && path.extname === ".html") { 43 | path.basename = "index"; 44 | } 45 | })) 46 | .pipe(gulp.dest("docs"))); 47 | 48 | gulp.task("build", ["build:reflect", "build:tests", "build:spec"]); 49 | 50 | gulp.task("test", ["build:reflect", "build:tests"], () => { 51 | console.log("Running tests..."); 52 | return gulp 53 | .src(["test/**/*.js"], { read: false }) 54 | .pipe(mocha({ reporter: "dot" })); 55 | }); 56 | 57 | gulp.task("watch:reflect", () => gulp.watch([ 58 | "index.d.ts", 59 | "no-conflict.d.ts", 60 | "globals.d.ts", 61 | "Reflect.ts", 62 | "ReflectLite.ts", 63 | "ReflectNoConflict.ts", 64 | "tsconfig.json", 65 | "test/**/*.ts", 66 | "test/**/tsconfig.json" 67 | ], ["test"])); 68 | gulp.task("watch:spec", () => gulp.watch(["spec.html"], ["build:spec"])); 69 | gulp.task("watch", ["watch:reflect", "watch:spec"], () => { 70 | const server = gls.static("docs", 8080); 71 | const promise = server.start(); 72 | gulp.watch(["docs/**/*"], file => server.notify(file)); 73 | return promise; 74 | }); 75 | 76 | gulp.task("prepublish", sequence("release", "clean", "test")); 77 | gulp.task("reflect", ["build:reflect"]); 78 | gulp.task("tests", ["build:tests"]); 79 | gulp.task("spec", ["build:spec"]); 80 | gulp.task("start", ["watch"]); 81 | gulp.task("default", ["build", "test"]); 82 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (C) Microsoft. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | // The "reflect-metadata" module has no imports or exports, but can be imported by modules to load the polyfill. 17 | export { }; 18 | 19 | declare global { 20 | namespace Reflect { 21 | /** 22 | * Applies a set of decorators to a target object. 23 | * @param decorators An array of decorators. 24 | * @param target The target object. 25 | * @returns The result of applying the provided decorators. 26 | * @remarks Decorators are applied in reverse order of their positions in the array. 27 | * @example 28 | * 29 | * class Example { } 30 | * 31 | * // constructor 32 | * Example = Reflect.decorate(decoratorsArray, Example); 33 | * 34 | */ 35 | function decorate(decorators: ClassDecorator[], target: Function): Function; 36 | /** 37 | * Applies a set of decorators to a property of a target object. 38 | * @param decorators An array of decorators. 39 | * @param target The target object. 40 | * @param propertyKey The property key to decorate. 41 | * @param attributes A property descriptor. 42 | * @remarks Decorators are applied in reverse order. 43 | * @example 44 | * 45 | * class Example { 46 | * // property declarations are not part of ES6, though they are valid in TypeScript: 47 | * // static staticProperty; 48 | * // property; 49 | * 50 | * static staticMethod() { } 51 | * method() { } 52 | * } 53 | * 54 | * // property (on constructor) 55 | * Reflect.decorate(decoratorsArray, Example, "staticProperty"); 56 | * 57 | * // property (on prototype) 58 | * Reflect.decorate(decoratorsArray, Example.prototype, "property"); 59 | * 60 | * // method (on constructor) 61 | * Object.defineProperty(Example, "staticMethod", 62 | * Reflect.decorate(decoratorsArray, Example, "staticMethod", 63 | * Object.getOwnPropertyDescriptor(Example, "staticMethod"))); 64 | * 65 | * // method (on prototype) 66 | * Object.defineProperty(Example.prototype, "method", 67 | * Reflect.decorate(decoratorsArray, Example.prototype, "method", 68 | * Object.getOwnPropertyDescriptor(Example.prototype, "method"))); 69 | * 70 | */ 71 | function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: Object, propertyKey: string | symbol, attributes?: PropertyDescriptor): PropertyDescriptor; 72 | /** 73 | * A default metadata decorator factory that can be used on a class, class member, or parameter. 74 | * @param metadataKey The key for the metadata entry. 75 | * @param metadataValue The value for the metadata entry. 76 | * @returns A decorator function. 77 | * @remarks 78 | * If `metadataKey` is already defined for the target and target key, the 79 | * metadataValue for that key will be overwritten. 80 | * @example 81 | * 82 | * // constructor 83 | * @Reflect.metadata(key, value) 84 | * class Example { 85 | * } 86 | * 87 | * // property (on constructor, TypeScript only) 88 | * class Example { 89 | * @Reflect.metadata(key, value) 90 | * static staticProperty; 91 | * } 92 | * 93 | * // property (on prototype, TypeScript only) 94 | * class Example { 95 | * @Reflect.metadata(key, value) 96 | * property; 97 | * } 98 | * 99 | * // method (on constructor) 100 | * class Example { 101 | * @Reflect.metadata(key, value) 102 | * static staticMethod() { } 103 | * } 104 | * 105 | * // method (on prototype) 106 | * class Example { 107 | * @Reflect.metadata(key, value) 108 | * method() { } 109 | * } 110 | * 111 | */ 112 | function metadata(metadataKey: any, metadataValue: any): { 113 | (target: Function): void; 114 | (target: Object, propertyKey: string | symbol): void; 115 | }; 116 | /** 117 | * Define a unique metadata entry on the target. 118 | * @param metadataKey A key used to store and retrieve metadata. 119 | * @param metadataValue A value that contains attached metadata. 120 | * @param target The target object on which to define metadata. 121 | * @example 122 | * 123 | * class Example { 124 | * } 125 | * 126 | * // constructor 127 | * Reflect.defineMetadata("custom:annotation", options, Example); 128 | * 129 | * // decorator factory as metadata-producing annotation. 130 | * function MyAnnotation(options): ClassDecorator { 131 | * return target => Reflect.defineMetadata("custom:annotation", options, target); 132 | * } 133 | * 134 | */ 135 | function defineMetadata(metadataKey: any, metadataValue: any, target: Object): void; 136 | /** 137 | * Define a unique metadata entry on the target. 138 | * @param metadataKey A key used to store and retrieve metadata. 139 | * @param metadataValue A value that contains attached metadata. 140 | * @param target The target object on which to define metadata. 141 | * @param propertyKey The property key for the target. 142 | * @example 143 | * 144 | * class Example { 145 | * // property declarations are not part of ES6, though they are valid in TypeScript: 146 | * // static staticProperty; 147 | * // property; 148 | * 149 | * static staticMethod(p) { } 150 | * method(p) { } 151 | * } 152 | * 153 | * // property (on constructor) 154 | * Reflect.defineMetadata("custom:annotation", Number, Example, "staticProperty"); 155 | * 156 | * // property (on prototype) 157 | * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "property"); 158 | * 159 | * // method (on constructor) 160 | * Reflect.defineMetadata("custom:annotation", Number, Example, "staticMethod"); 161 | * 162 | * // method (on prototype) 163 | * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "method"); 164 | * 165 | * // decorator factory as metadata-producing annotation. 166 | * function MyAnnotation(options): PropertyDecorator { 167 | * return (target, key) => Reflect.defineMetadata("custom:annotation", options, target, key); 168 | * } 169 | * 170 | */ 171 | function defineMetadata(metadataKey: any, metadataValue: any, target: Object, propertyKey: string | symbol): void; 172 | /** 173 | * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. 174 | * @param metadataKey A key used to store and retrieve metadata. 175 | * @param target The target object on which the metadata is defined. 176 | * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. 177 | * @example 178 | * 179 | * class Example { 180 | * } 181 | * 182 | * // constructor 183 | * result = Reflect.hasMetadata("custom:annotation", Example); 184 | * 185 | */ 186 | function hasMetadata(metadataKey: any, target: Object): boolean; 187 | /** 188 | * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. 189 | * @param metadataKey A key used to store and retrieve metadata. 190 | * @param target The target object on which the metadata is defined. 191 | * @param propertyKey The property key for the target. 192 | * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. 193 | * @example 194 | * 195 | * class Example { 196 | * // property declarations are not part of ES6, though they are valid in TypeScript: 197 | * // static staticProperty; 198 | * // property; 199 | * 200 | * static staticMethod(p) { } 201 | * method(p) { } 202 | * } 203 | * 204 | * // property (on constructor) 205 | * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty"); 206 | * 207 | * // property (on prototype) 208 | * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property"); 209 | * 210 | * // method (on constructor) 211 | * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod"); 212 | * 213 | * // method (on prototype) 214 | * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method"); 215 | * 216 | */ 217 | function hasMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; 218 | /** 219 | * Gets a value indicating whether the target object has the provided metadata key defined. 220 | * @param metadataKey A key used to store and retrieve metadata. 221 | * @param target The target object on which the metadata is defined. 222 | * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. 223 | * @example 224 | * 225 | * class Example { 226 | * } 227 | * 228 | * // constructor 229 | * result = Reflect.hasOwnMetadata("custom:annotation", Example); 230 | * 231 | */ 232 | function hasOwnMetadata(metadataKey: any, target: Object): boolean; 233 | /** 234 | * Gets a value indicating whether the target object has the provided metadata key defined. 235 | * @param metadataKey A key used to store and retrieve metadata. 236 | * @param target The target object on which the metadata is defined. 237 | * @param propertyKey The property key for the target. 238 | * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. 239 | * @example 240 | * 241 | * class Example { 242 | * // property declarations are not part of ES6, though they are valid in TypeScript: 243 | * // static staticProperty; 244 | * // property; 245 | * 246 | * static staticMethod(p) { } 247 | * method(p) { } 248 | * } 249 | * 250 | * // property (on constructor) 251 | * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty"); 252 | * 253 | * // property (on prototype) 254 | * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property"); 255 | * 256 | * // method (on constructor) 257 | * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod"); 258 | * 259 | * // method (on prototype) 260 | * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method"); 261 | * 262 | */ 263 | function hasOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; 264 | /** 265 | * Gets the metadata value for the provided metadata key on the target object or its prototype chain. 266 | * @param metadataKey A key used to store and retrieve metadata. 267 | * @param target The target object on which the metadata is defined. 268 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 269 | * @example 270 | * 271 | * class Example { 272 | * } 273 | * 274 | * // constructor 275 | * result = Reflect.getMetadata("custom:annotation", Example); 276 | * 277 | */ 278 | function getMetadata(metadataKey: any, target: Object): any; 279 | /** 280 | * Gets the metadata value for the provided metadata key on the target object or its prototype chain. 281 | * @param metadataKey A key used to store and retrieve metadata. 282 | * @param target The target object on which the metadata is defined. 283 | * @param propertyKey The property key for the target. 284 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 285 | * @example 286 | * 287 | * class Example { 288 | * // property declarations are not part of ES6, though they are valid in TypeScript: 289 | * // static staticProperty; 290 | * // property; 291 | * 292 | * static staticMethod(p) { } 293 | * method(p) { } 294 | * } 295 | * 296 | * // property (on constructor) 297 | * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty"); 298 | * 299 | * // property (on prototype) 300 | * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property"); 301 | * 302 | * // method (on constructor) 303 | * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod"); 304 | * 305 | * // method (on prototype) 306 | * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method"); 307 | * 308 | */ 309 | function getMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any; 310 | /** 311 | * Gets the metadata value for the provided metadata key on the target object. 312 | * @param metadataKey A key used to store and retrieve metadata. 313 | * @param target The target object on which the metadata is defined. 314 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 315 | * @example 316 | * 317 | * class Example { 318 | * } 319 | * 320 | * // constructor 321 | * result = Reflect.getOwnMetadata("custom:annotation", Example); 322 | * 323 | */ 324 | function getOwnMetadata(metadataKey: any, target: Object): any; 325 | /** 326 | * Gets the metadata value for the provided metadata key on the target object. 327 | * @param metadataKey A key used to store and retrieve metadata. 328 | * @param target The target object on which the metadata is defined. 329 | * @param propertyKey The property key for the target. 330 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 331 | * @example 332 | * 333 | * class Example { 334 | * // property declarations are not part of ES6, though they are valid in TypeScript: 335 | * // static staticProperty; 336 | * // property; 337 | * 338 | * static staticMethod(p) { } 339 | * method(p) { } 340 | * } 341 | * 342 | * // property (on constructor) 343 | * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty"); 344 | * 345 | * // property (on prototype) 346 | * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property"); 347 | * 348 | * // method (on constructor) 349 | * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod"); 350 | * 351 | * // method (on prototype) 352 | * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method"); 353 | * 354 | */ 355 | function getOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any; 356 | /** 357 | * Gets the metadata keys defined on the target object or its prototype chain. 358 | * @param target The target object on which the metadata is defined. 359 | * @returns An array of unique metadata keys. 360 | * @example 361 | * 362 | * class Example { 363 | * } 364 | * 365 | * // constructor 366 | * result = Reflect.getMetadataKeys(Example); 367 | * 368 | */ 369 | function getMetadataKeys(target: Object): any[]; 370 | /** 371 | * Gets the metadata keys defined on the target object or its prototype chain. 372 | * @param target The target object on which the metadata is defined. 373 | * @param propertyKey The property key for the target. 374 | * @returns An array of unique metadata keys. 375 | * @example 376 | * 377 | * class Example { 378 | * // property declarations are not part of ES6, though they are valid in TypeScript: 379 | * // static staticProperty; 380 | * // property; 381 | * 382 | * static staticMethod(p) { } 383 | * method(p) { } 384 | * } 385 | * 386 | * // property (on constructor) 387 | * result = Reflect.getMetadataKeys(Example, "staticProperty"); 388 | * 389 | * // property (on prototype) 390 | * result = Reflect.getMetadataKeys(Example.prototype, "property"); 391 | * 392 | * // method (on constructor) 393 | * result = Reflect.getMetadataKeys(Example, "staticMethod"); 394 | * 395 | * // method (on prototype) 396 | * result = Reflect.getMetadataKeys(Example.prototype, "method"); 397 | * 398 | */ 399 | function getMetadataKeys(target: Object, propertyKey: string | symbol): any[]; 400 | /** 401 | * Gets the unique metadata keys defined on the target object. 402 | * @param target The target object on which the metadata is defined. 403 | * @returns An array of unique metadata keys. 404 | * @example 405 | * 406 | * class Example { 407 | * } 408 | * 409 | * // constructor 410 | * result = Reflect.getOwnMetadataKeys(Example); 411 | * 412 | */ 413 | function getOwnMetadataKeys(target: Object): any[]; 414 | /** 415 | * Gets the unique metadata keys defined on the target object. 416 | * @param target The target object on which the metadata is defined. 417 | * @param propertyKey The property key for the target. 418 | * @returns An array of unique metadata keys. 419 | * @example 420 | * 421 | * class Example { 422 | * // property declarations are not part of ES6, though they are valid in TypeScript: 423 | * // static staticProperty; 424 | * // property; 425 | * 426 | * static staticMethod(p) { } 427 | * method(p) { } 428 | * } 429 | * 430 | * // property (on constructor) 431 | * result = Reflect.getOwnMetadataKeys(Example, "staticProperty"); 432 | * 433 | * // property (on prototype) 434 | * result = Reflect.getOwnMetadataKeys(Example.prototype, "property"); 435 | * 436 | * // method (on constructor) 437 | * result = Reflect.getOwnMetadataKeys(Example, "staticMethod"); 438 | * 439 | * // method (on prototype) 440 | * result = Reflect.getOwnMetadataKeys(Example.prototype, "method"); 441 | * 442 | */ 443 | function getOwnMetadataKeys(target: Object, propertyKey: string | symbol): any[]; 444 | /** 445 | * Deletes the metadata entry from the target object with the provided key. 446 | * @param metadataKey A key used to store and retrieve metadata. 447 | * @param target The target object on which the metadata is defined. 448 | * @returns `true` if the metadata entry was found and deleted; otherwise, false. 449 | * @example 450 | * 451 | * class Example { 452 | * } 453 | * 454 | * // constructor 455 | * result = Reflect.deleteMetadata("custom:annotation", Example); 456 | * 457 | */ 458 | function deleteMetadata(metadataKey: any, target: Object): boolean; 459 | /** 460 | * Deletes the metadata entry from the target object with the provided key. 461 | * @param metadataKey A key used to store and retrieve metadata. 462 | * @param target The target object on which the metadata is defined. 463 | * @param propertyKey The property key for the target. 464 | * @returns `true` if the metadata entry was found and deleted; otherwise, false. 465 | * @example 466 | * 467 | * class Example { 468 | * // property declarations are not part of ES6, though they are valid in TypeScript: 469 | * // static staticProperty; 470 | * // property; 471 | * 472 | * static staticMethod(p) { } 473 | * method(p) { } 474 | * } 475 | * 476 | * // property (on constructor) 477 | * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty"); 478 | * 479 | * // property (on prototype) 480 | * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property"); 481 | * 482 | * // method (on constructor) 483 | * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod"); 484 | * 485 | * // method (on prototype) 486 | * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method"); 487 | * 488 | */ 489 | function deleteMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; 490 | } 491 | } -------------------------------------------------------------------------------- /no-conflict.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (C) Microsoft. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | /** 17 | * Applies a set of decorators to a target object. 18 | * @param decorators An array of decorators. 19 | * @param target The target object. 20 | * @returns The result of applying the provided decorators. 21 | * @remarks Decorators are applied in reverse order of their positions in the array. 22 | * @example 23 | * 24 | * class Example { } 25 | * 26 | * // constructor 27 | * Example = Reflect.decorate(decoratorsArray, Example); 28 | * 29 | */ 30 | export declare function decorate(decorators: ClassDecorator[], target: Function): Function; 31 | /** 32 | * Applies a set of decorators to a property of a target object. 33 | * @param decorators An array of decorators. 34 | * @param target The target object. 35 | * @param propertyKey The property key to decorate. 36 | * @param attributes A property descriptor. 37 | * @remarks Decorators are applied in reverse order. 38 | * @example 39 | * 40 | * class Example { 41 | * // property declarations are not part of ES6, though they are valid in TypeScript: 42 | * // static staticProperty; 43 | * // property; 44 | * 45 | * static staticMethod() { } 46 | * method() { } 47 | * } 48 | * 49 | * // property (on constructor) 50 | * Reflect.decorate(decoratorsArray, Example, "staticProperty"); 51 | * 52 | * // property (on prototype) 53 | * Reflect.decorate(decoratorsArray, Example.prototype, "property"); 54 | * 55 | * // method (on constructor) 56 | * Object.defineProperty(Example, "staticMethod", 57 | * Reflect.decorate(decoratorsArray, Example, "staticMethod", 58 | * Object.getOwnPropertyDescriptor(Example, "staticMethod"))); 59 | * 60 | * // method (on prototype) 61 | * Object.defineProperty(Example.prototype, "method", 62 | * Reflect.decorate(decoratorsArray, Example.prototype, "method", 63 | * Object.getOwnPropertyDescriptor(Example.prototype, "method"))); 64 | * 65 | */ 66 | export declare function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: Object, propertyKey: string | symbol, attributes?: PropertyDescriptor): PropertyDescriptor; 67 | /** 68 | * A default metadata decorator factory that can be used on a class, class member, or parameter. 69 | * @param metadataKey The key for the metadata entry. 70 | * @param metadataValue The value for the metadata entry. 71 | * @returns A decorator function. 72 | * @remarks 73 | * If `metadataKey` is already defined for the target and target key, the 74 | * metadataValue for that key will be overwritten. 75 | * @example 76 | * 77 | * // constructor 78 | * @Reflect.metadata(key, value) 79 | * class Example { 80 | * } 81 | * 82 | * // property (on constructor, TypeScript only) 83 | * class Example { 84 | * @Reflect.metadata(key, value) 85 | * static staticProperty; 86 | * } 87 | * 88 | * // property (on prototype, TypeScript only) 89 | * class Example { 90 | * @Reflect.metadata(key, value) 91 | * property; 92 | * } 93 | * 94 | * // method (on constructor) 95 | * class Example { 96 | * @Reflect.metadata(key, value) 97 | * static staticMethod() { } 98 | * } 99 | * 100 | * // method (on prototype) 101 | * class Example { 102 | * @Reflect.metadata(key, value) 103 | * method() { } 104 | * } 105 | * 106 | */ 107 | export declare function metadata(metadataKey: any, metadataValue: any): { 108 | (target: Function): void; 109 | (target: Object, propertyKey: string | symbol): void; 110 | }; 111 | /** 112 | * Define a unique metadata entry on the target. 113 | * @param metadataKey A key used to store and retrieve metadata. 114 | * @param metadataValue A value that contains attached metadata. 115 | * @param target The target object on which to define metadata. 116 | * @example 117 | * 118 | * class Example { 119 | * } 120 | * 121 | * // constructor 122 | * Reflect.defineMetadata("custom:annotation", options, Example); 123 | * 124 | * // decorator factory as metadata-producing annotation. 125 | * function MyAnnotation(options): ClassDecorator { 126 | * return target => Reflect.defineMetadata("custom:annotation", options, target); 127 | * } 128 | * 129 | */ 130 | export declare function defineMetadata(metadataKey: any, metadataValue: any, target: Object): void; 131 | /** 132 | * Define a unique metadata entry on the target. 133 | * @param metadataKey A key used to store and retrieve metadata. 134 | * @param metadataValue A value that contains attached metadata. 135 | * @param target The target object on which to define metadata. 136 | * @param propertyKey The property key for the target. 137 | * @example 138 | * 139 | * class Example { 140 | * // property declarations are not part of ES6, though they are valid in TypeScript: 141 | * // static staticProperty; 142 | * // property; 143 | * 144 | * static staticMethod(p) { } 145 | * method(p) { } 146 | * } 147 | * 148 | * // property (on constructor) 149 | * Reflect.defineMetadata("custom:annotation", Number, Example, "staticProperty"); 150 | * 151 | * // property (on prototype) 152 | * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "property"); 153 | * 154 | * // method (on constructor) 155 | * Reflect.defineMetadata("custom:annotation", Number, Example, "staticMethod"); 156 | * 157 | * // method (on prototype) 158 | * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "method"); 159 | * 160 | * // decorator factory as metadata-producing annotation. 161 | * function MyAnnotation(options): PropertyDecorator { 162 | * return (target, key) => Reflect.defineMetadata("custom:annotation", options, target, key); 163 | * } 164 | * 165 | */ 166 | export declare function defineMetadata(metadataKey: any, metadataValue: any, target: Object, propertyKey: string | symbol): void; 167 | /** 168 | * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. 169 | * @param metadataKey A key used to store and retrieve metadata. 170 | * @param target The target object on which the metadata is defined. 171 | * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. 172 | * @example 173 | * 174 | * class Example { 175 | * } 176 | * 177 | * // constructor 178 | * result = Reflect.hasMetadata("custom:annotation", Example); 179 | * 180 | */ 181 | export declare function hasMetadata(metadataKey: any, target: Object): boolean; 182 | /** 183 | * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. 184 | * @param metadataKey A key used to store and retrieve metadata. 185 | * @param target The target object on which the metadata is defined. 186 | * @param propertyKey The property key for the target. 187 | * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. 188 | * @example 189 | * 190 | * class Example { 191 | * // property declarations are not part of ES6, though they are valid in TypeScript: 192 | * // static staticProperty; 193 | * // property; 194 | * 195 | * static staticMethod(p) { } 196 | * method(p) { } 197 | * } 198 | * 199 | * // property (on constructor) 200 | * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty"); 201 | * 202 | * // property (on prototype) 203 | * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property"); 204 | * 205 | * // method (on constructor) 206 | * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod"); 207 | * 208 | * // method (on prototype) 209 | * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method"); 210 | * 211 | */ 212 | export declare function hasMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; 213 | /** 214 | * Gets a value indicating whether the target object has the provided metadata key defined. 215 | * @param metadataKey A key used to store and retrieve metadata. 216 | * @param target The target object on which the metadata is defined. 217 | * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. 218 | * @example 219 | * 220 | * class Example { 221 | * } 222 | * 223 | * // constructor 224 | * result = Reflect.hasOwnMetadata("custom:annotation", Example); 225 | * 226 | */ 227 | export declare function hasOwnMetadata(metadataKey: any, target: Object): boolean; 228 | /** 229 | * Gets a value indicating whether the target object has the provided metadata key defined. 230 | * @param metadataKey A key used to store and retrieve metadata. 231 | * @param target The target object on which the metadata is defined. 232 | * @param propertyKey The property key for the target. 233 | * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. 234 | * @example 235 | * 236 | * class Example { 237 | * // property declarations are not part of ES6, though they are valid in TypeScript: 238 | * // static staticProperty; 239 | * // property; 240 | * 241 | * static staticMethod(p) { } 242 | * method(p) { } 243 | * } 244 | * 245 | * // property (on constructor) 246 | * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty"); 247 | * 248 | * // property (on prototype) 249 | * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property"); 250 | * 251 | * // method (on constructor) 252 | * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod"); 253 | * 254 | * // method (on prototype) 255 | * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method"); 256 | * 257 | */ 258 | export declare function hasOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; 259 | /** 260 | * Gets the metadata value for the provided metadata key on the target object or its prototype chain. 261 | * @param metadataKey A key used to store and retrieve metadata. 262 | * @param target The target object on which the metadata is defined. 263 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 264 | * @example 265 | * 266 | * class Example { 267 | * } 268 | * 269 | * // constructor 270 | * result = Reflect.getMetadata("custom:annotation", Example); 271 | * 272 | */ 273 | export declare function getMetadata(metadataKey: any, target: Object): any; 274 | /** 275 | * Gets the metadata value for the provided metadata key on the target object or its prototype chain. 276 | * @param metadataKey A key used to store and retrieve metadata. 277 | * @param target The target object on which the metadata is defined. 278 | * @param propertyKey The property key for the target. 279 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 280 | * @example 281 | * 282 | * class Example { 283 | * // property declarations are not part of ES6, though they are valid in TypeScript: 284 | * // static staticProperty; 285 | * // property; 286 | * 287 | * static staticMethod(p) { } 288 | * method(p) { } 289 | * } 290 | * 291 | * // property (on constructor) 292 | * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty"); 293 | * 294 | * // property (on prototype) 295 | * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property"); 296 | * 297 | * // method (on constructor) 298 | * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod"); 299 | * 300 | * // method (on prototype) 301 | * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method"); 302 | * 303 | */ 304 | export declare function getMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any; 305 | /** 306 | * Gets the metadata value for the provided metadata key on the target object. 307 | * @param metadataKey A key used to store and retrieve metadata. 308 | * @param target The target object on which the metadata is defined. 309 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 310 | * @example 311 | * 312 | * class Example { 313 | * } 314 | * 315 | * // constructor 316 | * result = Reflect.getOwnMetadata("custom:annotation", Example); 317 | * 318 | */ 319 | export declare function getOwnMetadata(metadataKey: any, target: Object): any; 320 | /** 321 | * Gets the metadata value for the provided metadata key on the target object. 322 | * @param metadataKey A key used to store and retrieve metadata. 323 | * @param target The target object on which the metadata is defined. 324 | * @param propertyKey The property key for the target. 325 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 326 | * @example 327 | * 328 | * class Example { 329 | * // property declarations are not part of ES6, though they are valid in TypeScript: 330 | * // static staticProperty; 331 | * // property; 332 | * 333 | * static staticMethod(p) { } 334 | * method(p) { } 335 | * } 336 | * 337 | * // property (on constructor) 338 | * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty"); 339 | * 340 | * // property (on prototype) 341 | * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property"); 342 | * 343 | * // method (on constructor) 344 | * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod"); 345 | * 346 | * // method (on prototype) 347 | * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method"); 348 | * 349 | */ 350 | export declare function getOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any; 351 | /** 352 | * Gets the metadata keys defined on the target object or its prototype chain. 353 | * @param target The target object on which the metadata is defined. 354 | * @returns An array of unique metadata keys. 355 | * @example 356 | * 357 | * class Example { 358 | * } 359 | * 360 | * // constructor 361 | * result = Reflect.getMetadataKeys(Example); 362 | * 363 | */ 364 | export declare function getMetadataKeys(target: Object): any[]; 365 | /** 366 | * Gets the metadata keys defined on the target object or its prototype chain. 367 | * @param target The target object on which the metadata is defined. 368 | * @param propertyKey The property key for the target. 369 | * @returns An array of unique metadata keys. 370 | * @example 371 | * 372 | * class Example { 373 | * // property declarations are not part of ES6, though they are valid in TypeScript: 374 | * // static staticProperty; 375 | * // property; 376 | * 377 | * static staticMethod(p) { } 378 | * method(p) { } 379 | * } 380 | * 381 | * // property (on constructor) 382 | * result = Reflect.getMetadataKeys(Example, "staticProperty"); 383 | * 384 | * // property (on prototype) 385 | * result = Reflect.getMetadataKeys(Example.prototype, "property"); 386 | * 387 | * // method (on constructor) 388 | * result = Reflect.getMetadataKeys(Example, "staticMethod"); 389 | * 390 | * // method (on prototype) 391 | * result = Reflect.getMetadataKeys(Example.prototype, "method"); 392 | * 393 | */ 394 | export declare function getMetadataKeys(target: Object, propertyKey: string | symbol): any[]; 395 | /** 396 | * Gets the unique metadata keys defined on the target object. 397 | * @param target The target object on which the metadata is defined. 398 | * @returns An array of unique metadata keys. 399 | * @example 400 | * 401 | * class Example { 402 | * } 403 | * 404 | * // constructor 405 | * result = Reflect.getOwnMetadataKeys(Example); 406 | * 407 | */ 408 | export declare function getOwnMetadataKeys(target: Object): any[]; 409 | /** 410 | * Gets the unique metadata keys defined on the target object. 411 | * @param target The target object on which the metadata is defined. 412 | * @param propertyKey The property key for the target. 413 | * @returns An array of unique metadata keys. 414 | * @example 415 | * 416 | * class Example { 417 | * // property declarations are not part of ES6, though they are valid in TypeScript: 418 | * // static staticProperty; 419 | * // property; 420 | * 421 | * static staticMethod(p) { } 422 | * method(p) { } 423 | * } 424 | * 425 | * // property (on constructor) 426 | * result = Reflect.getOwnMetadataKeys(Example, "staticProperty"); 427 | * 428 | * // property (on prototype) 429 | * result = Reflect.getOwnMetadataKeys(Example.prototype, "property"); 430 | * 431 | * // method (on constructor) 432 | * result = Reflect.getOwnMetadataKeys(Example, "staticMethod"); 433 | * 434 | * // method (on prototype) 435 | * result = Reflect.getOwnMetadataKeys(Example.prototype, "method"); 436 | * 437 | */ 438 | export declare function getOwnMetadataKeys(target: Object, propertyKey: string | symbol): any[]; 439 | /** 440 | * Deletes the metadata entry from the target object with the provided key. 441 | * @param metadataKey A key used to store and retrieve metadata. 442 | * @param target The target object on which the metadata is defined. 443 | * @returns `true` if the metadata entry was found and deleted; otherwise, false. 444 | * @example 445 | * 446 | * class Example { 447 | * } 448 | * 449 | * // constructor 450 | * result = Reflect.deleteMetadata("custom:annotation", Example); 451 | * 452 | */ 453 | export declare function deleteMetadata(metadataKey: any, target: Object): boolean; 454 | /** 455 | * Deletes the metadata entry from the target object with the provided key. 456 | * @param metadataKey A key used to store and retrieve metadata. 457 | * @param target The target object on which the metadata is defined. 458 | * @param propertyKey The property key for the target. 459 | * @returns `true` if the metadata entry was found and deleted; otherwise, false. 460 | * @example 461 | * 462 | * class Example { 463 | * // property declarations are not part of ES6, though they are valid in TypeScript: 464 | * // static staticProperty; 465 | * // property; 466 | * 467 | * static staticMethod(p) { } 468 | * method(p) { } 469 | * } 470 | * 471 | * // property (on constructor) 472 | * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty"); 473 | * 474 | * // property (on prototype) 475 | * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property"); 476 | * 477 | * // method (on constructor) 478 | * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod"); 479 | * 480 | * // method (on prototype) 481 | * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method"); 482 | * 483 | */ 484 | export declare function deleteMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; 485 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reflect-metadata", 3 | "version": "0.2.2", 4 | "description": "Polyfill for Metadata Reflection API", 5 | "type": "commonjs", 6 | "main": "Reflect.js", 7 | "types": "index.d.ts", 8 | "exports": { 9 | ".": { 10 | "types": "./index.d.ts", 11 | "default": "./Reflect.js" 12 | }, 13 | "./lite": { 14 | "types": "./index.d.ts", 15 | "default": "./ReflectLite.js" 16 | }, 17 | "./no-conflict": { 18 | "types": "./no-conflict.d.ts", 19 | "default": "./ReflectNoConflict.js" 20 | }, 21 | "./Reflect": "./Reflect.js", 22 | "./Reflect.js": "./Reflect.js" 23 | }, 24 | "scripts": { 25 | "prepublishOnly": "gulp prepublish", 26 | "build": "gulp build", 27 | "test": "gulp test", 28 | "start": "gulp start" 29 | }, 30 | "repository": { 31 | "type": "git", 32 | "url": "https://github.com/rbuckton/reflect-metadata.git" 33 | }, 34 | "keywords": [ 35 | "decorator", 36 | "metadata", 37 | "javascript", 38 | "reflect" 39 | ], 40 | "author": { 41 | "name": "Ron Buckton", 42 | "email": "ron.buckton@microsoft.com", 43 | "url": "http://github.com/rbuckton" 44 | }, 45 | "license": "Apache-2.0", 46 | "bugs": { 47 | "url": "https://github.com/rbuckton/reflect-metadata/issues" 48 | }, 49 | "homepage": "http://rbuckton.github.io/reflect-metadata", 50 | "dependencies": {}, 51 | "devDependencies": { 52 | "@types/chai": "^3.4.34", 53 | "@types/mocha": "^2.2.34", 54 | "@types/node": "^10.17.60", 55 | "chai": "^3.5.0", 56 | "del": "^2.2.2", 57 | "ecmarkup": "^3.9.3", 58 | "gulp": "^3.9.1", 59 | "gulp-emu": "^1.1.0", 60 | "gulp-live-server": "0.0.30", 61 | "gulp-mocha": "^3.0.1", 62 | "gulp-rename": "^1.2.2", 63 | "gulp-sequence": "^0.4.6", 64 | "gulp-tsb": "^2.0.3", 65 | "mocha": "^3.2.0", 66 | "typescript": "^2.1.4" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /spec.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | Metadata Proposal - ECMAScript 4 | 5 | 6 | 7 | 12 | 19 | 20 | 21 |

Metadata Proposal - ECMAScript

22 | A shim for this API can be found here: https://github.com/rbuckton/ReflectDecorators 23 |

Proposal to add Metadata to ECMAScript.

24 |
25 | 26 | 27 |

Syntax

28 | This section is non-normative. 29 |

 30 |     // define metadata on an object or property
 31 |     Reflect.defineMetadata(metadataKey, metadataValue, target);
 32 |     Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey);
 33 | 
 34 |     // check for presence of a metadata key on the prototype chain of an object or property
 35 |     let result = Reflect.hasMetadata(metadataKey, target);
 36 |     let result = Reflect.hasMetadata(metadataKey, target, propertyKey);
 37 | 
 38 |     // check for presence of an own metadata key of an object or property
 39 |     let result = Reflect.hasOwnMetadata(metadataKey, target);
 40 |     let result = Reflect.hasOwnMetadata(metadataKey, target, propertyKey);
 41 | 
 42 |     // get metadata value of a metadata key on the prototype chain of an object or property
 43 |     let result = Reflect.getMetadata(metadataKey, target);
 44 |     let result = Reflect.getMetadata(metadataKey, target, propertyKey);
 45 | 
 46 |     // get metadata value of an own metadata key of an object or property
 47 |     let result = Reflect.getOwnMetadata(metadataKey, target);
 48 |     let result = Reflect.getOwnMetadata(metadataKey, target, propertyKey);
 49 | 
 50 |     // get all metadata keys on the prototype chain of an object or property
 51 |     let result = Reflect.getMetadataKeys(target);
 52 |     let result = Reflect.getMetadataKeys(target, propertyKey);
 53 | 
 54 |     // get all own metadata keys of an object or property
 55 |     let result = Reflect.getOwnMetadataKeys(target);
 56 |     let result = Reflect.getOwnMetadataKeys(target, propertyKey);
 57 | 
 58 |     // delete metadata from an object or property
 59 |     let result = Reflect.deleteMetadata(metadataKey, target);
 60 |     let result = Reflect.deleteMetadata(metadataKey, target, propertyKey);
 61 | 
 62 |     // apply metadata via a decorator to a constructor
 63 |     @Reflect.metadata(metadataKey, metadataValue)
 64 |     class C {
 65 |       // apply metadata via a decorator to a method (property)
 66 |       @Reflect.metadata(metadataKey, metadataValue)
 67 |       method() {
 68 |       }
 69 |     }
 70 | 
 71 |     // Design-time type annotations
 72 |     function Type(type) { return Reflect.metadata("design:type", type); }
 73 |     function ParamTypes(...types) { return Reflect.metadata("design:paramtypes", types); }
 74 |     function ReturnType(type) { return Reflect.metadata("design:returntype", type); }
 75 | 
 76 |     // Decorator application
 77 |     @ParamTypes(String, Number)
 78 |     class C {
 79 |       constructor(text, i) {
 80 |       }
 81 | 
 82 |       @Type(String)
 83 |       get name() { return "text"; }
 84 | 
 85 |       @Type(Function)
 86 |       @ParamTypes(Number, Number)
 87 |       @ReturnType(Number)
 88 |       add(x, y) {
 89 |         return x + y;
 90 |       }
 91 |     }
 92 | 
 93 |     // Metadata introspection
 94 |     let obj = new C("a", 1);
 95 |     let paramTypes = Reflect.getMetadata("design:paramtypes", obj, "add"); // [Number, Number]
 96 |   
97 |
98 | 99 | 100 |

Abstract Operations

101 | 102 |

Operations on Objects

103 | 104 |

GetOrCreateMetadataMap ( O, P, Create )

105 |

When the abstract operation GetOrCreateMetadataMap is called with Object _O_, property key _P_, and Boolean _Create_ the following steps are taken:

106 | 107 | 1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 108 | 2. Let _targetMetadata_ be the value of _O_'s [[Metadata]] internal slot. 109 | 3. If _targetMetadata_ is *undefined*, then 110 | 1. If _Create_ is *false*, return *undefined*. 111 | 2. Set _targetMetadata_ to be a newly created *Map* object. 112 | 3. Set the [[Metadata]] internal slot of _O_ to _targetMetadata_. 113 | 4. Let _metadataMap_ be ? Invoke(_targetMetadata_, `"get"`, _P_). 114 | 5. If _metadataMap_ is *undefined*, then 115 | 1. If _Create_ is *false*, return *undefined*. 116 | 2. Set _metadataMap_ to be a newly created *Map* object. 117 | 3. Perform ? Invoke(_targetMetadata_, `"set"`, _P_, _metadataMap_). 118 | 6. Return _metadataMap_. 119 | 120 |
121 |
122 |
123 | 124 | 125 |

Ordinary and Exotic Objects Behaviors

126 | 127 | 128 |

Ordinary Object Internal Methods and Internal Slots

129 |

All ordinary objects have an internal slot called [[Metadata]]. The value of this internal slot is either *null* or a *Map* object and is used for storing metadata for an object.

130 | 131 |

[[HasMetadata]] ( MetadataKey, P )

132 |

When the [[HasMetadata]] internal method of _O_ is called with ECMAScript language value _MetadataKey_ and property key _P_, the following steps are taken:

133 | 134 | 1. Return ? OrdinaryHasMetadata(_MetadataKey_, _O_, _P_). 135 | 136 | 137 |

OrdinaryHasMetadata ( MetadataKey, O, P )

138 |

When the abstract operation OrdinaryHasMetadata is called with ECMAScript language value _MetadataKey_, Object _O_, and property key _P_, the following steps are taken:

139 | 140 | 1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 141 | 2. Let _hasOwn_ be ? OrdinaryHasOwnMetadata(_MetadataKey_, _O_, _P_). 142 | 3. If _hasOwn_ is *true*, return *true*. 143 | 4. Let _parent_ be ? _O_.[[GetPrototypeOf]](). 144 | 5. If _parent_ is not *null*, Return ? _parent_.[[HasMetadata]](_MetadataKey_, _P_). 145 | 6. Return *false*. 146 | 147 |
148 |
149 | 150 | 151 |

[[HasOwnMetadata]] ( MetadataKey, P )

152 |

When the [[HasOwnMetadata]] internal method of _O_ is called with ECMAScript language value _MetadataKey_ and property key _P_, the following steps are taken:

153 | 154 | 1. Return ? OrdinaryHasOwnMetadata(_MetadataKey_, _O_, _P_). 155 | 156 | 157 |

OrdinaryHasOwnMetadata ( MetadataKey, O, P )

158 |

When the abstract operation OrdinaryHasOwnMetadata is called with ECMAScript language value _MetadataKey_, Object _O_, and property key _P_, the following steps are taken:

159 | 160 | 1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 161 | 2. Let _metadataMap_ be ? GetOrCreateMetadataMap(_O_, _P_, *false*). 162 | 3. If _metadataMap_ is *undefined*, return *false*. 163 | 4. Return ? ToBoolean(? Invoke(_metadataMap_, `"has"`, _MetadataKey_)). 164 | 165 |
166 |
167 | 168 | 169 |

[[GetMetadata]] ( MetadataKey, P )

170 |

When the [[GetMatadata]] internal method of _O_ is called with ECMAScript language value _MetadataKey_ and property key _P_, the following steps are taken:

171 | 172 | 1. Return ? OrdinaryGetMetadata(_MetadataKey_, _O_, _P_). 173 | 174 | 175 |

OrdinaryGetMetadata ( MetadataKey, O, P )

176 |

When the abstract operation OrdinaryGetMetadata is called with ECMAScript language value _MetadataKey_, Object _O_, and property key _P_, the following steps are taken:

177 | 178 | 1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 179 | 2. Let _hasOwn_ be ? OrdinaryHasOwnMetadata(_MetadataKey_, _O_, _P_). 180 | 3. If _hasOwn_ is *true*, return ? OrdinaryGetOwnMetadata(_MetadataKey_, _O_, _P_). 181 | 4. Let _parent_ be ? _O_.[[GetPrototypeOf]](). 182 | 5. If _parent_ is not *null*, return ? _parent_.[[GetMetadata]](_MetadataKey_, _P_). 183 | 6. Return *undefined*. 184 | 185 |
186 |
187 | 188 | 189 |

[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )

190 |

When the [[GetOwnMetadata]] internal method of _O_ is called with ECMAScript language value _MetadataKey_ and property key _P_, the following steps are taken:

191 | 192 | 1. Return ? OrdinaryGetOwnMetadata(_MetadataKey_, _O_, _P_). 193 | 194 | 195 |

OrdinaryGetOwnMetadata ( MetadataKey, O, P )

196 |

When the abstract operation OrdinaryGetOwnMetadata is called with ECMAScript language value _MetadataKey_, Object _O_, and property key _P_, the following steps are taken:

197 | 198 | 1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 199 | 2. Let _metadataMap_ be ? GetOrCreateMetadataMap(_O_, _P_, *false*). 200 | 3. If _metadataMap_ is *undefined*, return *undefined*. 201 | 4. Return ? Invoke(_metadataMap_, `"get"`, _MetadataKey_). 202 | 203 |
204 |
205 | 206 | 207 |

[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )

208 |

When the [[DefineOwnMetadata]] internal method of _O_ is called with ECMAScript language value _MetadataKey_, ECMAScript language value _MetadataValue_, and property key _P_, the following steps are taken:

209 | 210 | 1. Return ? OrdinaryDefineOwnMetadata(_MetadataKey_, _MetadataValue_, _O_, _P_) 211 | 212 | 213 |

OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )

214 |

When the abstract operation OrdinaryDefineOwnProperty is called with ECMAScript language value _MetadataKey_, ECMAScript language value _MetadataValue_, Object _O_, and property key _P_, the following steps are taken:

215 | 216 | 1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 217 | 2. Let _metadataMap_ be ? GetOrCreateMetadataMap(_O_, _P_, *true*). 218 | 3. Return ? Invoke(_metadataMap_, `"set"`, _MetadataKey_, _MetadataValue_). 219 | 220 |
221 |
222 | 223 | 224 |

[[MetadataKeys]] ( P )

225 |

When the [[MetadataKeys]] internal method of _O_ is called with property key _P_ the following steps are taken:

226 | 227 | 1. Return ? OrdinaryMetadataKeys(_O_, _P_). 228 | 229 | 230 |

OrdinaryMetadataKeys ( O, P )

231 |

When the abstract operation OrdinaryMetadataKeys is called with Object _O_ and property key _P_ the following steps are taken:

232 | 233 | 1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 234 | 2. Let _ownKeys_ be ? OrdinaryOwnMetadataKeys(_O_, _P_). 235 | 3. Let _parent_ be ? _O_.[[GetPrototypeOf]](). 236 | 4. If _parent_ is *null*, then return _ownKeys_. 237 | 5. Let _parentKeys_ be ? _O_.[[OrdinaryMetadataKeys]](_P_). 238 | 6. Let _ownKeysLen_ = ? Get(_ownKeys_, "length"). 239 | 7. If _ownKeysLen_ is *0*, return _parentKeys_. 240 | 8. Let _parentKeysLen_ = ? Get(_parentKeys_, "length"). 241 | 9. If _parentKeysLen_ is *0*, return _ownKeys_. 242 | 10. Let _set_ be a newly created *Set* object. 243 | 11. Let _keys_ be ? ArrayCreate(0). 244 | 12. Let _k_ be *0*. 245 | 13. For each element _key_ of _ownKeys_ 246 | 1. Let _hasKey_ be ? Invoke(_set_, `"has"`, _key_). 247 | 2. If _hasKey_ is *false*, then 248 | 1. Let _Pk_ be ! ToString(_k_). 249 | 2. Perform ? Invoke(_set_, "add", _key_). 250 | 3. Let _defineStatus_ be CreateDataProperty(_keys_, _Pk_, _key_). 251 | 4. Assert: _defineStatus_ is *true*. 252 | 5. Increase _k_ by *1*. 253 | 14. For each element _key_ of _parentKeys_ 254 | 1. Let _hasKey_ be ? Invoke(_set_, `"has"`, _key_). 255 | 2. If _hasKey_ is *false*, then 256 | 1. Let _Pk_ be ! ToString(_k_). 257 | 2. Perform ? Invoke(_set_, `"add"`, _key_). 258 | 3. Let _defineStatus_ be CreateDataProperty(_keys_, _Pk_, _key_). 259 | 4. Assert: _defineStatus_ is *true*. 260 | 5. Increase _k_ by *1*. 261 | 15. Perform ? Set(_keys_, `"length"`, _k_). 262 | 16. return _keys_. 263 | 264 |
265 |
266 | 267 | 268 |

[[OwnMetadataKeys]] ( P )

269 |

When the [[OwnMetadataKeys]] internal method of _O_ is called with property key _P_ the following steps are taken:

270 | 271 | 1. Return OrdinaryOwnMetadataKeys(_O_, _P_). 272 | 273 | 274 |

OrdinaryOwnMetadataKeys ( O, P )

275 |

When the abstract operation OrdinaryOwnMetadataKeys is called with Object _O_ and property key _P_ the following steps are taken:

276 | 277 | 1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 278 | 2. Let _keys_ be ? ArrayCreate(0). 279 | 3. Let _metadataMap_ be ? GetOrCreateMetadataMap(_O_, _P_, *false*). 280 | 4. If _metadataMap_ is *undefined*, return _keys_. 281 | 5. Let _keysObj_ be ? Invoke(_metadataMap_, `"keys"`). 282 | 6. Let _iterator_ be ? GetIterator(_keysObj_). 283 | 7. Let _k_ be *0*. 284 | 8. Repeat 285 | 1. Let _Pk_ be ! ToString(_k_). 286 | 2. Let _next_ be ? IteratorStep(_iterator_). 287 | 3. If _next_ is *false*, then 288 | 1. Let _setStatus_ be ? Set(_keys_, `"length"`, _k_, _true_). 289 | 2. Assert: _setStatus_ is *true*. 290 | 3. Return _keys_. 291 | 4. Let _nextValue_ be ? IteratorValue(_next_). 292 | 5. Let _defineStatus_ be CreateDataPropertyOrThrow(_keys_, _Pk_, _nextValue_). 293 | 6. If _defineStatus_ is an abrupt completion, return ? IteratorClose(_iterator_, _defineStatus_). 294 | 7. Increase _k_ by *1*. 295 | 296 |
297 |
298 | 299 | 300 |

[[DeleteMetadata]]( MetadataKey, P )

301 |

When the [[DeleteMetadata]] internal method of _O_ is called with ECMAScript language value _MetadataKey_ and property key _P_ the following steps are taken:

302 | 303 | 1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 304 | 2. Let _metadataMap_ be ? GetOrCreateMetadataMap(_O_, _P_, *false*). 305 | 4. If _metadataMap_ is *undefined*, return *false*. 306 | 5. Return ? Invoke(_metadataMap_, `"delete"`, _MetadataKey_). 307 | 308 |
309 |
310 |
311 | 312 | 313 |

Reflection

314 | 315 |

The Reflect Object

316 |

This section contains amendments to the Reflect object.

317 | 318 |

Metadata Decorator Functions

319 |

A metadata decorator function is an anonymous built-in function that has [[MetadataKey]] and [[MetadataValue]] internal slots.

320 |

When a metadata decorator function _F_ is called with arguments _target_ and _key_, the following steps are taken:

321 | 322 | 1. Assert: _F_ has a [[MetadataKey]] internal slot whose value is an ECMAScript language value, or *undefined*. 323 | 2. Assert: _F_ has a [[MetadataValue]] internal slot whose value is an ECMAScript language value, or *undefined*. 324 | 3. If Type(_target_) is not Object, throw a *TypeError* exception. 325 | 4. If _key_ is not *undefined* and IsPropertyKey(_key_) is *false*, throw a *TypeError* exception. 326 | 5. Let _metadataKey_ be the value of _F_'s [[MetadataKey]] internal slot. 327 | 6. Let _metadataValue_ be the value of _F_'s [[MetadataValue]] internal slot. 328 | 7. Perform ? _target_.[[DefineMetadata]](_metadataKey_, _metadataValue_, _target_, _key_). 329 | 8. Return *undefined*. 330 | 331 |
332 | 333 | 334 |

Reflect.metadata ( metadataKey, metadataValue )

335 |

When the `metadata` function is called with arguments _metadataKey_ and _metadataValue_, the following steps are taken:

336 | 337 | 1. Let _decorator_ be a new built-in function object as defined in Metadata Decorator Functions. 338 | 2. Set the [[MetadataKey]] internal slot of _decorator_ to _metadataKey_. 339 | 3. Set the [[MetadataValue]] internal slot of _decorator_ to _metadataValue_. 340 | 4. Return _decorator_. 341 | 342 |
343 | 344 | 345 |

Reflect.defineMetadata ( metadataKey, metadataValue, target [, propertyKey] )

346 |

When the `defineMetadata` function is called with arguments _metadataKey_, _metadataValue_, _target_, and _propertyKey_, the following steps are taken:

347 | 348 | 1. If Type(_target_) is not Object, throw a *TypeError* exception. 349 | 2. Return ? _target_.[[DefineMetadata]](_metadataKey_, _metadataValue_, _propertyKey_). 350 | 351 |
352 | 353 | 354 |

Reflect.hasMetadata ( metadataKey, target [, propertyKey] )

355 |

When the `hasMetadata` function is called with arguments _metadataKey_, _target_, and _propertyKey_, the following steps are taken:

356 | 357 | 1. If Type(_target_) is not Object, throw a *TypeError* exception. 358 | 2. Return ? _target_.[[HasMetadata]](_metadataKey_, _propertyKey_). 359 | 360 |
361 | 362 | 363 |

Reflect.hasOwnMetadata ( metadataKey, target [, propertyKey] )

364 |

When the `hasOwnMetadata` function is called with arguments _metadataKey_, _target_, and _propertyKey_, the following steps are taken:

365 | 366 | 1. If Type(_target_) is not Object, throw a *TypeError* exception. 367 | 2. Return ? _target_.[[HasOwn]](_metadataKey_, _propertyKey_). 368 | 369 |
370 | 371 | 372 |

Reflect.getMetadata ( metadataKey, target [, propertyKey] )

373 |

When the `getMetadata` function is called with arguments _metadataKey_, _target_, and _propertyKey_, the following steps are taken:

374 | 375 | 1. If Type(_target_) is not Object, throw a *TypeError* exception. 376 | 2. Return ? _target_.[[GetMetadata]](_metadataKey_, _propertyKey_). 377 | 378 |
379 | 380 | 381 |

Reflect.getOwnMetadata ( metadataKey, target [, propertyKey] )

382 |

When the `getOwnMetadata` function is called with arguments _metadataKey_, _target_, and _propertyKey_, the following steps are taken:

383 | 384 | 1. If Type(_target_) is not Object, throw a *TypeError* exception. 385 | 2. Return ? _target_.[[GetOwnMetadata]](_metadataKey_, _propertyKey_). 386 | 387 |
388 | 389 | 390 |

Reflect.getMetadataKeys ( target [, propertyKey] )

391 |

When the `getMetadataKeys` function is called with arguments _target_ and _propertyKey_, the following steps are taken:

392 | 393 | 1. If Type(_target_) is not Object, throw a *TypeError* exception. 394 | 2. Return ? _target_.[[GetMetadataKeys]](_propertyKey_). 395 | 396 |
397 | 398 | 399 |

Reflect.getOwnMetadataKeys ( target [, propertyKey] )

400 |

When the `getOwnMetadataKeys` function is called with arguments _target_ and _propertyKey_, the following steps are taken:

401 | 402 | 1. If Type(_target_) is not Object, throw a *TypeError* exception. 403 | 2. Return ? _target_.[[GetOwnMetadataKeys]](_propertyKey_). 404 | 405 |
406 | 407 | 408 |

Reflect.deleteMetadata ( metadataKey, target [, propertyKey] )

409 |

When the `deleteMetadata` function is called with arguments _metadataKey_, _target_, and _propertyKey_, the following steps are taken:

410 | 411 | 1. If Type(_target_) is not Object, throw a *TypeError* exception. 412 | 2. Return ? _target_.[[DeleteMetadata]](_metadataKey_, _propertyKey_). 413 | 414 |
415 |
416 |
417 | -------------------------------------------------------------------------------- /spec/metadata.md: -------------------------------------------------------------------------------- 1 | # Metadata Reflection API 2 | 3 | The spec has moved to https://rbuckton.github.io/reflect-metadata/ -------------------------------------------------------------------------------- /standalone.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (C) Microsoft. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | declare namespace Reflect { 16 | /** 17 | * Applies a set of decorators to a target object. 18 | * @param decorators An array of decorators. 19 | * @param target The target object. 20 | * @returns The result of applying the provided decorators. 21 | * @remarks Decorators are applied in reverse order of their positions in the array. 22 | * @example 23 | * 24 | * class Example { } 25 | * 26 | * // constructor 27 | * Example = Reflect.decorate(decoratorsArray, Example); 28 | * 29 | */ 30 | function decorate(decorators: ClassDecorator[], target: Function): Function; 31 | /** 32 | * Applies a set of decorators to a property of a target object. 33 | * @param decorators An array of decorators. 34 | * @param target The target object. 35 | * @param propertyKey The property key to decorate. 36 | * @param attributes A property descriptor. 37 | * @remarks Decorators are applied in reverse order. 38 | * @example 39 | * 40 | * class Example { 41 | * // property declarations are not part of ES6, though they are valid in TypeScript: 42 | * // static staticProperty; 43 | * // property; 44 | * 45 | * static staticMethod() { } 46 | * method() { } 47 | * } 48 | * 49 | * // property (on constructor) 50 | * Reflect.decorate(decoratorsArray, Example, "staticProperty"); 51 | * 52 | * // property (on prototype) 53 | * Reflect.decorate(decoratorsArray, Example.prototype, "property"); 54 | * 55 | * // method (on constructor) 56 | * Object.defineProperty(Example, "staticMethod", 57 | * Reflect.decorate(decoratorsArray, Example, "staticMethod", 58 | * Object.getOwnPropertyDescriptor(Example, "staticMethod"))); 59 | * 60 | * // method (on prototype) 61 | * Object.defineProperty(Example.prototype, "method", 62 | * Reflect.decorate(decoratorsArray, Example.prototype, "method", 63 | * Object.getOwnPropertyDescriptor(Example.prototype, "method"))); 64 | * 65 | */ 66 | function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: Object, propertyKey: string | symbol, attributes?: PropertyDescriptor): PropertyDescriptor; 67 | /** 68 | * A default metadata decorator factory that can be used on a class, class member, or parameter. 69 | * @param metadataKey The key for the metadata entry. 70 | * @param metadataValue The value for the metadata entry. 71 | * @returns A decorator function. 72 | * @remarks 73 | * If `metadataKey` is already defined for the target and target key, the 74 | * metadataValue for that key will be overwritten. 75 | * @example 76 | * 77 | * // constructor 78 | * @Reflect.metadata(key, value) 79 | * class Example { 80 | * } 81 | * 82 | * // property (on constructor, TypeScript only) 83 | * class Example { 84 | * @Reflect.metadata(key, value) 85 | * static staticProperty; 86 | * } 87 | * 88 | * // property (on prototype, TypeScript only) 89 | * class Example { 90 | * @Reflect.metadata(key, value) 91 | * property; 92 | * } 93 | * 94 | * // method (on constructor) 95 | * class Example { 96 | * @Reflect.metadata(key, value) 97 | * static staticMethod() { } 98 | * } 99 | * 100 | * // method (on prototype) 101 | * class Example { 102 | * @Reflect.metadata(key, value) 103 | * method() { } 104 | * } 105 | * 106 | */ 107 | function metadata(metadataKey: any, metadataValue: any): { 108 | (target: Function): void; 109 | (target: Object, propertyKey: string | symbol): void; 110 | }; 111 | /** 112 | * Define a unique metadata entry on the target. 113 | * @param metadataKey A key used to store and retrieve metadata. 114 | * @param metadataValue A value that contains attached metadata. 115 | * @param target The target object on which to define metadata. 116 | * @example 117 | * 118 | * class Example { 119 | * } 120 | * 121 | * // constructor 122 | * Reflect.defineMetadata("custom:annotation", options, Example); 123 | * 124 | * // decorator factory as metadata-producing annotation. 125 | * function MyAnnotation(options): ClassDecorator { 126 | * return target => Reflect.defineMetadata("custom:annotation", options, target); 127 | * } 128 | * 129 | */ 130 | function defineMetadata(metadataKey: any, metadataValue: any, target: Object): void; 131 | /** 132 | * Define a unique metadata entry on the target. 133 | * @param metadataKey A key used to store and retrieve metadata. 134 | * @param metadataValue A value that contains attached metadata. 135 | * @param target The target object on which to define metadata. 136 | * @param propertyKey The property key for the target. 137 | * @example 138 | * 139 | * class Example { 140 | * // property declarations are not part of ES6, though they are valid in TypeScript: 141 | * // static staticProperty; 142 | * // property; 143 | * 144 | * static staticMethod(p) { } 145 | * method(p) { } 146 | * } 147 | * 148 | * // property (on constructor) 149 | * Reflect.defineMetadata("custom:annotation", Number, Example, "staticProperty"); 150 | * 151 | * // property (on prototype) 152 | * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "property"); 153 | * 154 | * // method (on constructor) 155 | * Reflect.defineMetadata("custom:annotation", Number, Example, "staticMethod"); 156 | * 157 | * // method (on prototype) 158 | * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "method"); 159 | * 160 | * // decorator factory as metadata-producing annotation. 161 | * function MyAnnotation(options): PropertyDecorator { 162 | * return (target, key) => Reflect.defineMetadata("custom:annotation", options, target, key); 163 | * } 164 | * 165 | */ 166 | function defineMetadata(metadataKey: any, metadataValue: any, target: Object, propertyKey: string | symbol): void; 167 | /** 168 | * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. 169 | * @param metadataKey A key used to store and retrieve metadata. 170 | * @param target The target object on which the metadata is defined. 171 | * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. 172 | * @example 173 | * 174 | * class Example { 175 | * } 176 | * 177 | * // constructor 178 | * result = Reflect.hasMetadata("custom:annotation", Example); 179 | * 180 | */ 181 | function hasMetadata(metadataKey: any, target: Object): boolean; 182 | /** 183 | * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. 184 | * @param metadataKey A key used to store and retrieve metadata. 185 | * @param target The target object on which the metadata is defined. 186 | * @param propertyKey The property key for the target. 187 | * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. 188 | * @example 189 | * 190 | * class Example { 191 | * // property declarations are not part of ES6, though they are valid in TypeScript: 192 | * // static staticProperty; 193 | * // property; 194 | * 195 | * static staticMethod(p) { } 196 | * method(p) { } 197 | * } 198 | * 199 | * // property (on constructor) 200 | * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty"); 201 | * 202 | * // property (on prototype) 203 | * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property"); 204 | * 205 | * // method (on constructor) 206 | * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod"); 207 | * 208 | * // method (on prototype) 209 | * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method"); 210 | * 211 | */ 212 | function hasMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; 213 | /** 214 | * Gets a value indicating whether the target object has the provided metadata key defined. 215 | * @param metadataKey A key used to store and retrieve metadata. 216 | * @param target The target object on which the metadata is defined. 217 | * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. 218 | * @example 219 | * 220 | * class Example { 221 | * } 222 | * 223 | * // constructor 224 | * result = Reflect.hasOwnMetadata("custom:annotation", Example); 225 | * 226 | */ 227 | function hasOwnMetadata(metadataKey: any, target: Object): boolean; 228 | /** 229 | * Gets a value indicating whether the target object has the provided metadata key defined. 230 | * @param metadataKey A key used to store and retrieve metadata. 231 | * @param target The target object on which the metadata is defined. 232 | * @param propertyKey The property key for the target. 233 | * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. 234 | * @example 235 | * 236 | * class Example { 237 | * // property declarations are not part of ES6, though they are valid in TypeScript: 238 | * // static staticProperty; 239 | * // property; 240 | * 241 | * static staticMethod(p) { } 242 | * method(p) { } 243 | * } 244 | * 245 | * // property (on constructor) 246 | * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty"); 247 | * 248 | * // property (on prototype) 249 | * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property"); 250 | * 251 | * // method (on constructor) 252 | * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod"); 253 | * 254 | * // method (on prototype) 255 | * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method"); 256 | * 257 | */ 258 | function hasOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; 259 | /** 260 | * Gets the metadata value for the provided metadata key on the target object or its prototype chain. 261 | * @param metadataKey A key used to store and retrieve metadata. 262 | * @param target The target object on which the metadata is defined. 263 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 264 | * @example 265 | * 266 | * class Example { 267 | * } 268 | * 269 | * // constructor 270 | * result = Reflect.getMetadata("custom:annotation", Example); 271 | * 272 | */ 273 | function getMetadata(metadataKey: any, target: Object): any; 274 | /** 275 | * Gets the metadata value for the provided metadata key on the target object or its prototype chain. 276 | * @param metadataKey A key used to store and retrieve metadata. 277 | * @param target The target object on which the metadata is defined. 278 | * @param propertyKey The property key for the target. 279 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 280 | * @example 281 | * 282 | * class Example { 283 | * // property declarations are not part of ES6, though they are valid in TypeScript: 284 | * // static staticProperty; 285 | * // property; 286 | * 287 | * static staticMethod(p) { } 288 | * method(p) { } 289 | * } 290 | * 291 | * // property (on constructor) 292 | * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty"); 293 | * 294 | * // property (on prototype) 295 | * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property"); 296 | * 297 | * // method (on constructor) 298 | * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod"); 299 | * 300 | * // method (on prototype) 301 | * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method"); 302 | * 303 | */ 304 | function getMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any; 305 | /** 306 | * Gets the metadata value for the provided metadata key on the target object. 307 | * @param metadataKey A key used to store and retrieve metadata. 308 | * @param target The target object on which the metadata is defined. 309 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 310 | * @example 311 | * 312 | * class Example { 313 | * } 314 | * 315 | * // constructor 316 | * result = Reflect.getOwnMetadata("custom:annotation", Example); 317 | * 318 | */ 319 | function getOwnMetadata(metadataKey: any, target: Object): any; 320 | /** 321 | * Gets the metadata value for the provided metadata key on the target object. 322 | * @param metadataKey A key used to store and retrieve metadata. 323 | * @param target The target object on which the metadata is defined. 324 | * @param propertyKey The property key for the target. 325 | * @returns The metadata value for the metadata key if found; otherwise, `undefined`. 326 | * @example 327 | * 328 | * class Example { 329 | * // property declarations are not part of ES6, though they are valid in TypeScript: 330 | * // static staticProperty; 331 | * // property; 332 | * 333 | * static staticMethod(p) { } 334 | * method(p) { } 335 | * } 336 | * 337 | * // property (on constructor) 338 | * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty"); 339 | * 340 | * // property (on prototype) 341 | * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property"); 342 | * 343 | * // method (on constructor) 344 | * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod"); 345 | * 346 | * // method (on prototype) 347 | * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method"); 348 | * 349 | */ 350 | function getOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any; 351 | /** 352 | * Gets the metadata keys defined on the target object or its prototype chain. 353 | * @param target The target object on which the metadata is defined. 354 | * @returns An array of unique metadata keys. 355 | * @example 356 | * 357 | * class Example { 358 | * } 359 | * 360 | * // constructor 361 | * result = Reflect.getMetadataKeys(Example); 362 | * 363 | */ 364 | function getMetadataKeys(target: Object): any[]; 365 | /** 366 | * Gets the metadata keys defined on the target object or its prototype chain. 367 | * @param target The target object on which the metadata is defined. 368 | * @param propertyKey The property key for the target. 369 | * @returns An array of unique metadata keys. 370 | * @example 371 | * 372 | * class Example { 373 | * // property declarations are not part of ES6, though they are valid in TypeScript: 374 | * // static staticProperty; 375 | * // property; 376 | * 377 | * static staticMethod(p) { } 378 | * method(p) { } 379 | * } 380 | * 381 | * // property (on constructor) 382 | * result = Reflect.getMetadataKeys(Example, "staticProperty"); 383 | * 384 | * // property (on prototype) 385 | * result = Reflect.getMetadataKeys(Example.prototype, "property"); 386 | * 387 | * // method (on constructor) 388 | * result = Reflect.getMetadataKeys(Example, "staticMethod"); 389 | * 390 | * // method (on prototype) 391 | * result = Reflect.getMetadataKeys(Example.prototype, "method"); 392 | * 393 | */ 394 | function getMetadataKeys(target: Object, propertyKey: string | symbol): any[]; 395 | /** 396 | * Gets the unique metadata keys defined on the target object. 397 | * @param target The target object on which the metadata is defined. 398 | * @returns An array of unique metadata keys. 399 | * @example 400 | * 401 | * class Example { 402 | * } 403 | * 404 | * // constructor 405 | * result = Reflect.getOwnMetadataKeys(Example); 406 | * 407 | */ 408 | function getOwnMetadataKeys(target: Object): any[]; 409 | /** 410 | * Gets the unique metadata keys defined on the target object. 411 | * @param target The target object on which the metadata is defined. 412 | * @param propertyKey The property key for the target. 413 | * @returns An array of unique metadata keys. 414 | * @example 415 | * 416 | * class Example { 417 | * // property declarations are not part of ES6, though they are valid in TypeScript: 418 | * // static staticProperty; 419 | * // property; 420 | * 421 | * static staticMethod(p) { } 422 | * method(p) { } 423 | * } 424 | * 425 | * // property (on constructor) 426 | * result = Reflect.getOwnMetadataKeys(Example, "staticProperty"); 427 | * 428 | * // property (on prototype) 429 | * result = Reflect.getOwnMetadataKeys(Example.prototype, "property"); 430 | * 431 | * // method (on constructor) 432 | * result = Reflect.getOwnMetadataKeys(Example, "staticMethod"); 433 | * 434 | * // method (on prototype) 435 | * result = Reflect.getOwnMetadataKeys(Example.prototype, "method"); 436 | * 437 | */ 438 | function getOwnMetadataKeys(target: Object, propertyKey: string | symbol): any[]; 439 | /** 440 | * Deletes the metadata entry from the target object with the provided key. 441 | * @param metadataKey A key used to store and retrieve metadata. 442 | * @param target The target object on which the metadata is defined. 443 | * @returns `true` if the metadata entry was found and deleted; otherwise, false. 444 | * @example 445 | * 446 | * class Example { 447 | * } 448 | * 449 | * // constructor 450 | * result = Reflect.deleteMetadata("custom:annotation", Example); 451 | * 452 | */ 453 | function deleteMetadata(metadataKey: any, target: Object): boolean; 454 | /** 455 | * Deletes the metadata entry from the target object with the provided key. 456 | * @param metadataKey A key used to store and retrieve metadata. 457 | * @param target The target object on which the metadata is defined. 458 | * @param propertyKey The property key for the target. 459 | * @returns `true` if the metadata entry was found and deleted; otherwise, false. 460 | * @example 461 | * 462 | * class Example { 463 | * // property declarations are not part of ES6, though they are valid in TypeScript: 464 | * // static staticProperty; 465 | * // property; 466 | * 467 | * static staticMethod(p) { } 468 | * method(p) { } 469 | * } 470 | * 471 | * // property (on constructor) 472 | * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty"); 473 | * 474 | * // property (on prototype) 475 | * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property"); 476 | * 477 | * // method (on constructor) 478 | * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod"); 479 | * 480 | * // method (on prototype) 481 | * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method"); 482 | * 483 | */ 484 | function deleteMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; 485 | } -------------------------------------------------------------------------------- /test/reflect-decorate.ts: -------------------------------------------------------------------------------- 1 | // Reflect.decorate ( decorators, target [, propertyKey [, descriptor] ] ) 2 | 3 | /// 4 | import { assert } from "chai"; 5 | import { script } from "./vm"; 6 | import { suites } from "./suites"; 7 | 8 | for (const { name, header, context } of suites) { 9 | describe(name, () => { 10 | describe("Reflect.decorate", () => { 11 | it("ThrowsIfDecoratorsArgumentNotArrayForFunctionOverload", () => { 12 | const { Reflect, TypeError } = script(context)` 13 | ${header} 14 | exports.Reflect = Reflect; 15 | exports.TypeError = TypeError; 16 | `; 17 | let target = function() { }; 18 | assert.throws(() => Reflect.decorate(undefined!, target, undefined!, undefined), TypeError); 19 | }); 20 | 21 | it("ThrowsIfTargetArgumentNotFunctionForFunctionOverload", () => { 22 | const { Reflect, TypeError } = script(context)` 23 | ${header} 24 | exports.Reflect = Reflect; 25 | exports.TypeError = TypeError; 26 | `; 27 | let decorators: (MethodDecorator | PropertyDecorator)[] = []; 28 | let target = {}; 29 | assert.throws(() => Reflect.decorate(decorators, target, undefined!, undefined), TypeError); 30 | }); 31 | 32 | it("ThrowsIfDecoratorsArgumentNotArrayForPropertyOverload", () => { 33 | const { Reflect, TypeError } = script(context)` 34 | ${header} 35 | exports.Reflect = Reflect; 36 | exports.TypeError = TypeError; 37 | `; 38 | let target = {}; 39 | let name = "name"; 40 | assert.throws(() => Reflect.decorate(undefined!, target, name, undefined), TypeError); 41 | }); 42 | 43 | it("ThrowsIfTargetArgumentNotObjectForPropertyOverload", () => { 44 | const { Reflect, TypeError } = script(context)` 45 | ${header} 46 | exports.Reflect = Reflect; 47 | exports.TypeError = TypeError; 48 | `; 49 | let decorators: (MethodDecorator | PropertyDecorator)[] = []; 50 | let target = 1; 51 | let name = "name"; 52 | assert.throws(() => Reflect.decorate(decorators, target, name, undefined), TypeError); 53 | }); 54 | 55 | it("ThrowsIfDecoratorsArgumentNotArrayForPropertyDescriptorOverload", () => { 56 | const { Reflect, TypeError } = script(context)` 57 | ${header} 58 | exports.Reflect = Reflect; 59 | exports.TypeError = TypeError; 60 | `; 61 | let target = {}; 62 | let name = "name"; 63 | let descriptor = {}; 64 | assert.throws(() => Reflect.decorate(undefined!, target, name, descriptor), TypeError); 65 | }); 66 | 67 | it("ThrowsIfTargetArgumentNotObjectForPropertyDescriptorOverload", () => { 68 | const { Reflect, TypeError } = script(context)` 69 | ${header} 70 | exports.Reflect = Reflect; 71 | exports.TypeError = TypeError; 72 | `; 73 | let decorators: (MethodDecorator | PropertyDecorator)[] = []; 74 | let target = 1; 75 | let name = "name"; 76 | let descriptor = {}; 77 | assert.throws(() => Reflect.decorate(decorators, target, name, descriptor), TypeError); 78 | }); 79 | 80 | it("ExecutesDecoratorsInReverseOrderForFunctionOverload", () => { 81 | const { Reflect } = script(context)` 82 | ${header} 83 | exports.Reflect = Reflect; 84 | `; 85 | let order: number[] = []; 86 | let decorators = [ 87 | (_target: Function): void => { order.push(0); }, 88 | (_target: Function): void => { order.push(1); } 89 | ]; 90 | let target = function() { }; 91 | Reflect.decorate(decorators, target); 92 | assert.deepEqual(order, [1, 0]); 93 | }); 94 | 95 | it("ExecutesDecoratorsInReverseOrderForPropertyOverload", () => { 96 | const { Reflect } = script(context)` 97 | ${header} 98 | exports.Reflect = Reflect; 99 | `; 100 | let order: number[] = []; 101 | let decorators = [ 102 | (_target: Object, _name: string | symbol): void => { order.push(0); }, 103 | (_target: Object, _name: string | symbol): void => { order.push(1); } 104 | ]; 105 | let target = {}; 106 | let name = "name"; 107 | Reflect.decorate(decorators, target, name, undefined); 108 | assert.deepEqual(order, [1, 0]); 109 | }); 110 | 111 | it("ExecutesDecoratorsInReverseOrderForPropertyDescriptorOverload", () => { 112 | const { Reflect } = script(context)` 113 | ${header} 114 | exports.Reflect = Reflect; 115 | `; 116 | let order: number[] = []; 117 | let decorators = [ 118 | (_target: Object, _name: string | symbol): void => { order.push(0); }, 119 | (_target: Object, _name: string | symbol): void => { order.push(1); } 120 | ]; 121 | let target = {}; 122 | let name = "name"; 123 | let descriptor = {}; 124 | Reflect.decorate(decorators, target, name, descriptor); 125 | assert.deepEqual(order, [1, 0]); 126 | }); 127 | 128 | it("DecoratorPipelineForFunctionOverload", () => { 129 | const { Reflect } = script(context)` 130 | ${header} 131 | exports.Reflect = Reflect; 132 | `; 133 | let A = function A(): void { }; 134 | let B = function B(): void { }; 135 | let decorators = [ 136 | (_target: Function): any => { return undefined; }, 137 | (_target: Function): any => { return A; }, 138 | (_target: Function): any => { return B; } 139 | ]; 140 | let target = function (): void { }; 141 | let result = Reflect.decorate(decorators, target); 142 | assert.strictEqual(result, A); 143 | }); 144 | 145 | it("DecoratorPipelineForPropertyOverload", () => { 146 | const { Reflect } = script(context)` 147 | ${header} 148 | exports.Reflect = Reflect; 149 | `; 150 | let A = {}; 151 | let B = {}; 152 | let decorators = [ 153 | (_target: Object, _name: string | symbol): any => { return undefined; }, 154 | (_target: Object, _name: string | symbol): any => { return A; }, 155 | (_target: Object, _name: string | symbol): any => { return B; } 156 | ]; 157 | let target = {}; 158 | let result = Reflect.decorate(decorators, target, "name", undefined); 159 | assert.strictEqual(result, A); 160 | }); 161 | 162 | it("DecoratorPipelineForPropertyDescriptorOverload", () => { 163 | const { Reflect } = script(context)` 164 | ${header} 165 | exports.Reflect = Reflect; 166 | `; 167 | let A = {}; 168 | let B = {}; 169 | let C = {}; 170 | let decorators = [ 171 | (_target: Object, _name: string | symbol): any => { return undefined; }, 172 | (_target: Object, _name: string | symbol): any => { return A; }, 173 | (_target: Object, _name: string | symbol): any => { return B; } 174 | ]; 175 | let target = {}; 176 | let result = Reflect.decorate(decorators, target, "name", C); 177 | assert.strictEqual(result, A); 178 | }); 179 | 180 | it("DecoratorCorrectTargetInPipelineForFunctionOverload", () => { 181 | const { Reflect } = script(context)` 182 | ${header} 183 | exports.Reflect = Reflect; 184 | `; 185 | let sent: Function[] = []; 186 | let A = function A(): void { }; 187 | let B = function B(): void { }; 188 | let decorators = [ 189 | (target: Function): any => { sent.push(target); return undefined; }, 190 | (target: Function): any => { sent.push(target); return undefined; }, 191 | (target: Function): any => { sent.push(target); return A; }, 192 | (target: Function): any => { sent.push(target); return B; } 193 | ]; 194 | let target = function (): void { }; 195 | Reflect.decorate(decorators, target); 196 | assert.deepEqual(sent, [target, B, A, A]); 197 | }); 198 | 199 | it("DecoratorCorrectTargetInPipelineForPropertyOverload", () => { 200 | const { Reflect } = script(context)` 201 | ${header} 202 | exports.Reflect = Reflect; 203 | `; 204 | let sent: Object[] = []; 205 | let decorators = [ 206 | (target: Object, _name: string | symbol): any => { sent.push(target); }, 207 | (target: Object, _name: string | symbol): any => { sent.push(target); }, 208 | (target: Object, _name: string | symbol): any => { sent.push(target); }, 209 | (target: Object, _name: string | symbol): any => { sent.push(target); } 210 | ]; 211 | let target = { }; 212 | Reflect.decorate(decorators, target, "name"); 213 | assert.deepEqual(sent, [target, target, target, target]); 214 | }); 215 | 216 | it("DecoratorCorrectNameInPipelineForPropertyOverload", () => { 217 | const { Reflect } = script(context)` 218 | ${header} 219 | exports.Reflect = Reflect; 220 | `; 221 | let sent: (symbol | string)[] = []; 222 | let decorators = [ 223 | (_target: Object, name: string | symbol): any => { sent.push(name); }, 224 | (_target: Object, name: string | symbol): any => { sent.push(name); }, 225 | (_target: Object, name: string | symbol): any => { sent.push(name); }, 226 | (_target: Object, name: string | symbol): any => { sent.push(name); } 227 | ]; 228 | let target = { }; 229 | Reflect.decorate(decorators, target, "name"); 230 | assert.deepEqual(sent, ["name", "name", "name", "name"]); 231 | }); 232 | 233 | it("DecoratorCorrectTargetInPipelineForPropertyDescriptorOverload", () => { 234 | const { Reflect } = script(context)` 235 | ${header} 236 | exports.Reflect = Reflect; 237 | `; 238 | let sent: Object[] = []; 239 | let A = { }; 240 | let B = { }; 241 | let C = { }; 242 | let decorators = [ 243 | (target: Object, _name: string | symbol): any => { sent.push(target); return undefined; }, 244 | (target: Object, _name: string | symbol): any => { sent.push(target); return undefined; }, 245 | (target: Object, _name: string | symbol): any => { sent.push(target); return A; }, 246 | (target: Object, _name: string | symbol): any => { sent.push(target); return B; } 247 | ]; 248 | let target = { }; 249 | Reflect.decorate(decorators, target, "name", C); 250 | assert.deepEqual(sent, [target, target, target, target]); 251 | }); 252 | 253 | it("DecoratorCorrectNameInPipelineForPropertyDescriptorOverload", () => { 254 | const { Reflect } = script(context)` 255 | ${header} 256 | exports.Reflect = Reflect; 257 | `; 258 | let sent: (symbol | string)[] = []; 259 | let A = { }; 260 | let B = { }; 261 | let C = { }; 262 | let decorators = [ 263 | (_target: Object, name: string | symbol): any => { sent.push(name); return undefined; }, 264 | (_target: Object, name: string | symbol): any => { sent.push(name); return undefined; }, 265 | (_target: Object, name: string | symbol): any => { sent.push(name); return A; }, 266 | (_target: Object, name: string | symbol): any => { sent.push(name); return B; } 267 | ]; 268 | let target = { }; 269 | Reflect.decorate(decorators, target, "name", C); 270 | assert.deepEqual(sent, ["name", "name", "name", "name"]); 271 | }); 272 | 273 | it("DecoratorCorrectDescriptorInPipelineForPropertyDescriptorOverload", () => { 274 | const { Reflect } = script(context)` 275 | ${header} 276 | exports.Reflect = Reflect; 277 | `; 278 | let sent: PropertyDescriptor[] = []; 279 | let A = { }; 280 | let B = { }; 281 | let C = { }; 282 | let decorators = [ 283 | (_target: Object, _name: string | symbol, descriptor: PropertyDescriptor): any => { sent.push(descriptor); return undefined; }, 284 | (_target: Object, _name: string | symbol, descriptor: PropertyDescriptor): any => { sent.push(descriptor); return undefined; }, 285 | (_target: Object, _name: string | symbol, descriptor: PropertyDescriptor): any => { sent.push(descriptor); return A; }, 286 | (_target: Object, _name: string | symbol, descriptor: PropertyDescriptor): any => { sent.push(descriptor); return B; } 287 | ]; 288 | let target = { }; 289 | Reflect.decorate(decorators, target, "name", C); 290 | assert.deepEqual(sent, [C, B, A, A]); 291 | }); 292 | }); 293 | }); 294 | } 295 | -------------------------------------------------------------------------------- /test/reflect-definemetadata.ts: -------------------------------------------------------------------------------- 1 | // 4.1.2 Reflect.defineMetadata ( metadataKey, metadataValue, target, propertyKey ) 2 | // https://rbuckton.github.io/reflect-metadata/#reflect.definemetadata 3 | 4 | /// 5 | import { assert } from "chai"; 6 | import { script } from "./vm"; 7 | import { suites } from "./suites"; 8 | 9 | for (const { name, header, context } of suites) { 10 | describe(name, () => { 11 | describe("Reflect.defineMetadata", () => { 12 | it("InvalidTarget", () => { 13 | const { Reflect, TypeError } = script(context)` 14 | ${header} 15 | exports.Reflect = Reflect; 16 | exports.TypeError = TypeError; 17 | `; 18 | assert.throws(() => Reflect.defineMetadata("key", "value", undefined, undefined!), TypeError); 19 | }); 20 | 21 | it("ValidTargetWithoutTargetKey", () => { 22 | const { Reflect } = script(context)` 23 | ${header} 24 | exports.Reflect = Reflect; 25 | `; 26 | assert.doesNotThrow(() => Reflect.defineMetadata("key", "value", { }, undefined!)); 27 | }); 28 | 29 | it("ValidTargetWithTargetKey", () => { 30 | const { Reflect } = script(context)` 31 | ${header} 32 | exports.Reflect = Reflect; 33 | `; 34 | assert.doesNotThrow(() => Reflect.defineMetadata("key", "value", { }, "name")); 35 | }); 36 | }); 37 | }); 38 | } -------------------------------------------------------------------------------- /test/reflect-deletemetadata.ts: -------------------------------------------------------------------------------- 1 | // 4.1.10 Reflect.deleteMetadata ( metadataKey, target [, propertyKey] ) 2 | // https://rbuckton.github.io/reflect-metadata/#reflect.deletemetadata 3 | 4 | /// 5 | import { assert } from "chai"; 6 | import { script } from "./vm"; 7 | import { suites } from "./suites"; 8 | 9 | for (const { name, header, context } of suites) { 10 | describe(name, () => { 11 | describe("Reflect.deleteMetadata", () => { 12 | it("InvalidTarget", () => { 13 | const { Reflect, TypeError } = script(context)` 14 | ${header} 15 | exports.Reflect = Reflect; 16 | exports.TypeError = TypeError; 17 | `; 18 | assert.throws(() => Reflect.deleteMetadata("key", undefined, undefined!), TypeError); 19 | }); 20 | 21 | it("WhenNotDefinedWithoutTargetKey", () => { 22 | const { Reflect } = script(context)` 23 | ${header} 24 | exports.Reflect = Reflect; 25 | `; 26 | let obj = {}; 27 | let result = Reflect.deleteMetadata("key", obj, undefined!); 28 | assert.equal(result, false); 29 | }); 30 | 31 | it("WhenDefinedWithoutTargetKey", () => { 32 | const { Reflect } = script(context)` 33 | ${header} 34 | exports.Reflect = Reflect; 35 | `; 36 | let obj = {}; 37 | Reflect.defineMetadata("key", "value", obj, undefined!); 38 | let result = Reflect.deleteMetadata("key", obj, undefined!); 39 | assert.equal(result, true); 40 | }); 41 | 42 | it("WhenDefinedOnPrototypeWithoutTargetKey", () => { 43 | const { Reflect } = script(context)` 44 | ${header} 45 | exports.Reflect = Reflect; 46 | `; 47 | let prototype = {}; 48 | Reflect.defineMetadata("key", "value", prototype, undefined!); 49 | let obj = Object.create(prototype); 50 | let result = Reflect.deleteMetadata("key", obj, undefined!); 51 | assert.equal(result, false); 52 | }); 53 | 54 | it("AfterDeleteMetadata", () => { 55 | const { Reflect } = script(context)` 56 | ${header} 57 | exports.Reflect = Reflect; 58 | `; 59 | let obj = {}; 60 | Reflect.defineMetadata("key", "value", obj, undefined!); 61 | Reflect.deleteMetadata("key", obj, undefined!); 62 | let result = Reflect.hasOwnMetadata("key", obj, undefined!); 63 | assert.equal(result, false); 64 | }); 65 | }); 66 | }); 67 | } -------------------------------------------------------------------------------- /test/reflect-getmetadata.ts: -------------------------------------------------------------------------------- 1 | // 4.1.5 Reflect.getMetadata ( metadataKey, target [, propertyKey] ) 2 | // https://rbuckton.github.io/reflect-metadata/#reflect.getmetadata 3 | 4 | /// 5 | import { assert } from "chai"; 6 | import { script } from "./vm"; 7 | import { suites } from "./suites"; 8 | 9 | for (const { name, header, context } of suites) { 10 | describe(name, () => { 11 | describe("Reflect.getMetadata", () => { 12 | it("InvalidTarget", () => { 13 | const { Reflect, TypeError } = script(context)` 14 | ${header} 15 | exports.Reflect = Reflect; 16 | exports.TypeError = TypeError; 17 | `; 18 | assert.throws(() => Reflect.getMetadata("key", undefined, undefined!), TypeError); 19 | }); 20 | 21 | it("WithoutTargetKeyWhenNotDefined", () => { 22 | const { Reflect } = script(context)` 23 | ${header} 24 | exports.Reflect = Reflect; 25 | `; 26 | let obj = {}; 27 | let result = Reflect.getMetadata("key", obj, undefined!); 28 | assert.equal(result, undefined); 29 | }); 30 | 31 | it("WithoutTargetKeyWhenDefined", () => { 32 | const { Reflect } = script(context)` 33 | ${header} 34 | exports.Reflect = Reflect; 35 | `; 36 | let obj = {}; 37 | Reflect.defineMetadata("key", "value", obj, undefined!); 38 | let result = Reflect.getMetadata("key", obj, undefined!); 39 | assert.equal(result, "value"); 40 | }); 41 | 42 | it("WithoutTargetKeyWhenDefinedOnPrototype", () => { 43 | const { Reflect } = script(context)` 44 | ${header} 45 | exports.Reflect = Reflect; 46 | `; 47 | let prototype = {}; 48 | let obj = Object.create(prototype); 49 | Reflect.defineMetadata("key", "value", prototype, undefined!); 50 | let result = Reflect.getMetadata("key", obj, undefined!); 51 | assert.equal(result, "value"); 52 | }); 53 | 54 | it("WithTargetKeyWhenNotDefined", () => { 55 | const { Reflect } = script(context)` 56 | ${header} 57 | exports.Reflect = Reflect; 58 | `; 59 | let obj = {}; 60 | let result = Reflect.getMetadata("key", obj, "name"); 61 | assert.equal(result, undefined); 62 | }); 63 | 64 | it("WithTargetKeyWhenDefined", () => { 65 | const { Reflect } = script(context)` 66 | ${header} 67 | exports.Reflect = Reflect; 68 | `; 69 | let obj = {}; 70 | Reflect.defineMetadata("key", "value", obj, "name"); 71 | let result = Reflect.getMetadata("key", obj, "name"); 72 | assert.equal(result, "value"); 73 | }); 74 | 75 | it("WithTargetKeyWhenDefinedOnPrototype", () => { 76 | const { Reflect } = script(context)` 77 | ${header} 78 | exports.Reflect = Reflect; 79 | `; 80 | let prototype = {}; 81 | let obj = Object.create(prototype); 82 | Reflect.defineMetadata("key", "value", prototype, "name"); 83 | let result = Reflect.getMetadata("key", obj, "name"); 84 | assert.equal(result, "value"); 85 | }); 86 | }); 87 | }); 88 | } -------------------------------------------------------------------------------- /test/reflect-getmetadatakeys.ts: -------------------------------------------------------------------------------- 1 | // 4.1.8 Reflect.getMetadataKeys ( target [, propertyKey] ) 2 | // https://rbuckton.github.io/reflect-metadata/#reflect.getmetadatakeys 3 | 4 | /// 5 | import { assert } from "chai"; 6 | import { script } from "./vm"; 7 | import { suites } from "./suites"; 8 | 9 | for (const { name, header, context } of suites) { 10 | describe(name, () => { 11 | describe("Reflect.getMetadataKeys", () => { 12 | it("KeysInvalidTarget", () => { 13 | const { Reflect, TypeError } = script(context)` 14 | ${header} 15 | exports.Reflect = Reflect; 16 | exports.TypeError = TypeError; 17 | `; 18 | // 1. If Type(target) is not Object, throw a TypeError exception. 19 | assert.throws(() => Reflect.getMetadataKeys(undefined, undefined!), TypeError); 20 | }); 21 | 22 | it("KeysWithoutTargetKeyWhenNotDefined", () => { 23 | const { Reflect } = script(context)` 24 | ${header} 25 | exports.Reflect = Reflect; 26 | `; 27 | let obj = {}; 28 | let result = Reflect.getMetadataKeys(obj, undefined!); 29 | assert.deepEqual(result, []); 30 | }); 31 | 32 | it("KeysWithoutTargetKeyWhenDefined", () => { 33 | const { Reflect } = script(context)` 34 | ${header} 35 | exports.Reflect = Reflect; 36 | `; 37 | let obj = {}; 38 | Reflect.defineMetadata("key", "value", obj, undefined!); 39 | let result = Reflect.getMetadataKeys(obj, undefined!); 40 | assert.deepEqual(result, ["key"]); 41 | }); 42 | 43 | it("KeysWithoutTargetKeyWhenDefinedOnPrototype", () => { 44 | const { Reflect } = script(context)` 45 | ${header} 46 | exports.Reflect = Reflect; 47 | `; 48 | let prototype = {}; 49 | let obj = Object.create(prototype); 50 | Reflect.defineMetadata("key", "value", prototype, undefined!); 51 | let result = Reflect.getMetadataKeys(obj, undefined!); 52 | assert.deepEqual(result, ["key"]); 53 | }); 54 | 55 | it("KeysOrderWithoutTargetKey", () => { 56 | const { Reflect } = script(context)` 57 | ${header} 58 | exports.Reflect = Reflect; 59 | `; 60 | let obj = {}; 61 | Reflect.defineMetadata("key1", "value", obj, undefined!); 62 | Reflect.defineMetadata("key0", "value", obj, undefined!); 63 | let result = Reflect.getMetadataKeys(obj, undefined!); 64 | assert.deepEqual(result, ["key1", "key0"]); 65 | }); 66 | 67 | it("KeysOrderAfterRedefineWithoutTargetKey", () => { 68 | const { Reflect } = script(context)` 69 | ${header} 70 | exports.Reflect = Reflect; 71 | `; 72 | let obj = {}; 73 | Reflect.defineMetadata("key1", "value", obj, undefined!); 74 | Reflect.defineMetadata("key0", "value", obj, undefined!); 75 | Reflect.defineMetadata("key1", "value", obj, undefined!); 76 | let result = Reflect.getMetadataKeys(obj, undefined!); 77 | assert.deepEqual(result, ["key1", "key0"]); 78 | }); 79 | 80 | it("KeysOrderWithoutTargetKeyWhenDefinedOnPrototype", () => { 81 | const { Reflect } = script(context)` 82 | ${header} 83 | exports.Reflect = Reflect; 84 | `; 85 | let prototype = {}; 86 | Reflect.defineMetadata("key2", "value", prototype, undefined!); 87 | let obj = Object.create(prototype); 88 | Reflect.defineMetadata("key1", "value", obj, undefined!); 89 | Reflect.defineMetadata("key0", "value", obj, undefined!); 90 | let result = Reflect.getMetadataKeys(obj, undefined!); 91 | assert.deepEqual(result, ["key1", "key0", "key2"]); 92 | }); 93 | 94 | it("KeysWithTargetKeyWhenNotDefined", () => { 95 | const { Reflect } = script(context)` 96 | ${header} 97 | exports.Reflect = Reflect; 98 | `; 99 | let obj = {}; 100 | let result = Reflect.getMetadataKeys(obj, "name"); 101 | assert.deepEqual(result, []); 102 | }); 103 | 104 | it("KeysWithTargetKeyWhenDefined", () => { 105 | const { Reflect } = script(context)` 106 | ${header} 107 | exports.Reflect = Reflect; 108 | `; 109 | let obj = {}; 110 | Reflect.defineMetadata("key", "value", obj, "name"); 111 | let result = Reflect.getMetadataKeys(obj, "name"); 112 | assert.deepEqual(result, ["key"]); 113 | }); 114 | 115 | it("KeysWithTargetKeyWhenDefinedOnPrototype", () => { 116 | const { Reflect } = script(context)` 117 | ${header} 118 | exports.Reflect = Reflect; 119 | `; 120 | let prototype = {}; 121 | let obj = Object.create(prototype); 122 | Reflect.defineMetadata("key", "value", prototype, "name"); 123 | let result = Reflect.getMetadataKeys(obj, "name"); 124 | assert.deepEqual(result, ["key"]); 125 | }); 126 | 127 | it("KeysOrderAfterRedefineWithTargetKey", () => { 128 | const { Reflect } = script(context)` 129 | ${header} 130 | exports.Reflect = Reflect; 131 | `; 132 | let obj = {}; 133 | Reflect.defineMetadata("key1", "value", obj, "name"); 134 | Reflect.defineMetadata("key0", "value", obj, "name"); 135 | Reflect.defineMetadata("key1", "value", obj, "name"); 136 | let result = Reflect.getMetadataKeys(obj, "name"); 137 | assert.deepEqual(result, ["key1", "key0"]); 138 | }); 139 | 140 | it("KeysOrderWithTargetKeyWhenDefinedOnPrototype", () => { 141 | const { Reflect } = script(context)` 142 | ${header} 143 | exports.Reflect = Reflect; 144 | `; 145 | let prototype = {}; 146 | Reflect.defineMetadata("key2", "value", prototype, "name"); 147 | let obj = Object.create(prototype); 148 | Reflect.defineMetadata("key1", "value", obj, "name"); 149 | Reflect.defineMetadata("key0", "value", obj, "name"); 150 | let result = Reflect.getMetadataKeys(obj, "name"); 151 | assert.deepEqual(result, ["key1", "key0", "key2"]); 152 | }); 153 | }); 154 | }); 155 | } -------------------------------------------------------------------------------- /test/reflect-getownmetadata.ts: -------------------------------------------------------------------------------- 1 | // 4.1.7 Reflect.getOwnMetadata ( metadataKey, target [, propertyKey] ) 2 | // https://rbuckton.github.io/reflect-metadata/#reflect.getownmetadata 3 | 4 | /// 5 | import { assert } from "chai"; 6 | import { script } from "./vm"; 7 | import { suites } from "./suites"; 8 | 9 | for (const { name, header, context } of suites) { 10 | describe(name, () => { 11 | describe("Reflect.getOwnMetadata", () => { 12 | it("InvalidTarget", () => { 13 | const { Reflect, TypeError } = script(context)` 14 | ${header} 15 | exports.Reflect = Reflect; 16 | exports.TypeError = TypeError; 17 | `; 18 | assert.throws(() => Reflect.getOwnMetadata("key", undefined, undefined!), TypeError); 19 | }); 20 | 21 | it("WithoutTargetKeyWhenNotDefined", () => {0 22 | const { Reflect } = script(context)` 23 | ${header} 24 | exports.Reflect = Reflect; 25 | `; 26 | let obj = {}; 27 | let result = Reflect.getOwnMetadata("key", obj, undefined!); 28 | assert.equal(result, undefined); 29 | }); 30 | 31 | it("WithoutTargetKeyWhenDefined", () => { 32 | const { Reflect } = script(context)` 33 | ${header} 34 | exports.Reflect = Reflect; 35 | `; 36 | let obj = {}; 37 | Reflect.defineMetadata("key", "value", obj, undefined!); 38 | let result = Reflect.getOwnMetadata("key", obj, undefined!); 39 | assert.equal(result, "value"); 40 | }); 41 | 42 | it("WithoutTargetKeyWhenDefinedOnPrototype", () => { 43 | const { Reflect } = script(context)` 44 | ${header} 45 | exports.Reflect = Reflect; 46 | `; 47 | let prototype = {}; 48 | let obj = Object.create(prototype); 49 | Reflect.defineMetadata("key", "value", prototype, undefined!); 50 | let result = Reflect.getOwnMetadata("key", obj, undefined!); 51 | assert.equal(result, undefined); 52 | }); 53 | 54 | it("WithTargetKeyWhenNotDefined", () => { 55 | const { Reflect } = script(context)` 56 | ${header} 57 | exports.Reflect = Reflect; 58 | `; 59 | let obj = {}; 60 | let result = Reflect.getOwnMetadata("key", obj, "name"); 61 | assert.equal(result, undefined); 62 | }); 63 | 64 | it("WithTargetKeyWhenDefined", () => { 65 | const { Reflect } = script(context)` 66 | ${header} 67 | exports.Reflect = Reflect; 68 | `; 69 | let obj = {}; 70 | Reflect.defineMetadata("key", "value", obj, "name"); 71 | let result = Reflect.getOwnMetadata("key", obj, "name"); 72 | assert.equal(result, "value"); 73 | }); 74 | 75 | it("WithTargetKeyWhenDefinedOnPrototype", () => { 76 | const { Reflect } = script(context)` 77 | ${header} 78 | exports.Reflect = Reflect; 79 | `; 80 | let prototype = {}; 81 | let obj = Object.create(prototype); 82 | Reflect.defineMetadata("key", "value", prototype, "name"); 83 | let result = Reflect.getOwnMetadata("key", obj, "name"); 84 | assert.equal(result, undefined); 85 | }); 86 | }); 87 | }); 88 | } -------------------------------------------------------------------------------- /test/reflect-getownmetadatakeys.ts: -------------------------------------------------------------------------------- 1 | // 4.1.9 Reflect.getOwnMetadataKeysKeys ( target [, propertyKey] ) 2 | // https://rbuckton.github.io/reflect-metadata/#reflect.getownmetadatakeys 3 | 4 | /// 5 | import { assert } from "chai"; 6 | import { script } from "./vm"; 7 | import { suites } from "./suites"; 8 | 9 | for (const { name, header, context } of suites) { 10 | describe(name, () => { 11 | describe("Reflect.getOwnMetadataKeys", () => { 12 | it("KeysKeysInvalidTarget", () => { 13 | const { Reflect, TypeError } = script(context)` 14 | ${header} 15 | exports.Reflect = Reflect; 16 | exports.TypeError = TypeError; 17 | `; 18 | // 1. If Type(target) is not Object, throw a TypeError exception. 19 | assert.throws(() => Reflect.getOwnMetadataKeys(undefined, undefined!), TypeError); 20 | }); 21 | 22 | it("KeysWithoutTargetKeyWhenNotDefined", () => { 23 | const { Reflect } = script(context)` 24 | ${header} 25 | exports.Reflect = Reflect; 26 | `; 27 | let obj = {}; 28 | let result = Reflect.getOwnMetadataKeys(obj, undefined!); 29 | assert.deepEqual(result, []); 30 | }); 31 | 32 | it("KeysWithoutTargetKeyWhenDefined", () => { 33 | const { Reflect } = script(context)` 34 | ${header} 35 | exports.Reflect = Reflect; 36 | `; 37 | let obj = {}; 38 | Reflect.defineMetadata("key", "value", obj, undefined!); 39 | let result = Reflect.getOwnMetadataKeys(obj, undefined!); 40 | assert.deepEqual(result, ["key"]); 41 | }); 42 | 43 | it("KeysWithoutTargetKeyWhenDefinedOnPrototype", () => { 44 | const { Reflect } = script(context)` 45 | ${header} 46 | exports.Reflect = Reflect; 47 | `; 48 | let prototype = {}; 49 | let obj = Object.create(prototype); 50 | Reflect.defineMetadata("key", "value", prototype, undefined!); 51 | let result = Reflect.getOwnMetadataKeys(obj, undefined!); 52 | assert.deepEqual(result, []); 53 | }); 54 | 55 | it("KeysOrderWithoutTargetKey", () => { 56 | const { Reflect } = script(context)` 57 | ${header} 58 | exports.Reflect = Reflect; 59 | `; 60 | let obj = {}; 61 | Reflect.defineMetadata("key1", "value", obj, undefined!); 62 | Reflect.defineMetadata("key0", "value", obj, undefined!); 63 | let result = Reflect.getOwnMetadataKeys(obj, undefined!); 64 | assert.deepEqual(result, ["key1", "key0"]); 65 | }); 66 | 67 | it("KeysOrderAfterRedefineWithoutTargetKey", () => { 68 | const { Reflect } = script(context)` 69 | ${header} 70 | exports.Reflect = Reflect; 71 | `; 72 | let obj = {}; 73 | Reflect.defineMetadata("key1", "value", obj, undefined!); 74 | Reflect.defineMetadata("key0", "value", obj, undefined!); 75 | Reflect.defineMetadata("key1", "value", obj, undefined!); 76 | let result = Reflect.getOwnMetadataKeys(obj, undefined!); 77 | assert.deepEqual(result, ["key1", "key0"]); 78 | }); 79 | 80 | it("KeysWithTargetKeyWhenNotDefined", () => { 81 | const { Reflect } = script(context)` 82 | ${header} 83 | exports.Reflect = Reflect; 84 | `; 85 | let obj = {}; 86 | let result = Reflect.getOwnMetadataKeys(obj, "name"); 87 | assert.deepEqual(result, []); 88 | }); 89 | 90 | it("KeysWithTargetKeyWhenDefined", () => { 91 | const { Reflect } = script(context)` 92 | ${header} 93 | exports.Reflect = Reflect; 94 | `; 95 | let obj = {}; 96 | Reflect.defineMetadata("key", "value", obj, "name"); 97 | let result = Reflect.getOwnMetadataKeys(obj, "name"); 98 | assert.deepEqual(result, ["key"]); 99 | }); 100 | 101 | it("KeysWithTargetKeyWhenDefinedOnPrototype", () => { 102 | const { Reflect } = script(context)` 103 | ${header} 104 | exports.Reflect = Reflect; 105 | `; 106 | let prototype = {}; 107 | let obj = Object.create(prototype); 108 | Reflect.defineMetadata("key", "value", prototype, "name"); 109 | let result = Reflect.getOwnMetadataKeys(obj, "name"); 110 | assert.deepEqual(result, []); 111 | }); 112 | 113 | it("KeysOrderAfterRedefineWithTargetKey", () => { 114 | const { Reflect } = script(context)` 115 | ${header} 116 | exports.Reflect = Reflect; 117 | `; 118 | let obj = {}; 119 | Reflect.defineMetadata("key1", "value", obj, "name"); 120 | Reflect.defineMetadata("key0", "value", obj, "name"); 121 | Reflect.defineMetadata("key1", "value", obj, "name"); 122 | let result = Reflect.getOwnMetadataKeys(obj, "name"); 123 | assert.deepEqual(result, ["key1", "key0"]); 124 | }); 125 | }); 126 | }); 127 | } -------------------------------------------------------------------------------- /test/reflect-hasmetadata.ts: -------------------------------------------------------------------------------- 1 | // 4.1.4 Reflect.hasMetadata ( metadataKey, target [, propertyKey] ) 2 | // https://rbuckton.github.io/reflect-metadata/#reflect.hasmetadata 3 | 4 | /// 5 | import { assert } from "chai"; 6 | import { script } from "./vm"; 7 | import { suites } from "./suites"; 8 | 9 | for (const { name, header, context } of suites) { 10 | describe(name, () => { 11 | describe("Reflect.hasMetadata", () => { 12 | it("InvalidTarget", () => { 13 | const { Reflect, TypeError } = script(context)` 14 | ${header} 15 | exports.Reflect = Reflect; 16 | exports.TypeError = TypeError; 17 | `; 18 | assert.throws(() => Reflect.hasMetadata("key", undefined, undefined!), TypeError); 19 | }); 20 | 21 | it("WithoutTargetKeyWhenNotDefined", () => { 22 | const { Reflect } = script(context)` 23 | ${header} 24 | exports.Reflect = Reflect; 25 | `; 26 | let obj = {}; 27 | let result = Reflect.hasMetadata("key", obj, undefined!); 28 | assert.equal(result, false); 29 | }); 30 | 31 | it("WithoutTargetKeyWhenDefined", () => { 32 | const { Reflect } = script(context)` 33 | ${header} 34 | exports.Reflect = Reflect; 35 | `; 36 | let obj = {}; 37 | Reflect.defineMetadata("key", "value", obj, undefined!); 38 | let result = Reflect.hasMetadata("key", obj, undefined!); 39 | assert.equal(result, true); 40 | }); 41 | 42 | it("WithoutTargetKeyWhenDefinedOnPrototype", () => { 43 | const { Reflect } = script(context)` 44 | ${header} 45 | exports.Reflect = Reflect; 46 | `; 47 | let prototype = {}; 48 | let obj = Object.create(prototype); 49 | Reflect.defineMetadata("key", "value", prototype, undefined!); 50 | let result = Reflect.hasMetadata("key", obj, undefined!); 51 | assert.equal(result, true); 52 | }); 53 | 54 | it("WithTargetKeyWhenNotDefined", () => { 55 | const { Reflect } = script(context)` 56 | ${header} 57 | exports.Reflect = Reflect; 58 | `; 59 | let obj = {}; 60 | let result = Reflect.hasMetadata("key", obj, "name"); 61 | assert.equal(result, false); 62 | }); 63 | 64 | it("WithTargetKeyWhenDefined", () => { 65 | const { Reflect } = script(context)` 66 | ${header} 67 | exports.Reflect = Reflect; 68 | `; 69 | let obj = {}; 70 | Reflect.defineMetadata("key", "value", obj, "name"); 71 | let result = Reflect.hasMetadata("key", obj, "name"); 72 | assert.equal(result, true); 73 | }); 74 | 75 | it("WithTargetKeyWhenDefinedOnPrototype", () => { 76 | const { Reflect } = script(context)` 77 | ${header} 78 | exports.Reflect = Reflect; 79 | `; 80 | let prototype = {}; 81 | let obj = Object.create(prototype); 82 | Reflect.defineMetadata("key", "value", prototype, "name"); 83 | let result = Reflect.hasMetadata("key", obj, "name"); 84 | assert.equal(result, true); 85 | }); 86 | }); 87 | }); 88 | } -------------------------------------------------------------------------------- /test/reflect-hasownmetadata.ts: -------------------------------------------------------------------------------- 1 | // 4.1.5 Reflect.hasOwnMetadata ( metadataKey, target [, propertyKey] ) 2 | // https://rbuckton.github.io/reflect-metadata/#reflect.hasownmetadata 3 | 4 | /// 5 | import { assert } from "chai"; 6 | import { script } from "./vm"; 7 | import { suites } from "./suites"; 8 | 9 | for (const { name, header, context } of suites) { 10 | describe(name, () => { 11 | describe("Reflect.hasOwnMetadata", () => { 12 | it("InvalidTarget", () => { 13 | const { Reflect, TypeError } = script(context)` 14 | ${header} 15 | exports.Reflect = Reflect; 16 | exports.TypeError = TypeError; 17 | `; 18 | assert.throws(() => Reflect.hasOwnMetadata("key", undefined, undefined!), TypeError); 19 | }); 20 | 21 | it("WithoutTargetKeyWhenNotDefined", () => { 22 | const { Reflect } = script(context)` 23 | ${header} 24 | exports.Reflect = Reflect; 25 | `; 26 | let obj = {}; 27 | let result = Reflect.hasOwnMetadata("key", obj, undefined!); 28 | assert.equal(result, false); 29 | }); 30 | 31 | it("WithoutTargetKeyWhenDefined", () => { 32 | const { Reflect } = script(context)` 33 | ${header} 34 | exports.Reflect = Reflect; 35 | `; 36 | let obj = {}; 37 | Reflect.defineMetadata("key", "value", obj, undefined!); 38 | let result = Reflect.hasOwnMetadata("key", obj, undefined!); 39 | assert.equal(result, true); 40 | }); 41 | 42 | it("WithoutTargetKeyWhenDefinedOnPrototype", () => { 43 | const { Reflect } = script(context)` 44 | ${header} 45 | exports.Reflect = Reflect; 46 | `; 47 | let prototype = {}; 48 | let obj = Object.create(prototype); 49 | Reflect.defineMetadata("key", "value", prototype, undefined!); 50 | let result = Reflect.hasOwnMetadata("key", obj, undefined!); 51 | assert.equal(result, false); 52 | }); 53 | 54 | it("WithTargetKeyWhenNotDefined", () => { 55 | const { Reflect } = script(context)` 56 | ${header} 57 | exports.Reflect = Reflect; 58 | `; 59 | let obj = {}; 60 | let result = Reflect.hasOwnMetadata("key", obj, "name"); 61 | assert.equal(result, false); 62 | }); 63 | 64 | it("WithTargetKeyWhenDefined", () => { 65 | const { Reflect } = script(context)` 66 | ${header} 67 | exports.Reflect = Reflect; 68 | `; 69 | let obj = {}; 70 | Reflect.defineMetadata("key", "value", obj, "name"); 71 | let result = Reflect.hasOwnMetadata("key", obj, "name"); 72 | assert.equal(result, true); 73 | }); 74 | 75 | it("WithTargetKeyWhenDefinedOnPrototype", () => { 76 | const { Reflect } = script(context)` 77 | ${header} 78 | exports.Reflect = Reflect; 79 | `; 80 | let prototype = {}; 81 | let obj = Object.create(prototype); 82 | Reflect.defineMetadata("key", "value", prototype, "name"); 83 | let result = Reflect.hasOwnMetadata("key", obj, "name"); 84 | assert.equal(result, false); 85 | }); 86 | }); 87 | }); 88 | } -------------------------------------------------------------------------------- /test/reflect-metadata.ts: -------------------------------------------------------------------------------- 1 | // 4.1.2 Reflect.metadata ( metadataKey, metadataValue ) 2 | // https://rbuckton.github.io/reflect-metadata/#reflect.metadata 3 | 4 | /// 5 | import { assert } from "chai"; 6 | import { script } from "./vm"; 7 | import { suites } from "./suites"; 8 | 9 | for (const { name, header, context } of suites) { 10 | describe(name, () => { 11 | describe("Reflect.metadata", () => { 12 | it("ReturnsDecoratorFunction", () => { 13 | const { Reflect } = script(context)` 14 | ${header} 15 | exports.Reflect = Reflect; 16 | `; 17 | let result = Reflect.metadata("key", "value"); 18 | assert.equal(typeof result, "function"); 19 | }); 20 | 21 | it("DecoratorThrowsWithInvalidTargetWithTargetKey", () => { 22 | const { Reflect, TypeError } = script(context)` 23 | ${header} 24 | exports.Reflect = Reflect; 25 | exports.TypeError = TypeError; 26 | `; 27 | let decorator = Reflect.metadata("key", "value"); 28 | assert.throws(() => decorator(undefined!, "name"), TypeError); 29 | }); 30 | 31 | it("DecoratorThrowsWithInvalidTargetKey", () => { 32 | const { Reflect, TypeError } = script(context)` 33 | ${header} 34 | exports.Reflect = Reflect; 35 | exports.TypeError = TypeError; 36 | `; 37 | let decorator = Reflect.metadata("key", "value"); 38 | assert.throws(() => decorator({}, {}), TypeError); 39 | }); 40 | 41 | it("OnTargetWithoutTargetKey", () => { 42 | const { Reflect } = script(context)` 43 | ${header} 44 | exports.Reflect = Reflect; 45 | `; 46 | let decorator = Reflect.metadata("key", "value"); 47 | let target = function () {} 48 | decorator(target); 49 | 50 | let result = Reflect.hasOwnMetadata("key", target, undefined!); 51 | assert.equal(result, true); 52 | }); 53 | 54 | it("OnTargetWithTargetKey", () => { 55 | const { Reflect } = script(context)` 56 | ${header} 57 | exports.Reflect = Reflect; 58 | `; 59 | let decorator = Reflect.metadata("key", "value"); 60 | let target = {} 61 | decorator(target, "name"); 62 | 63 | let result = Reflect.hasOwnMetadata("key", target, "name"); 64 | assert.equal(result, true); 65 | }); 66 | }); 67 | }); 68 | } -------------------------------------------------------------------------------- /test/reflect-other.ts: -------------------------------------------------------------------------------- 1 | import { assert } from "chai"; 2 | import { script } from "./vm"; 3 | import { suites } from "./suites"; 4 | 5 | for (const { name, header, context } of suites.filter(s => s.global)) { 6 | describe(name, () => { 7 | describe("Reflect", () => { 8 | it("does not clobber existing implementation", () => { 9 | const { Reflect, defineMetadata, obj } = script(context)` 10 | const fs = require("fs"); 11 | ${header} 12 | 13 | exports.Reflect = Reflect; 14 | exports.defineMetadata = Reflect.defineMetadata; 15 | exports.obj = {}; 16 | Reflect.defineMetadata("key", "value", exports.obj); 17 | 18 | const reflectPath = require.resolve("../Reflect.js"); 19 | const reflectContent = fs.readFileSync(reflectPath, "utf8"); 20 | const reflectFunction = Function(reflectContent); 21 | reflectFunction(); 22 | `; 23 | 24 | assert.notStrictEqual(Reflect.defineMetadata, defineMetadata); 25 | assert.strictEqual(Reflect.getOwnMetadata("key", obj), "value"); 26 | }); 27 | }); 28 | 29 | it("isProviderFor crash", () => { 30 | const { Reflect } = script(context)` 31 | Reflect.defineMetadata = function() {}; 32 | Reflect.getOwnMetadataKeys = function() { return [] }; 33 | Reflect.getMetadataKeys = function() { return []; } 34 | ${header} 35 | exports.Reflect = Reflect; 36 | `; 37 | let obj = {}; 38 | Reflect.getMetadataKeys(obj); 39 | }); 40 | }); 41 | } -------------------------------------------------------------------------------- /test/registry.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import { assert } from "chai"; 4 | import { script } from "./vm"; 5 | import { suites } from "./suites"; 6 | 7 | for (const { name, header, context } of suites.filter(s => s.global && !s.polyfill)) { 8 | describe(`ReflectNoConflict + ${name}`, () => { 9 | describe("MetadataRegistry", () => { 10 | it("defines registry", () => { 11 | const { registry } = script(context)` 12 | const ReflectNoConflict = require("../ReflectNoConflict"); 13 | ${header} 14 | 15 | const registrySymbol = Symbol.for("@reflect-metadata:registry"); 16 | exports.registry = Reflect[registrySymbol]; 17 | `; 18 | assert.isDefined(registry); 19 | }); 20 | it("two registries", () => { 21 | const { provider1, provider2 } = script(context)` 22 | const ReflectNoConflict = require("../ReflectNoConflict"); 23 | ${header} 24 | 25 | const registrySymbol = Symbol.for("@reflect-metadata:registry"); 26 | const registry = Reflect[registrySymbol]; 27 | 28 | const obj1 = {}; 29 | ReflectNoConflict.defineMetadata("key", "value", obj1); 30 | 31 | const obj2 = {}; 32 | Reflect.defineMetadata("key", "value", obj2); 33 | 34 | const provider1 = registry.getProvider(obj1, undefined); 35 | const provider2 = registry.getProvider(obj2, undefined); 36 | 37 | exports.provider1 = provider1; 38 | exports.provider2 = provider2; 39 | exports.registry = registry; 40 | `; 41 | assert.isDefined(provider1); 42 | assert.isDefined(provider2); 43 | assert.notStrictEqual(provider1, provider2); 44 | }); 45 | it("registries are shared", () => { 46 | const { ReflectNoConflict, Reflect } = script(context)` 47 | const ReflectNoConflict = require("../ReflectNoConflict"); 48 | ${header} 49 | 50 | exports.ReflectNoConflict = ReflectNoConflict; 51 | exports.Reflect = Reflect; 52 | `; 53 | const obj = {}; 54 | ReflectNoConflict.defineMetadata("key", "value", obj); 55 | assert.isTrue(Reflect.hasOwnMetadata("key", obj)); 56 | }); 57 | }); 58 | }); 59 | } 60 | 61 | for (const { name, header, context } of suites) { 62 | describe(`fallback + ${name}`, () => { 63 | it("MetadataRegistry", () => { 64 | const { provider1, provider2 } = script({ ESMap: Map, ...context })` 65 | { 66 | const Map = ESMap; 67 | const map = new Map(); 68 | Reflect.defineMetadata = function(key, value, target, prop) { 69 | let props = map.get(target); 70 | if (!props) map.set(target, props = new Map()); 71 | let meta = props.get(prop); 72 | if (!meta) props.set(prop, meta = new Map()); 73 | meta.set(key, value); 74 | }; 75 | Reflect.hasOwnMetadata = function(key, target, prop) { 76 | let props = map.get(target); 77 | let meta = props && props.get(prop); 78 | return meta && meta.has(key) || false; 79 | }; 80 | Reflect.getOwnMetadata = function(key, target, prop) { 81 | let props = map.get(target); 82 | let meta = props && props.get(prop); 83 | return meta && meta.get(key); 84 | }; 85 | Reflect.getOwnMetadataKeys = function(target, prop) { 86 | let props = map.get(target); 87 | let meta = props && props.get(prop); 88 | const keys = meta && meta.keys() || []; 89 | return [...keys]; 90 | }; 91 | Reflect.deleteMetadata = function(key, target, prop) { 92 | let props = map.get(target); 93 | let meta = props && props.get(prop); 94 | return meta && meta.delete(key) || false; 95 | }; 96 | } 97 | 98 | const obj = {}; 99 | Reflect.defineMetadata("a", 1, obj); 100 | Reflect.defineMetadata("b", 2, obj, "c"); 101 | 102 | { 103 | ${header} 104 | } 105 | 106 | const registrySymbol = Symbol.for("@reflect-metadata:registry"); 107 | const registry = Reflect[registrySymbol]; 108 | const provider1 = registry.getProvider(obj, undefined); 109 | const provider2 = registry.getProvider(obj, "c"); 110 | 111 | exports.provider1 = provider1; 112 | exports.provider2 = provider2; 113 | `; 114 | assert.isDefined(provider1); 115 | assert.isDefined(provider2); 116 | assert.strictEqual(provider1, provider2); 117 | }); 118 | }); 119 | } -------------------------------------------------------------------------------- /test/suites.ts: -------------------------------------------------------------------------------- 1 | interface TestSuite { 2 | name: string; 3 | header: string; 4 | global?: boolean; 5 | polyfill?: boolean; 6 | context?: any; 7 | } 8 | 9 | export const suites: TestSuite[] = [ 10 | { 11 | name: "Reflect.js", 12 | header: `require("../Reflect");`, 13 | global: true, 14 | }, 15 | { 16 | name: "Reflect.js (w/polyfill)", 17 | header: `require("../Reflect");`, 18 | global: true, 19 | polyfill: true, 20 | context: { 21 | Map: {}, 22 | Set: {}, 23 | WeakMap: {}, 24 | } 25 | }, 26 | { 27 | name: "ReflectLite.js", 28 | header: `require("../ReflectLite");`, 29 | global: true, 30 | }, 31 | { 32 | name: "ReflectNoConflict.js", 33 | header: `const Reflect = require("../ReflectNoConflict");`, 34 | }, 35 | ]; -------------------------------------------------------------------------------- /test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "noImplicitAny": true, 5 | "sourceMap": true, 6 | "module": "commonjs", 7 | "types": ["node", "mocha"], 8 | "typeRoots": ["../node_modules/@types"], 9 | }, 10 | "include": [ 11 | "**/*.ts" 12 | ] 13 | } -------------------------------------------------------------------------------- /test/vm.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import vm = require("vm"); 3 | import mod = require("module"); 4 | import fs = require("fs"); 5 | import path = require("path"); 6 | 7 | class Loader { 8 | cache = new Map(); 9 | context: vm.Context; 10 | constructor(context: vm.Context = { }) { 11 | this.context = vm.createContext(context); 12 | } 13 | load(id: string, filename = id, code?: string): any { 14 | let module = this.cache.get(id); 15 | if (module) return module.exports; 16 | module = { 17 | id, 18 | filename, 19 | exports: {}, 20 | require: undefined, 21 | loaded: false, 22 | paths: undefined!, 23 | children: undefined!, 24 | parent: undefined! 25 | }; 26 | this.cache.set(id, module); 27 | if (mod.builtinModules.indexOf(id) >= 0) { 28 | module.exports = require(id); 29 | module.loaded = true; 30 | } 31 | else { 32 | module.require = this.createRequire(filename); 33 | if (code === undefined) { 34 | code = fs.readFileSync(filename, { encoding: "utf8" }); 35 | } 36 | code = `(function(module, exports, require, __filename, __dirname) {${code}\n})`; 37 | const func = vm.runInContext(code, this.context, { filename }); 38 | func(module, module.exports, module.require, filename, path.dirname(filename)); 39 | module.loaded = true; 40 | } 41 | return module.exports; 42 | } 43 | createRequire(filename: string) { 44 | const req = mod.createRequireFromPath(filename) as NodeRequire; 45 | const require = ((id: string) => this.load(mod.builtinModules.indexOf(id) >= 0 ? id : req.resolve(id))) as NodeRequire; 46 | require.resolve = req.resolve; 47 | return require; 48 | } 49 | } 50 | 51 | export function script(context: vm.Context = {}): (array: TemplateStringsArray, ...args: any[]) => any{ 52 | return (array, ...args) => { 53 | let code = array[0]; 54 | for (let i = 1; i < array.length; i++) { 55 | code += args[i - 1]; 56 | code += array[i]; 57 | } 58 | const loader = new Loader(context); 59 | return loader.load("test.js", __filename, code); 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /tsconfig-release.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "newLine": "LF", 6 | "sourceMap": false, 7 | "strictNullChecks": true, 8 | "noImplicitAny": true, 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": true, 11 | "noImplicitReturns": true, 12 | "noImplicitThis": true 13 | }, 14 | "files": [ 15 | "globals.d.ts", 16 | "Reflect.ts", 17 | "ReflectLite.ts", 18 | "ReflectNoConflict.ts", 19 | ] 20 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "newLine": "LF", 6 | "sourceMap": true, 7 | "strictNullChecks": true, 8 | "noImplicitAny": true, 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": true, 11 | "noImplicitReturns": true, 12 | "noImplicitThis": true 13 | }, 14 | "files": [ 15 | "globals.d.ts", 16 | "Reflect.ts", 17 | "ReflectLite.ts", 18 | "ReflectNoConflict.ts", 19 | ] 20 | } --------------------------------------------------------------------------------