Skip to content

Commit

Permalink
MDL-66265 javascript: Add jshint ignore for ES6 files in root dir
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Sep 3, 2019
1 parent b5fbca8 commit f59ac41
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/amd/**
/*.js
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Grunt configuration
*/

/* eslint-env node */
module.exports = function(grunt) {
var path = require('path'),
tasks = {},
Expand Down
34 changes: 20 additions & 14 deletions babel-plugin-add-module-to-define.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -120,23 +121,28 @@ 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;
});

// 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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f59ac41

Please sign in to comment.