@@ -42,7 +42,8 @@ var visitorKeys__namespace = /*#__PURE__*/_interopNamespace(visitorKeys);
42
42
/**
43
43
* @local
44
44
* @typedef {import('acorn') } acorn
45
- * @typedef {import('../lib/espree').EnhancedTokTypes } EnhancedTokTypes
45
+ * @typedef {import('./espree').EnhancedTokTypes } EnhancedTokTypes
46
+ * @typedef {import('../espree').ecmaVersion } ecmaVersion
46
47
*/
47
48
48
49
// ----------------------------------------------------------------------------
@@ -75,23 +76,21 @@ var visitorKeys__namespace = /*#__PURE__*/_interopNamespace(visitorKeys);
75
76
* }} BaseEsprimaToken
76
77
*
77
78
* @typedef {{
78
- * type: string;
79
- * } & BaseEsprimaToken } EsprimaToken
80
- *
81
- * @typedef {{
82
- * type: string | acorn.TokenType;
83
- * } & BaseEsprimaToken } EsprimaTokenFlexible
84
- *
85
- * @typedef {{
86
79
* jsxAttrValueToken: boolean;
87
- * ecmaVersion: acorn. ecmaVersion;
80
+ * ecmaVersion: ecmaVersion;
88
81
* }} ExtraNoTokens
89
82
*
90
83
* @typedef {{
91
- * tokens: EsprimaTokenFlexible []
84
+ * tokens: EsprimaToken []
92
85
* } & ExtraNoTokens } Extra
93
86
*/
94
87
88
+ /**
89
+ * @typedef {{
90
+ * type: string;
91
+ * } & BaseEsprimaToken } EsprimaToken
92
+ */
93
+
95
94
//------------------------------------------------------------------------------
96
95
// Requirements
97
96
//------------------------------------------------------------------------------
@@ -179,7 +178,7 @@ class TokenTranslator {
179
178
}
180
179
181
180
/**
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
183
182
* inaccurate due to how templates are handled differently in Esprima and
184
183
* Acorn, but should be accurate for all other tokens.
185
184
* @param {acorn.Token } token The Acorn token to translate.
@@ -364,6 +363,7 @@ class TokenTranslator {
364
363
/**
365
364
* @local
366
365
* @typedef {import('../espree').ParserOptions } ParserOptions
366
+ * @typedef {import('../espree').ecmaVersion } ecmaVersion
367
367
*/
368
368
369
369
// ----------------------------------------------------------------------------
@@ -372,7 +372,7 @@ class TokenTranslator {
372
372
/**
373
373
* @local
374
374
* @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 ,
376
376
* sourceType: "script"|"module",
377
377
* range?: boolean,
378
378
* loc?: boolean,
@@ -385,7 +385,7 @@ class TokenTranslator {
385
385
* ranges: boolean,
386
386
* locations: boolean,
387
387
* allowReturnOutsideFunction: boolean,
388
- * tokens?: boolean | null ,
388
+ * tokens?: boolean,
389
389
* comment?: boolean
390
390
* }} NormalizedParserOptions
391
391
*/
@@ -541,18 +541,16 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
541
541
* @local
542
542
* @typedef {import('acorn') } acorn
543
543
* @typedef {typeof import('acorn-jsx').tokTypes } tokTypesType
544
- * @typedef {typeof import('acorn-jsx').AcornJsxParser } AcornJsxParser
544
+ * @typedef {import('acorn-jsx').AcornJsxParser } AcornJsxParser
545
545
* @typedef {import('../espree').ParserOptions } ParserOptions
546
+ * @typedef {import('../espree').ecmaVersion } ecmaVersion
546
547
*/
547
548
548
549
// ----------------------------------------------------------------------------
549
550
// Local types
550
551
// ----------------------------------------------------------------------------
551
552
/**
552
553
* @local
553
- *
554
- * @typedef {acorn.ecmaVersion } ecmaVersion
555
- *
556
554
* @typedef {{
557
555
* generator?: boolean
558
556
* } & acorn.Node } EsprimaNode
@@ -564,12 +562,6 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
564
562
*/
565
563
566
564
/**
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
- *
573
565
* @typedef {{
574
566
* type: string,
575
567
* value: string,
@@ -581,10 +573,16 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
581
573
* end: acorn.Position | undefined
582
574
* }
583
575
* }} 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
584
584
*
585
- * @typedef {{
586
- * comments?: EsprimaComment[]
587
- * } & acorn.Token[] } EspreeTokens
585
+ * @typedef {import('../espree').EspreeTokens } EspreeTokens
588
586
*
589
587
* @typedef {{
590
588
* tail?: boolean
@@ -611,7 +609,7 @@ const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
611
609
* @typedef {{
612
610
* sourceType?: "script"|"module"|"commonjs";
613
611
* comments?: EsprimaComment[];
614
- * tokens?: acorn.Token[] ;
612
+ * tokens?: EspreeTokens ;
615
613
* body: acorn.Node[];
616
614
* } & acorn.Node } EsprimaProgramNode
617
615
*/
@@ -1112,10 +1110,15 @@ const parsers = {
1112
1110
*/
1113
1111
get regular ( ) {
1114
1112
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 (
1116
1117
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
+ ) ;
1119
1122
}
1120
1123
return this . _regular ;
1121
1124
} ,
@@ -1126,11 +1129,17 @@ const parsers = {
1126
1129
*/
1127
1130
get jsx ( ) {
1128
1131
if ( this . _jsx === null ) {
1129
- const espreeParserFactory = espree ( ) ;
1132
+ const espreeParserFactory = /** @type { unknown } */ ( espree ( ) ) ;
1130
1133
const jsxFactory = jsx__default [ "default" ] ( ) ;
1131
1134
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
+ ) ;
1134
1143
}
1135
1144
return this . _jsx ;
1136
1145
} ,
@@ -1159,7 +1168,7 @@ const parsers = {
1159
1168
* Tokenizes the given code.
1160
1169
* @param {string } code The code to tokenize.
1161
1170
* @param {ParserOptions } options Options defining how to tokenize.
1162
- * @returns {acorn.Token[]|null } An array of tokens.
1171
+ * @returns {EspreeTokens } An array of tokens.
1163
1172
* @throws {EnhancedSyntaxError } If the input code is invalid.
1164
1173
* @private
1165
1174
*/
@@ -1171,7 +1180,7 @@ function tokenize(code, options) {
1171
1180
options = Object . assign ( { } , options , { tokens : true } ) ; // eslint-disable-line no-param-reassign
1172
1181
}
1173
1182
1174
- return new Parser ( options , code ) . tokenize ( ) ;
1183
+ return /** @type { EspreeTokens } */ ( new Parser ( options , code ) . tokenize ( ) ) ;
1175
1184
}
1176
1185
1177
1186
//------------------------------------------------------------------------------
0 commit comments