Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

use object assign when passing options #147

Merged
merged 2 commits into from
Jun 2, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function cssnext(string, options) {
if (options.import !== false) {
postcssInstance.use(require("postcss-import")(
typeof options.import === "object"
? options.import
? assign({}, options.import)
: undefined
)
)
Expand All @@ -155,7 +155,7 @@ function cssnext(string, options) {
if (options.url !== false) {
postcssInstance.use(require("postcss-url")(
typeof options.url === "object"
? options.url
? assign({}, options.url)
: undefined
)
)
Expand Down Expand Up @@ -186,7 +186,7 @@ function cssnext(string, options) {
) {
postcssInstance.use(cssnext.features[key](
typeof features[key] === "object"
? features[key]
? assign({}, features[key])
: undefined
)
)
Expand All @@ -201,7 +201,7 @@ function cssnext(string, options) {
assign(
{},
typeof options.compress === "object"
? options.compress
? assign({}, options.compress)
: {},
// forced calc options to false
// since we already used it
Expand Down
21 changes: 17 additions & 4 deletions test/option.import.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ test("cssnext import option", function(t) {
options: utils.readFixture("import.options.expected").trim(),
}
var opts = {from: "test/fixtures/here"}
function transformFn(c) {
return c + "\n new {}"
}
t.equal(
cssnext(input, opts).trim(),
expected.default,
Expand All @@ -23,9 +26,7 @@ test("cssnext import option", function(t) {
cssnext(input, {
from: opts.from,
import: {
transform: function(c) {
return c + "\n new {}"
},
transform: transformFn,
},
}).trim(),
expected.options,
Expand All @@ -36,6 +37,18 @@ test("cssnext import option", function(t) {
expected.default,
"should be able to import even as a postcss plugin"
)

var importOpt = {
transform: transformFn,
}
Object.freeze(importOpt)
t.doesNotThrow(function() {
cssnext(input, {
from: opts.from,
import: importOpt,
}).trim()
},
expected.options,
"should not use original object as option"
)
t.end()
})