@@ -211,6 +211,10 @@ module.exports.defineVisitor = function create(
211211 defaultOptions
212212 )
213213 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> } */
214218 const offsets = new Map ( )
215219 const ignoreTokens = new Set ( )
216220
@@ -227,7 +231,7 @@ module.exports.defineVisitor = function create(
227231 }
228232 if ( Array . isArray ( token ) ) {
229233 for ( const t of token ) {
230- if ( t === baseToken ) continue
234+ if ( ! t || t === baseToken ) continue
231235 offsets . set ( t , {
232236 baseToken,
233237 offset,
@@ -260,10 +264,16 @@ module.exports.defineVisitor = function create(
260264 return
261265 }
262266
263- setOffset ( token , offsetData . offset , offsetData . baseToken )
267+ setOffset (
268+ token ,
269+ offsetData . offset ,
270+ /** @type {Token } */ ( offsetData . baseToken )
271+ )
264272 if ( offsetData . baseline ) {
265273 setBaseline ( token )
266274 }
275+ const o = /** @type {OffsetData } */ ( offsets . get ( token ) )
276+ o . expectedIndent = offsetData . expectedIndent
267277 }
268278
269279 /**
@@ -722,7 +732,7 @@ module.exports.defineVisitor = function create(
722732 * Validate the given token with the pre-calculated expected indentation.
723733 * @param {Token } token The token to validate.
724734 * @param {number } expectedIndent The expected indentation.
725- * @param {number[ ] } [optionalExpectedIndents] The optional expected indentation.
735+ * @param {[number, number? ] } [optionalExpectedIndents] The optional expected indentation.
726736 * @returns {void }
727737 */
728738 function validateCore ( token , expectedIndent , optionalExpectedIndents ) {
@@ -786,8 +796,8 @@ module.exports.defineVisitor = function create(
786796 * Get the expected indent of comments.
787797 * @param {Token } nextToken The next token of comments.
788798 * @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? ] }
791801 */
792802 function getCommentExpectedIndents (
793803 nextToken ,
@@ -873,8 +883,8 @@ module.exports.defineVisitor = function create(
873883 baseline . add ( token )
874884 } else if ( baseline . has ( offsetInfo . baseToken ) ) {
875885 // 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 )
878888 ) . expectedIndent
879889 baseline . add ( token )
880890 } else {
0 commit comments