Skip to content

Not quite a bug but a confusing behavior: Sometimes throws vague error if two blocks of code are not separated by a semicolon #5751

@Spederan

Description

@Spederan

I was confused because my files ran fine both minified previously and they were currently running fine nonminified, but when i converted each to a string and added them together separated by a space (which worked fine dozens of times before across dozens of files), it threw an unexpected and vague error. After 20 minutes, i finally figured out its because it thought i was missing a semicolon, in retrospect it must have interpreted the code as a single line of code, and the missing semicolon as an error. My solution is now separating each file with a semicolon and a space, just to make sure.

At first i thought it was a bug because my original files ran fine, but my minified files (the minification process i thought i had perfected before) did not run fine. Now i am unsure, because after thinking about it this might have to do with javascript itself being confused, after i put the code into a single string which it would interpret as a single line.

My issue in relation to UglifyJS is that the error message didnt really point to anything but UglifyJS's own internals. I had no idea what was going on. An error message that points out the error in the string it was parsing wouldve been massively helpful, and i would have immediately seen the problem. For example: func() let a = 5; would throw an error i believe, and a more helpful error message would include that segment in the message. Also if there was a way to detect it was specifically missing a semicolon, that would have been helpful also. And in theory i dont see why a semicolon cant be automatically inserted here, as clearly the only context in which it makes sense is one in which it exists.

For reference, here is the error message i got:

JS_Parse_Error [SyntaxError]: Unexpected token: name «let», expected: punc «;»
at JS_Parse_Error.get (eval at (/home/anonymous/Documents/Spederan/speedrunjs/node_modules/uglify-js/tools/node.js:18:1), :63:23)
at getStackString (node:internal/util/inspect:1241:37)
at formatError (node:internal/util/inspect:1363:15)
at formatRaw (node:internal/util/inspect:986:14)
at formatValue (node:internal/util/inspect:841:10)
at inspect (node:internal/util/inspect:365:10)
at formatWithOptionsInternal (node:internal/util/inspect:2273:40)
at formatWithOptions (node:internal/util/inspect:2135:10)
at console.value (node:internal/console/constructor:340:14)
at console.log (node:internal/console/constructor:377:61) {
filename: '0',
line: 6610,
col: 17,
pos: 365301
}

Not sure if this counts as a bug or a feature request, but i wanted to share it regardless.

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

    Issue actions