UNPKG

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