-
Notifications
You must be signed in to change notification settings - Fork 415
/
css.ts
60 lines (47 loc) · 1.48 KB
/
css.ts
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
import type { Expression, SourceLocation, StringLiteral } from '@babel/types';
import type { ProcessorParams, Rules, ValueCache } from '@linaria/tags';
import { BaseProcessor } from '@linaria/tags';
export default class CssProcessor extends BaseProcessor {
constructor(...args: ProcessorParams) {
super(...args);
if (this.params.length > 0) {
throw new Error('Invalid usage of `css` tag');
}
}
// eslint-disable-next-line class-methods-use-this
public override addInterpolation(node: unknown, 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 override get asSelector(): string {
return this.className;
}
protected override get tagExpression(): Expression {
return this.tagExp;
}
public override get value(): StringLiteral {
return this.astService.stringLiteral(this.className);
}
}