MCPcopy Index your code
hub / github.com/formatjs/formatjs / transformWithTs

Function transformWithTs

packages/ts-transformer/transform.ts:959–991  ·  view source on GitHub ↗
(
  ts: TypeScript,
  opts: Opts
)

Source from the content-addressed store, hash-verified

957}
958
959export function transformWithTs(
960 ts: TypeScript,
961 opts: Opts
962): typescript.TransformerFactory<typescript.SourceFile> {
963 opts = {...DEFAULT_OPTS, ...opts}
964 debug('Transforming options', opts)
965 const transformFn: typescript.TransformerFactory<
966 typescript.SourceFile
967 > = ctx => {
968 return sf => {
969 const pragmaResult = PRAGMA_REGEX.exec(sf.text)
970 if (pragmaResult) {
971 debug('Pragma found', pragmaResult)
972 const [, pragma, kvString] = pragmaResult
973 if (pragma === opts.pragma) {
974 const kvs = kvString.split(' ')
975 const result: Record<string, string> = {}
976 for (const kv of kvs) {
977 const [k, v] = kv.split(':')
978 result[k] = v
979 }
980 debug('Pragma extracted', result)
981 if (typeof opts.onMetaExtracted === 'function') {
982 opts.onMetaExtracted(sf.fileName, result)
983 }
984 }
985 }
986 return ts.visitEachChild(sf, getVisitor(ts, ctx, sf, opts), ctx)
987 }
988 }
989
990 return transformFn
991}
992
993export function transform(
994 opts: Opts

Callers 3

parseScriptFunction · 0.90
factoryFunction · 0.85
transformFunction · 0.85

Calls 1

debugFunction · 0.70

Tested by

no test coverage detected