Skip to content

Commit c667c96

Browse files
committed
Add multi-line imports
1 parent aa28589 commit c667c96

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var _icssReplaceSymbols = require('icss-replace-symbols');
1616

1717
var _icssReplaceSymbols2 = _interopRequireDefault(_icssReplaceSymbols);
1818

19-
var matchImports = /^(.+?)\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/;
19+
var matchImports = /^(.+?|\([\s\S]+?\))\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/;
2020
var matchValueDefinition = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|\w+\([^\)]+\)|[^,]+)\s?/g;
2121
var matchImport = /^([\w-]+)(?:\s+as\s+([\w-]+))?/;
2222
var options = {};
@@ -55,7 +55,7 @@ exports['default'] = function (css) {
5555

5656
// We can use constants for path names
5757
if (definitions[path]) path = definitions[path];
58-
var imports = aliases.split(/\s*,\s*/).map(function (alias) {
58+
var imports = aliases.replace(/^\(\s*([\s\S]+)\s*\)$/, '$1').split(/\s*,\s*/).map(function (alias) {
5959
var tokens = matchImport.exec(alias);
6060
if (tokens) {
6161
var _tokens = _slicedToArray(tokens, 3);

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import postcss from 'postcss'
22
import replaceSymbols, { replaceAll } from 'icss-replace-symbols'
33

4-
const matchImports = /^(.+?)\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/
4+
const matchImports = /^(.+?|\([\s\S]+?\))\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/
55
const matchValueDefinition = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|\w+\([^\)]+\)|[^,]+)\s?/g
66
const matchImport = /^([\w-]+)(?:\s+as\s+([\w-]+))?/
77
let options = {}
@@ -28,7 +28,7 @@ export default css => {
2828
let [/*match*/, aliases, path] = matches
2929
// We can use constants for path names
3030
if (definitions[path]) path = definitions[path]
31-
let imports = aliases.split(/\s*,\s*/).map(alias => {
31+
let imports = aliases.replace(/^\(\s*([\s\S]+)\s*\)$/, '$1').split(/\s*,\s*/).map(alias => {
3232
let tokens = matchImport.exec(alias)
3333
if (tokens) {
3434
let [/*match*/, theirName, myName = theirName] = tokens

test/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,24 @@ describe('constants', () => {
110110
':export {\n named: red;\n 3char: #0f0;\n 6char: #00ff00;\n rgba: rgba(34, 12, 64, 0.3);\n hsla: hsla(220, 13.0%, 18.0%, 1);\n}\n' +
111111
'.foo { color: red; background-color: #0f0; border-top-color: #00ff00; border-bottom-color: rgba(34, 12, 64, 0.3); outline-color: hsla(220, 13.0%, 18.0%, 1); }')
112112
})
113+
114+
it('should import multiple from a single file on multiple lines', () => {
115+
test(
116+
`@value (
117+
blue,
118+
red
119+
) from "./colors.css";
120+
.foo { color: red; }
121+
.bar { color: blue }`,
122+
`:import("./colors.css") {
123+
i__const_blue_10: blue;
124+
i__const_red_11: red;
125+
}
126+
:export {
127+
blue: i__const_blue_10;
128+
red: i__const_red_11;
129+
}
130+
.foo { color: i__const_red_11; }
131+
.bar { color: i__const_blue_10 }`)
132+
})
113133
})

0 commit comments

Comments
 (0)