-
Notifications
You must be signed in to change notification settings - Fork 0
/
coffeescript.d.ts
796 lines (768 loc) · 28.8 KB
/
coffeescript.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
import * as Babel from "@babel/core";
/**
* List of precompiled CoffeeScript file extensions.
*/
export let FILE_EXTENSIONS: [".coffee", ".coffee.md", ".litcoffee"];
/**
* Version number of the CoffeeScript compiler.
*/
export let VERSION: string;
/**
* Helpers used internally to compile CoffeeScript code.
*/
export interface helpers {
/**
* Polyfill for `Array.prototype.some` used pre-transpilation in the compiler.
* Determines whether the specified callback function returns true for any
* element of an array.
*
* @param fn Predicate function test for each array element.
* @returns Whether one or more elements return `true` when passed to
* the predicate `fn(...)`.
*/
some:
| typeof Array.prototype.some
| ((this: any[], predicate: (value: any) => unknown) => boolean);
/**
* Peek at the start of a given string to see if it matches a sequence.
*
* @param string Target string to check the prefix literal against.
* @param literal Literal string to use for the prefix check.
* @param start Zero-indexed starting position of the prefix.
* The offset preceding the first character of the string is `0`.
* @returns Whether the `literal` prefix is found in `string`
* at the provided `start` position.
*/
starts(string: string, literal: string, start: number): boolean;
/**
* Peek at the end of a given string to see if it matches a sequence.
*
* @param string Target string to check the suffix literal against.
* @param literal Literal string to use for the suffix check.
* @param [back=0] Zero-indexed backtracking position of the prefix.
* The offset following the last character of the string is `0`.
* @returns Whether the `literal` suffix is found in `string`
* at the backtracking position or end of the string.
*/
ends(string: string, literal: string, back?: number): boolean;
/**
* Repeat a string `n` times.
* Uses a clever algorithm to have O(log(n)) string concatenation operations.
*
* @param str String to repeat.
* @param n 1-indexed number of repetitions.
* @returns Repeated string.
*/
repeat(str: string, n: number): string;
/**
* Trim out all falsy values from an array.
*
* @param array Array of boolean-operator indeterminate values.
* @returns Array of truthy values.
*/
compact(array: any[]): any[];
/**
* Count the number of occurrences of a search string in another string.
*
* @param string Target string to search.
* @param substring Search string to compute against target.
* @returns Number of times the search string appears in the
* target string.
*/
count(string: string, substr: string): number;
/**
* Merge objects, returning a fresh copy with attributes from both sides.
* Used every time `CoffeeScript.compile` is called, to allow properties in the
* options hash to propagate down the tree without polluting other branches.
*
* @param options Original, target object for merge operation.
* @param overrides Map of override key-values for merge operation.
* @returns Cloned object that merges `options` with `overrides`. The
* `overrides` properties have a higher merge priority than `options` properties.
*/
merge(options: object, overrides: object): object;
/**
* Extend a source object with the properties of another object (shallow copy).
*
* @param object Target object to extend.
* @param properties Source object to extend the source object.
* @returns The original `object` extended by the `properties` object.
*/
extend(object: object, properties: object): object;
/**
* Flattens an array recursively.
* Handy for getting a list of descendants from the nodes.
*
* @param array Array containing array and non-array elements.
* @returns A flattened version of the array with an array depth of `0`.
*/
flatten(array: any[]): any[];
/**
* Delete a key from an object, returning the value. Useful when a node is
* looking for a particular method in an options hash.
*
* @param obj Object to delete a key from.
* @param key Target key of object for the deletion operation.
* @returns The value of the deleted object entry.
*/
del(obj: object, key: any): any;
/**
* Helper function for extracting code from Literate CoffeeScript by stripping
* out all non-code blocks, producing a string of CoffeeScript code that can
* be compiled "normally."
*
* @param code Literate CoffeeScript code to extract code blocks from.
* @returns CoffeeScript code without surrounding Markdown documentation.
*/
invertLiterate(code: string): string;
/**
* Build a list of all comments attached to tokens.
*
* @param tokens Collection of CoffeeScript abstract
* syntax tree tokens, all sorted by source order.
* @returns List of comment strings present in CoffeeScript AST.
*/
extractAllCommentTokens(tokens: ASTNode[]): string[];
/**
* Build a dictionary of token comments organized by tokens’ locations
* used as lookup hashes.
*
* Though multiple tokens can have the same location hash, using exclusive
* location data allows to distinguish between zero-length generated tokens and
* actual source tokens, for example.
*
* The ranges for "overlapping" tokens with the same location data and
* and matching token hashes are merged into one array.
*
* If there are duplicate comments, they will get sorted out later.
*
* @param tokens List of CoffeeScript abstract syntax
* tree tokens with or without comments.
* @returns Hashmap of token comments vs token location offsets.
*/
buildTokenDataDictionary(tokens: ASTNode[]): object;
/**
* Generates a setter function that updates the location data of an object
* if it is a CoffeeScript abstract syntax tree node.
*
* @param parserState CoffeeScript parser state.
* @param firstLocationData Location data for first node.
* @param firstValue Abstract syntax tree for first node.
* @param lastLocationData Location data for last node.
* @param lastValue Abstract syntax tree for first node.
* @param [forceUpdateLocation=true] Whether to override the location data of the
* container and child nodes if the container has location data already.
*/
addDataToNode(
parserState: object,
firstLocationData: LocationData,
firstValue: ASTNode,
lastLocationData: LocationData,
lastValue: ASTNode,
forceUpdateLocation?: boolean,
): (obj: any) => any;
/**
* Attaches a set of comments to the supplied node.
*
* @param comments Collection of comment strings.
* @param node Node associated with `comments`.
* @returns The `node` merged with the `comments` array.
*/
attachCommentsToNode(comments: string[], node: ASTNode): any;
/**
* Convert JISON location data to a string.
*
* @param obj Token or `CoffeeScriptASTLocationData` object.
* @returns String representation of location data.
*/
locationDataToString(obj: LocationData | ASTNode): string;
/**
* A `.coffee.md` compatible version of `path.basename`.
*
* @param file File name path. Can be relative, absolute or missing a directory.
* @param [stripExt=false] Whether to strip the file extension in the output.
* @param [useWinPathSep=false] Whether to use the Windows path separator `\`
* as well as the Unix path separator `/`.
* @returns File name without extension.
*/
baseFileName(file: string, stripExt?: boolean, useWinPathSep?: any): string;
/**
* Determine if a filename represents a CoffeeScript file.
* A CoffeeScript file has the file extensions `.coffee`, `.coffee.md` or
* `.litcoffee`.
*
* @param file Filename without directories.
* @returns Whether a filename is a CoffeeScript file.
*/
isCoffee(file: string): boolean;
/**
* Determine if a filename represents a Literate CoffeeScript file.
* A Literate CoffeeScript file has the file extensions `.litcoffee`,
* or `.coffee.md`.
*
* @param file Filename without directories.
* @returns Whether a filename is a CoffeeScript file.
*/
isLiterate(file: string): boolean;
/**
* Throws a `CoffeeScriptSyntaxError` from a given location.
* The error's `toString` will return an error message following the "standard"
* format `<filename>:<line>:<col>: <message>` plus the line with the error and a
* marker showing where the error is.
*
* Instead of showing the compiler's stacktrace, show our custom error message
* (this is useful when the error bubbles up in Node.js applications that
* compile CoffeeScript for example).
*
* @throws Error object with location data and string
* representation.
*/
throwSyntaxError(message: any, location: any): never;
/**
* Update a compiler `SyntaxError` with source code information if it didn't have
* it already.
*
* @param error Syntax error with or without source code
* information.
* @param code Source code that produced the syntax error.
* @param filename File name for invalid CoffeeScript resource.
* @returns Syntax error with source code.
*/
updateSyntaxError(error: any, code: string, filename: string): any;
/**
* Maps a whitespace character to a character name.
*
* @param Single-character string.
* @returns Human-readable identifier for whitespace character, or the
* `string` parameter.
*/
nameWhitespaceCharacter(string: any): string;
/**
* Parses a CoffeeScript number string to a primitive JS number.
*
* @param string String representation of a number.
* @returns Parsed float or integer corresponding to number.
*/
parseNumber(string: string): number;
/**
* Checks if a value is a function.
*
* @param obj JavaScript value to check.
* @returns True if `obj` is a function.
*/
isFunction(obj: any): boolean;
/**
* Checks if a value is a number.
*
* @param obj JavaScript value to check.
* @returns True if `obj` is a number.
*/
isNumber(obj: any): boolean;
/**
* Checks if an value is a string.
*
* @param obj JavaScript value to check.
* @returns True if `obj` is a string.
*/
isString(obj: any): boolean;
/**
* Checks if an value is a primitive boolean or `Boolean` instance.
*
* @param obj JavaScript value to check.
* @returns True if `obj` is a boolean.
*/
isBoolean(obj: any): boolean;
/**
* Checks if an value is a literal JS object - `{}`.
*
* @param obj JavaScript value to check.
* @returns True if `obj` is a literal JS object.
*/
isPlainObject(obj: any): boolean;
/**
* Replace `\u{...}` with `\uxxxx[\uxxxx]` in regexes without the `u` flag.
*
* @param str String that may contain Unicode brace syntax - `\u{...}`.
* @param options Options for Unicode replacement.
* @param [options.delimiter]
* Separator between two Unicode characters in `str` parameter of
* `coffeescript.helpers.replaceUnicodeCodePointEscapes`.
* @param [options.error=unicode code point escapes greater than \\u{10ffff} are not allowed]
* Error message if `coffeescript.helpers.replaceUnicodeCodePointEscapes` fails.
* @param [options.flags]
* Which flags are present in the regular expression for the replacement operation.
* Must include `u` if provided to support Unicode escapes.
* @returns RegExp string with Unicode brace groups in the format `\uxxxx[\uxxxx]`.
*/
replaceUnicodeCodePointEscapes(str: string, options?: ReplaceUnicodeCodePointEscapesOptions): string;
}
/**
* Transpiles CoffeeScript to legacy, high-compatibility ECMAScript versions using Babel.
*
* @param code CoffeeScript code to be compiled.
* @param options CoffeeScript compiler options.
* @param options.ast If true, output an abstract syntax tree of the input CoffeeScript source code.
* @param options.bare If true, omit a top-level IIFE safety wrapper.
* @param options.filename File name to compile.
* @param options.header If true, output the `Generated by CoffeeScript` header.
* @param options.inlineMap If true, output the source map as a base64-encoded string in a comment at the bottom.
* @param options.sourceMap If true, output a source map object with the code.
* @param options.transpile Babel transpilation options - see `Babel.TransformOptions`.
* @returns Babel transpiler result for file.
*/
export function transpile(code: string, options?: Options): Babel.BabelFileResult;
/**
* Compiles CoffeeScript to JavaScript code, then outputs it as a string.
*
* @param code CoffeeScript code to be compiled.
* @param options CoffeeScript compiler options.
* @param options.ast If true, output an abstract syntax tree of the input CoffeeScript source code.
* @param options.bare If true, omit a top-level IIFE safety wrapper.
* @param options.filename File name to compile.
* @param options.header If true, output the `Generated by CoffeeScript` header.
* @param options.inlineMap If true, output the source map as a base64-encoded string in a comment at the bottom.
* @param options.sourceMap If true, output a source map object with the code.
* @param options.transpile Babel transpilation options - see `Babel.TransformOptions`.
* @returns Compiled and unevaluated JavaScript code if `options.sourceMap` is falsy and/or `undefined`.
* If `options.sourceMap` is `true`, this returns a `{js, v3SourceMap, sourceMap}` object, where `sourceMap` is a
* `SourceMap` object handy for doing programmatic lookups.
*/
export function compile(code: string, options: SourceMapOptions): CodeWithSourceMap;
export function compile(code: string, options?: Options): string;
/**
* Parse a string of CoffeeScript code or an array of lexed tokens, and return the AST. You can then compile it by
* calling `.compile()` on the root, or traverse it by using `.traverseChildren()` with a callback.
*
* @param code CoffeeScript code to be compiled.
* @param options CoffeeScript compiler options.
* @param options.ast If true, output an abstract syntax tree of the input CoffeeScript source code.
* @param options.bare If true, omit a top-level IIFE safety wrapper.
* @param options.filename File name to compile.
* @param options.header If true, output the `Generated by CoffeeScript` header.
* @param options.inlineMap If true, output the source map as a base64-encoded string in a comment
* at the bottom.
* @param options.sourceMap If true, output a source map object with the code.
* @param options.transpile Babel transpilation options - see `Babel.TransformOptions`.
* @returns Compiled and unevaluated JavaScript code.
*/
export function nodes(code: string, options?: Options): ASTBody;
/**
* Compiles and executes a CoffeeScript string in the NodeJS environment.
* Evaluates `__filename` and `__dirname` correctly in order to execute the CoffeeScript input.
*
* @param code CoffeeScript code to be compiled.
* @param options CoffeeScript compiler options.
* @param options.ast If true, output an abstract syntax tree of the input CoffeeScript source code.
* @param options.bare If true, omit a top-level IIFE safety wrapper.
* @param options.filename File name to compile.
* @param options.header If true, output the `Generated by CoffeeScript` header.
* @param options.inlineMap If true, output the source map as a base64-encoded string in a comment at the bottom.
* @param options.sourceMap If true, output a source map object with the code.
* @param options.transpile Babel transpilation options - see `Babel.TransformOptions`.
* @returns Output of evaluated CoffeeScript code in the NodeJS environment.
*/
export function run(code: string, options?: Options): any;
/**
* Compiles and executes a CoffeeScript string in a NodeJS-like browser environment.
* The CoffeeScript REPL uses this to run the input.
*
* @param code CoffeeScript code to be compiled.
* @param options CoffeeScript compiler options.
* @param options.ast If true, output an abstract syntax tree of the input CoffeeScript source code.
* @param options.bare If true, omit a top-level IIFE safety wrapper.
* @param options.filename File name to compile.
* @param options.header If true, output the `Generated by CoffeeScript` header.
* @param options.inlineMap If true, output the source map as a Base64-encoded string in a comment at the bottom.
* @param options.sourceMap If true, output a source map object with the code.
* @param options.transpile Babel transpilation options - see `Babel.TransformOptions`.
* @returns Output of compiled CoffeeScript code.
*/
export interface eval {
(code: string, options?: Options): any;
} // hack to avoid TS eval call protection
/**
* Node's module loader, patched to be able to handle multi-dot extensions.
* This is a horrible thing that should not be required.
*/
export function register(): {
[path: string]: object;
(path: string): object;
};
/**
* Synchronous module definitions for the CoffeeScript library files.
*
* @param path Path to CoffeeScript library submodule relative to the `./lib/coffeescript` directory.
* @returns CoffeeScript library submodule.
*/
export interface require {
[path: string]: object;
(path: string): require[keyof require];
}
/**
* Compiles a raw CoffeeScript file buffer string.
* Requires UTF-8 character encoding on the `raw` input string.
* Strip the Unicode byte order mark, if `filename` begins with one.
*
* @param raw Raw UTF-8 CoffeeScript file contents.
* @param filename File name with extension (not including
* directories).
* @param options CoffeeScript compiler
* options.
* @param options.ast If true, output an abstract syntax
* tree of the input CoffeeScript source code.
* @param options.bare If true, omit a top-level IIFE safety
* wrapper.
* @param options.filename File name to compile.
* @param options.header If true, output the `Generated by CoffeeScript` header.
* @param options.inlineMap If true, output the source map as a Base64-encoded string in a comment at the bottom.
* @param options.sourceMap If true, output a source map object with the code.
*/
export function _compileRawFileContent(raw: string, filename: string, options?: Options): string;
/**
* Reads and compiles a CoffeeScript file using `fs.readFileSync`.
* NodeJS wrapper around `coffeescript._compileRawFileContent`.
* Files are decoded as if they are UTF-8 character encoded or compliant with UTF-8.
*
* @param raw Raw UTF-8 CoffeeScript file contents.
* @param filename File name with extension (not including directories).
* @param options CoffeeScript compiler options.
* @param options.ast If true, output an abstract syntax tree
* of the input CoffeeScript source code.
* @param options.bare If true, omit a top-level IIFE safety
* wrapper.
* @param options.filename File name to compile.
* @param options.header If true, output the `Generated by
* CoffeeScript` header.
* @param options.inlineMap If true, output the source map as
* a Base64-encoded string in a comment at the bottom.
* @param options.sourceMap If true, output a source map
* object with the code.
*/
export function _compileFile(filename: string, options?: Options): string;
/**
* CoffeeScript compiler options.
*/
export interface Options {
/**
* If true, output an abstract syntax tree of the input CoffeeScript source code.
*/
ast?: boolean;
/**
* If true, omit a top-level IIFE safety wrapper.
*/
bare?: boolean;
/**
* File name to compile - defaults to `index.js`.
*/
filename?: string;
/**
* If true, output the `Generated by CoffeeScript` header.
*/
header?: boolean;
/**
* If true, output the source map as a base64-encoded string in a comment at the bottom.
*/
inlineMap?: boolean;
/**
* If true, output a source map object with the code.
*/
sourceMap?: boolean;
/**
* Babel transpilation options - see `Babel.TransformOptions`.
*/
transpile?: Babel.TransformOptions;
}
/**
* CoffeeScript compiler options for source map output.
* Type for compiler options when `sourceMap` is `true`.
*/
export interface SourceMapOptions {
/**
* If true, output an abstract syntax tree of the input CoffeeScript source code.
*/
ast?: boolean;
/**
* If true, omit a top-level IIFE safety wrapper.
*/
bare?: boolean;
/**
* File name to compile - defaults to `index.js`.
*/
filename?: string;
/**
* If true, output the `Generated by CoffeeScript` header.
*/
header?: boolean;
/**
* If true, output the source map as a base64-encoded string in a comment at the bottom.
*/
inlineMap?: boolean;
/**
* Output a source map object with the code.
*/
sourceMap: true;
/**
* Babel transpilation options - see `Babel.TransformOptions`.
*/
transpile?: Babel.TransformOptions;
}
/**
* Source location array.
*/
export type SourceLocation = [
/** Zero-indexed line number. */
number,
/** Zero-indexed column number. */
number,
];
/**
* Mozilla V3 raw source map.
*/
export interface RawSourceMap {
/** The generated filename this source map is associated with (optional). */
file: string;
/** A string of base64 VLQs which contain the actual mappings. */
mappings: string;
/** An array of identifiers which can be referenced by individual mappings. */
names: string[];
/** The URL root from which all sources are relative (optional). */
sourceRoot?: string;
/** An array of URLs to the original source files. */
sources: string[];
/** An array of contents of the original source files (optional). */
sourcesContent?: string[];
/** Which version of the source map spec this map is following. */
version: number;
}
/**
* Tracker object for line and column positions for a single line.
* Used to implement the `SourceMap` class.
*/
export interface LineMap {
columns: Array<{
column: number;
line: number;
sourceColumn: number;
sourceLine: number;
}>;
line: number;
/**
* Add source location data to line map.
*
* @param column Zero-indexed column number.
* @param source Source line and column to insert into map.
* @param options Column insertion options,
* @param options.noReplace If `true`, column replacement is allowed.
* @returns Added source location data.
*/
add: (column: number, source: SourceLocation, options?: { noReplace: boolean }) => SourceLocation | undefined;
/**
* Fetch source location data for a specific column.
*
* @param column Zero-indexed column number.
* @returns `[sourceLine, sourceColumn]` if it exists in line map.
*/
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
sourceLocation: (column: number) => SourceLocation | void;
}
/**
* Maps locations.
*/
export interface SourceMap {
lines: LineMap[];
/**
* Adds a mapping to the source map.
*
* @param sourceLocation Zero-indexed source location.
* @param generatedLocation Source line and column to insert into map.
* @param [options={}] Column insertion options.
* @param [options.noReplace] If `true`, column replacement is allowed.
* @returns Added source location data.
*/
add: (
sourceLocation: SourceLocation,
generatedLocation: SourceLocation,
options?: { noReplace: boolean },
) => ReturnType<LineMap["add"]>;
/**
* Fetch source location data for a specific column.
*
* @param column Zero-indexed column number.
* @returns `[sourceLine, sourceColumn]` if it exists in line map.
*/
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
sourceLocation: (column: number) => SourceLocation | void;
/**
* Generates a V3 source map, returning the generated JSON as a string.
*
* @param [options={}] Column insertion options
* @param [options.generatedFile] Property `generatedFile` in source map.
* @param [options.sourceFiles] Property `sources` in source map.
* @param [options.sourceRoot] Property `sourceRoot` in source map.
* @returns Added source location data.
*/
generate: (column: number, source: SourceLocation, options?: { noReplace: boolean }) => string;
/**
* VLQ encoding in reverse byte order.
*
* @param value Base-64 encoded value.
* @returns Reversed VLQ-encoded value.
* @throws "Cannot Base64 encode value: ${value}"
*/
encodeVlq: (value: string) => string;
/**
* Base-64 encoding for byte number.
*
* @param value Byte number in ASCII.
* @returns Base-64 encoded value or undefined.
* @throws "Cannot Base64 encode value: ${value}"
*/
encodeBase64: (value: string) => string;
}
/**
* Output of `CoffeeScript.compile` when `options.sourceMap` is `true`.
* Emitted as an object in the form `{js, v3SourceMap, sourceMap}`.
*/
export interface CodeWithSourceMap {
js: string;
sourceMap: SourceMap;
v3SourceMap: ReturnType<SourceMap["generate"]>;
}
/**
* Acorn.js parser location data object.
*/
export interface AcornLocationData {
end: number;
loc: {
end: {
line: number;
column: number;
};
start: {
line: number;
column: number;
};
};
range: LineMap;
start: number;
}
/**
* Jison parser location data object.
*/
export interface JisonLocationData {
first_column: number;
first_line: number;
last_line: number;
last_column: number;
}
/**
* CoffeeScript abstract syntax tree location data.
*/
export type LocationData = AcornLocationData | JisonLocationData;
/**
* Range data interface for CoffeeScript abstract syntax tree nodes.
*/
export interface ASTNodeRange {
from: ASTNode | null;
to: ASTNode | null;
exclusive: boolean;
equals: string;
locationData: LocationData;
}
/**
* CoffeeScript's abstract syntax tree node interfaces with all possible node properties.
*/
export interface ASTNode {
array?: boolean | ASTNode;
asKey?: boolean;
args?: ASTNode[];
base?: ASTNode;
body?: ASTBody | ASTNode;
bound?: boolean;
boundFuncs?: ASTNode[];
cases?: ASTNode[][];
classBody?: boolean;
comments?: string[];
condition?: ASTNode;
context?: string;
elseBody?: ASTNode | null;
expression?: ASTNode;
expressions?: ASTNode[];
first?: ASTNode;
flip?: boolean;
generated?: boolean;
guard?: ASTNode;
index?: ASTNode;
isChain?: boolean;
isGenerator?: boolean;
isNew?: boolean;
isSuper?: boolean;
locationData: LocationData;
name?: ASTNode;
negated?: boolean;
object?: boolean | ASTNode;
objects?: ASTNode[];
operator?: string;
otherwise?: ASTNode;
own?: boolean;
param?: boolean;
params?: ASTNode[];
parent?: ASTNode | null;
pattern?: boolean;
properties?: ASTNode[];
range?: boolean | ASTNodeRange[];
returns?: boolean;
subject?: ASTNode;
second?: ASTNode;
soak?: boolean;
source?: ASTNode;
subpattern?: boolean;
this?: boolean;
val?: string;
value?: ASTNode | string;
variable?: ASTNode;
}
/**
* Container interface for CoffeeScript abstract syntax trees.
*/
export interface ASTBody {
classBody?: boolean;
expressions: ASTNode[] | [];
locationData: LocationData;
}
/**
* Syntax error thrown by CoffeeScript compiler.
*/
export interface SyntaxError {
/** Source code that generated the `coffee` compiler error */
code?: string;
/** File name for invalid CoffeeScript resource. */
filename?: string;
/** Starting and ending location data. */
location: LocationData;
/** String representation of syntax error. */
stack: ReturnType<SyntaxError["toString"]>;
/** Stack trace generator for error. */
toString: () => string;
}
/**
* Options for `coffeescript.helpers.replaceUnicodeCodePointEscapes`.
*/
export interface ReplaceUnicodeCodePointEscapesOptions {
/**
* Separator between two Unicode characters in `str` parameter of
* `coffeescript.helpers.replaceUnicodeCodePointEscapes`.
*/
error?: string;
/**
* Error message if `coffeescript.helpers.replaceUnicodeCodePointEscapes` fails.
* Default: `unicode code point escapes greater than \\u{10ffff} are not allowed`.
*/
flags?: string;
/**
* Which flags are present in the regular expression for the replacement operation.
* Must include `u` if provided to support Unicode escapes.
*/
delimiter?: string;
}
export {};