-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtypes.d.ts
157 lines (146 loc) · 4.43 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
declare module "@danielx/civet" {
export type CivetAST = unknown
export type ParseOptions = Partial<{
autoVar: boolean
autoLet: boolean
coffeeBinaryExistential: boolean
coffeeBooleans: boolean
coffeeClasses: boolean
coffeeComment: boolean
coffeeCompat: boolean
coffeeDiv: boolean
coffeeDo: boolean
coffeeEq: boolean
coffeeForLoops: boolean
coffeeInterpolation: boolean
coffeeIsnt: boolean
coffeeJSX: boolean
coffeeLineContinuation: boolean
coffeeNot: boolean
coffeeOf: boolean
coffeePrototype: boolean
coffeeRange: boolean
defaultElement: string
globals: string[]
implicitReturns: boolean
jsxCode: boolean
objectIs: boolean
react: boolean
solid: boolean
client: boolean
rewriteCivetImports: string
rewriteTsImports: boolean
server: boolean
strict: boolean
symbols: string[]
tab: number
verbose: boolean
comptime: boolean
iife: boolean
repl: boolean
}>
export type CompileOptions = {
filename?: string
sourceMap?: boolean
inlineMap?: boolean
ast?: boolean | "raw"
js?: boolean
noCache?: boolean
hits?: string
trace?: string
parseOptions?: ParseOptions
/** Specifying an empty array will prevent ParseErrors from being thrown */
errors?: ParseError[]
/** Number of parallel threads to compile with (Node only) */
threads?: number
}
export type GenerateOptions = Omit<CompileOptions, "sourceMap"> & {
sourceMap?: undefined | SourceMap
}
export type SyncCompileOptions = CompileOptions &
{ parseOptions?: { comptime?: false } }
export type SourceMapping = [number] | [number, number, number, number]
export class SourceMap {
constructor(source: string)
updateSourceMap?(outputStr: string, inputPos: number): void
json(srcFileName: string, outFileName: string): unknown
source: string
lines: SourceMapping[][]
/** @deprecated */
data: { lines: SourceMapping[][] }
}
// TODO: Import ParseError class from Hera
export type ParseError = {
name: "ParseError"
message: string // filename:line:column header\nbody
header: string
body: string
filename: string
line: number | string
column: number | string
offset: number
}
export type ParseErrors = {
name: "ParseErrors"
message: string
errors: ParseError[]
}
export function isCompileError(err: any): err is ParseError | ParseErrors
type CompileOutput<T extends CompileOptions> =
T extends { ast: true } ? CivetAST :
T extends { sourceMap: true } ? {
code: string,
sourceMap: SourceMap,
} : string
export function compile<const T extends CompileOptions>(source: string, options?: T):
T extends { sync: true } ? CompileOutput<T> : Promise<CompileOutput<T>>
/** Warning: No caching */
export function parse(source: string, options?: CompileOptions & {startRule?: string}): CivetAST
/** Warning: No caching */
export function parseProgram<T extends CompileOptions>(source: string, options?: T):
T extends { comptime: true } ? Promise<CivetAST> : CivetAST
export function generate(ast: CivetAST, options?: GenerateOptions): string
export const lib: {
gatherRecursive(ast: CivetAST, predicate: (node: CivetAST) => boolean): CivetAST[]
gatherRecursiveAll(ast: CivetAST, predicate: (node: CivetAST) => boolean): CivetAST[]
}
const Civet: {
version: string
compile: typeof compile
isCompileError: typeof isCompileError
parse: typeof parse
generate: typeof generate
SourceMap: typeof SourceMap
ParseError: typeof ParseError
ParseErrors: typeof ParseErrors
sourcemap: {
locationTable(input: string): number[]
lookupLineColumn(table: number[], pos: number): [number, number]
SourceMap: typeof SourceMap
}
}
export default Civet;
}
declare module "@danielx/civet/esbuild-plugin" {
import { Plugin } from "esbuild"
interface Options {
filter?: RegExp
inlineMap?: boolean
js?: boolean
next?: unknown
}
const plugin: ((options: Options) => Plugin) & Plugin
export default plugin
}
declare module "@danielx/civet/config" {
export function findInDir(dirPath: string): Promise<string | undefined>
export function findConfig(path: string): Promise<string | null>
export function loadConfig(
path: string
): Promise<import("@danielx/civet").CompileOptions>
export default {
findInDir,
findConfig,
loadConfig,
}
}