@@ -211,6 +211,10 @@ module.exports.defineVisitor = function create(
211
211
defaultOptions
212
212
)
213
213
const sourceCode = context . getSourceCode ( )
214
+ /**
215
+ * @typedef { { baseToken: Token | null, offset: number, baseline: boolean, expectedIndent: number | undefined } } OffsetData
216
+ */
217
+ /** @type {Map<Token|null, OffsetData> } */
214
218
const offsets = new Map ( )
215
219
const ignoreTokens = new Set ( )
216
220
@@ -227,7 +231,7 @@ module.exports.defineVisitor = function create(
227
231
}
228
232
if ( Array . isArray ( token ) ) {
229
233
for ( const t of token ) {
230
- if ( t === baseToken ) continue
234
+ if ( ! t || t === baseToken ) continue
231
235
offsets . set ( t , {
232
236
baseToken,
233
237
offset,
@@ -260,10 +264,16 @@ module.exports.defineVisitor = function create(
260
264
return
261
265
}
262
266
263
- setOffset ( token , offsetData . offset , offsetData . baseToken )
267
+ setOffset (
268
+ token ,
269
+ offsetData . offset ,
270
+ /** @type {Token } */ ( offsetData . baseToken )
271
+ )
264
272
if ( offsetData . baseline ) {
265
273
setBaseline ( token )
266
274
}
275
+ const o = /** @type {OffsetData } */ ( offsets . get ( token ) )
276
+ o . expectedIndent = offsetData . expectedIndent
267
277
}
268
278
269
279
/**
@@ -722,7 +732,7 @@ module.exports.defineVisitor = function create(
722
732
* Validate the given token with the pre-calculated expected indentation.
723
733
* @param {Token } token The token to validate.
724
734
* @param {number } expectedIndent The expected indentation.
725
- * @param {number[ ] } [optionalExpectedIndents] The optional expected indentation.
735
+ * @param {[number, number? ] } [optionalExpectedIndents] The optional expected indentation.
726
736
* @returns {void }
727
737
*/
728
738
function validateCore ( token , expectedIndent , optionalExpectedIndents ) {
@@ -786,8 +796,8 @@ module.exports.defineVisitor = function create(
786
796
* Get the expected indent of comments.
787
797
* @param {Token } nextToken The next token of comments.
788
798
* @param {number } nextExpectedIndent The expected indent of the next token.
789
- * @param {number } lastExpectedIndent The expected indent of the last token.
790
- * @returns {number[ ] }
799
+ * @param {number|undefined } lastExpectedIndent The expected indent of the last token.
800
+ * @returns {[number, number? ] }
791
801
*/
792
802
function getCommentExpectedIndents (
793
803
nextToken ,
@@ -873,8 +883,8 @@ module.exports.defineVisitor = function create(
873
883
baseline . add ( token )
874
884
} else if ( baseline . has ( offsetInfo . baseToken ) ) {
875
885
// The base token is a baseline token on this line, so inherit it.
876
- offsetInfo . expectedIndent = offsets . get (
877
- offsetInfo . baseToken
886
+ offsetInfo . expectedIndent = /** @type { OffsetData } */ (
887
+ offsets . get ( offsetInfo . baseToken )
878
888
) . expectedIndent
879
889
baseline . add ( token )
880
890
} else {
0 commit comments