pattern-visitor.js 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6. var _estraverse = require('estraverse');
  7. var _esrecurse = require('esrecurse');
  8. var _esrecurse2 = _interopRequireDefault(_esrecurse);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  12. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /*
  13. Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
  14. Redistribution and use in source and binary forms, with or without
  15. modification, are permitted provided that the following conditions are met:
  16. * Redistributions of source code must retain the above copyright
  17. notice, this list of conditions and the following disclaimer.
  18. * Redistributions in binary form must reproduce the above copyright
  19. notice, this list of conditions and the following disclaimer in the
  20. documentation and/or other materials provided with the distribution.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  25. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  28. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. function getLast(xs) {
  33. return xs[xs.length - 1] || null;
  34. }
  35. var PatternVisitor = function (_esrecurse$Visitor) {
  36. _inherits(PatternVisitor, _esrecurse$Visitor);
  37. _createClass(PatternVisitor, null, [{
  38. key: 'isPattern',
  39. value: function isPattern(node) {
  40. var nodeType = node.type;
  41. return nodeType === _estraverse.Syntax.Identifier || nodeType === _estraverse.Syntax.ObjectPattern || nodeType === _estraverse.Syntax.ArrayPattern || nodeType === _estraverse.Syntax.SpreadElement || nodeType === _estraverse.Syntax.RestElement || nodeType === _estraverse.Syntax.AssignmentPattern;
  42. }
  43. }]);
  44. function PatternVisitor(options, rootPattern, callback) {
  45. _classCallCheck(this, PatternVisitor);
  46. var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(PatternVisitor).call(this, null, options));
  47. _this.rootPattern = rootPattern;
  48. _this.callback = callback;
  49. _this.assignments = [];
  50. _this.rightHandNodes = [];
  51. _this.restElements = [];
  52. return _this;
  53. }
  54. _createClass(PatternVisitor, [{
  55. key: 'Identifier',
  56. value: function Identifier(pattern) {
  57. var lastRestElement = getLast(this.restElements);
  58. this.callback(pattern, {
  59. topLevel: pattern === this.rootPattern,
  60. rest: lastRestElement != null && lastRestElement.argument === pattern,
  61. assignments: this.assignments
  62. });
  63. }
  64. }, {
  65. key: 'Property',
  66. value: function Property(property) {
  67. // Computed property's key is a right hand node.
  68. if (property.computed) {
  69. this.rightHandNodes.push(property.key);
  70. }
  71. // If it's shorthand, its key is same as its value.
  72. // If it's shorthand and has its default value, its key is same as its value.left (the value is AssignmentPattern).
  73. // If it's not shorthand, the name of new variable is its value's.
  74. this.visit(property.value);
  75. }
  76. }, {
  77. key: 'ArrayPattern',
  78. value: function ArrayPattern(pattern) {
  79. var i, iz, element;
  80. for (i = 0, iz = pattern.elements.length; i < iz; ++i) {
  81. element = pattern.elements[i];
  82. this.visit(element);
  83. }
  84. }
  85. }, {
  86. key: 'AssignmentPattern',
  87. value: function AssignmentPattern(pattern) {
  88. this.assignments.push(pattern);
  89. this.visit(pattern.left);
  90. this.rightHandNodes.push(pattern.right);
  91. this.assignments.pop();
  92. }
  93. }, {
  94. key: 'RestElement',
  95. value: function RestElement(pattern) {
  96. this.restElements.push(pattern);
  97. this.visit(pattern.argument);
  98. this.restElements.pop();
  99. }
  100. }, {
  101. key: 'MemberExpression',
  102. value: function MemberExpression(node) {
  103. // Computed property's key is a right hand node.
  104. if (node.computed) {
  105. this.rightHandNodes.push(node.property);
  106. }
  107. // the object is only read, write to its property.
  108. this.rightHandNodes.push(node.object);
  109. }
  110. //
  111. // ForInStatement.left and AssignmentExpression.left are LeftHandSideExpression.
  112. // By spec, LeftHandSideExpression is Pattern or MemberExpression.
  113. // (see also: https://github.com/estree/estree/pull/20#issuecomment-74584758)
  114. // But espree 2.0 and esprima 2.0 parse to ArrayExpression, ObjectExpression, etc...
  115. //
  116. }, {
  117. key: 'SpreadElement',
  118. value: function SpreadElement(node) {
  119. this.visit(node.argument);
  120. }
  121. }, {
  122. key: 'ArrayExpression',
  123. value: function ArrayExpression(node) {
  124. node.elements.forEach(this.visit, this);
  125. }
  126. }, {
  127. key: 'AssignmentExpression',
  128. value: function AssignmentExpression(node) {
  129. this.assignments.push(node);
  130. this.visit(node.left);
  131. this.rightHandNodes.push(node.right);
  132. this.assignments.pop();
  133. }
  134. }, {
  135. key: 'CallExpression',
  136. value: function CallExpression(node) {
  137. var _this2 = this;
  138. // arguments are right hand nodes.
  139. node.arguments.forEach(function (a) {
  140. _this2.rightHandNodes.push(a);
  141. });
  142. this.visit(node.callee);
  143. }
  144. }]);
  145. return PatternVisitor;
  146. }(_esrecurse2.default.Visitor);
  147. /* vim: set sw=4 ts=4 et tw=80 : */
  148. exports.default = PatternVisitor;
  149. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInBhdHRlcm4tdmlzaXRvci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7OztBQXdCQTs7QUFDQTs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUVBLFNBQVMsT0FBVCxDQUFpQixFQUFqQixFQUFxQjtBQUNqQixXQUFPLEdBQUcsR0FBRyxNQUFILEdBQVksQ0FBWixDQUFILElBQXFCLElBQXJCLENBRFU7Q0FBckI7O0lBSXFCOzs7OztrQ0FDQSxNQUFNO0FBQ25CLGdCQUFJLFdBQVcsS0FBSyxJQUFMLENBREk7QUFFbkIsbUJBQ0ksYUFBYSxtQkFBTyxVQUFQLElBQ2IsYUFBYSxtQkFBTyxhQUFQLElBQ2IsYUFBYSxtQkFBTyxZQUFQLElBQ2IsYUFBYSxtQkFBTyxhQUFQLElBQ2IsYUFBYSxtQkFBTyxXQUFQLElBQ2IsYUFBYSxtQkFBTyxpQkFBUCxDQVJFOzs7O0FB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