Skip to content

Commit

Permalink
refactor: move notes on types out of typedef blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed May 5, 2022
1 parent 41e0dd0 commit 855af29
Show file tree
Hide file tree
Showing 10 changed files with 1,368 additions and 3 deletions.
1,237 changes: 1,237 additions & 0 deletions dist/espree.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/espree.cjs.map

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions dist/espree.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Tokenizes the given code.
* @param {string} code The code to tokenize.
* @param {ParserOptions} options Options defining how to tokenize.
* @returns {import('acorn').Token[] | null} An array of tokens.
* @throws {import('./lib/espree').EnhancedSyntaxError} If the input code is invalid.
* @private
*/
export function tokenize(code: string, options: ParserOptions): import('acorn').Token[] | null;
/**
* Parses the given code.
* @param {string} code The code to tokenize.
* @param {ParserOptions} options Options defining how to tokenize.
* @returns {import('acorn').Node} The "Program" AST node.
* @throws {import('./lib/espree').EnhancedSyntaxError} If the input code is invalid.
*/
export function parse(code: string, options: ParserOptions): import('acorn').Node;
export const version: "main";
export const VisitorKeys: visitorKeys.VisitorKeys;
export const Syntax: {
[x: string]: string;
};
export const latestEcmaVersion: number;
export const supportedEcmaVersions: number[];
export type ParserOptions = {
allowReserved?: boolean;
ecmaVersion?: import('acorn').ecmaVersion;
sourceType?: "script" | "module" | "commonjs";
ecmaFeatures?: {
jsx?: boolean;
globalReturn?: boolean;
impliedStrict?: boolean;
};
range?: boolean;
loc?: boolean;
tokens?: boolean | null;
comment?: boolean;
};
import * as visitorKeys from "eslint-visitor-keys";
import jsx from "acorn-jsx";
//# sourceMappingURL=espree.d.ts.map
1 change: 1 addition & 0 deletions dist/espree.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions dist/lib/espree.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
declare function _default(): (Parser: typeof import('acorn-jsx').AcornJsxParser) => typeof EspreeParser;
export default _default;
export class EspreeParser extends acorn.Parser {
/**
* Adapted parser for Espree.
* @param {import('../espree').ParserOptions | null} opts Espree options
* @param {string | object} code The source code
*/
constructor(opts: import('../espree').ParserOptions | null, code: string | object);
/**
* Returns Espree tokens.
* @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
*/
tokenize(): {
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;
/**
* Parses.
* @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
*/
parse(): {
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;
/**
* Overwrites the default raise method to throw Esprima-style errors.
* @param {number} pos The position of the error.
* @param {string} message The error message.
* @throws {EnhancedSyntaxError} A syntax error.
* @returns {void}
*/
raiseRecoverable(pos: number, message: string): void;
/**
* Esprima-FB represents JSX strings as tokens called "JSXText", but Acorn-JSX
* uses regular tt.string without any distinction between this and regular JS
* strings. As such, we intercept an attempt to read a JSX string and set a flag
* on extra so that when tokens are converted, the next token will be switched
* to JSXText via onToken.
* @param {number} quote A character code
* @returns {void}
*/
jsx_readString(quote: number): void;
}
export type EnhancedSyntaxError = {
index?: number;
lineNumber?: number;
column?: number;
} & SyntaxError;
export type EnhancedTokTypes = {
jsxAttrValueToken?: import('acorn').TokenType;
} & typeof import('acorn-jsx').tokTypes;
import * as acorn from "acorn";
//# sourceMappingURL=espree.d.ts.map
1 change: 1 addition & 0 deletions dist/lib/espree.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/lib/token-translator.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
* `ecmaFeatures`, `range`, `loc`, `tokens` are not in `acorn.Options`
*
* `comment` is not in `acorn.Options` and doesn't err without it, but is used
*/
/**
* @typedef {{
* allowReserved?: boolean,
* ecmaVersion?: acorn.ecmaVersion,
Expand Down
10 changes: 7 additions & 3 deletions lib/espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
* column?: number;
* } & SyntaxError} EnhancedSyntaxError
*/

// We add `jsxAttrValueToken` ourselves.
/**
* We add `jsxAttrValueToken` ourselves.
* @typedef {{
* jsxAttrValueToken?: acorn.TokenType;
* } & tokTypesType} EnhancedTokTypes
Expand Down Expand Up @@ -50,9 +51,12 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
* @local
* @typedef {number} int
*/

/**
* First three properties as in `acorn.Comment`; next two as in `acorn.Comment`
* but optional. Last is different as has to allow `undefined`
*/
/**
* First three properties as in `acorn.Comment`; next two as in `acorn.Comment`
* but optional. Last is different as has to allow `undefined`
* @local
*
* @typedef {{
Expand Down
2 changes: 2 additions & 0 deletions lib/token-translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* `loc` and `range` are from `acorn.Token`
*
* Adds `regex`.
*/
/**
* @local
*
* @typedef {{
Expand Down

0 comments on commit 855af29

Please sign in to comment.