Last active
August 29, 2015 13:55
-
-
Save calvinmetcalf/8701624 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//we will use this again | |
function foo(){ | |
function bar(){ | |
} | |
return bar; | |
} | |
//export by itself | |
//with a declaration | |
export function foo(){ | |
function bar(){ | |
} | |
return bar; | |
} | |
//exports that function as foo | |
//in es6 we get more types of declarations so | |
export class Foo{ | |
} | |
// exports Foo as Foo | |
//but you can't export that variable | |
export foo; | |
// error | |
//and it's not an expression so you can't do this | |
//even if what returned was legal (which it isn't) | |
export foo(); | |
// error | |
//export a variable declaration (VariableStatement) | |
export let bar = foo(); | |
// exports bar as bar | |
//normal rules for right hand side | |
export let a = [thing1, thing2]; | |
//exports array as a | |
//chained variable expressions work too | |
export var a = 1, b = 2; | |
//exports a as 1 and b as 2 | |
//you're still declaring the variables so you can't | |
//use a name that is already there | |
var a = 1; | |
export var a = 2; | |
//error | |
// export defaults | |
// must be a AssignmentExpression | |
// aka anything on the right hand side of a var a = b; | |
export default foo; | |
//foo is exported as default | |
export default foo(); | |
//bar is exported as defult | |
export default function (){} | |
//function exported as default | |
export default let a = [thing1, thing2]; | |
//error | |
export default [thing1, thing2]; | |
//export list as default | |
//export expressions | |
//export a current variable | |
export { foo } | |
// export foo as foo | |
//export a current variable with a different name | |
export { foo as bar } | |
// export foo as bar | |
//but it can't be an expression, just a name (IdentifierReference or IdentifierName) | |
export { function(){} as bar } | |
//error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment