How to throw a syntax error in a typescript transform?

Viewed 155

I'm using ttypescript to hook my custom transform into the compiler, which works just fine. I've identified a situation in which I need to throw a compile error (syntax error) along the same channels and in the same format that typescript does.

How do I do this?

1 Answers

Looks like I can just use console.error and I have to format it correctly. I actually had a different problem that was hiding the fact that this worked.

For reference the code I use for the formatting is this:


    logError(node: ts.Node, error: string): undefined {
        if (!node || !node.getSourceFile()) {
            console.error("How did this happen?");
            return;
        }
        var source = ts.isSourceFile(node) ? node : node.getSourceFile();
        var pos = source.getLineAndCharacterOfPosition(node.pos);
        console.error(`${source.fileName}(${pos.line},${pos.character}):`, error);
        return;
    }
Related