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

Typescript compiler prevents tree shaking by removing comments. #21087

Closed
seivan opened this issue Jan 9, 2018 · 3 comments
Closed

Typescript compiler prevents tree shaking by removing comments. #21087

seivan opened this issue Jan 9, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@seivan
Copy link

seivan commented Jan 9, 2018

TypeScript Version: 2.7.0-dev.201xxxxx

Code
https://www.typescriptlang.org/play/index.html#src=class%20Sample%20%7B%0D%0A%20%20%20%20demo%20%3D%20()%20%3D%3E%20%7B%0D%0A%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Aconst%20Button%20%3D%20%2F*%40__PURE__*%2F%20new%20Sample().demo

Expected behavior:
The comment should not be stripped

Actual behavior:
The comment is stripped and tree shaking breaks in production.

Related:
"Tree shaking" works when using ES6 modules and targeting the file directly, e.g

import { Button } from "lib/Button"

But if you want, what I want, the glorious way of doing

import { Button } from "lib"

Then it's no good. UNLESS the transpiled code (the output before minifying) in the exported file looks like

const Button = /*@__PURE__*/ whateverFunctionThatCreatesButton { }

In other words, it's a no go with Typescripts compiler as it will remove that comment.

@mhegazy mhegazy added Bug A bug in TypeScript Domain: Comment Emit The issue relates to the emission of comments when compiling labels Jan 9, 2018
@mhegazy mhegazy added this to the TypeScript 2.8 milestone Jan 9, 2018
@weswigham
Copy link
Member

Duplicates #17606 (but it is worth remembering that new expressions should be tested for, too)

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Bug A bug in TypeScript Domain: Comment Emit The issue relates to the emission of comments when compiling labels Jan 10, 2018
@mhegazy mhegazy removed this from the TypeScript 2.8 milestone Jan 10, 2018
@seivan
Copy link
Author

seivan commented Jan 22, 2018

@weswigham Should this be closed since its a dupe?
From my point of view, this is a decent sized issue since it prevents tree shaking to work, thus creates larger than necessary bundles that need workarounds to prevent.

@weswigham
Copy link
Member

@seivan Yes. You should track #17606 instead of this issue.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants