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

TODO: Cannot have generic args on object field values in TypeScript #251

Closed
crazytoucan opened this issue Jun 15, 2018 · 2 comments
Closed
Assignees

Comments

@crazytoucan
Copy link

// src/foo.ts
export const Foo = {
    bar<T>() {
        return;
    }
};
$ sucrase src -d out --transforms typescript
src/foo.ts -> out/foo.js
Error: Error transforming src/foo.ts: TODO
    at tsStartParseObjPropValue (/Users/alexr/.config/yarn/global/node_modules/sucrase/dist/parser/plugins/typescript.js:1258:11)
    at parseObjPropValue (/Users/alexr/.config/yarn/global/node_modules/sucrase/dist/parser/traverser/expression.js:833:46)
    at parseObj (/Users/alexr/.config/yarn/global/node_modules/sucrase/dist/parser/traverser/expression.js:756:5)
    at parseExprAtom (/Users/alexr/.config/yarn/global/node_modules/sucrase/dist/parser/traverser/expression.js:487:7)
    at parseExprSubscripts (/Users/alexr/.config/yarn/global/node_modules/sucrase/dist/parser/traverser/expression.js:258:20)
    at parseMaybeUnary (/Users/alexr/.config/yarn/global/node_modules/sucrase/dist/parser/traverser/expression.js:244:20)
    at parseExprOps (/Users/alexr/.config/yarn/global/node_modules/sucrase/dist/parser/traverser/expression.js:184:20)
    at parseMaybeConditional (/Users/alexr/.config/yarn/global/node_modules/sucrase/dist/parser/traverser/expression.js:157:20)
    at baseParseMaybeAssign (/Users/alexr/.config/yarn/global/node_modules/sucrase/dist/parser/traverser/expression.js:141:20)
    at tsParseMaybeAssign (/Users/alexr/.config/yarn/global/node_modules/sucrase/dist/parser/plugins/typescript.js:1306:49)

Link: https://sucrase.io/#code=export%20const%20Foo%20%3D%20%7B%0A%20%20%20%20bar%3CT%3E()%20%7B%0A%20%20%20%20%20%20%20%20return%3B%0A%20%20%20%20%7D%0A%7D%3B%0A

Curiously, Sucrase behavior is compatible with your sample's Babel stack. ☺️

@crazytoucan
Copy link
Author

Current reasonable workaround is to transform that into an arrow function:

export const Foo = {
    bar: <T>() => {
        return;
    }
};

https://sucrase.io/#code=export%20const%20Foo%20%3D%20%7B%0A%20%20%20%20bar%3A%20%3CT%3E()%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20return%3B%0A%20%20%20%20%7D%0A%7D%3B%0A

@alangpierce
Copy link
Owner

Haha, yeah, Sucrase's parser is forked from Babel's, and that case also isn't implemented in Babel TS parsing. I'll look into how hard it would be to just implement, or it's possible it's been implemented recently in Babel and I just need to port the implementation.

alangpierce added a commit that referenced this issue Jun 26, 2018
Fixes #251

The Babel code had a TODO, but at least in our case, it seems as easy as
optionally calling the existing type parameter parsing code.
@alangpierce alangpierce self-assigned this Jun 26, 2018
alangpierce added a commit that referenced this issue Jun 26, 2018
Fixes #251

The Babel code had a TODO, but at least in our case, it seems as easy as
optionally calling the existing type parameter parsing code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants