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

reuse TS code templates for ES6/ES7 #169

Closed
atsu85 opened this issue Jun 8, 2016 · 14 comments
Closed

reuse TS code templates for ES6/ES7 #169

atsu85 opened this issue Jun 8, 2016 · 14 comments

Comments

@atsu85
Copy link
Contributor

atsu85 commented Jun 8, 2016

@EisenbergEffect, I noticed, that code templates are duplicated for both TypeScript and ES6/ES7 versions of the generated source code.

I'm wondering, if it is worth writing both TypeScript and ES6/ES7 versions of each class. Ideally ES6/ES7 should be generated from TypeScript. I guess You have considered it? Probably TypeScript compiler can't be used to only strip the type annotations (that might be what is desired here) so probably some other tool could be used instead? TypeScript compiler removes type annotations, but additionally:

  • replaces decorators with __decorate(...)
  • replaces class declarations with class expressions (that is more verbose and may be harder to grasp)

What are Your thoughts?

@EisenbergEffect
Copy link
Contributor

Are you saying we should, during creating a new project, invoke the TS compiler to compile TS code into ES2015 in order to get the source code that we create into a Babel project?

@atsu85
Copy link
Contributor Author

atsu85 commented Jun 8, 2016

No, not when the developer is creating a new project, but when building aurelia-cli project. That is what I had in mind - makes more sense to me ;)

@EisenbergEffect
Copy link
Contributor

Ah. Interesting. I'll think about it. Currently there isn't a build process for the cli, which is kind of nice.

@EisenbergEffect
Copy link
Contributor

I think this is a good idea...however, I don't think it will work 100% since TS requires using a different import syntax with NodeJS than Babel does. Maybe Babel can support the same syntax though? If so, I would be interested in trying this out. It would be nice not to have to write and maintain two versions of everything. Would you be interested in investigating further and possibly sending a PR for the build task? @atsu85

@atsu85
Copy link
Contributor Author

atsu85 commented Jun 9, 2016

I think this is a good idea

I'm glad to hear it, did You consider reopening this issue?

Actually I'm surprised, that at this point where skeleton-typescript still uses js instead of ts for building, You are attempting to write gulp tasks also in TypeScript :)

however, I don't think it will work 100% since TS requires using a different import syntax with NodeJS than Babel does.
Maybe Babel can support the same syntax though?

Looks like Babel supports the same syntax (import * as ... from ...;) that You have used in TypeScript:

  1. https://babeljs.io/docs/learn-es2015/
  2. http://stackoverflow.com/a/31387018/4973640
    But I haven't tried it and unfortunately I'm not familiar with Babel.

I'm surprised (maybe based on my incomplete understanding of ES6 modules), that Babel even works with that syntax (with that module), because as I understand this line:
import changed from 'gulp-changed';
means that gulp-changed should have a default export, that is imported with alias changed (it could have named exports as well in addition to default).

So if gulp-changed typings would contain
export default changed;
instead of
export = changed;
then the "Babel way" would also work with TypeScript:
import changed from 'gulp-changed';

@EisenbergEffect
Copy link
Contributor

I think it makes it work for compatibility purposes...but perhaps the TS syntax is actually correct. I just need to try it out and see if switching the babel version to that works. If so, we can probably take the approach you recommend. I'll report back soon.

@EisenbergEffect EisenbergEffect self-assigned this Jun 9, 2016
@atsu85
Copy link
Contributor Author

atsu85 commented Jun 9, 2016

but perhaps the TS syntax is actually correct

So far it still seems to me, that this is standard ES6 module import syntax, and not specific to TS

@atsu85
Copy link
Contributor Author

atsu85 commented Jun 10, 2016

I don't know why i didn't think about it before, when i wrote

Probably TypeScript compiler can't be used to only strip the type annotations (that might be what is desired here) so probably some other tool could be used instead?

but probably "transform-flow-strip-types" Babel plugin would do just what is desired here (remove TypeScript type info, but leave everything else, like ES7 decorators and class declarations there). But I haven't tested it, so I might have guessed incorrectly ;)

@EisenbergEffect
Copy link
Contributor

Bingo! That's probably the best fit. I didn't think of it either :)

@AdamWillden
Copy link

AdamWillden commented Jul 9, 2016

Just in case - I don't know if this TS flag helps? microsoft/TypeScript#2901

Transpile using typescript to es2016 and use that flag?

@doktordirk
Copy link
Contributor

that removes extend and öhm decorators or something. would need to provide those helpers oneself

@atsu85
Copy link
Contributor Author

atsu85 commented Jul 9, 2016

I think that the correct flag is allowSyntheticDefaultImports. It worked for me with i18n related issue.

@Alexander-Taran
Copy link
Contributor

@jwx this one is for you (-:

@3cp
Copy link
Member

3cp commented Oct 7, 2020

Most ts/es6 template files are merged in current skeleton. Only those with too much differences are kept as two files.

@3cp 3cp closed this as completed Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants