Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass es6 options to compiler #22

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/babel_compile.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
var babel = require("babel-core");
var extend = require("lodash/object/extend");

var mapFormat = {
'commonjs': 'common',
'amd': 'amd'
};

module.exports = function(source, options){
var result = babel.transform(source, {
var opts = extend({}, {
modules: mapFormat[options.modules]
});
}, options.babelOptions);
var result = babel.transform(source, opts);
return {
js: result.code
};
Expand Down
10 changes: 8 additions & 2 deletions lib/clean_traceur_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var traceurPath = require.resolve("traceur");
var search = "/node_modules/traceur/";
var index = traceurPath.indexOf(search);
var path = traceurPath.substr(0,index+search.length );
var extend = require("lodash/object/extend");

for(var name in require.cache) {
if( name.indexOf(path) === 0 ) {
Expand All @@ -33,15 +34,20 @@ globalNames.forEach(function(name){
global[name] = oldGlobals[name];
});

module.exports = function(){
module.exports = function(source, options){
var saved = {};

globalNames.forEach(function(name){
saved[name] = global[name];
global[name] = globals[name];
});

var opts = extend({}, {
filename: options.filename,
modules: options.modules
}, options.traceurOptions);

var result = traceur.compile.apply(traceur, arguments);
var result = traceur.compile(source, opts);

globalNames.forEach(function(name){
global[name] = saved[name];
Expand Down
8 changes: 5 additions & 3 deletions lib/es6_amd.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
var amd_amd = require('./amd_amd');
var getCompile = require('./es6_compiler');
var extend = require("lodash/object/extend");

module.exports = function(load, options){
var compile = getCompile(options);

load.source = compile(load.source.toString(), {
var opts = extend({}, options, {
filename: load.address,
modules: 'amd'
}).js;
});

load.source = compile(load.source.toString(), opts).js;
return amd_amd(load, options);
};
6 changes: 4 additions & 2 deletions lib/es6_cjs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var normalizeCJS = require('./normalize_cjs');
var getCompile = require('./es6_compiler');
var extend = require("lodash/object/extend");

module.exports = function(load, options){
var compile = getCompile(options);
Expand All @@ -9,10 +10,11 @@ module.exports = function(load, options){
copy[prop] = load[prop];
}

var result = compile(load.source.toString(), {
var opts = extend({}, options, {
filename: load.address,
modules: 'commonjs'
}).js;
});
var result = compile(load.source.toString(), opts).js;
if(options && (options.normalizeMap || options.normalize)) {
copy.source = result;
return normalizeCJS(copy, options);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
"web" : "http://bitovi.com/"
},
"dependencies": {
"babel-core": "~4.1.1",
"babel-core": "~4.7.12",
"comparify": "0.1.0",
"escodegen": "1.3.2",
"esprima": "1.1.1",
"estraverse": "1.5.0",
"js-module-formats": "~0.1.2",
"js-string-escape": "1.0.0",
"lodash": "^3.3.1",
"traceur": "0.0.58"
},
"devDependencies": {
Expand Down
9 changes: 9 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ describe('es6 - amd', function(){
transpiler: "babel"
}, done);
});

it("should pass in babel options", function(done){
doTranspile("es6", "es6", "es6_amd_babel_options.js", "amd", {
transpiler: "babel",
babelOptions: {
loose: "es6.modules"
}
}, done);
});
});

describe('cjs - amd', function(){
Expand Down
5 changes: 3 additions & 2 deletions test/tests/expected/es6_amd_babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ define([
var _interopRequire = function (obj) {
return obj && obj.__esModule ? obj['default'] : obj;
};
Object.defineProperty(exports, '__esModule', { value: true });
var amdMod = _interopRequire(_basicsAmdmodule);
exports['default'] = {
amdModule: amdMod,
name: 'es6Module'
};
var __useDefault = exports.__useDefault = true;
Object.defineProperty(exports, '__esModule', { value: true });
var __useDefault = true;
exports.__useDefault = __useDefault;
});
17 changes: 17 additions & 0 deletions test/tests/expected/es6_amd_babel_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
define([
'exports',
'basics/amdmodule'
], function (exports, _basicsAmdmodule) {
'use strict';
var _interopRequire = function (obj) {
return obj && obj.__esModule ? obj['default'] : obj;
};
exports.__esModule = true;
var amdMod = _interopRequire(_basicsAmdmodule);
exports['default'] = {
amdModule: amdMod,
name: 'es6Module'
};
var __useDefault = true;
exports.__useDefault = __useDefault;
});
10 changes: 6 additions & 4 deletions test/tests/expected/es6_cjs_babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };

Object.defineProperty(exports, "__esModule", {
value: true
});

var amdMod = _interopRequire(require("basics/amdmodule"));

exports["default"] = {
amdModule: amdMod,
name: "es6Module"
};
var __useDefault = exports.__useDefault = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
var __useDefault = true;
exports.__useDefault = __useDefault;