You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB

4 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = plugin;
  6. function plugin(targets, nodeTypes, detect) {
  7. class Plugin {
  8. constructor(result) {
  9. this.nodes = [];
  10. this.result = result;
  11. this.targets = targets;
  12. this.nodeTypes = nodeTypes;
  13. }
  14. push(node, metadata) {
  15. node._stylehacks = Object.assign({}, metadata, {
  16. message: `Bad ${metadata.identifier}: ${metadata.hack}`,
  17. browsers: this.targets
  18. });
  19. this.nodes.push(node);
  20. }
  21. any(node) {
  22. if (~this.nodeTypes.indexOf(node.type)) {
  23. detect.apply(this, arguments);
  24. return !!node._stylehacks;
  25. }
  26. return false;
  27. }
  28. detectAndResolve(...args) {
  29. this.nodes = [];
  30. detect.apply(this, args);
  31. return this.resolve();
  32. }
  33. detectAndWarn(...args) {
  34. this.nodes = [];
  35. detect.apply(this, args);
  36. return this.warn();
  37. }
  38. resolve() {
  39. return this.nodes.forEach(node => node.remove());
  40. }
  41. warn() {
  42. return this.nodes.forEach(node => {
  43. const { message, browsers, identifier, hack } = node._stylehacks;
  44. return node.warn(this.result, message, { browsers, identifier, hack });
  45. });
  46. }
  47. }
  48. return Plugin;
  49. }
  50. module.exports = exports["default"];