fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addEmptyLineBefore = addEmptyLineBefore;
// Add an empty line before a node. Mutates the node.
function addEmptyLineBefore(node /*: postcss$node*/, newline /*: '\n' | '\r\n'*/) /*: postcss$node*/{
if (!/\r?\n/.test(node.raws.before)) {
node.raws.before = newline.repeat(2) + node.raws.before;
} else {
node.raws.before = node.raws.before.replace(/(\r?\n)/, "".concat(newline, "$1"));
}
return node;
}

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Get an at rule's base name
*
* @param {AtRule} atRule
* @return {string} The name
*/
function _default(atRule) {
return atRule.params.replace(/\([^)]*\)/, "").trim();
}

View File

@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Get the index of a media query's params
*
* @param {AtRule} atRule
* @return {int} The index
*/
function _default(atRule) {
// Initial 1 is for the `@`
var index = 1 + atRule.name.length;
if (atRule.raw("afterName")) {
index += atRule.raw("afterName").length;
}
return index;
}

View File

@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Given a CSS statement, return the string before the block.
* For rules, this is the selector list (and surrounding whitespace).
* For at-rules, this is the name and params (and surrounding whitespace).
*
* If there is no block, return empty string.
*
* @param {Rule|AtRule} statement - postcss rule or at-rule node
* @param {object} options
* @param {boolean} [options.noRawBefore] - Leave out the `before` string
* @return {string}
*/
function _default(statement) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
noRawBefore = _ref.noRawBefore;
var result = "";
if (statement.type !== "rule" && statement.type !== "atrule") {
return result;
}
if (!noRawBefore) {
result += statement.raws.before;
}
if (statement.type === "rule") {
result += statement.selector;
} else {
result += "@".concat(statement.name).concat(statement.raws.afterName).concat(statement.params);
}
var between = statement.raws.between;
if (between !== undefined) {
result += between;
}
return result;
}

