vscode-css-languageservice
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -0,1 +1,5 @@ | ||
3.0.0 / 2017-01-11 | ||
================== | ||
* Changed API `LanguageService.getColorPresentations`: separate parameters `range` and `color` (to match LS API) | ||
2.1.7 / 2017-09-21 | ||
@@ -2,0 +6,0 @@ ================== |
@@ -27,2 +27,3 @@ (function (factory) { | ||
if (scnr === void 0) { scnr = new cssScanner_1.Scanner(); } | ||
this.keyframeRegex = /^@(\-(webkit|ms|moz|o)\-)?keyframes$/i; | ||
this.scanner = scnr; | ||
@@ -32,17 +33,14 @@ this.token = null; | ||
} | ||
Parser.prototype.peek = function (type, text, ignoreCase) { | ||
if (ignoreCase === void 0) { ignoreCase = true; } | ||
if (type !== this.token.type) { | ||
return false; | ||
} | ||
if (typeof text !== 'undefined') { | ||
if (ignoreCase) { | ||
return text.toLowerCase() === this.token.text.toLowerCase(); | ||
} | ||
else { | ||
return text === this.token.text; | ||
} | ||
} | ||
return true; | ||
Parser.prototype.peekIdent = function (text) { | ||
return cssScanner_1.TokenType.Ident === this.token.type && text.length === this.token.text.length && text === this.token.text.toLowerCase(); | ||
}; | ||
Parser.prototype.peekKeyword = function (text) { | ||
return cssScanner_1.TokenType.AtKeyword === this.token.type && text.length === this.token.text.length && text === this.token.text.toLowerCase(); | ||
}; | ||
Parser.prototype.peekDelim = function (text) { | ||
return cssScanner_1.TokenType.Delim === this.token.type && text === this.token.text; | ||
}; | ||
Parser.prototype.peek = function (type) { | ||
return type === this.token.type; | ||
}; | ||
Parser.prototype.peekRegExp = function (type, regEx) { | ||
@@ -82,8 +80,10 @@ if (type !== this.token.type) { | ||
}; | ||
Parser.prototype.acceptOne = function (type, text, ignoreCase) { | ||
if (ignoreCase === void 0) { ignoreCase = true; } | ||
for (var i = 0; i < text.length; i++) { | ||
if (this.peek(type, text[i], ignoreCase)) { | ||
this.consumeToken(); | ||
return true; | ||
Parser.prototype.acceptOneKeyword = function (keywords) { | ||
if (cssScanner_1.TokenType.AtKeyword === this.token.type) { | ||
for (var _i = 0, keywords_1 = keywords; _i < keywords_1.length; _i++) { | ||
var keyword = keywords_1[_i]; | ||
if (keyword.length === this.token.text.length && keyword === this.token.text.toLowerCase()) { | ||
this.consumeToken(); | ||
return true; | ||
} | ||
} | ||
@@ -93,5 +93,4 @@ } | ||
}; | ||
Parser.prototype.accept = function (type, text, ignoreCase) { | ||
if (ignoreCase === void 0) { ignoreCase = true; } | ||
if (this.peek(type, text, ignoreCase)) { | ||
Parser.prototype.accept = function (type) { | ||
if (type === this.token.type) { | ||
this.consumeToken(); | ||
@@ -102,4 +101,18 @@ return true; | ||
}; | ||
Parser.prototype.acceptIdent = function (text) { | ||
if (this.peekIdent(text)) { | ||
this.consumeToken(); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
Parser.prototype.acceptKeyword = function (text) { | ||
if (this.peekKeyword(text)) { | ||
this.consumeToken(); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
Parser.prototype.acceptDelim = function (text) { | ||
if (cssScanner_1.TokenType.Delim === this.token.type && text === this.token.text) { | ||
if (this.peekDelim(text)) { | ||
this.consumeToken(); | ||
@@ -236,12 +249,14 @@ return true; | ||
Parser.prototype._parseStylesheetStatement = function () { | ||
return this._parseRuleset(false) | ||
|| this._parseImport() | ||
|| this._parseMedia() | ||
|| this._parsePage() | ||
|| this._parseFontFace() | ||
|| this._parseKeyframe() | ||
|| this._parseSupports() | ||
|| this._parseViewPort() | ||
|| this._parseNamespace() | ||
|| this._parseDocument(); | ||
if (this.peek(cssScanner_1.TokenType.AtKeyword)) { | ||
return this._parseImport() | ||
|| this._parseMedia() | ||
|| this._parsePage() | ||
|| this._parseFontFace() | ||
|| this._parseKeyframe() | ||
|| this._parseSupports() | ||
|| this._parseViewPort() | ||
|| this._parseNamespace() | ||
|| this._parseDocument(); | ||
} | ||
return this._parseRuleset(false); | ||
}; | ||
@@ -283,3 +298,3 @@ Parser.prototype._tryParseRuleset = function (isNested) { | ||
Parser.prototype._parseAtApply = function () { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@apply')) { | ||
if (!this.peekKeyword('@apply')) { | ||
return null; | ||
@@ -541,6 +556,7 @@ } | ||
Parser.prototype._parseCharset = function () { | ||
var node = this.create(nodes.Node); | ||
if (!this.accept(cssScanner_1.TokenType.Charset)) { | ||
if (!this.peek(cssScanner_1.TokenType.Charset)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Node); | ||
this.consumeToken(); // charset | ||
if (!this.accept(cssScanner_1.TokenType.String)) { | ||
@@ -555,6 +571,7 @@ return this.finish(node, cssErrors_1.ParseError.IdentifierExpected); | ||
Parser.prototype._parseImport = function () { | ||
var node = this.create(nodes.Import); | ||
if (!this.accept(cssScanner_1.TokenType.AtKeyword, '@import')) { | ||
if (!this.peekKeyword('@import')) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Import); | ||
this.consumeToken(); // @import | ||
if (!node.addChild(this._parseURILiteral()) && !node.addChild(this._parseStringLiteral())) { | ||
@@ -571,6 +588,7 @@ return this.finish(node, cssErrors_1.ParseError.URIOrStringExpected); | ||
// namespace : NAMESPACE_SYM S* [IDENT S*]? [STRING|URI] S* ';' S* | ||
var node = this.create(nodes.Namespace); | ||
if (!this.accept(cssScanner_1.TokenType.AtKeyword, '@namespace')) { | ||
if (!this.peekKeyword('@namespace')) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Namespace); | ||
this.consumeToken(); // @namespace | ||
if (!node.addChild(this._parseURILiteral())) { | ||
@@ -588,3 +606,3 @@ node.addChild(this._parseIdent()); // optional prefix | ||
Parser.prototype._parseFontFace = function () { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@font-face')) { | ||
if (!this.peekKeyword('@font-face')) { | ||
return null; | ||
@@ -597,5 +615,5 @@ } | ||
Parser.prototype._parseViewPort = function () { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@-ms-viewport') && | ||
!this.peek(cssScanner_1.TokenType.AtKeyword, '@-o-viewport') && | ||
!this.peek(cssScanner_1.TokenType.AtKeyword, '@viewport')) { | ||
if (!this.peekKeyword('@-ms-viewport') && | ||
!this.peekKeyword('@-o-viewport') && | ||
!this.peekKeyword('@viewport')) { | ||
return null; | ||
@@ -608,11 +626,8 @@ } | ||
Parser.prototype._parseKeyframe = function () { | ||
if (!this.peekRegExp(cssScanner_1.TokenType.AtKeyword, this.keyframeRegex)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Keyframe); | ||
var atNode = this.create(nodes.Node); | ||
if (!this.accept(cssScanner_1.TokenType.AtKeyword, '@keyframes') && | ||
!this.accept(cssScanner_1.TokenType.AtKeyword, '@-webkit-keyframes') && | ||
!this.accept(cssScanner_1.TokenType.AtKeyword, '@-ms-keyframes') && | ||
!this.accept(cssScanner_1.TokenType.AtKeyword, '@-moz-keyframes') && | ||
!this.accept(cssScanner_1.TokenType.AtKeyword, '@-o-keyframes')) { | ||
return null; | ||
} | ||
this.consumeToken(); // atkeyword | ||
node.setKeyword(this.finish(atNode)); | ||
@@ -663,3 +678,3 @@ if (atNode.getText() === '@-ms-keyframes') { | ||
// SUPPORTS_SYM S* supports_condition '{' S* ruleset* '}' S* | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@supports')) { | ||
if (!this.peekKeyword('@supports')) { | ||
return null; | ||
@@ -691,3 +706,3 @@ } | ||
var node = this.create(nodes.SupportsCondition); | ||
if (this.accept(cssScanner_1.TokenType.Ident, 'not', true)) { | ||
if (this.acceptIdent('not')) { | ||
node.addChild(this._parseSupportsConditionInParens()); | ||
@@ -699,3 +714,3 @@ } | ||
var text = this.token.text; | ||
while (this.accept(cssScanner_1.TokenType.Ident, text, true)) { | ||
while (this.acceptIdent(text)) { | ||
node.addChild(this._parseSupportsConditionInParens()); | ||
@@ -754,6 +769,7 @@ } | ||
// media_query_list : S* [media_query [ ',' S* media_query ]* ]? | ||
var node = this.create(nodes.Media); | ||
if (!this.accept(cssScanner_1.TokenType.AtKeyword, '@media')) { | ||
if (!this.peekKeyword('@media')) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Media); | ||
this.consumeToken(); // @media | ||
if (!node.addChild(this._parseMediaQueryList())) { | ||
@@ -784,3 +800,3 @@ return this.finish(node, cssErrors_1.ParseError.MediaQueryExpected); | ||
if (!this.peek(cssScanner_1.TokenType.ParenthesisL)) { | ||
if (this.accept(cssScanner_1.TokenType.Ident, 'only', true) || this.accept(cssScanner_1.TokenType.Ident, 'not', true)) { | ||
if (this.acceptIdent('only') || this.acceptIdent('not')) { | ||
// optional | ||
@@ -792,3 +808,3 @@ } | ||
hasContent = true; | ||
parseExpression = this.accept(cssScanner_1.TokenType.Ident, 'and', true); | ||
parseExpression = this.acceptIdent('and'); | ||
} | ||
@@ -813,3 +829,3 @@ while (parseExpression) { | ||
} | ||
parseExpression = this.accept(cssScanner_1.TokenType.Ident, 'and', true); | ||
parseExpression = this.acceptIdent('and'); | ||
} | ||
@@ -837,6 +853,7 @@ return this.finish(node); | ||
// page_body : /* Can be empty */ declaration? [ ';' S* page_body ]? | page_margin_box page_body | ||
var node = this.create(nodes.Page); | ||
if (!this.accept(cssScanner_1.TokenType.AtKeyword, '@Page')) { | ||
if (!this.peekKeyword('@page')) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Page); | ||
this.consumeToken(); | ||
if (node.addChild(this._parsePageSelector())) { | ||
@@ -853,7 +870,7 @@ while (this.accept(cssScanner_1.TokenType.Comma)) { | ||
// page_margin_box : margin_sym S* '{' S* declaration? [ ';' S* declaration? ]* '}' S* | ||
var node = this.create(nodes.PageBoxMarginBox); | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword)) { | ||
return null; | ||
} | ||
if (!this.acceptOne(cssScanner_1.TokenType.AtKeyword, languageFacts.getPageBoxDirectives())) { | ||
var node = this.create(nodes.PageBoxMarginBox); | ||
if (!this.acceptOneKeyword(languageFacts.getPageBoxDirectives())) { | ||
this.markError(node, cssErrors_1.ParseError.UnknownAtRule, [], [cssScanner_1.TokenType.CurlyL]); | ||
@@ -866,6 +883,6 @@ } | ||
// pseudo_page : ':' [ "left" | "right" | "first" | "blank" ]; | ||
var node = this.create(nodes.Node); | ||
if (!this.peek(cssScanner_1.TokenType.Ident) && !this.peek(cssScanner_1.TokenType.Colon)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Node); | ||
node.addChild(this._parseIdent()); // optional ident | ||
@@ -881,6 +898,7 @@ if (this.accept(cssScanner_1.TokenType.Colon)) { | ||
// -moz-document is experimental but has been pushed to css4 | ||
var node = this.create(nodes.Document); | ||
if (!this.accept(cssScanner_1.TokenType.AtKeyword, '@-moz-document')) { | ||
if (!this.peekKeyword('@-moz-document')) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Document); | ||
this.consumeToken(); // @-moz-document | ||
this.resync([], [cssScanner_1.TokenType.CurlyL]); // ignore all the rules | ||
@@ -891,13 +909,14 @@ return this._parseBody(node, this._parseStylesheetStatement.bind(this)); | ||
// these are operators for binary expressions | ||
var node = this.createNode(nodes.NodeType.Operator); | ||
if (this.acceptDelim('/') || | ||
this.acceptDelim('*') || | ||
this.acceptDelim('+') || | ||
this.acceptDelim('-') || | ||
this.accept(cssScanner_1.TokenType.Dashmatch) || | ||
this.accept(cssScanner_1.TokenType.Includes) || | ||
this.accept(cssScanner_1.TokenType.SubstringOperator) || | ||
this.accept(cssScanner_1.TokenType.PrefixOperator) || | ||
this.accept(cssScanner_1.TokenType.SuffixOperator) || | ||
this.acceptDelim('=')) { | ||
if (this.peekDelim('/') || | ||
this.peekDelim('*') || | ||
this.peekDelim('+') || | ||
this.peekDelim('-') || | ||
this.peek(cssScanner_1.TokenType.Dashmatch) || | ||
this.peek(cssScanner_1.TokenType.Includes) || | ||
this.peek(cssScanner_1.TokenType.SubstringOperator) || | ||
this.peek(cssScanner_1.TokenType.PrefixOperator) || | ||
this.peek(cssScanner_1.TokenType.SuffixOperator) || | ||
this.peekDelim('=')) { | ||
var node = this.createNode(nodes.NodeType.Operator); | ||
this.consumeToken(); | ||
return this.finish(node); | ||
@@ -910,13 +929,13 @@ } | ||
Parser.prototype._parseUnaryOperator = function () { | ||
var node = this.create(nodes.Node); | ||
if (this.acceptDelim('+') || this.acceptDelim('-')) { | ||
return this.finish(node); | ||
} | ||
else { | ||
if (!this.peekDelim('+') && !this.peekDelim('-')) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Node); | ||
this.consumeToken(); | ||
return this.finish(node); | ||
}; | ||
Parser.prototype._parseCombinator = function () { | ||
var node = this.create(nodes.Node); | ||
if (this.acceptDelim('>')) { | ||
if (this.peekDelim('>')) { | ||
var node = this.create(nodes.Node); | ||
this.consumeToken(); | ||
var mark = this.mark(); | ||
@@ -933,13 +952,19 @@ if (!this.hasWhitespace() && this.acceptDelim('>')) { | ||
} | ||
else if (this.acceptDelim('+')) { | ||
else if (this.peekDelim('+')) { | ||
var node = this.create(nodes.Node); | ||
this.consumeToken(); | ||
node.type = nodes.NodeType.SelectorCombinatorSibling; | ||
return this.finish(node); | ||
} | ||
else if (this.acceptDelim('~')) { | ||
else if (this.peekDelim('~')) { | ||
var node = this.create(nodes.Node); | ||
this.consumeToken(); | ||
node.type = nodes.NodeType.SelectorCombinatorAllSiblings; | ||
return this.finish(node); | ||
} | ||
else if (this.acceptDelim('/')) { | ||
else if (this.peekDelim('/')) { | ||
var node = this.create(nodes.Node); | ||
this.consumeToken(); | ||
var mark = this.mark(); | ||
if (!this.hasWhitespace() && this.accept(cssScanner_1.TokenType.Ident, 'deep') && !this.hasWhitespace() && this.acceptDelim('/')) { | ||
if (!this.hasWhitespace() && this.acceptIdent('deep') && !this.hasWhitespace() && this.acceptDelim('/')) { | ||
node.type = nodes.NodeType.SelectorCombinatorShadowPiercingDescendant; | ||
@@ -974,3 +999,3 @@ return this.finish(node); | ||
Parser.prototype._parseHash = function () { | ||
if (!this.peek(cssScanner_1.TokenType.Hash) && !this.peek(cssScanner_1.TokenType.Delim, '#')) { | ||
if (!this.peek(cssScanner_1.TokenType.Hash) && !this.peekDelim('#')) { | ||
return null; | ||
@@ -991,3 +1016,3 @@ } | ||
// class: '.' IDENT ; | ||
if (!this.peek(cssScanner_1.TokenType.Delim, '.')) { | ||
if (!this.peekDelim('.')) { | ||
return null; | ||
@@ -1082,3 +1107,3 @@ } | ||
var node = this.createNode(nodes.NodeType.Prio); | ||
if (this.accept(cssScanner_1.TokenType.Exclamation) && this.accept(cssScanner_1.TokenType.Ident, 'important', true)) { | ||
if (this.accept(cssScanner_1.TokenType.Exclamation) && this.acceptIdent('important')) { | ||
return this.finish(node); | ||
@@ -1156,6 +1181,7 @@ } | ||
Parser.prototype._parseOperation = function () { | ||
var node = this.create(nodes.Node); | ||
if (!this.accept(cssScanner_1.TokenType.ParenthesisL)) { | ||
if (!this.peek(cssScanner_1.TokenType.ParenthesisL)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Node); | ||
this.consumeToken(); // ParenthesisL | ||
node.addChild(this._parseExpr()); | ||
@@ -1168,13 +1194,14 @@ if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) { | ||
Parser.prototype._parseNumeric = function () { | ||
var node = this.create(nodes.NumericValue); | ||
if (this.accept(cssScanner_1.TokenType.Num) || | ||
this.accept(cssScanner_1.TokenType.Percentage) || | ||
this.accept(cssScanner_1.TokenType.Resolution) || | ||
this.accept(cssScanner_1.TokenType.Length) || | ||
this.accept(cssScanner_1.TokenType.EMS) || | ||
this.accept(cssScanner_1.TokenType.EXS) || | ||
this.accept(cssScanner_1.TokenType.Angle) || | ||
this.accept(cssScanner_1.TokenType.Time) || | ||
this.accept(cssScanner_1.TokenType.Dimension) || | ||
this.accept(cssScanner_1.TokenType.Freq)) { | ||
if (this.peek(cssScanner_1.TokenType.Num) || | ||
this.peek(cssScanner_1.TokenType.Percentage) || | ||
this.peek(cssScanner_1.TokenType.Resolution) || | ||
this.peek(cssScanner_1.TokenType.Length) || | ||
this.peek(cssScanner_1.TokenType.EMS) || | ||
this.peek(cssScanner_1.TokenType.EXS) || | ||
this.peek(cssScanner_1.TokenType.Angle) || | ||
this.peek(cssScanner_1.TokenType.Time) || | ||
this.peek(cssScanner_1.TokenType.Dimension) || | ||
this.peek(cssScanner_1.TokenType.Freq)) { | ||
var node = this.create(nodes.NumericValue); | ||
this.consumeToken(); | ||
return this.finish(node); | ||
@@ -1185,10 +1212,11 @@ } | ||
Parser.prototype._parseStringLiteral = function () { | ||
if (!this.peek(cssScanner_1.TokenType.String) && !this.peek(cssScanner_1.TokenType.BadString)) { | ||
return null; | ||
} | ||
var node = this.createNode(nodes.NodeType.StringLiteral); | ||
if (this.accept(cssScanner_1.TokenType.String) || this.accept(cssScanner_1.TokenType.BadString)) { | ||
return this.finish(node); | ||
} | ||
return null; | ||
this.consumeToken(); | ||
return this.finish(node); | ||
}; | ||
Parser.prototype._parseURILiteral = function () { | ||
if (!this.peekRegExp(cssScanner_1.TokenType.Ident, /url(-prefix)?/i)) { | ||
if (!this.peekRegExp(cssScanner_1.TokenType.Ident, /^url(-prefix)?$/i)) { | ||
return null; | ||
@@ -1220,2 +1248,5 @@ } | ||
Parser.prototype._parseIdent = function (referenceTypes) { | ||
if (!this.peek(cssScanner_1.TokenType.Ident)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Identifier); | ||
@@ -1226,6 +1257,4 @@ if (referenceTypes) { | ||
node.isCustomProperty = this.peekRegExp(cssScanner_1.TokenType.Ident, /^--/); | ||
if (this.accept(cssScanner_1.TokenType.Ident)) { | ||
return this.finish(node); | ||
} | ||
return null; | ||
this.consumeToken(); | ||
return this.finish(node); | ||
}; | ||
@@ -1255,5 +1284,8 @@ Parser.prototype._parseFunction = function () { | ||
Parser.prototype._parseFunctionIdentifier = function () { | ||
if (!this.peek(cssScanner_1.TokenType.Ident)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Identifier); | ||
node.referenceTypes = [nodes.ReferenceType.Function]; | ||
if (this.accept(cssScanner_1.TokenType.Ident, 'progid')) { | ||
if (this.acceptIdent('progid')) { | ||
// support for IE7 specific filters: 'progid:DXImageTransform.Microsoft.MotionBlur(strength=13, direction=310)' | ||
@@ -1267,6 +1299,4 @@ if (this.accept(cssScanner_1.TokenType.Colon)) { | ||
} | ||
else if (this.accept(cssScanner_1.TokenType.Ident)) { | ||
return this.finish(node); | ||
} | ||
return null; | ||
this.consumeToken(); | ||
return this.finish(node); | ||
}; | ||
@@ -1273,0 +1303,0 @@ Parser.prototype._parseFunctionArgument = function () { |
@@ -176,3 +176,4 @@ var __extends = (this && this.__extends) || (function () { | ||
var current = this.scope.findScope(node.offset, node.length); | ||
node.getSelectors().getChildren().forEach(function (child) { | ||
for (var _i = 0, _a = node.getSelectors().getChildren(); _i < _a.length; _i++) { | ||
var child = _a[_i]; | ||
if (child instanceof nodes.Selector) { | ||
@@ -183,3 +184,3 @@ if (child.getChildren().length === 1) { | ||
} | ||
}); | ||
} | ||
return true; | ||
@@ -226,3 +227,3 @@ }; | ||
this.global = new GlobalScope(); | ||
node.accept(new ScopeBuilder(this.global)); | ||
node.acceptVisitor(new ScopeBuilder(this.global)); | ||
} | ||
@@ -229,0 +230,0 @@ Symbols.prototype.findSymbolsAtOffset = function (offset, referenceType) { |
@@ -47,6 +47,7 @@ var __extends = (this && this.__extends) || (function () { | ||
LESSParser.prototype._parseImport = function () { | ||
var node = this.create(nodes.Import); | ||
if (!this.accept(cssScanner_1.TokenType.AtKeyword, '@import') && !this.accept(cssScanner_1.TokenType.AtKeyword, '@import-once') /* deprecated in less 1.4.1 */) { | ||
if (!this.peekKeyword('@import') && !this.peekKeyword('@import-once') /* deprecated in less 1.4.1 */) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Import); | ||
this.consumeToken(); | ||
// less 1.4.1: @import (css) "lib" | ||
@@ -101,3 +102,3 @@ if (this.accept(cssScanner_1.TokenType.ParenthesisL)) { | ||
} | ||
if (this.accept(cssScanner_1.TokenType.Colon, ':')) { | ||
if (this.accept(cssScanner_1.TokenType.Colon)) { | ||
node.colonPosition = this.prevToken.offset; | ||
@@ -130,2 +131,5 @@ if (!node.setValue(this._parseDetachedRuleSet() || this._parseExpr())) { | ||
LESSParser.prototype._parseVariable = function () { | ||
if (!this.peekDelim('@') && !this.peek(cssScanner_1.TokenType.AtKeyword)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Variable); | ||
@@ -158,8 +162,11 @@ var mark = this.mark(); | ||
LESSParser.prototype._parseEscaped = function () { | ||
var node = this.createNode(nodes.NodeType.EscapedValue); | ||
if (this.accept(cssScanner_1.TokenType.EscapedJavaScript) || | ||
this.accept(cssScanner_1.TokenType.BadEscapedJavaScript)) { | ||
if (this.peek(cssScanner_1.TokenType.EscapedJavaScript) || | ||
this.peek(cssScanner_1.TokenType.BadEscapedJavaScript)) { | ||
var node = this.createNode(nodes.NodeType.EscapedValue); | ||
this.consumeToken(); | ||
return this.finish(node); | ||
} | ||
if (this.acceptDelim('~')) { | ||
if (this.peekDelim('~')) { | ||
var node = this.createNode(nodes.NodeType.EscapedValue); | ||
this.consumeToken(); | ||
return this.finish(node, this.accept(cssScanner_1.TokenType.String) ? null : cssErrors_1.ParseError.TermExpected); | ||
@@ -179,12 +186,17 @@ } | ||
LESSParser.prototype._parseGuardOperator = function () { | ||
var node = this.createNode(nodes.NodeType.Operator); | ||
if (this.acceptDelim('>')) { | ||
if (this.peekDelim('>')) { | ||
var node = this.createNode(nodes.NodeType.Operator); | ||
this.consumeToken(); | ||
this.acceptDelim('='); | ||
return node; | ||
} | ||
else if (this.acceptDelim('=')) { | ||
else if (this.peekDelim('=')) { | ||
var node = this.createNode(nodes.NodeType.Operator); | ||
this.consumeToken(); | ||
this.acceptDelim('<'); | ||
return node; | ||
} | ||
else if (this.acceptDelim('<')) { | ||
else if (this.peekDelim('<')) { | ||
var node = this.createNode(nodes.NodeType.Operator); | ||
this.consumeToken(); | ||
this.acceptDelim('='); | ||
@@ -240,4 +252,5 @@ return node; | ||
LESSParser.prototype._parseSelectorCombinator = function () { | ||
var node = this.createNode(nodes.NodeType.SelectorCombinator); | ||
if (this.acceptDelim('&')) { | ||
if (this.peekDelim('&')) { | ||
var node = this.createNode(nodes.NodeType.SelectorCombinator); | ||
this.consumeToken(); | ||
while (!this.hasWhitespace() && (this.acceptDelim('-') || this.accept(cssScanner_1.TokenType.Num) || this.accept(cssScanner_1.TokenType.Dimension) || node.addChild(this._parseIdent()) || this.acceptDelim('&'))) { | ||
@@ -251,2 +264,5 @@ // support &-foo | ||
LESSParser.prototype._parseSelectorIdent = function () { | ||
if (!this.peekInterpolatedIdent()) { | ||
return null; | ||
} | ||
var node = this.createNode(nodes.NodeType.SelectorInterpolation); | ||
@@ -257,2 +273,5 @@ var hasContent = this._acceptInterpolatedIdent(node); | ||
LESSParser.prototype._parsePropertyIdentifier = function () { | ||
if (!this.peekInterpolatedIdent()) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Identifier); | ||
@@ -264,3 +283,3 @@ node.isCustomProperty = this.peekRegExp(cssScanner_1.TokenType.Ident, /^--/); | ||
if (!this.hasWhitespace()) { | ||
this.accept(cssScanner_1.TokenType.Ident, '_'); | ||
this.acceptIdent('_'); | ||
} | ||
@@ -270,2 +289,5 @@ } | ||
}; | ||
LESSParser.prototype.peekInterpolatedIdent = function () { | ||
return this.peek(cssScanner_1.TokenType.Ident) || this.peekDelim('@') || this.peekDelim('-'); | ||
}; | ||
LESSParser.prototype._acceptInterpolatedIdent = function (node) { | ||
@@ -299,4 +321,5 @@ var _this = this; | ||
var mark = this.mark(); | ||
var node = this.createNode(nodes.NodeType.Interpolation); | ||
if (this.acceptDelim('@')) { | ||
if (this.peekDelim('@')) { | ||
var node = this.createNode(nodes.NodeType.Interpolation); | ||
this.consumeToken(); | ||
if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.CurlyL)) { | ||
@@ -349,3 +372,3 @@ this.restoreAtMark(mark); | ||
var identifier; | ||
if (this.peek(cssScanner_1.TokenType.Delim, '#') || this.peek(cssScanner_1.TokenType.Delim, '.')) { | ||
if (this.peekDelim('#') || this.peekDelim('.')) { | ||
identifier = this.create(nodes.Identifier); | ||
@@ -374,3 +397,3 @@ this.consumeToken(); // # or . | ||
this.consumeToken(); // : | ||
if (this.accept(cssScanner_1.TokenType.Ident, 'extend')) { | ||
if (this.acceptIdent('extend')) { | ||
return this._completeExtends(node); | ||
@@ -382,3 +405,3 @@ } | ||
LESSParser.prototype._parseExtend = function () { | ||
if (!this.peek(cssScanner_1.TokenType.Delim, '&')) { | ||
if (!this.peekDelim('&')) { | ||
return null; | ||
@@ -389,3 +412,3 @@ } | ||
this.consumeToken(); // & | ||
if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.Colon) || !this.accept(cssScanner_1.TokenType.Ident, 'extend')) { | ||
if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.Colon) || !this.acceptIdent('extend')) { | ||
this.restoreAtMark(mark); | ||
@@ -499,3 +522,3 @@ return null; | ||
// special rest variable: @rest... | ||
if (this.peek(cssScanner_1.TokenType.AtKeyword, '@rest')) { | ||
if (this.peekKeyword('@rest')) { | ||
var restNode = this.create(nodes.Node); | ||
@@ -528,3 +551,3 @@ this.consumeToken(); | ||
LESSParser.prototype._parseGuard = function () { | ||
if (!this.peek(cssScanner_1.TokenType.Ident, 'when')) { | ||
if (!this.peekIdent('when')) { | ||
return null; | ||
@@ -534,7 +557,7 @@ } | ||
this.consumeToken(); // when | ||
node.isNegated = this.accept(cssScanner_1.TokenType.Ident, 'not'); | ||
node.isNegated = this.acceptIdent('not'); | ||
if (!node.getConditions().addChild(this._parseGuardCondition())) { | ||
return this.finish(node, cssErrors_1.ParseError.ConditionExpected); | ||
} | ||
while (this.accept(cssScanner_1.TokenType.Ident, 'and') || this.accept(cssScanner_1.TokenType.Comma, ',')) { | ||
while (this.acceptIdent('and') || this.accept(cssScanner_1.TokenType.Comma)) { | ||
if (!node.getConditions().addChild(this._parseGuardCondition())) { | ||
@@ -547,6 +570,7 @@ return this.finish(node, cssErrors_1.ParseError.ConditionExpected); | ||
LESSParser.prototype._parseGuardCondition = function () { | ||
var node = this.create(nodes.GuardCondition); | ||
if (!this.accept(cssScanner_1.TokenType.ParenthesisL)) { | ||
if (!this.peek(cssScanner_1.TokenType.ParenthesisL)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.GuardCondition); | ||
this.consumeToken(); // ParenthesisL | ||
if (!node.addChild(this._parseExpr())) { | ||
@@ -561,3 +585,3 @@ // empty (?) | ||
LESSParser.prototype._parseFunctionIdentifier = function () { | ||
if (this.peek(cssScanner_1.TokenType.Delim, '%')) { | ||
if (this.peekDelim('%')) { | ||
var node = this.create(nodes.Identifier); | ||
@@ -564,0 +588,0 @@ node.referenceTypes = [nodes.ReferenceType.Function]; |
@@ -42,16 +42,22 @@ var __extends = (this && this.__extends) || (function () { | ||
SCSSParser.prototype._parseStylesheetStatement = function () { | ||
return _super.prototype._parseStylesheetStatement.call(this) | ||
|| this._parseVariableDeclaration() | ||
|| this._parseWarnAndDebug() | ||
|| this._parseControlStatement() | ||
|| this._parseMixinDeclaration() | ||
|| this._parseMixinContent() | ||
|| this._parseMixinReference() // @include | ||
|| this._parseFunctionDeclaration(); | ||
var node = _super.prototype._parseStylesheetStatement.call(this); | ||
if (node) { | ||
return node; | ||
} | ||
if (this.peek(cssScanner_1.TokenType.AtKeyword)) { | ||
return this._parseWarnAndDebug() | ||
|| this._parseControlStatement() | ||
|| this._parseMixinDeclaration() | ||
|| this._parseMixinContent() | ||
|| this._parseMixinReference() // @include | ||
|| this._parseFunctionDeclaration(); | ||
} | ||
return this._parseVariableDeclaration(); | ||
}; | ||
SCSSParser.prototype._parseImport = function () { | ||
var node = this.create(nodes.Import); | ||
if (!this.accept(cssScanner_1.TokenType.AtKeyword, '@import')) { | ||
if (!this.peekKeyword('@import')) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Import); | ||
this.consumeToken(); | ||
if (!node.addChild(this._parseURILiteral()) && !node.addChild(this._parseStringLiteral())) { | ||
@@ -73,2 +79,5 @@ return this.finish(node, cssErrors_1.ParseError.URIOrStringExpected); | ||
if (panic === void 0) { panic = []; } | ||
if (!this.peek(scssScanner.VariableName)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.VariableDeclaration); | ||
@@ -78,3 +87,3 @@ if (!node.setVariable(this._parseVariable())) { | ||
} | ||
if (!this.accept(cssScanner_1.TokenType.Colon, ':')) { | ||
if (!this.accept(cssScanner_1.TokenType.Colon)) { | ||
return this.finish(node, cssErrors_1.ParseError.ColonExpected); | ||
@@ -87,5 +96,6 @@ } | ||
while (this.accept(cssScanner_1.TokenType.Exclamation)) { | ||
if (!this.acceptOne(cssScanner_1.TokenType.Ident, ['default', 'global'], false)) { | ||
if (!this.peekRegExp(cssScanner_1.TokenType.Ident, /^(default|global)$/)) { | ||
return this.finish(node, cssErrors_1.ParseError.UnknownKeyword); | ||
} | ||
this.consumeToken(); | ||
} | ||
@@ -104,6 +114,7 @@ if (this.peek(cssScanner_1.TokenType.SemiColon)) { | ||
SCSSParser.prototype._parseVariable = function () { | ||
var node = this.create(nodes.Variable); | ||
if (!this.accept(scssScanner.VariableName)) { | ||
if (!this.peek(scssScanner.VariableName)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Variable); | ||
this.consumeToken(); | ||
return node; | ||
@@ -113,2 +124,5 @@ }; | ||
var _this = this; | ||
if (!this.peek(cssScanner_1.TokenType.Ident) && !this.peek(scssScanner.InterpolationFunction) && !this.peekDelim('-')) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Identifier); | ||
@@ -153,4 +167,5 @@ node.referenceTypes = referenceTypes; | ||
SCSSParser.prototype._parseInterpolation = function () { | ||
var node = this.create(nodes.Interpolation); | ||
if (this.accept(scssScanner.InterpolationFunction)) { | ||
if (this.peek(scssScanner.InterpolationFunction)) { | ||
var node = this.create(nodes.Interpolation); | ||
this.consumeToken(); | ||
if (!node.addChild(this._parseBinaryExpr()) && !this._parseSelectorCombinator()) { | ||
@@ -169,5 +184,5 @@ return this.finish(node, cssErrors_1.ParseError.ExpressionExpected); | ||
|| this.peek(scssScanner.GreaterEqualsOperator) || this.peek(scssScanner.SmallerEqualsOperator) | ||
|| this.peek(cssScanner_1.TokenType.Delim, '>') || this.peek(cssScanner_1.TokenType.Delim, '<') | ||
|| this.peek(cssScanner_1.TokenType.Ident, 'and') || this.peek(cssScanner_1.TokenType.Ident, 'or') | ||
|| this.peek(cssScanner_1.TokenType.Delim, '%')) { | ||
|| this.peekDelim('>') || this.peekDelim('<') | ||
|| this.peekIdent('and') || this.peekIdent('or') | ||
|| this.peekDelim('%')) { | ||
var node = this.createNode(nodes.NodeType.Operator); | ||
@@ -180,3 +195,3 @@ this.consumeToken(); | ||
SCSSParser.prototype._parseUnaryOperator = function () { | ||
if (this.peek(cssScanner_1.TokenType.Ident, 'not')) { | ||
if (this.peekIdent('not')) { | ||
var node = this.create(nodes.Node); | ||
@@ -213,3 +228,3 @@ this.consumeToken(); | ||
} | ||
if (!this.accept(cssScanner_1.TokenType.Colon, ':')) { | ||
if (!this.accept(cssScanner_1.TokenType.Colon)) { | ||
return this.finish(node, cssErrors_1.ParseError.ColonExpected, [cssScanner_1.TokenType.Colon], resyncStopTokens); | ||
@@ -241,4 +256,5 @@ } | ||
SCSSParser.prototype._parseExtends = function () { | ||
var node = this.create(nodes.ExtendsReference); | ||
if (this.accept(cssScanner_1.TokenType.AtKeyword, '@extend')) { | ||
if (this.peekKeyword('@extend')) { | ||
var node = this.create(nodes.ExtendsReference); | ||
this.consumeToken(); | ||
if (!node.getSelectors().addChild(this._parseSimpleSelector())) { | ||
@@ -251,3 +267,3 @@ return this.finish(node, cssErrors_1.ParseError.SelectorExpected); | ||
if (this.accept(cssScanner_1.TokenType.Exclamation)) { | ||
if (!this.accept(cssScanner_1.TokenType.Ident, 'optional', true)) { | ||
if (!this.acceptIdent('optional')) { | ||
return this.finish(node, cssErrors_1.ParseError.UnknownKeyword); | ||
@@ -264,4 +280,5 @@ } | ||
SCSSParser.prototype._parseSelectorCombinator = function () { | ||
var node = this.createNode(nodes.NodeType.SelectorCombinator); | ||
if (this.acceptDelim('&')) { | ||
if (this.peekDelim('&')) { | ||
var node = this.createNode(nodes.NodeType.SelectorCombinator); | ||
this.consumeToken(); | ||
while (!this.hasWhitespace() && (this.acceptDelim('-') || this.accept(cssScanner_1.TokenType.Num) || this.accept(cssScanner_1.TokenType.Dimension) || node.addChild(this._parseIdent()) || this.acceptDelim('&'))) { | ||
@@ -275,8 +292,11 @@ // support &-foo-1 | ||
SCSSParser.prototype._parseSelectorPlaceholder = function () { | ||
var node = this.createNode(nodes.NodeType.SelectorPlaceholder); | ||
if (this.acceptDelim('%')) { | ||
if (this.peekDelim('%')) { | ||
var node = this.createNode(nodes.NodeType.SelectorPlaceholder); | ||
this.consumeToken(); | ||
this._parseIdent(); | ||
return this.finish(node); | ||
} | ||
else if (this.accept(cssScanner_1.TokenType.AtKeyword, '@at-root')) { | ||
else if (this.peekKeyword('@at-root')) { | ||
var node = this.createNode(nodes.NodeType.SelectorPlaceholder); | ||
this.consumeToken(); | ||
return this.finish(node); | ||
@@ -287,5 +307,5 @@ } | ||
SCSSParser.prototype._parseWarnAndDebug = function () { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@debug') | ||
&& !this.peek(cssScanner_1.TokenType.AtKeyword, '@warn') | ||
&& !this.peek(cssScanner_1.TokenType.AtKeyword, '@error')) { | ||
if (!this.peekKeyword('@debug') | ||
&& !this.peekKeyword('@warn') | ||
&& !this.peekKeyword('@error')) { | ||
return null; | ||
@@ -307,3 +327,3 @@ } | ||
SCSSParser.prototype._parseIfStatement = function (parseStatement) { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@if')) { | ||
if (!this.peekKeyword('@if')) { | ||
return null; | ||
@@ -320,4 +340,4 @@ } | ||
this._parseBody(node, parseStatement); | ||
if (this.accept(cssScanner_1.TokenType.AtKeyword, '@else')) { | ||
if (this.peek(cssScanner_1.TokenType.Ident, 'if')) { | ||
if (this.acceptKeyword('@else')) { | ||
if (this.peekIdent('if')) { | ||
node.setElseClause(this._internalParseIfStatement(parseStatement)); | ||
@@ -334,3 +354,3 @@ } | ||
SCSSParser.prototype._parseForStatement = function (parseStatement) { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@for')) { | ||
if (!this.peekKeyword('@for')) { | ||
return null; | ||
@@ -343,3 +363,3 @@ } | ||
} | ||
if (!this.accept(cssScanner_1.TokenType.Ident, 'from')) { | ||
if (!this.acceptIdent('from')) { | ||
return this.finish(node, scssErrors_1.SCSSParseError.FromExpected, [cssScanner_1.TokenType.CurlyR]); | ||
@@ -350,3 +370,3 @@ } | ||
} | ||
if (!this.accept(cssScanner_1.TokenType.Ident, 'to') && !this.accept(cssScanner_1.TokenType.Ident, 'through')) { | ||
if (!this.acceptIdent('to') && !this.acceptIdent('through')) { | ||
return this.finish(node, scssErrors_1.SCSSParseError.ThroughOrToExpected, [cssScanner_1.TokenType.CurlyR]); | ||
@@ -360,3 +380,3 @@ } | ||
SCSSParser.prototype._parseEachStatement = function (parseStatement) { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@each')) { | ||
if (!this.peekKeyword('@each')) { | ||
return null; | ||
@@ -376,3 +396,3 @@ } | ||
this.finish(variables); | ||
if (!this.accept(cssScanner_1.TokenType.Ident, 'in')) { | ||
if (!this.acceptIdent('in')) { | ||
return this.finish(node, scssErrors_1.SCSSParseError.InExpected, [cssScanner_1.TokenType.CurlyR]); | ||
@@ -386,3 +406,3 @@ } | ||
SCSSParser.prototype._parseWhileStatement = function (parseStatement) { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@while')) { | ||
if (!this.peekKeyword('@while')) { | ||
return null; | ||
@@ -402,3 +422,3 @@ } | ||
SCSSParser.prototype._parseFunctionDeclaration = function () { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@function')) { | ||
if (!this.peekKeyword('@function')) { | ||
return null; | ||
@@ -427,3 +447,3 @@ } | ||
SCSSParser.prototype._parseReturnStatement = function () { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@return')) { | ||
if (!this.peekKeyword('@return')) { | ||
return null; | ||
@@ -439,3 +459,3 @@ } | ||
SCSSParser.prototype._parseMixinDeclaration = function () { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@mixin')) { | ||
if (!this.peekKeyword('@mixin')) { | ||
return null; | ||
@@ -478,3 +498,3 @@ } | ||
SCSSParser.prototype._parseMixinContent = function () { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@content')) { | ||
if (!this.peekKeyword('@content')) { | ||
return null; | ||
@@ -487,3 +507,3 @@ } | ||
SCSSParser.prototype._parseMixinReference = function () { | ||
if (!this.peek(cssScanner_1.TokenType.AtKeyword, '@include')) { | ||
if (!this.peekKeyword('@include')) { | ||
return null; | ||
@@ -555,6 +575,7 @@ } | ||
SCSSParser.prototype._parseOperation = function () { | ||
var node = this.create(nodes.Node); | ||
if (!this.accept(cssScanner_1.TokenType.ParenthesisL)) { | ||
if (!this.peek(cssScanner_1.TokenType.ParenthesisL)) { | ||
return null; | ||
} | ||
var node = this.create(nodes.Node); | ||
this.consumeToken(); | ||
while (node.addChild(this._parseListElement())) { | ||
@@ -561,0 +582,0 @@ this.accept(cssScanner_1.TokenType.Comma); // optional |
@@ -117,7 +117,8 @@ (function (factory) { | ||
if (needsSortText) { | ||
result.items.forEach(function (i) { | ||
for (var _i = 0, _a = result.items; _i < _a.length; _i++) { | ||
var i = _a[_i]; | ||
if (!i.sortText) { | ||
i.sortText = 'd'; | ||
} | ||
}); | ||
} | ||
} | ||
@@ -178,3 +179,2 @@ return result; | ||
CSSCompletion.prototype.getCompletionsForDeclarationValue = function (node, result) { | ||
var _this = this; | ||
var propertyName = node.getFullPropertyName(); | ||
@@ -227,11 +227,11 @@ var entry = languageFacts.getProperties()[propertyName]; | ||
else { | ||
var existingValues = new Set(); | ||
this.styleSheet.accept(new ValuesCollector(node, existingValues)); | ||
existingValues.getEntries().forEach(function (existingValue) { | ||
var existingValues = collectValues(this.styleSheet, node); | ||
for (var _b = 0, _c = existingValues.getEntries(); _b < _c.length; _b++) { | ||
var existingValue = _c[_b]; | ||
result.items.push({ | ||
label: existingValue, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), existingValue), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), existingValue), | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Value | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -243,5 +243,5 @@ this.getVariableProposals(existingNode, result); | ||
CSSCompletion.prototype.getValueEnumProposals = function (entry, existingNode, result) { | ||
var _this = this; | ||
if (entry.values) { | ||
entry.values.forEach(function (value) { | ||
for (var _i = 0, _a = entry.values; _i < _a.length; _i++) { | ||
var value = _a[_i]; | ||
if (languageFacts.isCommonValue(value)) { | ||
@@ -260,3 +260,3 @@ var insertString = value.name; | ||
documentation: languageFacts.getEntryDescription(value), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), insertString), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), insertString), | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Value, | ||
@@ -267,3 +267,3 @@ insertTextFormat: insertTextFormat | ||
} | ||
}); | ||
} | ||
} | ||
@@ -290,5 +290,5 @@ return result; | ||
CSSCompletion.prototype.getVariableProposals = function (existingNode, result) { | ||
var _this = this; | ||
var symbols = this.getSymbolContext().findSymbolsAtOffset(this.offset, nodes.ReferenceType.Variable); | ||
symbols.forEach(function (symbol) { | ||
for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) { | ||
var symbol = symbols_1[_i]; | ||
var insertText = strings.startsWith(symbol.name, '--') ? "var(" + symbol.name + ")" : symbol.name; | ||
@@ -298,3 +298,3 @@ var suggest = { | ||
documentation: symbol.value ? strings.getLimitedString(symbol.value) : symbol.value, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), insertText), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText), | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Variable, | ||
@@ -310,7 +310,6 @@ sortText: 'z' | ||
result.items.push(suggest); | ||
}); | ||
} | ||
return result; | ||
}; | ||
CSSCompletion.prototype.getVariableProposalsForCSSVarFunction = function (result) { | ||
var _this = this; | ||
var symbols = this.getSymbolContext().findSymbolsAtOffset(this.offset, nodes.ReferenceType.Variable); | ||
@@ -320,14 +319,14 @@ symbols = symbols.filter(function (symbol) { | ||
}); | ||
symbols.forEach(function (symbol) { | ||
for (var _i = 0, symbols_2 = symbols; _i < symbols_2.length; _i++) { | ||
var symbol = symbols_2[_i]; | ||
result.items.push({ | ||
label: symbol.name, | ||
documentation: symbol.value ? strings.getLimitedString(symbol.value) : symbol.value, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(null), symbol.name), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(null), symbol.name), | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Variable | ||
}); | ||
}); | ||
} | ||
return result; | ||
}; | ||
CSSCompletion.prototype.getUnitProposals = function (entry, existingNode, result) { | ||
var _this = this; | ||
var currentWord = '0'; | ||
@@ -347,15 +346,17 @@ if (this.currentWord.length > 0) { | ||
} | ||
entry.restrictions.forEach(function (restriction) { | ||
for (var _i = 0, _a = entry.restrictions; _i < _a.length; _i++) { | ||
var restriction = _a[_i]; | ||
var units = languageFacts.units[restriction]; | ||
if (units) { | ||
units.forEach(function (unit) { | ||
for (var _b = 0, units_1 = units; _b < units_1.length; _b++) { | ||
var unit = units_1[_b]; | ||
var insertText = currentWord + unit; | ||
result.items.push({ | ||
label: insertText, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), insertText), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText), | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Unit | ||
}); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
return result; | ||
@@ -371,3 +372,2 @@ }; | ||
CSSCompletion.prototype.getColorProposals = function (entry, existingNode, result) { | ||
var _this = this; | ||
for (var color in languageFacts.colors) { | ||
@@ -390,11 +390,12 @@ result.items.push({ | ||
var colorValues = new Set(); | ||
this.styleSheet.accept(new ColorValueCollector(colorValues)); | ||
colorValues.getEntries().forEach(function (color) { | ||
this.styleSheet.acceptVisitor(new ColorValueCollector(colorValues)); | ||
for (var _i = 0, _a = colorValues.getEntries(); _i < _a.length; _i++) { | ||
var color = _a[_i]; | ||
result.items.push({ | ||
label: color, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), color), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), color), | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Color | ||
}); | ||
}); | ||
languageFacts.colorFunctions.forEach(function (p) { | ||
} | ||
var _loop_1 = function (p) { | ||
var tabStop = 1; | ||
@@ -407,7 +408,12 @@ var replaceFunction = function (match, p1) { return '${' + tabStop++ + ':' + p1 + '}'; }; | ||
documentation: p.desc, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), insertText), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this_1.getCompletionRange(existingNode), insertText), | ||
insertTextFormat: SnippetFormat, | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Function | ||
}); | ||
}); | ||
}; | ||
var this_1 = this; | ||
for (var _b = 0, _c = languageFacts.colorFunctions; _b < _c.length; _b++) { | ||
var p = _c[_b]; | ||
_loop_1(p); | ||
} | ||
return result; | ||
@@ -449,10 +455,10 @@ }; | ||
CSSCompletion.prototype.getLineWidthProposals = function (entry, existingNode, result) { | ||
var _this = this; | ||
languageFacts.lineWidthKeywords.forEach(function (lineWidth) { | ||
for (var _i = 0, _a = languageFacts.lineWidthKeywords; _i < _a.length; _i++) { | ||
var lineWidth = _a[_i]; | ||
result.items.push({ | ||
label: lineWidth, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), lineWidth), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), lineWidth), | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Value | ||
}); | ||
}); | ||
} | ||
return result; | ||
@@ -535,8 +541,8 @@ }; | ||
CSSCompletion.prototype.getCompletionForTopLevel = function (result) { | ||
var _this = this; | ||
languageFacts.getAtDirectives().forEach(function (entry) { | ||
for (var _i = 0, _a = languageFacts.getAtDirectives(); _i < _a.length; _i++) { | ||
var entry = _a[_i]; | ||
if (entry.browsers.count > 0) { | ||
result.items.push({ | ||
label: entry.name, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(null), entry.name), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(null), entry.name), | ||
documentation: languageFacts.getEntryDescription(entry), | ||
@@ -546,3 +552,3 @@ kind: vscode_languageserver_types_1.CompletionItemKind.Keyword | ||
} | ||
}); | ||
} | ||
this.getCompletionsForSelector(null, false, result); | ||
@@ -572,7 +578,8 @@ return result; | ||
} | ||
languageFacts.getPseudoClasses().forEach(function (entry) { | ||
for (var _i = 0, _a = languageFacts.getPseudoClasses(); _i < _a.length; _i++) { | ||
var entry = _a[_i]; | ||
if (entry.browsers.onCodeComplete) { | ||
var item = { | ||
label: entry.name, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), entry.name), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), entry.name), | ||
documentation: languageFacts.getEntryDescription(entry), | ||
@@ -586,8 +593,9 @@ kind: vscode_languageserver_types_1.CompletionItemKind.Function | ||
} | ||
}); | ||
languageFacts.getPseudoElements().forEach(function (entry) { | ||
} | ||
for (var _b = 0, _c = languageFacts.getPseudoElements(); _b < _c.length; _b++) { | ||
var entry = _c[_b]; | ||
if (entry.browsers.onCodeComplete) { | ||
var item = { | ||
label: entry.name, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), entry.name), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), entry.name), | ||
documentation: languageFacts.getEntryDescription(entry), | ||
@@ -601,18 +609,20 @@ kind: vscode_languageserver_types_1.CompletionItemKind.Function | ||
} | ||
}); | ||
} | ||
if (!isNested) { | ||
languageFacts.html5Tags.forEach(function (entry) { | ||
for (var _d = 0, _e = languageFacts.html5Tags; _d < _e.length; _d++) { | ||
var entry = _e[_d]; | ||
result.items.push({ | ||
label: entry, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), entry), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), entry), | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Keyword | ||
}); | ||
}); | ||
languageFacts.svgElements.forEach(function (entry) { | ||
} | ||
for (var _f = 0, _g = languageFacts.svgElements; _f < _g.length; _f++) { | ||
var entry = _g[_f]; | ||
result.items.push({ | ||
label: entry, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), entry), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), entry), | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Keyword | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -714,19 +724,19 @@ var visited = {}; | ||
CSSCompletion.prototype.getCompletionsForMixinReference = function (ref, result) { | ||
var _this = this; | ||
var allMixins = this.getSymbolContext().findSymbolsAtOffset(this.offset, nodes.ReferenceType.Mixin); | ||
allMixins.forEach(function (mixinSymbol) { | ||
for (var _i = 0, allMixins_1 = allMixins; _i < allMixins_1.length; _i++) { | ||
var mixinSymbol = allMixins_1[_i]; | ||
if (mixinSymbol.node instanceof nodes.MixinDeclaration) { | ||
result.items.push(_this.makeTermProposal(mixinSymbol, mixinSymbol.node.getParameters(), null)); | ||
result.items.push(this.makeTermProposal(mixinSymbol, mixinSymbol.node.getParameters(), null)); | ||
} | ||
}); | ||
} | ||
return result; | ||
}; | ||
CSSCompletion.prototype.getTermProposals = function (entry, existingNode, result) { | ||
var _this = this; | ||
var allFunctions = this.getSymbolContext().findSymbolsAtOffset(this.offset, nodes.ReferenceType.Function); | ||
allFunctions.forEach(function (functionSymbol) { | ||
for (var _i = 0, allFunctions_1 = allFunctions; _i < allFunctions_1.length; _i++) { | ||
var functionSymbol = allFunctions_1[_i]; | ||
if (functionSymbol.node instanceof nodes.FunctionDeclaration) { | ||
result.items.push(_this.makeTermProposal(functionSymbol, functionSymbol.node.getParameters(), existingNode)); | ||
result.items.push(this.makeTermProposal(functionSymbol, functionSymbol.node.getParameters(), existingNode)); | ||
} | ||
}); | ||
} | ||
return result; | ||
@@ -796,31 +806,21 @@ }; | ||
}()); | ||
var InternalValueCollector = /** @class */ (function () { | ||
function InternalValueCollector(entries) { | ||
this.entries = entries; | ||
// nothing to do | ||
} | ||
InternalValueCollector.prototype.visitNode = function (node) { | ||
function collectValues(styleSheet, declaration) { | ||
var fullPropertyName = declaration.getFullPropertyName(); | ||
var entries = new Set(); | ||
function visitValue(node) { | ||
if (node instanceof nodes.Identifier || node instanceof nodes.NumericValue || node instanceof nodes.HexColorValue) { | ||
this.entries.add(node.getText()); | ||
entries.add(node.getText()); | ||
} | ||
return true; | ||
}; | ||
return InternalValueCollector; | ||
}()); | ||
var ValuesCollector = /** @class */ (function () { | ||
function ValuesCollector(declaration, entries) { | ||
this.declaration = declaration; | ||
this.entries = entries; | ||
this.propertyName = declaration.getFullPropertyName(); | ||
} | ||
ValuesCollector.prototype.matchesProperty = function (decl) { | ||
function matchesProperty(decl) { | ||
var propertyName = decl.getFullPropertyName(); | ||
return this.propertyName === propertyName; | ||
}; | ||
ValuesCollector.prototype.visitNode = function (node) { | ||
if (node instanceof nodes.Declaration && node !== this.declaration) { | ||
if (this.matchesProperty(node)) { | ||
return fullPropertyName === propertyName; | ||
} | ||
function vistNode(node) { | ||
if (node instanceof nodes.Declaration && node !== declaration) { | ||
if (matchesProperty(node)) { | ||
var value = node.getValue(); | ||
if (value) { | ||
value.accept(new InternalValueCollector(this.entries)); | ||
value.accept(visitValue); | ||
} | ||
@@ -830,5 +830,6 @@ } | ||
return true; | ||
}; | ||
return ValuesCollector; | ||
}()); | ||
} | ||
styleSheet.accept(vistNode); | ||
return entries; | ||
} | ||
var ColorValueCollector = /** @class */ (function () { | ||
@@ -835,0 +836,0 @@ function ColorValueCollector(entries) { |
@@ -33,3 +33,3 @@ (function (factory) { | ||
entries.push.apply(entries, nodes.ParseErrorCollector.entries(stylesheet)); | ||
entries.push.apply(entries, lint_1.LintVisitor.entries(stylesheet, new lintRules_1.LintConfigurationSettings(settings && settings.lint))); | ||
entries.push.apply(entries, lint_1.LintVisitor.entries(stylesheet, document, new lintRules_1.LintConfigurationSettings(settings && settings.lint))); | ||
function toDiagnostic(marker) { | ||
@@ -36,0 +36,0 @@ var range = vscode_languageserver_types_1.Range.create(document.positionAt(marker.getOffset()), document.positionAt(marker.getOffset() + marker.getLength())); |
@@ -606,3 +606,4 @@ (function (factory) { | ||
if (browsers) { | ||
browsers.split(',').forEach(function (s) { | ||
for (var _i = 0, _a = browsers.split(','); _i < _a.length; _i++) { | ||
var s = _a[_i]; | ||
s = s.trim(); | ||
@@ -621,3 +622,3 @@ if (s === 'all') { | ||
} | ||
}); | ||
} | ||
} | ||
@@ -624,0 +625,0 @@ else { |
@@ -36,4 +36,4 @@ var __extends = (this && this.__extends) || (function () { | ||
LESSCompletion.prototype.createFunctionProposals = function (proposals, existingNode, sortToEnd, result) { | ||
var _this = this; | ||
proposals.forEach(function (p) { | ||
for (var _i = 0, proposals_1 = proposals; _i < proposals_1.length; _i++) { | ||
var p = proposals_1[_i]; | ||
var item = { | ||
@@ -43,3 +43,3 @@ label: p.name, | ||
documentation: p.description, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), p.name + '($0)'), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), p.name + '($0)'), | ||
insertTextFormat: vscode_languageserver_types_1.InsertTextFormat.Snippet, | ||
@@ -52,3 +52,3 @@ kind: vscode_languageserver_types_1.CompletionItemKind.Function | ||
result.items.push(item); | ||
}); | ||
} | ||
return result; | ||
@@ -55,0 +55,0 @@ }; |
@@ -46,16 +46,20 @@ (function (factory) { | ||
var LintVisitor = /** @class */ (function () { | ||
function LintVisitor(settings) { | ||
function LintVisitor(document, settings) { | ||
this.warnings = []; | ||
this.settings = settings; | ||
this.documentText = document.getText(); | ||
this.keyframes = new NodesByRootMap(); | ||
} | ||
LintVisitor.entries = function (node, settings) { | ||
var visitor = new LintVisitor(settings); | ||
node.accept(visitor); | ||
return visitor.getEntries(); | ||
LintVisitor.entries = function (node, document, settings, entryFilter) { | ||
var visitor = new LintVisitor(document, settings); | ||
node.acceptVisitor(visitor); | ||
visitor.completeValidations(); | ||
return visitor.getEntries(entryFilter); | ||
}; | ||
LintVisitor.prototype.fetch = function (input, s) { | ||
var elements = []; | ||
for (var i = 0; i < input.length; i++) { | ||
if (input[i].name.toLowerCase() === s) { | ||
elements.push(input[i]); | ||
for (var _i = 0, input_1 = input; _i < input_1.length; _i++) { | ||
var curr = input_1[_i]; | ||
if (curr.name === s) { | ||
elements.push(curr); | ||
} | ||
@@ -67,5 +71,5 @@ } | ||
var elements = []; | ||
for (var _i = 0, input_1 = input; _i < input_1.length; _i++) { | ||
var inputElement = input_1[_i]; | ||
if (inputElement.name.toLowerCase() === s) { | ||
for (var _i = 0, input_2 = input; _i < input_2.length; _i++) { | ||
var inputElement = input_2[_i]; | ||
if (inputElement.name === s) { | ||
var expression = inputElement.node.getValue(); | ||
@@ -89,12 +93,2 @@ if (expression && this.findValueInExpression(expression, v)) { | ||
}; | ||
LintVisitor.prototype.fetchWithin = function (input, s) { | ||
var elements = []; | ||
for (var _i = 0, input_2 = input; _i < input_2.length; _i++) { | ||
var inputElement = input_2[_i]; | ||
if (inputElement.name.toLowerCase().indexOf(s) >= 0) { | ||
elements.push(inputElement); | ||
} | ||
} | ||
return elements; | ||
}; | ||
LintVisitor.prototype.getEntries = function (filter) { | ||
@@ -134,4 +128,4 @@ if (filter === void 0) { filter = (nodes.Level.Warning | nodes.Level.Error); } | ||
switch (node.type) { | ||
case nodes.NodeType.Stylesheet: | ||
return this.visitStylesheet(node); | ||
case nodes.NodeType.Keyframe: | ||
return this.visitKeyframe(node); | ||
case nodes.NodeType.FontFace: | ||
@@ -149,43 +143,42 @@ return this.visitFontFace(node); | ||
return this.visitImport(node); | ||
case nodes.NodeType.HexColorValue: | ||
return this.visitHexColorValue(node); | ||
case nodes.NodeType.Prio: | ||
return this.visitPrio(node); | ||
} | ||
return this.visitUnknownNode(node); | ||
return true; | ||
}; | ||
LintVisitor.prototype.visitStylesheet = function (node) { | ||
LintVisitor.prototype.completeValidations = function () { | ||
this.validateKeyframes(); | ||
}; | ||
LintVisitor.prototype.visitKeyframe = function (node) { | ||
var keyword = node.getKeyword(); | ||
var text = keyword.getText(); | ||
this.keyframes.add(node.getName(), text, (text !== '@keyframes') ? keyword : null); | ||
return true; | ||
}; | ||
LintVisitor.prototype.validateKeyframes = function () { | ||
// @keyframe and it's vendor specific alternatives | ||
// @keyframe should be included | ||
var _this = this; | ||
var keyframes = new NodesByRootMap(); | ||
node.accept(function (node) { | ||
if (node instanceof nodes.Keyframe) { | ||
var keyword = node.getKeyword(); | ||
var text = keyword.getText(); | ||
keyframes.add(node.getName(), text, (text !== '@keyframes') ? keyword : null); | ||
} | ||
return true; | ||
}); | ||
var expected = ['@-webkit-keyframes', '@-moz-keyframes', '@-o-keyframes']; | ||
var _loop_1 = function (name) { | ||
var actual = keyframes.data[name].names; | ||
for (var name in this.keyframes.data) { | ||
var actual = this.keyframes.data[name].names; | ||
var needsStandard = (actual.indexOf('@keyframes') === -1); | ||
if (!needsStandard && actual.length === 1) { | ||
return "continue"; | ||
continue; // only the non-vendor specific keyword is used, that's fine, no warning | ||
} | ||
var addVendorSpecificWarnings = function (node) { | ||
if (needsStandard) { | ||
var message = localize('keyframes.standardrule.missing', "Always define standard rule '@keyframes' when defining keyframes."); | ||
_this.addEntry(node, lintRules_1.Rules.IncludeStandardPropertyWhenUsingVendorPrefix, message); | ||
var missingVendorSpecific = this.getMissingNames(expected, actual); | ||
if (missingVendorSpecific || needsStandard) { | ||
for (var _i = 0, _a = this.keyframes.data[name].nodes; _i < _a.length; _i++) { | ||
var node = _a[_i]; | ||
if (needsStandard) { | ||
var message = localize('keyframes.standardrule.missing', "Always define standard rule '@keyframes' when defining keyframes."); | ||
this.addEntry(node, lintRules_1.Rules.IncludeStandardPropertyWhenUsingVendorPrefix, message); | ||
} | ||
if (missingVendorSpecific) { | ||
var message = localize('keyframes.vendorspecific.missing', "Always include all vendor specific rules: Missing: {0}", missingVendorSpecific); | ||
this.addEntry(node, lintRules_1.Rules.AllVendorPrefixes, message); | ||
} | ||
} | ||
if (missingVendorSpecific) { | ||
var message = localize('keyframes.vendorspecific.missing', "Always include all vendor specific rules: Missing: {0}", missingVendorSpecific); | ||
_this.addEntry(node, lintRules_1.Rules.AllVendorPrefixes, message); | ||
} | ||
}; | ||
var missingVendorSpecific = this_1.getMissingNames(expected, actual); | ||
if (missingVendorSpecific || needsStandard) { | ||
keyframes.data[name].nodes.forEach(addVendorSpecificWarnings); | ||
} | ||
}; | ||
var this_1 = this; | ||
for (var name in keyframes.data) { | ||
_loop_1(name); | ||
} | ||
@@ -195,7 +188,7 @@ return true; | ||
LintVisitor.prototype.visitSimpleSelector = function (node) { | ||
var text = node.getText(); | ||
var firstChar = this.documentText.charAt(node.offset); | ||
///////////////////////////////////////////////////////////// | ||
// Lint - The universal selector (*) is known to be slow. | ||
///////////////////////////////////////////////////////////// | ||
if (text === '*') { | ||
if (node.length === 1 && firstChar === '*') { | ||
this.addEntry(node, lintRules_1.Rules.UniversalSelector); | ||
@@ -206,3 +199,3 @@ } | ||
///////////////////////////////////////////////////////////// | ||
if (text.indexOf('#') === 0) { | ||
if (firstChar === '#') { | ||
this.addEntry(node, lintRules_1.Rules.AvoidIdSelector); | ||
@@ -220,3 +213,2 @@ } | ||
LintVisitor.prototype.visitRuleSet = function (node) { | ||
var _this = this; | ||
///////////////////////////////////////////////////////////// | ||
@@ -235,8 +227,9 @@ // Lint - Don't use empty rulesets. | ||
var propertyTable = []; | ||
declarations.getChildren().forEach(function (element) { | ||
for (var _i = 0, _a = declarations.getChildren(); _i < _a.length; _i++) { | ||
var element = _a[_i]; | ||
if (element instanceof nodes.Declaration) { | ||
var decl = element; | ||
propertyTable.push(new Element(decl.getFullPropertyName(), decl)); | ||
propertyTable.push(new Element(decl.getFullPropertyName().toLowerCase(), decl)); | ||
} | ||
}, this); | ||
} | ||
///////////////////////////////////////////////////////////// | ||
@@ -249,20 +242,21 @@ // the rule warns when it finds: | ||
///////////////////////////////////////////////////////////// | ||
if (this.fetchWithin(propertyTable, 'box-sizing').length === 0) { | ||
if (this.fetch(propertyTable, 'box-sizing').length === 0) { | ||
var widthEntries = this.fetch(propertyTable, 'width'); | ||
if (widthEntries.length > 0) { | ||
var problemDetected_1 = false; | ||
['border', 'border-left', 'border-right', 'padding', 'padding-left', 'padding-right'].forEach(function (p) { | ||
var elements = _this.fetch(propertyTable, p); | ||
for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) { | ||
var element = elements_1[_i]; | ||
var problemDetected = false; | ||
for (var _b = 0, _c = ['border', 'border-left', 'border-right', 'padding', 'padding-left', 'padding-right']; _b < _c.length; _b++) { | ||
var p = _c[_b]; | ||
var elements_1 = this.fetch(propertyTable, p); | ||
for (var _d = 0, elements_2 = elements_1; _d < elements_2.length; _d++) { | ||
var element = elements_2[_d]; | ||
var value = element.node.getValue(); | ||
if (value && !value.matches('none')) { | ||
_this.addEntry(element.node, lintRules_1.Rules.BewareOfBoxModelSize); | ||
problemDetected_1 = true; | ||
this.addEntry(element.node, lintRules_1.Rules.BewareOfBoxModelSize); | ||
problemDetected = true; | ||
} | ||
} | ||
}); | ||
if (problemDetected_1) { | ||
for (var _i = 0, widthEntries_1 = widthEntries; _i < widthEntries_1.length; _i++) { | ||
var widthEntry = widthEntries_1[_i]; | ||
} | ||
if (problemDetected) { | ||
for (var _e = 0, widthEntries_1 = widthEntries; _e < widthEntries_1.length; _e++) { | ||
var widthEntry = widthEntries_1[_e]; | ||
this.addEntry(widthEntry.node, lintRules_1.Rules.BewareOfBoxModelSize); | ||
@@ -274,17 +268,18 @@ } | ||
if (heightEntries.length > 0) { | ||
var problemDetected_2 = false; | ||
['border', 'border-top', 'border-bottom', 'padding', 'padding-top', 'padding-bottom'].forEach(function (p) { | ||
var elements = _this.fetch(propertyTable, p); | ||
for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) { | ||
var element = elements_2[_i]; | ||
var problemDetected = false; | ||
for (var _f = 0, _g = ['border', 'border-top', 'border-bottom', 'padding', 'padding-top', 'padding-bottom']; _f < _g.length; _f++) { | ||
var p = _g[_f]; | ||
var elements_3 = this.fetch(propertyTable, p); | ||
for (var _h = 0, elements_4 = elements_3; _h < elements_4.length; _h++) { | ||
var element = elements_4[_h]; | ||
var value = element.node.getValue(); | ||
if (value && !value.matches('none')) { | ||
_this.addEntry(element.node, lintRules_1.Rules.BewareOfBoxModelSize); | ||
problemDetected_2 = true; | ||
this.addEntry(element.node, lintRules_1.Rules.BewareOfBoxModelSize); | ||
problemDetected = true; | ||
} | ||
} | ||
}); | ||
if (problemDetected_2) { | ||
for (var _a = 0, heightEntries_1 = heightEntries; _a < heightEntries_1.length; _a++) { | ||
var heightEntry = heightEntries_1[_a]; | ||
} | ||
if (problemDetected) { | ||
for (var _j = 0, heightEntries_1 = heightEntries; _j < heightEntries_1.length; _j++) { | ||
var heightEntry = heightEntries_1[_j]; | ||
this.addEntry(heightEntry.node, lintRules_1.Rules.BewareOfBoxModelSize); | ||
@@ -301,3 +296,4 @@ } | ||
if (displayElems.length > 0) { | ||
['width', 'height', 'margin-top', 'margin-bottom', 'float'].forEach(function (prop) { | ||
for (var _k = 0, _l = ['width', 'height', 'margin-top', 'margin-bottom', 'float']; _k < _l.length; _k++) { | ||
var prop = _l[_k]; | ||
var elem = self.fetch(propertyTable, prop); | ||
@@ -312,3 +308,3 @@ for (var index = 0; index < elem.length; index++) { | ||
} | ||
}); | ||
} | ||
} | ||
@@ -336,11 +332,2 @@ // With 'display: inline-block', 'float' has no effect | ||
///////////////////////////////////////////////////////////// | ||
// Don't use !important | ||
///////////////////////////////////////////////////////////// | ||
node.accept(function (n) { | ||
if (n.type === nodes.NodeType.Prio) { | ||
self.addEntry(n, lintRules_1.Rules.AvoidImportant); | ||
} | ||
return true; | ||
}); | ||
///////////////////////////////////////////////////////////// | ||
// Avoid 'float' | ||
@@ -357,10 +344,10 @@ ///////////////////////////////////////////////////////////// | ||
var element = propertyTable[i]; | ||
if (element.name.toLowerCase() !== 'background') { | ||
if (element.name !== 'background') { | ||
var value = element.node.getValue(); | ||
if (value && value.getText()[0] !== '-') { | ||
var elements_3 = this.fetch(propertyTable, element.name); | ||
if (elements_3.length > 1) { | ||
for (var k = 0; k < elements_3.length; k++) { | ||
var value_1 = elements_3[k].node.getValue(); | ||
if (value_1 && value_1.getText()[0] !== '-' && elements_3[k] !== element) { | ||
if (value && this.documentText.charAt(value.offset) !== '-') { | ||
var elements_5 = this.fetch(propertyTable, element.name); | ||
if (elements_5.length > 1) { | ||
for (var k = 0; k < elements_5.length; k++) { | ||
var value_1 = elements_5[k].node.getValue(); | ||
if (value_1 && this.documentText.charAt(value_1.offset) !== '-' && elements_5[k] !== element) { | ||
this.addEntry(element.node, lintRules_1.Rules.DuplicateDeclarations); | ||
@@ -378,5 +365,6 @@ } | ||
var containsUnknowns = false; | ||
declarations.getChildren().forEach(function (node) { | ||
if (_this.isCSSDeclaration(node)) { | ||
var decl = node; | ||
for (var _m = 0, _o = declarations.getChildren(); _m < _o.length; _m++) { | ||
var node_3 = _o[_m]; | ||
if (this.isCSSDeclaration(node_3)) { | ||
var decl = node_3; | ||
var name = decl.getFullPropertyName(); | ||
@@ -387,3 +375,3 @@ var firstChar = name.charAt(0); | ||
if (!languageFacts.isKnownProperty(name)) { | ||
_this.addEntry(decl.getProperty(), lintRules_1.Rules.UnknownVendorSpecificProperty); | ||
this.addEntry(decl.getProperty(), lintRules_1.Rules.UnknownVendorSpecificProperty); | ||
} | ||
@@ -396,7 +384,7 @@ var nonPrefixedName = decl.getNonPrefixedPropertyName(); | ||
if (firstChar === '*' || firstChar === '_') { | ||
_this.addEntry(decl.getProperty(), lintRules_1.Rules.IEStarHack); | ||
this.addEntry(decl.getProperty(), lintRules_1.Rules.IEStarHack); | ||
name = name.substr(1); | ||
} | ||
if (!languageFacts.isKnownProperty(name)) { | ||
_this.addEntry(decl.getProperty(), lintRules_1.Rules.UnknownProperty, localize('property.unknownproperty.detailed', "Unknown property: '{0}'", name)); | ||
this.addEntry(decl.getProperty(), lintRules_1.Rules.UnknownProperty, localize('property.unknownproperty.detailed', "Unknown property: '{0}'", name)); | ||
} | ||
@@ -409,5 +397,5 @@ propertiesBySuffix.add(name, name, null); // don't pass the node as we don't show errors on the standard | ||
} | ||
}); | ||
} | ||
if (!containsUnknowns) { | ||
var _loop_2 = function (suffix) { | ||
for (var suffix in propertiesBySuffix.data) { | ||
var entry = propertiesBySuffix.data[suffix]; | ||
@@ -417,3 +405,3 @@ var actual = entry.names; | ||
if (!needsStandard && actual.length === 1) { | ||
return "continue"; | ||
continue; // only the non-vendor specific rule is used, that's fine, no warning | ||
} | ||
@@ -427,20 +415,16 @@ var expected = []; | ||
} | ||
var addVendorSpecificWarnings = function (node) { | ||
if (needsStandard) { | ||
var message = localize('property.standard.missing', "Also define the standard property '{0}' for compatibility", suffix); | ||
_this.addEntry(node, lintRules_1.Rules.IncludeStandardPropertyWhenUsingVendorPrefix, message); | ||
var missingVendorSpecific = this.getMissingNames(expected, actual); | ||
if (missingVendorSpecific || needsStandard) { | ||
for (var _p = 0, _q = entry.nodes; _p < _q.length; _p++) { | ||
var node_4 = _q[_p]; | ||
if (needsStandard) { | ||
var message = localize('property.standard.missing', "Also define the standard property '{0}' for compatibility", suffix); | ||
this.addEntry(node_4, lintRules_1.Rules.IncludeStandardPropertyWhenUsingVendorPrefix, message); | ||
} | ||
if (missingVendorSpecific) { | ||
var message = localize('property.vendorspecific.missing', "Always include all vendor specific properties: Missing: {0}", missingVendorSpecific); | ||
this.addEntry(node_4, lintRules_1.Rules.AllVendorPrefixes, message); | ||
} | ||
} | ||
if (missingVendorSpecific) { | ||
var message = localize('property.vendorspecific.missing', "Always include all vendor specific properties: Missing: {0}", missingVendorSpecific); | ||
_this.addEntry(node, lintRules_1.Rules.AllVendorPrefixes, message); | ||
} | ||
}; | ||
var missingVendorSpecific = this_2.getMissingNames(expected, actual); | ||
if (missingVendorSpecific || needsStandard) { | ||
entry.nodes.forEach(addVendorSpecificWarnings); | ||
} | ||
}; | ||
var this_2 = this; | ||
for (var suffix in propertiesBySuffix.data) { | ||
_loop_2(suffix); | ||
} | ||
@@ -450,2 +434,9 @@ } | ||
}; | ||
LintVisitor.prototype.visitPrio = function (node) { | ||
///////////////////////////////////////////////////////////// | ||
// Don't use !important | ||
///////////////////////////////////////////////////////////// | ||
this.addEntry(node, lintRules_1.Rules.AvoidImportant); | ||
return true; | ||
}; | ||
LintVisitor.prototype.visitNumericValue = function (node) { | ||
@@ -465,3 +456,2 @@ ///////////////////////////////////////////////////////////// | ||
LintVisitor.prototype.visitFontFace = function (node) { | ||
var _this = this; | ||
var declarations = node.getDeclarations(); | ||
@@ -474,5 +464,6 @@ if (!declarations) { | ||
var containsUnknowns = false; | ||
declarations.getChildren().forEach(function (node) { | ||
if (_this.isCSSDeclaration(node)) { | ||
var name = (node.getProperty().getName().toLocaleLowerCase()); | ||
for (var _i = 0, _a = declarations.getChildren(); _i < _a.length; _i++) { | ||
var node_5 = _a[_i]; | ||
if (this.isCSSDeclaration(node_5)) { | ||
var name = (node_5.getProperty().getName().toLowerCase()); | ||
if (name === 'src') { | ||
@@ -488,3 +479,3 @@ definesSrc = true; | ||
} | ||
}); | ||
} | ||
if (!containsUnknowns && (!definesSrc || !definesFontFamily)) { | ||
@@ -508,11 +499,9 @@ this.addEntry(node, lintRules_1.Rules.RequiredPropertiesForFontFace); | ||
}; | ||
LintVisitor.prototype.visitUnknownNode = function (node) { | ||
LintVisitor.prototype.visitHexColorValue = function (node) { | ||
// Rule: #eeff0011 or #eeff00 or #ef01 or #ef0 | ||
if (node.type === nodes.NodeType.HexColorValue) { | ||
var text = node.getText(); | ||
if (text.length !== 9 && text.length !== 7 && text.length !== 5 && text.length !== 4) { | ||
this.addEntry(node, lintRules_1.Rules.HexColorLength); | ||
} | ||
var length = node.length; | ||
if (length !== 9 && length !== 7 && length !== 5 && length !== 4) { | ||
this.addEntry(node, lintRules_1.Rules.HexColorLength); | ||
} | ||
return true; | ||
return false; | ||
}; | ||
@@ -519,0 +508,0 @@ LintVisitor.prototype.visitFunction = function (node) { |
@@ -42,5 +42,5 @@ var __extends = (this && this.__extends) || (function () { | ||
SCSSCompletion.prototype.createFunctionProposals = function (proposals, existingNode, sortToEnd, result) { | ||
var _this = this; | ||
proposals.forEach(function (p) { | ||
var insertText = p.func.replace(/\[?(\$\w+)\]?/g, _this.createReplaceFunction()); | ||
for (var _i = 0, proposals_1 = proposals; _i < proposals_1.length; _i++) { | ||
var p = proposals_1[_i]; | ||
var insertText = p.func.replace(/\[?(\$\w+)\]?/g, this.createReplaceFunction()); | ||
var label = p.func.substr(0, p.func.indexOf('(')); | ||
@@ -51,3 +51,3 @@ var item = { | ||
documentation: p.desc, | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(_this.getCompletionRange(existingNode), insertText), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText), | ||
insertTextFormat: vscode_languageserver_types_1.InsertTextFormat.Snippet, | ||
@@ -60,3 +60,3 @@ kind: vscode_languageserver_types_1.CompletionItemKind.Function | ||
result.items.push(item); | ||
}); | ||
} | ||
return result; | ||
@@ -63,0 +63,0 @@ }; |
@@ -170,3 +170,2 @@ var __extends = (this && this.__extends) || (function () { | ||
MarkedStringPrinter.prototype.doPrintElement = function (element, indent) { | ||
var _this = this; | ||
var name = element.findAttribute('name'); | ||
@@ -189,3 +188,4 @@ // special case: a simple label | ||
if (element.attributes) { | ||
element.attributes.forEach(function (attr) { | ||
for (var _i = 0, _a = element.attributes; _i < _a.length; _i++) { | ||
var attr = _a[_i]; | ||
if (attr.name !== 'name') { | ||
@@ -197,6 +197,6 @@ content.push(' '); | ||
content.push('='); | ||
content.push(quotes.ensure(value, _this.quote)); | ||
content.push(quotes.ensure(value, this.quote)); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
@@ -225,3 +225,4 @@ content.push('>'); | ||
var result = new Element(); | ||
node.getChildren().forEach(function (child) { | ||
for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) { | ||
var child = _a[_i]; | ||
switch (child.type) { | ||
@@ -307,3 +308,3 @@ case nodes.NodeType.SelectorCombinator: | ||
} | ||
}); | ||
} | ||
return result; | ||
@@ -337,3 +338,2 @@ } | ||
SelectorElementBuilder.prototype.processSelector = function (selector) { | ||
var _this = this; | ||
var parentElement = null; | ||
@@ -351,20 +351,21 @@ if (!(this.element instanceof RootElement)) { | ||
} | ||
selector.getChildren().forEach(function (selectorChild) { | ||
for (var _i = 0, _a = selector.getChildren(); _i < _a.length; _i++) { | ||
var selectorChild = _a[_i]; | ||
if (selectorChild instanceof nodes.SimpleSelector) { | ||
if (_this.prev instanceof nodes.SimpleSelector) { | ||
if (this.prev instanceof nodes.SimpleSelector) { | ||
var labelElement = new LabelElement('\u2026'); | ||
_this.element.addChild(labelElement); | ||
_this.element = labelElement; | ||
this.element.addChild(labelElement); | ||
this.element = labelElement; | ||
} | ||
else if (_this.prev && (_this.prev.matches('+') || _this.prev.matches('~'))) { | ||
_this.element = _this.element.parent; | ||
else if (this.prev && (this.prev.matches('+') || this.prev.matches('~'))) { | ||
this.element = this.element.parent; | ||
} | ||
if (_this.prev && _this.prev.matches('~')) { | ||
_this.element.addChild(toElement(selectorChild)); | ||
_this.element.addChild(new LabelElement('\u22EE')); | ||
if (this.prev && this.prev.matches('~')) { | ||
this.element.addChild(toElement(selectorChild)); | ||
this.element.addChild(new LabelElement('\u22EE')); | ||
} | ||
var thisElement = toElement(selectorChild, parentElement); | ||
var root = thisElement.findRoot(); | ||
_this.element.addChild(root); | ||
_this.element = thisElement; | ||
this.element.addChild(root); | ||
this.element = thisElement; | ||
} | ||
@@ -376,5 +377,5 @@ if (selectorChild instanceof nodes.SimpleSelector || | ||
selectorChild.type === nodes.NodeType.SelectorCombinatorAllSiblings) { | ||
_this.prev = selectorChild; | ||
this.prev = selectorChild; | ||
} | ||
}); | ||
} | ||
}; | ||
@@ -381,0 +382,0 @@ return SelectorElementBuilder; |
{ | ||
"name": "vscode-css-languageservice", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Language service for CSS, LESS and SCSS", | ||
@@ -5,0 +5,0 @@ "main": "./lib/cssLanguageService.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
803989
21150