source: trip-planner-front/node_modules/@babel/helper-create-class-features-plugin/lib/features.js@ 6fe77af

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

primeNG components

  • Property mode set to 100644
File size: 5.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.FEATURES = void 0;
7exports.enableFeature = enableFeature;
8exports.isLoose = isLoose;
9exports.verifyUsedFeatures = verifyUsedFeatures;
10
11var _decorators = require("./decorators");
12
13const FEATURES = Object.freeze({
14 fields: 1 << 1,
15 privateMethods: 1 << 2,
16 decorators: 1 << 3,
17 privateIn: 1 << 4,
18 staticBlocks: 1 << 5
19});
20exports.FEATURES = FEATURES;
21const featuresSameLoose = new Map([[FEATURES.fields, "@babel/plugin-proposal-class-properties"], [FEATURES.privateMethods, "@babel/plugin-proposal-private-methods"], [FEATURES.privateIn, "@babel/plugin-proposal-private-property-in-object"]]);
22const featuresKey = "@babel/plugin-class-features/featuresKey";
23const looseKey = "@babel/plugin-class-features/looseKey";
24const looseLowPriorityKey = "@babel/plugin-class-features/looseLowPriorityKey/#__internal__@babel/preset-env__please-overwrite-loose-instead-of-throwing";
25
26function enableFeature(file, feature, loose) {
27 if (!hasFeature(file, feature) || canIgnoreLoose(file, feature)) {
28 file.set(featuresKey, file.get(featuresKey) | feature);
29
30 if (loose === "#__internal__@babel/preset-env__prefer-true-but-false-is-ok-if-it-prevents-an-error") {
31 setLoose(file, feature, true);
32 file.set(looseLowPriorityKey, file.get(looseLowPriorityKey) | feature);
33 } else if (loose === "#__internal__@babel/preset-env__prefer-false-but-true-is-ok-if-it-prevents-an-error") {
34 setLoose(file, feature, false);
35 file.set(looseLowPriorityKey, file.get(looseLowPriorityKey) | feature);
36 } else {
37 setLoose(file, feature, loose);
38 }
39 }
40
41 let resolvedLoose;
42 let higherPriorityPluginName;
43
44 for (const [mask, name] of featuresSameLoose) {
45 if (!hasFeature(file, mask)) continue;
46 const loose = isLoose(file, mask);
47
48 if (canIgnoreLoose(file, mask)) {
49 continue;
50 } else if (resolvedLoose === !loose) {
51 throw new Error("'loose' mode configuration must be the same for @babel/plugin-proposal-class-properties, " + "@babel/plugin-proposal-private-methods and " + "@babel/plugin-proposal-private-property-in-object (when they are enabled).");
52 } else {
53 resolvedLoose = loose;
54 higherPriorityPluginName = name;
55 }
56 }
57
58 if (resolvedLoose !== undefined) {
59 for (const [mask, name] of featuresSameLoose) {
60 if (hasFeature(file, mask) && isLoose(file, mask) !== resolvedLoose) {
61 setLoose(file, mask, resolvedLoose);
62 console.warn(`Though the "loose" option was set to "${!resolvedLoose}" in your @babel/preset-env ` + `config, it will not be used for ${name} since the "loose" mode option was set to ` + `"${resolvedLoose}" for ${higherPriorityPluginName}.\nThe "loose" option must be the ` + `same for @babel/plugin-proposal-class-properties, @babel/plugin-proposal-private-methods ` + `and @babel/plugin-proposal-private-property-in-object (when they are enabled): you can ` + `silence this warning by explicitly adding\n` + `\t["${name}", { "loose": ${resolvedLoose} }]\n` + `to the "plugins" section of your Babel config.`);
63 }
64 }
65 }
66}
67
68function hasFeature(file, feature) {
69 return !!(file.get(featuresKey) & feature);
70}
71
72function isLoose(file, feature) {
73 return !!(file.get(looseKey) & feature);
74}
75
76function setLoose(file, feature, loose) {
77 if (loose) file.set(looseKey, file.get(looseKey) | feature);else file.set(looseKey, file.get(looseKey) & ~feature);
78 file.set(looseLowPriorityKey, file.get(looseLowPriorityKey) & ~feature);
79}
80
81function canIgnoreLoose(file, feature) {
82 return !!(file.get(looseLowPriorityKey) & feature);
83}
84
85function verifyUsedFeatures(path, file) {
86 if ((0, _decorators.hasOwnDecorators)(path.node)) {
87 if (!hasFeature(file, FEATURES.decorators)) {
88 throw path.buildCodeFrameError("Decorators are not enabled." + "\nIf you are using " + '["@babel/plugin-proposal-decorators", { "legacy": true }], ' + 'make sure it comes *before* "@babel/plugin-proposal-class-properties" ' + "and enable loose mode, like so:\n" + '\t["@babel/plugin-proposal-decorators", { "legacy": true }]\n' + '\t["@babel/plugin-proposal-class-properties", { "loose": true }]');
89 }
90
91 if (path.isPrivate()) {
92 throw path.buildCodeFrameError(`Private ${path.isClassMethod() ? "methods" : "fields"} in decorated classes are not supported yet.`);
93 }
94 }
95
96 if (path.isClassPrivateMethod != null && path.isClassPrivateMethod()) {
97 if (!hasFeature(file, FEATURES.privateMethods)) {
98 throw path.buildCodeFrameError("Class private methods are not enabled.");
99 }
100 }
101
102 if (path.isPrivateName() && path.parentPath.isBinaryExpression({
103 operator: "in",
104 left: path.node
105 })) {
106 if (!hasFeature(file, FEATURES.privateIn)) {
107 throw path.buildCodeFrameError("Private property in checks are not enabled.");
108 }
109 }
110
111 if (path.isProperty()) {
112 if (!hasFeature(file, FEATURES.fields)) {
113 throw path.buildCodeFrameError("Class fields are not enabled.");
114 }
115 }
116
117 if (path.isStaticBlock != null && path.isStaticBlock()) {
118 if (!hasFeature(file, FEATURES.staticBlocks)) {
119 throw path.buildCodeFrameError("Static class blocks are not enabled. " + "Please add `@babel/plugin-proposal-class-static-block` to your configuration.");
120 }
121 }
122}
Note: See TracBrowser for help on using the repository browser.