Limit file-based plugins/presets to only exporting functions. (#6494)

This commit is contained in:
Logan Smyth 2017-10-18 10:17:45 -07:00 committed by GitHub
parent 445b252bc4
commit 1b4307205e
32 changed files with 158 additions and 66 deletions

View File

@ -556,6 +556,15 @@ function normalizePair(
);
}
if (filepath !== null && typeof value === "object" && value) {
// We allow object values for plugins/presets nested directly within a
// config object, because it can be useful to define them in nested
// configuration contexts.
throw new Error(
"Plugin/Preset files are not allowed to export objects, only functions.",
);
}
if (options != null && typeof options !== "object") {
throw new Error(
"Plugin/Preset options must be an object, null, or undefined",

View File

@ -7,6 +7,8 @@
'use strict';
exports.__esModule = true;
exports.default = {
plugins: [require('../../../../../babel-plugin-syntax-decorators')]
module.exports = function() {
return {
plugins: [require('../../../../../babel-plugin-syntax-decorators')]
};
};

View File

@ -1,5 +1,7 @@
module.exports = {
plugins: [
require('../../../../../babel-plugin-syntax-decorators'),
]
module.exports = function() {
return {
plugins: [
require('../../../../../babel-plugin-syntax-decorators'),
]
};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -0,0 +1,3 @@
module.exports = function() {
return {};
};

View File

@ -12,12 +12,14 @@ const main = defineHelper(__dirname, "main", `
}
`);
module.exports = {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
module.exports = function() {
return {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
},
},
},
};
};

View File

@ -17,12 +17,14 @@ const main = defineHelper(__dirname, "main", `
}
`);
module.exports = {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
module.exports = function() {
return {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
},
},
},
};
};

View File

@ -8,12 +8,14 @@ const main = defineHelper(__dirname, "main", `
}
`);
module.exports = {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
module.exports = function() {
return {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
},
},
},
};
};

View File

@ -17,12 +17,14 @@ const main = defineHelper(__dirname, "main", `
}
`);
module.exports = {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
module.exports = function() {
return {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
},
},
},
};
};

View File

@ -15,12 +15,14 @@ const main = defineHelper(__dirname, "main", `
}
`);
module.exports = {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
module.exports = function() {
return {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
},
},
},
};
};

View File

@ -14,12 +14,14 @@ const main = defineHelper(__dirname, "main", `
}
`);
module.exports = {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
module.exports = function() {
return {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
},
},
},
};
};

View File

@ -12,16 +12,18 @@ const main = defineHelper(__dirname, "main", `
}
`);
module.exports = {
visitor: {
Identifier(path) {
if (path.node.name === "REPLACE_ME_1") {
const mainHelper = this.addHelper(main);
path.replaceWith(mainHelper);
} else if (path.node.name === "REPLACE_ME_2") {
const dependencyHelper = this.addHelper(dependency);
path.replaceWith(dependencyHelper);
}
module.exports = function() {
return {
visitor: {
Identifier(path) {
if (path.node.name === "REPLACE_ME_1") {
const mainHelper = this.addHelper(main);
path.replaceWith(mainHelper);
} else if (path.node.name === "REPLACE_ME_2") {
const dependencyHelper = this.addHelper(dependency);
path.replaceWith(dependencyHelper);
}
},
},
},
};
};

View File

@ -15,12 +15,14 @@ const main = defineHelper(__dirname, "main", `
}
`);
module.exports = {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
module.exports = function() {
return {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") return;
const helper = this.addHelper(main);
path.replaceWith(helper);
},
},
},
};
};