Skip to content

Commit

Permalink
Merge branch 'MDL-66265-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Sep 4, 2019
2 parents 700e5ca + 9ec0cbe commit 9483886
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 39 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
2 changes: 2 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/amd/**
/*.js
2 changes: 2 additions & 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 Expand Up @@ -575,6 +576,7 @@ module.exports = function(grunt) {
};

if (relativePath) {
/* eslint-disable camelcase */
sub.relative_root = relativePath;
}

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
80 changes: 56 additions & 24 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"grunt-eslint": "20.1.0",
"grunt-sass": "2.1.0",
"grunt-stylelint": "0.6.0",
"jshint": "^2.10.2",
"semver": "5.3.0",
"shifter": "0.5.0",
"stylelint": "8.0.0",
Expand Down

0 comments on commit 9483886

Please sign in to comment.