diff --git a/.eslintrc b/.eslintrc index 23887170377..c6ebc85fdbc 100644 --- a/.eslintrc +++ b/.eslintrc @@ -204,7 +204,7 @@ } }, { - files: ["**/amd/src/*.js", "**/amd/src/**/*.js"], + files: ["**/amd/src/*.js", "**/amd/src/**/*.js", "*.js"], // We support es6 now. Woot! env: { es6: true diff --git a/.jshintignore b/.jshintignore index be738ed3186..5e61b7c699d 100644 --- a/.jshintignore +++ b/.jshintignore @@ -1 +1,2 @@ **/amd/** +/*.js diff --git a/Gruntfile.js b/Gruntfile.js index 771bed1f101..70a2240d9c9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -24,6 +24,7 @@ * Grunt configuration */ +/* eslint-env node */ module.exports = function(grunt) { var path = require('path'), tasks = {}, diff --git a/babel-plugin-add-module-to-define.js b/babel-plugin-add-module-to-define.js index 133df3ff2af..cdbd8a7e2f5 100644 --- a/babel-plugin-add-module-to-define.js +++ b/babel-plugin-add-module-to-define.js @@ -33,8 +33,9 @@ */ "use strict"; +/* eslint-env node */ -module.exports = ({ template, types }) => { +module.exports = ({template, types}) => { const fs = require('fs'); const path = require('path'); const glob = require('glob'); @@ -120,15 +121,20 @@ module.exports = ({ template, types }) => { throw new Error('Unable to find module name for ' + searchFileName); } - // This is heavily inspired by the babel-plugin-add-module-exports plugin. - // See: https://github.com/59naga/babel-plugin-add-module-exports - // - // This is used when we detect a module using "export default Foo;" to make - // sure the transpiled code just returns Foo directly rather than an object - // with the default property (i.e. {default: Foo}). - // - // Note: This means that we can't support modules that combine named exports - // with a default export. + /** + * This is heavily inspired by the babel-plugin-add-module-exports plugin. + * See: https://github.com/59naga/babel-plugin-add-module-exports + * + * This is used when we detect a module using "export default Foo;" to make + * sure the transpiled code just returns Foo directly rather than an object + * with the default property (i.e. {default: Foo}). + * + * Note: This means that we can't support modules that combine named exports + * with a default export. + * + * @param {String} path + * @param {String} exportObjectName + */ function addModuleExportsDefaults(path, exportObjectName) { const rootPath = path.findParent(path => { return path.key === 'body' || !path.parentPath; @@ -136,7 +142,7 @@ module.exports = ({ template, types }) => { // HACK: `path.node.body.push` instead of path.pushContainer(due doesn't work in Plugin.post). // This is hardcoded to work specifically with AMD. - rootPath.node.body.push(template(`return ${exportObjectName}.default`)()) + rootPath.node.body.push(template(`return ${exportObjectName}.default`)()); } return { @@ -174,9 +180,9 @@ module.exports = ({ template, types }) => { // Check for any Object.defineProperty('exports', 'default') calls. if (!this.addedReturnForDefaultExport && path.get('callee').matchesPattern('Object.defineProperty')) { - const [identifier, prop] = path.get('arguments') - const objectName = identifier.get('name').node - const propertyName = prop.get('value').node + const [identifier, prop] = path.get('arguments'); + const objectName = identifier.get('name').node; + const propertyName = prop.get('value').node; if ((objectName === 'exports' || objectName === '_exports') && propertyName === 'default') { addModuleExportsDefaults(path, objectName);