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

Use compiler enum than magic number #362

Closed

Conversation

HerringtonDarkholme
Copy link
Contributor

@HerringtonDarkholme HerringtonDarkholme commented Nov 8, 2016

fix #86

@johnnyreilly
Copy link
Member

johnnyreilly commented Nov 8, 2016

Cool! Is this still an issue though?: microsoft/TypeScript#4690

See the point made by @jbrantly here

@HerringtonDarkholme
Copy link
Contributor Author

Don't worry, I only access compiler in this case. So no redundant require will be generated.
It will even be resistant to enum value change for version upgrade but that's quite once in a blue moon for typescript team

@johnnyreilly
Copy link
Member

LGTM 👍

@HerringtonDarkholme
Copy link
Contributor Author

HerringtonDarkholme commented Nov 8, 2016

actually I found typescript has been required in servicesHost, in getDirectories. I guess we want to avoid requiring typescript because we want to support custom compiler and does not require user to install both tsc and custom copmiler.

@johnnyreilly
Copy link
Member

johnnyreilly commented Nov 8, 2016

That's a good point. I'm wondering if I've changed something by mistake or if @jbrantly previously decided to use this approach. @jbrantly would you be able to provide any insight here? Is it ok to be requiring typescript as we are or is that something we ought to avoid?

It looks like using import typescript = require('typescript'); predates the refactor:

import typescript = require('typescript');

@johnnyreilly
Copy link
Member

BTW @HerringtonDarkholme ts-loader 1.1.0 (with vue support) has 🚢 😄

@HerringtonDarkholme
Copy link
Contributor Author

@johnnyreilly can this be merged?

@johnnyreilly
Copy link
Member

Well @jbrantly hasn't come back with a reason why not. That being the case I figure we should merge this; since we seem to be import typescript = require('typescript'); already Feel free to merge!

@jbrantly
Copy link
Member

jbrantly commented Nov 15, 2016

Apologies, I missed the first mention. The original idea was to not require('typescript') in the output generated by TypeScript so as to be able to support custom compilers, that's correct. However, the TypeScript definitions were still used, which didn't generate a require as long as only metadata was accessed. At the time, accessing a constant enum also generated a require. It seems like that's still the case, so this could still be an issue.

@jbrantly
Copy link
Member

Regarding the current use of typescript.sys in servicesHost, I think it should actually be compiler.sys. It doesn't look like typescript.sys was accessed in the original code.

@johnnyreilly
Copy link
Member

Regarding the current use of typescript.sys in servicesHost, I think it should actually be compiler.sys. It doesn't look like typescript.sys was accessed in the original code.

You're right - I'll take a look at this.

At the time, accessing a constant enum also generated a require. It seems like that's still the case, so this could still be an issue.

In that case let's not merge for now. When that issue is resolved let's merge then

@HerringtonDarkholme
Copy link
Contributor Author

At the time, accessing a constant enum also generated a require. It seems like that's still the case, so this could still be an issue.

I don't think this is an issue because we can always use compiler's enum so no require will be generated.

@johnnyreilly
Copy link
Member

I see the red 😭

It only occurs on the 2.1.1 build. Without having looked into it I'm going to speculate that is as expected:

  • the comparison tests only run against 2.0 and 2.1
  • this changes the compiler usage and so may well be as expected

To avoid confusion I suggest we do the following:

  1. initially fix the TypeScript -> compiler issue. Address any changes in the comparison test pack that may arise.
  2. reapply the initial enum fix this PR raised. Compare the emitted JavaScript for compilerSetup.ts and servicesHost.ts before and after the fix. Share our findings and discuss. That way we're making the decision on the back of actual code and it becomes a simple case of "let's do this now" or "let's wait" for concrete reasons.

I can look into 1. but probably not until this weekend as I've a very busy week ahead. I don't mind if others want to pick this up first - but if no-one does I will.

@johnnyreilly
Copy link
Member

Oh and let's do 2 as distinct from 1 to avoid confusion

@johnnyreilly
Copy link
Member

Okay I've done 1. Took less time than expected

@jbrantly
Copy link
Member

I don't think this is an issue because we can always use compiler's enum so no require will be generated.

That's a good point and something I didn't realize when first looking at this. I believe you're probably right.

@HerringtonDarkholme
Copy link
Contributor Author

HerringtonDarkholme commented Nov 16, 2016

@johnnyreilly
Copy link
Member

I don't get the reference? Were there problems with ScriptTarget? Oh - this is because ES6 has become ES2015 and so on isn't it?

@johnnyreilly
Copy link
Member

Good effort though! 👍

@HerringtonDarkholme
Copy link
Contributor Author

this is because ES6 has become ES2015 and so on isn't it?

Exactly. Then to support both TS2.1 and below we need to add another layer of abstraction, and it is workaround anyway. That just does not worth. I would prefer magic number workaround.

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

Successfully merging this pull request may close these issues.

3 participants