@mohsen-azimi/tsz-dev 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/tsz.js +80 -4
- package/bundler/package.json +1 -1
- package/bundler/tsz_wasm_bg.wasm +0 -0
- package/lib-assets/decorators.d.ts +382 -0
- package/lib-assets/decorators.legacy.d.ts +20 -0
- package/lib-assets/dom.asynciterable.d.ts +18 -0
- package/lib-assets/dom.d.ts +40771 -0
- package/lib-assets/dom.iterable.d.ts +18 -0
- package/lib-assets/es2015.collection.d.ts +145 -0
- package/lib-assets/es2015.core.d.ts +595 -0
- package/lib-assets/es2015.d.ts +26 -0
- package/lib-assets/es2015.generator.d.ts +75 -0
- package/lib-assets/es2015.iterable.d.ts +603 -0
- package/lib-assets/es2015.promise.d.ts +79 -0
- package/lib-assets/es2015.proxy.d.ts +126 -0
- package/lib-assets/es2015.reflect.d.ts +142 -0
- package/lib-assets/es2015.symbol.d.ts +44 -0
- package/lib-assets/es2015.symbol.wellknown.d.ts +324 -0
- package/lib-assets/es2016.array.include.d.ts +114 -0
- package/lib-assets/es2016.d.ts +19 -0
- package/lib-assets/es2016.full.d.ts +21 -0
- package/lib-assets/es2016.intl.d.ts +29 -0
- package/lib-assets/es2017.arraybuffer.d.ts +19 -0
- package/lib-assets/es2017.d.ts +24 -0
- package/lib-assets/es2017.date.d.ts +29 -0
- package/lib-assets/es2017.full.d.ts +21 -0
- package/lib-assets/es2017.intl.d.ts +42 -0
- package/lib-assets/es2017.object.d.ts +47 -0
- package/lib-assets/es2017.sharedmemory.d.ts +133 -0
- package/lib-assets/es2017.string.d.ts +43 -0
- package/lib-assets/es2017.typedarrays.d.ts +51 -0
- package/lib-assets/es2018.asyncgenerator.d.ts +75 -0
- package/lib-assets/es2018.asynciterable.d.ts +51 -0
- package/lib-assets/es2018.d.ts +22 -0
- package/lib-assets/es2018.full.d.ts +22 -0
- package/lib-assets/es2018.intl.d.ts +81 -0
- package/lib-assets/es2018.promise.d.ts +28 -0
- package/lib-assets/es2018.regexp.d.ts +35 -0
- package/lib-assets/es2019.array.d.ts +77 -0
- package/lib-assets/es2019.d.ts +22 -0
- package/lib-assets/es2019.full.d.ts +22 -0
- package/lib-assets/es2019.intl.d.ts +21 -0
- package/lib-assets/es2019.object.d.ts +31 -0
- package/lib-assets/es2019.string.d.ts +35 -0
- package/lib-assets/es2019.symbol.d.ts +22 -0
- package/lib-assets/es2020.bigint.d.ts +763 -0
- package/lib-assets/es2020.d.ts +25 -0
- package/lib-assets/es2020.date.d.ts +40 -0
- package/lib-assets/es2020.full.d.ts +22 -0
- package/lib-assets/es2020.intl.d.ts +472 -0
- package/lib-assets/es2020.number.d.ts +26 -0
- package/lib-assets/es2020.promise.d.ts +45 -0
- package/lib-assets/es2020.sharedmemory.d.ts +97 -0
- package/lib-assets/es2020.string.d.ts +42 -0
- package/lib-assets/es2020.symbol.wellknown.d.ts +39 -0
- package/lib-assets/es2021.d.ts +21 -0
- package/lib-assets/es2021.full.d.ts +22 -0
- package/lib-assets/es2021.intl.d.ts +164 -0
- package/lib-assets/es2021.promise.d.ts +46 -0
- package/lib-assets/es2021.string.d.ts +31 -0
- package/lib-assets/es2021.weakref.d.ts +76 -0
- package/lib-assets/es2022.array.d.ts +119 -0
- package/lib-assets/es2022.d.ts +23 -0
- package/lib-assets/es2022.error.d.ts +73 -0
- package/lib-assets/es2022.full.d.ts +22 -0
- package/lib-assets/es2022.intl.d.ts +143 -0
- package/lib-assets/es2022.object.d.ts +24 -0
- package/lib-assets/es2022.regexp.d.ts +37 -0
- package/lib-assets/es2022.string.d.ts +23 -0
- package/lib-assets/es2023.array.d.ts +922 -0
- package/lib-assets/es2023.collection.d.ts +19 -0
- package/lib-assets/es2023.d.ts +20 -0
- package/lib-assets/es2023.full.d.ts +22 -0
- package/lib-assets/es2023.intl.d.ts +54 -0
- package/lib-assets/es2024.arraybuffer.d.ts +63 -0
- package/lib-assets/es2024.collection.d.ts +29 -0
- package/lib-assets/es2024.d.ts +24 -0
- package/lib-assets/es2024.full.d.ts +22 -0
- package/lib-assets/es2024.object.d.ts +27 -0
- package/lib-assets/es2024.promise.d.ts +33 -0
- package/lib-assets/es2024.regexp.d.ts +23 -0
- package/lib-assets/es2024.sharedmemory.d.ts +66 -0
- package/lib-assets/es2024.string.d.ts +27 -0
- package/lib-assets/es5.d.ts +4599 -0
- package/lib-assets/es5.full.d.ts +20 -0
- package/lib-assets/es6.d.ts +21 -0
- package/lib-assets/esnext.array.d.ts +33 -0
- package/lib-assets/esnext.collection.d.ts +94 -0
- package/lib-assets/esnext.d.ts +28 -0
- package/lib-assets/esnext.decorators.d.ts +26 -0
- package/lib-assets/esnext.disposable.d.ts +191 -0
- package/lib-assets/esnext.error.d.ts +22 -0
- package/lib-assets/esnext.float16.d.ts +443 -0
- package/lib-assets/esnext.full.d.ts +22 -0
- package/lib-assets/esnext.intl.d.ts +19 -0
- package/lib-assets/esnext.iterator.d.ts +146 -0
- package/lib-assets/esnext.promise.d.ts +32 -0
- package/lib-assets/esnext.sharedmemory.d.ts +23 -0
- package/lib-assets/esnext.typedarrays.d.ts +90 -0
- package/lib-assets/lib_manifest.json +855 -0
- package/lib-assets/scripthost.d.ts +320 -0
- package/lib-assets/tsserverlibrary.d.ts +17 -0
- package/lib-assets/typescript.d.ts +11441 -0
- package/lib-assets/webworker.asynciterable.d.ts +18 -0
- package/lib-assets/webworker.d.ts +13768 -0
- package/lib-assets/webworker.importscripts.d.ts +21 -0
- package/lib-assets/webworker.iterable.d.ts +18 -0
- package/node/package.json +1 -1
- package/node/tsz_wasm_bg.wasm +0 -0
- package/package.json +2 -2
package/bin/tsz.js
CHANGED
|
@@ -99,15 +99,79 @@ if (inputFiles.length === 0) {
|
|
|
99
99
|
const program = new TsProgram();
|
|
100
100
|
program.setCompilerOptions(JSON.stringify(options));
|
|
101
101
|
|
|
102
|
+
// ─── Load TypeScript lib files ────────────────────────────────────────────────
|
|
103
|
+
// Lib .d.ts files (lib.es5.d.ts, lib.dom.d.ts, etc.) provide global type
|
|
104
|
+
// definitions (Array, String, Promise, console, document, etc.).
|
|
105
|
+
// They are bundled in the package under lib-assets/ with a manifest.
|
|
106
|
+
const libDir = path.join(pkgDir, 'lib-assets');
|
|
107
|
+
const manifestPath = path.join(libDir, 'lib_manifest.json');
|
|
108
|
+
|
|
109
|
+
if (fs.existsSync(manifestPath)) {
|
|
110
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
111
|
+
const libs = manifest.libs || {};
|
|
112
|
+
|
|
113
|
+
// Resolve the default root lib based on target (matches tsc's getDefaultLibFileName).
|
|
114
|
+
// Default target is ES5 → root lib is "es5.full" (equivalent to tsc's "lib.d.ts").
|
|
115
|
+
const targetLibMap = {
|
|
116
|
+
es5: 'es5.full', es2015: 'es6', es2016: 'es2016.full',
|
|
117
|
+
es2017: 'es2017.full', es2018: 'es2018.full', es2019: 'es2019.full',
|
|
118
|
+
es2020: 'es2020.full', es2021: 'es2021.full', es2022: 'es2022.full',
|
|
119
|
+
es2023: 'esnext.full', es2024: 'esnext.full', esnext: 'esnext.full',
|
|
120
|
+
};
|
|
121
|
+
const rootLib = targetLibMap[(options.target || 'es5').toLowerCase()] || 'es5.full';
|
|
122
|
+
|
|
123
|
+
// BFS to resolve all transitive lib references
|
|
124
|
+
const visited = new Set();
|
|
125
|
+
const queue = [rootLib];
|
|
126
|
+
while (queue.length > 0) {
|
|
127
|
+
const name = queue.shift();
|
|
128
|
+
if (!name || visited.has(name)) continue;
|
|
129
|
+
visited.add(name);
|
|
130
|
+
const entry = libs[name];
|
|
131
|
+
if (!entry) continue;
|
|
132
|
+
const filePath = path.join(libDir, entry.fileName);
|
|
133
|
+
try {
|
|
134
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
135
|
+
// Use canonical name (lib.es5.d.ts) so tsc-compatible lookups work
|
|
136
|
+
program.addLibFile(entry.canonicalFileName || entry.fileName, content);
|
|
137
|
+
} catch { /* skip missing files */ }
|
|
138
|
+
// Follow references
|
|
139
|
+
if (entry.references) {
|
|
140
|
+
for (const ref of entry.references) queue.push(ref);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Map from absolute path → source text, used for offset→line/col conversion.
|
|
146
|
+
const sourceTexts = new Map();
|
|
147
|
+
|
|
102
148
|
for (const file of inputFiles) {
|
|
103
149
|
try {
|
|
104
150
|
const text = fs.readFileSync(file, 'utf8');
|
|
105
151
|
program.addSourceFile(file, text);
|
|
152
|
+
sourceTexts.set(file, text);
|
|
106
153
|
} catch (err) {
|
|
107
154
|
console.error(`tsz: cannot read ${file}: ${err.message}`);
|
|
108
155
|
}
|
|
109
156
|
}
|
|
110
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Convert a 0-based UTF-16 character offset to { line, character } (0-based).
|
|
160
|
+
* This matches the position model used by tsc.
|
|
161
|
+
*/
|
|
162
|
+
function offsetToLineChar(text, offset) {
|
|
163
|
+
const clamped = Math.max(0, Math.min(offset, text.length));
|
|
164
|
+
let line = 0;
|
|
165
|
+
let lineStart = 0;
|
|
166
|
+
for (let i = 0; i < clamped; i++) {
|
|
167
|
+
if (text[i] === '\n') {
|
|
168
|
+
line++;
|
|
169
|
+
lineStart = i + 1;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { line, character: clamped - lineStart };
|
|
173
|
+
}
|
|
174
|
+
|
|
111
175
|
let diagnostics;
|
|
112
176
|
try {
|
|
113
177
|
diagnostics = JSON.parse(program.getSemanticDiagnosticsJson(undefined));
|
|
@@ -121,17 +185,29 @@ try {
|
|
|
121
185
|
let errorCount = 0;
|
|
122
186
|
let warningCount = 0;
|
|
123
187
|
|
|
188
|
+
// tsc diagnostic category codes: 0=warning, 1=error, 2=suggestion, 3=message
|
|
189
|
+
const CATEGORY_NAMES = { 0: 'warning', 1: 'error', 2: 'suggestion', 3: 'message' };
|
|
190
|
+
|
|
124
191
|
for (const d of diagnostics) {
|
|
125
|
-
const category =
|
|
192
|
+
const category = CATEGORY_NAMES[d.category] || 'error';
|
|
126
193
|
if (category === 'error') errorCount++;
|
|
127
194
|
else if (category === 'warning') warningCount++;
|
|
128
195
|
|
|
129
196
|
const file = d.file || '<unknown>';
|
|
130
197
|
const relFile = path.relative(process.cwd(), file);
|
|
131
|
-
const line = (d.line != null ? d.line + 1 : '?');
|
|
132
|
-
const col = (d.character != null ? d.character + 1 : '?');
|
|
133
|
-
const code = d.code ? `TS${d.code}` : '';
|
|
134
198
|
|
|
199
|
+
// Compute 1-based line/character from byte offset if available
|
|
200
|
+
let line = '?', col = '?';
|
|
201
|
+
if (typeof d.start === 'number') {
|
|
202
|
+
const src = sourceTexts.get(file);
|
|
203
|
+
if (src != null) {
|
|
204
|
+
const pos = offsetToLineChar(src, d.start);
|
|
205
|
+
line = pos.line + 1;
|
|
206
|
+
col = pos.character + 1;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const code = d.code ? `TS${d.code}` : '';
|
|
135
211
|
console.error(`${relFile}(${line},${col}): ${category} ${code}: ${d.messageText || d.message || ''}`);
|
|
136
212
|
}
|
|
137
213
|
|
package/bundler/package.json
CHANGED
package/bundler/tsz_wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -0,0 +1,382 @@
|
|
|
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
|
+
MERCHANTABILITY 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
|
+
/**
|
|
18
|
+
* The decorator context types provided to class element decorators.
|
|
19
|
+
*/
|
|
20
|
+
type ClassMemberDecoratorContext =
|
|
21
|
+
| ClassMethodDecoratorContext
|
|
22
|
+
| ClassGetterDecoratorContext
|
|
23
|
+
| ClassSetterDecoratorContext
|
|
24
|
+
| ClassFieldDecoratorContext
|
|
25
|
+
| ClassAccessorDecoratorContext;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The decorator context types provided to any decorator.
|
|
29
|
+
*/
|
|
30
|
+
type DecoratorContext =
|
|
31
|
+
| ClassDecoratorContext
|
|
32
|
+
| ClassMemberDecoratorContext;
|
|
33
|
+
|
|
34
|
+
type DecoratorMetadataObject = Record<PropertyKey, unknown> & object;
|
|
35
|
+
|
|
36
|
+
type DecoratorMetadata = typeof globalThis extends { Symbol: { readonly metadata: symbol; }; } ? DecoratorMetadataObject : DecoratorMetadataObject | undefined;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Context provided to a class decorator.
|
|
40
|
+
* @template Class The type of the decorated class associated with this context.
|
|
41
|
+
*/
|
|
42
|
+
interface ClassDecoratorContext<
|
|
43
|
+
Class extends abstract new (...args: any) => any = abstract new (...args: any) => any,
|
|
44
|
+
> {
|
|
45
|
+
/** The kind of element that was decorated. */
|
|
46
|
+
readonly kind: "class";
|
|
47
|
+
|
|
48
|
+
/** The name of the decorated class. */
|
|
49
|
+
readonly name: string | undefined;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Adds a callback to be invoked after the class definition has been finalized.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* function customElement(name: string): ClassDecoratorFunction {
|
|
57
|
+
* return (target, context) => {
|
|
58
|
+
* context.addInitializer(function () {
|
|
59
|
+
* customElements.define(name, this);
|
|
60
|
+
* });
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* @customElement("my-element")
|
|
65
|
+
* class MyElement {}
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
addInitializer(initializer: (this: Class) => void): void;
|
|
69
|
+
|
|
70
|
+
readonly metadata: DecoratorMetadata;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Context provided to a class method decorator.
|
|
75
|
+
* @template This The type on which the class element will be defined. For a static class element, this will be
|
|
76
|
+
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
|
77
|
+
* @template Value The type of the decorated class method.
|
|
78
|
+
*/
|
|
79
|
+
interface ClassMethodDecoratorContext<
|
|
80
|
+
This = unknown,
|
|
81
|
+
Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any,
|
|
82
|
+
> {
|
|
83
|
+
/** The kind of class element that was decorated. */
|
|
84
|
+
readonly kind: "method";
|
|
85
|
+
|
|
86
|
+
/** The name of the decorated class element. */
|
|
87
|
+
readonly name: string | symbol;
|
|
88
|
+
|
|
89
|
+
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
|
90
|
+
readonly static: boolean;
|
|
91
|
+
|
|
92
|
+
/** A value indicating whether the class element has a private name. */
|
|
93
|
+
readonly private: boolean;
|
|
94
|
+
|
|
95
|
+
/** An object that can be used to access the current value of the class element at runtime. */
|
|
96
|
+
readonly access: {
|
|
97
|
+
/**
|
|
98
|
+
* Determines whether an object has a property with the same name as the decorated element.
|
|
99
|
+
*/
|
|
100
|
+
has(object: This): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Gets the current value of the method from the provided object.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* let fn = context.access.get(instance);
|
|
106
|
+
*/
|
|
107
|
+
get(object: This): Value;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Adds a callback to be invoked either after static methods are defined but before
|
|
112
|
+
* static initializers are run (when decorating a `static` element), or before instance
|
|
113
|
+
* initializers are run (when decorating a non-`static` element).
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const bound: ClassMethodDecoratorFunction = (value, context) {
|
|
118
|
+
* if (context.private) throw new TypeError("Not supported on private methods.");
|
|
119
|
+
* context.addInitializer(function () {
|
|
120
|
+
* this[context.name] = this[context.name].bind(this);
|
|
121
|
+
* });
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* class C {
|
|
125
|
+
* message = "Hello";
|
|
126
|
+
*
|
|
127
|
+
* @bound
|
|
128
|
+
* m() {
|
|
129
|
+
* console.log(this.message);
|
|
130
|
+
* }
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
addInitializer(initializer: (this: This) => void): void;
|
|
135
|
+
|
|
136
|
+
readonly metadata: DecoratorMetadata;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Context provided to a class getter decorator.
|
|
141
|
+
* @template This The type on which the class element will be defined. For a static class element, this will be
|
|
142
|
+
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
|
143
|
+
* @template Value The property type of the decorated class getter.
|
|
144
|
+
*/
|
|
145
|
+
interface ClassGetterDecoratorContext<
|
|
146
|
+
This = unknown,
|
|
147
|
+
Value = unknown,
|
|
148
|
+
> {
|
|
149
|
+
/** The kind of class element that was decorated. */
|
|
150
|
+
readonly kind: "getter";
|
|
151
|
+
|
|
152
|
+
/** The name of the decorated class element. */
|
|
153
|
+
readonly name: string | symbol;
|
|
154
|
+
|
|
155
|
+
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
|
156
|
+
readonly static: boolean;
|
|
157
|
+
|
|
158
|
+
/** A value indicating whether the class element has a private name. */
|
|
159
|
+
readonly private: boolean;
|
|
160
|
+
|
|
161
|
+
/** An object that can be used to access the current value of the class element at runtime. */
|
|
162
|
+
readonly access: {
|
|
163
|
+
/**
|
|
164
|
+
* Determines whether an object has a property with the same name as the decorated element.
|
|
165
|
+
*/
|
|
166
|
+
has(object: This): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Invokes the getter on the provided object.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* let value = context.access.get(instance);
|
|
172
|
+
*/
|
|
173
|
+
get(object: This): Value;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Adds a callback to be invoked either after static methods are defined but before
|
|
178
|
+
* static initializers are run (when decorating a `static` element), or before instance
|
|
179
|
+
* initializers are run (when decorating a non-`static` element).
|
|
180
|
+
*/
|
|
181
|
+
addInitializer(initializer: (this: This) => void): void;
|
|
182
|
+
|
|
183
|
+
readonly metadata: DecoratorMetadata;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Context provided to a class setter decorator.
|
|
188
|
+
* @template This The type on which the class element will be defined. For a static class element, this will be
|
|
189
|
+
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
|
190
|
+
* @template Value The type of the decorated class setter.
|
|
191
|
+
*/
|
|
192
|
+
interface ClassSetterDecoratorContext<
|
|
193
|
+
This = unknown,
|
|
194
|
+
Value = unknown,
|
|
195
|
+
> {
|
|
196
|
+
/** The kind of class element that was decorated. */
|
|
197
|
+
readonly kind: "setter";
|
|
198
|
+
|
|
199
|
+
/** The name of the decorated class element. */
|
|
200
|
+
readonly name: string | symbol;
|
|
201
|
+
|
|
202
|
+
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
|
203
|
+
readonly static: boolean;
|
|
204
|
+
|
|
205
|
+
/** A value indicating whether the class element has a private name. */
|
|
206
|
+
readonly private: boolean;
|
|
207
|
+
|
|
208
|
+
/** An object that can be used to access the current value of the class element at runtime. */
|
|
209
|
+
readonly access: {
|
|
210
|
+
/**
|
|
211
|
+
* Determines whether an object has a property with the same name as the decorated element.
|
|
212
|
+
*/
|
|
213
|
+
has(object: This): boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Invokes the setter on the provided object.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* context.access.set(instance, value);
|
|
219
|
+
*/
|
|
220
|
+
set(object: This, value: Value): void;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Adds a callback to be invoked either after static methods are defined but before
|
|
225
|
+
* static initializers are run (when decorating a `static` element), or before instance
|
|
226
|
+
* initializers are run (when decorating a non-`static` element).
|
|
227
|
+
*/
|
|
228
|
+
addInitializer(initializer: (this: This) => void): void;
|
|
229
|
+
|
|
230
|
+
readonly metadata: DecoratorMetadata;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Context provided to a class `accessor` field decorator.
|
|
235
|
+
* @template This The type on which the class element will be defined. For a static class element, this will be
|
|
236
|
+
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
|
237
|
+
* @template Value The type of decorated class field.
|
|
238
|
+
*/
|
|
239
|
+
interface ClassAccessorDecoratorContext<
|
|
240
|
+
This = unknown,
|
|
241
|
+
Value = unknown,
|
|
242
|
+
> {
|
|
243
|
+
/** The kind of class element that was decorated. */
|
|
244
|
+
readonly kind: "accessor";
|
|
245
|
+
|
|
246
|
+
/** The name of the decorated class element. */
|
|
247
|
+
readonly name: string | symbol;
|
|
248
|
+
|
|
249
|
+
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
|
250
|
+
readonly static: boolean;
|
|
251
|
+
|
|
252
|
+
/** A value indicating whether the class element has a private name. */
|
|
253
|
+
readonly private: boolean;
|
|
254
|
+
|
|
255
|
+
/** An object that can be used to access the current value of the class element at runtime. */
|
|
256
|
+
readonly access: {
|
|
257
|
+
/**
|
|
258
|
+
* Determines whether an object has a property with the same name as the decorated element.
|
|
259
|
+
*/
|
|
260
|
+
has(object: This): boolean;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Invokes the getter on the provided object.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* let value = context.access.get(instance);
|
|
267
|
+
*/
|
|
268
|
+
get(object: This): Value;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Invokes the setter on the provided object.
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* context.access.set(instance, value);
|
|
275
|
+
*/
|
|
276
|
+
set(object: This, value: Value): void;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Adds a callback to be invoked immediately after the auto `accessor` being
|
|
281
|
+
* decorated is initialized (regardless if the `accessor` is `static` or not).
|
|
282
|
+
*/
|
|
283
|
+
addInitializer(initializer: (this: This) => void): void;
|
|
284
|
+
|
|
285
|
+
readonly metadata: DecoratorMetadata;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Describes the target provided to class `accessor` field decorators.
|
|
290
|
+
* @template This The `this` type to which the target applies.
|
|
291
|
+
* @template Value The property type for the class `accessor` field.
|
|
292
|
+
*/
|
|
293
|
+
interface ClassAccessorDecoratorTarget<This, Value> {
|
|
294
|
+
/**
|
|
295
|
+
* Invokes the getter that was defined prior to decorator application.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* let value = target.get.call(instance);
|
|
299
|
+
*/
|
|
300
|
+
get(this: This): Value;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Invokes the setter that was defined prior to decorator application.
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* target.set.call(instance, value);
|
|
307
|
+
*/
|
|
308
|
+
set(this: This, value: Value): void;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Describes the allowed return value from a class `accessor` field decorator.
|
|
313
|
+
* @template This The `this` type to which the target applies.
|
|
314
|
+
* @template Value The property type for the class `accessor` field.
|
|
315
|
+
*/
|
|
316
|
+
interface ClassAccessorDecoratorResult<This, Value> {
|
|
317
|
+
/**
|
|
318
|
+
* An optional replacement getter function. If not provided, the existing getter function is used instead.
|
|
319
|
+
*/
|
|
320
|
+
get?(this: This): Value;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* An optional replacement setter function. If not provided, the existing setter function is used instead.
|
|
324
|
+
*/
|
|
325
|
+
set?(this: This, value: Value): void;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* An optional initializer mutator that is invoked when the underlying field initializer is evaluated.
|
|
329
|
+
* @param value The incoming initializer value.
|
|
330
|
+
* @returns The replacement initializer value.
|
|
331
|
+
*/
|
|
332
|
+
init?(this: This, value: Value): Value;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Context provided to a class field decorator.
|
|
337
|
+
* @template This The type on which the class element will be defined. For a static class element, this will be
|
|
338
|
+
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
|
339
|
+
* @template Value The type of the decorated class field.
|
|
340
|
+
*/
|
|
341
|
+
interface ClassFieldDecoratorContext<
|
|
342
|
+
This = unknown,
|
|
343
|
+
Value = unknown,
|
|
344
|
+
> {
|
|
345
|
+
/** The kind of class element that was decorated. */
|
|
346
|
+
readonly kind: "field";
|
|
347
|
+
|
|
348
|
+
/** The name of the decorated class element. */
|
|
349
|
+
readonly name: string | symbol;
|
|
350
|
+
|
|
351
|
+
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
|
352
|
+
readonly static: boolean;
|
|
353
|
+
|
|
354
|
+
/** A value indicating whether the class element has a private name. */
|
|
355
|
+
readonly private: boolean;
|
|
356
|
+
|
|
357
|
+
/** An object that can be used to access the current value of the class element at runtime. */
|
|
358
|
+
readonly access: {
|
|
359
|
+
/**
|
|
360
|
+
* Determines whether an object has a property with the same name as the decorated element.
|
|
361
|
+
*/
|
|
362
|
+
has(object: This): boolean;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Gets the value of the field on the provided object.
|
|
366
|
+
*/
|
|
367
|
+
get(object: This): Value;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Sets the value of the field on the provided object.
|
|
371
|
+
*/
|
|
372
|
+
set(object: This, value: Value): void;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Adds a callback to be invoked immediately after the field being decorated
|
|
377
|
+
* is initialized (regardless if the field is `static` or not).
|
|
378
|
+
*/
|
|
379
|
+
addInitializer(initializer: (this: This) => void): void;
|
|
380
|
+
|
|
381
|
+
readonly metadata: DecoratorMetadata;
|
|
382
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
MERCHANTABILITY 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
|
+
declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
|
|
18
|
+
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
|
|
19
|
+
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
|
20
|
+
declare type ParameterDecorator = (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
MERCHANTABILITY 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
|
+
// This file's contents are now included in the main types file.
|
|
18
|
+
// The file has been left for backward compatibility.
|