stylelint-css-in-js-syntax
Version:
This plugin provides [ESLint](https://eslint.org/) rules that limit the line length of your comments. Furthermore, an **automatic fix** is included such that you can save time manually formatting your comments. As such it is recommended to apply this rule
35 lines (33 loc) • 946 B
JavaScript
function extractQuasisAndExpressions(css) {
const quasis = [];
const expressions = [];
let current = "";
let indentation = 0;
for (let cursor = 0; cursor < css.length; cursor++) {
const currentChar = css[cursor];
const nextChar = css[cursor + 1];
if (!indentation && currentChar === "$" && nextChar === "{") {
indentation++;
quasis.push({ value: { cooked: current } });
current = "";
cursor += 1;
continue;
}
if (indentation && currentChar === "{") {
indentation++;
}
if (indentation && currentChar === "}") {
indentation--;
if (indentation === 0) {
expressions.push(current);
current = "";
continue;
}
}
current += css[cursor];
}
quasis.push({ value: { cooked: current } });
return { quasis, expressions };
}
export { extractQuasisAndExpressions };
//# sourceMappingURL=util.extract-quasis-and-expressions.mjs.map