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

Commit a9dea4e

Browse files
committed
Merge pull request #147 from cssnext/fix/import-mutability
use object assign when passing options to atImport plugin
2 parents 513e9cd + 143fb7f commit a9dea4e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function cssnext(string, options) {
145145
if (options.import !== false) {
146146
postcssInstance.use(require("postcss-import")(
147147
typeof options.import === "object"
148-
? options.import
148+
? assign({}, options.import)
149149
: undefined
150150
)
151151
)
@@ -155,7 +155,7 @@ function cssnext(string, options) {
155155
if (options.url !== false) {
156156
postcssInstance.use(require("postcss-url")(
157157
typeof options.url === "object"
158-
? options.url
158+
? assign({}, options.url)
159159
: undefined
160160
)
161161
)
@@ -186,7 +186,7 @@ function cssnext(string, options) {
186186
) {
187187
postcssInstance.use(cssnext.features[key](
188188
typeof features[key] === "object"
189-
? features[key]
189+
? assign({}, features[key])
190190
: undefined
191191
)
192192
)
@@ -201,7 +201,7 @@ function cssnext(string, options) {
201201
assign(
202202
{},
203203
typeof options.compress === "object"
204-
? options.compress
204+
? assign({}, options.compress)
205205
: {},
206206
// forced calc options to false
207207
// since we already used it

test/option.import.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ test("cssnext import option", function(t) {
1414
options: utils.readFixture("import.options.expected").trim(),
1515
}
1616
var opts = {from: "test/fixtures/here"}
17+
function transformFn(c) {
18+
return c + "\n new {}"
19+
}
1720
t.equal(
1821
cssnext(input, opts).trim(),
1922
expected.default,
@@ -23,9 +26,7 @@ test("cssnext import option", function(t) {
2326
cssnext(input, {
2427
from: opts.from,
2528
import: {
26-
transform: function(c) {
27-
return c + "\n new {}"
28-
},
29+
transform: transformFn,
2930
},
3031
}).trim(),
3132
expected.options,
@@ -36,6 +37,18 @@ test("cssnext import option", function(t) {
3637
expected.default,
3738
"should be able to import even as a postcss plugin"
3839
)
39-
40+
var importOpt = {
41+
transform: transformFn,
42+
}
43+
Object.freeze(importOpt)
44+
t.doesNotThrow(function() {
45+
cssnext(input, {
46+
from: opts.from,
47+
import: importOpt,
48+
}).trim()
49+
},
50+
expected.options,
51+
"should not use original object as option"
52+
)
4053
t.end()
4154
})

0 commit comments

Comments
 (0)