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

Referencing constructor params is not handled #13

Closed
mad-gooze opened this issue Oct 16, 2019 · 9 comments
Closed

Referencing constructor params is not handled #13

mad-gooze opened this issue Oct 16, 2019 · 9 comments
Labels
bug Something isn't working

Comments

@mad-gooze
Copy link
Contributor

Hi! Thanks for a nice lib!

I am trying to use it in my project, and I've found an issue with constructor params.

Please see a unit test in #12

It is broken now - https://github.com/mad-gooze/ts-transformer-minify-privates/blob/reference-ctor-params-unit-test/tests/test-cases/reference-ctor-params/input.ts#L5 (privateField is not replaced so resulting code is incorrect)

@timocov
Copy link
Owner

timocov commented Oct 16, 2019

Hey,

I appreciate your feedback!

Looks like a bug. Would you like to make fixes for this issue as well?

@timocov timocov added the bug Something isn't working label Oct 16, 2019
@mad-gooze
Copy link
Contributor Author

I'll try to work out a fix this week.

@schmidt-sebastian
Copy link

schmidt-sebastian commented Oct 24, 2019

@mad-gooze I work on the Firebase SDKs (https://github.com/firebase/firebase-js-sdk) and am trying to evaluate whether we can use this library as a starting ground for minification. Unfortunately, this issue is a major blocker for us.

At first glance, the fix does not seem to be super straightforward, as your test case illustrates:

console.log(privateField);

console, log and privateField are all simply marked as Identifiers and therefore indistinguishable. As such, we likely have to keep a mapping of the identifiers that we already renamed within the current scope. I played around with this a little, and while it is certainly not rocket science, it does introduce state keeping to ts-transformer-minify-privates, which would be nice to avoid.

I don't want to duplicate our efforts and would like to know if you have already started looking into this and could use help?

@timocov
Copy link
Owner

timocov commented Oct 24, 2019

Hey @schmidt-sebastian, thank you for reaching out.

Unfortunately, this issue is a major blocker for us.

@mad-gooze could you please tell whether you've started on the fix for this issue or I could fix it instead?

At first glance, the fix does not seem to be super straightforward, as your test case illustrates

Just for reference https://ts-ast-viewer.com/#code/KYDwDg9gTgLgBAYwDYEMDOa4GFUbgbwFgAoOMuMAVwCMkBLBRCAOzRikoRmgAoTyBFKHQBuKGMCGjxwAGJ1gSACYAuOM0oBbasCj9yASgL7BTVhCTAAdEggBzHmGFiJ8xUqvcAMhAQokBgDcJCaCaMAwACp0msAQlDA8PEYAvAB8ZmgW1rYOTtKuCsoGQaEAviQVxEA.

Actually here we can use type checker from the program to detect if one of the symbol's declaration is ctor parameter with private keyword and if so - just rename that identifier.

@timocov
Copy link
Owner

timocov commented Oct 29, 2019

@mad-gooze ping

@mad-gooze
Copy link
Contributor Author

sorry guys, fix is ready #14

timocov added a commit that referenced this issue Oct 30, 2019
fix referencing constructor params in constructor body (fixes #13)
@timocov
Copy link
Owner

timocov commented Oct 30, 2019

@mad-gooze thank you a lot for your work on this! All PRs are just merged into master. Give me some time and I'll release the new version (I'll comment here about it).

/cc @schmidt-sebastian

@timocov
Copy link
Owner

timocov commented Oct 30, 2019

Looks like for now we can remove some unnecessary code (which is covered by new check), see f317645 🎉

@timocov
Copy link
Owner

timocov commented Oct 30, 2019

Version 0.3.0 has been released just now. npmjs - https://www.npmjs.com/package/ts-transformer-minify-privates/v/0.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants