/
githubmirror
/
babel
Обзор
Документация
Войти
/
githubmirror
/
babel
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/babel-plugin-transform-json-strings/src/index.ts
31 строка
1019 B
liuxingbaoyu
Enable `strictFunctionTypes` (#17946)
22 май 2026, 17:12
Не верифицирован
22 май 2026, 17:12
c6d71f3
Код
Авторство
О чём код?
import { declare } from "@babel/helper-plugin-utils"; import type { NodePath, types as t } from "@babel/core"; export default declare(api => { api.assertVersion(REQUIRED_VERSION("^7.0.0-0 || ^8.0.0")); const regex = /(\\*)([\u2028\u2029])/g; function replace(match: string, escapes: string, separator: string) { // If there's an odd number, that means the separator itself was escaped. // "\X" escapes X. // "\\X" escapes the backslash, so X is unescaped. const isEscaped = escapes.length % 2 === 1; if (isEscaped) return match; return `${escapes}\\u${separator.charCodeAt(0).toString(16)}`; } return { name: "transform-json-strings", manipulateOptions: undefined, visitor: api.traverse.explode({ "DirectiveLiteral|StringLiteral"({ node, }: NodePath<t.DirectiveLiteral | t.StringLiteral>) { const { extra } = node; if (!extra?.raw) return; extra.raw = (extra.raw as string).replace(regex, replace); }, }), }; });