Skip to content

minimal modules for a hypothetical es6 with lua's return

Notifications You must be signed in to change notification settings

juliangruber/turn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

turn

minimal modules for a hypothetical es6 with lua's return, inspired by substack/mmmify and motivated by @shtylman.

build status

syntax

Use import PATH to load a module from the string PATH. import is a keyword like typeof that just returns an ordinary value.

Use return VALUE in the top level scope to export functionality and jump out of the current context.

example

// main.js

var foo = import './foo.js'
console.log(foo(5));
// foo.js

var bar = import './bar.js'
return function (n) { return bar(n) * 10 };
// bar.js

return function (n) { return n + 3 };

build it with browserify:

$ browserify -t turn main.js > bundle.js

then run it with node (or a browser):

$ node bundle.js
80

POW.

how this works

Normally return statements outside of functions are illegal in JavaScript. turn adds an anonymous function wrapper around each file and transforms top level return into return module.exports=.

methods

var turn = require('turn')

This module is a browserify transform but you don't need to use browserify necessarily to use it.

turn()

Return a through-stream desugaring the import keyword and top level return into require() and module.exports=... that can be parsed by node and browserify.

install

With npm do:

npm install turn

license

MIT

About

minimal modules for a hypothetical es6 with lua's return

Resources

Stars

Watchers

Forks

Packages

No packages published