@@ -71,43 +71,92 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7171 });
7272};` ;
7373
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
74133 const generatorHelper = `
75134var __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, f;
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]); }; }
77138 function step(op) {
78139 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- switch (f = 1, op[0]) {
87- case 0: case 1: sent = op; break;
88- case 4: return _.label++, { value: op[1], done: false };
89- case 7: op = _.stack.pop(), _.trys.pop(); continue;
90- default:
91- var r = _.trys.length > 0 && _.trys[_.trys.length - 1];
92- if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; }
93- if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; }
94- if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; }
95- if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; }
96- if (r[2]) { _.stack.pop(); }
97- _.trys.pop();
98- continue;
99- }
100- op = body.call(thisArg, _);
101- }
102- catch (e) { op = [6, e]; }
103- finally { f = 0, sent = void 0; }
104- }
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 };
105159 }
106- return {
107- next: function (v) { return step([0, v]); },
108- "throw": function (v) { return step([1, v]); },
109- "return": function (v) { return step([2, v]); }
110- };
111160};` ;
112161
113162 // emit output for the __export helper function
0 commit comments