1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = wrapInClass;
|
5 |
|
6 | var _commonTags = require("common-tags");
|
7 |
|
8 | function wrapInClass(text) {
|
9 | const imports = [];
|
10 | const composes = [];
|
11 | let match;
|
12 | const rImports = /@import.*?(?:$|;)/g;
|
13 | const rComposes = /\b(?:composes\s*?:\s*(.*?)(?:from\s(.+?))?(?=[}\n\r]))/gim;
|
14 |
|
15 | while (match = rImports.exec(text)) {
|
16 | imports.push(match[0]);
|
17 | }
|
18 |
|
19 | match = null;
|
20 |
|
21 | while (match = rComposes.exec(text)) {
|
22 | composes.push(match[0]);
|
23 | }
|
24 |
|
25 | text = text.replace(rImports, '').replace(rComposes, '');
|
26 |
|
27 | let val = _commonTags.stripIndents`
|
28 | .cls1 {
|
29 | ${text.trim() || '/*!*/'}
|
30 | }`;
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | if (composes.length) {
|
37 | composes.unshift(`composes: cls1;`);
|
38 | val += `\n.cls2 {\n${composes.join('\n')}\n}`;
|
39 | }
|
40 |
|
41 | if (imports.length) val = `${imports.join('\n')}\n${val}`;
|
42 | return val;
|
43 | } |
\ | No newline at end of file |