Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create and expose an expression transpiler #4169

Closed
weswigham opened this issue Aug 5, 2015 · 3 comments
Closed

Create and expose an expression transpiler #4169

weswigham opened this issue Aug 5, 2015 · 3 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@weswigham
Copy link
Member

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);'
@RyanCavanaugh
Copy link
Member

Could someone reasonably write this with a wrapper using transpile and source maps? It's likely we'd have to do almost the entire amount of work as the entire file anyway, so the perf impact of running the whole file seems minimal.

@weswigham
Copy link
Member Author

@RyanCavanaugh Not... really? Certainly not easily. AFAIK it's relatively impossible to just text-edit expressions directly into some contexts (like if I wanted to execute an expression in the context of a parameter initializer). TBH what needs to happen is, once transforms is merged, calculate the transforms flags up to the desired execution context, then create a node tree for the input expression and transform it using those node flags and the active compiler options. (This is what @rbuckton had told me back when I has first asked for the feature.)

@RyanCavanaugh
Copy link
Member

Closing due to lack of other feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants