microsoft/TypeScript · error · Error

Syntax error in ${absoluteBasePath}: ${output.diagnostics![0

Error message

Syntax error in ${absoluteBasePath}: ${output.diagnostics![0].messageText}

What it means

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.

Source

Thrown at src/harness/fourslashImpl.ts:4680

export function runFourSlashTest(basePath: string, testType: FourSlashTestType, fileName: string, serverLogBaseliner?: FourSlashServerLogBaseliner): void {
    const content = Harness.IO.readFile(fileName)!;
    runFourSlashTestContent(basePath, testType, content, fileName, serverLogBaseliner);
}

export function runFourSlashTestContent(basePath: string, testType: FourSlashTestType, content: string, fileName: string, serverLogBaseliner?: FourSlashServerLogBaseliner): void {
    // Give file paths an absolute path for the virtual file system
    const absoluteBasePath = ts.combinePaths(Harness.virtualFileSystemRoot, basePath);
    const absoluteFileName = ts.combinePaths(Harness.virtualFileSystemRoot, fileName);

    // Parse out the files and their metadata
    const testData = parseTestData(absoluteBasePath, content, absoluteFileName);
    const state = new TestState(absoluteFileName, absoluteBasePath, testType, testData);
    if (serverLogBaseliner) serverLogBaseliner.baseline = () => state.baselineTsserverLog();
    const actualFileName = Harness.IO.resolvePath(fileName) || absoluteFileName;
    const output = ts.transpileModule(content, { reportDiagnostics: true, fileName: actualFileName, compilerOptions: { target: ts.ScriptTarget.ES2015, inlineSourceMap: true, inlineSources: true } });
    if (output.diagnostics!.length > 0) {
        throw new Error(`Syntax error in ${absoluteBasePath}: ${output.diagnostics![0].messageText}`);
    }
    runCode(output.outputText, state, actualFileName);
    state.baselineTest();
}

function runCode(code: string, state: TestState, fileName: string): void {
    // Compile and execute the test
    const generatedFile = ts.changeExtension(fileName, ".js");
    const wrappedCode = `(function(ts, test, goTo, config, verify, edit, debug, format, cancellation, classification, completion, verifyOperationIsCancelled, ignoreInterpolations) {${code}\n//# sourceURL=${ts.getBaseFileName(generatedFile)}\n})`;

    // Provide the content of the current test to 'source-map-support' so that it can give us the correct source positions
    // for test failures.
    sourceMapSupport.install({
        retrieveFile: path => {
            return path === generatedFile ? wrappedCode :
                undefined!;
        },
    });

View on GitHub (pinned to b465fdbfe1)

Solutions

  1. Open the test file at the path shown and fix the syntax error described by messageText.
  2. Run tsc --noEmit on the test file in isolation to get fuller diagnostics with line numbers.
  3. If the error mentions a specific token or unexpected character, check for stray markers (e.g. unclosed /* */ or [| |]) leaking into executable code.

Example fix

// before — missing closing paren in test body
verify.completions().hasDocumentation;
// after
verify.completions().hasDocumentation();
Defensive patterns

Strategy: try-catch

Try / catch

// The throw happens deep in runFourSlashTestContent; catch at the runner boundary
// and re-surface the underlying transpile diagnostic with a file path.
try {
    runFourSlashTestContent(basePath, testType, content, fileName);
} catch (e) {
    // e.message already contains the first diagnostic messageText; log full path.
    throw new Error(`Fourslash test failed to transpile: ${(e as Error).message}`);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12). Data as JSON: /api/errors/edde3919a1cecb4a. Report an issue: GitHub.