Skip to content

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

Open
@kodie

Description

@kodie

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')

Activity

garfix

garfix commented on Nov 10, 2021

@garfix
Owner

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

kodie commented on Nov 11, 2021

@kodie
Author

@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

garfix commented on Nov 11, 2021

@garfix
Owner

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kodie@garfix

        Issue actions

          Newlines are still being preserved after the end of a function · Issue #2 · garfix/js-minify