Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 14 additions & 8 deletions packages/@react-spectrum/s2/style/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,23 @@ export function mergeStyles(...styles: (StyleString | null | undefined)[]): Styl
}

let map = new Map<string, string>();
let macroClasses: string[] = [];
let macroClasses: string[] | undefined;

if (process.env.NODE_ENV !== 'production') {
macroClasses = [];
}

for (let style of definedStyles) {
// must call toString here for the static macro
let str = style.toString();

// Extract and preserve macro debug classes
let macroMatches = str.matchAll(/-macro-(static|dynamic)-[^\s]+/g);
for (let match of macroMatches) {
if (!macroClasses.includes(match[0])) {
macroClasses.push(match[0]);
// Extract and preserve macro debug classes (dev only)
if (process.env.NODE_ENV !== 'production') {
let macroMatches = str.matchAll(/-macro-(static|dynamic)-[^\s]+/g);
for (let match of macroMatches) {
if (!macroClasses!.includes(match[0])) {
macroClasses!.push(match[0]);
}
}
}

Expand All @@ -73,8 +79,8 @@ export function mergeStyles(...styles: (StyleString | null | undefined)[]): Styl
res += value;
}

// Append all macro debug classes
if (macroClasses.length > 0) {
// Append all macro debug classes (dev only)
if (process.env.NODE_ENV !== 'production' && macroClasses && macroClasses.length > 0) {
res += ' ' + macroClasses.join(' ');
}

Expand Down
11 changes: 7 additions & 4 deletions packages/@react-spectrum/s2/style/style-macro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ export function createTheme<T extends Theme>(theme: T): StyleFunction<ThemePrope
// Also generate a variable for each overridable property that overlaps with the style definition. If those are defined,
// the defaults from the style definition are omitted.
let allowedOverridesSet = new Set<string>();
let js = 'let rules = " ", currentRules = {};\n';
let js = process.env.NODE_ENV !== 'production'
? 'let rules = " ", currentRules = {};\n'
: 'let rules = " ";\n';
if (allowedOverrides?.length) {
for (let property of allowedOverrides) {
let shorthand = theme.shorthands[property];
Expand Down Expand Up @@ -351,7 +353,8 @@ export function createTheme<T extends Theme>(theme: T): StyleFunction<ThemePrope
}
}

let regex = `/(?:^|\\s)(${[...allowedOverridesSet].map(p => classNamePrefix(p, p)).join('|')}|-macro\\$)[^\\s]+/g`;
let macroPart = process.env.NODE_ENV !== 'production' ? '|-macro\\$' : '';
let regex = `/(?:^|\\s)(${[...allowedOverridesSet].map(p => classNamePrefix(p, p)).join('|')}${macroPart})[^\\s]+/g`;
if (loop) {
js += `let matches = String(overrides || '').matchAll(${regex});\n`;
js += 'for (let p of matches) {\n';
Expand Down Expand Up @@ -682,7 +685,7 @@ class StyleRule implements Rule {
this.pseudos = '';
this.property = property;
this.value = value;
if (isCompilingDependencies !== null) {
if (process.env.NODE_ENV !== 'production' && isCompilingDependencies !== null) {
this.themeProperty = themeProperty;
this.themeValue = themeValue;
}
Expand Down Expand Up @@ -732,7 +735,7 @@ class StyleRule implements Rule {
res += `${indent}if (!${this.property.replace('--', '__')}) `;
}
res += `${indent}rules += ' ${this.className}';`;
if (this.themeProperty) {
if (process.env.NODE_ENV !== 'production' && this.themeProperty) {
let name = this.themeProperty;
if (this.pseudos) {
conditionStack.push(this.pseudos);
Expand Down