wWhen merging options, take precedence over the current array - fixes #2648

This commit is contained in:
Sebastian McKenzie
2015-11-02 19:21:24 +00:00
parent 72f384bb29
commit 2bdc222c0b
2 changed files with 16 additions and 5 deletions

View File

@@ -7,13 +7,15 @@ export default function (dest?: Object, src?: Object): ?Object {
return merge(dest, src, function (a, b) {
if (b && Array.isArray(a)) {
let c = a.slice(0);
for (let v of b) {
if (a.indexOf(v) < 0) {
c.push(v);
let newArray = b.slice(0);
for (let item of a) {
if (newArray.indexOf(item) < 0) {
newArray.push(item);
}
}
return c;
return newArray;
}
});
}

View File

@@ -24,6 +24,15 @@ function transformAsync(code, opts) {
}
suite("api", function () {
test("options merge backwards", function () {
return transformAsync("", {
presets: [__dirname + "/../../babel-preset-es2015"],
plugins: [__dirname + "/../../babel-plugin-syntax-jsx"]
}).then(function (result) {
assert.ok(result.options.plugins[0][0].manipulateOptions.toString().indexOf("jsx") >= 0);
});
});
test("code option false", function () {
return transformAsync("foo('bar');", { code: false }).then(function (result) {
assert.ok(!result.code);