UNPKG

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