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

Newlines are still being preserved after the end of a function #2

Open
kodie opened this issue Nov 4, 2021 · 3 comments
Open

Newlines are still being preserved after the end of a function #2

kodie opened this issue Nov 4, 2021 · 3 comments

Comments

@kodie
Copy link

kodie commented Nov 4, 2021

This was also an issue with JShrink: tedious/JShrink#87 and is actually how I came across your issue related to that here: tedious/JShrink#105

But I'm still seeing this issue with js-minify.

For example:

function hello () {
  console.log('Hello World')
}

console.log('yay')

Should become:

function hello(){console.log('Hello World')}console.log('yay')

But currently it becomes:

function hello(){console.log('Hello World')}
console.log('yay')
@garfix
Copy link
Owner

garfix commented Nov 10, 2021

Hi @kodie,

The reason why the library doesn't remove this whitespace can best be explained with a simple example:

let hello = function() {
  console.log('Hello World')
}

console.log('yay')

if this becomes

let hello = function(){console.log('Hello World')}console.log('yay')

the result of evaluation is

Uncaught SyntaxError: Unexpected identifier

I think this issue can only be resolved by full parsing the javascript file but this takes a lot of time.

@kodie
Copy link
Author

kodie commented Nov 11, 2021

@garfix In that case, couldn't we have it append a semicolon to the end of the function? So it becomes:

let hello = function(){console.log('Hello World')};console.log('yay')

@garfix
Copy link
Owner

garfix commented Nov 11, 2021

I elaborated on the semicolon versus newline decision in #1.

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