syntaxWalker.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright 2013 Palantir Technologies, Inc.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. var ts = require("typescript");
  20. var SyntaxWalker = /** @class */ (function () {
  21. function SyntaxWalker() {
  22. }
  23. SyntaxWalker.prototype.walk = function (node) {
  24. this.visitNode(node);
  25. };
  26. SyntaxWalker.prototype.visitAnyKeyword = function (node) {
  27. this.walkChildren(node);
  28. };
  29. SyntaxWalker.prototype.visitArrayLiteralExpression = function (node) {
  30. this.walkChildren(node);
  31. };
  32. SyntaxWalker.prototype.visitArrayType = function (node) {
  33. this.walkChildren(node);
  34. };
  35. SyntaxWalker.prototype.visitArrowFunction = function (node) {
  36. this.walkChildren(node);
  37. };
  38. SyntaxWalker.prototype.visitBinaryExpression = function (node) {
  39. this.walkChildren(node);
  40. };
  41. SyntaxWalker.prototype.visitBindingElement = function (node) {
  42. this.walkChildren(node);
  43. };
  44. SyntaxWalker.prototype.visitBindingPattern = function (node) {
  45. this.walkChildren(node);
  46. };
  47. SyntaxWalker.prototype.visitBlock = function (node) {
  48. this.walkChildren(node);
  49. };
  50. SyntaxWalker.prototype.visitBreakStatement = function (node) {
  51. this.walkChildren(node);
  52. };
  53. SyntaxWalker.prototype.visitCallExpression = function (node) {
  54. this.walkChildren(node);
  55. };
  56. SyntaxWalker.prototype.visitCallSignature = function (node) {
  57. this.walkChildren(node);
  58. };
  59. SyntaxWalker.prototype.visitCaseClause = function (node) {
  60. this.walkChildren(node);
  61. };
  62. SyntaxWalker.prototype.visitClassDeclaration = function (node) {
  63. this.walkChildren(node);
  64. };
  65. SyntaxWalker.prototype.visitClassExpression = function (node) {
  66. this.walkChildren(node);
  67. };
  68. SyntaxWalker.prototype.visitCatchClause = function (node) {
  69. this.walkChildren(node);
  70. };
  71. SyntaxWalker.prototype.visitConditionalExpression = function (node) {
  72. this.walkChildren(node);
  73. };
  74. SyntaxWalker.prototype.visitConstructSignature = function (node) {
  75. this.walkChildren(node);
  76. };
  77. SyntaxWalker.prototype.visitConstructorDeclaration = function (node) {
  78. this.walkChildren(node);
  79. };
  80. SyntaxWalker.prototype.visitConstructorType = function (node) {
  81. this.walkChildren(node);
  82. };
  83. SyntaxWalker.prototype.visitContinueStatement = function (node) {
  84. this.walkChildren(node);
  85. };
  86. SyntaxWalker.prototype.visitDebuggerStatement = function (node) {
  87. this.walkChildren(node);
  88. };
  89. SyntaxWalker.prototype.visitDefaultClause = function (node) {
  90. this.walkChildren(node);
  91. };
  92. SyntaxWalker.prototype.visitDoStatement = function (node) {
  93. this.walkChildren(node);
  94. };
  95. SyntaxWalker.prototype.visitElementAccessExpression = function (node) {
  96. this.walkChildren(node);
  97. };
  98. SyntaxWalker.prototype.visitEndOfFileToken = function (node) {
  99. this.walkChildren(node);
  100. };
  101. SyntaxWalker.prototype.visitEnumDeclaration = function (node) {
  102. this.walkChildren(node);
  103. };
  104. SyntaxWalker.prototype.visitEnumMember = function (node) {
  105. this.walkChildren(node);
  106. };
  107. SyntaxWalker.prototype.visitExportAssignment = function (node) {
  108. this.walkChildren(node);
  109. };
  110. SyntaxWalker.prototype.visitExpressionStatement = function (node) {
  111. this.walkChildren(node);
  112. };
  113. SyntaxWalker.prototype.visitForStatement = function (node) {
  114. this.walkChildren(node);
  115. };
  116. SyntaxWalker.prototype.visitForInStatement = function (node) {
  117. this.walkChildren(node);
  118. };
  119. SyntaxWalker.prototype.visitForOfStatement = function (node) {
  120. this.walkChildren(node);
  121. };
  122. SyntaxWalker.prototype.visitFunctionDeclaration = function (node) {
  123. this.walkChildren(node);
  124. };
  125. SyntaxWalker.prototype.visitFunctionExpression = function (node) {
  126. this.walkChildren(node);
  127. };
  128. SyntaxWalker.prototype.visitFunctionType = function (node) {
  129. this.walkChildren(node);
  130. };
  131. SyntaxWalker.prototype.visitGetAccessor = function (node) {
  132. this.walkChildren(node);
  133. };
  134. SyntaxWalker.prototype.visitIdentifier = function (node) {
  135. this.walkChildren(node);
  136. };
  137. SyntaxWalker.prototype.visitIfStatement = function (node) {
  138. this.walkChildren(node);
  139. };
  140. SyntaxWalker.prototype.visitImportDeclaration = function (node) {
  141. this.walkChildren(node);
  142. };
  143. SyntaxWalker.prototype.visitImportEqualsDeclaration = function (node) {
  144. this.walkChildren(node);
  145. };
  146. SyntaxWalker.prototype.visitIndexSignatureDeclaration = function (node) {
  147. this.walkChildren(node);
  148. };
  149. SyntaxWalker.prototype.visitInterfaceDeclaration = function (node) {
  150. this.walkChildren(node);
  151. };
  152. SyntaxWalker.prototype.visitJsxAttribute = function (node) {
  153. this.walkChildren(node);
  154. };
  155. SyntaxWalker.prototype.visitJsxElement = function (node) {
  156. this.walkChildren(node);
  157. };
  158. SyntaxWalker.prototype.visitJsxExpression = function (node) {
  159. this.walkChildren(node);
  160. };
  161. SyntaxWalker.prototype.visitJsxSelfClosingElement = function (node) {
  162. this.walkChildren(node);
  163. };
  164. SyntaxWalker.prototype.visitJsxSpreadAttribute = function (node) {
  165. this.walkChildren(node);
  166. };
  167. SyntaxWalker.prototype.visitLabeledStatement = function (node) {
  168. this.walkChildren(node);
  169. };
  170. SyntaxWalker.prototype.visitMethodDeclaration = function (node) {
  171. this.walkChildren(node);
  172. };
  173. SyntaxWalker.prototype.visitMethodSignature = function (node) {
  174. this.walkChildren(node);
  175. };
  176. SyntaxWalker.prototype.visitModuleDeclaration = function (node) {
  177. this.walkChildren(node);
  178. };
  179. SyntaxWalker.prototype.visitNamedImports = function (node) {
  180. this.walkChildren(node);
  181. };
  182. SyntaxWalker.prototype.visitNamespaceImport = function (node) {
  183. this.walkChildren(node);
  184. };
  185. SyntaxWalker.prototype.visitNewExpression = function (node) {
  186. this.walkChildren(node);
  187. };
  188. SyntaxWalker.prototype.visitNonNullExpression = function (node) {
  189. this.walkChildren(node);
  190. };
  191. SyntaxWalker.prototype.visitNumericLiteral = function (node) {
  192. this.walkChildren(node);
  193. };
  194. SyntaxWalker.prototype.visitObjectLiteralExpression = function (node) {
  195. this.walkChildren(node);
  196. };
  197. SyntaxWalker.prototype.visitParameterDeclaration = function (node) {
  198. this.walkChildren(node);
  199. };
  200. SyntaxWalker.prototype.visitPostfixUnaryExpression = function (node) {
  201. this.walkChildren(node);
  202. };
  203. SyntaxWalker.prototype.visitPrefixUnaryExpression = function (node) {
  204. this.walkChildren(node);
  205. };
  206. SyntaxWalker.prototype.visitPropertyAccessExpression = function (node) {
  207. this.walkChildren(node);
  208. };
  209. SyntaxWalker.prototype.visitPropertyAssignment = function (node) {
  210. this.walkChildren(node);
  211. };
  212. SyntaxWalker.prototype.visitPropertyDeclaration = function (node) {
  213. this.walkChildren(node);
  214. };
  215. SyntaxWalker.prototype.visitPropertySignature = function (node) {
  216. this.walkChildren(node);
  217. };
  218. SyntaxWalker.prototype.visitRegularExpressionLiteral = function (node) {
  219. this.walkChildren(node);
  220. };
  221. SyntaxWalker.prototype.visitReturnStatement = function (node) {
  222. this.walkChildren(node);
  223. };
  224. SyntaxWalker.prototype.visitSetAccessor = function (node) {
  225. this.walkChildren(node);
  226. };
  227. SyntaxWalker.prototype.visitSourceFile = function (node) {
  228. this.walkChildren(node);
  229. };
  230. SyntaxWalker.prototype.visitStringLiteral = function (node) {
  231. this.walkChildren(node);
  232. };
  233. SyntaxWalker.prototype.visitSwitchStatement = function (node) {
  234. this.walkChildren(node);
  235. };
  236. SyntaxWalker.prototype.visitTemplateExpression = function (node) {
  237. this.walkChildren(node);
  238. };
  239. SyntaxWalker.prototype.visitThrowStatement = function (node) {
  240. this.walkChildren(node);
  241. };
  242. SyntaxWalker.prototype.visitTryStatement = function (node) {
  243. this.walkChildren(node);
  244. };
  245. SyntaxWalker.prototype.visitTupleType = function (node) {
  246. this.walkChildren(node);
  247. };
  248. SyntaxWalker.prototype.visitTypeAliasDeclaration = function (node) {
  249. this.walkChildren(node);
  250. };
  251. SyntaxWalker.prototype.visitTypeAssertionExpression = function (node) {
  252. this.walkChildren(node);
  253. };
  254. SyntaxWalker.prototype.visitTypeLiteral = function (node) {
  255. this.walkChildren(node);
  256. };
  257. SyntaxWalker.prototype.visitTypeReference = function (node) {
  258. this.walkChildren(node);
  259. };
  260. SyntaxWalker.prototype.visitVariableDeclaration = function (node) {
  261. this.walkChildren(node);
  262. };
  263. SyntaxWalker.prototype.visitVariableDeclarationList = function (node) {
  264. this.walkChildren(node);
  265. };
  266. SyntaxWalker.prototype.visitVariableStatement = function (node) {
  267. this.walkChildren(node);
  268. };
  269. SyntaxWalker.prototype.visitWhileStatement = function (node) {
  270. this.walkChildren(node);
  271. };
  272. SyntaxWalker.prototype.visitWithStatement = function (node) {
  273. this.walkChildren(node);
  274. };
  275. SyntaxWalker.prototype.visitNode = function (node) {
  276. switch (node.kind) {
  277. case ts.SyntaxKind.AnyKeyword:
  278. this.visitAnyKeyword(node);
  279. break;
  280. case ts.SyntaxKind.ArrayBindingPattern:
  281. this.visitBindingPattern(node);
  282. break;
  283. case ts.SyntaxKind.ArrayLiteralExpression:
  284. this.visitArrayLiteralExpression(node);
  285. break;
  286. case ts.SyntaxKind.ArrayType:
  287. this.visitArrayType(node);
  288. break;
  289. case ts.SyntaxKind.ArrowFunction:
  290. this.visitArrowFunction(node);
  291. break;
  292. case ts.SyntaxKind.BinaryExpression:
  293. this.visitBinaryExpression(node);
  294. break;
  295. case ts.SyntaxKind.BindingElement:
  296. this.visitBindingElement(node);
  297. break;
  298. case ts.SyntaxKind.Block:
  299. this.visitBlock(node);
  300. break;
  301. case ts.SyntaxKind.BreakStatement:
  302. this.visitBreakStatement(node);
  303. break;
  304. case ts.SyntaxKind.CallExpression:
  305. this.visitCallExpression(node);
  306. break;
  307. case ts.SyntaxKind.CallSignature:
  308. this.visitCallSignature(node);
  309. break;
  310. case ts.SyntaxKind.CaseClause:
  311. this.visitCaseClause(node);
  312. break;
  313. case ts.SyntaxKind.ClassDeclaration:
  314. this.visitClassDeclaration(node);
  315. break;
  316. case ts.SyntaxKind.ClassExpression:
  317. this.visitClassExpression(node);
  318. break;
  319. case ts.SyntaxKind.CatchClause:
  320. this.visitCatchClause(node);
  321. break;
  322. case ts.SyntaxKind.ConditionalExpression:
  323. this.visitConditionalExpression(node);
  324. break;
  325. case ts.SyntaxKind.ConstructSignature:
  326. this.visitConstructSignature(node);
  327. break;
  328. case ts.SyntaxKind.Constructor:
  329. this.visitConstructorDeclaration(node);
  330. break;
  331. case ts.SyntaxKind.ConstructorType:
  332. this.visitConstructorType(node);
  333. break;
  334. case ts.SyntaxKind.ContinueStatement:
  335. this.visitContinueStatement(node);
  336. break;
  337. case ts.SyntaxKind.DebuggerStatement:
  338. this.visitDebuggerStatement(node);
  339. break;
  340. case ts.SyntaxKind.DefaultClause:
  341. this.visitDefaultClause(node);
  342. break;
  343. case ts.SyntaxKind.DoStatement:
  344. this.visitDoStatement(node);
  345. break;
  346. case ts.SyntaxKind.ElementAccessExpression:
  347. this.visitElementAccessExpression(node);
  348. break;
  349. case ts.SyntaxKind.EndOfFileToken:
  350. this.visitEndOfFileToken(node);
  351. break;
  352. case ts.SyntaxKind.EnumDeclaration:
  353. this.visitEnumDeclaration(node);
  354. break;
  355. case ts.SyntaxKind.EnumMember:
  356. this.visitEnumMember(node);
  357. break;
  358. case ts.SyntaxKind.ExportAssignment:
  359. this.visitExportAssignment(node);
  360. break;
  361. case ts.SyntaxKind.ExpressionStatement:
  362. this.visitExpressionStatement(node);
  363. break;
  364. case ts.SyntaxKind.ForStatement:
  365. this.visitForStatement(node);
  366. break;
  367. case ts.SyntaxKind.ForInStatement:
  368. this.visitForInStatement(node);
  369. break;
  370. case ts.SyntaxKind.ForOfStatement:
  371. this.visitForOfStatement(node);
  372. break;
  373. case ts.SyntaxKind.FunctionDeclaration:
  374. this.visitFunctionDeclaration(node);
  375. break;
  376. case ts.SyntaxKind.FunctionExpression:
  377. this.visitFunctionExpression(node);
  378. break;
  379. case ts.SyntaxKind.FunctionType:
  380. this.visitFunctionType(node);
  381. break;
  382. case ts.SyntaxKind.GetAccessor:
  383. this.visitGetAccessor(node);
  384. break;
  385. case ts.SyntaxKind.Identifier:
  386. this.visitIdentifier(node);
  387. break;
  388. case ts.SyntaxKind.IfStatement:
  389. this.visitIfStatement(node);
  390. break;
  391. case ts.SyntaxKind.ImportDeclaration:
  392. this.visitImportDeclaration(node);
  393. break;
  394. case ts.SyntaxKind.ImportEqualsDeclaration:
  395. this.visitImportEqualsDeclaration(node);
  396. break;
  397. case ts.SyntaxKind.IndexSignature:
  398. this.visitIndexSignatureDeclaration(node);
  399. break;
  400. case ts.SyntaxKind.InterfaceDeclaration:
  401. this.visitInterfaceDeclaration(node);
  402. break;
  403. case ts.SyntaxKind.JsxAttribute:
  404. this.visitJsxAttribute(node);
  405. break;
  406. case ts.SyntaxKind.JsxElement:
  407. this.visitJsxElement(node);
  408. break;
  409. case ts.SyntaxKind.JsxExpression:
  410. this.visitJsxExpression(node);
  411. break;
  412. case ts.SyntaxKind.JsxSelfClosingElement:
  413. this.visitJsxSelfClosingElement(node);
  414. break;
  415. case ts.SyntaxKind.JsxSpreadAttribute:
  416. this.visitJsxSpreadAttribute(node);
  417. break;
  418. case ts.SyntaxKind.LabeledStatement:
  419. this.visitLabeledStatement(node);
  420. break;
  421. case ts.SyntaxKind.MethodDeclaration:
  422. this.visitMethodDeclaration(node);
  423. break;
  424. case ts.SyntaxKind.MethodSignature:
  425. this.visitMethodSignature(node);
  426. break;
  427. case ts.SyntaxKind.ModuleDeclaration:
  428. this.visitModuleDeclaration(node);
  429. break;
  430. case ts.SyntaxKind.NamedImports:
  431. this.visitNamedImports(node);
  432. break;
  433. case ts.SyntaxKind.NamespaceImport:
  434. this.visitNamespaceImport(node);
  435. break;
  436. case ts.SyntaxKind.NewExpression:
  437. this.visitNewExpression(node);
  438. break;
  439. case ts.SyntaxKind.NonNullExpression:
  440. this.visitNonNullExpression(node);
  441. break;
  442. case ts.SyntaxKind.NumericLiteral:
  443. this.visitNumericLiteral(node);
  444. break;
  445. case ts.SyntaxKind.ObjectBindingPattern:
  446. this.visitBindingPattern(node);
  447. break;
  448. case ts.SyntaxKind.ObjectLiteralExpression:
  449. this.visitObjectLiteralExpression(node);
  450. break;
  451. case ts.SyntaxKind.Parameter:
  452. this.visitParameterDeclaration(node);
  453. break;
  454. case ts.SyntaxKind.PostfixUnaryExpression:
  455. this.visitPostfixUnaryExpression(node);
  456. break;
  457. case ts.SyntaxKind.PrefixUnaryExpression:
  458. this.visitPrefixUnaryExpression(node);
  459. break;
  460. case ts.SyntaxKind.PropertyAccessExpression:
  461. this.visitPropertyAccessExpression(node);
  462. break;
  463. case ts.SyntaxKind.PropertyAssignment:
  464. this.visitPropertyAssignment(node);
  465. break;
  466. case ts.SyntaxKind.PropertyDeclaration:
  467. this.visitPropertyDeclaration(node);
  468. break;
  469. case ts.SyntaxKind.PropertySignature:
  470. this.visitPropertySignature(node);
  471. break;
  472. case ts.SyntaxKind.RegularExpressionLiteral:
  473. this.visitRegularExpressionLiteral(node);
  474. break;
  475. case ts.SyntaxKind.ReturnStatement:
  476. this.visitReturnStatement(node);
  477. break;
  478. case ts.SyntaxKind.SetAccessor:
  479. this.visitSetAccessor(node);
  480. break;
  481. case ts.SyntaxKind.SourceFile:
  482. this.visitSourceFile(node);
  483. break;
  484. case ts.SyntaxKind.StringLiteral:
  485. this.visitStringLiteral(node);
  486. break;
  487. case ts.SyntaxKind.SwitchStatement:
  488. this.visitSwitchStatement(node);
  489. break;
  490. case ts.SyntaxKind.TemplateExpression:
  491. this.visitTemplateExpression(node);
  492. break;
  493. case ts.SyntaxKind.ThrowStatement:
  494. this.visitThrowStatement(node);
  495. break;
  496. case ts.SyntaxKind.TryStatement:
  497. this.visitTryStatement(node);
  498. break;
  499. case ts.SyntaxKind.TupleType:
  500. this.visitTupleType(node);
  501. break;
  502. case ts.SyntaxKind.TypeAliasDeclaration:
  503. this.visitTypeAliasDeclaration(node);
  504. break;
  505. case ts.SyntaxKind.TypeAssertionExpression:
  506. this.visitTypeAssertionExpression(node);
  507. break;
  508. case ts.SyntaxKind.TypeLiteral:
  509. this.visitTypeLiteral(node);
  510. break;
  511. case ts.SyntaxKind.TypeReference:
  512. this.visitTypeReference(node);
  513. break;
  514. case ts.SyntaxKind.VariableDeclaration:
  515. this.visitVariableDeclaration(node);
  516. break;
  517. case ts.SyntaxKind.VariableDeclarationList:
  518. this.visitVariableDeclarationList(node);
  519. break;
  520. case ts.SyntaxKind.VariableStatement:
  521. this.visitVariableStatement(node);
  522. break;
  523. case ts.SyntaxKind.WhileStatement:
  524. this.visitWhileStatement(node);
  525. break;
  526. case ts.SyntaxKind.WithStatement:
  527. this.visitWithStatement(node);
  528. break;
  529. default:
  530. this.walkChildren(node);
  531. }
  532. };
  533. SyntaxWalker.prototype.walkChildren = function (node) {
  534. var _this = this;
  535. ts.forEachChild(node, function (child) { return _this.visitNode(child); });
  536. };
  537. return SyntaxWalker;
  538. }());
  539. exports.SyntaxWalker = SyntaxWalker;