source: imaps-frontend/node_modules/regenerator-transform/lib/leap.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

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