index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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" || this.kind === "using") && 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" || this.kind === "using") {
  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. let elemRef;
  283. if (core.types.isRestElement(elem)) {
  284. elemRef = this.toArray(arrayRef);
  285. elemRef = core.types.callExpression(core.types.memberExpression(elemRef, core.types.identifier("slice")), [core.types.numericLiteral(i)]);
  286. this.push(elem.argument, elemRef);
  287. } else {
  288. elemRef = core.types.memberExpression(arrayRef, core.types.numericLiteral(i), true);
  289. this.push(elem, elemRef);
  290. }
  291. }
  292. }
  293. init(pattern, ref) {
  294. if (!core.types.isArrayExpression(ref) && !core.types.isMemberExpression(ref)) {
  295. const memo = this.scope.maybeGenerateMemoised(ref, true);
  296. if (memo) {
  297. this.nodes.push(this.buildVariableDeclaration(memo, core.types.cloneNode(ref)));
  298. ref = memo;
  299. }
  300. }
  301. this.push(pattern, ref);
  302. return this.nodes;
  303. }
  304. }
  305. function buildObjectExcludingKeys(excludedKeys, objRef, scope, addHelper, objectRestNoSymbols, useBuiltIns) {
  306. const keys = [];
  307. let allLiteral = true;
  308. let hasTemplateLiteral = false;
  309. for (let i = 0; i < excludedKeys.length; i++) {
  310. const prop = excludedKeys[i];
  311. const key = prop.key;
  312. if (core.types.isIdentifier(key) && !prop.computed) {
  313. keys.push(core.types.stringLiteral(key.name));
  314. } else if (core.types.isTemplateLiteral(key)) {
  315. keys.push(core.types.cloneNode(key));
  316. hasTemplateLiteral = true;
  317. } else if (core.types.isLiteral(key)) {
  318. keys.push(core.types.stringLiteral(String(key.value)));
  319. } else if (core.types.isPrivateName(key)) ; else {
  320. keys.push(core.types.cloneNode(key));
  321. allLiteral = false;
  322. }
  323. }
  324. let value;
  325. if (keys.length === 0) {
  326. const extendsHelper = useBuiltIns ? core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("assign")) : addHelper("extends");
  327. value = core.types.callExpression(extendsHelper, [core.types.objectExpression([]), core.types.sequenceExpression([core.types.callExpression(addHelper("objectDestructuringEmpty"), [core.types.cloneNode(objRef)]), core.types.cloneNode(objRef)])]);
  328. } else {
  329. let keyExpression = core.types.arrayExpression(keys);
  330. if (!allLiteral) {
  331. keyExpression = core.types.callExpression(core.types.memberExpression(keyExpression, core.types.identifier("map")), [addHelper("toPropertyKey")]);
  332. } else if (!hasTemplateLiteral && !core.types.isProgram(scope.block)) {
  333. const programScope = scope.getProgramParent();
  334. const id = programScope.generateUidIdentifier("excluded");
  335. programScope.push({
  336. id,
  337. init: keyExpression,
  338. kind: "const"
  339. });
  340. keyExpression = core.types.cloneNode(id);
  341. }
  342. value = core.types.callExpression(addHelper(`objectWithoutProperties${objectRestNoSymbols ? "Loose" : ""}`), [core.types.cloneNode(objRef), keyExpression]);
  343. }
  344. return value;
  345. }
  346. function convertVariableDeclaration(path, addHelper, arrayLikeIsIterable, iterableIsArray, objectRestNoSymbols, useBuiltIns) {
  347. const {
  348. node,
  349. scope
  350. } = path;
  351. const nodeKind = node.kind;
  352. const nodeLoc = node.loc;
  353. const nodes = [];
  354. for (let i = 0; i < node.declarations.length; i++) {
  355. const declar = node.declarations[i];
  356. const patternId = declar.init;
  357. const pattern = declar.id;
  358. const destructuring = new DestructuringTransformer({
  359. blockHoist: node._blockHoist,
  360. nodes: nodes,
  361. scope: scope,
  362. kind: node.kind,
  363. iterableIsArray,
  364. arrayLikeIsIterable,
  365. useBuiltIns,
  366. objectRestNoSymbols,
  367. addHelper
  368. });
  369. if (core.types.isPattern(pattern)) {
  370. destructuring.init(pattern, patternId);
  371. if (+i !== node.declarations.length - 1) {
  372. core.types.inherits(nodes[nodes.length - 1], declar);
  373. }
  374. } else {
  375. nodes.push(core.types.inherits(destructuring.buildVariableAssignment(pattern, patternId), declar));
  376. }
  377. }
  378. let tail = null;
  379. let nodesOut = [];
  380. for (const node of nodes) {
  381. if (core.types.isVariableDeclaration(node)) {
  382. if (tail !== null) {
  383. tail.declarations.push(...node.declarations);
  384. continue;
  385. } else {
  386. node.kind = nodeKind;
  387. tail = node;
  388. }
  389. } else {
  390. tail = null;
  391. }
  392. if (!node.loc) {
  393. node.loc = nodeLoc;
  394. }
  395. nodesOut.push(node);
  396. }
  397. 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) {
  398. const expr = nodesOut[1].expression;
  399. expr.arguments = [nodesOut[0].declarations[0].init];
  400. nodesOut = [expr];
  401. } else {
  402. if (core.types.isForStatement(path.parent, {
  403. init: node
  404. }) && !nodesOut.some(v => core.types.isVariableDeclaration(v))) {
  405. for (let i = 0; i < nodesOut.length; i++) {
  406. const node = nodesOut[i];
  407. if (core.types.isExpressionStatement(node)) {
  408. nodesOut[i] = node.expression;
  409. }
  410. }
  411. }
  412. }
  413. if (nodesOut.length === 1) {
  414. path.replaceWith(nodesOut[0]);
  415. } else {
  416. path.replaceWithMultiple(nodesOut);
  417. }
  418. scope.crawl();
  419. }
  420. function convertAssignmentExpression(path, addHelper, arrayLikeIsIterable, iterableIsArray, objectRestNoSymbols, useBuiltIns) {
  421. const {
  422. node,
  423. scope,
  424. parentPath
  425. } = path;
  426. const nodes = [];
  427. const destructuring = new DestructuringTransformer({
  428. operator: node.operator,
  429. scope: scope,
  430. nodes: nodes,
  431. arrayLikeIsIterable,
  432. iterableIsArray,
  433. objectRestNoSymbols,
  434. useBuiltIns,
  435. addHelper
  436. });
  437. let ref;
  438. if (!parentPath.isExpressionStatement() && !parentPath.isSequenceExpression() || path.isCompletionRecord()) {
  439. ref = scope.generateUidIdentifierBasedOnNode(node.right, "ref");
  440. nodes.push(core.types.variableDeclaration("var", [core.types.variableDeclarator(ref, node.right)]));
  441. if (core.types.isArrayExpression(node.right)) {
  442. destructuring.arrayRefSet.add(ref.name);
  443. }
  444. }
  445. destructuring.init(node.left, ref || node.right);
  446. if (ref) {
  447. if (parentPath.isArrowFunctionExpression()) {
  448. path.replaceWith(core.types.blockStatement([]));
  449. nodes.push(core.types.returnStatement(core.types.cloneNode(ref)));
  450. } else {
  451. nodes.push(core.types.expressionStatement(core.types.cloneNode(ref)));
  452. }
  453. }
  454. path.replaceWithMultiple(nodes);
  455. scope.crawl();
  456. }
  457. function variableDeclarationHasPattern(node) {
  458. for (const declar of node.declarations) {
  459. if (core.types.isPattern(declar.id)) {
  460. return true;
  461. }
  462. }
  463. return false;
  464. }
  465. var index = helperPluginUtils.declare((api, options) => {
  466. var _ref, _api$assumption, _ref2, _options$allowArrayLi, _ref3, _api$assumption2;
  467. api.assertVersion(7);
  468. const {
  469. useBuiltIns = false
  470. } = options;
  471. const iterableIsArray = (_ref = (_api$assumption = api.assumption("iterableIsArray")) != null ? _api$assumption : options.loose) != null ? _ref : false;
  472. const arrayLikeIsIterable = (_ref2 = (_options$allowArrayLi = options.allowArrayLike) != null ? _options$allowArrayLi : api.assumption("arrayLikeIsIterable")) != null ? _ref2 : false;
  473. const objectRestNoSymbols = (_ref3 = (_api$assumption2 = api.assumption("objectRestNoSymbols")) != null ? _api$assumption2 : options.loose) != null ? _ref3 : false;
  474. return {
  475. name: "transform-destructuring",
  476. visitor: {
  477. ExportNamedDeclaration(path) {
  478. const declaration = path.get("declaration");
  479. if (!declaration.isVariableDeclaration()) return;
  480. if (!variableDeclarationHasPattern(declaration.node)) return;
  481. const specifiers = [];
  482. for (const name of Object.keys(path.getOuterBindingIdentifiers())) {
  483. specifiers.push(core.types.exportSpecifier(core.types.identifier(name), core.types.identifier(name)));
  484. }
  485. path.replaceWith(declaration.node);
  486. path.insertAfter(core.types.exportNamedDeclaration(null, specifiers));
  487. path.scope.crawl();
  488. },
  489. ForXStatement(path) {
  490. const {
  491. node,
  492. scope
  493. } = path;
  494. const left = node.left;
  495. if (core.types.isPattern(left)) {
  496. const temp = scope.generateUidIdentifier("ref");
  497. node.left = core.types.variableDeclaration("var", [core.types.variableDeclarator(temp)]);
  498. path.ensureBlock();
  499. const statementBody = path.node.body.body;
  500. const nodes = [];
  501. if (statementBody.length === 0 && path.isCompletionRecord()) {
  502. nodes.unshift(core.types.expressionStatement(scope.buildUndefinedNode()));
  503. }
  504. nodes.unshift(core.types.expressionStatement(core.types.assignmentExpression("=", left, core.types.cloneNode(temp))));
  505. unshiftForXStatementBody(path, nodes);
  506. scope.crawl();
  507. return;
  508. }
  509. if (!core.types.isVariableDeclaration(left)) return;
  510. const pattern = left.declarations[0].id;
  511. if (!core.types.isPattern(pattern)) return;
  512. const key = scope.generateUidIdentifier("ref");
  513. node.left = core.types.variableDeclaration(left.kind, [core.types.variableDeclarator(key, null)]);
  514. const nodes = [];
  515. const destructuring = new DestructuringTransformer({
  516. kind: left.kind,
  517. scope: scope,
  518. nodes: nodes,
  519. arrayLikeIsIterable,
  520. iterableIsArray,
  521. objectRestNoSymbols,
  522. useBuiltIns,
  523. addHelper: name => this.addHelper(name)
  524. });
  525. destructuring.init(pattern, key);
  526. unshiftForXStatementBody(path, nodes);
  527. scope.crawl();
  528. },
  529. CatchClause({
  530. node,
  531. scope
  532. }) {
  533. const pattern = node.param;
  534. if (!core.types.isPattern(pattern)) return;
  535. const ref = scope.generateUidIdentifier("ref");
  536. node.param = ref;
  537. const nodes = [];
  538. const destructuring = new DestructuringTransformer({
  539. kind: "let",
  540. scope: scope,
  541. nodes: nodes,
  542. arrayLikeIsIterable,
  543. iterableIsArray,
  544. objectRestNoSymbols,
  545. useBuiltIns,
  546. addHelper: name => this.addHelper(name)
  547. });
  548. destructuring.init(pattern, ref);
  549. node.body.body = [...nodes, ...node.body.body];
  550. scope.crawl();
  551. },
  552. AssignmentExpression(path, state) {
  553. if (!core.types.isPattern(path.node.left)) return;
  554. convertAssignmentExpression(path, name => state.addHelper(name), arrayLikeIsIterable, iterableIsArray, objectRestNoSymbols, useBuiltIns);
  555. },
  556. VariableDeclaration(path, state) {
  557. const {
  558. node,
  559. parent
  560. } = path;
  561. if (core.types.isForXStatement(parent)) return;
  562. if (!parent || !path.container) return;
  563. if (!variableDeclarationHasPattern(node)) return;
  564. convertVariableDeclaration(path, name => state.addHelper(name), arrayLikeIsIterable, iterableIsArray, objectRestNoSymbols, useBuiltIns);
  565. }
  566. }
  567. };
  568. });
  569. exports.buildObjectExcludingKeys = buildObjectExcludingKeys;
  570. exports.default = index;
  571. exports.unshiftForXStatementBody = unshiftForXStatementBody;
  572. //# sourceMappingURL=index.js.map