MDL-66265 javascript: Add jshint ignore for ES6 files in root dir

This commit is contained in:
Andrew Nicols
2019-09-04 06:48:11 +08:00
parent b5fbca8f4a
commit f59ac4166c
4 changed files with 23 additions and 15 deletions
+1 -1
View File
@@ -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
+1
View File
@@ -1 +1,2 @@
**/amd/**
/*.js
+1
View File
@@ -24,6 +24,7 @@
* Grunt configuration
*/
/* eslint-env node */
module.exports = function(grunt) {
var path = require('path'),
tasks = {},
+20 -14
View File
@@ -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);