| 121 | } |
| 122 | |
| 123 | export 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 | |
| 151 | export const parseVariants = (value: string | undefined): boolean[] => |
| 152 | value === "both" ? [true, false] |