@@ -71,49 +71,92 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
71
71
});
72
72
};` ;
73
73
74
+ // The __generator helper is used by down-level transformations to emulate the runtime
75
+ // semantics of an ES2015 generator function. When called, this helper returns an
76
+ // object that implements the Iterator protocol, in that it has `next`, `return`, and
77
+ // `throw` methods that step through the generator when invoked.
78
+ //
79
+ // parameters:
80
+ // thisArg The value to use as the `this` binding for the transformed generator body.
81
+ // body A function that acts as the transformed generator body.
82
+ //
83
+ // variables:
84
+ // _ Persistent state for the generator that is shared between the helper and the
85
+ // generator body. The state object has the following members:
86
+ // sent() - A method that returns or throws the current completion value.
87
+ // label - The next point at which to resume evaluation of the generator body.
88
+ // trys - A stack of protected regions (try/catch/finally blocks).
89
+ // ops - A stack of pending instructions when inside of a finally block.
90
+ // f A value indicating whether the generator is executing.
91
+ // y An iterator to delegate for a yield*.
92
+ // t A temporary variable that holds one of the following values (note that these
93
+ // cases do not overlap):
94
+ // - The completion value when resuming from a `yield` or `yield*`.
95
+ // - The error value for a catch block.
96
+ // - The current protected region (array of try/catch/finally/end labels).
97
+ // - The verb (`next`, `throw`, or `return` method) to delegate to the expression
98
+ // of a `yield*`.
99
+ // - The result of evaluating the verb delegated to the expression of a `yield*`.
100
+ //
101
+ // functions:
102
+ // verb(n) Creates a bound callback to the `step` function for opcode `n`.
103
+ // step(op) Evaluates opcodes in a generator body until execution is suspended or
104
+ // completed.
105
+ //
106
+ // The __generator helper understands a limited set of instructions:
107
+ // 0: next(value?) - Start or resume the generator with the specified value.
108
+ // 1: throw(error) - Resume the generator with an exception. If the generator is
109
+ // suspended inside of one or more protected regions, evaluates
110
+ // any intervening finally blocks between the current label and
111
+ // the nearest catch block or function boundary. If uncaught, the
112
+ // exception is thrown to the caller.
113
+ // 2: return(value?) - Resume the generator as if with a return. If the generator is
114
+ // suspended inside of one or more protected regions, evaluates any
115
+ // intervening finally blocks.
116
+ // 3: break(label) - Jump to the specified label. If the label is outside of the
117
+ // current protected region, evaluates any intervening finally
118
+ // blocks.
119
+ // 4: yield(value?) - Yield execution to the caller with an optional value. When
120
+ // resumed, the generator will continue at the next label.
121
+ // 5: yield*(value) - Delegates evaluation to the supplied iterator. When
122
+ // delegation completes, the generator will continue at the next
123
+ // label.
124
+ // 6: catch(error) - Handles an exception thrown from within the generator body. If
125
+ // the current label is inside of one or more protected regions,
126
+ // evaluates any intervening finally blocks between the current
127
+ // label and the nearest catch block or function boundary. If
128
+ // uncaught, the exception is thrown to the caller.
129
+ // 7: endfinally - Ends a finally block, resuming the last instruction prior to
130
+ // entering a finally block.
131
+ //
132
+ // For examples of how these are used, see the comments in ./transformers/generators.ts
74
133
const generatorHelper = `
75
134
var __generator = (this && this.__generator) || function (thisArg, body) {
76
- var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r;
135
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t;
136
+ return { next: verb(0), "throw": verb(1), "return": verb(2) };
137
+ function verb(n) { return function (v) { return step([n, v]); }; }
77
138
function step(op) {
78
139
if (f) throw new TypeError("Generator is already executing.");
79
- while (1) {
80
- if (_.done) switch (op[0]) {
81
- case 0: return { value: void 0, done: true };
82
- case 1: case 6: throw op[1];
83
- case 2: return { value: op[1], done: true };
84
- }
85
- try {
86
- if (f = 1, y) {
87
- v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"];
88
- if (v && !(v = v.call(y, op[1])).done) return v;
89
- if (y = void 0, v) op[0] = 0, op[1] = v.value; continue;
90
- }
91
- switch (op[0]) {
92
- case 0: case 1: sent = op; break;
93
- case 4: return _.label++, { value: op[1], done: false };
94
- case 5: _.label++, y = op[1], op = [0]; continue;
95
- case 7: op = _.stack.pop(), _.trys.pop(); continue;
96
- default:
97
- r = _.trys.length > 0 && _.trys[_.trys.length - 1];
98
- if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; }
99
- if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; }
100
- if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; }
101
- if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; }
102
- if (r[2]) { _.stack.pop(); }
103
- _.trys.pop();
104
- continue;
105
- }
106
- op = body.call(thisArg, _);
107
- }
108
- catch (e) { op = [6, e], y = void 0; }
109
- finally { f = 0, sent = v = r = void 0; }
110
- }
140
+ while (_) try {
141
+ if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
142
+ if (y = 0, t) op = [0, t.value];
143
+ switch (op[0]) {
144
+ case 0: case 1: t = op; break;
145
+ case 4: _.label++; return { value: op[1], done: false };
146
+ case 5: _.label++; y = op[1]; op = [0]; continue;
147
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
148
+ default:
149
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
150
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
151
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
152
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
153
+ if (t[2]) _.ops.pop();
154
+ _.trys.pop(); continue;
155
+ }
156
+ op = body.call(thisArg, _);
157
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
158
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
111
159
}
112
- return {
113
- next: function (v) { return step([0, v]); },
114
- "throw": function (v) { return step([1, v]); },
115
- "return": function (v) { return step([2, v]); }
116
- };
117
160
};` ;
118
161
119
162
// emit output for the __export helper function
0 commit comments