Skip to content

Commit 4513fe3

Browse files
authored
chore: remove unusued compiler variable tracking (#165)
1 parent 76d94c7 commit 4513fe3

File tree

4 files changed

+4
-63
lines changed

4 files changed

+4
-63
lines changed

src/compiler/atRules.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,13 @@ export interface ReactNativeAtRule {
3737

3838
export function maybeMutateReactNativeOptions(
3939
rule: Rule | ReactNativeAtRule,
40-
builder: StylesheetBuilder,
40+
_builder: StylesheetBuilder,
4141
) {
4242
if (rule.type !== "custom" || rule.value?.name !== "react-native") {
4343
return;
4444
}
4545

46-
const { declarations } = rule.value.body.value;
47-
if (!declarations) return;
48-
49-
for (const declaration of declarations) {
50-
if (declaration.property !== "custom") continue;
51-
52-
switch (declaration.value.name) {
53-
case "preserve-variables": {
54-
declaration.value.value.forEach((token) => {
55-
if (token.type !== "dashed-ident") {
56-
return;
57-
}
58-
59-
if (token.value !== "true" && token.value !== "false") {
60-
return;
61-
}
62-
63-
builder.setOptions("preserveVariables", token.value === "true");
64-
});
65-
break;
66-
}
67-
default:
68-
break;
69-
}
70-
}
46+
// TODO: Add inline options
7147
}
7248

7349
/***********************************************

src/compiler/compiler.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
type CustomAtRules,
1010
type MediaRule,
1111
type Rule,
12-
type TokenOrValue,
1312
type Visitor,
1413
} from "lightningcss";
1514

@@ -89,7 +88,8 @@ export function compile(code: Buffer | string, options: CompilerOptions = {}) {
8988
} else {
9089
logger(
9190
`firstPass buffer too large to log in full (${firstPass.length} bytes). Preview: ` +
92-
firstPass.subarray(0, 1024).toString() + "..."
91+
firstPass.subarray(0, 1024).toString() +
92+
"...",
9393
);
9494
}
9595
}
@@ -126,27 +126,6 @@ export function compile(code: Buffer | string, options: CompilerOptions = {}) {
126126
},
127127
};
128128

129-
if (options.stripUnusedVariables) {
130-
const onVarUsage = (token: TokenOrValue) => {
131-
if (token.type === "function") {
132-
token.value.arguments.forEach((token) => onVarUsage(token));
133-
} else if (token.type === "var") {
134-
builder.varUsage.add(token.value.name.ident);
135-
if (token.value.fallback) {
136-
const fallbackValues = token.value.fallback;
137-
fallbackValues.forEach((varObj) => onVarUsage(varObj));
138-
}
139-
}
140-
};
141-
142-
visitor.Declaration = (decl) => {
143-
if (decl.property === "unparsed" || decl.property === "custom") {
144-
decl.value.value.forEach((token) => onVarUsage(token));
145-
}
146-
return decl;
147-
};
148-
}
149-
150129
lightningcss({
151130
code: firstPass,
152131
visitor,

src/compiler/compiler.types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ export interface CompilerOptions {
1212
stylesheetOrder?: number;
1313
features?: FeatureFlagRecord;
1414
logger?: (message: string) => void | Debugger;
15-
/** Strip unused variables declarations. Defaults: false */
16-
stripUnusedVariables?: boolean;
17-
/** @internal */
18-
ignorePropertyWarningRegex?: (string | RegExp)[];
19-
preserveVariables?: boolean;
2015
hexColors?: boolean;
2116
colorPrecision?: number;
2217
}

src/compiler/stylesheet.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,6 @@ export class StylesheetBuilder {
331331
forceTuple,
332332
);
333333
} else if (property.startsWith("--")) {
334-
// If we have enabled variable usage tracking, skip unused variables
335-
if (
336-
this.options.stripUnusedVariables &&
337-
!property.startsWith("--__rn-css") &&
338-
!this.varUsage.has(property)
339-
) {
340-
return;
341-
}
342-
343334
rule.v ??= [];
344335
rule.v.push([property.slice(2), value]);
345336
} else if (isStyleFunction(value)) {

0 commit comments

Comments
 (0)