source: imaps-frontend/node_modules/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining/lib/index.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

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