source: trip-planner-front/node_modules/regenerator-transform/lib/leap.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.1 KB
Line 
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5var _assert = _interopRequireDefault(require("assert"));
6
7var _emit = require("./emit");
8
9var _util = require("util");
10
11var _util2 = require("./util");
12
13/**
14 * Copyright (c) 2014-present, Facebook, Inc.
15 *
16 * This source code is licensed under the MIT license found in the
17 * LICENSE file in the root directory of this source tree.
18 */
19function Entry() {
20 _assert["default"].ok(this instanceof Entry);
21}
22
23function FunctionEntry(returnLoc) {
24 Entry.call(this);
25 (0, _util2.getTypes)().assertLiteral(returnLoc);
26 this.returnLoc = returnLoc;
27}
28
29(0, _util.inherits)(FunctionEntry, Entry);
30exports.FunctionEntry = FunctionEntry;
31
32function LoopEntry(breakLoc, continueLoc, label) {
33 Entry.call(this);
34 var t = (0, _util2.getTypes)();
35 t.assertLiteral(breakLoc);
36 t.assertLiteral(continueLoc);
37
38 if (label) {
39 t.assertIdentifier(label);
40 } else {
41 label = null;
42 }
43
44 this.breakLoc = breakLoc;
45 this.continueLoc = continueLoc;
46 this.label = label;
47}
48
49(0, _util.inherits)(LoopEntry, Entry);
50exports.LoopEntry = LoopEntry;
51
52function SwitchEntry(breakLoc) {
53 Entry.call(this);
54 (0, _util2.getTypes)().assertLiteral(breakLoc);
55 this.breakLoc = breakLoc;
56}
57
58(0, _util.inherits)(SwitchEntry, Entry);
59exports.SwitchEntry = SwitchEntry;
60
61function TryEntry(firstLoc, catchEntry, finallyEntry) {
62 Entry.call(this);
63 var t = (0, _util2.getTypes)();
64 t.assertLiteral(firstLoc);
65
66 if (catchEntry) {
67 _assert["default"].ok(catchEntry instanceof CatchEntry);
68 } else {
69 catchEntry = null;
70 }
71
72 if (finallyEntry) {
73 _assert["default"].ok(finallyEntry instanceof FinallyEntry);
74 } else {
75 finallyEntry = null;
76 } // Have to have one or the other (or both).
77
78
79 _assert["default"].ok(catchEntry || finallyEntry);
80
81 this.firstLoc = firstLoc;
82 this.catchEntry = catchEntry;
83 this.finallyEntry = finallyEntry;
84}
85
86(0, _util.inherits)(TryEntry, Entry);
87exports.TryEntry = TryEntry;
88
89function CatchEntry(firstLoc, paramId) {
90 Entry.call(this);
91 var t = (0, _util2.getTypes)();
92 t.assertLiteral(firstLoc);
93 t.assertIdentifier(paramId);
94 this.firstLoc = firstLoc;
95 this.paramId = paramId;
96}
97
98(0, _util.inherits)(CatchEntry, Entry);
99exports.CatchEntry = CatchEntry;
100
101function FinallyEntry(firstLoc, afterLoc) {
102 Entry.call(this);
103 var t = (0, _util2.getTypes)();
104 t.assertLiteral(firstLoc);
105 t.assertLiteral(afterLoc);
106 this.firstLoc = firstLoc;
107 this.afterLoc = afterLoc;
108}
109
110(0, _util.inherits)(FinallyEntry, Entry);
111exports.FinallyEntry = FinallyEntry;
112
113function LabeledEntry(breakLoc, label) {
114 Entry.call(this);
115 var t = (0, _util2.getTypes)();
116 t.assertLiteral(breakLoc);
117 t.assertIdentifier(label);
118 this.breakLoc = breakLoc;
119 this.label = label;
120}
121
122(0, _util.inherits)(LabeledEntry, Entry);
123exports.LabeledEntry = LabeledEntry;
124
125function LeapManager(emitter) {
126 _assert["default"].ok(this instanceof LeapManager);
127
128 _assert["default"].ok(emitter instanceof _emit.Emitter);
129
130 this.emitter = emitter;
131 this.entryStack = [new FunctionEntry(emitter.finalLoc)];
132}
133
134var LMp = LeapManager.prototype;
135exports.LeapManager = LeapManager;
136
137LMp.withEntry = function (entry, callback) {
138 _assert["default"].ok(entry instanceof Entry);
139
140 this.entryStack.push(entry);
141
142 try {
143 callback.call(this.emitter);
144 } finally {
145 var popped = this.entryStack.pop();
146
147 _assert["default"].strictEqual(popped, entry);
148 }
149};
150
151LMp._findLeapLocation = function (property, label) {
152 for (var i = this.entryStack.length - 1; i >= 0; --i) {
153 var entry = this.entryStack[i];
154 var loc = entry[property];
155
156 if (loc) {
157 if (label) {
158 if (entry.label && entry.label.name === label.name) {
159 return loc;
160 }
161 } else if (entry instanceof LabeledEntry) {// Ignore LabeledEntry entries unless we are actually breaking to
162 // a label.
163 } else {
164 return loc;
165 }
166 }
167 }
168
169 return null;
170};
171
172LMp.getBreakLoc = function (label) {
173 return this._findLeapLocation("breakLoc", label);
174};
175
176LMp.getContinueLoc = function (label) {
177 return this._findLeapLocation("continueLoc", label);
178};
Note: See TracBrowser for help on using the repository browser.