UNPKG

899 BJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.default = wrapInClass;
5
6var _commonTags = require("common-tags");
7
8function wrapInClass(text) {
9 const imports = [];
10 let match;
11 const rImports = /@import.*?(?:$|;)/g; // eslint-disable-next-line no-cond-assign
12
13 while (match = rImports.exec(text)) {
14 imports.push(match[0]);
15 }
16
17 text = text.replace(rImports, ''); // Components need two css classes, the actual style declarations and a hook class.
18 // We need both so that that interpolations have a class that is _only_
19 // the single class, e.g. no additional classes composed in so that it can be used
20 // as a selector
21 //
22 // comment prevents Sass from removing the empty class
23
24 let val = _commonTags.stripIndents`
25 .cls1 { /*!*/ }
26 .cls2 {
27 composes: cls1;
28
29 ${text.trim()}
30 }`;
31 if (imports.length) val = `${imports.join('\n')}\n${val}`;
32 return val;
33}
\No newline at end of file