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.

41 lines
1.0 KiB

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