Skip to content

Export syntax for ES6 modules #1215

Closed
Closed
@sheetalkamat

Description

@sheetalkamat

As per ES6 grammar:

ExportDeclaration :
export * FromClause ;
export ExportClause FromClause ;
export ExportClause ;
export VariableStatement
export Declaration
export default HoistableDeclaration[Default]
export default [lookahead ≠ function ] AssignmentExpression[In] ;


ExportClause[NoReference] :
{ }
{ ExportsList }
{ ExportsList , }

ExportsList :
ExportSpecifier
ExportsList , ExportSpecifier

ExportSpecifier :
IdentifierName
IdentifierName as IdentifierName

FromClause :
from ModuleSpecifier

ModuleSpecifier :
StringLiteral

Meanings of export syntax that we currently do not support (doesn't list generators since we do not support them as yet)

export default function name() { } 
// function name() { } 
// exports.default = name;
export default function () { } 
// function _temp() { } 
// exports.default = _temp;
export default = expression; 
// var _tmp = expression;
// exports.default = _tmp;
export { }; 
// Make this external module
export { } from StringLiteral; 
// import __tmp = require(StringLiteral)
export { a }; 
//exports.a = a;
export { a } from StringLiteral; 
// import __tmp = require(StringLiteral)
// exports.a = _tmp.a
export { id1 as a}; 
//exports.a = id1;
export { id1 as a } from StringLiteral; 
// import __tmp = require(StringLiteral)
// exports.a = _tmp.id1
export * from StringLiteral
// import _tmp = require(StringLIteral)
// foreach(a in _tmp.exports) 
// exports.a = _tmp.exports[a] 

Few things to consider:

  1. Resolution of export name is as follows,
  • if the name is directly exported clause (without referring to another module) - the resolution is returned for this name
  • if the name is exported using names eg. export {a} from stringLiteral - that resolution is returned
  • it is tried to be resolved from export entries of name (except default) from export * from StringLiteral
  • Should we be reporting errors for the name from export * from StringLiteral that is shadowed by the local exports/indirect named exports/existing * exports. According to ES6 it is ok, but should we still report error for shadowing for unintentional cases?
  1. The export names are always resolved in order of local exports, indirect exports and then star exports, But typescript currently uses declaration order to determine duplicate error. Should we change this order for duplicate naming or is it ok?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ES6Relates to the ES6 Spec

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions