-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathscss-declaration.js
More file actions
102 lines (80 loc) · 2.59 KB
/
scss-declaration.js
File metadata and controls
102 lines (80 loc) · 2.59 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* @fileoverview SCSS variable node for CSSTree.
* @author Nicholas C. Zakas
*/
//-----------------------------------------------------------------------------
// Imports
//-----------------------------------------------------------------------------
import { tokenTypes } from "@eslint/css-tree";
//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------
const DOLLARSIGN = 0x0024; // U+0024 DOLLAR SIGN ($)
function consumeValueRaw() {
return this.Raw(this.consumeUntilExclamationMarkOrSemicolon, true);
}
function consumeValue() {
const startValueToken = this.tokenIndex;
const value = this.Value();
if (value.type !== 'Raw' &&
this.eof === false &&
this.tokenType !== tokenTypes.Semicolon &&
this.isBalanceEdge(startValueToken) === false) {
this.error();
}
return value;
}
//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------
export const name = 'ScssDeclaration';
export const walkContext = 'declaration';
export const structure = {
variable: String,
value: ['Value', 'Raw']
};
export function parse() {
const start = this.tokenStart;
const startToken = this.tokenIndex;
const variable = readVariable.call(this);
let value;
this.skipSC();
this.eat(tokenTypes.Colon);
this.skipSC();
if (this.parseValue) {
value = this.parseWithFallback(consumeValue, consumeValueRaw);
} else {
value = consumeValueRaw.call(this, this.tokenIndex);
}
// Do not include semicolon to range per spec
// https://drafts.csswg.org/css-syntax/#declaration-diagram
if (this.eof === false &&
this.tokenType !== tokenTypes.Semicolon &&
this.isBalanceEdge(startToken) === false) {
this.error();
}
// skip semicolon if present
if (this.tokenType === tokenTypes.Semicolon) {
this.next();
}
return {
type: name,
loc: this.getLocation(start, this.tokenStart),
variable,
value
};
}
export function generate(node) {
this.token(tokenTypes.Delim, '$');
this.token(tokenTypes.Ident, node.variable);
this.token(tokenTypes.Colon, ':');
this.node(node.value);
}
function readVariable() {
const start = this.tokenStart;
if (this.isDelim(DOLLARSIGN)) {
this.eat(tokenTypes.Delim);
}
this.eat(tokenTypes.Ident);
return this.substrToCursor(start);
}