Skip to content

Make traceur (maybe all traceur-compiled modules) loadable via node 'require' #209

@arv

Description

@arv

Original author: usrbi...@yahoo.com (February 26, 2013 22:10:37)

I believe it might not be much harder to do this for all modules, so
I've tentatively extended the scope of the bug.

For those just joining: Currently traceur uses an 'eval' hack to
load into node. This loses line numbers in stack traces, and some
flexibility.

Proof-of-concept (way out-of-date currently):

Make bin/runtime.js and bin/traceur.js
run natively in both node and browser.
https://codereview.appspot.com/6745048/

The goal in a nutshell is (as I see it)

$ cat H.js
module H {
export function h(n) {
return 'hello ' + n;
}
}
$ ./traceur --out H.out.js H.js
$ node
> var runtime = require('bin/traceur.js');
> traceur.runtime.setupGlobals(global); // See below.
> var H = require('./H.out.js').H;
> H.h('world');
'hello world'
>
$ cat H.out.html
<script src="runtime.js"></script>
<script src="H.out.js"></script>
<script>console.log(H.h('world'));</script>
$ my-browser H.out.html

Caveats:

Because modules can't affect the loading code's environment, you
need an extra step to install the polyfills for running compiled
traceur code in the current context:

var traceur = require('bin/traceur.js');
traceur.runtime.setupGlobals(global);

There may be other unforseen problems, obviously, so maybe have this
as an optional output format, not default.

Original issue: http://code.google.com/p/traceur-compiler/issues/detail?id=206

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions