PageRenderTime 69ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/walk.js

https://gitlab.com/junxianlim/kokochat
JavaScript | 369 lines | 302 code | 32 blank | 35 comment | 96 complexity | ae72b19737fc0028e85fb0bfe4c5420b MD5 | raw file
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.acorn || (g.acorn = {})).walk = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  2. // AST walker module for Mozilla Parser API compatible trees
  3. // A simple walk is one where you simply specify callbacks to be
  4. // called on specific nodes. The last two arguments are optional. A
  5. // simple use would be
  6. //
  7. // walk.simple(myTree, {
  8. // Expression: function(node) { ... }
  9. // });
  10. //
  11. // to do something with all expressions. All Parser API node types
  12. // can be used to identify node types, as well as Expression,
  13. // Statement, and ScopeBody, which denote categories of nodes.
  14. //
  15. // The base argument can be used to pass a custom (recursive)
  16. // walker, and state can be used to give this walked an initial
  17. // state.
  18. "use strict";
  19. exports.__esModule = true;
  20. exports.simple = simple;
  21. exports.ancestor = ancestor;
  22. exports.recursive = recursive;
  23. exports.findNodeAt = findNodeAt;
  24. exports.findNodeAround = findNodeAround;
  25. exports.findNodeAfter = findNodeAfter;
  26. exports.findNodeBefore = findNodeBefore;
  27. exports.make = make;
  28. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  29. function simple(node, visitors, base, state, override) {
  30. if (!base) base = exports.base;(function c(node, st, override) {
  31. var type = override || node.type,
  32. found = visitors[type];
  33. base[type](node, st, c);
  34. if (found) found(node, st);
  35. })(node, state, override);
  36. }
  37. // An ancestor walk builds up an array of ancestor nodes (including
  38. // the current node) and passes them to the callback as the state parameter.
  39. function ancestor(node, visitors, base, state) {
  40. if (!base) base = exports.base;
  41. if (!state) state = [];(function c(node, st, override) {
  42. var type = override || node.type,
  43. found = visitors[type];
  44. if (node != st[st.length - 1]) {
  45. st = st.slice();
  46. st.push(node);
  47. }
  48. base[type](node, st, c);
  49. if (found) found(node, st);
  50. })(node, state);
  51. }
  52. // A recursive walk is one where your functions override the default
  53. // walkers. They can modify and replace the state parameter that's
  54. // threaded through the walk, and can opt how and whether to walk
  55. // their child nodes (by calling their third argument on these
  56. // nodes).
  57. function recursive(node, state, funcs, base, override) {
  58. var visitor = funcs ? exports.make(funcs, base) : base;(function c(node, st, override) {
  59. visitor[override || node.type](node, st, c);
  60. })(node, state, override);
  61. }
  62. function makeTest(test) {
  63. if (typeof test == "string") return function (type) {
  64. return type == test;
  65. };else if (!test) return function () {
  66. return true;
  67. };else return test;
  68. }
  69. var Found = function Found(node, state) {
  70. _classCallCheck(this, Found);
  71. this.node = node;this.state = state;
  72. };
  73. // Find a node with a given start, end, and type (all are optional,
  74. // null can be used as wildcard). Returns a {node, state} object, or
  75. // undefined when it doesn't find a matching node.
  76. function findNodeAt(node, start, end, test, base, state) {
  77. test = makeTest(test);
  78. if (!base) base = exports.base;
  79. try {
  80. ;(function c(node, st, override) {
  81. var type = override || node.type;
  82. if ((start == null || node.start <= start) && (end == null || node.end >= end)) base[type](node, st, c);
  83. if (test(type, node) && (start == null || node.start == start) && (end == null || node.end == end)) throw new Found(node, st);
  84. })(node, state);
  85. } catch (e) {
  86. if (e instanceof Found) return e;
  87. throw e;
  88. }
  89. }
  90. // Find the innermost node of a given type that contains the given
  91. // position. Interface similar to findNodeAt.
  92. function findNodeAround(node, pos, test, base, state) {
  93. test = makeTest(test);
  94. if (!base) base = exports.base;
  95. try {
  96. ;(function c(node, st, override) {
  97. var type = override || node.type;
  98. if (node.start > pos || node.end < pos) return;
  99. base[type](node, st, c);
  100. if (test(type, node)) throw new Found(node, st);
  101. })(node, state);
  102. } catch (e) {
  103. if (e instanceof Found) return e;
  104. throw e;
  105. }
  106. }
  107. // Find the outermost matching node after a given position.
  108. function findNodeAfter(node, pos, test, base, state) {
  109. test = makeTest(test);
  110. if (!base) base = exports.base;
  111. try {
  112. ;(function c(node, st, override) {
  113. if (node.end < pos) return;
  114. var type = override || node.type;
  115. if (node.start >= pos && test(type, node)) throw new Found(node, st);
  116. base[type](node, st, c);
  117. })(node, state);
  118. } catch (e) {
  119. if (e instanceof Found) return e;
  120. throw e;
  121. }
  122. }
  123. // Find the outermost matching node before a given position.
  124. function findNodeBefore(node, pos, test, base, state) {
  125. test = makeTest(test);
  126. if (!base) base = exports.base;
  127. var max = undefined;(function c(node, st, override) {
  128. if (node.start > pos) return;
  129. var type = override || node.type;
  130. if (node.end <= pos && (!max || max.node.end < node.end) && test(type, node)) max = new Found(node, st);
  131. base[type](node, st, c);
  132. })(node, state);
  133. return max;
  134. }
  135. // Used to create a custom walker. Will fill in all missing node
  136. // type properties with the defaults.
  137. function make(funcs, base) {
  138. if (!base) base = exports.base;
  139. var visitor = {};
  140. for (var type in base) visitor[type] = base[type];
  141. for (var type in funcs) visitor[type] = funcs[type];
  142. return visitor;
  143. }
  144. function skipThrough(node, st, c) {
  145. c(node, st);
  146. }
  147. function ignore(_node, _st, _c) {}
  148. // Node walkers.
  149. var base = {};
  150. exports.base = base;
  151. base.Program = base.BlockStatement = function (node, st, c) {
  152. for (var i = 0; i < node.body.length; ++i) {
  153. c(node.body[i], st, "Statement");
  154. }
  155. };
  156. base.Statement = skipThrough;
  157. base.EmptyStatement = ignore;
  158. base.ExpressionStatement = base.ParenthesizedExpression = function (node, st, c) {
  159. return c(node.expression, st, "Expression");
  160. };
  161. base.IfStatement = function (node, st, c) {
  162. c(node.test, st, "Expression");
  163. c(node.consequent, st, "Statement");
  164. if (node.alternate) c(node.alternate, st, "Statement");
  165. };
  166. base.LabeledStatement = function (node, st, c) {
  167. return c(node.body, st, "Statement");
  168. };
  169. base.BreakStatement = base.ContinueStatement = ignore;
  170. base.WithStatement = function (node, st, c) {
  171. c(node.object, st, "Expression");
  172. c(node.body, st, "Statement");
  173. };
  174. base.SwitchStatement = function (node, st, c) {
  175. c(node.discriminant, st, "Expression");
  176. for (var i = 0; i < node.cases.length; ++i) {
  177. var cs = node.cases[i];
  178. if (cs.test) c(cs.test, st, "Expression");
  179. for (var j = 0; j < cs.consequent.length; ++j) {
  180. c(cs.consequent[j], st, "Statement");
  181. }
  182. }
  183. };
  184. base.ReturnStatement = base.YieldExpression = function (node, st, c) {
  185. if (node.argument) c(node.argument, st, "Expression");
  186. };
  187. base.ThrowStatement = base.SpreadElement = function (node, st, c) {
  188. return c(node.argument, st, "Expression");
  189. };
  190. base.TryStatement = function (node, st, c) {
  191. c(node.block, st, "Statement");
  192. if (node.handler) {
  193. c(node.handler.param, st, "Pattern");
  194. c(node.handler.body, st, "ScopeBody");
  195. }
  196. if (node.finalizer) c(node.finalizer, st, "Statement");
  197. };
  198. base.WhileStatement = base.DoWhileStatement = function (node, st, c) {
  199. c(node.test, st, "Expression");
  200. c(node.body, st, "Statement");
  201. };
  202. base.ForStatement = function (node, st, c) {
  203. if (node.init) c(node.init, st, "ForInit");
  204. if (node.test) c(node.test, st, "Expression");
  205. if (node.update) c(node.update, st, "Expression");
  206. c(node.body, st, "Statement");
  207. };
  208. base.ForInStatement = base.ForOfStatement = function (node, st, c) {
  209. c(node.left, st, "ForInit");
  210. c(node.right, st, "Expression");
  211. c(node.body, st, "Statement");
  212. };
  213. base.ForInit = function (node, st, c) {
  214. if (node.type == "VariableDeclaration") c(node, st);else c(node, st, "Expression");
  215. };
  216. base.DebuggerStatement = ignore;
  217. base.FunctionDeclaration = function (node, st, c) {
  218. return c(node, st, "Function");
  219. };
  220. base.VariableDeclaration = function (node, st, c) {
  221. for (var i = 0; i < node.declarations.length; ++i) {
  222. var decl = node.declarations[i];
  223. c(decl.id, st, "Pattern");
  224. if (decl.init) c(decl.init, st, "Expression");
  225. }
  226. };
  227. base.Function = function (node, st, c) {
  228. for (var i = 0; i < node.params.length; i++) {
  229. c(node.params[i], st, "Pattern");
  230. }c(node.body, st, node.expression ? "ScopeExpression" : "ScopeBody");
  231. };
  232. // FIXME drop these node types in next major version
  233. // (They are awkward, and in ES6 every block can be a scope.)
  234. base.ScopeBody = function (node, st, c) {
  235. return c(node, st, "Statement");
  236. };
  237. base.ScopeExpression = function (node, st, c) {
  238. return c(node, st, "Expression");
  239. };
  240. base.Pattern = function (node, st, c) {
  241. if (node.type == "Identifier") c(node, st, "VariablePattern");else if (node.type == "MemberExpression") c(node, st, "MemberPattern");else c(node, st);
  242. };
  243. base.VariablePattern = ignore;
  244. base.MemberPattern = skipThrough;
  245. base.RestElement = function (node, st, c) {
  246. return c(node.argument, st, "Pattern");
  247. };
  248. base.ArrayPattern = function (node, st, c) {
  249. for (var i = 0; i < node.elements.length; ++i) {
  250. var elt = node.elements[i];
  251. if (elt) c(elt, st, "Pattern");
  252. }
  253. };
  254. base.ObjectPattern = function (node, st, c) {
  255. for (var i = 0; i < node.properties.length; ++i) {
  256. c(node.properties[i].value, st, "Pattern");
  257. }
  258. };
  259. base.Expression = skipThrough;
  260. base.ThisExpression = base.Super = base.MetaProperty = ignore;
  261. base.ArrayExpression = function (node, st, c) {
  262. for (var i = 0; i < node.elements.length; ++i) {
  263. var elt = node.elements[i];
  264. if (elt) c(elt, st, "Expression");
  265. }
  266. };
  267. base.ObjectExpression = function (node, st, c) {
  268. for (var i = 0; i < node.properties.length; ++i) {
  269. c(node.properties[i], st);
  270. }
  271. };
  272. base.FunctionExpression = base.ArrowFunctionExpression = base.FunctionDeclaration;
  273. base.SequenceExpression = base.TemplateLiteral = function (node, st, c) {
  274. for (var i = 0; i < node.expressions.length; ++i) {
  275. c(node.expressions[i], st, "Expression");
  276. }
  277. };
  278. base.UnaryExpression = base.UpdateExpression = function (node, st, c) {
  279. c(node.argument, st, "Expression");
  280. };
  281. base.BinaryExpression = base.LogicalExpression = function (node, st, c) {
  282. c(node.left, st, "Expression");
  283. c(node.right, st, "Expression");
  284. };
  285. base.AssignmentExpression = base.AssignmentPattern = function (node, st, c) {
  286. c(node.left, st, "Pattern");
  287. c(node.right, st, "Expression");
  288. };
  289. base.ConditionalExpression = function (node, st, c) {
  290. c(node.test, st, "Expression");
  291. c(node.consequent, st, "Expression");
  292. c(node.alternate, st, "Expression");
  293. };
  294. base.NewExpression = base.CallExpression = function (node, st, c) {
  295. c(node.callee, st, "Expression");
  296. if (node.arguments) for (var i = 0; i < node.arguments.length; ++i) {
  297. c(node.arguments[i], st, "Expression");
  298. }
  299. };
  300. base.MemberExpression = function (node, st, c) {
  301. c(node.object, st, "Expression");
  302. if (node.computed) c(node.property, st, "Expression");
  303. };
  304. base.ExportNamedDeclaration = base.ExportDefaultDeclaration = function (node, st, c) {
  305. if (node.declaration) c(node.declaration, st);
  306. };
  307. base.ImportDeclaration = function (node, st, c) {
  308. for (var i = 0; i < node.specifiers.length; i++) {
  309. c(node.specifiers[i], st);
  310. }
  311. };
  312. base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifier = base.Identifier = base.Literal = ignore;
  313. base.TaggedTemplateExpression = function (node, st, c) {
  314. c(node.tag, st, "Expression");
  315. c(node.quasi, st);
  316. };
  317. base.ClassDeclaration = base.ClassExpression = function (node, st, c) {
  318. return c(node, st, "Class");
  319. };
  320. base.Class = function (node, st, c) {
  321. if (node.id) c(node.id, st, "Pattern");
  322. if (node.superClass) c(node.superClass, st, "Expression");
  323. for (var i = 0; i < node.body.body.length; i++) {
  324. c(node.body.body[i], st);
  325. }
  326. };
  327. base.MethodDefinition = base.Property = function (node, st, c) {
  328. if (node.computed) c(node.key, st, "Expression");
  329. c(node.value, st, "Expression");
  330. };
  331. base.ComprehensionExpression = function (node, st, c) {
  332. for (var i = 0; i < node.blocks.length; i++) {
  333. c(node.blocks[i].right, st, "Expression");
  334. }c(node.body, st, "Expression");
  335. };
  336. },{}]},{},[1])(1)
  337. });