/
githubmirror
/
next.js
Обзор
Документация
Войти
/
githubmirror
/
next.js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
canary
packages/next-codemod/lib/parser.ts
26 строк
781 B
Jiachi Liu
codemod: make parser more comptible (#71122)
11 окт 2024, 16:05
Не верифицирован
11 окт 2024, 16:05
b524c36
Код
Авторство
О чём код?
import j from 'jscodeshift' import babylonParse from 'jscodeshift/parser/babylon' import tsOptions from 'jscodeshift/parser/tsOptions' const dtsOptions = { ...tsOptions, plugins: [ ...tsOptions.plugins.filter((plugin) => plugin !== 'typescript'), ['typescript', { dts: true }], ], } function createParserFromPath(filePath: string): j.JSCodeshift { const isDeclarationFile = /\.d\.(m|c)?ts$/.test(filePath) if (isDeclarationFile) { return j.withParser(babylonParse(dtsOptions)) } // jsx is allowed in .js files, feed them into the tsx parser. // tsx parser :.js, .jsx, .tsx // ts parser: .ts, .mts, .cts const isTsFile = /\.(m|c)?.ts$/.test(filePath) return isTsFile ? j.withParser('ts') : j.withParser('tsx') } export { createParserFromPath }