• Stars
    star
    153
  • Rank 242,456 (Top 5 %)
  • Language
  • Created over 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Proposal: add more export-from statements in ES7




This spec has been withdrawn in favor of the equivalent micro-proposals: export ns from and export default from.










Additional export-from statements in ES7

ES7 Proposal

Stage: 1

Author: Lee Byron

Specification: Spec.md

AST: ESTree.md

Transpiler: See Babel's es7.exportExtensions option.

Problem statement and rationale

The export ___ from "module" statements are a very useful mechanism for building up "package" modules in a declarative way. In the ES6 spec, we can:

  • export through a single export with export {x} from "mod"
  • ...optionally renaming it with export {x as v} from "mod"
  • We can also spread all exports with export * from "mod".

These three export-from statements are easy to understand if you understand the semantics of the similar looking import statements.

However, there are other import statements which would have very useful export-from forms.

  • Exporting the ModuleNameSpace object as a named export: export * as ns from "mod"
  • Forwarding the default export of the referenced module as a named export of this module: export v from "mod"

Current ES6 Modules:

Import Statement Form [[ModuleRequest]] [[ImportName]] [[LocalName]]
import v from "mod"; "mod" "default" "v"
import * as ns from "mod"; "mod" "*" "ns"
import {x} from "mod"; "mod" "x" "x"
import {x as v} from "mod"; "mod" "x" "v"
import "mod";
Export Statement Form [[ModuleRequest]] [[ImportName]] [[LocalName]] [[ExportName]]
export var v; null null "v" "v"
export default function f(){}; null null "f" "default"
export default function(){}; null null "*default*" "default"
export default 42; null null "*default*" "default"
export {x}; null null "x" "x"
export {x as v}; null null "x" "v"
export {x} from "mod"; "mod" "x" null "x"
export {x as v} from "mod"; "mod" "x" null "v"
export * from "mod"; "mod" "*" null null

Proposed additions:

Export Statement Form [[ModuleRequest]] [[ImportName]] [[LocalName]] [[ExportName]]
export * as ns from "mod"; "mod" "*" null "ns"
export v from "mod"; "mod" "default" null "v"

Symmetry between import and export

There's a syntactic symmetry between the export-from statements and the import statements they resemble. There is also a semantic symmetry; where import creates a locally named binding, export-from creates an export entry.

As an example:

export {v} from "mod";

Is symmetric to:

import {v} from "mod";

However, where importing v introduces a name in the local scope, export-from v does not alter the local scope, instead creating an export entry.

The two proposed additions follow this same symmetric pattern:

Exporting a namespace exotic object without altering local scope:

// proposed:
export * as ns from "mod";
// symmetric to:
import * as ns from "mod";

Re-exporting a module's default export with a name:

// proposed:
export v from "mod";
// symmetric to:
import v from "mod";

Using the terminology of Table 42 in ECMA-262 v6 RC4, the export-from form can be created from the symmetric import form by setting export-from's [[ExportName]] to import's [[LocalName]] and export-from's [[LocalName]] to null.

Table showing symmetry

Statement Form [[ModuleRequest]] [[ImportName]] [[LocalName]] [[ExportName]]
import v from "mod"; "mod" "default" "v"
export v from "mod"; "mod" "default" null "v"
import * as ns from "mod"; "mod" "*" "ns"
export * as ns from "mod"; "mod" "*" null "ns"
import {x} from "mod"; "mod" "x" "x"
export {x} from "mod"; "mod" "x" null "x"
import {x as v} from "mod"; "mod" "x" "v"
export {x as v} from "mod"; "mod" "x" null "v"
import * from "mod" "mod" null null (many)
export * from "mod"; "mod" "*" null null (many)

Note: import * from "mod" is only included for illustrative purposes. It is not in existing spec or part of this proposal.

Compound export-from statements

This proposal also includes the symmetric export-from for the compound imports:

// proposed
export v, {x, y as w} from "mod"
// symmetric to
import v, {x, y as w} from "mod"

As well as

// proposed
export v, * as ns from "mod"
// symmetric to
import v, * as ns from "mod"

Export default from

