source: imaps-frontend/node_modules/@babel/plugin-transform-class-static-block/lib/index.js

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[79a0317]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _helperPluginUtils = require("@babel/helper-plugin-utils");
8var _helperCreateClassFeaturesPlugin = require("@babel/helper-create-class-features-plugin");
9function generateUid(scope, denyList) {
10 const name = "";
11 let uid;
12 let i = 1;
13 do {
14 uid = `_${name}`;
15 if (i > 1) uid += i;
16 i++;
17 } while (denyList.has(uid));
18 return uid;
19}
20var _default = exports.default = (0, _helperPluginUtils.declare)(({
21 types: t,
22 template,
23 assertVersion
24}) => {
25 assertVersion("^7.12.0 || >8.0.0-alpha <8.0.0-beta");
26 return {
27 name: "transform-class-static-block",
28 manipulateOptions: (_, parser) => parser.plugins.push("classStaticBlock"),
29 pre() {
30 (0, _helperCreateClassFeaturesPlugin.enableFeature)(this.file, _helperCreateClassFeaturesPlugin.FEATURES.staticBlocks, false);
31 },
32 visitor: {
33 ClassBody(classBody) {
34 const {
35 scope
36 } = classBody;
37 const privateNames = new Set();
38 const body = classBody.get("body");
39 for (const path of body) {
40 if (path.isPrivate()) {
41 privateNames.add(path.get("key.id").node.name);
42 }
43 }
44 for (const path of body) {
45 if (!path.isStaticBlock()) continue;
46 const staticBlockPrivateId = generateUid(scope, privateNames);
47 privateNames.add(staticBlockPrivateId);
48 const staticBlockRef = t.privateName(t.identifier(staticBlockPrivateId));
49 let replacement;
50 const blockBody = path.node.body;
51 if (blockBody.length === 1 && t.isExpressionStatement(blockBody[0])) {
52 replacement = t.inheritsComments(blockBody[0].expression, blockBody[0]);
53 } else {
54 replacement = template.expression.ast`(() => { ${blockBody} })()`;
55 }
56 path.replaceWith(t.classPrivateProperty(staticBlockRef, replacement, [], true));
57 }
58 }
59 }
60 };
61});
62
63//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.