source: trip-planner-front/node_modules/@babel/plugin-proposal-class-static-block/lib/index.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 1.7 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 _pluginSyntaxClassStaticBlock = require("@babel/plugin-syntax-class-static-block");
11
12var _helperCreateClassFeaturesPlugin = require("@babel/helper-create-class-features-plugin");
13
14function generateUid(scope, denyList) {
15 const name = "";
16 let uid;
17 let i = 1;
18
19 do {
20 uid = scope._generateUid(name, i);
21 i++;
22 } while (denyList.has(uid));
23
24 return uid;
25}
26
27var _default = (0, _helperPluginUtils.declare)(({
28 types: t,
29 template,
30 assertVersion
31}) => {
32 assertVersion("^7.12.0");
33 return {
34 name: "proposal-class-static-block",
35 inherits: _pluginSyntaxClassStaticBlock.default,
36
37 pre() {
38 (0, _helperCreateClassFeaturesPlugin.enableFeature)(this.file, _helperCreateClassFeaturesPlugin.FEATURES.staticBlocks, false);
39 },
40
41 visitor: {
42 ClassBody(classBody) {
43 const {
44 scope
45 } = classBody;
46 const privateNames = new Set();
47 const body = classBody.get("body");
48
49 for (const path of body) {
50 if (path.isPrivate()) {
51 privateNames.add(path.get("key.id").node.name);
52 }
53 }
54
55 for (const path of body) {
56 if (!path.isStaticBlock()) continue;
57 const staticBlockPrivateId = generateUid(scope, privateNames);
58 privateNames.add(staticBlockPrivateId);
59 const staticBlockRef = t.privateName(t.identifier(staticBlockPrivateId));
60 path.replaceWith(t.classPrivateProperty(staticBlockRef, template.expression.ast`(() => { ${path.node.body} })()`, [], true));
61 }
62 }
63
64 }
65 };
66});
67
68exports.default = _default;
Note: See TracBrowser for help on using the repository browser.