Skip to content

Commit b7823a8

Browse files
authored
Merge pull request #42 from jerrysu/master
Add multi-line imports
2 parents b9cfa00 + c667c96 commit b7823a8

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

lib/index.js

+2-2
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, result) {
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

+2-2
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, result) => {
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

+20
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,24 @@ describe('constants', () => {
120120
':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' +
121121
'.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); }')
122122
})
123+
124+
it('should import multiple from a single file on multiple lines', () => {
125+
test(
126+
`@value (
127+
blue,
128+
red
129+
) from "./colors.css";
130+
.foo { color: red; }
131+
.bar { color: blue }`,
132+
`:import("./colors.css") {
133+
i__const_blue_10: blue;
134+
i__const_red_11: red;
135+
}
136+
:export {
137+
blue: i__const_blue_10;
138+
red: i__const_red_11;
139+
}
140+
.foo { color: i__const_red_11; }
141+
.bar { color: i__const_blue_10 }`)
142+
})
123143
})

0 commit comments

Comments
 (0)