Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/babel-core/src/config/option-manager.js
Expand Up @@ -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",
Expand Down
Expand Up @@ -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')]
};
};
@@ -1,5 +1,7 @@
module.exports = {
plugins: [
require('../../../../../babel-plugin-syntax-decorators'),
]
module.exports = function() {
return {
plugins: [
require('../../../../../babel-plugin-syntax-decorators'),
]
};
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Expand Up @@ -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);
},
},
},
};
};
16 changes: 9 additions & 7 deletions packages/babel-helpers/test/fixtures/dependencies/deep/plugin.js
Expand Up @@ -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);
},
},
},
};
};
Expand Up @@ -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);
},
},
},
};
};
Expand Up @@ -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);
},
},
},
};
};
Expand Up @@ -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);
},
},
},
};
};
Expand Up @@ -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);
},
},
},
};
};
Expand Up @@ -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);
}
},
},
},
};
};
Expand Up @@ -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);
},
},
},
};
};