Skip to content

Commit

Permalink
Do not generate mangled selector if mangling is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Machy8 committed Feb 13, 2023
1 parent 488b414 commit dea1d4d
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions packages/stylify/src/Compiler/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,9 @@ export class Compiler {
contentToProcess = contentToProcess.replace(
/\[([^{}\s]+)\]{([^{}]+)}/g,
(fullMatch: string, cssSelectors: string, stylifySelectors: string) => {
const customSelector = MacroMatch.replaceCharactersAliases(cssSelectors);
const customSelectorSelector = this.mangleSelectors
? minifiedSelectorGenerator.generateMangledSelector(fullMatch, null)
: fullMatch;

this.addCustomSelector(
customSelectorSelector,
`${customSelector}{${stylifySelectors.replace(/;/g, ' ')}}`,
this.generateMangledSelector(fullMatch, null),
`${MacroMatch.replaceCharactersAliases(cssSelectors)}{${stylifySelectors.replace(/;/g, ' ')}}`,
false,
'customMatchedInClass'
);
Expand All @@ -471,12 +466,8 @@ export class Compiler {
contentToProcess = contentToProcess.replace(
/(\S+):{([^{}]+)}/g,
(fullMatch: string, screenAndPseudoClasses: string, stylifySelectors: string) => {
const customSelectorSelector = this.mangleSelectors
? minifiedSelectorGenerator.generateMangledSelector(fullMatch, null)
: fullMatch;

this.addCustomSelector(
customSelectorSelector,
this.generateMangledSelector(fullMatch, null),
stylifySelectors.split(';')
.map((stylifySelector) => `${screenAndPseudoClasses}:${stylifySelector}`)
.join(' '),
Expand Down Expand Up @@ -537,6 +528,14 @@ export class Compiler {
return contentOptions as Data;
}

private generateMangledSelector(selector: string, prefix: string|null = '.'): string {
if (!this.mangleSelectors) {
return selector;
}

return minifiedSelectorGenerator.generateMangledSelector(selector, prefix);
}

private configureCompilationResult(compilationResult: CompilationResult): CompilationResult
{
const newLine = this.dev ? '\n' : '';
Expand Down Expand Up @@ -634,7 +633,7 @@ export class Compiler {
const isUtilitiesGroup = config.type === 'utilitiesGroup';
const isCustomSelectorMatchedInClass = config.type === 'customMatchedInClass';
const isClassSelector = isComponent || isUtilitiesGroup || isCustomSelectorMatchedInClass;
const preparedEscapedSelector = this.mangleSelectors || config.type === 'custom'
const preparedEscapedSelector = this.mangleSelectors || config.type === 'custom'
? selector
: escapeCssSelector(selector, isComponent || isUtilitiesGroup || isCustomSelectorMatchedInClass);

Expand Down Expand Up @@ -670,7 +669,7 @@ export class Compiler {

return fullMatch.substring(1).replace(
prepareStringForReplace(clearedComponentName),
`.${minifiedSelectorGenerator.generateMangledSelector(clearedComponentName)}`
`.${this.generateMangledSelector(clearedComponentName)}`
);
});
}
Expand Down Expand Up @@ -715,8 +714,7 @@ export class Compiler {
})
: selectorsOrGenerator;

minifiedSelectorGenerator.generateMangledSelector(componentSelector);

this.generateMangledSelector(componentSelector);
this.addCustomSelector(componentSelector, componentSelectors, false, 'component');
}
}
Expand Down

0 comments on commit dea1d4d

Please sign in to comment.