1
+ import SourceMap , { V3SourceMap } from './sourcemap' ;
2
+ import { Token , LexerOptions } from './lexer' ;
3
+ import { Block } from './nodes' ;
4
+
5
+ export const VERSION : string ;
6
+ export const FILE_EXTENSIONS : Array < string > ;
7
+
8
+ interface CompileOptions {
9
+ header ?: boolean ;
10
+ shiftLine ?: boolean ;
11
+
12
+ // Source map options.
13
+ sourceMap ?: boolean ;
14
+ generatedFile ?: string ;
15
+ sourceRoot ?: string ;
16
+ sourceFiles ?: Array < string > ;
17
+ inline ?: boolean ;
18
+ }
19
+
20
+ type CompileResult = string | {
21
+ js : string ,
22
+ sourceMap : SourceMap ,
23
+ v3SourceMap : V3SourceMap ,
24
+ } ;
25
+
26
+ interface RunOptions extends CompileOptions {
27
+ filename ?: string ;
28
+ }
29
+
30
+ /**
31
+ * Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
32
+ *
33
+ * If `options.sourceMap` is specified, then `options.filename` must also be specified. All
34
+ * options that can be passed to `SourceMap#generate` may also be passed here.
35
+ *
36
+ * This returns a javascript string, unless `options.sourceMap` is passed,
37
+ * in which case this returns a `{js, v3SourceMap, sourceMap}`
38
+ * object, where sourceMap is a sourcemap.coffee#SourceMap object, handy for doing programatic
39
+ * lookups.
40
+ */
41
+ export function compile ( code : string , options ?: CompileOptions ) : CompileResult ;
42
+
43
+ /**
44
+ * Tokenize a string of CoffeeScript code, and return the array of tokens.
45
+ */
46
+ export function tokens ( code : string , options ?: LexerOptions ) : Array < Token > ;
47
+
48
+ /**
49
+ * Parse a string of CoffeeScript code or an array of lexed tokens, and
50
+ * return the AST. You can then compile it by calling `.compile()` on the root,
51
+ * or traverse it by using `.traverseChildren()` with a callback.
52
+ */
53
+ export function nodes ( source : string | Array < Token > , options ?: LexerOptions ) : Block ;
54
+
55
+ /**
56
+ * Compile and execute a string of CoffeeScript (on the server), correctly
57
+ * setting `__filename`, `__dirname`, and relative `require()`.
58
+ */
59
+ export function run ( code : string , options ?: RunOptions ) ;
0 commit comments