25
node_modules/stylelint-scss/dist/utils/blockString.js generated vendored Normal file
View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
var _beforeBlockString = _interopRequireDefault(require("./beforeBlockString"));
var _hasBlock = _interopRequireDefault(require("./hasBlock"));
var _rawNodeString = _interopRequireDefault(require("./rawNodeString"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Return a CSS statement's block -- the string that starts with `{` and ends with `}`.
*
* If the statement has no block (e.g. `@import url(foo.css);`),
* return undefined.
*
* @param {Rule|AtRule} statement - postcss rule or at-rule node
* @return {string|undefined}
*/
function _default(statement) {
if (!(0, _hasBlock["default"])(statement)) {
return;
}
return (0, _rawNodeString["default"])(statement).slice((0, _beforeBlockString["default"])(statement).length);
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Create configurationError from text and set CLI exit code
*
* @param {string} text
* @return {Error} - The error, with text and exit code
*/
function _default(text) {
var err = new Error(text);
err.code = 78;
return err;
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Get the index of a declaration's value
*
* @param {Decl} decl
* @return {int} The index
*/
function _default(decl) {
var beforeColon = decl.toString().indexOf(":");
var afterColon = decl.raw("between").length - decl.raw("between").indexOf(":");
return beforeColon + afterColon;
}

22
node_modules/stylelint-scss/dist/utils/eachRoot.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Executes a provided function once for each CSS block element.
*
* @param {Root|Document} root - root element of file.
* @param {function} cb - Function to execute for each CSS block element
*/
function _default(root, cb) {
// class `Document` is a part of `postcss-html`,
// It is collection of roots in HTML File.
// See: https://github.com/gucong3000/postcss-html/blob/master/lib/document.js
if (root.constructor.name === "Document") {
root.nodes.forEach(cb);
} else {
cb(root);
}
}

View File

@@ -0,0 +1,209 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = findCommentsInRaws;
/**
* Finds comments, both CSS comments and double slash ones, in a CSS string
* This helper exists because PostCSS drops some inline comments (those
* between selectors, property values, etc.)
* https://github.com/postcss/postcss/issues/845#issuecomment-232306259
*
* @param {string} rawString -- the source raw CSS string
* @return {array} array of objects with these props:
* <20> type -- "css" or "double-slash"
* <20> source: { start, end }
* IMPORTANT: the function itself considers \r as a character, and counts
* it for `start` and `end`. But if their values are passed to PostCSS's
* result.warn(), than "\r\n" is consideren ONE CHAR (newline)!
* <20> raws
* raws.startToken -- `/*`, `/**`, `/**!`, etc.
* raws.left -- whitespace after the comment opening marker
* raws.text -- the full comment, including markers (//, /*)
* raws.right -- whitespace before the comment closing marker
* raws.endToken -- `*\/`, `**\/` for CSS comments
* <20> text -- the comment text only, excluding //, /*, trailing whitespaces
* <20> inlineAfter -- true, if there is something before the comment on
* the same line
* <20> inlineBefore -- true, if there is something after the comment on
* the same line
*/
function findCommentsInRaws(rawString) {
var result = [];
var comment = {};
// Keeps track of which structure the parser is inside (string, comment,
// url function, parens). E.g., /* comment */ inside a string doesn't
// constitute a comment, so as url(//path)
var modesEntered = [{
mode: "normal",
character: null
}];
var commentStart = null;
// postcss-scss transforms //-comments into CSS comments, like so:
// `// comment` -> `/* comment*/`. So to have a correct intex we need to
// keep track on the added `*/` sequences
var offset = 0;
for (var i = 0; i < rawString.length; i++) {
var character = rawString[i];
var prevChar = i > 0 ? rawString[i - 1] : null;
var nextChar = i + 1 < rawString.length ? rawString[i + 1] : null;
var lastModeIndex = modesEntered.length - 1;
var mode = modesEntered[lastModeIndex] && modesEntered[lastModeIndex].mode;
switch (character) {
// If entering/exiting a string
case '"':
case "'":
{
if (mode === "comment") {
break;
}
if (mode === "string" && modesEntered[lastModeIndex].character === character && prevChar !== "\\") {
// Exiting a string
modesEntered.pop();
} else {
// Entering a string
modesEntered.push({
mode: "string",
character: character
});
}
break;
}
// Entering url, other function or parens (only url matters)
case "(":
{
if (mode === "comment" || mode === "string") {
break;
}
var functionNameRegSearch = /(?:^|[\n\r]|\s-|[:\s,.(){}*+/%])([\w-]*)$/.exec(rawString.substring(0, i));
// A `\S(` can be in, say, `@media(`
if (!functionNameRegSearch) {
modesEntered.push({
mode: "parens",
character: "("
});
break;
}
var functionName = functionNameRegSearch[1];
modesEntered.push({
mode: functionName === "url" ? "url" : "parens",
character: "("
});
break;
}
// Exiting url, other function or parens
case ")":
{
if (mode === "comment" || mode === "string") {
break;
}
modesEntered.pop();
break;
}
// checking for comment
case "/":
{
// Break if the / is inside a comment because we leap over the second
// slash in // and in */, so the / is not from a marker. Also break
// if inside a string
if (mode === "comment" || mode === "string") {
break;
}
if (nextChar === "*") {
modesEntered.push({
mode: "comment",
character: "/*"
});
comment = {
type: "css",
source: {
start: i + offset
},
// If i is 0 then the file/the line starts with this comment
inlineAfter: i > 0 && rawString.substring(0, i).search(/\n\s*$/) === -1
};
commentStart = i;
// Skip the next iteration as the * is already checked
i++;
} else if (nextChar === "/") {
// `url(//path/to/file)` has no comment
if (mode === "url") {
break;
}
modesEntered.push({
mode: "comment",
character: "//"
});
comment = {
type: "double-slash",
source: {
start: i + offset
},
// If i is 0 then the file/the line starts with this comment
inlineAfter: i > 0 && rawString.substring(0, i).search(/\n\s*$/) === -1
};
commentStart = i;
// Skip the next iteration as the second slash in // is already checked
i++;
}
break;
}
// Might be a closing `*/`
case "*":
{
if (mode === "comment" && modesEntered[lastModeIndex].character === "/*" && nextChar === "/") {
comment.source.end = i + 1 + offset;
var commentRaw = rawString.substring(commentStart, i + 2);
var matches = /^(\/\*+[!#]?)(\s*)([\s\S]*?)(\s*)(\*+\/)$/.exec(commentRaw);
modesEntered.pop();
comment.raws = {
startToken: matches[1],
left: matches[2],
text: commentRaw,
right: matches[4],
endToken: matches[5]
};
comment.text = matches[3];
comment.inlineBefore = rawString.substring(i + 2).search(/^\s*\S+\s*?\n/) !== -1;
result.push(Object.assign({}, comment));
comment = {};
// Skip the next loop as the / in */ is already checked
i++;
}
break;
}
default:
{
var isNewline = character === "\r" && rawString[i + 1] === "\n" || character === "\n" && rawString[i - 1] !== "\r";
// //-comments end before newline and if the code string ends
if (isNewline || i === rawString.length - 1) {
if (mode === "comment" && modesEntered[lastModeIndex].character === "//") {
comment.source.end = (isNewline ? i - 1 : i) + offset;
var _commentRaw = rawString.substring(commentStart, isNewline ? i : i + 1);
var _matches = /^(\/+)(\s*)(.*?)(\s*)$/.exec(_commentRaw);
modesEntered.pop();
comment.raws = {
startToken: _matches[1],
left: _matches[2],
text: _commentRaw,
right: _matches[4]
};
comment.text = _matches[3];
comment.inlineBefore = false;
result.push(Object.assign({}, comment));
comment = {};
// Compensate for the `*/` added by postcss-scss
offset += 2;
}
}
break;
}
}
}
return result;
}

75
node_modules/stylelint-scss/dist/utils/functions.js generated vendored Normal file
View File

@@ -0,0 +1,75 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.STRING_FUNCTIONS = exports.SELECTOR_FUNCTIONS = exports.META_FUNCTIONS = exports.MATH_FUNCTIONS = exports.MAP_FUNCTIONS = exports.LIST_FUNCTIONS = exports.GLOBAL_FUNCTIONS = exports.COLOR_FUNCTIONS = exports.ALL_FUNCTIONS = void 0;
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/**
* @see https://sass-lang.com/documentation/modules#global-functions
*/
var GLOBAL_FUNCTIONS = Object.freeze(["hsl", "hsla", "if", "rgb", "rgba"]);
/**
* @see https://sass-lang.com/documentation/modules/color
*/
exports.GLOBAL_FUNCTIONS = GLOBAL_FUNCTIONS;
var COLOR_FUNCTIONS = Object.freeze(["adjust-color", "adjust-hue", "alpha", "blackness", "blue", "change-color", "complement", "darken", "desaturate", "fade-in", "fade-out", "grayscale", "green", "hue", "ie-hex-str", "invert", "lighten", "lightness", "mix", "opacity", "red", "saturate", "saturation", "scale-color", "transparentize",
// with namespace
"color.adjust", "color.alpha", "color.blackness", "color.blue", "color.change", "color.complement", "color.grayscale", "color.green", "color.hue", "color.hwb", "color.ie-hex-str", "color.invert", "color.lightness", "color.mix", "color.red", "color.saturation", "color.scale", "color.whiteness"]);
/**
* @see https://sass-lang.com/documentation/modules/list
*/
exports.COLOR_FUNCTIONS = COLOR_FUNCTIONS;
var LIST_FUNCTIONS = Object.freeze(["append", "index", "is-bracketed", "join", "length", "list-separator", "nth", "set-nth", "list.zip",
// with namespace
"list.append", "list.index", "list.is-bracketed", "list.join", "list.length", "list.nth", "list.separator", "list.set-nth", "list.slash", "zip"]);
/**
* @see https://sass-lang.com/documentation/modules/map
*/
exports.LIST_FUNCTIONS = LIST_FUNCTIONS;
var MAP_FUNCTIONS = Object.freeze(["map-get", "map-has-key", "map-keys", "map-merge", "map-remove", "map-values",
// with namespace
"map.deep-merge", "map.deep-remove", "map.get", "map.has-key", "map.keys", "map.merge", "map.remove", "map.set", "map.values"]);
/**
* @see https://sass-lang.com/documentation/modules/math
*/
exports.MAP_FUNCTIONS = MAP_FUNCTIONS;
var MATH_FUNCTIONS = Object.freeze(["abs", "ceil", "comparable", "floor", "max", "min", "percentage", "random", "round", "unit", "unitless",
// with namespace
"math.abs", "math.acos", "math.asin", "math.atan", "math.atan2", "math.ceil", "math.clamp", "math.compatible", "math.cos", "math.div", "math.floor", "math.hypot", "math.is-unitless", "math.log", "math.max", "math.min", "math.percentage", "math.pow", "math.random", "math.round", "math.sin", "math.sqrt", "math.tan", "math.unit"]);
/**
* @see https://sass-lang.com/documentation/modules/meta
*/
exports.MATH_FUNCTIONS = MATH_FUNCTIONS;
var META_FUNCTIONS = Object.freeze(["call", "content-exists", "feature-exists", "function-exists", "get-function", "global-variable-exists", "inspect", "keywords", "mixin-exists", "type-of", "variable-exists",
// with namespace
"meta.calc-args", "meta.calc-name", "meta.call", "meta.content-exists", "meta.feature-exists", "meta.function-exists", "meta.get-function", "meta.global-variable-exists", "meta.inspect", "meta.keywords", "meta.mixin-exists", "meta.module-functions", "meta.module-variables", "meta.type-of", "meta.variable-exists"]);
/**
* @see https://sass-lang.com/documentation/modules/selector
*/
exports.META_FUNCTIONS = META_FUNCTIONS;
var SELECTOR_FUNCTIONS = Object.freeze(["is-superselector", "selector-append", "selector-extend", "selector-nest", "selector-parse", "selector-replace", "selector-unify", "simple-selectors",
// with namespace
"selector.append", "selector.extend", "selector.is-superselector", "selector.nest", "selector.parse", "selector.replace", "selector.simple-selectors", "selector.unify"]);
/**
* @see https://sass-lang.com/documentation/modules/string
*/
exports.SELECTOR_FUNCTIONS = SELECTOR_FUNCTIONS;
var STRING_FUNCTIONS = Object.freeze(["quote", "str-index", "str-insert", "str-length", "str-slice", "to-lower-case", "to-upper-case", "unique-id", "unquote",
// with namespace
"string.index", "string.insert", "string.length", "string.quote", "string.slice", "string.to-lower-case", "string.to-upper-case", "string.unique-id", "string.unquote"]);
exports.STRING_FUNCTIONS = STRING_FUNCTIONS;
var ALL_FUNCTIONS = Object.freeze([].concat(_toConsumableArray(GLOBAL_FUNCTIONS), _toConsumableArray(COLOR_FUNCTIONS), _toConsumableArray(LIST_FUNCTIONS), _toConsumableArray(MAP_FUNCTIONS), _toConsumableArray(MATH_FUNCTIONS), _toConsumableArray(META_FUNCTIONS), _toConsumableArray(SELECTOR_FUNCTIONS), _toConsumableArray(STRING_FUNCTIONS)));
exports.ALL_FUNCTIONS = ALL_FUNCTIONS;

15
node_modules/stylelint-scss/dist/utils/hasBlock.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check if a statement has an block (empty or otherwise).
*
* @param {Rule|AtRule} statement - postcss rule or at-rule node
* @return {boolean} True if `statement` has a block (empty or otherwise)
*/
function _default(statement) {
return statement.nodes !== undefined;
}

15
node_modules/stylelint-scss/dist/utils/hasEmptyLine.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check if a string contains at least one empty line
*
* @param {string} string
* @return {boolean}
*/
function _default(string) {
return string && (string.includes("\n\n") || string.includes("\n\r\n"));
}

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check whether a selector has an interpolating ampersand
* An "interpolating ampersand" is an "&" used to interpolate within another
* simple selector (e.g. `&-modifier`), rather than an "&" that stands
* on its own as a simple selector (e.g. `& .child`)
*
* @param {string} selector
* @return {boolean} If `true`, the selector has an interpolating ampersand
*/
function _default(selector) {
for (var i = 0; i < selector.length; i++) {
if (selector[i] !== "&") {
continue;
}
if (selector[i - 1] !== undefined && !isCombinator(selector[i - 1])) {
return true;
}
if (selector[i + 1] !== undefined && !isCombinator(selector[i + 1])) {
return true;
}
}
return false;
}
function isCombinator(x) {
return /[\s+>~]/.test(x);
}

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
var _hasLessInterpolation = _interopRequireDefault(require("./hasLessInterpolation"));
var _hasPsvInterpolation = _interopRequireDefault(require("./hasPsvInterpolation"));
var _hasScssInterpolation = _interopRequireDefault(require("./hasScssInterpolation"));
var _hasTplInterpolation = _interopRequireDefault(require("./hasTplInterpolation"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Check whether a string has interpolation
*
* @param {string} string
* @return {boolean} If `true`, a string has interpolation
*/
function _default(string) {
// SCSS or Less interpolation
return !!((0, _hasLessInterpolation["default"])(string) || (0, _hasScssInterpolation["default"])(string) || (0, _hasTplInterpolation["default"])(string) || (0, _hasPsvInterpolation["default"])(string));
}

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check whether a string has less interpolation
*
* @param {string} string
* @return {boolean} If `true`, a string has less interpolation
*/
function _default(string) {
return /@{.+?}/.test(string);
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Determines whether a given node has nested sibling.
*
* @param {import('postcss').Node} node
* @return {boolean}
*/
function _default(node) {
return node && node.parent.nodes.some(function (n) {
return n !== node && n.type === "nesting";
});
}

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check whether a string has postcss-simple-vars interpolation
*
* @param {string} string
*/
function _default(string) {
return /\$\(.+?\)/.test(string);
}

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check whether a string has scss interpolation
*
* @param {string} string
*/
function _default(string) {
return /#{.+?}/.test(string);
}

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check whether a string has JS template literal interpolation or HTML-like template
*
* @param {string} string
* @return {boolean} If `true`, a string has template literal interpolation
*/
function _default(string) {
return /{.+?}/.test(string);
}

292
node_modules/stylelint-scss/dist/utils/index.js generated vendored Normal file
View File

@@ -0,0 +1,292 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
addEmptyLineBefore: true,
atRuleBaseName: true,
atRuleParamIndex: true,
beforeBlockString: true,
blockString: true,
declarationValueIndex: true,
eachRoot: true,
findCommentsInRaws: true,
hasBlock: true,
hasEmptyLine: true,
hasInterpolatingAmpersand: true,
isInlineComment: true,
isNativeCssFunction: true,
isSingleLineString: true,
isStandardRule: true,
isStandardSelector: true,
isStandardSyntaxProperty: true,
isWhitespace: true,
namespace: true,
optionsHaveException: true,
optionsHaveIgnored: true,
parseFunctionArguments: true,
parseNestedPropRoot: true,
parseSelector: true,
rawNodeString: true,
removeEmptyLinesBefore: true,
findOperators: true,
whitespaceChecker: true,
hasNestedSibling: true,
isType: true,
moduleNamespace: true
};
Object.defineProperty(exports, "addEmptyLineBefore", {
enumerable: true,
get: function get() {
return _addEmptyLineBefore.addEmptyLineBefore;
}
});
Object.defineProperty(exports, "atRuleBaseName", {
enumerable: true,
get: function get() {
return _atRuleBaseName["default"];
}
});
Object.defineProperty(exports, "atRuleParamIndex", {
enumerable: true,
get: function get() {
return _atRuleParamIndex["default"];
}
});
Object.defineProperty(exports, "beforeBlockString", {
enumerable: true,
get: function get() {
return _beforeBlockString["default"];
}
});
Object.defineProperty(exports, "blockString", {
enumerable: true,
get: function get() {
return _blockString["default"];
}
});
Object.defineProperty(exports, "declarationValueIndex", {
enumerable: true,
get: function get() {
return _declarationValueIndex["default"];
}
});
Object.defineProperty(exports, "eachRoot", {
enumerable: true,
get: function get() {
return _eachRoot["default"];
}
});
Object.defineProperty(exports, "findCommentsInRaws", {
enumerable: true,
get: function get() {
return _findCommentsInRaws["default"];
}
});
Object.defineProperty(exports, "findOperators", {
enumerable: true,
get: function get() {
return _sassValueParser["default"];
}
});
Object.defineProperty(exports, "hasBlock", {
enumerable: true,
get: function get() {
return _hasBlock["default"];
}
});
Object.defineProperty(exports, "hasEmptyLine", {
enumerable: true,
get: function get() {
return _hasEmptyLine["default"];
}
});
Object.defineProperty(exports, "hasInterpolatingAmpersand", {
enumerable: true,
get: function get() {
return _hasInterpolatingAmpersand["default"];
}
});
Object.defineProperty(exports, "hasNestedSibling", {
enumerable: true,
get: function get() {
return _hasNestedSibling["default"];
}
});
Object.defineProperty(exports, "isInlineComment", {
enumerable: true,
get: function get() {
return _isInlineComment["default"];
}
});
Object.defineProperty(exports, "isNativeCssFunction", {
enumerable: true,
get: function get() {
return _isNativeCssFunction["default"];
}
});
Object.defineProperty(exports, "isSingleLineString", {
enumerable: true,
get: function get() {
return _isSingleLineString["default"];
}
});
Object.defineProperty(exports, "isStandardRule", {
enumerable: true,
get: function get() {
return _isStandardRule["default"];
}
});
Object.defineProperty(exports, "isStandardSelector", {
enumerable: true,
get: function get() {
return _isStandardSelector["default"];
}
});
Object.defineProperty(exports, "isStandardSyntaxProperty", {
enumerable: true,
get: function get() {
return _isStandardSyntaxProperty["default"];
}
});
Object.defineProperty(exports, "isType", {
enumerable: true,
get: function get() {
return _isType["default"];
}
});
Object.defineProperty(exports, "isWhitespace", {
enumerable: true,
get: function get() {
return _isWhitespace["default"];
}
});
Object.defineProperty(exports, "moduleNamespace", {
enumerable: true,
get: function get() {
return _moduleNamespace.moduleNamespace;
}
});
Object.defineProperty(exports, "namespace", {
enumerable: true,
get: function get() {
return _namespace["default"];
}
});
Object.defineProperty(exports, "optionsHaveException", {
enumerable: true,
get: function get() {
return _optionsHaveException["default"];
}
});
Object.defineProperty(exports, "optionsHaveIgnored", {
enumerable: true,
get: function get() {
return _optionsHaveIgnored["default"];
}
});
Object.defineProperty(exports, "parseFunctionArguments", {
enumerable: true,
get: function get() {
return _parseFunctionArguments.parseFunctionArguments;
}
});
Object.defineProperty(exports, "parseNestedPropRoot", {
enumerable: true,
get: function get() {
return _parseNestedPropRoot["default"];
}
});
Object.defineProperty(exports, "parseSelector", {
enumerable: true,
get: function get() {
return _parseSelector["default"];
}
});
Object.defineProperty(exports, "rawNodeString", {
enumerable: true,
get: function get() {
return _rawNodeString["default"];
}
});
Object.defineProperty(exports, "removeEmptyLinesBefore", {
enumerable: true,
get: function get() {
return _removeEmptyLinesBefore.removeEmptyLinesBefore;
}
});
Object.defineProperty(exports, "whitespaceChecker", {
enumerable: true,
get: function get() {
return _whitespaceChecker["default"];
}
});
var _addEmptyLineBefore = require("./addEmptyLineBefore");
var _atRuleBaseName = _interopRequireDefault(require("./atRuleBaseName"));
var _atRuleParamIndex = _interopRequireDefault(require("./atRuleParamIndex"));
var _beforeBlockString = _interopRequireDefault(require("./beforeBlockString"));
var _blockString = _interopRequireDefault(require("./blockString"));
var _declarationValueIndex = _interopRequireDefault(require("./declarationValueIndex"));
var _eachRoot = _interopRequireDefault(require("./eachRoot"));
var _findCommentsInRaws = _interopRequireDefault(require("./findCommentsInRaws"));
var _functions = require("./functions");
Object.keys(_functions).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _functions[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _functions[key];
}
});
});
var _hasBlock = _interopRequireDefault(require("./hasBlock"));
var _hasEmptyLine = _interopRequireDefault(require("./hasEmptyLine"));
var _hasInterpolatingAmpersand = _interopRequireDefault(require("./hasInterpolatingAmpersand"));
var _isInlineComment = _interopRequireDefault(require("./isInlineComment"));
var _isNativeCssFunction = _interopRequireDefault(require("./isNativeCssFunction"));
var _isSingleLineString = _interopRequireDefault(require("./isSingleLineString"));
var _isStandardRule = _interopRequireDefault(require("./isStandardRule"));
var _isStandardSelector = _interopRequireDefault(require("./isStandardSelector"));
var _isStandardSyntaxProperty = _interopRequireDefault(require("./isStandardSyntaxProperty"));
var _isWhitespace = _interopRequireDefault(require("./isWhitespace"));
var _namespace = _interopRequireDefault(require("./namespace"));
var _optionsHaveException = _interopRequireDefault(require("./optionsHaveException"));
var _optionsHaveIgnored = _interopRequireDefault(require("./optionsHaveIgnored"));
var _parseFunctionArguments = require("./parseFunctionArguments");
var _parseNestedPropRoot = _interopRequireDefault(require("./parseNestedPropRoot"));
var _parseSelector = _interopRequireDefault(require("./parseSelector"));
var _rawNodeString = _interopRequireDefault(require("./rawNodeString"));
var _removeEmptyLinesBefore = require("./removeEmptyLinesBefore");
var _ruleUrl = require("./ruleUrl");
Object.keys(_ruleUrl).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _ruleUrl[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _ruleUrl[key];
}
});
});
var _sassValueParser = _interopRequireDefault(require("./sassValueParser"));
var _whitespaceChecker = _interopRequireDefault(require("./whitespaceChecker"));
var _hasNestedSibling = _interopRequireDefault(require("./hasNestedSibling"));
var _isType = _interopRequireDefault(require("./isType"));
var _moduleNamespace = require("./moduleNamespace");
var _validateTypes = require("./validateTypes");
Object.keys(_validateTypes).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _validateTypes[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _validateTypes[key];
}
});
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check whether a Node is a custom property set
*
* @param {import('postcss').Rule} node
* @returns {boolean}
*/
function _default(node) {
var _node$raws, _node$raws$prop, _node$raws2, _node$raws2$value;
var prop = (node === null || node === void 0 ? void 0 : (_node$raws = node.raws) === null || _node$raws === void 0 ? void 0 : (_node$raws$prop = _node$raws.prop) === null || _node$raws$prop === void 0 ? void 0 : _node$raws$prop.raw) || node.prop;
var value = (node === null || node === void 0 ? void 0 : (_node$raws2 = node.raws) === null || _node$raws2 === void 0 ? void 0 : (_node$raws2$value = _node$raws2.value) === null || _node$raws2$value === void 0 ? void 0 : _node$raws2$value.raw) || node.value;
return node.type === "decl" && prop.startsWith("--") && value.startsWith("{") && value.endsWith("}");
}

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = isInlineComment;
/**
* Check if a comment is inline one (i.e. on the same line as some non-comment
* code). Only works with comments that are not ignored by PostCSS. To work
* with those that are ignored use `findCommentInRaws`
*
* @param {Comment} comment - PostCSS comment node
* @return {boolean} true, if the comment is an inline one
*/
function isInlineComment(comment) {
var nextNode = comment.next();
var isBeforeSomething = !!nextNode && nextNode.type !== "comment" && comment.source.end.line === nextNode.source.start.line;
var isAfterSomething = comment.raws.before.search(/\n/) === -1;
return isAfterSomething || isBeforeSomething;
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = isNativeCssFunction;
var nativeCssFunctions = new Set(["annotation", "attr", "blur", "brightness", "calc", "character-variant", "circle", "contrast", "cross-fade", "cubic-bezier", "drop-shadow", "element", "ellipse", "fit-content", "format", "frames", "grayscale", "hsl", "hsla", "hue-rotate", "image", "image-set", "inset", "invert", "leader", "linear-gradient", "local", "matrix", "matrix3d", "minmax", "opacity", "ornaments", "perspective", "polygon", "radial-gradient", "rect", "repeat", "repeating-linear-gradient", "repeating-radial-gradient", "rgb", "rgba", "rotate", "rotate3d", "rotateX", "rotatex", "rotateY", "rotatey", "rotateZ", "rotatez", "saturate", "scale", "scale3d", "scaleX", "scalex", "scaleY", "scaley", "scaleZ", "scalez", "sepia", "skew", "skewX", "skewY", "steps", "styleset", "stylistic", "swash", "symbols", "target-counter", "target-counters", "target-text", "translate", "translate3d", "translateX", "translatex", "translateY", "translatey", "translateZ", "translatez", "url", "var"]);
/**
* Check if a function name is a native CSS function name.
*
* @param {string} functionName The name to check.
* @returns {boolean} Whether or not the given function name is a native CSS function name.
*/
function isNativeCssFunction(functionName) {
return nativeCssFunctions.has(functionName);
}

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check if a string is a single line (i.e. does not contain
* any newline characters).
*
* @param {string} input
* @return {boolean}
*/
function _default(input) {
return !/[\n\r]/.test(input);
}

View File

@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
var _isCustomPropertySet = _interopRequireDefault(require("./isCustomPropertySet"));
var _isStandardSelector = _interopRequireDefault(require("./isStandardSelector"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Check whether a Node is a standard rule
*
* @param {import('postcss').Rule} rule
* @returns {boolean}
*/
function _default(rule) {
var _rule$raws, _rule$raws$selector;
// Get full selector
var selector = (rule === null || rule === void 0 ? void 0 : (_rule$raws = rule.raws) === null || _rule$raws === void 0 ? void 0 : (_rule$raws$selector = _rule$raws.selector) === null || _rule$raws$selector === void 0 ? void 0 : _rule$raws$selector.raw) || rule.selector;
if (!(0, _isStandardSelector["default"])(rule.selector)) {
return false;
}
// Custom property set (e.g. --custom-property-set: {})
if ((0, _isCustomPropertySet["default"])(rule)) {
return false;
}
// Called Less mixin (e.g. a { .mixin() })
// @ts-ignore TODO TYPES support LESS and SASS types somehow
if (rule.mixin) {
return false;
}
// Less detached rulesets
if (selector.startsWith("@") && selector.endsWith(":")) {
return false;
}
// Ignore Less &:extend rule
// @ts-ignore TODO TYPES support LESS and SASS types somehow
if (rule.extend) {
return false;
}
// Ignore mixin or &:extend rule
// https://github.com/shellscape/postcss-less/blob/master/lib/less-parser.js#L52
// @ts-ignore TODO TYPES support LESS and SASS types somehow
if (rule.params && rule.params[0]) {
return false;
}
// Non-outputting Less mixin definition (e.g. .mixin() {})
if (selector.endsWith(")") && !selector.includes(":")) {
return false;
}
// Less guards
if (/when\s+(not\s+)*\(/.test(selector)) {
return false;
}
// Ignore Scss nested properties
if (selector.endsWith(":")) {
return false;
}
return true;
}

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
var _isStandardSyntaxSelector = _interopRequireDefault(require("./isStandardSyntaxSelector"));
var _hasInterpolation = _interopRequireDefault(require("./hasInterpolation"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Check whether a selector is standard
*
* @param {string} selector
* @return {boolean} If `true`, the selector is standard
*/
function _default(selector) {
var standardSyntaxSelector = (0, _isStandardSyntaxSelector["default"])(selector);
// SCSS placeholder selectors
if (!standardSyntaxSelector) {
if (selector.indexOf("%") === 0 && !(0, _hasInterpolation["default"])(selector)) {
return true;
}
}
return standardSyntaxSelector;
}

View File

@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
var _hasInterpolation = _interopRequireDefault(require("./hasInterpolation"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Check whether a property is standard
*
* @param {string} property
* @returns {boolean}
*/
function _default(property) {
// SCSS var (e.g. $var: x), list (e.g. $list: (x)) or map (e.g. $map: (key:value))
if (property.startsWith("$")) {
return false;
}
// Less var (e.g. @var: x)
if (property.startsWith("@")) {
return false;
}
// Less append property value with space (e.g. transform+_: scale(2))
if (property.endsWith("+") || property.endsWith("+_")) {
return false;
}
// SCSS or Less interpolation
if ((0, _hasInterpolation["default"])(property)) {
return false;
}
return true;
}

View File

@@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
var _hasInterpolation = _interopRequireDefault(require("./hasInterpolation"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Check whether a selector is standard
*
* @param {string} selector
* @returns {boolean}
*/
function _default(selector) {
// SCSS or Less interpolation
if ((0, _hasInterpolation["default"])(selector)) {
return false;
}
// SCSS placeholder selectors
if (selector.startsWith("%")) {
return false;
}
// Less :extend()
if (/:extend(\(.*?\))?/.test(selector)) {
return false;
}
// Less mixin with resolved nested selectors (e.g. .foo().bar or .foo(@a, @b)[bar])
if (/\.[\w-]+\(.*\).+/.test(selector)) {
return false;
}
// ERB template tags
if (selector.includes("<%") || selector.includes("%>")) {
return false;
}
return true;
}

16
node_modules/stylelint-scss/dist/utils/isType.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Determine whether the given node is of the given type.
*
* @param {import('postcss').Node} node
* @param {string} type
* @return {boolean}
*/
function _default(node, type) {
return node && node.type === type;
}

15
node_modules/stylelint-scss/dist/utils/isWhitespace.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check if a character is whitespace.
*
* @param {string} char - A single character
* @return {boolean}
*/
function _default(_char) {
return [" ", "\n", "\t", "\r", "\f"].includes(_char);
}

View File

@@ -0,0 +1,54 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.moduleNamespace = moduleNamespace;
/**
* Returns the namespace of an imported module or `null` if the namespace is removed.
*
* Example: no import found, possibly using global function
* `@use "sass:color";`
* `moduleNamespace(root, 'sass:map')` returns 'map'
*
* Example: default namespace
* `@use "sass:map";`
* `moduleNamespace(root, 'sass:map')` returns `map`
*
* Example: custom namespace
* `@use "sass:map" as ns;`
* `moduleNamespace(root, 'sass:map')` returns 'ns'
*
* Example: no namespace
* `@use "sass:map" as *;`
* `moduleNamespace(root, 'sass:map')` returns `null`
*
* Have a look at the tests for more examples.
*/
function moduleNamespace(root, module) {
var moduleNamespace = getDefaultNamespace(module);
root.walkAtRules("use", function (rule) {
var customNamespace = getCustomNamespace(module, rule);
switch (customNamespace) {
case null:
return;
case "*":
moduleNamespace = null;
return;
default:
moduleNamespace = customNamespace;
}
});
return moduleNamespace;
}
function getDefaultNamespace(module) {
return module.match(/([^/:]+)$/)[1].replace(/\.[^.]+$/, "");
}
function getCustomNamespace(module, rule) {
var ruleParamsParts = rule.params.split(new RegExp("[\"']".concat(module, "['\"][ \n]*as")));
if (ruleParamsParts.length < 2) {
return null;
}
var secondRuleParamsPart = ruleParamsParts[1].trim();
return !secondRuleParamsPart.startsWith("*") ? secondRuleParamsPart.split(" ")[0] : "*";
}

10
node_modules/stylelint-scss/dist/utils/namespace.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = namespace;
var prefix = "scss";
function namespace(ruleName) {
return "".concat(prefix, "/").concat(ruleName);
}

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check if an options object contains a certain `except` keyword.
* It will look for an `except` property whose value should
* be an array of keywords.
*
* @param {object} options
* @param {string} exceptionName
* @return {boolean}
*/
function _default(options, exceptionName) {
return options && options.except && options.except.includes(exceptionName);
}

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Check if an options object contains a certain `ignore` keyword.
* It will look for an `ignore` property whose value should
* be an array of keywords.
*
* @param {object} options
* @param {string} ignoredName
* @return {boolean}
*/
function _default(options, ignoredName) {
return options && options.ignore && options.ignore.includes(ignoredName);
}

View File

@@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.groupByKeyValue = groupByKeyValue;
exports.mapToKeyValue = mapToKeyValue;
exports.parseFunctionArguments = parseFunctionArguments;
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function groupByKeyValue(nodes) {
if (!nodes) {
return [];
}
var groupIndex = 0;
return nodes.reduce(function (acc, node, nodeIndex) {
var isComma = node.type === "div" && node.value === ",";
var skipTrailingComma = isComma && nodeIndex === nodes.length - 1;
if (skipTrailingComma) {
return acc;
}
if (isComma) {
groupIndex++;
}
acc[groupIndex] = acc[groupIndex] || [];
if (!isComma) {
acc[groupIndex].push(node);
}
return acc;
}, []);
}
function mapToKeyValue(nodes) {
var keyVal = nodes.reduce(function (acc, curr, i) {
if (acc.length === 1) {
return acc;
}
var nextNode = nodes[i + 1];
var isNextNodeColon = nextNode && nextNode.type === "div" && nextNode.value === ":";
if (isNextNodeColon) {
acc.push({
key: _postcssValueParser["default"].stringify(nodes[i]),
value: _postcssValueParser["default"].stringify(nodes.slice(2))
});
return acc;
}
acc.push({
value: _postcssValueParser["default"].stringify(nodes)
});
return acc;
}, []);
return keyVal[0];
}
function parseFunctionArguments(value) {
var parsed = (0, _postcssValueParser["default"])(value);
if (!parsed.nodes[0] || parsed.nodes[0].type !== "function") {
return [];
}
return parsed.nodes.map(function (node) {
return groupByKeyValue(node.nodes).map(mapToKeyValue);
})[0];
}

View File

@@ -0,0 +1,84 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = parseNestedPropRoot;
/**
* Attempts to parse a selector as if it"s a root for a group of nested props
* E.g.: `margin: {`, `font: 10px/1.1 Arial {` ("{" excluded)
*/
function parseNestedPropRoot(propString) {
var modesEntered = [{
mode: "normal",
character: null,
isCalculationEnabled: true
}];
var result = {};
var lastModeIndex = 0;
var propName = "";
for (var i = 0; i < propString.length; i++) {
var character = propString[i];
var prevCharacter = propString[i - 1];
// If entering/exiting a string
if (character === '"' || character === "'") {
if (modesEntered[lastModeIndex].isCalculationEnabled === true) {
modesEntered.push({
mode: "string",
isCalculationEnabled: false,
character: character
});
lastModeIndex++;
} else if (modesEntered[lastModeIndex].mode === "string" && modesEntered[lastModeIndex].character === character && prevCharacter !== "\\") {
modesEntered.pop();
lastModeIndex--;
}
}
// If entering/exiting interpolation
if (character === "{") {
modesEntered.push({
mode: "interpolation",
isCalculationEnabled: true
});
lastModeIndex++;
} else if (character === "}") {
modesEntered.pop();
lastModeIndex--;
}
// Check for : outside fn call, string or interpolation. It must be at the
// end of a string or have a whitespace between it and following value
if (modesEntered[lastModeIndex].mode === "normal" && character === ":" && prevCharacter !== "\\") {
var propValueStr = propString.substring(i + 1);
if (propValueStr.length) {
var propValue = {
before: /^(\s*)/.exec(propValueStr)[1],
value: propValueStr.trim()
};
// It's a declaration if 1) there is a whitespace after :, or
// 2) the value is a number with/without a unit (starts with a number
// or a dot), or
// 3) the value is a variable (starts with $), or
// 4) the value a string, surprisingly
if (propValue.before === "" && !/^[\d.$'"]/.test(propValue.value)) {
return null;
}
// +1 for the colon
propValue.sourceIndex = propValue.before.length + i + 1;
result.propValue = propValue;
}
result.propName = {
after: /(\s*)$/.exec(propName)[1],
value: propName.trim()
};
return result;
}
propName += character;
}
return null;
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _default(selector, result, node, cb) {
try {
return (0, _postcssSelectorParser["default"])(cb).processSync(selector);
} catch (e) {
result.warn("Cannot parse selector", {
node: node
});
}
}

View File

@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
/**
* Stringify PostCSS node including its raw "before" string.
*
* @param {Node} node - Any PostCSS node
* @return {string}
*/
function _default(node) {
var result = "";
if (node.raws.before) {
result += node.raws.before;
}
result += node.toString();
return result;
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.removeEmptyLinesBefore = removeEmptyLinesBefore;
// Remove empty lines before a node. Mutates the node.
function removeEmptyLinesBefore(node /*: postcss$node*/, newline /*: '\n' | '\r\n'*/) /*: postcss$node*/{
node.raws.before = node.raws.before.replace(/(\r?\n\s*\n)+/g, newline);
return node;
}

29
node_modules/stylelint-scss/dist/utils/ruleUrl.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ruleUrl = ruleUrl;
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var revision = "master";
/**
* Get the specified rule's URL.
*
* @param {string} ruleName
* @return {string}
*/
function ruleUrl(ruleName) {
var name = ruleName;
if (name.includes("/")) {
var _name$split = name.split("/", 2);
var _name$split2 = _slicedToArray(_name$split, 2);
name = _name$split2[1];
}
return "https://github.com/stylelint-scss/stylelint-scss/blob/".concat(revision, "/src/rules/").concat(name);
}

View File

@@ -0,0 +1,896 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = findOperators;
exports.isInsideFunctionCall = isInsideFunctionCall;
exports.mathOperatorCharType = mathOperatorCharType;
/**
* Processes a string and finds Sass operators in it
*
* @param {Object} args - Named arguments object
* @param {String} args.string - the input string
* @param {Number} args.globalIndex - the position of args.string from the start of the line
* @param {Boolean} args.isAfterColon - pass "true" if the string is
* a variable value, a mixin/function parameter default.
* In such cases + and / tend to be operations more often
* @param {Function} args.callback - will be called on every instance of
* an operator. Accepts parameters:
* • string - the default source string
* • globalIndex - the string's position in the outer input
* • startIndex - index in string, where the operator starts
* • endIndex - index in string, where the operator ends (for `==`, etc.)
*
* @return {Array} array of { symbol, globalIndex, startIndex, endIndex }
* for each operator found within a string
*/
function findOperators(_ref) {
var string = _ref.string,
globalIndex = _ref.globalIndex,
isAfterColon = _ref.isAfterColon,
callback = _ref.callback;
var mathOperators = ["+", "/", "-", "*", "%"];
// A stack of modes activated for the current char: string, interpolation
// Calculations inside strings are not processed, so spaces are not linted
var modesEntered = [{
mode: "normal",
isCalculationEnabled: true,
character: null
}];
var result = [];
var lastModeIndex = 0;
for (var i = 0; i < string.length; i++) {
var character = string[i];
var substringStartingWithIndex = string.substring(i);
var lastMode = modesEntered[lastModeIndex];
// If entering/exiting a string
if (character === '"' || character === "'") {
if (lastMode && lastMode.isCalculationEnabled === true) {
modesEntered.push({
mode: "string",
isCalculationEnabled: false,
character: character
});
lastModeIndex++;
} else if (lastMode && lastMode.mode === "string" && lastMode.character === character && string[i - 1] !== "\\") {
modesEntered.pop();
lastModeIndex--;
}
}
// If entering/exiting interpolation (may be inside a string)
// Comparing with length-2 because `#{` at the very end doesnt matter
if (character === "#" && i + 1 < string.length - 2 && string[i + 1] === "{") {
modesEntered.push({
mode: "interpolation",
isCalculationEnabled: true
});
lastModeIndex++;
} else if (character === "}") {
modesEntered.pop();
lastModeIndex--;
}
// Don't lint if inside a string
if (lastMode && lastMode.isCalculationEnabled === false) {
continue;
}
// If it's a math operator
if (mathOperators.includes(character) && mathOperatorCharType(string, i, isAfterColon) === "op" ||
// or is "<" or ">"
substringStartingWithIndex.search(/^[<>]([^=]|$)/) !== -1) {
result.push({
symbol: string[i],
globalIndex: globalIndex,
startIndex: i,
endIndex: i
});
if (callback) {
callback(string, globalIndex, i, i);
}
}
// "<=", ">=", "!=", "=="
if (substringStartingWithIndex.search(/^[><=!]=/) !== -1) {
result.push({
symbol: string[i],
globalIndex: globalIndex,
startIndex: i,
endIndex: i + 1
});
if (callback) {
callback(string, globalIndex, i, i + 1);
}
}
}
// result.length > 0 && console.log(string, result)
return result;
}
/**
* Checks if a character is an operator, a sign (+ or -), or part of a string
*
* @param {String} string - the source string
* @param {Number} index - the index of the character in string to check
* @param {Boolean} isAfterColon - if the value string a variable
* value, a mixin/function parameter default. In such cases + and / tend
* to be operations more often
* @return {String|false}
* • "op", if the character is a operator in a math/string operation
* • "sign" if it is a + or - before a numeric,
* • "char" if it is a part of a string,
* • false - if it is none from above (most likely an error)
*/
function mathOperatorCharType(string, index, isAfterColon) {
// !Checking here to prevent unnecessary calculations and deep recursion
// when calling isPrecedingOperator()
if (!["+", "/", "-", "*", "%"].includes(string[index])) {
return "char";
}
var character = string[index];
var prevCharacter = string[index - 1];
if (prevCharacter !== "\\") {
// ---- Processing + characters
if (character === "+") {
return checkPlus(string, index, isAfterColon);
}
// ---- Processing - characters
if (character === "-") {
return checkMinus(string, index);
}
// ---- Processing * character
if (character === "*") {
return checkMultiplication(string, index);
}
// ---- Processing % character
if (character === "%") {
return checkPercent(string, index);
}
// ---- Processing / character
// https://sass-lang.com/documentation/operators/numeric#slash-separated-values
if (character === "/") {
return checkSlash(string, index, isAfterColon);
}
}
return "char";
}
// --------------------------------------------------------------------------
// Functions for checking particular characters (+, -, /)
// --------------------------------------------------------------------------
/**
* Checks the specified `*` char type: operator, sign (*), part of string
*
* @param {String} string - the source string
* @param {Number} index - the index of the character in string to check
* @return {String|false}
* • "op", if the character is a operator in a math/string operation
* • "sign" if it is a sign before a positive number,
* • "char" if it is a part of a string or identifier,
* • false - if it is none from above (most likely an error)
*/
function checkMultiplication(string, index) {
var insideFn = isInsideFunctionCall(string, index);
if (insideFn.is && insideFn.fn) {
var fnArgsReg = new RegExp(insideFn.fn + "\\(([^)]+)\\)");
var fnArgs = string.match(fnArgsReg);
var isSingleMultiplicationChar = Array.isArray(fnArgs) && fnArgs[1] === "*";
// e.g. selector(:has(*))
if (isSingleMultiplicationChar) {
return "char";
}
}
return "op";
}
/**
* Checks the specified `+` char type: operator, sign (+ or -), part of string
*
* @param {String} string - the source string
* @param {Number} index - the index of the character in string to check
* @param {Boolean} isAftercolon - if the value string a variable
* value, a mixin/function parameter default. In such cases + is always an
* operator if surrounded by numbers/values with units
* @return {String|false}
* • "op", if the character is a operator in a math/string operation
* • "sign" if it is a sign before a positive number,
* • false - if it is none from above (most likely an error)
*/
function checkPlus(string, index, isAftercolon) {
var before = string.substring(0, index);
var after = string.substring(index + 1);
// If the character is at the beginning of the input
var isAtStart_ = isAtStart(string, index);
// If the character is at the end of the input
var isAtEnd_ = isAtEnd(string, index);
var isWhitespaceBefore = before.search(/\s$/) !== -1;
var isWhitespaceAfter = after.search(/^\s/) !== -1;
var isValueWithUnitAfter_ = isValueWithUnitAfter(after);
var isNumberAfter_ = isNumberAfter(after);
var isInterpolationAfter_ = isInterpolationAfter(after);
// The early check above helps prevent deep recursion here
var isPrecedingOperator_ = isPrecedingOperator(string, index);
if (isAtStart_) {
// console.log("+, `+<sth>` or `+ <sth>`")
return "sign";
}
// E.g. `1+1`, `string+#fff`
if (!isAtStart_ && !isWhitespaceBefore && !isAtEnd_ && !isWhitespaceAfter) {
// E.g. `1-+1`
if (isPrecedingOperator_) {
// console.log('1+1')
return "sign";
}
// console.log("+, no spaces")
return "op";
}
// e.g. `something +something`
if (!isAtEnd_ && !isWhitespaceAfter) {
// e.g. `+something`, ` ... , +something`, etc.
if (isNoOperandBefore(string, index)) {
// console.log("+, nothing before")
return "sign";
}
// e.g. `sth +10px`, `sth +1`
if (isValueWithUnitAfter_.is && !isValueWithUnitAfter_.opsBetween || isNumberAfter_.is && !isNumberAfter_.opsBetween) {
if (isAftercolon === true) {
// console.log(": 10px +1")
return "op";
}
// e.g. `(sth +10px)`, `fun(sth +1)`
if (isInsideParens(string, index) || isInsideFunctionCall(string, index).is) {
// console.log("+10px or +1, inside function or parens")
return "op";
}
// e.g. `#{10px +1}`
if (isInsideInterpolation(string, index)) {
// console.log('+, #{10px +1}')
return "op";
}
// console.log('+, default')
return "sign";
}
// e.g. `sth +#fff`, `sth +string`, `sth +#{...}`, `sth +$var`
if (isStringAfter(after) || isHexColorAfter(after) || after[0] === "$" || isInterpolationAfter_.is && !isInterpolationAfter_.opsBefore) {
// e.g. `sth+ +string`
if (isPrecedingOperator_) {
// console.log("+10px or +1, before is an operator")
return "sign";
}
// console.log("+#000, +string, +#{sth}, +$var")
return "op";
}
// console.log('sth +sth, default')
return "op";
}
// If the + is after a value, e.g. `$var+`
if (!isAtStart_ && !isWhitespaceBefore) {
// It is always an operator. Prior to Sass 4, `#{...}+` was different,
// but that's not logical and had been fixed.
// console.log('1+ sth')
return "op";
}
// If it has whitespaces on both sides
// console.log('sth + sth')
return "op";
}
/**
* Checks the specified `-` character: operator, sign (+ or -), part of string
*
* @param {String} string - the source string
* @param {Number} index - the index of the character in string to check
* @return {String|false}
* • "op", if the character is a operator in a math/string operation
* • "sign" if it is a sign before a negative number,
* • "char" if it is a part of a string or identifier,
* • false - if it is none from above (most likely an error)
*/
function checkMinus(string, index) {
var before = string.substring(0, index);
var after = string.substring(index + 1);
// If the character is at the beginning of the input
var isAtStart_ = isAtStart(string, index);
// If the character is at the end of the input
var isAtEnd_ = isAtEnd(string, index);
var isWhitespaceBefore = before.search(/\s$/) !== -1;
var isWhitespaceAfter = after.search(/^\s/) !== -1;
var isValueWithUnitAfter_ = isValueWithUnitAfter(after);
var isValueWithUnitBefore_ = isValueWithUnitBefore(before);
var isNumberAfter_ = isNumberAfter(after);
var isNumberBefore_ = isNumberBefore(before);
var isInterpolationAfter_ = isInterpolationAfter(after);
var isParensAfter_ = isParensAfter(after);
var isParensBefore_ = isParensBefore(before);
// The early check above helps prevent deep recursion here
var isPrecedingOperator_ = isPrecedingOperator(string, index);
var isInsideFunctionCall_ = isInsideFunctionCall(string, index);
if (isAtStart_) {
// console.log("-, -<sth> or - <sth>")
return "sign";
}
// `10 - 11`
if (!isAtEnd_ && !isAtStart_ && isWhitespaceBefore && isWhitespaceAfter) {
// console.log("-, Op: 10px - 10px")
return "op";
}
// e.g. `something -10px`
if (!isAtEnd_ && !isAtStart_ && isWhitespaceBefore && !isWhitespaceAfter) {
if (isParensAfter_.is && !isParensAfter_.opsBefore) {
// console.log("-, Op: <sth> -(...)")
return "op";
}
// e.g. `#{10px -1}`, `#{math.acos(-0.5)}`
if (isInsideInterpolation(string, index)) {
// e.g. `url(https://my-url.com/image-#{$i -2}-dark.svg)`
if (isInsideFunctionCall_.fn === "url") {
return "op";
}
if (isInsideFunctionCall_.is && (isValueWithUnitAfter_.is && !isValueWithUnitAfter_.opsBetween || isNumberAfter_.is && !isNumberAfter_.opsBetween)) {
return "sign";
}
// e.g. `#{$i * -10}px`
if (isWhitespaceBefore && isNumberAfter_.is && isPrecedingOperator_) {
return "sign";
}
return "op";
}
// e.g. `sth -1px`, `sth -1`.
// Always a sign, even inside parens/function args
if (isValueWithUnitAfter_.is && !isValueWithUnitAfter_.opsBetween || isNumberAfter_.is && !isNumberAfter_.opsBetween) {
// console.log("-, sign: -1px or -1")
return "sign";
}
// e.g. `sth --1`, `sth +-2px`
if (isValueWithUnitAfter_.is && isValueWithUnitAfter_.opsBetween || isNumberAfter_.is && isNumberAfter_.opsBetween) {
// console.log("-, op: --1px or --1")
return "op";
}
// `<sth> -string`, `<sth> -#{...}`
if (isStringAfter(after) || isInterpolationAfter_.is && !isInterpolationAfter_.opsBefore) {
// console.log("-, char: -#{...}")
return "char";
}
// e.g. `#0af -#f0a`, and edge-cases can take a hike
if (isHexColorAfter(after) && isHexColorBefore(before.trim())) {
// console.log("-, op: #fff-, -#fff")
return "op";
}
// If the - is before a variable, than it's most likely an operator
if (after[0] === "$") {
if (isPrecedingOperator_) {
// console.log("-, sign: -$var, another operator before")
return "sign";
}
// console.log("-, op: -$var, NO other operator before")
return "op";
}
// By default let's make it an sign for now
// console.log('-, sign: default in <sth> -<sth>')
return "sign";
}
// No whitespace before,
// e.g. `10x- something`
if (!isAtEnd_ && !isAtStart_ && !isWhitespaceBefore && isWhitespaceAfter) {
if (isParensBefore_) {
// console.log('-, op: `(...)- <sth>`')
return "op";
}
// e.g. `#{10px- 1}`
if (isInsideInterpolation(string, index)) {
return "op";
}
if (isNumberBefore(before) || isHexColorBefore(before)) {
// console.log('`-, op: 10- <sth>, #aff- <sth>`')
return "op";
}
// console.log('-, char: default in <sth>- <sth>')
return "char";
}
// NO Whitespace,
// e.g. `10px-1`
if (!isAtEnd_ && !isAtStart_ && !isWhitespaceBefore && !isWhitespaceAfter) {
// console.log('no spaces')
// `<something>-1`, `<something>-10px`
if (isValueWithUnitAfter_.is && !isValueWithUnitAfter_.opsBetween || isNumberAfter_.is && !isNumberAfter_.opsBetween) {
// `10px-1`, `1-10px`, `1-1`, `1x-1x`
if (isValueWithUnitBefore_ || isNumberBefore_) {
// console.log("-, op: 1-10px")
return "op";
}
// The - could be a "sign" here, but for now "char" does the job
}
// `1-$var`
if (isNumberBefore_ && after[0] === "$") {
// console.log("-, op: 1-$var")
return "op";
}
// `fn()-10px`
if (isFunctionBefore(before) && (isNumberAfter_.is && !isNumberAfter_.opsBetween || isValueWithUnitAfter_.is && !isValueWithUnitAfter_.opsBetween)) {
// console.log("-, op: fn()-10px")
return "op";
}
}
// And in all the other cases it's a character inside a string
// console.log("-, default: char")
return "char";
}
/**
* Checks the specified `/` character: operator, sign (+ or -), part of string
*
* @param {String} string - the source string
* @param {Number} index - the index of the character in string to check
* @param {Boolean} isAfterColon - if the value string a variable
* value, a mixin/function parameter default. In such cases / is always an
* operator if surrounded by numbers/values with units
* @return {String|false}
* • "op", if the character is a operator in a math/string operation
* • "char" if it gets compiled as-is, e.g. `font: 10px/1.2;`,
* • false - if it is none from above (most likely an error)
*/
function checkSlash(string, index, isAfterColon) {
// Trimming these, as spaces before/after a slash don't matter
var before = string.substring(0, index).trim();
var after = string.substring(index + 1).trim();
var isValueWithUnitAfter_ = isValueWithUnitAfter(after);
var isValueWithUnitBefore_ = isValueWithUnitBefore(before);
var isNumberAfter_ = isNumberAfter(after);
var isNumberBefore_ = isNumberBefore(before);
var isParensAfter_ = isParensAfter(after);
var isParensBefore_ = isParensBefore(before);
// FIRST OFF. Interpolation on any of the sides is a NO-GO for division op
if (isInterpolationBefore(before).is || isInterpolationAfter(after).is) {
// console.log("/, interpolation")
return "char";
}
// having a dot before probably means a relative path.
// e.g. url(../../image.png)
if (isDotBefore(before)) {
return "char";
}
// e.g. `(1px/1)`, `fn(7 / 15)`, but not `url(8/11)`
var isInsideFn = isInsideFunctionCall(string, index);
if (isInsideFn.is && isInsideFn.fn === "url") {
// e.g. `url(https://my-url.com/image-#{$i /2}-dark.svg)`
if (isInsideInterpolation(string, index)) {
return "op";
}
return "char";
}
// e.g. `10px/normal`
if (isStringBefore(before).is || isStringAfter(after)) {
// console.log("/, string")
return "char";
}
// For all other value options (numbers, value+unit, hex color)
// `$var/1`, `#fff/-$var`
// Here we don't care if there is a sign before the var
if (isVariableBefore(before) || isVariableAfter(after).is) {
// console.log("/, variable")
return "op";
}
if (isFunctionBefore(before) || isFunctionAfter(after).is) {
// console.log("/, function as operand")
return "op";
}
if (isParensBefore_ || isParensAfter_.is) {
// console.log("/, function as operand")
return "op";
}
// `$var: 10px/2; // 5px`
if (isAfterColon === true && (isValueWithUnitAfter_.is || isNumberAfter_.is) && (isValueWithUnitBefore_ || isNumberBefore_)) {
return "op";
}
// Quick check of the following operator symbol - if it is a math operator
if (
// +, *, % count as operators unless after interpolation or at the start
before.search(/[^{,(}\s]\s*[+*%][^(){},]+$/) !== -1 ||
// We consider minus as op only if surrounded by whitespaces (` - `);
before.search(/[^{,(}\s]\s+-\s[^(){},]+$/) !== -1 ||
// `10/2 * 3`, `10/2 % 3`, with or without spaces
after.search(/^[^(){},]+[*%]/) !== -1 ||
// `10px/2px+1`, `10px/2px+ 1`
after.search(/^[^(){},\s]+\+/) !== -1 ||
// Anything but `10px/2px +1`, `10px/2px +1px`
after.search(/^[^(){},\s]+\s+(\+\D)/) !== -1 ||
// Following ` -`: only if `$var` after (`10/10 -$var`)
after.search(/^[^(){},\s]+\s+-(\$|\s)/) !== -1 ||
// Following `-`: only if number after (`10s/10s-10`, `10s/10s-.1`)
after.search(/^[^(){},\s]+-(\.)?\d/) !== -1 ||
// Or if there is a number before anything but string after (not `10s/1-str`,)
after.search(/^(\d*\.)?\d+-\s*[^#a-zA-Z_\s]/) !== -1) {
// console.log("/, math op around")
return "op";
}
if (isInsideParens(string, index) || isInsideFn.is && isInsideFn.fn !== "url") {
// console.log("/, parens or function arg")
return "op";
}
// console.log("/, default")
return "char";
}
/**
* Checks the specified `%` character: operator or part of value
*
* @param {String} string - the source string
* @param {Number} index - the index of the character in string to check
* @return {String|false}
* • "op", if the character is a operator in a math/string operation
* • "char" if it gets compiled as-is, e.g. `width: 10%`,
* • false - if it is none from above (most likely an error)
*/
function checkPercent(string, index) {
// Trimming these, as spaces before/after a slash don't matter
var before = string.substring(0, index);
var after = string.substring(index + 1);
// If the character is at the beginning of the input
var isAtStart_ = isAtStart(string, index);
// If the character is at the end of the input
var isAtEnd_ = isAtEnd(string, index);
var isWhitespaceBefore = before.search(/\s$/) !== -1;
var isWhitespaceAfter = after.search(/^\s/) !== -1;
var isParensBefore_ = isParensBefore(before);
// FIRST OFF. Interpolation on any of the sides is a NO-GO
if (isInterpolationBefore(before.trim()).is || isInterpolationAfter(after.trim()).is) {
// console.log("%, interpolation")
return "char";
}
if (isAtStart_ || isAtEnd_) {
// console.log("%, start/end")
return "char";
}
// In `<sth> %<sth>` it's most likely an operator (except for interpolation
// checked above)
if (isWhitespaceBefore && !isWhitespaceAfter) {
// console.log("%, `<sth> %<sth>`")
return "op";
}
// `$var% 1`, `$var%1`, `$var%-1`
if (isVariableBefore(before) || isParensBefore_) {
// console.log("%, after a variable, function or parens")
return "op";
}
// in all other cases in `<sth>% <sth>` it is most likely a unit
if (!isWhitespaceBefore && isWhitespaceAfter) {
// console.log("%, `<sth>% <sth>`")
return "char";
}
// console.log("%, default")
return "char";
}
// --------------------------------------------------------------------------
// Lots of elementary helpers
// --------------------------------------------------------------------------
function isAtStart(string, index) {
var before = string.substring(0, index).trim();
return before.length === 0 || before.search(/[({,]$/) !== -1;
}
function isAtEnd(string, index) {
var after = string.substring(index + 1).trim();
return after.length === 0 || after.search(/^[,)}]/) !== -1;
}
function isInsideParens(string, index) {
var before = string.substring(0, index).trim();
var after = string.substring(index + 1).trim();
return before.search(/(?:^|[,{\s])\([^(){},]+$/) !== -1 && after.search(/^[^(){},\s]+\s*\)/) !== -1;
}
function isInsideInterpolation(string, index) {
var before = string.substring(0, index).trim();
return before.search(/#{[^}]*$/) !== -1;
}
/**
* Checks if the character is inside a function arguments
*
* @param {String} string - the input string
* @param {Number} index - current character index
* @return {Object} return
* {Boolean} return.is - if inside a function arguments
* {String} return.fn - function name
*/
function isInsideFunctionCall(string, index) {
var result = {
is: false,
fn: null
};
var before = string.substring(0, index).trim();
var after = string.substring(index + 1).trim();
var beforeMatch = before.match(/(?:[a-zA-Z_-][\w-]*\()?(:?[a-zA-Z_-][\w-]*)\(/);
if (beforeMatch && beforeMatch[0] && after.search(/^[^(,]+\)/) !== -1) {
result.is = true;
result.fn = beforeMatch[1];
}
return result;
}
/**
* Checks if there is a string before the character.
* Also checks if there is a math operator in between
*
* @param {String} before - the input string that preceses the character
* @return {Object} return
* {Boolean} return.is - if there is a string
* {String} return.opsBetween - if there are operators in between
*/
function isStringBefore(before) {
var result = {
is: false,
opsBetween: false
};
var stringOpsClipped = before.replace(/(\s*[+/*%]|\s+-)+$/, "");
if (stringOpsClipped !== before) {
result.opsBetween = true;
}
// If it is quoted
if (stringOpsClipped[stringOpsClipped.length - 1] === '"' || stringOpsClipped[stringOpsClipped.length - 1] === "'") {
result.is = true;
} else if (stringOpsClipped.search(/(?:^|[/(){},: ])([a-zA-Z_][\w-]*|-+[a-zA-Z_][\w-]*)$/) !== -1) {
// First pattern: a1, a1a, a-1,
result.is = true;
}
return result;
}
function isStringAfter(after) {
var stringTrimmed = after.trim();
// If it is quoted
if (stringTrimmed[0] === '"' || stringTrimmed[0] === "'") return true;
// e.g. `a1`, `a1a`, `a-1`, and even `--s323`
return stringTrimmed.search(/^([a-zA-Z_][\w-]*|-+[a-zA-Z_][\w-]*)(?:$|[)}, ])/) !== -1;
}
function isInterpolationAfter(after) {
var result = {
is: false,
opsBetween: false
};
var matches = after.match(/^\s*([+/*%-]\s*)*#{/);
if (matches) {
if (matches[0]) {
result.is = true;
}
if (matches[1]) {
result.opsBetween = true;
}
}
return result;
}
function isParensAfter(after) {
var result = {
is: false,
opsBetween: false
};
var matches = after.match(/^\s*([+/*%-]\s*)*\(/);
if (matches) {
if (matches[0]) {
result.is = true;
}
if (matches[1]) {
result.opsBetween = true;
}
}
return result;
}
function isParensBefore(before) {
return before.search(/\)\s*$/) !== -1;
}
/**
* Checks if there is an interpolation before the character.
* Also checks if there is a math operator in between
*
* @param {String} before - the input string that preceses the character
* @return {Object} return
* {Boolean} return.is - if there is an interpolation
* {String} return.opsBetween - if there are operators in between
*/
function isInterpolationBefore(before) {
var result = {
is: false,
opsBetween: false
};
// Removing preceding operators if any
var beforeOpsClipped = before.replace(/(\s*[+/*%-])+$/, "");
if (beforeOpsClipped !== before) {
result.opsBetween = true;
}
if (beforeOpsClipped[beforeOpsClipped.length - 1] === "}") {
result.is = true;
}
return result;
}
function isValueWithUnitBefore(before) {
// 1px, 0.1p-x, .2p-, 11.2pdf-df1df_
// Surprisingly, ` d.10px` - .10px is separated from a sequence
// and is considered a value with a unit
return before.trim().search(/(^|[/(, .])\d[\w-]+$/) !== -1;
}
function isValueWithUnitAfter(after) {
var result = {
is: false,
opsBetween: false
};
// 1px, 0.1p-x, .2p-, 11.2pdf-dfd1f_
// Again, ` d.10px` - .10px is separated from a sequence
// and is considered a value with a unit
var matches = after.match(/^\s*([+/*%-]\s*)*(\d+(\.\d+)?|\.\d+)[\w-%]+(?:$|[)}, ])/);
if (matches) {
if (matches[0]) {
result.is = true;
}
if (matches[1]) {
result.opsBetween = true;
}
}
return result;
}
function isNumberAfter(after) {
var result = {
is: false,
opsBetween: false
};
var matches = after.match(/^\s*([+/*%-]\s*)*(\d+(\.\d+)?|\.\d+)(?:$|[)}, ])/);
if (matches) {
if (matches[0]) {
result.is = true;
}
if (matches[1]) {
result.opsBetween = true;
}
}
return result;
}
function isNumberBefore(before) {
return before.trim().search(/(?:^|[/(){},\s])(\d+(\.\d+)?|\.\d+)$/) !== -1;
}
function isVariableBefore(before) {
return before.trim().search(/\$[\w-]+$/) !== -1;
}
function isVariableAfter(after) {
var result = {
is: false,
opsBetween: false
};
var matches = after.match(/^\s*([+/*%-]\s*)*\$/);
if (matches) {
if (matches[0]) {
result.is = true;
}
if (matches[1]) {
result.opsBetween = true;
}
}
return result;
}
function isDotBefore(before) {
return before.slice(-1) === ".";
}
function isFunctionBefore(before) {
return before.trim().search(/[\w-]\(.*?\)\s*$/) !== -1;
}
function isFunctionAfter(after) {
var result = {
is: false,
opsBetween: false
};
// `-fn()` is a valid function name, so if a - should be a sign/operator,
// it must have a space after
var matches = after.match(/^\s*(-\s+|[+/*%]\s*)*[a-zA-Z_-][\w-]*\(/);
if (matches) {
if (matches[0]) {
result.is = true;
}
if (matches[1]) {
result.opsBetween = true;
}
}
return result;
}
/**
* Checks if the input string is a hex color value
*
* @param {String} string - the input
* @return {Boolean} true, if the input is a hex color
*/
function isHexColor(string) {
return string.trim().search(/^#([\da-fA-F]{3}|[\da-fA-F]{6})$/) !== -1;
}
function isHexColorAfter(after) {
var afterTrimmed = after.match(/(.*?)(?:[)},+/*%\-\s]|$)/)[1].trim();
return isHexColor(afterTrimmed);
}
function isHexColorBefore(before) {
return before.search(/(?:[/(){},+*%-\s]|^)#([\da-fA-F]{3}|[\da-fA-F]{6})$/) !== -1;
}
/**
* Checks if there is no operand before the current char
* In other words, the current char is at the start of a possible operation,
* e.g. at the string start, after the opening paren or after a comma
*
* @param {String} string - the input string
* @param {Number} index - current char's position in string
* @return {Boolean}
*/
function isNoOperandBefore(string, index) {
var before = string.substring(0, index).trim();
return before.length === 0 || before.search(/[({,]&/) !== -1;
}
function isPrecedingOperator(string, index) {
var prevCharIndex = -1;
for (var i = index - 1; i >= 0; i--) {
if (string[i].search(/\s/) === -1) {
prevCharIndex = i;
break;
}
}
if (prevCharIndex === -1) {
return false;
}
if (mathOperatorCharType(string, prevCharIndex) === "op") {
return true;
}
return false;
}

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isBoolean = isBoolean;
exports.isNumber = isNumber;
exports.isRegExp = isRegExp;
exports.isString = isString;
/**
* Checks if the value is a boolean or a Boolean object.
* @param {unknown} value
* @returns {value is boolean}
*/
function isBoolean(value) {
return typeof value === "boolean" || value instanceof Boolean;
}
/**
* Checks if the value is a number or a Number object.
* @param {unknown} value
* @returns {value is number}
*/
function isNumber(value) {
return typeof value === "number" || value instanceof Number;
}
/**
* Checks if the value is a regular expression.
* @param {unknown} value
* @returns {value is RegExp}
*/
function isRegExp(value) {
return value instanceof RegExp;
}
/**
* Checks if the value is a string or a String object.
* @param {unknown} value
* @returns {value is string}
*/
function isString(value) {
return typeof value === "string" || value instanceof String;
}

View File

@@ -0,0 +1,315 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
var _isWhitespace = _interopRequireDefault(require("./isWhitespace"));
var _isSingleLineString = _interopRequireDefault(require("./isSingleLineString"));
var _configurationError = _interopRequireDefault(require("./configurationError"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Create a whitespaceChecker, which exposes the following functions:
* - `before()`
* - `beforeAllowingIndentation()`
* - `after()`
* - `afterOneOnly()`
*
* @param {"space"|"newline"} targetWhitespace - This is a keyword instead
* of the actual character (e.g. " ") in order to accommodate
* different styles of newline ("\n" vs "\r\n")
* @param {
* "always"|"never"
* |"always-single-line"|"always-multi-line"
* | "never-single-line"|"never-multi-line"
* } expectation
* @param {object} messages - An object of message functions;
* calling `before*()` or `after*()` and the `expectation` that is passed
* determines which message functions are required
* @param {function} [messages.expectedBefore]
* @param {function} [messages.rejectedBefore]
* @param {function} [messages.expectedAfter]
* @param {function} [messages.rejectedAfter]
* @param {function} [messages.expectedBeforeSingleLine]
* @param {function} [messages.rejectedBeforeSingleLine]
* @param {function} [messages.expectedBeforeMultiLine]
* @param {function} [messages.rejectedBeforeMultiLine]
* @return {object} The checker, with its exposed checking functions
*/
function _default(targetWhitespace, expectation, messages) {
// Keep track of active arguments in order to avoid passing
// too much stuff around, making signatures long and confusing.
// This variable gets reset anytime a checking function is called.
var activeArgs;
/**
* Check for whitespace *before* a character.
*
* @param {object} args - Named arguments object
* @param {string} args.source - The source string
* @param {number} args.index - The index of the character to check before
* @param {function} args.err - If a violation is found, this callback
* will be invoked with the relevant warning message.
* Typically this callback will report() the violation.
* @param {function} args.errTarget - If a violation is found, this string
* will be sent to the relevant warning message.
* @param {string} [args.lineCheckStr] - Single- and multi-line checkers
* will use this string to determine whether they should proceed,
* i.e. if this string is one line only, single-line checkers will check,
* multi-line checkers will ignore.
* If none is passed, they will use `source`.
* @param {boolean} [args.onlyOneChar=false] - Only check *one* character before.
* By default, "always-*" checks will look for the `targetWhitespace` one
* before and then ensure there is no whitespace two before. This option
* bypasses that second check.
* @param {boolean} [args.allowIndentation=false] - Allow arbitrary indentation
* between the `targetWhitespace` (almost definitely a newline) and the `index`.
* With this option, the checker will see if a newline *begins* the whitespace before
* the `index`.
*/
function before(_ref) {
var source = _ref.source,
index = _ref.index,
err = _ref.err,
errTarget = _ref.errTarget,
lineCheckStr = _ref.lineCheckStr,
_ref$onlyOneChar = _ref.onlyOneChar,
onlyOneChar = _ref$onlyOneChar === void 0 ? false : _ref$onlyOneChar,
_ref$allowIndentation = _ref.allowIndentation,
allowIndentation = _ref$allowIndentation === void 0 ? false : _ref$allowIndentation;
activeArgs = {
source: source,
index: index,
err: err,
errTarget: errTarget,
onlyOneChar: onlyOneChar,
allowIndentation: allowIndentation
};
switch (expectation) {
case "always":
expectBefore();
break;
case "never":
rejectBefore();
break;
case "always-single-line":
if (!(0, _isSingleLineString["default"])(lineCheckStr || source)) {
return;
}
expectBefore(messages.expectedBeforeSingleLine);
break;
case "never-single-line":
if (!(0, _isSingleLineString["default"])(lineCheckStr || source)) {
return;
}
rejectBefore(messages.rejectedBeforeSingleLine);
break;
case "always-multi-line":
if ((0, _isSingleLineString["default"])(lineCheckStr || source)) {
return;
}
expectBefore(messages.expectedBeforeMultiLine);
break;
case "never-multi-line":
if ((0, _isSingleLineString["default"])(lineCheckStr || source)) {
return;
}
rejectBefore(messages.rejectedBeforeMultiLine);
break;
default:
throw (0, _configurationError["default"])("Unknown expectation \"".concat(expectation, "\""));
}
}
/**
* Check for whitespace *after* a character.
*
* Parameters are pretty much the same as for `before()`, above, just substitute
* the word "after" for "before".
*/
function after(_ref2) {
var source = _ref2.source,
index = _ref2.index,
err = _ref2.err,
errTarget = _ref2.errTarget,
lineCheckStr = _ref2.lineCheckStr,
_ref2$onlyOneChar = _ref2.onlyOneChar,
onlyOneChar = _ref2$onlyOneChar === void 0 ? false : _ref2$onlyOneChar;
activeArgs = {
source: source,
index: index,
err: err,
errTarget: errTarget,
onlyOneChar: onlyOneChar
};
switch (expectation) {
case "always":
expectAfter();
break;
case "never":
rejectAfter();
break;
case "always-single-line":
if (!(0, _isSingleLineString["default"])(lineCheckStr || source)) {
return;
}
expectAfter(messages.expectedAfterSingleLine);
break;
case "never-single-line":
if (!(0, _isSingleLineString["default"])(lineCheckStr || source)) {
return;
}
rejectAfter(messages.rejectedAfterSingleLine);
break;
case "always-multi-line":
if ((0, _isSingleLineString["default"])(lineCheckStr || source)) {
return;
}
expectAfter(messages.expectedAfterMultiLine);
break;
case "never-multi-line":
if ((0, _isSingleLineString["default"])(lineCheckStr || source)) {
return;
}
rejectAfter(messages.rejectedAfterMultiLine);
break;
case "at-least-one-space":
expectAfter(messages.expectedAfterAtLeast);
break;
default:
throw (0, _configurationError["default"])("Unknown expectation \"".concat(expectation, "\""));
}
}
function beforeAllowingIndentation(obj) {
before(Object.assign({}, obj, {
allowIndentation: true
}));
}
function expectBefore() {
var messageFunc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : messages.expectedBefore;
if (activeArgs.allowIndentation) {
expectBeforeAllowingIndentation(messageFunc);
return;
}
var _activeArgs = activeArgs,
source = _activeArgs.source,
index = _activeArgs.index;
var oneCharBefore = source[index - 1];
var twoCharsBefore = source[index - 2];
if (!isValue(oneCharBefore)) {
return;
}
if (targetWhitespace === "newline") {
// If index is preceeded by a Windows CR-LF ...
if (oneCharBefore === "\n" && twoCharsBefore === "\r") {
if (activeArgs.onlyOneChar || !(0, _isWhitespace["default"])(source[index - 3])) {
return;
}
}
// If index is followed by a Unix LF ...
if (oneCharBefore === "\n" && twoCharsBefore !== "\r") {
if (activeArgs.onlyOneChar || !(0, _isWhitespace["default"])(twoCharsBefore)) {
return;
}
}
}
if (targetWhitespace === "space" && oneCharBefore === " ") {
if (activeArgs.onlyOneChar || !(0, _isWhitespace["default"])(twoCharsBefore)) {
return;
}
}
activeArgs.err(messageFunc(activeArgs.errTarget ? activeArgs.errTarget : source[index]));
}
function expectBeforeAllowingIndentation() {
var messageFunc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : messages.expectedBefore;
var _activeArgs2 = activeArgs,
source = _activeArgs2.source,
index = _activeArgs2.index,
err = _activeArgs2.err;
var expectedChar = function () {
if (targetWhitespace === "newline") {
return "\n";
}
if (targetWhitespace === "space") {
return " ";
}
}();
var i = index - 1;
while (source[i] !== expectedChar) {
if (source[i] === "\t" || source[i] === " ") {
i--;
continue;
}
err(messageFunc(activeArgs.errTarget ? activeArgs.errTarget : source[index]));
return;
}
}
function rejectBefore() {
var messageFunc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : messages.rejectedBefore;
var _activeArgs3 = activeArgs,
source = _activeArgs3.source,
index = _activeArgs3.index;
var oneCharBefore = source[index - 1];
if (isValue(oneCharBefore) && (0, _isWhitespace["default"])(oneCharBefore)) {
activeArgs.err(messageFunc(activeArgs.errTarget ? activeArgs.errTarget : source[index]));
}
}
function afterOneOnly(obj) {
after(Object.assign({}, obj, {
onlyOneChar: true
}));
}
function expectAfter() {
var messageFunc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : messages.expectedAfter;
var _activeArgs4 = activeArgs,
source = _activeArgs4.source,
index = _activeArgs4.index;
var oneCharAfter = index + 1 < source.length ? source[index + 1] : "";
var twoCharsAfter = index + 2 < source.length ? source[index + 2] : "";
if (!isValue(oneCharAfter)) {
return;
}
if (targetWhitespace === "newline") {
// If index is followed by a Windows CR-LF ...
if (oneCharAfter === "\r" && twoCharsAfter === "\n") {
var threeCharsAfter = index + 3 < source.length ? source[index + 3] : "";
if (activeArgs.onlyOneChar || !(0, _isWhitespace["default"])(threeCharsAfter)) {
return;
}
}
// If index is followed by a Unix LF ...
if (oneCharAfter === "\n") {
if (activeArgs.onlyOneChar || !(0, _isWhitespace["default"])(twoCharsAfter)) {
return;
}
}
}
if (targetWhitespace === "space" && oneCharAfter === " ") {
if (expectation === "at-least-one-space" || activeArgs.onlyOneChar || !(0, _isWhitespace["default"])(twoCharsAfter)) {
return;
}
}
activeArgs.err(messageFunc(activeArgs.errTarget ? activeArgs.errTarget : source[index]));
}
function rejectAfter() {
var messageFunc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : messages.rejectedAfter;
var _activeArgs5 = activeArgs,
source = _activeArgs5.source,
index = _activeArgs5.index;
var oneCharAfter = index + 1 < source.length ? source[index + 1] : "";
if (isValue(oneCharAfter) && (0, _isWhitespace["default"])(oneCharAfter)) {
activeArgs.err(messageFunc(activeArgs.errTarget ? activeArgs.errTarget : source[index]));
}
}
return {
before: before,
beforeAllowingIndentation: beforeAllowingIndentation,
after: after,
afterOneOnly: afterOneOnly
};
}
function isValue(x) {
return x !== undefined && x !== null;
}