index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var helperPluginUtils = require('@babel/helper-plugin-utils');
  4. var core = require('@babel/core');
  5. function isPureVoid(node) {
  6. return core.types.isUnaryExpression(node) && node.operator === "void" && core.types.isPureish(node.argument);
  7. }
  8. function unshiftForXStatementBody(statementPath, newStatements) {
  9. statementPath.ensureBlock();
  10. const {
  11. scope,
  12. node
  13. } = statementPath;
  14. const bodyScopeBindings = statementPath.get("body").scope.bindings;
  15. const hasShadowedBlockScopedBindings = Object.keys(bodyScopeBindings).some(name => scope.hasBinding(name));
  16. if (hasShadowedBlockScopedBindings) {
  17. node.body = core.types.blockStatement([...newStatements, node.body]);
  18. } else {
  19. node.body.body.unshift(...newStatements);
  20. }
  21. }
  22. function hasArrayRest(pattern) {
  23. return pattern.elements.some(elem => core.types.isRestElement(elem));
  24. }
  25. function hasObjectRest(pattern) {
  26. return pattern.properties.some(prop => core.types.isRestElement(prop));
  27. }
  28. const STOP_TRAVERSAL = {};
  29. const arrayUnpackVisitor = (node, ancestors, state) => {
  30. if (!ancestors.length) {
  31. return;
  32. }
  33. if (core.types.isIdentifier(node) && core.types.isReferenced(node, ancestors[ancestors.length - 1].node) && state.bindings[node.name]) {
  34. state.deopt = true;
  35. throw STOP_TRAVERSAL;
  36. }
  37. };
  38. class DestructuringTransformer {
  39. constructor(opts) {
  40. this.blockHoist = void 0;
  41. this.operator = void 0;
  42. this.arrayRefSet = void 0;
  43. this.nodes = void 0;
  44. this.scope = void 0;
  45. this.kind = void 0;
  46. this.iterableIsArray = void 0;
  47. this.arrayLikeIsIterable = void 0;
  48. this.objectRestNoSymbols = void 0;
  49. this.useBuiltIns = void 0;
  50. this.addHelper = void 0;
  51. this.blockHoist = opts.blockHoist;
  52. this.operator = opts.operator;
  53. this.arrayRefSet = new Set();
  54. this.nodes = opts.nodes || [];
  55. this.scope = opts.scope;
  56. this.kind = opts.kind;
  57. this.iterableIsArray = opts.iterableIsArray;
  58. this.arrayLikeIsIterable = opts.arrayLikeIsIterable;
  59. this.objectRestNoSymbols = opts.objectRestNoSymbols;
  60. this.useBuiltIns = opts.useBuiltIns;
  61. this.addHelper = opts.addHelper;
  62. }
  63. getExtendsHelper() {
  64. return this.useBuiltIns ? core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("assign")) : this.addHelper("extends");
  65. }
  66. buildVariableAssignment(id, init) {
  67. let op = this.operator;
  68. if (core.types.isMemberExpression(id) || core.types.isOptionalMemberExpression(id)) op = "=";
  69. let node;
  70. if (op) {
  71. node = core.types.expressionStatement(core.types.assignmentExpression(op, id, core.types.cloneNode(init) || this.scope.buildUndefinedNode()));
  72. } else {
  73. let nodeInit;
  74. if (this.kind === "const" && init === null) {
  75. nodeInit = this.scope.buildUndefinedNode();
  76. } else {
  77. nodeInit = core.types.cloneNode(init);
  78. }
  79. node = core.types.variableDeclaration(this.kind, [core.types.variableDeclarator(id, nodeInit)]);
  80. }
  81. node._blockHoist = this.blockHoist;
  82. return node;
  83. }
  84. buildVariableDeclaration(id, init) {
  85. const declar = core.types.variableDeclaration("var", [core.types.variableDeclarator(core.types.cloneNode(id), core.types.cloneNode(init))]);
  86. declar._blockHoist = this.blockHoist;
  87. return declar;
  88. }
  89. push(id, _init) {
  90. const init = core.types.cloneNode(_init);
  91. if (core.types.isObjectPattern(id)) {
  92. this.pushObjectPattern(id, init);
  93. } else if (core.types.isArrayPattern(id)) {
  94. this.pushArrayPattern(id, init);
  95. } else if (core.types.isAssignmentPattern(id)) {
  96. this.pushAssignmentPattern(id, init);
  97. } else {
  98. this.nodes.push(this.buildVariableAssignment(id, init));
  99. }
  100. }
  101. toArray(node, count) {
  102. if (this.iterableIsArray || core.types.isIdentifier(node) && this.arrayRefSet.has(node.name)) {
  103. return node;
  104. } else {
  105. const {
  106. scope,
  107. arrayLikeIsIterable
  108. } = this;
  109. if (core.types.isIdentifier(node)) {
  110. const binding = scope.getBinding(node.name);
  111. if (binding != null && binding.constant && binding.path.isGenericType("Array")) {
  112. return node;
  113. }
  114. }
  115. if (core.types.isArrayExpression(node)) {
  116. return node;
  117. }
  118. if (core.types.isIdentifier(node, {
  119. name: "arguments"
  120. })) {
  121. return core.template.expression.ast`
  122. Array.prototype.slice.call(${node})
  123. `;
  124. }
  125. let helperName;
  126. const args = [node];
  127. if (typeof count === "number") {
  128. args.push(core.types.numericLiteral(count));
  129. helperName = "slicedToArray";
  130. } else {
  131. helperName = "toArray";
  132. }
  133. if (arrayLikeIsIterable) {
  134. args.unshift(scope.path.hub.addHelper(helperName));
  135. helperName = "maybeArrayLike";
  136. }
  137. return core.types.callExpression(scope.path.hub.addHelper(helperName), args);
  138. }
  139. }
  140. pushAssignmentPattern({
  141. left,
  142. right
  143. }, valueRef) {
  144. if (isPureVoid(valueRef)) {
  145. this.push(left, right);
  146. return;
  147. }
  148. const tempId = this.scope.generateUidIdentifierBasedOnNode(valueRef);
  149. this.nodes.push(this.buildVariableDeclaration(tempId, valueRef));
  150. const tempConditional = core.types.conditionalExpression(core.types.binaryExpression("===", core.types.cloneNode(tempId), this.scope.buildUndefinedNode()), right, core.types.cloneNode(tempId));
  151. if (core.types.isPattern(left)) {
  152. let patternId;
  153. let node;
  154. if (this.kind === "const" || this.kind === "let") {
  155. patternId = this.scope.generateUidIdentifier(tempId.name);
  156. node = this.buildVariableDeclaration(patternId, tempConditional);
  157. } else {
  158. patternId = tempId;
  159. node = core.types.expressionStatement(core.types.assignmentExpression("=", core.types.cloneNode(tempId), tempConditional));
  160. }
  161. this.nodes.push(node);
  162. this.push(left, patternId);
  163. } else {
  164. this.nodes.push(this.buildVariableAssignment(left, tempConditional));
  165. }
  166. }
  167. pushObjectRest(pattern, objRef, spreadProp, spreadPropIndex) {
  168. const value = buildObjectExcludingKeys(pattern.properties.slice(0, spreadPropIndex), objRef, this.scope, name => this.addHelper(name), this.objectRestNoSymbols, this.useBuiltIns);
  169. this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value));
  170. }
  171. pushObjectProperty(prop, propRef) {
  172. if (core.types.isLiteral(prop.key)) prop.computed = true;
  173. const pattern = prop.value;
  174. const objRef = core.types.memberExpression(core.types.cloneNode(propRef), prop.key, prop.computed);
  175. if (core.types.isPattern(pattern)) {
  176. this.push(pattern, objRef);
  177. } else {
  178. this.nodes.push(this.buildVariableAssignment(pattern, objRef));
  179. }
  180. }
  181. pushObjectPattern(pattern, objRef) {
  182. if (!pattern.properties.length) {
  183. this.nodes.push(core.types.expressionStatement(core.types.callExpression(this.addHelper("objectDestructuringEmpty"), isPureVoid(objRef) ? [] : [objRef])));
  184. return;
  185. }
  186. if (pattern.properties.length > 1 && !this.scope.isStatic(objRef)) {
  187. const temp = this.scope.generateUidIdentifierBasedOnNode(objRef);
  188. this.nodes.push(this.buildVariableDeclaration(temp, objRef));
  189. objRef = temp;
  190. }
  191. if (hasObjectRest(pattern)) {
  192. let copiedPattern;
  193. for (let i = 0; i < pattern.properties.length; i++) {
  194. const prop = pattern.properties[i];
  195. if (core.types.isRestElement(prop)) {
  196. break;
  197. }
  198. const key = prop.key;
  199. if (prop.computed && !this.scope.isPure(key)) {
  200. const name = this.scope.generateUidIdentifierBasedOnNode(key);
  201. this.nodes.push(this.buildVariableDeclaration(name, key));
  202. if (!copiedPattern) {
  203. copiedPattern = pattern = Object.assign({}, pattern, {
  204. properties: pattern.properties.slice()
  205. });
  206. }
  207. copiedPattern.properties[i] = Object.assign({}, prop, {
  208. key: name
  209. });
  210. }
  211. }
  212. }
  213. for (let i = 0; i < pattern.properties.length; i++) {
  214. const prop = pattern.properties[i];
  215. if (core.types.isRestElement(prop)) {
  216. this.pushObjectRest(pattern, objRef, prop, i);
  217. } else {
  218. this.pushObjectProperty(prop, objRef);
  219. }
  220. }
  221. }
  222. canUnpackArrayPattern(pattern, arr) {
  223. if (!core.types.isArrayExpression(arr)) return false;
  224. if (pattern.elements.length > arr.elements.length) return;
  225. if (pattern.elements.length < arr.elements.length && !hasArrayRest(pattern)) {
  226. return false;
  227. }
  228. for (const elem of pattern.elements) {
  229. if (!elem) return false;
  230. if (core.types.isMemberExpression(elem)) return false;
  231. }
  232. for (const elem of arr.elements) {
  233. if (core.types.isSpreadElement(elem)) return false;
  234. if (core.types.isCallExpression(elem)) return false;
  235. if (core.types.isMemberExpression(elem)) return false;
  236. }
  237. const bindings = core.types.getBindingIdentifiers(pattern);
  238. const state = {
  239. deopt: false,
  240. bindings
  241. };
  242. try {
  243. core.types.traverse(arr, arrayUnpackVisitor, state);
  244. } catch (e) {
  245. if (e !== STOP_TRAVERSAL) throw e;
  246. }
  247. return !state.deopt;
  248. }
  249. pushUnpackedArrayPattern(pattern, arr) {
  250. const holeToUndefined = el => el != null ? el : this.scope.buildUndefinedNode();
  251. for (let i = 0; i < pattern.elements.length; i++) {
  252. const elem = pattern.elements[i];
  253. if (core.types.isRestElement(elem)) {
  254. this.push(elem.argument, core.types.arrayExpression(arr.elements.slice(i).map(holeToUndefined)));
  255. } else {
  256. this.push(elem, holeToUndefined(arr.elements[i]));
  257. }
  258. }
  259. }
  260. pushArrayPattern(pattern, arrayRef) {
  261. if (arrayRef === null) {
  262. this.nodes.push(core.types.expressionStatement(core.types.callExpression(this.addHelper("objectDestructuringEmpty"), [])));
  263. return;
  264. }
  265. if (!pattern.elements) return;
  266. if (this.canUnpackArrayPattern(pattern, arrayRef)) {
  267. this.pushUnpackedArrayPattern(pattern, arrayRef);
  268. return;
  269. }
  270. const count = !hasArrayRest(pattern) && pattern.elements.length;
  271. const toArray = this.toArray(arrayRef, count);
  272. if (core.types.isIdentifier(toArray)) {
  273. arrayRef = toArray;
  274. } else {
  275. arrayRef = this.scope.generateUidIdentifierBasedOnNode(arrayRef);
  276. this.arrayRefSet.add(arrayRef.name);
  277. this.nodes.push(this.buildVariableDeclaration(arrayRef, toArray));
  278. }
  279. for (let i = 0; i < pattern.elements.length; i++) {
  280. const elem = pattern.elements[i];
  281. if (!elem) continue;
  282. if (core.types.isRestElement(elem)) {
  283. this.push(elem.argument, core.types.callExpression(core.types.memberExpression(core.types.callExpression(this.scope.path.hub.addHelper("arrayLikeToArray"), [arrayRef]), core.types.identifier("slice")), [core.types.numericLiteral(i)]));
  284. } else {
  285. this.push(elem, core.types.memberExpression(arrayRef, core.types.numericLiteral(i), true));
  286. }
  287. }
  288. }
  289. init(pattern, ref) {
  290. if (!core.types.isArrayExpression(ref) && !core.types.isMemberExpression(ref)) {
  291. const memo = this.scope.maybeGenerateMemoised(ref, true);
  292. if (memo) {
  293. this.nodes.push(this.buildVariableDeclaration(memo, core.types.cloneNode(ref)));
  294. ref = memo;
  295. }
  296. }
  297. this.push(pattern, ref);
  298. return this.nodes;
  299. }
  300. }
  301. function buildObjectExcludingKeys(excludedKeys, objRef, scope, addHelper, objectRestNoSymbols, useBuiltIns) {
  302. const keys = [];
  303. let allLiteral = true;
  304. let hasTemplateLiteral = false;
  305. for (let i = 0; i < excludedKeys.length; i++) {
  306. const prop = excludedKeys[i];
  307. const key = prop.key;
  308. if (core.types.isIdentifier(key) && !prop.computed) {
  309. keys.push(core.types.stringLiteral(key.name));
  310. } else if (core.types.isTemplateLiteral(key)) {
  311. keys.push(core.types.cloneNode(key));
  312. hasTemplateLiteral = true;
  313. } else if (core.types.isLiteral(key)) {
  314. keys.push(core.types.stringLiteral(String(key.value)));
  315. } else if (core.types.isPrivateName(key)) ; else {
  316. keys.push(core.types.cloneNode(key));
  317. allLiteral = false;
  318. }
  319. }
  320. let value;
  321. if (keys.length === 0) {
  322. const extendsHelper = useBuiltIns ? core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("assign")) : addHelper("extends");
  323. value = core.types.callExpression(extendsHelper, [core.types.objectExpression([]), core.types.sequenceExpression([core.types.callExpression(addHelper("objectDestructuringEmpty"), [core.types.cloneNode(objRef)]), core.types.cloneNode(objRef)])]);
  324. } else {
  325. let keyExpression = core.types.arrayExpression(keys);
  326. if (!allLiteral) {
  327. keyExpression = core.types.callExpression(core.types.memberExpression(keyExpression, core.types.identifier("map")), [addHelper("toPropertyKey")]);
  328. } else if (!hasTemplateLiteral && !core.types.isProgram(scope.block)) {
  329. const programScope = scope.getProgramParent();
  330. const id = programScope.generateUidIdentifier("excluded");
  331. programScope.push({
  332. id,
  333. init: keyExpression,
  334. kind: "const"
  335. });
  336. keyExpression = core.types.cloneNode(id);
  337. }
  338. value = core.types.callExpression(addHelper(`objectWithoutProperties${objectRestNoSymbols ? "Loose" : ""}`), [core.types.cloneNode(objRef), keyExpression]);
  339. }
  340. return value;
  341. }
  342. function convertVariableDeclaration(path, addHelper, arrayLikeIsIterable, iterableIsArray, objectRestNoSymbols, useBuiltIns) {
  343. const {
  344. node,
  345. scope
  346. } = path;
  347. const nodeKind = node.kind;
  348. const nodeLoc = node.loc;
  349. const nodes = [];
  350. for (let i = 0; i < node.declarations.length; i++) {
  351. const declar = node.declarations[i];
  352. const patternId = declar.init;
  353. const pattern = declar.id;
  354. const destructuring = new DestructuringTransformer({
  355. blockHoist: node._blockHoist,
  356. nodes: nodes,
  357. scope: scope,
  358. kind: node.kind,
  359. iterableIsArray,
  360. arrayLikeIsIterable,
  361. useBuiltIns,
  362. objectRestNoSymbols,
  363. addHelper
  364. });
  365. if (core.types.isPattern(pattern)) {
  366. destructuring.init(pattern, patternId);
  367. if (+i !== node.declarations.length - 1) {
  368. core.types.inherits(nodes[nodes.length - 1], declar);
  369. }
  370. } else {
  371. nodes.push(core.types.inherits(destructuring.buildVariableAssignment(pattern, patternId), declar));
  372. }
  373. }
  374. let tail = null;
  375. let nodesOut = [];
  376. for (const node of nodes) {
  377. if (core.types.isVariableDeclaration(node)) {
  378. if (tail !== null) {
  379. tail.declarations.push(...node.declarations);
  380. continue;
  381. } else {
  382. node.kind = nodeKind;
  383. tail = node;
  384. }
  385. } else {
  386. tail = null;
  387. }
  388. if (!node.loc) {
  389. node.loc = nodeLoc;
  390. }
  391. nodesOut.push(node);
  392. }
  393. if (nodesOut.length === 2 && core.types.isVariableDeclaration(nodesOut[0]) && core.types.isExpressionStatement(nodesOut[1]) && core.types.isCallExpression(nodesOut[1].expression) && nodesOut[0].declarations.length === 1) {
  394. const expr = nodesOut[1].expression;
  395. expr.arguments = [nodesOut[0].declarations[0].init];
  396. nodesOut = [expr];
  397. } else {
  398. if (core.types.isForStatement(path.parent, {
  399. init: node
  400. }) && !nodesOut.some(v => core.types.isVariableDeclaration(v))) {
  401. for (let i = 0; i < nodesOut.length; i++) {
  402. const node = nodesOut[i];
  403. if (core.types.isExpressionStatement(node)) {
  404. nodesOut[i] = node.expression;
  405. }
  406. }
  407. }
  408. }
  409. if (nodesOut.length === 1) {
  410. path.replaceWith(nodesOut[0]);
  411. } else {
  412. path.replaceWithMultiple(nodesOut);
  413. }
  414. scope.crawl();
  415. }
  416. function convertAssignmentExpression(path, addHelper, arrayLikeIsIterable, iterableIsArray, objectRestNoSymbols, useBuiltIns) {
  417. const {
  418. node,
  419. scope,
  420. parentPath
  421. } = path;
  422. const nodes = [];
  423. const destructuring = new DestructuringTransformer({
  424. operator: node.operator,
  425. scope: scope,
  426. nodes: nodes,
  427. arrayLikeIsIterable,
  428. iterableIsArray,
  429. objectRestNoSymbols,
  430. useBuiltIns,
  431. addHelper
  432. });
  433. let ref;
  434. if (!parentPath.isExpressionStatement() && !parentPath.isSequenceExpression() || path.isCompletionRecord()) {
  435. ref = scope.generateUidIdentifierBasedOnNode(node.right, "ref");
  436. nodes.push(core.types.variableDeclaration("var", [core.types.variableDeclarator(ref, node.right)]));
  437. if (core.types.isArrayExpression(node.right)) {
  438. destructuring.arrayRefSet.add(ref.name);
  439. }
  440. }
  441. destructuring.init(node.left, ref || node.right);
  442. if (ref) {
  443. if (parentPath.isArrowFunctionExpression()) {
  444. path.replaceWith(core.types.blockStatement([]));
  445. nodes.push(core.types.returnStatement(core.types.cloneNode(ref)));
  446. } else {
  447. nodes.push(core.types.expressionStatement(core.types.cloneNode(ref)));
  448. }
  449. }
  450. path.replaceWithMultiple(nodes);
  451. scope.crawl();
  452. }
  453. function variableDeclarationHasDestructuringPattern(node) {
  454. for (const declar of node.declarations) {
  455. if (core.types.isPattern(declar.id) && declar.id.type !== "VoidPattern") {
  456. return true;
  457. }
  458. }
  459. return false;
  460. }
  461. var index = helperPluginUtils.declare((api, options) => {
  462. var _ref, _api$assumption, _ref2, _options$allowArrayLi, _ref3, _api$assumption2;
  463. api.assertVersion(7);
  464. const {
  465. useBuiltIns = false
  466. } = options;
  467. const iterableIsArray = (_ref = (_api$assumption = api.assumption("iterableIsArray")) != null ? _api$assumption : options.loose) != null ? _ref : false;
  468. const arrayLikeIsIterable = (_ref2 = (_options$allowArrayLi = options.allowArrayLike) != null ? _options$allowArrayLi : api.assumption("arrayLikeIsIterable")) != null ? _ref2 : false;
  469. const objectRestNoSymbols = (_ref3 = (_api$assumption2 = api.assumption("objectRestNoSymbols")) != null ? _api$assumption2 : options.loose) != null ? _ref3 : false;
  470. return {
  471. name: "transform-destructuring",
  472. visitor: {
  473. ExportNamedDeclaration(path) {
  474. const declaration = path.get("declaration");
  475. if (!declaration.isVariableDeclaration()) return;
  476. if (!variableDeclarationHasDestructuringPattern(declaration.node)) return;
  477. {
  478. var _path$splitExportDecl;
  479. (_path$splitExportDecl = path.splitExportDeclaration) != null ? _path$splitExportDecl : path.splitExportDeclaration = require("@babel/traverse").NodePath.prototype.splitExportDeclaration;
  480. }
  481. path.splitExportDeclaration();
  482. },
  483. ForXStatement(path) {
  484. const {
  485. node,
  486. scope
  487. } = path;
  488. const left = node.left;
  489. if (core.types.isPattern(left)) {
  490. const temp = scope.generateUidIdentifier("ref");
  491. node.left = core.types.variableDeclaration("var", [core.types.variableDeclarator(temp)]);
  492. path.ensureBlock();
  493. const statementBody = path.node.body.body;
  494. const nodes = [];
  495. if (statementBody.length === 0 && path.isCompletionRecord()) {
  496. nodes.unshift(core.types.expressionStatement(scope.buildUndefinedNode()));
  497. }
  498. nodes.unshift(core.types.expressionStatement(core.types.assignmentExpression("=", left, core.types.cloneNode(temp))));
  499. unshiftForXStatementBody(path, nodes);
  500. scope.crawl();
  501. return;
  502. }
  503. if (!core.types.isVariableDeclaration(left)) return;
  504. const pattern = left.declarations[0].id;
  505. if (!core.types.isPattern(pattern) || pattern.type === "VoidPattern") return;
  506. const key = scope.generateUidIdentifier("ref");
  507. node.left = core.types.variableDeclaration(left.kind, [core.types.variableDeclarator(key, null)]);
  508. const nodes = [];
  509. const destructuring = new DestructuringTransformer({
  510. kind: left.kind,
  511. scope: scope,
  512. nodes: nodes,
  513. arrayLikeIsIterable,
  514. iterableIsArray,
  515. objectRestNoSymbols,
  516. useBuiltIns,
  517. addHelper: name => this.addHelper(name)
  518. });
  519. destructuring.init(pattern, key);
  520. unshiftForXStatementBody(path, nodes);
  521. scope.crawl();
  522. },
  523. CatchClause({
  524. node,
  525. scope
  526. }) {
  527. const pattern = node.param;
  528. if (!core.types.isPattern(pattern)) return;
  529. const ref = scope.generateUidIdentifier("ref");
  530. node.param = ref;
  531. const nodes = [];
  532. const destructuring = new DestructuringTransformer({
  533. kind: "let",
  534. scope: scope,
  535. nodes: nodes,
  536. arrayLikeIsIterable,
  537. iterableIsArray,
  538. objectRestNoSymbols,
  539. useBuiltIns,
  540. addHelper: name => this.addHelper(name)
  541. });
  542. destructuring.init(pattern, ref);
  543. node.body.body = [...nodes, ...node.body.body];
  544. scope.crawl();
  545. },
  546. AssignmentExpression(path, state) {
  547. if (!core.types.isPattern(path.node.left)) return;
  548. convertAssignmentExpression(path, name => state.addHelper(name), arrayLikeIsIterable, iterableIsArray, objectRestNoSymbols, useBuiltIns);
  549. },
  550. VariableDeclaration(path, state) {
  551. const {
  552. node,
  553. parent
  554. } = path;
  555. if (core.types.isForXStatement(parent)) return;
  556. if (!parent || !path.container) return;
  557. if (!variableDeclarationHasDestructuringPattern(node)) return;
  558. convertVariableDeclaration(path, name => state.addHelper(name), arrayLikeIsIterable, iterableIsArray, objectRestNoSymbols, useBuiltIns);
  559. }
  560. }
  561. };
  562. });
  563. exports.buildObjectExcludingKeys = buildObjectExcludingKeys;
  564. exports.default = index;
  565. exports.unshiftForXStatementBody = unshiftForXStatementBody;
  566. //# sourceMappingURL=index.js.map