Skip to content

Create and expose an expression transpiler #4169

@weswigham

Description

@weswigham

As a library consumer, I would like to be able to call an API method which takes a file location and a TS string and returns a JS string.

And by that I mean a function which given an execution context and a TS string, gives equivalent JS for that location (like transpile, but context aware).

This is useful for watch expressions and console debugging, and without something like this, it is difficult/impossible to account for all the renaming the TS compiler does in such expressions (super, this, arguments, default parameters, probably more).

So, an example.
With project file foo.ts:

class A {
    foo(): string {
        return 'A';
    }
}

class B extends A {
    foo(): string {
/*marker*/      return 'B';
    }
}

calling

ts.transpileExpression(/*marker file location*/, 'super.foo()')

should yield the string

'_super.prototype.foo.call(this);'

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions