-
Notifications
You must be signed in to change notification settings - Fork 413
Expand file tree
/
Copy pathcss.ts
More file actions
69 lines (58 loc) · 1.52 KB
/
Copy pathcss.ts
File metadata and controls
69 lines (58 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import type {
Rules,
SourceLocation,
StringLiteral,
ValueCache,
} from '@wyw-in-js/processor-utils';
import { TaggedTemplateProcessor } from '@wyw-in-js/processor-utils';
type StaticClassNameValue = {
className: string;
kind: 'class-name';
value: string;
};
export default class CssProcessor extends TaggedTemplateProcessor {
public override get asSelector(): string {
return this.className;
}
public override get value(): StringLiteral {
return this.astService.stringLiteral(this.className);
}
// eslint-disable-next-line class-methods-use-this
public override addInterpolation(
node: unknown,
precedingCss: string,
source: string
): string {
throw new Error(
`css tag cannot handle '${source}' as an interpolated value`
);
}
public override doEvaltimeReplacement(): void {
this.replacer(this.value, false);
}
public override doRuntimeReplacement(): void {
this.replacer(this.astService.stringLiteral(this.className), false);
}
public override extractRules(
valueCache: ValueCache,
cssText: string,
loc?: SourceLocation | null
): Rules {
const rules: Rules = {};
const selector = `.${this.className}`;
rules[selector] = {
cssText,
className: this.className,
displayName: this.displayName,
start: loc?.start ?? null,
};
return rules;
}
public getStaticValue(): StaticClassNameValue {
return {
className: this.className,
kind: 'class-name',
value: this.className,
};
}
}