MCPcopy Create free account
hub / github.com/arktypeio/arktype / dumpFile

Function dumpFile

ark/jetbrains/scripts/dumpTokens.ts:123–149  ·  view source on GitHub ↗
(
	tokenize: Tokenize,
	path: string,
	ark: boolean
)

Source from the content-addressed store, hash-verified

121}
122
123export const dumpFile = (
124 tokenize: Tokenize,
125 path: string,
126 ark: boolean
127): DumpedFile => {
128 const ext = path.slice(path.lastIndexOf(".") + 1)
129 try {
130 const tokens = tokenize(readFileSync(path, "utf8"), ext, ark)
131 const scopeIndex = new Map<string, number>()
132 const scopes: string[][] = []
133 const lines = tokens.map(line =>
134 line.map((t): [number, number, number] => {
135 const key = JSON.stringify(t.scopes)
136 let i = scopeIndex.get(key)
137 if (i === undefined) {
138 i = scopes.length
139 scopeIndex.set(key, i)
140 scopes.push(t.scopes)
141 }
142 return [t.start, t.end, i]
143 })
144 )
145 return { path, ark, scopes, lines }
146 } catch (e) {
147 return { path, ark, error: String(e) }
148 }
149}
150
151export const parseVariants = (value: string | undefined): boolean[] =>
152 value === "both" ? [true, false]

Callers 3

diffEngine.tsFile · 0.90
writeGoldens.tsFile · 0.90
dumpTokens.tsFile · 0.70

Calls 6

tokenizeFunction · 0.85
StringInterface · 0.85
mapMethod · 0.65
getMethod · 0.65
setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected