Merge pull request #3638 from babel/christophehurpeau-patch-2

[Bug Fix] option manager: val = val.buildPreset should be before the check if the preset supports options
This commit is contained in:
Henry Zhu 2016-08-05 09:49:33 -04:00 committed by GitHub
commit 96f31ed38f
34 changed files with 153 additions and 7 deletions

View File

@ -268,16 +268,17 @@ export default class OptionManager {
val = require(presetLoc);
}
if (typeof val !== "function" && options !== undefined) {
throw new Error(`Options ${JSON.stringify(options)} passed to ` +
(presetLoc || "a preset") + " which does not accept options.");
}
// For compatibility with babel-core < 6.13.x, allow presets to export an object with a
// a 'buildPreset' function that will return the preset itself, while still exporting a
// simple object (rather than a function), for supporting old Babel versions.
if (typeof val === "object" && val.buildPreset) val = val.buildPreset;
if (typeof val !== "function" && options !== undefined) {
throw new Error(`Options ${JSON.stringify(options)} passed to ` +
(presetLoc || "a preset") + " which does not accept options.");
}
if (typeof val === "function") val = val(context, options);
if (typeof val !== "object") {

View File

@ -44,7 +44,11 @@ function run(task) {
newOpts.plugins = wrapPackagesArray("plugin", newOpts.plugins);
newOpts.presets = wrapPackagesArray("preset", newOpts.presets).map(function (val) {
return val[0];
if (val.length > 2) {
throw new Error(`Unexpected extra options ${JSON.stringify(val.slice(2))} passed to preset.`);
}
return val;
});
return newOpts;

View File

@ -34,6 +34,7 @@
"babel-plugin-transform-regenerator": "^6.9.0"
},
"devDependencies": {
"babel-helper-transform-fixture-test-runner": "^6.9.0"
"babel-helper-transform-fixture-test-runner": "^6.9.0",
"babel-helper-plugin-test-runner": "^6.8.0"
}
}

View File

@ -0,0 +1 @@
export function a () {}

View File

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.a = a;
function a() {}

View File

@ -0,0 +1,5 @@
{
"presets": [
["es2015", {}]
]
}

View File

@ -0,0 +1 @@
export function a () {}

View File

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.a = a;
function a() {}

View File

@ -0,0 +1,5 @@
{
"presets": [
["es2015", { "loose": false }]
]
}

View File

@ -0,0 +1 @@
export function a () {}

View File

@ -0,0 +1,5 @@
"use strict";
exports.__esModule = true;
exports.a = a;
function a() {}

View File

@ -0,0 +1,5 @@
{
"presets": [
["es2015", { "loose": true }]
]
}

View File

@ -0,0 +1 @@
export function a () {}

View File

@ -0,0 +1,7 @@
define(["exports"], function (exports) {
"use strict";
exports.__esModule = true;
exports.a = a;
function a() {}
});

View File

@ -0,0 +1,5 @@
{
"presets": [
["es2015", { "modules": "amd", "loose": true }]
]
}

View File

@ -0,0 +1 @@
export function a () {}

View File

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.a = a;
function a() {}

View File

@ -0,0 +1,5 @@
{
"presets": [
["es2015", { "modules": "commonjs" }]
]
}

View File

@ -0,0 +1 @@
export function a () {}

View File

@ -0,0 +1 @@
export function a() {}

View File

@ -0,0 +1,5 @@
{
"presets": [
["es2015", { "modules": false }]
]
}

View File

@ -0,0 +1 @@
export function a () {}

View File

@ -0,0 +1,12 @@
System.register([], function (_export, _context) {
"use strict";
function a() {}
_export("a", a);
return {
setters: [],
execute: function () {}
};
});

View File

@ -0,0 +1,5 @@
{
"presets": [
["es2015", { "modules": "systemjs" }]
]
}

View File

@ -0,0 +1 @@
export function a () {}

View File

@ -0,0 +1,21 @@
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(["exports"], factory);
} else if (typeof exports !== "undefined") {
factory(exports);
} else {
var mod = {
exports: {}
};
factory(mod.exports);
global.actual = mod.exports;
}
})(this, function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.a = a;
function a() {}
});

View File

@ -0,0 +1,5 @@
{
"presets": [
["es2015", { "modules": "umd" }]
]
}

View File

@ -0,0 +1 @@
export function a () {}

View File

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.a = a;
function a() {}

View File

@ -0,0 +1,5 @@
{
"presets": [
["es2015"]
]
}

View File

@ -0,0 +1 @@
export function a () {}

View File

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.a = a;
function a() {}

View File

@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}

View File

@ -0,0 +1 @@
require("babel-helper-plugin-test-runner")(__dirname);