Use of the "import" name in Components.utils.import causes javascript validators to choke and fail.

NEW
Unassigned

Status

()

Core
XPConnect
8 years ago
6 years ago

People

(Reporter: Andrew, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

8 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.18) Gecko/2010021501 Ubuntu/9.04 (jaunty) Firefox/3.0.18
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.18) Gecko/2010021501 Ubuntu/9.04 (jaunty) Firefox/3.0.18

Since "import" is a reserved keyword in javascript, YUI Compressor fails to compress files and JSLint will not pass validation for scripts using Components.utils.import.

YIU Compressor error:
"missing name after . operator"
(line/column numbers point to the column directly after ".import")
"Compilation produced X syntax errors"
Where X is the number of import statements used.

JSLint error:
"Expected an identifier and instead saw 'import' (a reserved word)."
(line/column numbers point to the column directly after the "." in ".import")


Reproducible: Always

Steps to Reproduce:
1. Put "Components.utils.import('')" in a javascript .js file (this is valid JS for a browser overlay script, for example)
2. Run Yahoo's YIU Compressor on the file.
3. Run the contents of the file through JSLint.

Updated

7 years ago
Status: UNCONFIRMED → NEW
Ever confirmed: true

Comment 1

6 years ago
While I personally feel the use of import was a "bad idea", it is legal.

As described in  http://es5.github.com/#A.1 and http://es5.github.com/#x7.6,  IdentifierName does not exclude ReservedWord, only Identifier does.

Identifier ::
  IdentifierName but not ReservedWord

IdentifierName ::
  IdentifierStart
  IdentifierName IdentifierPart


These following  use  IdentifierName (which does not excluded ReservedWord) and therefore are legal.

a.import
a["import"]
a = { import: "test" }


On the other hand the following (FunctionDeclaration, FunctionExpression, and VariableDeclaration) are illegal because they use Identifier. .

function import() {}
var a = function import() {}
var import = "a";


Also see discussion at bottom of https://bugzilla.mozilla.org/show_bug.cgi?id=238324.
You need to log in before you can comment on or make changes to this bug.