shapesecurity / shift-parser-js

ECMAScript parser that produces a Shift format AST
http://shift-ast.org/parser.html
Apache License 2.0
251 stars 28 forks source link

Correct assignment of ExportName #285

Closed jugglinmike closed 8 years ago

jugglinmike commented 8 years ago

The string "default" is only assigned to the [[LocalName]] field of ExportEntry records. By incorrectly using that string as a synthetic value for [[ExportName]], the parser cannot detect cases where an export which is explicitly named "default" collides with a default export as specified via export default.

Update the parser to correctly assign the value "default" to [[ExportName]] in these cases. Remove unnecessary logic concerning each entry's [[LocalName]] value.

15.2.3.5 Static Semantics: ExportEntries

[...]

ExportDeclaration : export default HoistableDeclaration

1. Let names be BoundNames of HoistableDeclaration.
2. Let localName be the sole element of names.
3. Return a new List containing the Record {[[ModuleRequest]]:
   null, [[ImportName]]: null, [[LocalName]]: localName,
   [[ExportName]]: "default"}.

ExportDeclaration : export default ClassDeclaration

1. Let names be BoundNames of ClassDeclaration.
2. Let localName be the sole element of names.
3. Return a new List containing the Record {[[ModuleRequest]]:
   null, [[ImportName]]: null, [[LocalName]]: localName,
   [[ExportName]]: "default"}.

ExportDeclaration : export default AssignmentExpression;

1. Let entry be the Record {[[ModuleRequest]]: null,
   [[ImportName]]: null, [[LocalName]]: "*default*",
   [[ExportName]]: "default"}.
2. Return a new List containing entry.

Source: http://www.ecma-international.org/ecma-262/6.0/#sec-exports-static-semantics-exportentries

michaelficarra commented 8 years ago

This looks great! Can you please add your name to the CLA and re-run CI by amending and force-pushing? See the CI failure for the exact email address to use in case you're unsure.

michaelficarra commented 8 years ago

Can you add tests for let a; export default function a(){} and let a; export default class a{}?

michaelficarra commented 8 years ago

Fixed by #297.