-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not require quotes on rules creation
- Loading branch information
Showing
3 changed files
with
42 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
import postcss from 'postcss' | ||
import postcss from "postcss"; | ||
|
||
const createImports = imports => { | ||
return Object.keys(imports).map(path => { | ||
const aliases = imports[path] | ||
const aliases = imports[path]; | ||
const declarations = Object.keys(aliases).map(key => | ||
postcss.decl({ | ||
prop: key, | ||
value: aliases[key], | ||
raws: { before: '\n ' } | ||
raws: { before: "\n " } | ||
}) | ||
) | ||
); | ||
return postcss | ||
.rule({ | ||
selector: `:import(${path})`, | ||
raws: { after: '\n' } | ||
selector: `:import('${path}')`, | ||
raws: { after: "\n" } | ||
}) | ||
.append(declarations) | ||
}) | ||
} | ||
.append(declarations); | ||
}); | ||
}; | ||
|
||
const createExports = exports => { | ||
const declarations = Object.keys(exports).map(key => | ||
postcss.decl({ | ||
prop: key, | ||
value: exports[key], | ||
raws: { before: '\n ' } | ||
raws: { before: "\n " } | ||
}) | ||
) | ||
); | ||
if (declarations.length === 0) { | ||
return [] | ||
return []; | ||
} | ||
const rule = postcss | ||
.rule({ | ||
selector: `:export`, | ||
raws: { after: '\n' } | ||
raws: { after: "\n" } | ||
}) | ||
.append(declarations) | ||
return [rule] | ||
} | ||
.append(declarations); | ||
return [rule]; | ||
}; | ||
|
||
const createICSSRules = (imports, exports) => [ | ||
...createImports(imports), | ||
...createExports(exports) | ||
] | ||
]; | ||
|
||
export default createICSSRules | ||
export default createICSSRules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { default as replaceValueSymbols } from './replaceValueSymbols.js' | ||
export { default as replaceSymbols } from './replaceSymbols.js' | ||
export { default as extractICSS } from './extractICSS.js' | ||
export { default as createICSSRules } from './createICSSRules.js' | ||
export { default as replaceValueSymbols } from "./replaceValueSymbols.js"; | ||
export { default as replaceSymbols } from "./replaceSymbols.js"; | ||
export { default as extractICSS } from "./extractICSS.js"; | ||
export { default as createICSSRules } from "./createICSSRules.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,47 @@ | ||
import postcss from 'postcss' | ||
import { createICSSRules } from '../src' | ||
/* eslint-env jest */ | ||
import postcss from "postcss"; | ||
import { createICSSRules } from "../src"; | ||
|
||
const run = (imports, exports) => { | ||
return postcss.root().append(createICSSRules(imports, exports)).toString() | ||
} | ||
return postcss.root().append(createICSSRules(imports, exports)).toString(); | ||
}; | ||
|
||
test('create :import statement', () => { | ||
test("create :import statement", () => { | ||
expect( | ||
run( | ||
{ | ||
colors: { | ||
a: 'b', | ||
c: 'd' | ||
}, | ||
'"path/file"': { | ||
e: 'f' | ||
"path/file": { | ||
e: "f" | ||
} | ||
}, | ||
{} | ||
) | ||
).toEqual( | ||
':import(colors) {\n a: b;\n c: d\n}\n:import("path/file") {\n e: f\n}' | ||
) | ||
}) | ||
).toEqual(":import('path/file') {\n e: f\n}"); | ||
}); | ||
|
||
test('create :export statement', () => { | ||
test("create :export statement", () => { | ||
expect( | ||
run( | ||
{}, | ||
{ | ||
a: 'b', | ||
c: 'd' | ||
a: "b", | ||
c: "d" | ||
} | ||
) | ||
).toEqual(':export {\n a: b;\n c: d\n}') | ||
}) | ||
).toEqual(":export {\n a: b;\n c: d\n}"); | ||
}); | ||
|
||
test('create :import and :export', () => { | ||
test("create :import and :export", () => { | ||
expect( | ||
run( | ||
{ | ||
colors: { | ||
a: 'b' | ||
a: "b" | ||
} | ||
}, | ||
{ | ||
c: 'd' | ||
c: "d" | ||
} | ||
) | ||
).toEqual(':import(colors) {\n a: b\n}\n:export {\n c: d\n}') | ||
}) | ||
).toEqual(":import('colors') {\n a: b\n}\n:export {\n c: d\n}"); | ||
}); |