One use case is to take the default export of an inner module and export it as the default export of the outer module. This is written as:

export default from "mod";

This is not additional syntax above what's already proposed. In fact, this is just the export v from "mod" syntax where the export name happens to be default. This nicely mirrors the other export default ____ forms in both syntax and semantics without requiring additional specification. An alteration to an existing lookahead restriction is necessary for supporting this case.

More Repositories

1

testcheck-js

Generative testing for JavaScript
JavaScript
1,184
star
2

react-loops

React Loops works with React Hooks as part of the React Velcro Architecture
JavaScript
1,166
star
3

iterall

🌻 Minimal zero-dependency utilities for using Iterables in all JavaScript environments.
JavaScript
815
star
4

async-to-gen

⌛ Use async functions in your JavaScript today with speed and simplicity.
JavaScript
506
star
5

spec-md

📖 Additions to Markdown for writing specification documents
HTML
380
star
6

streamgraph

Processing applet which creates the images seen in the Streamgraph paper
Java
281
star
7

mesh

Processing library for creating point meshes.
Java
97
star
8

rollup-plugin-flow

Rollup plugin for removing Flow type annotations.
JavaScript
80
star
9

4000

63
star
10

cocoa-oauth2

Cocoa library for handling oauth2
59
star
11

til

Today I Learned
JavaScript
55
star
12

interactive-script

Easy to write interactive scripts
JavaScript
52
star
13

ecmascript-iterator-hof

Higher Order Functions on Iterators
JavaScript
42
star
14

rollup-plugin-async

Transforms Async functions to generator functions before bundling.
JavaScript
40
star
15

ecmascript-reverse-iterable

ReverseIterable Interface Spec Proposal
JavaScript
30
star
16

keyboard

My keyboard config
30
star
17

anyconnect-dark

Dark OSX menu bar assets for Cisco AnyConnect VPN.
24
star
18

mocha-check

Generative property testing for Mocha
17
star
19

bigtype

💥 Type big stuff
HTML
17
star
20

huron.wedding

Our wedding site
HTML
16
star
21

centerclock

A generative abstract clock.
JavaScript
13
star
22

fb-notify

Objective-C
12
star
23

grunt-jest

Grunt task for running jest tests.
JavaScript
12
star
24

respectify

Replaces the term 'politically correct' with 'respectful of other people' because it makes you oddly happy.
JavaScript
12
star
25

jasmine-check

Generative property testing for Jasmine
11
star
26

loda-js

Use JavaScript functionally, you shall.
JavaScript
10
star
27

ofxSDL

Overrides the openFrameworks windowing system to use SDL rather than GLUT.
C++
9
star
28

unflowify

Browserify transform for removing Flow type annotations.
JavaScript
9
star
29

fb-cocoa

Objective-C
8
star
30

remark-comment

Remark plugin to support comments
JavaScript
7
star
31

bubbletype

JavaScript
7
star
32

advent-of-code-2016

Solutions to the Advent of Code 2016 puzzles
JavaScript
6
star
33

dotfiles

JavaScript
6
star
34

ecmascript-reduced

Proposal for short-circuiting Array.prototype.reduce()
JavaScript
4
star
35

leebyron.github.io

Who has business cards anymore?
TypeScript
4
star
36

shapetween

(ARCHIVED 2007) Processing Library for tween and shape curves
Java
4
star
37

Wesley

Snipes
JavaScript
3
star
38

dbmd

Dropbox Hosted Markdown based CMS
JavaScript
3
star
39

iFBG

3
star
40

chain-js

A reactive framework.
JavaScript
2
star
41

cocoa-fbg

2
star
42

of-xcode-templates

openFrameworks XCode Templates
C++
2
star
43

shitty-peg

A Shitty PEG Parser
JavaScript
2
star
44

codespaces-dotfiles

Shell
2
star
45

lisp

Let's Learn Lisp with Lee
JavaScript
1
star
46

phagos

Button Mashing Glutton
C++
1
star
47

nuri-dog

http://nuri.dog
HTML
1
star
48

cocoa-net-connection

Cocoa class which monitors net connectivity
Objective-C
1
star
49

lrumap

JavaScript
1
star