Skip to content

Commit

Permalink
remove duplicate tokens from categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Siekmann committed Sep 24, 2021
1 parent 820f93b commit 94a1d80
Showing 1 changed file with 38 additions and 30 deletions.
68 changes: 38 additions & 30 deletions addon/src/parsers/postcss.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,38 +105,46 @@ function determineTokensForCategory(
(!range.to || (declaration.source?.start?.line || -1) <= range.to.line)
);

return declarationsWithinRange.map((declaration) => {
const description = comments.find(
(comment) =>
comment.source?.input.file === declaration.source?.input.file &&
comment.source?.start?.line === declaration.source?.end?.line
);

const value = determineTokenValue(declaration.value, declarations);
let presenterToken: TokenPresenter | undefined;

if (description) {
const presenterResultsToken = /@presenter (.+)/g.exec(description.text);

if (presenterResultsToken) {
presenterToken = presenterResultsToken[1] as TokenPresenter;
description.text = description.text.replace(
presenterResultsToken[0] || '',
''
);
return declarationsWithinRange
.map((declaration) => {
const description = comments.find(
(comment) =>
comment.source?.input.file === declaration.source?.input.file &&
comment.source?.start?.line === declaration.source?.end?.line
);

const value = determineTokenValue(declaration.value, declarations);
let presenterToken: TokenPresenter | undefined;

if (description) {
const presenterResultsToken = /@presenter (.+)/g.exec(description.text);

if (presenterResultsToken) {
presenterToken = presenterResultsToken[1] as TokenPresenter;
description.text = description.text.replace(
presenterResultsToken[0] || '',
''
);
}
}
}

return {
description: description?.text,
isAlias: value !== declaration.value,
name: declaration.prop,
presenter: presenterToken || presenter,
rawValue: declaration.value,
sourceType,
value
};
});
return {
description: description?.text,
isAlias: value !== declaration.value,
name: declaration.prop,
presenter: presenterToken || presenter,
rawValue: declaration.value,
sourceType,
value
};
})
.slice()
.reverse()
.filter(
(token, index, tokens) =>
index === tokens.findIndex((t) => t.name === token.name)
)
.reverse();
}

function determineTokenValue(
Expand Down

0 comments on commit 94a1d80

Please sign in to comment.