async-browser-context 0.2.4 → 0.3.1
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/CHANGELOG.md +94 -0
- package/README.md +45 -30
- package/dist/babel/async-generator-helpers.d.ts +6 -6
- package/dist/babel/async-generator-helpers.d.ts.map +1 -1
- package/dist/babel/async-generator-helpers.js +33 -22
- package/dist/babel/async-generator-helpers.js.map +1 -1
- package/dist/babel/async-generator-resources.d.ts +14 -0
- package/dist/babel/async-generator-resources.d.ts.map +1 -0
- package/dist/babel/async-generator-resources.js +38 -0
- package/dist/babel/async-generator-resources.js.map +1 -0
- package/dist/babel/bind-generators.d.ts +1 -1
- package/dist/babel/bind-generators.d.ts.map +1 -1
- package/dist/babel/bind-generators.js +88 -44
- package/dist/babel/bind-generators.js.map +1 -1
- package/dist/babel/name-coroutines.d.ts +14 -8
- package/dist/babel/name-coroutines.d.ts.map +1 -1
- package/dist/babel/name-coroutines.js +160 -39
- package/dist/babel/name-coroutines.js.map +1 -1
- package/dist/babel/preset.d.ts +24 -13
- package/dist/babel/preset.d.ts.map +1 -1
- package/dist/babel/preset.js +37 -9
- package/dist/babel/preset.js.map +1 -1
- package/dist/babel/runtime-calls.d.ts +22 -0
- package/dist/babel/runtime-calls.d.ts.map +1 -0
- package/dist/babel/runtime-calls.js +69 -0
- package/dist/babel/runtime-calls.js.map +1 -0
- package/dist/babel/skip-runtime.d.ts +18 -11
- package/dist/babel/skip-runtime.d.ts.map +1 -1
- package/dist/babel/skip-runtime.js +52 -16
- package/dist/babel/skip-runtime.js.map +1 -1
- package/dist/babel/static-members.d.ts +4 -0
- package/dist/babel/static-members.d.ts.map +1 -0
- package/dist/babel/static-members.js +112 -0
- package/dist/babel/static-members.js.map +1 -0
- package/dist/core/async-generator.d.ts +26 -8
- package/dist/core/async-generator.d.ts.map +1 -1
- package/dist/core/async-generator.js +162 -44
- package/dist/core/async-generator.js.map +1 -1
- package/dist/core/async-local-storage.d.ts +3 -0
- package/dist/core/async-local-storage.d.ts.map +1 -1
- package/dist/core/async-local-storage.js +3 -0
- package/dist/core/async-local-storage.js.map +1 -1
- package/dist/core/callback-hook.d.ts +3 -3
- package/dist/core/coroutine.d.ts +6 -2
- package/dist/core/coroutine.d.ts.map +1 -1
- package/dist/core/coroutine.js +35 -21
- package/dist/core/coroutine.js.map +1 -1
- package/dist/core/function-name.d.ts +9 -0
- package/dist/core/function-name.d.ts.map +1 -0
- package/dist/core/function-name.js +12 -0
- package/dist/core/function-name.js.map +1 -0
- package/dist/core/hooks.d.ts +2 -1
- package/dist/core/hooks.d.ts.map +1 -1
- package/dist/core/hooks.js +21 -6
- package/dist/core/hooks.js.map +1 -1
- package/dist/core/snapshot.d.ts +2 -1
- package/dist/core/snapshot.d.ts.map +1 -1
- package/dist/core/snapshot.js +7 -3
- package/dist/core/snapshot.js.map +1 -1
- package/dist/core/store.d.ts +28 -0
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/store.js +90 -20
- package/dist/core/store.js.map +1 -1
- package/dist/core/variable.d.ts +2 -1
- package/dist/core/variable.d.ts.map +1 -1
- package/dist/core/variable.js +5 -2
- package/dist/core/variable.js.map +1 -1
- package/dist/node/index.d.ts +10 -4
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +51 -16
- package/dist/node/index.js.map +1 -1
- package/dist/node/runtime.d.ts +7 -6
- package/dist/node/runtime.d.ts.map +1 -1
- package/dist/node/runtime.js +29 -16
- package/dist/node/runtime.js.map +1 -1
- package/dist/opentelemetry/context-manager.d.ts.map +1 -1
- package/dist/opentelemetry/context-manager.js +172 -13
- package/dist/opentelemetry/context-manager.js.map +1 -1
- package/dist/patches/callbacks.d.ts.map +1 -1
- package/dist/patches/callbacks.js +84 -29
- package/dist/patches/callbacks.js.map +1 -1
- package/dist/patches/events.d.ts.map +1 -1
- package/dist/patches/events.js +203 -91
- package/dist/patches/events.js.map +1 -1
- package/dist/patches/handler-interfaces.d.ts +4 -3
- package/dist/patches/handler-interfaces.d.ts.map +1 -1
- package/dist/patches/handler-interfaces.js +7 -5
- package/dist/patches/handler-interfaces.js.map +1 -1
- package/dist/patches/promise.d.ts +3 -0
- package/dist/patches/promise.d.ts.map +1 -1
- package/dist/patches/promise.js +13 -5
- package/dist/patches/promise.js.map +1 -1
- package/dist/patches/streams.d.ts.map +1 -1
- package/dist/patches/streams.js +36 -16
- package/dist/patches/streams.js.map +1 -1
- package/dist/patches/timers.d.ts.map +1 -1
- package/dist/patches/timers.js +17 -5
- package/dist/patches/timers.js.map +1 -1
- package/dist/patches/to-string.d.ts +4 -0
- package/dist/patches/to-string.d.ts.map +1 -1
- package/dist/patches/to-string.js +12 -6
- package/dist/patches/to-string.js.map +1 -1
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +3 -3
- package/dist/runtime.js.map +1 -1
- package/dist/vite/plugin.d.ts +7 -2
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/vite/plugin.js +30 -6
- package/dist/vite/plugin.js.map +1 -1
- package/package.json +52 -25
- package/src/babel/async-generator-helpers.ts +34 -23
- package/src/babel/async-generator-resources.ts +40 -0
- package/src/babel/bind-generators.ts +91 -47
- package/src/babel/name-coroutines.ts +170 -41
- package/src/babel/preset.ts +47 -15
- package/src/babel/runtime-calls.ts +73 -0
- package/src/babel/skip-runtime.ts +58 -18
- package/src/babel/static-members.ts +117 -0
- package/src/core/async-generator.ts +169 -46
- package/src/core/async-local-storage.ts +3 -0
- package/src/core/callback-hook.ts +3 -3
- package/src/core/coroutine.ts +35 -21
- package/src/core/function-name.ts +11 -0
- package/src/core/hooks.ts +23 -6
- package/src/core/snapshot.ts +8 -3
- package/src/core/store.ts +107 -21
- package/src/core/variable.ts +6 -2
- package/src/node/index.ts +62 -19
- package/src/node/runtime.ts +33 -15
- package/src/opentelemetry/context-manager.ts +188 -13
- package/src/patches/callbacks.ts +87 -30
- package/src/patches/events.ts +249 -103
- package/src/patches/handler-interfaces.ts +7 -5
- package/src/patches/promise.ts +17 -13
- package/src/patches/streams.ts +36 -16
- package/src/patches/timers.ts +17 -5
- package/src/patches/to-string.ts +12 -6
- package/src/runtime.ts +3 -3
- package/src/vite/plugin.ts +38 -8
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
* The async generators of transformed code. `@babel/plugin-transform-async-generator-functions`
|
|
3
3
|
* changes each async generator into a sync generator and its helper `wrapAsyncGenerator`.
|
|
4
4
|
* The helper continued each step in a `then` callback, and a `then` callback is slow in
|
|
5
|
-
* Firefox. The preset replaces the helper with `asyncGenerator` of the runtime
|
|
6
|
-
*
|
|
7
|
-
* continues each step with a native `await`.
|
|
5
|
+
* Firefox. The preset replaces the helper with `asyncGenerator` of the runtime. It also takes
|
|
6
|
+
* the helpers `OverloadYield`, `awaitAsyncGenerator` and `asyncGeneratorDelegate` from this
|
|
7
|
+
* module. The driver in this module then continues each step with a native `await`.
|
|
8
8
|
*
|
|
9
9
|
* The protocol is the protocol of the Babel 8 helper: the body gives
|
|
10
10
|
* `new OverloadYield(value, 0)` for an `await`, and `new OverloadYield(promise, 1)` for a
|
|
11
11
|
* step of `yield*`. Each other value is a `yield`. Where the helper differs from a native async
|
|
12
12
|
* generator, the driver does as the native generator. Thus `return()` at a `yield` awaits its
|
|
13
|
-
* value first, and a request on a complete generator settles at once.
|
|
13
|
+
* value first, and a request on a complete generator settles at once. The delegate of this
|
|
14
|
+
* module also gives kind 2 for a step of `yield*` after `return()`.
|
|
14
15
|
*/
|
|
15
16
|
/** The Promise of the time when the module loads, for the rejections of the methods. */
|
|
16
17
|
const NativePromise = Promise;
|
|
17
18
|
/**
|
|
18
|
-
* The value that the body gives for an `await` (kind 0)
|
|
19
|
-
*
|
|
19
|
+
* The value that the body gives for an `await` (kind 0), for a step of `yield*` (kind 1), or
|
|
20
|
+
* for a step of `yield*` after `return()` (kind 2). The helpers `awaitAsyncGenerator` and
|
|
21
|
+
* `asyncGeneratorDelegate` make it with `new`.
|
|
20
22
|
*/
|
|
21
23
|
export class OverloadYield {
|
|
22
24
|
v;
|
|
@@ -26,6 +28,83 @@ export class OverloadYield {
|
|
|
26
28
|
this.k = kind;
|
|
27
29
|
}
|
|
28
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* The error of a step of `yield*` that was rejected. The driver gives it back to the delegate,
|
|
33
|
+
* and the delegate throws the error. Thus the error goes into the body at the `yield*`, also
|
|
34
|
+
* when the delegate has no `throw` method.
|
|
35
|
+
*/
|
|
36
|
+
class DelegateRejection {
|
|
37
|
+
error;
|
|
38
|
+
constructor(error) {
|
|
39
|
+
this.error = error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The helper `awaitAsyncGenerator` of Babel: the body gives its value for an `await`. The preset
|
|
44
|
+
* gives this function in place of the helper of Babel. Thus the marker is always the class of this
|
|
45
|
+
* module, also when `@babel/plugin-transform-runtime` gives the other helpers.
|
|
46
|
+
*/
|
|
47
|
+
export function awaitAsyncGenerator(value) {
|
|
48
|
+
return new OverloadYield(value, 0);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The helper `asyncGeneratorDelegate` of Babel 8: a sync iterator for `yield*` in an async
|
|
52
|
+
* generator. Each step of the inner async iterator becomes `new OverloadYield(promise, 1)`, or
|
|
53
|
+
* kind 2 after `return()`. The driver awaits the promise, and gives a copy of its result back to
|
|
54
|
+
* the iterator. After kind 2, the driver gives it back with `return()`. Thus a complete inner
|
|
55
|
+
* iterator ends the body, as with a native `yield*`.
|
|
56
|
+
*/
|
|
57
|
+
export function asyncGeneratorDelegate(inner) {
|
|
58
|
+
const iterator = inner;
|
|
59
|
+
let waiting = false;
|
|
60
|
+
const pump = (key, value) => {
|
|
61
|
+
waiting = true;
|
|
62
|
+
const promise = new NativePromise((resolve) => {
|
|
63
|
+
resolve(Reflect.apply(iterator[key], inner, [value]));
|
|
64
|
+
});
|
|
65
|
+
return { done: false, value: new OverloadYield(promise, key === "return" ? 2 : 1) };
|
|
66
|
+
};
|
|
67
|
+
const delegate = {
|
|
68
|
+
[Symbol.iterator]() { return this; },
|
|
69
|
+
next(value) {
|
|
70
|
+
if (!waiting) {
|
|
71
|
+
return pump("next", value);
|
|
72
|
+
}
|
|
73
|
+
waiting = false;
|
|
74
|
+
if (value instanceof DelegateRejection) {
|
|
75
|
+
throw value.error;
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
delegate["throw"] = (value) => {
|
|
81
|
+
if (typeof iterator.throw === "function") {
|
|
82
|
+
return pump("throw", value);
|
|
83
|
+
}
|
|
84
|
+
// Without a throw method, a native yield* closes the inner iterator and awaits its return()
|
|
85
|
+
// (AsyncIteratorClose). An error of return() goes into the body, else a TypeError.
|
|
86
|
+
waiting = true;
|
|
87
|
+
const closed = new NativePromise((resolve) => {
|
|
88
|
+
resolve(typeof iterator.return === "function" ? Reflect.apply(iterator.return, inner, []) : undefined);
|
|
89
|
+
}).then((result) => {
|
|
90
|
+
if (typeof iterator.return === "function" && !isObject(result)) {
|
|
91
|
+
throw new TypeError("The result of return() of the iterator of yield* is not an object");
|
|
92
|
+
}
|
|
93
|
+
throw new TypeError("The iterator of yield* has no throw method");
|
|
94
|
+
});
|
|
95
|
+
return { done: false, value: new OverloadYield(closed, 1) };
|
|
96
|
+
};
|
|
97
|
+
if (typeof iterator.return === "function") {
|
|
98
|
+
delegate["return"] = (value) => {
|
|
99
|
+
if (waiting) {
|
|
100
|
+
waiting = false;
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
return pump("return", value);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return delegate;
|
|
107
|
+
}
|
|
29
108
|
/**
|
|
30
109
|
* A value that is not a thenable, in a box. The browser runtime reads the `then` property of an
|
|
31
110
|
* awaited object one time, in the context of the body. When the object has no `then` method,
|
|
@@ -42,6 +121,10 @@ export class PlainValue {
|
|
|
42
121
|
export function unbox(value) {
|
|
43
122
|
return value instanceof PlainValue ? value.value : value;
|
|
44
123
|
}
|
|
124
|
+
/** This function gives `true` for a value that can have properties: an object or a function. */
|
|
125
|
+
export function isObject(value) {
|
|
126
|
+
return (typeof value === "object" && value !== null) || typeof value === "function";
|
|
127
|
+
}
|
|
45
128
|
/** The key of the request function of each async generator object. */
|
|
46
129
|
const INVOKE = Symbol("async-browser-context/invoke");
|
|
47
130
|
/** This function starts a request. For an object that is not an async generator of the runtime, it gives a rejected promise, as a native method does. */
|
|
@@ -53,27 +136,31 @@ function request(target, key, argument) {
|
|
|
53
136
|
return invoke(key, argument);
|
|
54
137
|
}
|
|
55
138
|
/**
|
|
56
|
-
* This function gives %AsyncIteratorPrototype% of the engine
|
|
57
|
-
* `Symbol.asyncDispose` and the async iterator
|
|
58
|
-
* generator
|
|
139
|
+
* This function gives %AsyncIteratorPrototype% of the engine from an async generator function.
|
|
140
|
+
* The prototype gives `Symbol.asyncIterator`, `Symbol.asyncDispose` and the async iterator
|
|
141
|
+
* helpers. If a compiler changed the async generator function, the function gives `undefined`.
|
|
142
|
+
*
|
|
143
|
+
* @internal
|
|
59
144
|
*/
|
|
60
|
-
function
|
|
145
|
+
export function asyncIteratorPrototypeOf(generatorFunction) {
|
|
146
|
+
let prototype;
|
|
61
147
|
try {
|
|
62
|
-
|
|
63
|
-
// The directive tells the Babel preset not to change this function (src/babel/skip-runtime.ts)
|
|
64
|
-
// Stryker disable next-line all: the directive matters only when a bundler applies the preset to the runtime
|
|
65
|
-
"async-browser-context runtime";
|
|
66
|
-
};
|
|
67
|
-
const prototype = Object.getPrototypeOf(Object.getPrototypeOf(generatorFunction.prototype));
|
|
68
|
-
return prototype !== null && typeof prototype[Symbol.asyncIterator] === "function" ? prototype : undefined;
|
|
148
|
+
prototype = Object.getPrototypeOf(Object.getPrototypeOf(generatorFunction.prototype));
|
|
69
149
|
}
|
|
70
150
|
catch {
|
|
151
|
+
// A function without a prototype object, for example an arrow function
|
|
71
152
|
return undefined;
|
|
72
153
|
}
|
|
154
|
+
return prototype !== null && typeof prototype[Symbol.asyncIterator] === "function" ? prototype : undefined;
|
|
73
155
|
}
|
|
74
|
-
/**
|
|
75
|
-
|
|
76
|
-
|
|
156
|
+
/**
|
|
157
|
+
* This function makes the prototype of the async generator objects of transformed code. Its
|
|
158
|
+
* methods are not enumerable, as native methods. Without `parent`, the prototype inherits from
|
|
159
|
+
* `Object.prototype` and gets its own `Symbol.asyncIterator` method.
|
|
160
|
+
*
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
export function makeAsyncGeneratorPrototype(parent) {
|
|
77
164
|
const prototype = Object.create(parent ?? Object.prototype);
|
|
78
165
|
const methods = {
|
|
79
166
|
next(value) { return request(this, "next", value); },
|
|
@@ -88,7 +175,28 @@ const AsyncGeneratorPrototype = (() => {
|
|
|
88
175
|
}
|
|
89
176
|
Object.defineProperty(prototype, Symbol.toStringTag, { value: "AsyncGenerator", configurable: true });
|
|
90
177
|
return prototype;
|
|
91
|
-
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* This function gives %AsyncIteratorPrototype% of the engine, or `undefined`. Another preset in
|
|
181
|
+
* the same Babel configuration, for example `next/babel` with its preset-env, can change the
|
|
182
|
+
* async generator below in the runtime itself. Its helper is then a module that loads at this
|
|
183
|
+
* time, and the call can throw. The catch keeps the runtime available, with a prototype
|
|
184
|
+
* without the parent of the engine.
|
|
185
|
+
*/
|
|
186
|
+
function engineAsyncIteratorPrototype() {
|
|
187
|
+
try {
|
|
188
|
+
return asyncIteratorPrototypeOf(async function* () {
|
|
189
|
+
// The directive tells the Babel preset not to change this function (src/babel/skip-runtime.ts)
|
|
190
|
+
// Stryker disable next-line all: the directive matters only when a bundler applies the preset to the runtime
|
|
191
|
+
"async-browser-context runtime";
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/** The prototype of the async generator objects of transformed code. */
|
|
199
|
+
const AsyncGeneratorPrototype = makeAsyncGeneratorPrototype(engineAsyncIteratorPrototype());
|
|
92
200
|
/**
|
|
93
201
|
* This function makes an async generator object. The object queues the requests of the
|
|
94
202
|
* consumer, and starts one request at a time, as a native async generator does. `enter`
|
|
@@ -97,8 +205,10 @@ const AsyncGeneratorPrototype = (() => {
|
|
|
97
205
|
export function createAsyncGenerator(step, PromiseConstructor, enter = (start) => start(), prepare = (value) => value) {
|
|
98
206
|
let first;
|
|
99
207
|
let last;
|
|
100
|
-
/**
|
|
101
|
-
let
|
|
208
|
+
/** `true` after the first step of the body. While a step operates, the requests wait in the queue. */
|
|
209
|
+
let started = false;
|
|
210
|
+
/** `true` when the body is complete. */
|
|
211
|
+
let complete = false;
|
|
102
212
|
/** This function starts the requests in the queue, one after the other, until the queue is empty. */
|
|
103
213
|
const run = async (key, argument) => {
|
|
104
214
|
// The directive tells the Babel preset not to change this function (src/babel/skip-runtime.ts)
|
|
@@ -108,12 +218,10 @@ export function createAsyncGenerator(step, PromiseConstructor, enter = (start) =
|
|
|
108
218
|
for (;;) {
|
|
109
219
|
let failed = false;
|
|
110
220
|
let settled;
|
|
111
|
-
let done = false;
|
|
112
221
|
try {
|
|
113
|
-
if (
|
|
222
|
+
if (complete || (!started && key !== "next")) {
|
|
114
223
|
// The body does not operate: it is complete, or return() or throw() came before the start
|
|
115
|
-
|
|
116
|
-
done = true;
|
|
224
|
+
complete = true;
|
|
117
225
|
if (key === "throw") {
|
|
118
226
|
throw argument;
|
|
119
227
|
}
|
|
@@ -123,6 +231,7 @@ export function createAsyncGenerator(step, PromiseConstructor, enter = (start) =
|
|
|
123
231
|
}
|
|
124
232
|
}
|
|
125
233
|
else {
|
|
234
|
+
started = true;
|
|
126
235
|
if (key === "return") {
|
|
127
236
|
// At a yield, return() awaits its value first. A rejection goes into the body at the yield.
|
|
128
237
|
try {
|
|
@@ -135,7 +244,16 @@ export function createAsyncGenerator(step, PromiseConstructor, enter = (start) =
|
|
|
135
244
|
resumed = true;
|
|
136
245
|
}
|
|
137
246
|
let result = step(key, argument, resumed);
|
|
247
|
+
// return() at a yield already awaited its value. If the body completes with that value, a native generator does not await it again.
|
|
248
|
+
if (key === "return" && result.done === true && result.value === argument) {
|
|
249
|
+
settled = argument;
|
|
250
|
+
complete = true;
|
|
251
|
+
result = { done: true, value: undefined };
|
|
252
|
+
}
|
|
138
253
|
for (;;) {
|
|
254
|
+
if (complete) {
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
139
257
|
const yielded = result.value;
|
|
140
258
|
const overloaded = yielded instanceof OverloadYield;
|
|
141
259
|
let value;
|
|
@@ -143,37 +261,37 @@ export function createAsyncGenerator(step, PromiseConstructor, enter = (start) =
|
|
|
143
261
|
value = unbox(await prepare(overloaded ? yielded.v : yielded));
|
|
144
262
|
}
|
|
145
263
|
catch (error) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
result = step("throw", error, true);
|
|
264
|
+
// The error goes into the body at the await or the yield. The delegate of a yield* throws it.
|
|
265
|
+
result = overloaded && yielded.k !== 0 ? step("next", new DelegateRejection(error), true) : step("throw", error, true);
|
|
149
266
|
continue;
|
|
150
267
|
}
|
|
151
268
|
resumed = true;
|
|
152
269
|
if (overloaded) {
|
|
153
|
-
const
|
|
154
|
-
if (yielded.k === 0 ||
|
|
155
|
-
|
|
156
|
-
result = step(
|
|
270
|
+
const resumeKey = yielded.k === 2 ? "return" : "next";
|
|
271
|
+
if (yielded.k === 0 || !isObject(value)) {
|
|
272
|
+
// The value of an await. For a result of yield* that is not an object, the body throws a TypeError.
|
|
273
|
+
result = step(resumeKey, value, true);
|
|
157
274
|
continue;
|
|
158
275
|
}
|
|
159
|
-
// A step of yield
|
|
160
|
-
//
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
276
|
+
// A step of yield*. As a native yield*, the driver reads done and value one time, and the body gets a copy.
|
|
277
|
+
// The driver does not compare the result of the body with the copy, because the yield* of WebKit makes a new object.
|
|
278
|
+
const done = Boolean(value.done);
|
|
279
|
+
const item = value.value;
|
|
280
|
+
result = step(resumeKey, { value: item, done }, true);
|
|
281
|
+
if (done) {
|
|
164
282
|
continue;
|
|
165
283
|
}
|
|
166
|
-
|
|
284
|
+
// The body gives the result back. Its value is not awaited, as with a native yield*.
|
|
285
|
+
value = item;
|
|
167
286
|
}
|
|
168
287
|
settled = value;
|
|
169
|
-
|
|
288
|
+
complete = result.done === true;
|
|
170
289
|
break;
|
|
171
290
|
}
|
|
172
|
-
state = done ? "done" : "yield";
|
|
173
291
|
}
|
|
174
292
|
}
|
|
175
293
|
catch (error) {
|
|
176
|
-
|
|
294
|
+
complete = true;
|
|
177
295
|
failed = true;
|
|
178
296
|
settled = error;
|
|
179
297
|
}
|
|
@@ -184,7 +302,7 @@ export function createAsyncGenerator(step, PromiseConstructor, enter = (start) =
|
|
|
184
302
|
current.reject(settled);
|
|
185
303
|
}
|
|
186
304
|
else {
|
|
187
|
-
current.resolve({ value: settled, done });
|
|
305
|
+
current.resolve({ value: settled, done: complete });
|
|
188
306
|
}
|
|
189
307
|
if (first === undefined) {
|
|
190
308
|
last = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-generator.js","sourceRoot":"","sources":["../../src/core/async-generator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"async-generator.js","sourceRoot":"","sources":["../../src/core/async-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,wFAAwF;AACxF,MAAM,aAAa,GAAwB,OAAO,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACb,CAAC,CAAW;IACZ,CAAC,CAAa;IACvB,YAAY,KAAe,EAAE,IAAgB;QACzC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC;QACf,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IAClB,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,iBAAiB;IACV,KAAK,CAAW;IACzB,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AAuB,CAA8C,CAAC;IACtG,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAG,MAAM,EAAE,CAAC,CAAC;IAC7D,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
|
@@ -41,6 +41,9 @@ export declare class AsyncLocalStorage<T> {
|
|
|
41
41
|
* This method sets `store` for the rest of the current synchronous step, and for the
|
|
42
42
|
* code that this step starts later. Prefer `run()`: `enterWith()` can also
|
|
43
43
|
* change the store of the code that called the current function.
|
|
44
|
+
*
|
|
45
|
+
* Outside all steps, for example at the top level of a module, the store stays after the
|
|
46
|
+
* task as a default store, as on Node.js. No code sets the root context again.
|
|
44
47
|
*/
|
|
45
48
|
enterWith(store: T): void;
|
|
46
49
|
/** This method disables the storage. `getStore()` gives `undefined` until the next `run()` or `enterWith()`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-local-storage.d.ts","sourceRoot":"","sources":["../../src/core/async-local-storage.ts"],"names":[],"mappings":"AAGA,6FAA6F;AAC7F,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACvC,yDAAyD;IACzD,QAAQ,CAAC,YAAY,CAAC,EAAG,CAAC,GAAG,SAAS,CAAC;IACvC,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,CAAC,EAAG,MAAM,GAAG,SAAS,CAAC;CACvC;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,iBAAiB,CAAC,CAAC;;gBAIhB,OAAO,GAAG,wBAAwB,CAAC,CAAC,CAAM;IAItD,+BAA+B;IAC/B,IAAI,IAAI,IAAK,MAAM,CAElB;IAED;;;OAGG;IACH,QAAQ,IAAK,CAAC,GAAG,SAAS;IAI1B;;;;OAIG;IACH,GAAG,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAAE,KAAK,EAAG,CAAC,EAAE,QAAQ,EAAG,CAAC,GAAG,IAAI,EAAG,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,EAAG,C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AAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,EAAG,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,CAAC,GAAI,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,CAAC;IAIxG,gHAAgH;IAChH,MAAM,CAAC,QAAQ,IAAK,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAAE,EAAE,EAAG,CAAC,GAAG,IAAI,EAAG,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,CAAC;CAI1F"}
|
|
@@ -48,6 +48,9 @@ export class AsyncLocalStorage {
|
|
|
48
48
|
* This method sets `store` for the rest of the current synchronous step, and for the
|
|
49
49
|
* code that this step starts later. Prefer `run()`: `enterWith()` can also
|
|
50
50
|
* change the store of the code that called the current function.
|
|
51
|
+
*
|
|
52
|
+
* Outside all steps, for example at the top level of a module, the store stays after the
|
|
53
|
+
* task as a default store, as on Node.js. No code sets the root context again.
|
|
51
54
|
*/
|
|
52
55
|
enterWith(store) {
|
|
53
56
|
this.#enabled = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-local-storage.js","sourceRoot":"","sources":["../../src/core/async-local-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAUrD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,iBAAiB;IACjB,SAAS,CAAe;IACjC,QAAQ,GAAG,IAAI,CAAC;IAEhB,YAAY,UAAwC,EAAE;QAClD,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAI,EAAE,IAAI,EAAG,OAAO,CAAC,IAAI,EAAE,YAAY,EAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IACnG,CAAC;IAED,+BAA+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that the library starts. For
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* @param callback - The function that the library starts. For a step
|
|
12
|
+
* after an `await`, it is the body of the async function or the async
|
|
13
|
+
* generator. It has the name of that function.
|
|
14
14
|
* @param source - The API that got the callback, for example
|
|
15
15
|
* `"setTimeout"`, `"Promise.then"`, `"addEventListener:click"`,
|
|
16
16
|
* `"onclick"` or `"await"`.
|
package/dist/core/coroutine.d.ts
CHANGED
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
* This function gives an async function that operates `generatorFunction`. The preset gives
|
|
3
3
|
* this function to `@babel/plugin-transform-async-to-generator` as its
|
|
4
4
|
* `method` option, and adds `name`, the name of the async function, if it has one.
|
|
5
|
+
*
|
|
6
|
+
* The first step of the body operates in the step of the caller. Thus an `enterWith()` of that
|
|
7
|
+
* step stays for the caller, as on Node.js.
|
|
5
8
|
*/
|
|
6
9
|
export declare function coroutine<T, A extends unknown[], R>(generatorFunction: (this: T, ...args: A) => Generator<unknown, R, unknown>, name?: string): (this: T, ...args: A) => Promise<R>;
|
|
7
10
|
/**
|
|
8
11
|
* This function gives a function that makes an async generator object, which operates
|
|
9
12
|
* `generatorFunction`. The preset gives this function in place of the helper
|
|
10
|
-
* `wrapAsyncGenerator` of `@babel/plugin-transform-async-generator-functions`.
|
|
13
|
+
* `wrapAsyncGenerator` of `@babel/plugin-transform-async-generator-functions`. It adds `name`,
|
|
14
|
+
* the name of the async generator, if it has one.
|
|
11
15
|
*
|
|
12
16
|
* Each step of the body operates in the context of the call that made the generator
|
|
13
17
|
* (rule C5). The driver continues each step with a native `await` (`async-generator.ts`).
|
|
14
18
|
*/
|
|
15
|
-
export declare function asyncGenerator<T, A extends unknown[]>(generatorFunction: (this: T, ...args: A) => Generator<unknown, unknown, unknown
|
|
19
|
+
export declare function asyncGenerator<T, A extends unknown[]>(generatorFunction: (this: T, ...args: A) => Generator<unknown, unknown, unknown>, name?: string): (this: T, ...args: A) => AsyncGenerator<unknown, unknown, unknown>;
|
|
16
20
|
type AnyIterator = Iterator<unknown, unknown, unknown> | AsyncIterator<unknown, unknown, unknown>;
|
|
17
21
|
/**
|
|
18
22
|
* This function binds a generator object to the current context. The body of
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coroutine.d.ts","sourceRoot":"","sources":["../../src/core/coroutine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"coroutine.d.ts","sourceRoot":"","sources":["../../src/core/coroutine.ts"],"names":[],"mappings":"AAyEA;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC/C,iBAAiB,EAAG,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,EAC7E,IAAI,CAAC,EAAG,MAAM,GACd,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAkExC;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EACjD,iBAAiB,EAAG,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EACnF,IAAI,CAAC,EAAG,MAAM,GACd,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CA2CvE;AAED,KAAK,WAAW,GAAG,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAGlG;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,EAAE,SAAS,EAAG,CAAC,GAAI,CAAC,CA2BtE"}
|
package/dist/core/coroutine.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createAsyncGenerator, PlainValue, unbox } from "./async-generator.js";
|
|
2
|
-
import {
|
|
1
|
+
import { createAsyncGenerator, isObject, PlainValue, unbox } from "./async-generator.js";
|
|
2
|
+
import { copyNameAndLength } from "./function-name.js";
|
|
3
|
+
import { applyQuietly, applyWithHooks, store } from "./store.js";
|
|
3
4
|
/**
|
|
4
5
|
* The code from the Babel preset uses these runtime functions. Do not use them
|
|
5
6
|
* directly.
|
|
@@ -12,24 +13,19 @@ import { applyWithHooks, store } from "./store.js";
|
|
|
12
13
|
*/
|
|
13
14
|
/**
|
|
14
15
|
* This function gives the generator function to the callback hooks, with the name of the
|
|
15
|
-
* async function. The preset gives the name, because the generator function
|
|
16
|
+
* async function or the async generator. The preset gives the name, because the generator function
|
|
16
17
|
* of Babel has no name. The function sets the name only when a hook operates.
|
|
17
18
|
*/
|
|
18
19
|
function namedForHooks(generatorFunction, name) {
|
|
19
|
-
if (name
|
|
20
|
+
if (name === undefined) {
|
|
21
|
+
return generatorFunction;
|
|
22
|
+
}
|
|
23
|
+
// Stryker disable next-line ConditionalExpression: the check only prevents a second change to the same name
|
|
24
|
+
if (generatorFunction.name !== name) {
|
|
20
25
|
Object.defineProperty(generatorFunction, "name", { value: name, configurable: true });
|
|
21
26
|
}
|
|
22
27
|
return generatorFunction;
|
|
23
28
|
}
|
|
24
|
-
/**
|
|
25
|
-
* This function gives an async function that operates `generatorFunction`. The preset gives
|
|
26
|
-
* this function to `@babel/plugin-transform-async-to-generator` as its
|
|
27
|
-
* `method` option, and adds `name`, the name of the async function, if it has one.
|
|
28
|
-
*/
|
|
29
|
-
/** This function gives `true` for a value that can have a `then` property: an object or a function. */
|
|
30
|
-
function isObject(value) {
|
|
31
|
-
return (typeof value === "object" && value !== null) || typeof value === "function";
|
|
32
|
-
}
|
|
33
29
|
/**
|
|
34
30
|
* This function gives the value that a driver awaits or gives as its result, in place of `value`. It
|
|
35
31
|
* operates in the context of the body, as `await` reads the `then` property there:
|
|
@@ -77,12 +73,17 @@ function awaitable(value, NativePromise, box) {
|
|
|
77
73
|
* This function gives an async function that operates `generatorFunction`. The preset gives
|
|
78
74
|
* this function to `@babel/plugin-transform-async-to-generator` as its
|
|
79
75
|
* `method` option, and adds `name`, the name of the async function, if it has one.
|
|
76
|
+
*
|
|
77
|
+
* The first step of the body operates in the step of the caller. Thus an `enterWith()` of that
|
|
78
|
+
* step stays for the caller, as on Node.js.
|
|
80
79
|
*/
|
|
81
80
|
export function coroutine(generatorFunction, name) {
|
|
82
81
|
const NativePromise = store.intrinsics.Promise;
|
|
83
|
-
|
|
82
|
+
const asyncFunction = function asyncFunction(...args) {
|
|
84
83
|
// The context of the call. The body can change it with AsyncLocalStorage.enterWith.
|
|
85
84
|
let frame = store.current;
|
|
85
|
+
// An async function that a hook starts does not start the hooks (store.ts, applyQuietly)
|
|
86
|
+
const quiet = store.inHook === true;
|
|
86
87
|
let generator;
|
|
87
88
|
const next = (value) => generator.next(value);
|
|
88
89
|
const throwInto = (error) => generator.throw(error);
|
|
@@ -98,9 +99,11 @@ export function coroutine(generatorFunction, name) {
|
|
|
98
99
|
store.current = frame;
|
|
99
100
|
try {
|
|
100
101
|
const hooks = resumed ? store.hooks : undefined;
|
|
101
|
-
const result =
|
|
102
|
-
? resume
|
|
103
|
-
:
|
|
102
|
+
const result = quiet
|
|
103
|
+
? applyQuietly(resume, undefined, [argument])
|
|
104
|
+
: hooks === undefined
|
|
105
|
+
? resume(argument)
|
|
106
|
+
: applyWithHooks(hooks, namedForHooks(generatorFunction, name), "await", resume, undefined, [argument]);
|
|
104
107
|
// The result object is new for each step, so the change is not visible to other code
|
|
105
108
|
result.value = awaitable(result.value, NativePromise, result.done !== true);
|
|
106
109
|
return result;
|
|
@@ -137,19 +140,25 @@ export function coroutine(generatorFunction, name) {
|
|
|
137
140
|
};
|
|
138
141
|
return drive();
|
|
139
142
|
};
|
|
143
|
+
// Where Babel gives no named wrapper, for example in a class field, the function keeps the name and the length of the source
|
|
144
|
+
copyNameAndLength(asyncFunction, name, generatorFunction.length);
|
|
145
|
+
return asyncFunction;
|
|
140
146
|
}
|
|
141
147
|
/**
|
|
142
148
|
* This function gives a function that makes an async generator object, which operates
|
|
143
149
|
* `generatorFunction`. The preset gives this function in place of the helper
|
|
144
|
-
* `wrapAsyncGenerator` of `@babel/plugin-transform-async-generator-functions`.
|
|
150
|
+
* `wrapAsyncGenerator` of `@babel/plugin-transform-async-generator-functions`. It adds `name`,
|
|
151
|
+
* the name of the async generator, if it has one.
|
|
145
152
|
*
|
|
146
153
|
* Each step of the body operates in the context of the call that made the generator
|
|
147
154
|
* (rule C5). The driver continues each step with a native `await` (`async-generator.ts`).
|
|
148
155
|
*/
|
|
149
|
-
export function asyncGenerator(generatorFunction) {
|
|
156
|
+
export function asyncGenerator(generatorFunction, name) {
|
|
150
157
|
const NativePromise = store.intrinsics.Promise;
|
|
151
|
-
|
|
158
|
+
const makeAsyncGenerator = function makeAsyncGenerator(...args) {
|
|
152
159
|
let frame = store.current;
|
|
160
|
+
// An async generator that a hook makes does not start the hooks (store.ts, applyQuietly)
|
|
161
|
+
const quiet = store.inHook === true;
|
|
153
162
|
const generator = Reflect.apply(generatorFunction, this, args);
|
|
154
163
|
const methods = {
|
|
155
164
|
next: (argument) => generator.next(argument),
|
|
@@ -161,10 +170,13 @@ export function asyncGenerator(generatorFunction) {
|
|
|
161
170
|
const previous = store.current;
|
|
162
171
|
store.current = frame;
|
|
163
172
|
try {
|
|
173
|
+
if (quiet) {
|
|
174
|
+
return applyQuietly(methods[key], undefined, [argument]);
|
|
175
|
+
}
|
|
164
176
|
const hooks = resumed ? store.hooks : undefined;
|
|
165
177
|
return hooks === undefined
|
|
166
178
|
? methods[key](argument)
|
|
167
|
-
: applyWithHooks(hooks, generatorFunction, "await", methods[key], undefined, [argument]);
|
|
179
|
+
: applyWithHooks(hooks, namedForHooks(generatorFunction, name), "await", methods[key], undefined, [argument]);
|
|
168
180
|
}
|
|
169
181
|
finally {
|
|
170
182
|
frame = store.current;
|
|
@@ -184,6 +196,8 @@ export function asyncGenerator(generatorFunction) {
|
|
|
184
196
|
};
|
|
185
197
|
return createAsyncGenerator(step, NativePromise, undefined, prepare);
|
|
186
198
|
};
|
|
199
|
+
copyNameAndLength(makeAsyncGenerator, name, generatorFunction.length);
|
|
200
|
+
return makeAsyncGenerator;
|
|
187
201
|
}
|
|
188
202
|
/**
|
|
189
203
|
* This function binds a generator object to the current context. The body of
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coroutine.js","sourceRoot":"","sources":["../../src/core/coroutine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"coroutine.js","sourceRoot":"","sources":["../../src/core/coroutine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,KAAK,EAAc,MAAM,YAAY,CAAC;AAE7E;;;;;;;;;GASG;AAEH;;;;GAIG;AACH,SAAS,aAAa,CAAC,iBAA4B,EAAE,IAAyB;IAC1E,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACrB,OAAO,iBAAiB,CAAC;IAC7B,CAAC;IACD,4GAA4G;IAC5G,IAAI,iBAAiB,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAClC,MAAM,CAAC,cAAc,CAAC,iBAAiB,EAAE,MAAM,EAAE,EAAE,KAAK,EAAG,IAAI,EAAE,YAAY,EAAG,IAAI,EAAE,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,iBAAiB,CAA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,CAAC,OAAO,GAAG,QAAQ,CAAC;QAC7B,CAAC;IACL,CAAC,CAAC;IACF,wEAAwE;IACxE,8DAA8D;IAC9D,MAAM,OAAO,GAAG;QACZ,IAAI,CAAC,KAAgB,IAAc,OAAO,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QAClE,KAAK,CAAC,KAAgB,IAAc,OAAO,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACpE,MAAM,CAAC,KAAgB,IAAc,OAAO,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;KACzE,CAAC;IACF,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CAAW,CAAM,CAAC;IAC7E,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE;QAC3B,IAAI,EAAG,EAAE,KAAK,EAAG,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAG,IAAI,EAAE,YAAY,EAAG,IAAI,EAAE;QACrE,KAAK,EAAG,EAAE,KAAK,EAAG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAG,IAAI,EAAE,YAAY,EAAG,IAAI,EAAE;QACvE,MAAM,EAAG,EAAE,KAAK,EAAG,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAG,IAAI,EAAE,YAAY,EAAG,IAAI,EAAE;KAC5E,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function gives the function of the runtime the `name` and the `length` of the source
|
|
3
|
+
* function, as the native function has them. Without a name, the name is the empty string, as
|
|
4
|
+
* for a native anonymous function. The preset gives the name, if the source has one. Where Babel
|
|
5
|
+
* gives no named wrapper, for example in a class field, the function of the runtime is the
|
|
6
|
+
* function that the program sees. The browser runtime and the Node.js runtime both use it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function copyNameAndLength(fn: Function, name: string | undefined, length: number): void;
|
|
9
|
+
//# sourceMappingURL=function-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-name.d.ts","sourceRoot":"","sources":["../../src/core/function-name.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAG,QAAQ,EAAE,IAAI,EAAG,MAAM,GAAG,SAAS,EAAE,MAAM,EAAG,MAAM,GAAI,IAAI,CAGlG"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function gives the function of the runtime the `name` and the `length` of the source
|
|
3
|
+
* function, as the native function has them. Without a name, the name is the empty string, as
|
|
4
|
+
* for a native anonymous function. The preset gives the name, if the source has one. Where Babel
|
|
5
|
+
* gives no named wrapper, for example in a class field, the function of the runtime is the
|
|
6
|
+
* function that the program sees. The browser runtime and the Node.js runtime both use it.
|
|
7
|
+
*/
|
|
8
|
+
export function copyNameAndLength(fn, name, length) {
|
|
9
|
+
Object.defineProperty(fn, "name", { value: name ?? "", configurable: true });
|
|
10
|
+
Object.defineProperty(fn, "length", { value: length, configurable: true });
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=function-name.js.map
|