Skip to content

Commit

Permalink
Fix duplicate custom selector definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Machy8 committed Jan 18, 2023
1 parent e6831e6 commit 1d066fb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
9 changes: 6 additions & 3 deletions packages/stylify/src/Compiler/CustomSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class CustomSelector {
continue;
}

selectors[selectorToAdd] = selectorsOrChildren;
selectors[selectorToAdd] = [selectors[selectorToAdd] ?? '', selectorsOrChildren].join(' ');
continue;
}

Expand All @@ -59,7 +59,7 @@ export class CustomSelector {
};

processTree(rootSelector, this.tree);

console.log(selectors);
return selectors;
}

Expand All @@ -72,7 +72,10 @@ export class CustomSelector {
let contentIterator = 0;
const contentlength = content.length;

const parseContent = (content: string, actualTree: CustomSelectorTreeItemInterface): any => {
const parseContent = (
content: string,
actualTree: CustomSelectorTreeItemInterface
): CustomSelectorTreeItemInterface => {
let tokenQueue = '';

while (contentIterator < contentlength) {
Expand Down
28 changes: 26 additions & 2 deletions packages/stylify/tests/jest/custom-selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ beforeEach(() => {
});

test('Custom selectors - only set', (): void => {
const customSelectorsSet = {
const customSelectors = {
'*': 'box-sizing:border-box',
'body': 'font-size:16px',
'article h1': 'font-size:16px',
Expand All @@ -20,7 +20,7 @@ test('Custom selectors - only set', (): void => {

const compiler = new Compiler({
dev: true,
customSelectors: customSelectorsSet
customSelectors
});

let compilationResult = compiler.compile(testUtils.getHtmlInputFile());
Expand Down Expand Up @@ -56,3 +56,27 @@ test('Random order', (): void => {

testUtils.testCssFileToBe(compilationResult.generateCss(), 'random-order');
});

test('Duplicate definition', (): void => {
const customSelectors = {
'article': `
h1, h2 {
color:blue
span { margin:24px }
}
h2 {
font-size:24px
span { font-weight:bold }
}
`
};

const compiler = new Compiler({
dev: true,
customSelectors
});

let compilationResult = compiler.compile('<article></article>');

testUtils.testCssFileToBe(compilationResult.generateCss(), 'duplicate-definition');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
article h1,
article h2{
color: blue
}
article h1 span,
article h2 span{
margin: 24px
}
article h2{
font-size: 24px
}
article h2 span{
font-weight: bold
}

0 comments on commit 1d066fb

Please sign in to comment.