{"record":{"id":"edde3919a1cecb4a","repo":"microsoft/TypeScript","slug":"syntax-error-in-absolutebasepath-output-diag","errorCode":null,"errorMessage":"Syntax error in ${absoluteBasePath}: ${output.diagnostics![0].messageText}","messagePattern":"Syntax error in (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/harness/fourslashImpl.ts","lineNumber":4680,"sourceCode":"\r\nexport function runFourSlashTest(basePath: string, testType: FourSlashTestType, fileName: string, serverLogBaseliner?: FourSlashServerLogBaseliner): void {\r\n    const content = Harness.IO.readFile(fileName)!;\r\n    runFourSlashTestContent(basePath, testType, content, fileName, serverLogBaseliner);\r\n}\r\n\r\nexport function runFourSlashTestContent(basePath: string, testType: FourSlashTestType, content: string, fileName: string, serverLogBaseliner?: FourSlashServerLogBaseliner): void {\r\n    // Give file paths an absolute path for the virtual file system\r\n    const absoluteBasePath = ts.combinePaths(Harness.virtualFileSystemRoot, basePath);\r\n    const absoluteFileName = ts.combinePaths(Harness.virtualFileSystemRoot, fileName);\r\n\r\n    // Parse out the files and their metadata\r\n    const testData = parseTestData(absoluteBasePath, content, absoluteFileName);\r\n    const state = new TestState(absoluteFileName, absoluteBasePath, testType, testData);\r\n    if (serverLogBaseliner) serverLogBaseliner.baseline = () => state.baselineTsserverLog();\r\n    const actualFileName = Harness.IO.resolvePath(fileName) || absoluteFileName;\r\n    const output = ts.transpileModule(content, { reportDiagnostics: true, fileName: actualFileName, compilerOptions: { target: ts.ScriptTarget.ES2015, inlineSourceMap: true, inlineSources: true } });\r\n    if (output.diagnostics!.length > 0) {\r\n        throw new Error(`Syntax error in ${absoluteBasePath}: ${output.diagnostics![0].messageText}`);\r\n    }\r\n    runCode(output.outputText, state, actualFileName);\r\n    state.baselineTest();\r\n}\r\n\r\nfunction runCode(code: string, state: TestState, fileName: string): void {\r\n    // Compile and execute the test\r\n    const generatedFile = ts.changeExtension(fileName, \".js\");\r\n    const wrappedCode = `(function(ts, test, goTo, config, verify, edit, debug, format, cancellation, classification, completion, verifyOperationIsCancelled, ignoreInterpolations) {${code}\\n//# sourceURL=${ts.getBaseFileName(generatedFile)}\\n})`;\r\n\r\n    // Provide the content of the current test to 'source-map-support' so that it can give us the correct source positions\r\n    // for test failures.\r\n    sourceMapSupport.install({\r\n        retrieveFile: path => {\r\n            return path === generatedFile ? wrappedCode :\r\n                undefined!;\r\n        },\r\n    });\r","sourceCodeStart":4662,"sourceCodeEnd":4698,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/harness/fourslashImpl.ts#L4662-L4698","documentation":"Thrown by runFourSlashTestContent when transpiling the fourslash test body (the generated code inside the wrapper) reports one or more diagnostics. The harness transpiles the raw test file content with inlineSourceMap before executing it, and surfaces the first diagnostic's messageText with the file path. This catches syntax/type errors in the test's TypeScript code, not in the code under test.","triggerScenarios":"A fourslash test file contains invalid TypeScript in the inline executable portion (the lines that call verify.*, goTo.*, etc.), so ts.transpileModule with reportDiagnostics:true yields a non-empty diagnostics array.","commonSituations":"Test author writes invalid JS/TS in the test body (unbalanced braces, bad assertion syntax), edits the file outside the //// blocks but inside the executable section, or the test was generated incorrectly. The error points at the test file, not the compiler.","solutions":["Open the test file at the path shown and fix the syntax error described by messageText.","Run tsc --noEmit on the test file in isolation to get fuller diagnostics with line numbers.","If the error mentions a specific token or unexpected character, check for stray markers (e.g. unclosed /* */ or [| |]) leaking into executable code."],"exampleFix":"// before — missing closing paren in test body\nverify.completions().hasDocumentation;\n// after\nverify.completions().hasDocumentation();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// The throw happens deep in runFourSlashTestContent; catch at the runner boundary\n// and re-surface the underlying transpile diagnostic with a file path.\ntry {\n    runFourSlashTestContent(basePath, testType, content, fileName);\n} catch (e) {\n    // e.message already contains the first diagnostic messageText; log full path.\n    throw new Error(`Fourslash test failed to transpile: ${(e as Error).message}`);\n}","preventionTips":["Lint fourslash test files with tsc --noEmit before running them.","Keep executable test statements simple and review them after editing marker/range syntax."],"tags":["fourslash","test-syntax","transpile-error"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}