Closed Bug 553875 Opened 14 years ago Closed 6 years ago

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

Categories

(Core :: XPConnect, defect)

defect
Not set
normal

Tracking

()

RESOLVED INACTIVE

People

(Reporter: andrew, Unassigned)

Details

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.
Status: UNCONFIRMED → NEW
Ever confirmed: true
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.
Per policy at https://wiki.mozilla.org/Bug_Triage/Projects/Bug_Handling/Bug_Husbandry#Inactive_Bugs. If this bug is not an enhancement request or a bug not present in a supported release of Firefox, then it may be reopened.
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.