Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinmetcalf/8701624 to your computer and use it in GitHub Desktop.
Save calvinmetcalf/8701624 to your computer and use it in GitHub Desktop.
//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
@zenparsing
Copy link

export foo;
// syntax error:  you want export { foo };

export foo();
// syntax error

export default let a = [thing1, thing2];
// syntax error

@calvinmetcalf
Copy link
Author

thanks I updated it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment