Skip to content
Permalink
Browse files

feat: option to suppress value export (#673)

Fixes #672
  • Loading branch information...
lunsdorf authored and tivac committed Sep 23, 2019
1 parent ac8ea56 commit 97a5b1ea70f600d9effc3df539c7c1e0923da018
@@ -224,6 +224,18 @@ new Processor({
*/
```

### `exportValues`

Enable exporting `@value` identifiers.

**Default**: `true`

```js
new Processor({
exportValues : false
});
```

## Properties

### `.files`
@@ -37,13 +37,14 @@ class Processor {
const options = Object.assign(
Object.create(null),
{
cwd : process.cwd(),
map : false,
rewrite : true,
verbose : false,
resolvers : [],
postcss : {},
dupewarn : true,
cwd : process.cwd(),
dupewarn : true,
exportValues : true,
map : false,
postcss : {},
resolvers : [],
rewrite : true,
verbose : false,
},
opts
);
@@ -379,8 +380,11 @@ class Processor {

file.exports = Object.assign(
Object.create(null),
// export @value entries
mapValues(file.values, ({ value }) => value),

// optionally export @value entries
this._options.exportValues ?
mapValues(file.values, ({ value }) => value) :
null,

// export classes
message(result, "classes"),
@@ -8,6 +8,23 @@ Object {
}
`;

exports[`/processor.js options exportValues should not export @values by default 1`] = `
Object {
"a": "#F00",
"b": Array [
"mc61ce7a4a_b",
],
}
`;

exports[`/processor.js options exportValues should not export @values when exportValues is false 1`] = `
Object {
"b": Array [
"mc8df92ddf_b",
],
}
`;

exports[`/processor.js options lifecycle options after should run async postcss plugins 1`] = `
"/* packages/processor/test/specimens/relative.css */
.wooga {
@@ -146,6 +146,38 @@ describe("/processor.js", () => {
});
});

describe("exportValues", () => {
it("should export @values by default", async () => {
const processor = new Processor({});

const { exports } = await processor.string(
"./exportValues.css",
dedent(`
@value a: #F00;
.b {}
`)
);

expect(exports).toMatchSnapshot();
});

it("should not export @values when exportValues is false", async () => {
const processor = new Processor({
exportValues : false,
});

const { exports } = await processor.string(
"./exportGlobals.css",
dedent(`
@value a: #F00;
.b {}
`)
);

expect(exports).toMatchSnapshot();
});
});

describe("rewrite", () => {
it("should rewrite url() references by default", async () => {
const processor = new Processor();

0 comments on commit 97a5b1e

Please sign in to comment.
You can’t perform that action at this time.