in src/parser/cssParser.ts [478:530]
public _tryParseCustomPropertyDeclaration(stopTokens?: TokenType[]): nodes.CustomPropertyDeclaration | null {
if (!this.peekRegExp(TokenType.Ident, /^--/)) {
return null;
}
const node = this.create(nodes.CustomPropertyDeclaration);
if (!node.setProperty(this._parseProperty())) {
return null;
}
if (!this.accept(TokenType.Colon)) {
return this.finish(node, ParseError.ColonExpected, [TokenType.Colon]);
}
if (this.prevToken) {
node.colonPosition = this.prevToken.offset;
}
const mark = this.mark();
if (this.peek(TokenType.CurlyL)) {
// try to parse it as nested declaration
const propertySet = this.create(nodes.CustomPropertySet);
const declarations = this._parseDeclarations(this._parseRuleSetDeclaration.bind(this));
if (propertySet.setDeclarations(declarations) && !declarations.isErroneous(true)) {
propertySet.addChild(this._parsePrio());
if (this.peek(TokenType.SemiColon)) {
this.finish(propertySet);
node.setPropertySet(propertySet);
node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
return this.finish(node);
}
}
this.restoreAtMark(mark);
}
// try to parse as expression
const expression = this._parseExpr();
if (expression && !expression.isErroneous(true)) {
this._parsePrio();
if (this.peekOne(...(stopTokens || []), TokenType.SemiColon, TokenType.EOF)) {
node.setValue(expression);
if (this.peek(TokenType.SemiColon)) {
node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
}
return this.finish(node);
}
}
this.restoreAtMark(mark);
node.addChild(this._parseCustomPropertyValue(stopTokens));
node.addChild(this._parsePrio());
if (isDefined(node.colonPosition) && this.token.offset === node.colonPosition + 1) {
return this.finish(node, ParseError.PropertyValueExpected);
}
return this.finish(node);
}