index.js 956 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _helperPluginUtils = require("@babel/helper-plugin-utils");
  7. var _pluginSyntaxJsonStrings = require("@babel/plugin-syntax-json-strings");
  8. var _default = (0, _helperPluginUtils.declare)(api => {
  9. api.assertVersion(7);
  10. const regex = /(\\*)([\u2028\u2029])/g;
  11. function replace(match, escapes, separator) {
  12. const isEscaped = escapes.length % 2 === 1;
  13. if (isEscaped) return match;
  14. return `${escapes}\\u${separator.charCodeAt(0).toString(16)}`;
  15. }
  16. return {
  17. name: "proposal-json-strings",
  18. inherits: _pluginSyntaxJsonStrings.default,
  19. visitor: {
  20. "DirectiveLiteral|StringLiteral"({
  21. node
  22. }) {
  23. const {
  24. extra
  25. } = node;
  26. if (!(extra != null && extra.raw)) return;
  27. extra.raw = extra.raw.replace(regex, replace);
  28. }
  29. }
  30. };
  31. });
  32. exports.default = _default;