Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.enableFeature = enableFeature;
  6. exports.isLoose = isLoose;
  7. exports.verifyUsedFeatures = verifyUsedFeatures;
  8. exports.FEATURES = void 0;
  9. var _decorators = require("./decorators");
  10. const FEATURES = Object.freeze({
  11. fields: 1 << 1,
  12. privateMethods: 1 << 2,
  13. decorators: 1 << 3
  14. });
  15. exports.FEATURES = FEATURES;
  16. const featuresKey = "@babel/plugin-class-features/featuresKey";
  17. const looseKey = "@babel/plugin-class-features/looseKey";
  18. function enableFeature(file, feature, loose) {
  19. if (!hasFeature(file, feature)) {
  20. file.set(featuresKey, file.get(featuresKey) | feature);
  21. if (loose) file.set(looseKey, file.get(looseKey) | feature);
  22. }
  23. }
  24. function hasFeature(file, feature) {
  25. return !!(file.get(featuresKey) & feature);
  26. }
  27. function isLoose(file, feature) {
  28. return !!(file.get(looseKey) & feature);
  29. }
  30. function verifyUsedFeatures(path, file) {
  31. if ((0, _decorators.hasOwnDecorators)(path.node)) {
  32. if (!hasFeature(file, FEATURES.decorators)) {
  33. 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 }]');
  34. }
  35. if (path.isPrivate()) {
  36. throw path.buildCodeFrameError(`Private ${path.isClassMethod() ? "methods" : "fields"} in decorated classes are not supported yet.`);
  37. }
  38. }
  39. if (path.isPrivate() && path.isMethod()) {
  40. if (!hasFeature(file, FEATURES.privateMethods)) {
  41. throw path.buildCodeFrameError("Class private methods are not enabled.");
  42. }
  43. }
  44. if (hasFeature(file, FEATURES.privateMethods) && hasFeature(file, FEATURES.fields) && isLoose(file, FEATURES.privateMethods) !== isLoose(file, FEATURES.fields)) {
  45. throw path.buildCodeFrameError("'loose' mode configuration must be the same for both @babel/plugin-proposal-class-properties " + "and @babel/plugin-proposal-private-methods");
  46. }
  47. if (path.isProperty()) {
  48. if (!hasFeature(file, FEATURES.fields)) {
  49. throw path.buildCodeFrameError("Class fields are not enabled.");
  50. }
  51. }
  52. }