UNPKG

monaco-editor

Version:
1,523 lines (1,519 loc) • 1.23 MB
/*!----------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Version: 0.34.1(547870b6881302c5b4ff32173c16d06009e3588f) * Released under the MIT license * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt *-----------------------------------------------------------------------------*/ // src/language/css/css.worker.ts import * as worker from "../../editor/editor.worker.js"; // node_modules/vscode-css-languageservice/lib/esm/parser/cssScanner.js var TokenType; (function(TokenType2) { TokenType2[TokenType2["Ident"] = 0] = "Ident"; TokenType2[TokenType2["AtKeyword"] = 1] = "AtKeyword"; TokenType2[TokenType2["String"] = 2] = "String"; TokenType2[TokenType2["BadString"] = 3] = "BadString"; TokenType2[TokenType2["UnquotedString"] = 4] = "UnquotedString"; TokenType2[TokenType2["Hash"] = 5] = "Hash"; TokenType2[TokenType2["Num"] = 6] = "Num"; TokenType2[TokenType2["Percentage"] = 7] = "Percentage"; TokenType2[TokenType2["Dimension"] = 8] = "Dimension"; TokenType2[TokenType2["UnicodeRange"] = 9] = "UnicodeRange"; TokenType2[TokenType2["CDO"] = 10] = "CDO"; TokenType2[TokenType2["CDC"] = 11] = "CDC"; TokenType2[TokenType2["Colon"] = 12] = "Colon"; TokenType2[TokenType2["SemiColon"] = 13] = "SemiColon"; TokenType2[TokenType2["CurlyL"] = 14] = "CurlyL"; TokenType2[TokenType2["CurlyR"] = 15] = "CurlyR"; TokenType2[TokenType2["ParenthesisL"] = 16] = "ParenthesisL"; TokenType2[TokenType2["ParenthesisR"] = 17] = "ParenthesisR"; TokenType2[TokenType2["BracketL"] = 18] = "BracketL"; TokenType2[TokenType2["BracketR"] = 19] = "BracketR"; TokenType2[TokenType2["Whitespace"] = 20] = "Whitespace"; TokenType2[TokenType2["Includes"] = 21] = "Includes"; TokenType2[TokenType2["Dashmatch"] = 22] = "Dashmatch"; TokenType2[TokenType2["SubstringOperator"] = 23] = "SubstringOperator"; TokenType2[TokenType2["PrefixOperator"] = 24] = "PrefixOperator"; TokenType2[TokenType2["SuffixOperator"] = 25] = "SuffixOperator"; TokenType2[TokenType2["Delim"] = 26] = "Delim"; TokenType2[TokenType2["EMS"] = 27] = "EMS"; TokenType2[TokenType2["EXS"] = 28] = "EXS"; TokenType2[TokenType2["Length"] = 29] = "Length"; TokenType2[TokenType2["Angle"] = 30] = "Angle"; TokenType2[TokenType2["Time"] = 31] = "Time"; TokenType2[TokenType2["Freq"] = 32] = "Freq"; TokenType2[TokenType2["Exclamation"] = 33] = "Exclamation"; TokenType2[TokenType2["Resolution"] = 34] = "Resolution"; TokenType2[TokenType2["Comma"] = 35] = "Comma"; TokenType2[TokenType2["Charset"] = 36] = "Charset"; TokenType2[TokenType2["EscapedJavaScript"] = 37] = "EscapedJavaScript"; TokenType2[TokenType2["BadEscapedJavaScript"] = 38] = "BadEscapedJavaScript"; TokenType2[TokenType2["Comment"] = 39] = "Comment"; TokenType2[TokenType2["SingleLineComment"] = 40] = "SingleLineComment"; TokenType2[TokenType2["EOF"] = 41] = "EOF"; TokenType2[TokenType2["CustomToken"] = 42] = "CustomToken"; })(TokenType || (TokenType = {})); var MultiLineStream = function() { function MultiLineStream2(source) { this.source = source; this.len = source.length; this.position = 0; } MultiLineStream2.prototype.substring = function(from, to) { if (to === void 0) { to = this.position; } return this.source.substring(from, to); }; MultiLineStream2.prototype.eos = function() { return this.len <= this.position; }; MultiLineStream2.prototype.pos = function() { return this.position; }; MultiLineStream2.prototype.goBackTo = function(pos) { this.position = pos; }; MultiLineStream2.prototype.goBack = function(n) { this.position -= n; }; MultiLineStream2.prototype.advance = function(n) { this.position += n; }; MultiLineStream2.prototype.nextChar = function() { return this.source.charCodeAt(this.position++) || 0; }; MultiLineStream2.prototype.peekChar = function(n) { if (n === void 0) { n = 0; } return this.source.charCodeAt(this.position + n) || 0; }; MultiLineStream2.prototype.lookbackChar = function(n) { if (n === void 0) { n = 0; } return this.source.charCodeAt(this.position - n) || 0; }; MultiLineStream2.prototype.advanceIfChar = function(ch) { if (ch === this.source.charCodeAt(this.position)) { this.position++; return true; } return false; }; MultiLineStream2.prototype.advanceIfChars = function(ch) { if (this.position + ch.length > this.source.length) { return false; } var i = 0; for (; i < ch.length; i++) { if (this.source.charCodeAt(this.position + i) !== ch[i]) { return false; } } this.advance(i); return true; }; MultiLineStream2.prototype.advanceWhileChar = function(condition) { var posNow = this.position; while (this.position < this.len && condition(this.source.charCodeAt(this.position))) { this.position++; } return this.position - posNow; }; return MultiLineStream2; }(); var _a = "a".charCodeAt(0); var _f = "f".charCodeAt(0); var _z = "z".charCodeAt(0); var _u = "u".charCodeAt(0); var _A = "A".charCodeAt(0); var _F = "F".charCodeAt(0); var _Z = "Z".charCodeAt(0); var _0 = "0".charCodeAt(0); var _9 = "9".charCodeAt(0); var _TLD = "~".charCodeAt(0); var _HAT = "^".charCodeAt(0); var _EQS = "=".charCodeAt(0); var _PIP = "|".charCodeAt(0); var _MIN = "-".charCodeAt(0); var _USC = "_".charCodeAt(0); var _PRC = "%".charCodeAt(0); var _MUL = "*".charCodeAt(0); var _LPA = "(".charCodeAt(0); var _RPA = ")".charCodeAt(0); var _LAN = "<".charCodeAt(0); var _RAN = ">".charCodeAt(0); var _ATS = "@".charCodeAt(0); var _HSH = "#".charCodeAt(0); var _DLR = "$".charCodeAt(0); var _BSL = "\\".charCodeAt(0); var _FSL = "/".charCodeAt(0); var _NWL = "\n".charCodeAt(0); var _CAR = "\r".charCodeAt(0); var _LFD = "\f".charCodeAt(0); var _DQO = '"'.charCodeAt(0); var _SQO = "'".charCodeAt(0); var _WSP = " ".charCodeAt(0); var _TAB = " ".charCodeAt(0); var _SEM = ";".charCodeAt(0); var _COL = ":".charCodeAt(0); var _CUL = "{".charCodeAt(0); var _CUR = "}".charCodeAt(0); var _BRL = "[".charCodeAt(0); var _BRR = "]".charCodeAt(0); var _CMA = ",".charCodeAt(0); var _DOT = ".".charCodeAt(0); var _BNG = "!".charCodeAt(0); var _QSM = "?".charCodeAt(0); var _PLS = "+".charCodeAt(0); var staticTokenTable = {}; staticTokenTable[_SEM] = TokenType.SemiColon; staticTokenTable[_COL] = TokenType.Colon; staticTokenTable[_CUL] = TokenType.CurlyL; staticTokenTable[_CUR] = TokenType.CurlyR; staticTokenTable[_BRR] = TokenType.BracketR; staticTokenTable[_BRL] = TokenType.BracketL; staticTokenTable[_LPA] = TokenType.ParenthesisL; staticTokenTable[_RPA] = TokenType.ParenthesisR; staticTokenTable[_CMA] = TokenType.Comma; var staticUnitTable = {}; staticUnitTable["em"] = TokenType.EMS; staticUnitTable["ex"] = TokenType.EXS; staticUnitTable["px"] = TokenType.Length; staticUnitTable["cm"] = TokenType.Length; staticUnitTable["mm"] = TokenType.Length; staticUnitTable["in"] = TokenType.Length; staticUnitTable["pt"] = TokenType.Length; staticUnitTable["pc"] = TokenType.Length; staticUnitTable["deg"] = TokenType.Angle; staticUnitTable["rad"] = TokenType.Angle; staticUnitTable["grad"] = TokenType.Angle; staticUnitTable["ms"] = TokenType.Time; staticUnitTable["s"] = TokenType.Time; staticUnitTable["hz"] = TokenType.Freq; staticUnitTable["khz"] = TokenType.Freq; staticUnitTable["%"] = TokenType.Percentage; staticUnitTable["fr"] = TokenType.Percentage; staticUnitTable["dpi"] = TokenType.Resolution; staticUnitTable["dpcm"] = TokenType.Resolution; var Scanner = function() { function Scanner2() { this.stream = new MultiLineStream(""); this.ignoreComment = true; this.ignoreWhitespace = true; this.inURL = false; } Scanner2.prototype.setSource = function(input) { this.stream = new MultiLineStream(input); }; Scanner2.prototype.finishToken = function(offset, type, text) { return { offset, len: this.stream.pos() - offset, type, text: text || this.stream.substring(offset) }; }; Scanner2.prototype.substring = function(offset, len) { return this.stream.substring(offset, offset + len); }; Scanner2.prototype.pos = function() { return this.stream.pos(); }; Scanner2.prototype.goBackTo = function(pos) { this.stream.goBackTo(pos); }; Scanner2.prototype.scanUnquotedString = function() { var offset = this.stream.pos(); var content = []; if (this._unquotedString(content)) { return this.finishToken(offset, TokenType.UnquotedString, content.join("")); } return null; }; Scanner2.prototype.scan = function() { var triviaToken = this.trivia(); if (triviaToken !== null) { return triviaToken; } var offset = this.stream.pos(); if (this.stream.eos()) { return this.finishToken(offset, TokenType.EOF); } return this.scanNext(offset); }; Scanner2.prototype.tryScanUnicode = function() { var offset = this.stream.pos(); if (!this.stream.eos() && this._unicodeRange()) { return this.finishToken(offset, TokenType.UnicodeRange); } this.stream.goBackTo(offset); return void 0; }; Scanner2.prototype.scanNext = function(offset) { if (this.stream.advanceIfChars([_LAN, _BNG, _MIN, _MIN])) { return this.finishToken(offset, TokenType.CDO); } if (this.stream.advanceIfChars([_MIN, _MIN, _RAN])) { return this.finishToken(offset, TokenType.CDC); } var content = []; if (this.ident(content)) { return this.finishToken(offset, TokenType.Ident, content.join("")); } if (this.stream.advanceIfChar(_ATS)) { content = ["@"]; if (this._name(content)) { var keywordText = content.join(""); if (keywordText === "@charset") { return this.finishToken(offset, TokenType.Charset, keywordText); } return this.finishToken(offset, TokenType.AtKeyword, keywordText); } else { return this.finishToken(offset, TokenType.Delim); } } if (this.stream.advanceIfChar(_HSH)) { content = ["#"]; if (this._name(content)) { return this.finishToken(offset, TokenType.Hash, content.join("")); } else { return this.finishToken(offset, TokenType.Delim); } } if (this.stream.advanceIfChar(_BNG)) { return this.finishToken(offset, TokenType.Exclamation); } if (this._number()) { var pos = this.stream.pos(); content = [this.stream.substring(offset, pos)]; if (this.stream.advanceIfChar(_PRC)) { return this.finishToken(offset, TokenType.Percentage); } else if (this.ident(content)) { var dim = this.stream.substring(pos).toLowerCase(); var tokenType_1 = staticUnitTable[dim]; if (typeof tokenType_1 !== "undefined") { return this.finishToken(offset, tokenType_1, content.join("")); } else { return this.finishToken(offset, TokenType.Dimension, content.join("")); } } return this.finishToken(offset, TokenType.Num); } content = []; var tokenType = this._string(content); if (tokenType !== null) { return this.finishToken(offset, tokenType, content.join("")); } tokenType = staticTokenTable[this.stream.peekChar()]; if (typeof tokenType !== "undefined") { this.stream.advance(1); return this.finishToken(offset, tokenType); } if (this.stream.peekChar(0) === _TLD && this.stream.peekChar(1) === _EQS) { this.stream.advance(2); return this.finishToken(offset, TokenType.Includes); } if (this.stream.peekChar(0) === _PIP && this.stream.peekChar(1) === _EQS) { this.stream.advance(2); return this.finishToken(offset, TokenType.Dashmatch); } if (this.stream.peekChar(0) === _MUL && this.stream.peekChar(1) === _EQS) { this.stream.advance(2); return this.finishToken(offset, TokenType.SubstringOperator); } if (this.stream.peekChar(0) === _HAT && this.stream.peekChar(1) === _EQS) { this.stream.advance(2); return this.finishToken(offset, TokenType.PrefixOperator); } if (this.stream.peekChar(0) === _DLR && this.stream.peekChar(1) === _EQS) { this.stream.advance(2); return this.finishToken(offset, TokenType.SuffixOperator); } this.stream.nextChar(); return this.finishToken(offset, TokenType.Delim); }; Scanner2.prototype.trivia = function() { while (true) { var offset = this.stream.pos(); if (this._whitespace()) { if (!this.ignoreWhitespace) { return this.finishToken(offset, TokenType.Whitespace); } } else if (this.comment()) { if (!this.ignoreComment) { return this.finishToken(offset, TokenType.Comment); } } else { return null; } } }; Scanner2.prototype.comment = function() { if (this.stream.advanceIfChars([_FSL, _MUL])) { var success_1 = false, hot_1 = false; this.stream.advanceWhileChar(function(ch) { if (hot_1 && ch === _FSL) { success_1 = true; return false; } hot_1 = ch === _MUL; return true; }); if (success_1) { this.stream.advance(1); } return true; } return false; }; Scanner2.prototype._number = function() { var npeek = 0, ch; if (this.stream.peekChar() === _DOT) { npeek = 1; } ch = this.stream.peekChar(npeek); if (ch >= _0 && ch <= _9) { this.stream.advance(npeek + 1); this.stream.advanceWhileChar(function(ch2) { return ch2 >= _0 && ch2 <= _9 || npeek === 0 && ch2 === _DOT; }); return true; } return false; }; Scanner2.prototype._newline = function(result) { var ch = this.stream.peekChar(); switch (ch) { case _CAR: case _LFD: case _NWL: this.stream.advance(1); result.push(String.fromCharCode(ch)); if (ch === _CAR && this.stream.advanceIfChar(_NWL)) { result.push("\n"); } return true; } return false; }; Scanner2.prototype._escape = function(result, includeNewLines) { var ch = this.stream.peekChar(); if (ch === _BSL) { this.stream.advance(1); ch = this.stream.peekChar(); var hexNumCount = 0; while (hexNumCount < 6 && (ch >= _0 && ch <= _9 || ch >= _a && ch <= _f || ch >= _A && ch <= _F)) { this.stream.advance(1); ch = this.stream.peekChar(); hexNumCount++; } if (hexNumCount > 0) { try { var hexVal = parseInt(this.stream.substring(this.stream.pos() - hexNumCount), 16); if (hexVal) { result.push(String.fromCharCode(hexVal)); } } catch (e) { } if (ch === _WSP || ch === _TAB) { this.stream.advance(1); } else { this._newline([]); } return true; } if (ch !== _CAR && ch !== _LFD && ch !== _NWL) { this.stream.advance(1); result.push(String.fromCharCode(ch)); return true; } else if (includeNewLines) { return this._newline(result); } } return false; }; Scanner2.prototype._stringChar = function(closeQuote, result) { var ch = this.stream.peekChar(); if (ch !== 0 && ch !== closeQuote && ch !== _BSL && ch !== _CAR && ch !== _LFD && ch !== _NWL) { this.stream.advance(1); result.push(String.fromCharCode(ch)); return true; } return false; }; Scanner2.prototype._string = function(result) { if (this.stream.peekChar() === _SQO || this.stream.peekChar() === _DQO) { var closeQuote = this.stream.nextChar(); result.push(String.fromCharCode(closeQuote)); while (this._stringChar(closeQuote, result) || this._escape(result, true)) { } if (this.stream.peekChar() === closeQuote) { this.stream.nextChar(); result.push(String.fromCharCode(closeQuote)); return TokenType.String; } else { return TokenType.BadString; } } return null; }; Scanner2.prototype._unquotedChar = function(result) { var ch = this.stream.peekChar(); if (ch !== 0 && ch !== _BSL && ch !== _SQO && ch !== _DQO && ch !== _LPA && ch !== _RPA && ch !== _WSP && ch !== _TAB && ch !== _NWL && ch !== _LFD && ch !== _CAR) { this.stream.advance(1); result.push(String.fromCharCode(ch)); return true; } return false; }; Scanner2.prototype._unquotedString = function(result) { var hasContent = false; while (this._unquotedChar(result) || this._escape(result)) { hasContent = true; } return hasContent; }; Scanner2.prototype._whitespace = function() { var n = this.stream.advanceWhileChar(function(ch) { return ch === _WSP || ch === _TAB || ch === _NWL || ch === _LFD || ch === _CAR; }); return n > 0; }; Scanner2.prototype._name = function(result) { var matched = false; while (this._identChar(result) || this._escape(result)) { matched = true; } return matched; }; Scanner2.prototype.ident = function(result) { var pos = this.stream.pos(); var hasMinus = this._minus(result); if (hasMinus) { if (this._minus(result) || this._identFirstChar(result) || this._escape(result)) { while (this._identChar(result) || this._escape(result)) { } return true; } } else if (this._identFirstChar(result) || this._escape(result)) { while (this._identChar(result) || this._escape(result)) { } return true; } this.stream.goBackTo(pos); return false; }; Scanner2.prototype._identFirstChar = function(result) { var ch = this.stream.peekChar(); if (ch === _USC || ch >= _a && ch <= _z || ch >= _A && ch <= _Z || ch >= 128 && ch <= 65535) { this.stream.advance(1); result.push(String.fromCharCode(ch)); return true; } return false; }; Scanner2.prototype._minus = function(result) { var ch = this.stream.peekChar(); if (ch === _MIN) { this.stream.advance(1); result.push(String.fromCharCode(ch)); return true; } return false; }; Scanner2.prototype._identChar = function(result) { var ch = this.stream.peekChar(); if (ch === _USC || ch === _MIN || ch >= _a && ch <= _z || ch >= _A && ch <= _Z || ch >= _0 && ch <= _9 || ch >= 128 && ch <= 65535) { this.stream.advance(1); result.push(String.fromCharCode(ch)); return true; } return false; }; Scanner2.prototype._unicodeRange = function() { if (this.stream.advanceIfChar(_PLS)) { var isHexDigit = function(ch) { return ch >= _0 && ch <= _9 || ch >= _a && ch <= _f || ch >= _A && ch <= _F; }; var codePoints = this.stream.advanceWhileChar(isHexDigit) + this.stream.advanceWhileChar(function(ch) { return ch === _QSM; }); if (codePoints >= 1 && codePoints <= 6) { if (this.stream.advanceIfChar(_MIN)) { var digits = this.stream.advanceWhileChar(isHexDigit); if (digits >= 1 && digits <= 6) { return true; } } else { return true; } } } return false; }; return Scanner2; }(); // node_modules/vscode-css-languageservice/lib/esm/utils/strings.js function startsWith(haystack, needle) { if (haystack.length < needle.length) { return false; } for (var i = 0; i < needle.length; i++) { if (haystack[i] !== needle[i]) { return false; } } return true; } function endsWith(haystack, needle) { var diff = haystack.length - needle.length; if (diff > 0) { return haystack.lastIndexOf(needle) === diff; } else if (diff === 0) { return haystack === needle; } else { return false; } } function difference(first, second, maxLenDelta) { if (maxLenDelta === void 0) { maxLenDelta = 4; } var lengthDifference = Math.abs(first.length - second.length); if (lengthDifference > maxLenDelta) { return 0; } var LCS = []; var zeroArray = []; var i, j; for (i = 0; i < second.length + 1; ++i) { zeroArray.push(0); } for (i = 0; i < first.length + 1; ++i) { LCS.push(zeroArray); } for (i = 1; i < first.length + 1; ++i) { for (j = 1; j < second.length + 1; ++j) { if (first[i - 1] === second[j - 1]) { LCS[i][j] = LCS[i - 1][j - 1] + 1; } else { LCS[i][j] = Math.max(LCS[i - 1][j], LCS[i][j - 1]); } } } return LCS[first.length][second.length] - Math.sqrt(lengthDifference); } function getLimitedString(str, ellipsis) { if (ellipsis === void 0) { ellipsis = true; } if (!str) { return ""; } if (str.length < 140) { return str; } return str.slice(0, 140) + (ellipsis ? "\u2026" : ""); } function trim(str, regexp) { var m = regexp.exec(str); if (m && m[0].length) { return str.substr(0, str.length - m[0].length); } return str; } function repeat(value, count) { var s = ""; while (count > 0) { if ((count & 1) === 1) { s += value; } value += value; count = count >>> 1; } return s; } // node_modules/vscode-css-languageservice/lib/esm/parser/cssNodes.js var __extends = function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var NodeType; (function(NodeType2) { NodeType2[NodeType2["Undefined"] = 0] = "Undefined"; NodeType2[NodeType2["Identifier"] = 1] = "Identifier"; NodeType2[NodeType2["Stylesheet"] = 2] = "Stylesheet"; NodeType2[NodeType2["Ruleset"] = 3] = "Ruleset"; NodeType2[NodeType2["Selector"] = 4] = "Selector"; NodeType2[NodeType2["SimpleSelector"] = 5] = "SimpleSelector"; NodeType2[NodeType2["SelectorInterpolation"] = 6] = "SelectorInterpolation"; NodeType2[NodeType2["SelectorCombinator"] = 7] = "SelectorCombinator"; NodeType2[NodeType2["SelectorCombinatorParent"] = 8] = "SelectorCombinatorParent"; NodeType2[NodeType2["SelectorCombinatorSibling"] = 9] = "SelectorCombinatorSibling"; NodeType2[NodeType2["SelectorCombinatorAllSiblings"] = 10] = "SelectorCombinatorAllSiblings"; NodeType2[NodeType2["SelectorCombinatorShadowPiercingDescendant"] = 11] = "SelectorCombinatorShadowPiercingDescendant"; NodeType2[NodeType2["Page"] = 12] = "Page"; NodeType2[NodeType2["PageBoxMarginBox"] = 13] = "PageBoxMarginBox"; NodeType2[NodeType2["ClassSelector"] = 14] = "ClassSelector"; NodeType2[NodeType2["IdentifierSelector"] = 15] = "IdentifierSelector"; NodeType2[NodeType2["ElementNameSelector"] = 16] = "ElementNameSelector"; NodeType2[NodeType2["PseudoSelector"] = 17] = "PseudoSelector"; NodeType2[NodeType2["AttributeSelector"] = 18] = "AttributeSelector"; NodeType2[NodeType2["Declaration"] = 19] = "Declaration"; NodeType2[NodeType2["Declarations"] = 20] = "Declarations"; NodeType2[NodeType2["Property"] = 21] = "Property"; NodeType2[NodeType2["Expression"] = 22] = "Expression"; NodeType2[NodeType2["BinaryExpression"] = 23] = "BinaryExpression"; NodeType2[NodeType2["Term"] = 24] = "Term"; NodeType2[NodeType2["Operator"] = 25] = "Operator"; NodeType2[NodeType2["Value"] = 26] = "Value"; NodeType2[NodeType2["StringLiteral"] = 27] = "StringLiteral"; NodeType2[NodeType2["URILiteral"] = 28] = "URILiteral"; NodeType2[NodeType2["EscapedValue"] = 29] = "EscapedValue"; NodeType2[NodeType2["Function"] = 30] = "Function"; NodeType2[NodeType2["NumericValue"] = 31] = "NumericValue"; NodeType2[NodeType2["HexColorValue"] = 32] = "HexColorValue"; NodeType2[NodeType2["RatioValue"] = 33] = "RatioValue"; NodeType2[NodeType2["MixinDeclaration"] = 34] = "MixinDeclaration"; NodeType2[NodeType2["MixinReference"] = 35] = "MixinReference"; NodeType2[NodeType2["VariableName"] = 36] = "VariableName"; NodeType2[NodeType2["VariableDeclaration"] = 37] = "VariableDeclaration"; NodeType2[NodeType2["Prio"] = 38] = "Prio"; NodeType2[NodeType2["Interpolation"] = 39] = "Interpolation"; NodeType2[NodeType2["NestedProperties"] = 40] = "NestedProperties"; NodeType2[NodeType2["ExtendsReference"] = 41] = "ExtendsReference"; NodeType2[NodeType2["SelectorPlaceholder"] = 42] = "SelectorPlaceholder"; NodeType2[NodeType2["Debug"] = 43] = "Debug"; NodeType2[NodeType2["If"] = 44] = "If"; NodeType2[NodeType2["Else"] = 45] = "Else"; NodeType2[NodeType2["For"] = 46] = "For"; NodeType2[NodeType2["Each"] = 47] = "Each"; NodeType2[NodeType2["While"] = 48] = "While"; NodeType2[NodeType2["MixinContentReference"] = 49] = "MixinContentReference"; NodeType2[NodeType2["MixinContentDeclaration"] = 50] = "MixinContentDeclaration"; NodeType2[NodeType2["Media"] = 51] = "Media"; NodeType2[NodeType2["Keyframe"] = 52] = "Keyframe"; NodeType2[NodeType2["FontFace"] = 53] = "FontFace"; NodeType2[NodeType2["Import"] = 54] = "Import"; NodeType2[NodeType2["Namespace"] = 55] = "Namespace"; NodeType2[NodeType2["Invocation"] = 56] = "Invocation"; NodeType2[NodeType2["FunctionDeclaration"] = 57] = "FunctionDeclaration"; NodeType2[NodeType2["ReturnStatement"] = 58] = "ReturnStatement"; NodeType2[NodeType2["MediaQuery"] = 59] = "MediaQuery"; NodeType2[NodeType2["MediaCondition"] = 60] = "MediaCondition"; NodeType2[NodeType2["MediaFeature"] = 61] = "MediaFeature"; NodeType2[NodeType2["FunctionParameter"] = 62] = "FunctionParameter"; NodeType2[NodeType2["FunctionArgument"] = 63] = "FunctionArgument"; NodeType2[NodeType2["KeyframeSelector"] = 64] = "KeyframeSelector"; NodeType2[NodeType2["ViewPort"] = 65] = "ViewPort"; NodeType2[NodeType2["Document"] = 66] = "Document"; NodeType2[NodeType2["AtApplyRule"] = 67] = "AtApplyRule"; NodeType2[NodeType2["CustomPropertyDeclaration"] = 68] = "CustomPropertyDeclaration"; NodeType2[NodeType2["CustomPropertySet"] = 69] = "CustomPropertySet"; NodeType2[NodeType2["ListEntry"] = 70] = "ListEntry"; NodeType2[NodeType2["Supports"] = 71] = "Supports"; NodeType2[NodeType2["SupportsCondition"] = 72] = "SupportsCondition"; NodeType2[NodeType2["NamespacePrefix"] = 73] = "NamespacePrefix"; NodeType2[NodeType2["GridLine"] = 74] = "GridLine"; NodeType2[NodeType2["Plugin"] = 75] = "Plugin"; NodeType2[NodeType2["UnknownAtRule"] = 76] = "UnknownAtRule"; NodeType2[NodeType2["Use"] = 77] = "Use"; NodeType2[NodeType2["ModuleConfiguration"] = 78] = "ModuleConfiguration"; NodeType2[NodeType2["Forward"] = 79] = "Forward"; NodeType2[NodeType2["ForwardVisibility"] = 80] = "ForwardVisibility"; NodeType2[NodeType2["Module"] = 81] = "Module"; NodeType2[NodeType2["UnicodeRange"] = 82] = "UnicodeRange"; })(NodeType || (NodeType = {})); var ReferenceType; (function(ReferenceType2) { ReferenceType2[ReferenceType2["Mixin"] = 0] = "Mixin"; ReferenceType2[ReferenceType2["Rule"] = 1] = "Rule"; ReferenceType2[ReferenceType2["Variable"] = 2] = "Variable"; ReferenceType2[ReferenceType2["Function"] = 3] = "Function"; ReferenceType2[ReferenceType2["Keyframe"] = 4] = "Keyframe"; ReferenceType2[ReferenceType2["Unknown"] = 5] = "Unknown"; ReferenceType2[ReferenceType2["Module"] = 6] = "Module"; ReferenceType2[ReferenceType2["Forward"] = 7] = "Forward"; ReferenceType2[ReferenceType2["ForwardVisibility"] = 8] = "ForwardVisibility"; })(ReferenceType || (ReferenceType = {})); function getNodeAtOffset(node, offset) { var candidate = null; if (!node || offset < node.offset || offset > node.end) { return null; } node.accept(function(node2) { if (node2.offset === -1 && node2.length === -1) { return true; } if (node2.offset <= offset && node2.end >= offset) { if (!candidate) { candidate = node2; } else if (node2.length <= candidate.length) { candidate = node2; } return true; } return false; }); return candidate; } function getNodePath(node, offset) { var candidate = getNodeAtOffset(node, offset); var path = []; while (candidate) { path.unshift(candidate); candidate = candidate.parent; } return path; } function getParentDeclaration(node) { var decl = node.findParent(NodeType.Declaration); var value = decl && decl.getValue(); if (value && value.encloses(node)) { return decl; } return null; } var Node = function() { function Node2(offset, len, nodeType) { if (offset === void 0) { offset = -1; } if (len === void 0) { len = -1; } this.parent = null; this.offset = offset; this.length = len; if (nodeType) { this.nodeType = nodeType; } } Object.defineProperty(Node2.prototype, "end", { get: function() { return this.offset + this.length; }, enumerable: false, configurable: true }); Object.defineProperty(Node2.prototype, "type", { get: function() { return this.nodeType || NodeType.Undefined; }, set: function(type) { this.nodeType = type; }, enumerable: false, configurable: true }); Node2.prototype.getTextProvider = function() { var node = this; while (node && !node.textProvider) { node = node.parent; } if (node) { return node.textProvider; } return function() { return "unknown"; }; }; Node2.prototype.getText = function() { return this.getTextProvider()(this.offset, this.length); }; Node2.prototype.matches = function(str) { return this.length === str.length && this.getTextProvider()(this.offset, this.length) === str; }; Node2.prototype.startsWith = function(str) { return this.length >= str.length && this.getTextProvider()(this.offset, str.length) === str; }; Node2.prototype.endsWith = function(str) { return this.length >= str.length && this.getTextProvider()(this.end - str.length, str.length) === str; }; Node2.prototype.accept = function(visitor) { if (visitor(this) && this.children) { for (var _i = 0, _a2 = this.children; _i < _a2.length; _i++) { var child = _a2[_i]; child.accept(visitor); } } }; Node2.prototype.acceptVisitor = function(visitor) { this.accept(visitor.visitNode.bind(visitor)); }; Node2.prototype.adoptChild = function(node, index) { if (index === void 0) { index = -1; } if (node.parent && node.parent.children) { var idx = node.parent.children.indexOf(node); if (idx >= 0) { node.parent.children.splice(idx, 1); } } node.parent = this; var children = this.children; if (!children) { children = this.children = []; } if (index !== -1) { children.splice(index, 0, node); } else { children.push(node); } return node; }; Node2.prototype.attachTo = function(parent, index) { if (index === void 0) { index = -1; } if (parent) { parent.adoptChild(this, index); } return this; }; Node2.prototype.collectIssues = function(results) { if (this.issues) { results.push.apply(results, this.issues); } }; Node2.prototype.addIssue = function(issue) { if (!this.issues) { this.issues = []; } this.issues.push(issue); }; Node2.prototype.hasIssue = function(rule) { return Array.isArray(this.issues) && this.issues.some(function(i) { return i.getRule() === rule; }); }; Node2.prototype.isErroneous = function(recursive) { if (recursive === void 0) { recursive = false; } if (this.issues && this.issues.length > 0) { return true; } return recursive && Array.isArray(this.children) && this.children.some(function(c) { return c.isErroneous(true); }); }; Node2.prototype.setNode = function(field, node, index) { if (index === void 0) { index = -1; } if (node) { node.attachTo(this, index); this[field] = node; return true; } return false; }; Node2.prototype.addChild = function(node) { if (node) { if (!this.children) { this.children = []; } node.attachTo(this); this.updateOffsetAndLength(node); return true; } return false; }; Node2.prototype.updateOffsetAndLength = function(node) { if (node.offset < this.offset || this.offset === -1) { this.offset = node.offset; } var nodeEnd = node.end; if (nodeEnd > this.end || this.length === -1) { this.length = nodeEnd - this.offset; } }; Node2.prototype.hasChildren = function() { return !!this.children && this.children.length > 0; }; Node2.prototype.getChildren = function() { return this.children ? this.children.slice(0) : []; }; Node2.prototype.getChild = function(index) { if (this.children && index < this.children.length) { return this.children[index]; } return null; }; Node2.prototype.addChildren = function(nodes) { for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) { var node = nodes_1[_i]; this.addChild(node); } }; Node2.prototype.findFirstChildBeforeOffset = function(offset) { if (this.children) { var current = null; for (var i = this.children.length - 1; i >= 0; i--) { current = this.children[i]; if (current.offset <= offset) { return current; } } } return null; }; Node2.prototype.findChildAtOffset = function(offset, goDeep) { var current = this.findFirstChildBeforeOffset(offset); if (current && current.end >= offset) { if (goDeep) { return current.findChildAtOffset(offset, true) || current; } return current; } return null; }; Node2.prototype.encloses = function(candidate) { return this.offset <= candidate.offset && this.offset + this.length >= candidate.offset + candidate.length; }; Node2.prototype.getParent = function() { var result = this.parent; while (result instanceof Nodelist) { result = result.parent; } return result; }; Node2.prototype.findParent = function(type) { var result = this; while (result && result.type !== type) { result = result.parent; } return result; }; Node2.prototype.findAParent = function() { var types = []; for (var _i = 0; _i < arguments.length; _i++) { types[_i] = arguments[_i]; } var result = this; while (result && !types.some(function(t) { return result.type === t; })) { result = result.parent; } return result; }; Node2.prototype.setData = function(key, value) { if (!this.options) { this.options = {}; } this.options[key] = value; }; Node2.prototype.getData = function(key) { if (!this.options || !this.options.hasOwnProperty(key)) { return null; } return this.options[key]; }; return Node2; }(); var Nodelist = function(_super) { __extends(Nodelist2, _super); function Nodelist2(parent, index) { if (index === void 0) { index = -1; } var _this = _super.call(this, -1, -1) || this; _this.attachTo(parent, index); _this.offset = -1; _this.length = -1; return _this; } return Nodelist2; }(Node); var UnicodeRange = function(_super) { __extends(UnicodeRange2, _super); function UnicodeRange2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(UnicodeRange2.prototype, "type", { get: function() { return NodeType.UnicodeRange; }, enumerable: false, configurable: true }); UnicodeRange2.prototype.setRangeStart = function(rangeStart) { return this.setNode("rangeStart", rangeStart); }; UnicodeRange2.prototype.getRangeStart = function() { return this.rangeStart; }; UnicodeRange2.prototype.setRangeEnd = function(rangeEnd) { return this.setNode("rangeEnd", rangeEnd); }; UnicodeRange2.prototype.getRangeEnd = function() { return this.rangeEnd; }; return UnicodeRange2; }(Node); var Identifier = function(_super) { __extends(Identifier2, _super); function Identifier2(offset, length) { var _this = _super.call(this, offset, length) || this; _this.isCustomProperty = false; return _this; } Object.defineProperty(Identifier2.prototype, "type", { get: function() { return NodeType.Identifier; }, enumerable: false, configurable: true }); Identifier2.prototype.containsInterpolation = function() { return this.hasChildren(); }; return Identifier2; }(Node); var Stylesheet = function(_super) { __extends(Stylesheet2, _super); function Stylesheet2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(Stylesheet2.prototype, "type", { get: function() { return NodeType.Stylesheet; }, enumerable: false, configurable: true }); return Stylesheet2; }(Node); var Declarations = function(_super) { __extends(Declarations2, _super); function Declarations2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(Declarations2.prototype, "type", { get: function() { return NodeType.Declarations; }, enumerable: false, configurable: true }); return Declarations2; }(Node); var BodyDeclaration = function(_super) { __extends(BodyDeclaration2, _super); function BodyDeclaration2(offset, length) { return _super.call(this, offset, length) || this; } BodyDeclaration2.prototype.getDeclarations = function() { return this.declarations; }; BodyDeclaration2.prototype.setDeclarations = function(decls) { return this.setNode("declarations", decls); }; return BodyDeclaration2; }(Node); var RuleSet = function(_super) { __extends(RuleSet2, _super); function RuleSet2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(RuleSet2.prototype, "type", { get: function() { return NodeType.Ruleset; }, enumerable: false, configurable: true }); RuleSet2.prototype.getSelectors = function() { if (!this.selectors) { this.selectors = new Nodelist(this); } return this.selectors; }; RuleSet2.prototype.isNested = function() { return !!this.parent && this.parent.findParent(NodeType.Declarations) !== null; }; return RuleSet2; }(BodyDeclaration); var Selector = function(_super) { __extends(Selector2, _super); function Selector2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(Selector2.prototype, "type", { get: function() { return NodeType.Selector; }, enumerable: false, configurable: true }); return Selector2; }(Node); var SimpleSelector = function(_super) { __extends(SimpleSelector2, _super); function SimpleSelector2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(SimpleSelector2.prototype, "type", { get: function() { return NodeType.SimpleSelector; }, enumerable: false, configurable: true }); return SimpleSelector2; }(Node); var AtApplyRule = function(_super) { __extends(AtApplyRule2, _super); function AtApplyRule2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(AtApplyRule2.prototype, "type", { get: function() { return NodeType.AtApplyRule; }, enumerable: false, configurable: true }); AtApplyRule2.prototype.setIdentifier = function(node) { return this.setNode("identifier", node, 0); }; AtApplyRule2.prototype.getIdentifier = function() { return this.identifier; }; AtApplyRule2.prototype.getName = function() { return this.identifier ? this.identifier.getText() : ""; }; return AtApplyRule2; }(Node); var AbstractDeclaration = function(_super) { __extends(AbstractDeclaration2, _super); function AbstractDeclaration2(offset, length) { return _super.call(this, offset, length) || this; } return AbstractDeclaration2; }(Node); var CustomPropertySet = function(_super) { __extends(CustomPropertySet2, _super); function CustomPropertySet2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(CustomPropertySet2.prototype, "type", { get: function() { return NodeType.CustomPropertySet; }, enumerable: false, configurable: true }); return CustomPropertySet2; }(BodyDeclaration); var Declaration = function(_super) { __extends(Declaration2, _super); function Declaration2(offset, length) { var _this = _super.call(this, offset, length) || this; _this.property = null; return _this; } Object.defineProperty(Declaration2.prototype, "type", { get: function() { return NodeType.Declaration; }, enumerable: false, configurable: true }); Declaration2.prototype.setProperty = function(node) { return this.setNode("property", node); }; Declaration2.prototype.getProperty = function() { return this.property; }; Declaration2.prototype.getFullPropertyName = function() { var propertyName = this.property ? this.property.getName() : "unknown"; if (this.parent instanceof Declarations && this.parent.getParent() instanceof NestedProperties) { var parentDecl = this.parent.getParent().getParent(); if (parentDecl instanceof Declaration2) { return parentDecl.getFullPropertyName() + propertyName; } } return propertyName; }; Declaration2.prototype.getNonPrefixedPropertyName = function() { var propertyName = this.getFullPropertyName(); if (propertyName && propertyName.charAt(0) === "-") { var vendorPrefixEnd = propertyName.indexOf("-", 1); if (vendorPrefixEnd !== -1) { return propertyName.substring(vendorPrefixEnd + 1); } } return propertyName; }; Declaration2.prototype.setValue = function(value) { return this.setNode("value", value); }; Declaration2.prototype.getValue = function() { return this.value; }; Declaration2.prototype.setNestedProperties = function(value) { return this.setNode("nestedProperties", value); }; Declaration2.prototype.getNestedProperties = function() { return this.nestedProperties; }; return Declaration2; }(AbstractDeclaration); var CustomPropertyDeclaration = function(_super) { __extends(CustomPropertyDeclaration2, _super); function CustomPropertyDeclaration2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(CustomPropertyDeclaration2.prototype, "type", { get: function() { return NodeType.CustomPropertyDeclaration; }, enumerable: false, configurable: true }); CustomPropertyDeclaration2.prototype.setPropertySet = function(value) { return this.setNode("propertySet", value); }; CustomPropertyDeclaration2.prototype.getPropertySet = function() { return this.propertySet; }; return CustomPropertyDeclaration2; }(Declaration); var Property = function(_super) { __extends(Property2, _super); function Property2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(Property2.prototype, "type", { get: function() { return NodeType.Property; }, enumerable: false, configurable: true }); Property2.prototype.setIdentifier = function(value) { return this.setNode("identifier", value); }; Property2.prototype.getIdentifier = function() { return this.identifier; }; Property2.prototype.getName = function() { return trim(this.getText(), /[_\+]+$/); }; Property2.prototype.isCustomProperty = function() { return !!this.identifier && this.identifier.isCustomProperty; }; return Property2; }(Node); var Invocation = function(_super) { __extends(Invocation2, _super); function Invocation2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(Invocation2.prototype, "type", { get: function() { return NodeType.Invocation; }, enumerable: false, configurable: true }); Invocation2.prototype.getArguments = function() { if (!this.arguments) { this.arguments = new Nodelist(this); } return this.arguments; }; return Invocation2; }(Node); var Function = function(_super) { __extends(Function2, _super); function Function2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(Function2.prototype, "type", { get: function() { return NodeType.Function; }, enumerable: false, configurable: true }); Function2.prototype.setIdentifier = function(node) { return this.setNode("identifier", node, 0); }; Function2.prototype.getIdentifier = function() { return this.identifier; }; Function2.prototype.getName = function() { return this.identifier ? this.identifier.getText() : ""; }; return Function2; }(Invocation); var FunctionParameter = function(_super) { __extends(FunctionParameter2, _super); function FunctionParameter2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(FunctionParameter2.prototype, "type", { get: function() { return NodeType.FunctionParameter; }, enumerable: false, configurable: true }); FunctionParameter2.prototype.setIdentifier = function(node) { return this.setNode("identifier", node, 0); }; FunctionParameter2.prototype.getIdentifier = function() { return this.identifier; }; FunctionParameter2.prototype.getName = function() { return this.identifier ? this.identifier.getText() : ""; }; FunctionParameter2.prototype.setDefaultValue = function(node) { return this.setNode("defaultValue", node, 0); }; FunctionParameter2.prototype.getDefaultValue = function() { return this.defaultValue; }; return FunctionParameter2; }(Node); var FunctionArgument = function(_super) { __extends(FunctionArgument2, _super); function FunctionArgument2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(FunctionArgument2.prototype, "type", { get: function() { return NodeType.FunctionArgument; }, enumerable: false, configurable: true }); FunctionArgument2.prototype.setIdentifier = function(node) { return this.setNode("identifier", node, 0); }; FunctionArgument2.prototype.getIdentifier = function() { return this.identifier; }; FunctionArgument2.prototype.getName = function() { return this.identifier ? this.identifier.getText() : ""; }; FunctionArgument2.prototype.setValue = function(node) { return this.setNode("value", node, 0); }; FunctionArgument2.prototype.getValue = function() { return this.value; }; return FunctionArgument2; }(Node); var IfStatement = function(_super) { __extends(IfStatement2, _super); function IfStatement2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(IfStatement2.prototype, "type", { get: function() { return NodeType.If; }, enumerable: false, configurable: true }); IfStatement2.prototype.setExpression = function(node) { return this.setNode("expression", node, 0); }; IfStatement2.prototype.setElseClause = function(elseClause) { return this.setNode("elseClause", elseClause); }; return IfStatement2; }(BodyDeclaration); var ForStatement = function(_super) { __extends(ForStatement2, _super); function ForStatement2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(ForStatement2.prototype, "type", { get: function() { return NodeType.For; }, enumerable: false, configurable: true }); ForStatement2.prototype.setVariable = function(node) { return this.setNode("variable", node, 0); }; return ForStatement2; }(BodyDeclaration); var EachStatement = function(_super) { __extends(EachStatement2, _super); function EachStatement2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(EachStatement2.prototype, "type", { get: function() { return NodeType.Each; }, enumerable: false, configurable: true }); EachStatement2.prototype.getVariables = function() { if (!this.variables) { this.variables = new Nodelist(this); } return this.variables; }; return EachStatement2; }(BodyDeclaration); var WhileStatement = function(_super) { __extends(WhileStatement2, _super); function WhileStatement2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(WhileStatement2.prototype, "type", { get: function() { return NodeType.While; }, enumerable: false, configurable: true }); return WhileStatement2; }(BodyDeclaration); var ElseStatement = function(_super) { __extends(ElseStatement2, _super); function ElseStatement2(offset, length) { return _super.call(this, offset, length) || this; } Object.defineProperty(ElseStatement2.prototype, "type", { get: function() { return NodeType.Else; }, enumerable: false, configurable: true }); return ElseStatement2; }(BodyDeclaration); var FunctionDeclaration = function(_super) { __extends(Functio