Skip to content

Commit

Permalink
Merge pull request #4862 from emberjs/babel-6
Browse files Browse the repository at this point in the history
Babel 6
  • Loading branch information
bmac authored Mar 21, 2017
2 parents 13e334a + fffb635 commit 8e600fe
Show file tree
Hide file tree
Showing 10 changed files with 974 additions and 902 deletions.
9 changes: 5 additions & 4 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var merge = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
var globals = require('./lib/globals');
var yuidoc = require('./lib/yuidoc');
var stripClassCallCheck = require('babel5-plugin-strip-class-callcheck');
var StripClassCallCheck = require('babel6-plugin-strip-class-callcheck');
var path = require('path');

// allow toggling of heimdall instrumentation
Expand All @@ -20,10 +20,11 @@ for (var i = 0; i < args.length; i++) {

module.exports = function(defaults) {
var app = new EmberAddon(defaults, {
babel: {
plugins: [
// use babel6 options until we are using [email protected]
babel6: {
postTransformPlugins: [
// while ember-data strips itself, ember does not currently
{ transformer: stripClassCallCheck, position: 'after' }
[StripClassCallCheck]
]
}
});
Expand Down
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ module.exports = {
return;
}

this.options.babel = this.options.babel || {};
add(this.options.babel, 'blacklist', ['es6.modules', 'useStrict']);
add(this.options.babel, 'loose', ['es6.classes']);
add(this.options.babel, 'plugins', require('./lib/stripped-build-plugins')(process.env.EMBER_ENV));
let customPlugins = require('./lib/stripped-build-plugins')(process.env.EMBER_ENV);

this.options.babel = {
loose: true,
plugins: customPlugins.plugins,
postTransformPlugins: customPlugins.postTransformPlugins
};

this._hasSetupBabelOptions = true;
},
Expand Down
10 changes: 10 additions & 0 deletions lib/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* global module */
module.exports = {
parserOptions: {
ecmaVersion: 6,
},

env: {
node: true,
}
};
33 changes: 19 additions & 14 deletions lib/babel-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@ function babelOptions(libraryName, _options) {
_options = _options || {};

var options = {
whitelist: [
'es6.templateLiterals',
'es6.parameters',
'es6.arrowFunctions',
'es6.destructuring',
'es6.spread',
'es6.properties.computed',
'es6.properties.shorthand',
'es6.blockScoping',
'es6.constants',
'es6.modules',
'es6.classes'
],
plugins: [],
postTransformPlugins: [],
sourceMaps: false,
modules: 'amdStrict',
moduleRoot: libraryName,
moduleIds: true,
// Transforms /index.js files to use their containing directory name
Expand All @@ -36,6 +24,23 @@ function babelOptions(libraryName, _options) {
options[opt] = _options[opt];
});

options.plugins = options.plugins.concat([
['transform-es2015-modules-amd', { noInterop: true, loose: true }],
'transform-es2015-arrow-functions',
'transform-es2015-computed-properties',
'transform-es2015-shorthand-properties',
'transform-es2015-template-literals',
'transform-es2015-parameters',
'transform-es2015-destructuring',
'transform-es2015-spread',
'transform-es2015-block-scoping',
'transform-es2015-constants',
['transform-es2015-classes', { loose: true }],
], options.postTransformPlugins).filter(Boolean);

// this is not a "real" babel option, so we delete it
delete options.postTransformPlugins;

return options;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/javascripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ function collapse(tree, outputFileName) {
var dsGlobal = fs.readFileSync(dsGlobalPath, { encoding: 'utf8' });

var withLoader = merge([tree, loader, license, emberShim]);

return concat(withLoader, {
inputFiles: ['license.js', 'loader.js', '**/*.js'],
headerFiles: ['license.js', 'loader.js'],
inputFiles: ['**/*.js'],
outputFile: '/' + outputFileName,
header: '(function(){ \n"use strict";\n',
footer: '\nrequire("ember-data");\nrequire("ember-load-initializers")["default"](Ember.Application, "ember-data");\n' + dsGlobal + '}).call(this);\n' + emberDataShims
Expand Down
25 changes: 13 additions & 12 deletions lib/stripped-build-plugins.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
var fs = require('fs');
var path = require('path');
var filterImports = require('babel-plugin-filter-imports');
var featureFlags = require('babel-plugin-feature-flags');
var stripHeimdall = require('babel5-plugin-strip-heimdall');
var stripClassCallCheck = require('babel5-plugin-strip-class-callcheck');
var FilterImports = require('babel-plugin-filter-imports');
var FeatureFlags = require('babel-plugin-feature-flags');
var StripHeimdall = require('babel6-plugin-strip-heimdall');
var StripClassCallCheck = require('babel6-plugin-strip-class-callcheck');

function uniqueAdd(obj, key, values) {
var a = obj[key] = obj[key] || [];
Expand All @@ -29,22 +28,24 @@ module.exports = function(environment) {
// features[feature] = false;
// }
// }

var postTransformPlugins = [];
var plugins = [
featureFlags({
[FeatureFlags, {
import: { module: 'ember-data/-private/features' },
features: features
}),
{ transformer: stripClassCallCheck, position: 'after' }
}]
];

if (process.env.INSTRUMENT_HEIMDALL === 'false') {
plugins.push(stripHeimdall);
plugins.push([StripHeimdall]);
uniqueAdd(filteredImports, 'ember-data/-private/debug', ['instrument']);
} else {
console.warn('NOT STRIPPING HEIMDALL');
}

if (environment === 'production' || process.env.INSTRUMENT_HEIMDALL !== 'false') {
if (environment === 'production' || process.env.INSTRUMENT_HEIMDALL === 'true') {
postTransformPlugins.push([StripClassCallCheck]);
uniqueAdd(filteredImports, 'ember-data/-private/debug', [
'assert',
'assertPolymorphicType',
Expand All @@ -56,7 +57,7 @@ module.exports = function(environment) {
'debugSeal'
]);
}
plugins.push(filterImports(filteredImports));
plugins.push([FilterImports, filteredImports]);

return plugins;
return { plugins, postTransformPlugins };
};
3 changes: 1 addition & 2 deletions lib/stripped-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ var babelBuild = require('./babel-build');
var strippedBuildPlugins = require('./stripped-build-plugins');

module.exports = function(packageName, tree, environmentBuildingFor) {
var options = {};
options.plugins = strippedBuildPlugins(environmentBuildingFor);
var options = strippedBuildPlugins(environmentBuildingFor);

return babelBuild(packageName, tree, options);
};
25 changes: 18 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"license": "MIT",
"dependencies": {
"amd-name-resolver": "0.0.5",
"babel-plugin-feature-flags": "^0.2.1",
"babel-plugin-filter-imports": "^0.2.0",
"babel5-plugin-strip-class-callcheck": "^5.1.0",
"babel5-plugin-strip-heimdall": "^5.0.2",
"broccoli-babel-transpiler": "^5.5.0",
"babel-plugin-feature-flags": "^0.3.1",
"babel-plugin-filter-imports": "^0.3.1",
"babel6-plugin-strip-class-callcheck": "^6.0.0",
"babel6-plugin-strip-heimdall": "^6.0.1",
"broccoli-babel-transpiler": "^6.0.0",
"broccoli-file-creator": "^1.0.0",
"broccoli-merge-trees": "^1.0.0",
"chalk": "^1.1.1",
"ember-cli-babel": "^5.1.7",
"ember-cli-babel": "^6.0.0-beta.7",
"ember-cli-path-utils": "^1.0.0",
"ember-cli-string-utils": "^1.0.0",
"ember-cli-test-info": "^1.0.0",
Expand All @@ -45,6 +45,17 @@
"silent-error": "^1.0.0"
},
"devDependencies": {
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-plugin-transform-es2015-block-scoping": "^6.23.0",
"babel-plugin-transform-es2015-classes": "^6.23.0",
"babel-plugin-transform-es2015-computed-properties": "^6.22.0",
"babel-plugin-transform-es2015-constants": "^6.1.4",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-es2015-modules-amd": "^6.24.0",
"babel-plugin-transform-es2015-parameters": "^6.23.0",
"babel-plugin-transform-es2015-shorthand-properties": "^6.22.0",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-es2015-template-literals": "^6.22.0",
"bower": "^1.6.5",
"broccoli-asset-rev": "^2.4.5",
"broccoli-concat": "^3.2.2",
Expand All @@ -60,7 +71,7 @@
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-eslint": "1.3.0",
"ember-cli-htmlbars": "^1.1.1",
"ember-cli-htmlbars-inline-precompile": "^0.3.6",
"ember-cli-htmlbars-inline-precompile": "^0.4.0-beta.2",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-internal-test-helpers": "^0.8.1",
"ember-cli-pretender": "^1.0.1",
Expand Down
8 changes: 7 additions & 1 deletion tests/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import 'dummy/tests/helpers/setup-ember-dev';
/*
babel@6 currently (6.24.0) puts `import 'foo'` (for side effects) at the
end of the module dep list. Unfortunately, for this to work `setup-ember-dev`
must be evaluated before the `qunit` module is evaluated (because we change
`QUnit.module`).
*/
import requiredWorkAroundBabelBug from 'dummy/tests/helpers/setup-ember-dev'; // eslint-disable-line
import resolver from './helpers/resolver';
import {
setResolver
Expand Down
Loading

0 comments on commit 8e600fe

Please sign in to comment.