source: trip-planner-front/node_modules/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining/lib/index.js@ 84d0fbb

Last change on this file since 84d0fbb was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var helperPluginUtils = require('@babel/helper-plugin-utils');
6var pluginProposalOptionalChaining = require('@babel/plugin-proposal-optional-chaining');
7var helperSkipTransparentExpressionWrappers = require('@babel/helper-skip-transparent-expression-wrappers');
8var core = require('@babel/core');
9
10function matchAffectedArguments(argumentNodes) {
11 const spreadIndex = argumentNodes.findIndex(node => core.types.isSpreadElement(node));
12 return spreadIndex >= 0 && spreadIndex !== argumentNodes.length - 1;
13}
14
15function shouldTransform(path) {
16 let optionalPath = path;
17 const chains = [];
18
19 while (optionalPath.isOptionalMemberExpression() || optionalPath.isOptionalCallExpression()) {
20 const {
21 node
22 } = optionalPath;
23 chains.push(node);
24
25 if (optionalPath.isOptionalMemberExpression()) {
26 optionalPath = helperSkipTransparentExpressionWrappers.skipTransparentExprWrappers(optionalPath.get("object"));
27 } else if (optionalPath.isOptionalCallExpression()) {
28 optionalPath = helperSkipTransparentExpressionWrappers.skipTransparentExprWrappers(optionalPath.get("callee"));
29 }
30 }
31
32 for (let i = 0; i < chains.length; i++) {
33 const node = chains[i];
34
35 if (core.types.isOptionalCallExpression(node) && matchAffectedArguments(node.arguments)) {
36 if (node.optional) {
37 return true;
38 }
39
40 const callee = chains[i + 1];
41
42 if (core.types.isOptionalMemberExpression(callee, {
43 optional: true
44 })) {
45 return true;
46 }
47 }
48 }
49
50 return false;
51}
52
53var index = helperPluginUtils.declare(api => {
54 api.assertVersion(7);
55 const noDocumentAll = api.assumption("noDocumentAll");
56 const pureGetters = api.assumption("pureGetters");
57 return {
58 name: "bugfix-v8-spread-parameters-in-optional-chaining",
59 visitor: {
60 "OptionalCallExpression|OptionalMemberExpression"(path) {
61 if (shouldTransform(path)) {
62 pluginProposalOptionalChaining.transform(path, {
63 noDocumentAll,
64 pureGetters
65 });
66 }
67 }
68
69 }
70 };
71});
72
73exports.default = index;
74//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.