[ES6] Module binding can be exported by multiple names
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 31 Jul 2016 07:04:57 +0000 (07:04 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 31 Jul 2016 07:04:57 +0000 (07:04 +0000)
commit0ddfc9fd13e84c5495c701faf138ad5204e6adfd
tree2a263efbf6d6d501952dcc9535ad9ff95d3daf16
parentcce8746a033d81967e6cbe8f216035ba972add26
[ES6] Module binding can be exported by multiple names
https://bugs.webkit.org/show_bug.cgi?id=160343

Reviewed by Saam Barati.

ES6 Module can export the same local binding by using multiple names.
For example,

    ```
    var value = 42;

    export { value };
    export { value as value2 };
    ```

Currently, we only allowed one local binding to be exported with one name. So, in the above case,
the local binding "value" is exported as "value2" and "value" name is not exported. This is wrong.

To fix this issue, we collect the correspondence (local name => exported name) to the local bindings
in the parser. Previously, we only maintained the exported local bindings in the parser. And utilize
this information when creating the export entries in ModuleAnalyzer.

And this patch also moves ModuleScopeData from the Scope object to the Parser class since exported
names should be managed per-module, not per-scope.

This change fixes several test262 failures.

* JavaScriptCore.xcodeproj/project.pbxproj:
* parser/ModuleAnalyzer.cpp:
(JSC::ModuleAnalyzer::exportVariable):
(JSC::ModuleAnalyzer::analyze):
(JSC::ModuleAnalyzer::exportedBinding): Deleted.
(JSC::ModuleAnalyzer::declareExportAlias): Deleted.
* parser/ModuleAnalyzer.h:
* parser/ModuleScopeData.h: Copied from Source/JavaScriptCore/parser/ModuleAnalyzer.h.
(JSC::ModuleScopeData::create):
(JSC::ModuleScopeData::exportedBindings):
(JSC::ModuleScopeData::exportName):
(JSC::ModuleScopeData::exportBinding):
* parser/Nodes.cpp:
(JSC::ProgramNode::ProgramNode):
(JSC::ModuleProgramNode::ModuleProgramNode):
(JSC::EvalNode::EvalNode):
(JSC::FunctionNode::FunctionNode):
* parser/Nodes.h:
(JSC::ModuleProgramNode::moduleScopeData):
* parser/NodesAnalyzeModule.cpp:
(JSC::ExportDefaultDeclarationNode::analyzeModule):
(JSC::ExportNamedDeclarationNode::analyzeModule): Deleted.
* parser/Parser.cpp:
(JSC::Parser<LexerType>::Parser):
(JSC::Parser<LexerType>::parseModuleSourceElements):
(JSC::Parser<LexerType>::parseVariableDeclarationList):
(JSC::Parser<LexerType>::createBindingPattern):
(JSC::Parser<LexerType>::parseFunctionDeclaration):
(JSC::Parser<LexerType>::parseClassDeclaration):
(JSC::Parser<LexerType>::parseExportSpecifier):
(JSC::Parser<LexerType>::parseExportDeclaration):
* parser/Parser.h:
(JSC::Parser::exportName):
(JSC::Parser<LexerType>::parse):
(JSC::ModuleScopeData::create): Deleted.
(JSC::ModuleScopeData::exportedBindings): Deleted.
(JSC::ModuleScopeData::exportName): Deleted.
(JSC::ModuleScopeData::exportBinding): Deleted.
(JSC::Scope::Scope): Deleted.
(JSC::Scope::setSourceParseMode): Deleted.
(JSC::Scope::moduleScopeData): Deleted.
(JSC::Scope::setIsModule): Deleted.
* tests/modules/aliased-names.js: Added.
* tests/modules/aliased-names/main.js: Added.
(change):
* tests/stress/modules-syntax-error-with-names.js:
(export.Cocoa):
(SyntaxError.Cannot.export.a.duplicate.name):
* tests/test262.yaml:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@203953 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/parser/ModuleAnalyzer.cpp
Source/JavaScriptCore/parser/ModuleAnalyzer.h
Source/JavaScriptCore/parser/ModuleScopeData.h [new file with mode: 0644]
Source/JavaScriptCore/parser/Nodes.cpp
Source/JavaScriptCore/parser/Nodes.h
Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp
Source/JavaScriptCore/parser/Parser.cpp
Source/JavaScriptCore/parser/Parser.h
Source/JavaScriptCore/tests/modules/aliased-names.js [new file with mode: 0644]
Source/JavaScriptCore/tests/modules/aliased-names/main.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/modules-syntax-error-with-names.js
Source/JavaScriptCore/tests/test262.yaml