Skip to content
Merged
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
28 changes: 2 additions & 26 deletions src/compiler/atRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,13 @@ export interface ReactNativeAtRule {

export function maybeMutateReactNativeOptions(
rule: Rule | ReactNativeAtRule,
builder: StylesheetBuilder,
_builder: StylesheetBuilder,
) {
if (rule.type !== "custom" || rule.value?.name !== "react-native") {
return;
}

const { declarations } = rule.value.body.value;
if (!declarations) return;

for (const declaration of declarations) {
if (declaration.property !== "custom") continue;

switch (declaration.value.name) {
case "preserve-variables": {
declaration.value.value.forEach((token) => {
if (token.type !== "dashed-ident") {
return;
}

if (token.value !== "true" && token.value !== "false") {
return;
}

builder.setOptions("preserveVariables", token.value === "true");
});
break;
}
default:
break;
}
}
// TODO: Add inline options
}

/***********************************************
Expand Down
25 changes: 2 additions & 23 deletions src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
type CustomAtRules,
type MediaRule,
type Rule,
type TokenOrValue,
type Visitor,
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import type TokenOrValue was removed but there's a typo in the PR title: 'unusued' should be 'unused'.

Suggested change
type Visitor,

Copilot uses AI. Check for mistakes.
} from "lightningcss";

Expand Down Expand Up @@ -89,7 +88,8 @@ export function compile(code: Buffer | string, options: CompilerOptions = {}) {
} else {
logger(
`firstPass buffer too large to log in full (${firstPass.length} bytes). Preview: ` +
firstPass.subarray(0, 1024).toString() + "..."
firstPass.subarray(0, 1024).toString() +
"...",
);
}
}
Expand Down Expand Up @@ -126,27 +126,6 @@ export function compile(code: Buffer | string, options: CompilerOptions = {}) {
},
};

if (options.stripUnusedVariables) {
const onVarUsage = (token: TokenOrValue) => {
if (token.type === "function") {
token.value.arguments.forEach((token) => onVarUsage(token));
} else if (token.type === "var") {
builder.varUsage.add(token.value.name.ident);
if (token.value.fallback) {
const fallbackValues = token.value.fallback;
fallbackValues.forEach((varObj) => onVarUsage(varObj));
}
}
};

visitor.Declaration = (decl) => {
if (decl.property === "unparsed" || decl.property === "custom") {
decl.value.value.forEach((token) => onVarUsage(token));
}
return decl;
};
}

lightningcss({
code: firstPass,
visitor,
Expand Down
5 changes: 0 additions & 5 deletions src/compiler/compiler.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ export interface CompilerOptions {
stylesheetOrder?: number;
features?: FeatureFlagRecord;
logger?: (message: string) => void | Debugger;
/** Strip unused variables declarations. Defaults: false */
stripUnusedVariables?: boolean;
/** @internal */
ignorePropertyWarningRegex?: (string | RegExp)[];
preserveVariables?: boolean;
hexColors?: boolean;
colorPrecision?: number;
}
Expand Down
9 changes: 0 additions & 9 deletions src/compiler/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,6 @@ export class StylesheetBuilder {
forceTuple,
);
} else if (property.startsWith("--")) {
// If we have enabled variable usage tracking, skip unused variables
if (
this.options.stripUnusedVariables &&
!property.startsWith("--__rn-css") &&
!this.varUsage.has(property)
) {
return;
}

rule.v ??= [];
rule.v.push([property.slice(2), value]);
} else if (isStyleFunction(value)) {
Expand Down