source: trip-planner-front/node_modules/@babel/plugin-transform-classes/lib/index.js@ b738035

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

initial commit

  • Property mode set to 100644
File size: 2.8 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _helperPluginUtils = require("@babel/helper-plugin-utils");
9
10var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
11
12var _helperFunctionName = require("@babel/helper-function-name");
13
14var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
15
16var _core = require("@babel/core");
17
18var _globals = require("globals");
19
20var _transformClass = require("./transformClass");
21
22const getBuiltinClasses = category => Object.keys(_globals[category]).filter(name => /^[A-Z]/.test(name));
23
24const builtinClasses = new Set([...getBuiltinClasses("builtin"), ...getBuiltinClasses("browser")]);
25
26var _default = (0, _helperPluginUtils.declare)((api, options) => {
27 var _api$assumption, _api$assumption2, _api$assumption3, _api$assumption4;
28
29 api.assertVersion(7);
30 const {
31 loose
32 } = options;
33 const setClassMethods = (_api$assumption = api.assumption("setClassMethods")) != null ? _api$assumption : options.loose;
34 const constantSuper = (_api$assumption2 = api.assumption("constantSuper")) != null ? _api$assumption2 : options.loose;
35 const superIsCallableConstructor = (_api$assumption3 = api.assumption("superIsCallableConstructor")) != null ? _api$assumption3 : options.loose;
36 const noClassCalls = (_api$assumption4 = api.assumption("noClassCalls")) != null ? _api$assumption4 : options.loose;
37 const VISITED = Symbol();
38 return {
39 name: "transform-classes",
40 visitor: {
41 ExportDefaultDeclaration(path) {
42 if (!path.get("declaration").isClassDeclaration()) return;
43 (0, _helperSplitExportDeclaration.default)(path);
44 },
45
46 ClassDeclaration(path) {
47 const {
48 node
49 } = path;
50 const ref = node.id || path.scope.generateUidIdentifier("class");
51 path.replaceWith(_core.types.variableDeclaration("let", [_core.types.variableDeclarator(ref, _core.types.toExpression(node))]));
52 },
53
54 ClassExpression(path, state) {
55 const {
56 node
57 } = path;
58 if (node[VISITED]) return;
59 const inferred = (0, _helperFunctionName.default)(path);
60
61 if (inferred && inferred !== node) {
62 path.replaceWith(inferred);
63 return;
64 }
65
66 node[VISITED] = true;
67 path.replaceWith((0, _transformClass.default)(path, state.file, builtinClasses, loose, {
68 setClassMethods,
69 constantSuper,
70 superIsCallableConstructor,
71 noClassCalls
72 }));
73
74 if (path.isCallExpression()) {
75 (0, _helperAnnotateAsPure.default)(path);
76 const callee = path.get("callee");
77
78 if (callee.isArrowFunctionExpression()) {
79 callee.arrowFunctionToExpression();
80 }
81 }
82 }
83
84 }
85 };
86});
87
88exports.default = _default;
Note: See TracBrowser for help on using the repository browser.