mirror of
https://github.com/moodle/moodle.git
synced 2025-08-02 23:59:41 +02:00
MDL-66265 javascript: Add jshint ignore for ES6 files in root dir
This commit is contained in:
parent
b5fbca8f4a
commit
f59ac4166c
4 changed files with 23 additions and 15 deletions
|
@ -204,7 +204,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
files: ["**/amd/src/*.js", "**/amd/src/**/*.js"],
|
files: ["**/amd/src/*.js", "**/amd/src/**/*.js", "*.js"],
|
||||||
// We support es6 now. Woot!
|
// We support es6 now. Woot!
|
||||||
env: {
|
env: {
|
||||||
es6: true
|
es6: true
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
**/amd/**
|
**/amd/**
|
||||||
|
/*.js
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
* Grunt configuration
|
* Grunt configuration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* eslint-env node */
|
||||||
module.exports = function(grunt) {
|
module.exports = function(grunt) {
|
||||||
var path = require('path'),
|
var path = require('path'),
|
||||||
tasks = {},
|
tasks = {},
|
||||||
|
|
|
@ -33,8 +33,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
/* eslint-env node */
|
||||||
|
|
||||||
module.exports = ({ template, types }) => {
|
module.exports = ({template, types}) => {
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
|
@ -120,15 +121,20 @@ module.exports = ({ template, types }) => {
|
||||||
throw new Error('Unable to find module name for ' + searchFileName);
|
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 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
|
* This is used when we detect a module using "export default Foo;" to make
|
||||||
// with the default property (i.e. {default: Foo}).
|
* 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.
|
* 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) {
|
function addModuleExportsDefaults(path, exportObjectName) {
|
||||||
const rootPath = path.findParent(path => {
|
const rootPath = path.findParent(path => {
|
||||||
return path.key === 'body' || !path.parentPath;
|
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).
|
// HACK: `path.node.body.push` instead of path.pushContainer(due doesn't work in Plugin.post).
|
||||||
// This is hardcoded to work specifically with AMD.
|
// 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 {
|
return {
|
||||||
|
@ -174,9 +180,9 @@ module.exports = ({ template, types }) => {
|
||||||
|
|
||||||
// Check for any Object.defineProperty('exports', 'default') calls.
|
// Check for any Object.defineProperty('exports', 'default') calls.
|
||||||
if (!this.addedReturnForDefaultExport && path.get('callee').matchesPattern('Object.defineProperty')) {
|
if (!this.addedReturnForDefaultExport && path.get('callee').matchesPattern('Object.defineProperty')) {
|
||||||
const [identifier, prop] = path.get('arguments')
|
const [identifier, prop] = path.get('arguments');
|
||||||
const objectName = identifier.get('name').node
|
const objectName = identifier.get('name').node;
|
||||||
const propertyName = prop.get('value').node
|
const propertyName = prop.get('value').node;
|
||||||
|
|
||||||
if ((objectName === 'exports' || objectName === '_exports') && propertyName === 'default') {
|
if ((objectName === 'exports' || objectName === '_exports') && propertyName === 'default') {
|
||||||
addModuleExportsDefaults(path, objectName);
|
addModuleExportsDefaults(path, objectName);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue