{"version":3,"sources":["../../src/utils/typescript.ts"],"sourcesContent":["import type ts from \"typescript\";\n\nimport { TSModule } from \"./programs.js\";\n\nexport function getLanguageServiceHost(\n\tprogram: ts.Program,\n\ttsModule: TSModule,\n): ts.LanguageServiceHost {\n\treturn {\n\t\tgetCompilationSettings: () => program.getCompilerOptions(),\n\t\tgetCurrentDirectory: () => program.getCurrentDirectory(),\n\t\tgetDefaultLibFileName: (options) => tsModule.getDefaultLibFilePath(options),\n\t\tgetScriptFileNames: () =>\n\t\t\tprogram.getSourceFiles().map((sourceFile) => sourceFile.fileName),\n\t\tgetScriptSnapshot: (name) =>\n\t\t\ttsModule.ScriptSnapshot.fromString(\n\t\t\t\tprogram.getSourceFile(name)?.text ?? \"\",\n\t\t\t),\n\t\tgetScriptVersion: () => \"1\",\n\t\t// NB: We can't check `program` for files, it won't contain valid files like package.json\n\t\t/* eslint-disable @typescript-eslint/unbound-method */\n\t\tdirectoryExists: tsModule.sys.directoryExists,\n\t\tfileExists: tsModule.sys.fileExists,\n\t\tgetDirectories: tsModule.sys.getDirectories,\n\t\treadDirectory: tsModule.sys.readDirectory,\n\t\treadFile: tsModule.sys.readFile,\n\t\t/* eslint-enable @typescript-eslint/unbound-method */\n\t};\n}\n\nexport function getNodeForExpectType(\n\tnode: ts.Node,\n\ttsModule: TSModule,\n): ts.Node {\n\tif (tsModule.isVariableStatement(node)) {\n\t\tconst {\n\t\t\tdeclarationList: { declarations },\n\t\t} = node;\n\t\tif (declarations.length === 1) {\n\t\t\tconst { initializer } = declarations[0];\n\t\t\tif (initializer) {\n\t\t\t\treturn initializer;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn node;\n}\n\nexport function matchModuloWhitespace(\n\tactual: string,\n\texpected: string,\n): boolean {\n\t// TODO: it's much easier to normalize actual based on the displayParts\n\t//       This isn't 100% correct if a type has a space in it, e.g. type T = \"string literal\"\n\tconst normActual = actual.replace(/[\\n\\r ]+/g, \" \").trim();\n\tconst normExpected = expected.replace(/[\\n\\r ]+/g, \" \").trim();\n\treturn normActual === normExpected;\n}\n"],"mappings":";AAIO,SAAS,uBACf,SACA,UACyB;AACzB,SAAO;AAAA,IACN,wBAAwB,MAAM,QAAQ,mBAAmB;AAAA,IACzD,qBAAqB,MAAM,QAAQ,oBAAoB;AAAA,IACvD,uBAAuB,CAAC,YAAY,SAAS,sBAAsB,OAAO;AAAA,IAC1E,oBAAoB,MACnB,QAAQ,eAAe,EAAE,IAAI,CAAC,eAAe,WAAW,QAAQ;AAAA,IACjE,mBAAmB,CAAC,SACnB,SAAS,eAAe;AAAA,MACvB,QAAQ,cAAc,IAAI,GAAG,QAAQ;AAAA,IACtC;AAAA,IACD,kBAAkB,MAAM;AAAA;AAAA;AAAA,IAGxB,iBAAiB,SAAS,IAAI;AAAA,IAC9B,YAAY,SAAS,IAAI;AAAA,IACzB,gBAAgB,SAAS,IAAI;AAAA,IAC7B,eAAe,SAAS,IAAI;AAAA,IAC5B,UAAU,SAAS,IAAI;AAAA;AAAA,EAExB;AACD;AAEO,SAAS,qBACf,MACA,UACU;AACV,MAAI,SAAS,oBAAoB,IAAI,GAAG;AACvC,UAAM;AAAA,MACL,iBAAiB,EAAE,aAAa;AAAA,IACjC,IAAI;AACJ,QAAI,aAAa,WAAW,GAAG;AAC9B,YAAM,EAAE,YAAY,IAAI,aAAa,CAAC;AACtC,UAAI,aAAa;AAChB,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;AAEO,SAAS,sBACf,QACA,UACU;AAGV,QAAM,aAAa,OAAO,QAAQ,aAAa,GAAG,EAAE,KAAK;AACzD,QAAM,eAAe,SAAS,QAAQ,aAAa,GAAG,EAAE,KAAK;AAC7D,SAAO,eAAe;AACvB;","names":[]}