I am trying to minify a third-party JavaScript library using Google Closure Compiler, but it errors out at below line:
inBlock.package = package = name
The error is
ERROR – Parse error. missing name after . operator**
name above is a local variable inside a function and inBlock is an input argument. Nowhere in the function is package declared other than that error line.
I guess it may be due to package is a reserved keyword in JavaScript?
Any idea what package is in JavaScript and how to fix it?
You’re right,
packageis a reserved word in JavaScript (but only in strict mode, which will be why the code works in some places).packageis future-reserved, which means it’s not used for anything, but you can’t use it to name variables. However (if you really must), you can use it to name keys in objects like this:As long as you use a string. You can’t do this:
I would say you’re better off naming it something else.
For those wondering if this is still true today –
packagewas added to the future-reserved list in ES-3 (1999), and has remained there until today. At the time of writing, we are at ES-11 (2020), where it is still unavailable.The relevant parts of the ES-11 2020 spec are:
11.6.2 Note 2:
and 12.1.1 SS: Early Errors: