import ts from "typescript" ; import * as utils from "tsutils" ; import { NodeWrap } from "tsutils" ; const IGNORE_TEXT = "// @ts-ignore FIXME" ; function findParentJSX ( n ) { if ( n ) { const kind = n . kind as number ; if ( kind >= 260 && kind <= 270 ) { return [ kind , n ] ; } return findParentJSX ( n . parent ) ; } return null ; } function getLine ( diagnostic , position ? ) { const { line } = diagnostic ! . file ! . getLineAndCharacterOfPosition ( position || diagnostic . start ! ) ; return line ; } export default function insertIgnore ( diagnostic , codeSplitByLine , includeJSX ) { const convertedAST = utils . convertAst ( diagnostic . file ! ) ; const n = utils . getWrappedNodeAtPosition ( convertedAST . wrapped , diagnostic . start ! ) ; const line = getLine ( diagnostic ) ; const isInJSX = findParentJSX ( n ) ; if ( isInJSX && ! includeJSX ) { return codeSplitByLine ; } codeSplitByLine . splice ( line , 0 , IGNORE_TEXT ) ; return codeSplitByLine ; }