Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: code
  • Loading branch information
alexander-akait committed Apr 3, 2024
commit 262eac95202622491f4dceb8ec87716acfaa1530
18 changes: 6 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const plugin = (options = {}) => {
Once(root, { rule }) {
const exports = Object.create(null);

function exportScopedName(name, rawName, node, needExport = true) {
function exportScopedName(name, rawName, node) {
const scopedName = generateScopedName(
rawName ? rawName : name,
root.source.input.from,
Expand All @@ -123,10 +123,6 @@ const plugin = (options = {}) => {
);
const { key, value } = exportEntry;

if (!needExport) {
return scopedName;
}

exports[key] = exports[key] || [];

if (exports[key].indexOf(value) < 0) {
Expand All @@ -136,27 +132,25 @@ const plugin = (options = {}) => {
return scopedName;
}

function localizeNode(node, needExport = true) {
function localizeNode(node) {
switch (node.type) {
case "selector":
node.nodes = node.map((item) => localizeNode(item, needExport));
node.nodes = node.map((item) => localizeNode(item));
return node;
case "class":
return selectorParser.className({
value: exportScopedName(
node.value,
node.raws && node.raws.value ? node.raws.value : null,
node,
needExport
node
),
});
case "id": {
return selectorParser.id({
value: exportScopedName(
node.value,
node.raws && node.raws.value ? node.raws.value : null,
node,
needExport
node
),
});
}
Expand All @@ -166,7 +160,7 @@ const plugin = (options = {}) => {
attribute: node.attribute,
operator: node.operator,
quoteMark: "'",
value: exportScopedName(node.value, null, null, needExport),
value: exportScopedName(node.value, null, null),
});
}
}
Expand Down