source: imaps-frontend/node_modules/@babel/plugin-transform-react-pure-annotations/lib/index.js@ 79a0317

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.6 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _helperPluginUtils = require("@babel/helper-plugin-utils");
8var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
9var _core = require("@babel/core");
10const PURE_CALLS = [["react", new Set(["cloneElement", "createContext", "createElement", "createFactory", "createRef", "forwardRef", "isValidElement", "memo", "lazy"])], ["react-dom", new Set(["createPortal"])]];
11var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
12 api.assertVersion(7);
13 return {
14 name: "transform-react-pure-annotations",
15 visitor: {
16 CallExpression(path) {
17 if (isReactCall(path)) {
18 (0, _helperAnnotateAsPure.default)(path);
19 }
20 }
21 }
22 };
23});
24function isReactCall(path) {
25 const calleePath = path.get("callee");
26 if (!calleePath.isMemberExpression()) {
27 for (const [module, methods] of PURE_CALLS) {
28 for (const method of methods) {
29 if (calleePath.referencesImport(module, method)) {
30 return true;
31 }
32 }
33 }
34 return false;
35 }
36 const object = calleePath.get("object");
37 const callee = calleePath.node;
38 if (!callee.computed && _core.types.isIdentifier(callee.property)) {
39 const propertyName = callee.property.name;
40 for (const [module, methods] of PURE_CALLS) {
41 if (object.referencesImport(module, "default") || object.referencesImport(module, "*")) {
42 return methods.has(propertyName);
43 }
44 }
45 }
46 return false;
47}
48
49//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.