You're right, package
is a reserved word in JavaScript (but only in strict mode, which will be why the code works in some places).
package
is 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:
inBlock['package'] = name; // this is ok
As long as you use a string. You can't do this:
inBlock.package = name; // this is not ok
I would say you're better off naming it something else.
For those wondering if this is still true today - package
was 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:
enum
is not currently used as a keyword in this specification. It is a future reserved word, set aside for use as a keyword in future language extensions.
Similarly, implements
, interface
, package
, private
, protected
, and public
are future reserved words in strict mode code.
and 12.1.1 SS: Early Errors:
Identifier
: IdentifierName
but not ReservedWord
It is a Syntax Error if this phrase is contained in strict mode code and the StringValue of IdentifierName is: "implements
", "interface
", "let
", "package
", "private
", "protected
", "public
", "static
", or "yield
".