@@ -42,7 +42,8 @@ var visitorKeys__namespace = /*#__PURE__*/_interopNamespace(visitorKeys);
4242/**
4343 * @local
4444 * @typedef {import('acorn') } acorn
45- * @typedef {import('../lib/espree').EnhancedTokTypes } EnhancedTokTypes
45+ * @typedef {import('./espree').EnhancedTokTypes } EnhancedTokTypes
46+ * @typedef {import('../espree').ecmaVersion } ecmaVersion
4647 */
4748
4849// ----------------------------------------------------------------------------
@@ -75,23 +76,21 @@ var visitorKeys__namespace = /*#__PURE__*/_interopNamespace(visitorKeys);
7576 * }} BaseEsprimaToken
7677 *
7778 * @typedef {{
78- * type: string;
79- * } & BaseEsprimaToken } EsprimaToken
80- *
81- * @typedef {{
82- * type: string | acorn.TokenType;
83- * } & BaseEsprimaToken } EsprimaTokenFlexible
84- *
85- * @typedef {{
8679 * jsxAttrValueToken: boolean;
87- * ecmaVersion: acorn. ecmaVersion;
80+ * ecmaVersion: ecmaVersion;
8881 * }} ExtraNoTokens
8982 *
9083 * @typedef {{
91- * tokens: EsprimaTokenFlexible []
84+ * tokens: EsprimaToken []
9285 * } & ExtraNoTokens } Extra
9386 */
9487
88+ /**
89+ * @typedef {{
90+ * type: string;
91+ * } & BaseEsprimaToken } EsprimaToken
92+ */
93+
9594//------------------------------------------------------------------------------
9695// Requirements
9796//------------------------------------------------------------------------------
@@ -179,7 +178,7 @@ class TokenTranslator {
179178 }
180179
181180 /**
182- * Translates a single Esprima token to a single Acorn token. This may be
181+ * Translates a single Acorn token to a single Esprima token. This may be
183182 * inaccurate due to how templates are handled differently in Esprima and
184183 * Acorn, but should be accurate for all other tokens.
185184 * @param {acorn.Token } token The Acorn token to translate.
@@ -364,6 +363,7 @@ class TokenTranslator {
364363/**
365364 * @local
366365 * @typedef {import('../espree').ParserOptions } ParserOptions
366+ * @typedef {import('../espree').ecmaVersion } ecmaVersion
367367 */
368368
369369// ----------------------------------------------------------------------------
@@ -372,7 +372,7 @@ class TokenTranslator {
372372/**
373373 * @local
374374 * @typedef {{
375- * ecmaVersion: 10 | 9 | 8 | 7 | 6 | 5 | 3 | 11 | 12 | 13 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | "latest" ,
375+ * ecmaVersion: ecmaVersion ,
376376 * sourceType: "script"|"module",
377377 * range?: boolean,
378378 * loc?: boolean,
@@ -385,7 +385,7 @@ class TokenTranslator {
385385 * ranges: boolean,
386386 * locations: boolean,
387387 * allowReturnOutsideFunction: boolean,
388- * tokens?: boolean | null ,
388+ * tokens?: boolean,
389389 * comment?: boolean
390390 * }} NormalizedParserOptions
391391 */
@@ -541,18 +541,16 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
541541 * @local
542542 * @typedef {import('acorn') } acorn
543543 * @typedef {typeof import('acorn-jsx').tokTypes } tokTypesType
544- * @typedef {typeof import('acorn-jsx').AcornJsxParser } AcornJsxParser
544+ * @typedef {import('acorn-jsx').AcornJsxParser } AcornJsxParser
545545 * @typedef {import('../espree').ParserOptions } ParserOptions
546+ * @typedef {import('../espree').ecmaVersion } ecmaVersion
546547 */
547548
548549// ----------------------------------------------------------------------------
549550// Local types
550551// ----------------------------------------------------------------------------
551552/**
552553 * @local
553- *
554- * @typedef {acorn.ecmaVersion } ecmaVersion
555- *
556554 * @typedef {{
557555 * generator?: boolean
558556 * } & acorn.Node } EsprimaNode
@@ -564,12 +562,6 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
564562 */
565563
566564/**
567- * First three properties as in `acorn.Comment`; next two as in `acorn.Comment`
568- * but optional. Last is different as has to allow `undefined`
569- */
570- /**
571- * @local
572- *
573565 * @typedef {{
574566 * type: string,
575567 * value: string,
@@ -581,10 +573,16 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
581573 * end: acorn.Position | undefined
582574 * }
583575 * }} EsprimaComment
576+ */
577+
578+ /**
579+ * First two properties as in `acorn.Comment`; next two as in `acorn.Comment`
580+ * but optional. Last is different as has to allow `undefined`
581+ */
582+ /**
583+ * @local
584584 *
585- * @typedef {{
586- * comments?: EsprimaComment[]
587- * } & acorn.Token[] } EspreeTokens
585+ * @typedef {import('../espree').EspreeTokens } EspreeTokens
588586 *
589587 * @typedef {{
590588 * tail?: boolean
@@ -611,7 +609,7 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
611609 * @typedef {{
612610 * sourceType?: "script"|"module"|"commonjs";
613611 * comments?: EsprimaComment[];
614- * tokens?: acorn.Token[] ;
612+ * tokens?: EspreeTokens ;
615613 * body: acorn.Node[];
616614 * } & acorn.Node } EsprimaProgramNode
617615 */
@@ -1112,10 +1110,15 @@ const parsers = {
11121110 */
11131111 get regular ( ) {
11141112 if ( this . _regular === null ) {
1115- const espreeParserFactory = espree ( ) ;
1113+ const espreeParserFactory = /** @type {unknown } */ ( espree ( ) ) ;
1114+
1115+ this . _regular = /** @type {IEspreeParser } */ (
1116+ acorn__namespace . Parser . extend (
11161117
1117- // Cast the `acorn.Parser` to our own for required properties not specified in *.d.ts
1118- this . _regular = espreeParserFactory ( /** @type {AcornJsxParser } */ ( acorn__namespace . Parser ) ) ;
1118+ /** @type {(BaseParser: typeof acorn.Parser) => typeof acorn.Parser } */
1119+ ( espreeParserFactory )
1120+ )
1121+ ) ;
11191122 }
11201123 return this . _regular ;
11211124 } ,
@@ -1126,11 +1129,17 @@ const parsers = {
11261129 */
11271130 get jsx ( ) {
11281131 if ( this . _jsx === null ) {
1129- const espreeParserFactory = espree ( ) ;
1132+ const espreeParserFactory = /** @type { unknown } */ ( espree ( ) ) ;
11301133 const jsxFactory = jsx__default [ "default" ] ( ) ;
11311134
1132- // Cast the `acorn.Parser` to our own for required properties not specified in *.d.ts
1133- this . _jsx = espreeParserFactory ( jsxFactory ( acorn__namespace . Parser ) ) ;
1135+ this . _jsx = /** @type {IEspreeParser } */ (
1136+ acorn__namespace . Parser . extend (
1137+ jsxFactory ,
1138+
1139+ /** @type {(BaseParser: typeof acorn.Parser) => typeof acorn.Parser } */
1140+ ( espreeParserFactory )
1141+ )
1142+ ) ;
11341143 }
11351144 return this . _jsx ;
11361145 } ,
@@ -1159,7 +1168,7 @@ const parsers = {
11591168 * Tokenizes the given code.
11601169 * @param {string } code The code to tokenize.
11611170 * @param {ParserOptions } options Options defining how to tokenize.
1162- * @returns {acorn.Token[]|null } An array of tokens.
1171+ * @returns {EspreeTokens } An array of tokens.
11631172 * @throws {EnhancedSyntaxError } If the input code is invalid.
11641173 * @private
11651174 */
@@ -1171,7 +1180,7 @@ function tokenize(code, options) {
11711180 options = Object . assign ( { } , options , { tokens : true } ) ; // eslint-disable-line no-param-reassign
11721181 }
11731182
1174- return new Parser ( options , code ) . tokenize ( ) ;
1183+ return /** @type { EspreeTokens } */ ( new Parser ( options , code ) . tokenize ( ) ) ;
11751184}
11761185
11771186//------------------------------------------------------------------------------
0 commit comments