Skip to content

Commit 855af29

Browse files
committed
refactor: move notes on types out of typedef blocks
1 parent 41e0dd0 commit 855af29

File tree

10 files changed

+1368
-3
lines changed

10 files changed

+1368
-3
lines changed

dist/espree.cjs

Lines changed: 1237 additions & 0 deletions
Large diffs are not rendered by default.

dist/espree.cjs.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/espree.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Tokenizes the given code.
3+
* @param {string} code The code to tokenize.
4+
* @param {ParserOptions} options Options defining how to tokenize.
5+
* @returns {import('acorn').Token[] | null} An array of tokens.
6+
* @throws {import('./lib/espree').EnhancedSyntaxError} If the input code is invalid.
7+
* @private
8+
*/
9+
export function tokenize(code: string, options: ParserOptions): import('acorn').Token[] | null;
10+
/**
11+
* Parses the given code.
12+
* @param {string} code The code to tokenize.
13+
* @param {ParserOptions} options Options defining how to tokenize.
14+
* @returns {import('acorn').Node} The "Program" AST node.
15+
* @throws {import('./lib/espree').EnhancedSyntaxError} If the input code is invalid.
16+
*/
17+
export function parse(code: string, options: ParserOptions): import('acorn').Node;
18+
export const version: "main";
19+
export const VisitorKeys: visitorKeys.VisitorKeys;
20+
export const Syntax: {
21+
[x: string]: string;
22+
};
23+
export const latestEcmaVersion: number;
24+
export const supportedEcmaVersions: number[];
25+
export type ParserOptions = {
26+
allowReserved?: boolean;
27+
ecmaVersion?: import('acorn').ecmaVersion;
28+
sourceType?: "script" | "module" | "commonjs";
29+
ecmaFeatures?: {
30+
jsx?: boolean;
31+
globalReturn?: boolean;
32+
impliedStrict?: boolean;
33+
};
34+
range?: boolean;
35+
loc?: boolean;
36+
tokens?: boolean | null;
37+
comment?: boolean;
38+
};
39+
import * as visitorKeys from "eslint-visitor-keys";
40+
import jsx from "acorn-jsx";
41+
//# sourceMappingURL=espree.d.ts.map

dist/espree.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/espree.d.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
declare function _default(): (Parser: typeof import('acorn-jsx').AcornJsxParser) => typeof EspreeParser;
2+
export default _default;
3+
export class EspreeParser extends acorn.Parser {
4+
/**
5+
* Adapted parser for Espree.
6+
* @param {import('../espree').ParserOptions | null} opts Espree options
7+
* @param {string | object} code The source code
8+
*/
9+
constructor(opts: import('../espree').ParserOptions | null, code: string | object);
10+
/**
11+
* Returns Espree tokens.
12+
* @returns {{comments?: {type: string; value: string; range?: [number, number]; start?: number; end?: number; loc?: {start: import('acorn').Position | undefined; end: import('acorn').Position | undefined}}[]} & import('acorn').Token[] | null} Espree tokens
13+
*/
14+
tokenize(): {
15+
comments?: {
16+
type: string;
17+
value: string;
18+
range?: [number, number];
19+
start?: number;
20+
end?: number;
21+
loc?: {
22+
start: import('acorn').Position | undefined;
23+
end: import('acorn').Position | undefined;
24+
};
25+
}[];
26+
} & import('acorn').Token[] | null;
27+
/**
28+
* Parses.
29+
* @returns {{sourceType?: "script" | "module" | "commonjs"; comments?: {type: string; value: string; range?: [number, number]; start?: number; end?: number; loc?: {start: import('acorn').Position | undefined; end: import('acorn').Position | undefined}}[]; tokens?: import('acorn').Token[]; body: import('acorn').Node[]} & import('acorn').Node} The program Node
30+
*/
31+
parse(): {
32+
sourceType?: "script" | "module" | "commonjs";
33+
comments?: {
34+
type: string;
35+
value: string;
36+
range?: [number, number];
37+
start?: number;
38+
end?: number;
39+
loc?: {
40+
start: import('acorn').Position | undefined;
41+
end: import('acorn').Position | undefined;
42+
};
43+
}[];
44+
tokens?: import('acorn').Token[];
45+
body: import('acorn').Node[];
46+
} & import('acorn').Node;
47+
/**
48+
* Overwrites the default raise method to throw Esprima-style errors.
49+
* @param {number} pos The position of the error.
50+
* @param {string} message The error message.
51+
* @throws {EnhancedSyntaxError} A syntax error.
52+
* @returns {void}
53+
*/
54+
raiseRecoverable(pos: number, message: string): void;
55+
/**
56+
* Esprima-FB represents JSX strings as tokens called "JSXText", but Acorn-JSX
57+
* uses regular tt.string without any distinction between this and regular JS
58+
* strings. As such, we intercept an attempt to read a JSX string and set a flag
59+
* on extra so that when tokens are converted, the next token will be switched
60+
* to JSXText via onToken.
61+
* @param {number} quote A character code
62+
* @returns {void}
63+
*/
64+
jsx_readString(quote: number): void;
65+
}
66+
export type EnhancedSyntaxError = {
67+
index?: number;
68+
lineNumber?: number;
69+
column?: number;
70+
} & SyntaxError;
71+
export type EnhancedTokTypes = {
72+
jsxAttrValueToken?: import('acorn').TokenType;
73+
} & typeof import('acorn-jsx').tokTypes;
74+
import * as acorn from "acorn";
75+
//# sourceMappingURL=espree.d.ts.map

dist/lib/espree.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/token-translator.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

espree.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
* `ecmaFeatures`, `range`, `loc`, `tokens` are not in `acorn.Options`
7373
*
7474
* `comment` is not in `acorn.Options` and doesn't err without it, but is used
75+
*/
76+
/**
7577
* @typedef {{
7678
* allowReserved?: boolean,
7779
* ecmaVersion?: acorn.ecmaVersion,

lib/espree.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
1515
* column?: number;
1616
* } & SyntaxError} EnhancedSyntaxError
1717
*/
18+
19+
// We add `jsxAttrValueToken` ourselves.
1820
/**
19-
* We add `jsxAttrValueToken` ourselves.
2021
* @typedef {{
2122
* jsxAttrValueToken?: acorn.TokenType;
2223
* } & tokTypesType} EnhancedTokTypes
@@ -50,9 +51,12 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
5051
* @local
5152
* @typedef {number} int
5253
*/
54+
55+
/**
56+
* First three properties as in `acorn.Comment`; next two as in `acorn.Comment`
57+
* but optional. Last is different as has to allow `undefined`
58+
*/
5359
/**
54-
* First three properties as in `acorn.Comment`; next two as in `acorn.Comment`
55-
* but optional. Last is different as has to allow `undefined`
5660
* @local
5761
*
5862
* @typedef {{

lib/token-translator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
* `loc` and `range` are from `acorn.Token`
3030
*
3131
* Adds `regex`.
32+
*/
33+
/**
3234
* @local
3335
*
3436
* @typedef {{

0 commit comments

Comments
 (0)