Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Created October 30, 2014 16:31
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 OliverJAsh/7dcc37216ea43ecd6f73 to your computer and use it in GitHub Desktop.
Save OliverJAsh/7dcc37216ea43ecd6f73 to your computer and use it in GitHub Desktop.
Traceur error
npm install
./node_modules/.bin/traceur --out out.js test.js

node main.js
var test = require('traceur').require('./test.js');
console.log(1, test);
System.register("test", [], function() {
"use strict";
var $__0 = this;
var __moduleName = "test";
var foo = (function() {
$__0;
});
module.exports = {foo: 'bar'};
return {};
});
System.get("test" + '');
{
"name": "traceur-error",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"traceur": "0.0.72"
}
}
var foo = () => {
this;
};
module.exports = { foo: 'bar' };
@OliverJAsh
Copy link
Author

 node main.js
1 {}

Should be:

 node main.js
1 { foo: 'bar' }

@johnjbarton
Copy link

To correctly emulate the traceur.require you need to compile with commonjs:

./node_modules/.bin/traceur --modules=commonjs --out out.js test.js

The resulting commonjs module fails because this is used in module scope. That causes our code to add the extra outer function wrapper. Once we make such use of this illegal in module scope, this bug will also be fixed. See #1478

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