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

Minifying JS with default exported function using prototype #525

Closed
jarmo opened this issue Jul 31, 2022 · 1 comment
Closed

Minifying JS with default exported function using prototype #525

jarmo opened this issue Jul 31, 2022 · 1 comment

Comments

@jarmo
Copy link

jarmo commented Jul 31, 2022

Having foo.js with contents:

export default function Foo() {
  console.info("Foo")
}

Foo.prototype.bar = function() {
  console.info("bar")
}

Produces invalid minified output:

$ minify foo.js
export default function(){console.info("Foo")}Foo.prototype.bar=function(){console.info("bar")}

Problem is that function name Foo will be stripped and after that Foo.prototype.bar will throw an error.

minify should not break JS like this.

Currently a work-around is to change foo.js into the following:

function Foo() {
  console.info("Foo")
}

Foo.prototype.bar = function() {
  console.info("bar")
}

export default Foo

Then everything works as expected:

$ minify foo.js
function Foo(){console.info("Foo")}Foo.prototype.bar=function(){console.info("bar")};export default Foo
@tdewolff
Copy link
Owner

tdewolff commented Aug 3, 2022

Thanks, should be fixed now!

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

No branches or pull requests

2 participants