-
Notifications
You must be signed in to change notification settings - Fork 459
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
Different TS-JEST / TS emitted code when importing 3rd party libs #213
Comments
@kulshekhar From what you explained, there is another transpilation happening... TS -> TS emitted code -> babel -> ES5 JS Since TypeScript can emit ES5 why would we need babel? |
When When it is set to false, only typescript is used. This was done recently in PR #172 That might be a good starting point to understand why this was done. (I could attempt an explanation but because I don't use babel or allowSyntheticDefaultImports, there's a chance I might miss something or state something incorrectly) |
@kulshekhar I understand the logic behind that PR, yet it solved one issue just to introduce an other. If I set |
@shlomiassaf there was a short discussion somewhere around whether we should use another setting to tell jest to use babel as well. Would such a setting solve this issue? edit: here's that conversation |
It seems to me it'd be a good idea, and then just default to true if (Might also be a good idea to at the same time move the TS_CONFIG into a seperate "ts-loader" key - it seems a little strange to keep it in globals. Would break backward compat though) |
@GeeWee when you say move TS_CONFIG into a separate "ts-loader" what exactly do you mean by this? Are you saying another JSON field in Jest? Or are you saying you would like to have more than one tsconfig file to point to? Also I agree with the |
Yeah another JSON field, like:
It seems a little silly having to expose |
While I agree about the TS_CONFIG bit, I'm a bit hesitant to introduce breaking changes. Adding a flag to control babel usage seems sensible though - with the default value (absence) leaving the behavior unchanged. So if this isn't set, ts-jest will process through babel if I'm not sure what the best way to name this flag would be though:
|
I totally agree with you about the breaking changes. Another point there is, where do you want the babel flag? I think |
|
Good idea about the breaking change issue #217 I agree. Oh so you're thinking to only check the flag if I get what you're saying, but as an outsider I was really surprised to learn that ts-loader used babel if |
Yes, because currently babel is used only when allowSyntheticDefaultImports is true. Come to think of it, ts-jest is currently using allowSyntheticDefaultImports where the new flag should be used. If we introduce this new flag, we can remove the check for allowSyntheticDefaultImports because it'll become irrelevant.
This wasn't always the case. The PR that did this was merged only a few weeks ago.
If we were implementing this from scratch, I'd agree 100%. As things stand, users using this (that PR fixed issues for a lot of people) are opted in to babel by default. And those who aren't using this don't really care about babel (probably). Well, we can use |
I've mulled it over. There are three options as I see it.
Pros.
Cons.
If we can't think of a use case where you would be interested in using babel without
Pros.
Cons.
This removes all the cons from the suggestion above, but it is a little harder to explain to the users. Thoughts? |
Another thing going for option 2 is that it makes sure the users know what's going on. Currently, as you pointed out as well, users have no idea that ts-jest uses babel when It is a breaking change but the fix required at the users' end would be straightforward - set |
I think the reason nobody knows what's going on is because it's not documented. I feel like option #1 would be easily explained with something like: 'If |
Sounds good |
@shlomiassaf I've sent a PR to your repo. Can you confirm that this fixes your issue? |
I'm confused on the conclusion. My understanding is that right now |
@jupl babel is used internally by ts-jest only when |
Currently babel is only used when allowSyntheticDefaultImports is set to
true, so it covers all cases. I imagine if we end up using babel for every
transformation we will make them independent
On Wed, May 24, 2017, 20:43 jupl ***@***.***> wrote:
I'm confused on the conclusion. My understanding is that right now
skipBabel is only applicable to allowSyntheticDefaultImports. If that's
the case is the plan to eventually make skipBabel be independent of
allowSyntheticDefaultImports?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#213 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGFg4MgaQUT_E7v11y95og3xGJzpGtnjks5r9Ho1gaJpZM4NaeJh>
.
--
mvh.
Gustav Wengel
|
Continuing the discussion from issue 209
For the same code compiled with TS, ts-jest emits a different output.
allowSyntheticDefaultImports
set to true.When using this statement:
In TS compilation without
ts-jest
pathToRegexp is a functionIn TS compilation with
ts-jest
pathToRegexp is an object.It's not deterministic, different outcome for the same TS compilation process
The text was updated successfully, but these errors were encountered: