@@ -1193,6 +1193,35 @@ let needsPrecedingSemicolon;
11931193 "WithStatement" ,
11941194 ] ) ;
11951195
1196+ const TS_TYPE_NODE_TYPES = new Set ( [
1197+ "TSAsExpression" ,
1198+ "TSSatisfiesExpression" ,
1199+ "TSTypeAliasDeclaration" ,
1200+ "TSTypeAnnotation" ,
1201+ ] ) ;
1202+
1203+ /**
1204+ * Determines whether a specified node is inside a TypeScript type context.
1205+ * @param {ASTNode } node The node to check.
1206+ * @returns {boolean } Whether the node is inside a TypeScript type context.
1207+ */
1208+ function isInType ( node ) {
1209+ for ( let currNode = node ; ; ) {
1210+ const { parent } = currNode ;
1211+ if ( ! parent ) {
1212+ break ;
1213+ }
1214+ if (
1215+ TS_TYPE_NODE_TYPES . has ( parent . type ) &&
1216+ currNode === parent . typeAnnotation
1217+ ) {
1218+ return true ;
1219+ }
1220+ currNode = parent ;
1221+ }
1222+ return false ;
1223+ }
1224+
11961225 needsPrecedingSemicolon = function ( sourceCode , node ) {
11971226 const prevToken = sourceCode . getTokenBefore ( node ) ;
11981227
@@ -1206,6 +1235,16 @@ let needsPrecedingSemicolon;
12061235
12071236 const prevNode = sourceCode . getNodeByRangeIndex ( prevToken . range [ 0 ] ) ;
12081237
1238+ if (
1239+ prevNode . type === "TSDeclareFunction" ||
1240+ prevNode . parent . type === "TSImportEqualsDeclaration" ||
1241+ prevNode . parent . parent ?. type === "TSImportEqualsDeclaration" ||
1242+ TS_TYPE_NODE_TYPES . has ( prevNode . type ) ||
1243+ isInType ( prevNode )
1244+ ) {
1245+ return false ;
1246+ }
1247+
12091248 if ( isClosingParenToken ( prevToken ) ) {
12101249 return ! STATEMENTS . has ( prevNode . type ) ;
12111250 }
@@ -1222,6 +1261,12 @@ let needsPrecedingSemicolon;
12221261 }
12231262
12241263 if ( IDENTIFIER_OR_KEYWORD . has ( prevToken . type ) ) {
1264+ if (
1265+ prevNode . parent . type === "VariableDeclarator" &&
1266+ ! prevNode . parent . init
1267+ ) {
1268+ return false ;
1269+ }
12251270 if ( BREAK_OR_CONTINUE . has ( prevNode . parent . type ) ) {
12261271 return false ;
12271272 }
0 commit comments