Sha256: 89d4c36b480cbeb8d8b29607d63db9e9da5b9948ad8158ee9633f89a5c86d337

Contents?: true

Size: 1.64 KB

Versions: 48

Compression:

Stored size: 1.64 KB

Contents

module.exports = function calcAtRulePatternPriority(pattern, node) {
	// 0 — it pattern doesn't match
	// 1 — pattern without `name` and `hasBlock`
	// 10010 — pattern match `hasBlock`
	// 10100 — pattern match `name`
	// 20110 — pattern match `name` and `hasBlock`
	// 21100 — patter match `name` and `parameter`
	// 31110 — patter match `name`, `parameter`, and `hasBlock`

	let priority = 0;

	// match `hasBlock`
	if (pattern.hasOwnProperty('hasBlock') && node.hasBlock === pattern.hasBlock) {
		priority += 10;
		priority += 10000;
	}

	// match `name`
	if (pattern.hasOwnProperty('name') && node.name === pattern.name) {
		priority += 100;
		priority += 10000;
	}

	// match `name`
	if (pattern.hasOwnProperty('parameter') && pattern.parameter.test(node.parameter)) {
		priority += 1100;
		priority += 10000;
	}

	// doesn't have `name` and `hasBlock`
	if (
		!pattern.hasOwnProperty('hasBlock') &&
		!pattern.hasOwnProperty('name') &&
		!pattern.hasOwnProperty('paremeter')
	) {
		priority = 1;
	}

	// patter has `name` and `hasBlock`, but it doesn't match both properties
	if (pattern.hasOwnProperty('hasBlock') && pattern.hasOwnProperty('name') && priority < 20000) {
		priority = 0;
	}

	// patter has `name` and `parameter`, but it doesn't match both properties
	if (pattern.hasOwnProperty('name') && pattern.hasOwnProperty('parameter') && priority < 21100) {
		priority = 0;
	}

	// patter has `name`, `parameter`, and `hasBlock`, but it doesn't match all properties
	if (
		pattern.hasOwnProperty('name') &&
		pattern.hasOwnProperty('parameter') &&
		pattern.hasOwnProperty('hasBlock') &&
		priority < 30000
	) {
		priority = 0;
	}

	return priority;
};

Version data entries

48 entries across 24 versions & 1 rubygems

Version Path
trusty-cms-4.3.4 node_modules/stylelint-order/rules/order/calcAtRulePatternPriority.js
trusty-cms-4.3.4 node_modules/postcss-sorting/lib/calcAtRulePatternPriority.js
trusty-cms-4.3.3 node_modules/postcss-sorting/lib/calcAtRulePatternPriority.js
trusty-cms-4.3.3 node_modules/stylelint-order/rules/order/calcAtRulePatternPriority.js
trusty-cms-4.3.2 node_modules/stylelint-order/rules/order/calcAtRulePatternPriority.js
trusty-cms-4.3.2 node_modules/postcss-sorting/lib/calcAtRulePatternPriority.js
trusty-cms-4.3.1 node_modules/stylelint-order/rules/order/calcAtRulePatternPriority.js
trusty-cms-4.3.1 node_modules/postcss-sorting/lib/calcAtRulePatternPriority.js
trusty-cms-4.3 node_modules/postcss-sorting/lib/calcAtRulePatternPriority.js
trusty-cms-4.3 node_modules/stylelint-order/rules/order/calcAtRulePatternPriority.js
trusty-cms-4.2.3 node_modules/stylelint-order/rules/order/calcAtRulePatternPriority.js
trusty-cms-4.2.3 node_modules/postcss-sorting/lib/calcAtRulePatternPriority.js
trusty-cms-4.2.2 node_modules/stylelint-order/rules/order/calcAtRulePatternPriority.js
trusty-cms-4.2.2 node_modules/postcss-sorting/lib/calcAtRulePatternPriority.js
trusty-cms-4.2.1 node_modules/postcss-sorting/lib/calcAtRulePatternPriority.js
trusty-cms-4.2.1 node_modules/stylelint-order/rules/order/calcAtRulePatternPriority.js
trusty-cms-4.2 node_modules/stylelint-order/rules/order/calcAtRulePatternPriority.js
trusty-cms-4.2 node_modules/postcss-sorting/lib/calcAtRulePatternPriority.js
trusty-cms-4.1.9 node_modules/stylelint-order/rules/order/calcAtRulePatternPriority.js
trusty-cms-4.1.9 node_modules/postcss-sorting/lib/calcAtRulePatternPriority.js