@markuplint/ml-core
Advanced tools
Comparing version 2.0.0-rc.3 to 2.0.0-rc.5
@@ -128,3 +128,6 @@ "use strict"; | ||
try { | ||
(0, tslib_1.__classPrivateFieldSet)(this, _MLCore_document, new ml_dom_1.Document((0, tslib_1.__classPrivateFieldGet)(this, _MLCore_ast, "f"), (0, tslib_1.__classPrivateFieldGet)(this, _MLCore_ruleset, "f"), (0, tslib_1.__classPrivateFieldGet)(this, _MLCore_schemas, "f"), (0, tslib_1.__classPrivateFieldGet)(this, _MLCore_filename, "f")), "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _MLCore_document, new ml_dom_1.Document((0, tslib_1.__classPrivateFieldGet)(this, _MLCore_ast, "f"), (0, tslib_1.__classPrivateFieldGet)(this, _MLCore_ruleset, "f"), (0, tslib_1.__classPrivateFieldGet)(this, _MLCore_schemas, "f"), { | ||
filename: (0, tslib_1.__classPrivateFieldGet)(this, _MLCore_filename, "f"), | ||
tagNameCaseSensitive: (0, tslib_1.__classPrivateFieldGet)(this, _MLCore_parser, "f").tagNameCaseSensitive, | ||
}), "f"); | ||
} | ||
@@ -131,0 +134,0 @@ catch (err) { |
@@ -45,3 +45,6 @@ import type { MLRule } from '../'; | ||
*/ | ||
constructor(ast: MLASTDocument, ruleset: Ruleset, schemas: readonly [MLMLSpec, ...ExtendedSpec[]], filename?: string); | ||
constructor(ast: MLASTDocument, ruleset: Ruleset, schemas: readonly [MLMLSpec, ...ExtendedSpec[]], options?: { | ||
filename?: string; | ||
tagNameCaseSensitive?: boolean; | ||
}); | ||
get doctype(): MLDOMDoctype<T, O> | null; | ||
@@ -48,0 +51,0 @@ get tree(): AnonymousNode<T, O>[]; |
@@ -26,3 +26,3 @@ "use strict"; | ||
*/ | ||
constructor(ast, ruleset, schemas, filename) { | ||
constructor(ast, ruleset, schemas, options) { | ||
/** | ||
@@ -39,3 +39,3 @@ * | ||
this.specs = (0, ml_spec_1.getSpec)(schemas); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _MLDOMDocument_filename, filename, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _MLDOMDocument_filename, options === null || options === void 0 ? void 0 : options.filename, "f"); | ||
// console.log(ast.nodeList.map((n, i) => `${i}: ${n.uuid} "${n.raw.trim()}"(${n.type})`)); | ||
@@ -48,3 +48,3 @@ this.nodeList = Object.freeze(ast.nodeList.map(astNode => { | ||
})); | ||
this._ruleMapping(ruleset); | ||
this._ruleMapping(ruleset, options === null || options === void 0 ? void 0 : options.tagNameCaseSensitive); | ||
} | ||
@@ -130,3 +130,3 @@ /** | ||
} | ||
_ruleMapping(ruleset) { | ||
_ruleMapping(ruleset, tagNameCaseSensitive) { | ||
docLog('Rule Mapping'); | ||
@@ -177,3 +177,3 @@ const ruleMapper = new rule_mapper_1.RuleMapper(this.nodeList); | ||
*/ | ||
(0, match_selector_1.matchSelector)(selectorTarget, selector); | ||
(0, match_selector_1.matchSelector)(selectorTarget, selector, tagNameCaseSensitive); | ||
if (!matches.matched) { | ||
@@ -221,3 +221,3 @@ return; | ||
} | ||
const matches = (0, match_selector_1.matchSelector)(selectorTarget, selector); | ||
const matches = (0, match_selector_1.matchSelector)(selectorTarget, selector, tagNameCaseSensitive); | ||
if (!matches.matched) { | ||
@@ -224,0 +224,0 @@ return; |
@@ -15,3 +15,3 @@ import type MLDOMAbstractElement from '../tokens/abstract-element'; | ||
declare type TargetElement = MLDOMAbstractElement<any, any>; | ||
export declare function matchSelector(el: TargetElement, selector: string | RegexSelector | undefined): SelectorMatches; | ||
export declare function matchSelector(el: TargetElement, selector: string | RegexSelector | undefined, tagNameCaseSensitive?: boolean): SelectorMatches; | ||
export {}; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const selector_1 = require("./selector"); | ||
function matchSelector(el, selector) { | ||
function matchSelector(el, selector, tagNameCaseSensitive) { | ||
if (!selector) { | ||
@@ -14,3 +14,3 @@ return { | ||
if (typeof selector === 'string') { | ||
const sel = (0, selector_1.createSelector)(selector); | ||
const sel = (0, selector_1.createSelector)(selector, tagNameCaseSensitive); | ||
const specificity = sel.match(el); | ||
@@ -17,0 +17,0 @@ if (specificity) { |
import type MLDOMAbstractElement from '../tokens/abstract-element'; | ||
export declare type Specificity = [number, number, number]; | ||
export declare function createSelector(selector: string): Selector; | ||
export declare function createSelector(selector: string, tagNameCaseSensitive?: boolean): Selector; | ||
export declare function compareSpecificity(a: Specificity, b: Specificity): 0 | 1 | -1; | ||
@@ -8,5 +8,5 @@ declare type TargetElement = MLDOMAbstractElement<any, any>; | ||
#private; | ||
constructor(selector: string); | ||
constructor(selector: string, tagNameCaseSensitive: boolean); | ||
match(el: TargetElement, caller?: TargetElement | null): Specificity | false; | ||
} | ||
export {}; |
"use strict"; | ||
var _Selector_ruleset, _Ruleset_selectorGroup, _StructuredSelector_edge, _StructuredSelector_selector, _SelectorTarget_isAdded, _SelectorTarget_combinatedFrom; | ||
var _Selector_ruleset, _Ruleset_selectorGroup, _StructuredSelector_edge, _StructuredSelector_selector, _SelectorTarget_tagNameCaseSensitive, _SelectorTarget_isAdded, _SelectorTarget_combinatedFrom; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -10,4 +10,4 @@ exports.compareSpecificity = exports.createSelector = void 0; | ||
const resLog = log.extend('result'); | ||
function createSelector(selector) { | ||
return new Selector(selector); | ||
function createSelector(selector, tagNameCaseSensitive) { | ||
return new Selector(selector, !!tagNameCaseSensitive); | ||
} | ||
@@ -38,5 +38,5 @@ exports.createSelector = createSelector; | ||
class Selector { | ||
constructor(selector) { | ||
constructor(selector, tagNameCaseSensitive) { | ||
_Selector_ruleset.set(this, void 0); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Selector_ruleset, Ruleset.parse(selector), "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Selector_ruleset, Ruleset.parse(selector, tagNameCaseSensitive), "f"); | ||
} | ||
@@ -55,7 +55,7 @@ match(el, caller = el) { | ||
class Ruleset { | ||
constructor(selectors) { | ||
constructor(selectors, tagNameCaseSensitive) { | ||
_Ruleset_selectorGroup.set(this, []); | ||
(0, tslib_1.__classPrivateFieldGet)(this, _Ruleset_selectorGroup, "f").push(...selectors.map(selector => new StructuredSelector(selector))); | ||
(0, tslib_1.__classPrivateFieldGet)(this, _Ruleset_selectorGroup, "f").push(...selectors.map(selector => new StructuredSelector(selector, tagNameCaseSensitive))); | ||
} | ||
static parse(selector) { | ||
static parse(selector, tagNameCaseSensitive) { | ||
const selectors = []; | ||
@@ -65,3 +65,3 @@ (0, postcss_selector_parser_1.default)(root => { | ||
}).processSync(selector); | ||
return new Ruleset(selectors); | ||
return new Ruleset(selectors, tagNameCaseSensitive); | ||
} | ||
@@ -79,11 +79,11 @@ match(el, caller) { | ||
class StructuredSelector { | ||
constructor(selector) { | ||
constructor(selector, tagNameCaseSensitive) { | ||
_StructuredSelector_edge.set(this, void 0); | ||
_StructuredSelector_selector.set(this, void 0); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _StructuredSelector_selector, selector, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _StructuredSelector_edge, new SelectorTarget(), "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _StructuredSelector_edge, new SelectorTarget(tagNameCaseSensitive), "f"); | ||
(0, tslib_1.__classPrivateFieldGet)(this, _StructuredSelector_selector, "f").nodes.forEach(node => { | ||
switch (node.type) { | ||
case 'combinator': { | ||
const combinatedTarget = new SelectorTarget(); | ||
const combinatedTarget = new SelectorTarget(tagNameCaseSensitive); | ||
combinatedTarget.from((0, tslib_1.__classPrivateFieldGet)(this, _StructuredSelector_edge, "f"), node); | ||
@@ -118,3 +118,3 @@ (0, tslib_1.__classPrivateFieldSet)(this, _StructuredSelector_edge, combinatedTarget, "f"); | ||
class SelectorTarget { | ||
constructor() { | ||
constructor(tagNameCaseSensitive) { | ||
this.tag = null; | ||
@@ -125,4 +125,6 @@ this.id = []; | ||
this.pseudo = []; | ||
_SelectorTarget_tagNameCaseSensitive.set(this, void 0); | ||
_SelectorTarget_isAdded.set(this, false); | ||
_SelectorTarget_combinatedFrom.set(this, null); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _SelectorTarget_tagNameCaseSensitive, tagNameCaseSensitive, "f"); | ||
} | ||
@@ -278,3 +280,3 @@ match(el, caller) { | ||
for (const pseudo of this.pseudo) { | ||
const pseudoRes = pseudoMatch(pseudo, el, caller); | ||
const pseudoRes = pseudoMatch(pseudo, el, caller, (0, tslib_1.__classPrivateFieldGet)(this, _SelectorTarget_tagNameCaseSensitive, "f")); | ||
specificity[0] += pseudoRes.specificity[0]; | ||
@@ -289,3 +291,9 @@ specificity[1] += pseudoRes.specificity[1]; | ||
specificity[2] += 1; | ||
if (this.tag.value.toLowerCase() !== el.nodeName.toLowerCase()) { | ||
let a = this.tag.value; | ||
let b = el.nodeName; | ||
if (!(0, tslib_1.__classPrivateFieldGet)(this, _SelectorTarget_tagNameCaseSensitive, "f")) { | ||
a = a.toLowerCase(); | ||
b = b.toLowerCase(); | ||
} | ||
if (a !== b) { | ||
matched = false; | ||
@@ -329,3 +337,3 @@ } | ||
} | ||
_SelectorTarget_isAdded = new WeakMap(), _SelectorTarget_combinatedFrom = new WeakMap(); | ||
_SelectorTarget_tagNameCaseSensitive = new WeakMap(), _SelectorTarget_isAdded = new WeakMap(), _SelectorTarget_combinatedFrom = new WeakMap(); | ||
function attrMatch(attr, el) { | ||
@@ -385,3 +393,3 @@ return el.attributes.some(attrOfEl => { | ||
} | ||
function pseudoMatch(pseudo, el, caller) { | ||
function pseudoMatch(pseudo, el, caller, tagNameCaseSensitive) { | ||
switch (pseudo.value) { | ||
@@ -392,3 +400,3 @@ /** | ||
case ':closest': { | ||
const ruleset = new Ruleset(pseudo.nodes); | ||
const ruleset = new Ruleset(pseudo.nodes, tagNameCaseSensitive); | ||
const specificity = getSpecificity(ruleset.match(el, caller)); | ||
@@ -414,3 +422,3 @@ let parent = el.getParentElement(); | ||
case ':not': { | ||
const ruleset = new Ruleset(pseudo.nodes); | ||
const ruleset = new Ruleset(pseudo.nodes, tagNameCaseSensitive); | ||
const resList = ruleset.match(el, caller); | ||
@@ -425,3 +433,3 @@ const specificity = getSpecificity(resList); | ||
case ':is': { | ||
const ruleset = new Ruleset(pseudo.nodes); | ||
const ruleset = new Ruleset(pseudo.nodes, tagNameCaseSensitive); | ||
const resList = ruleset.match(el, caller); | ||
@@ -436,3 +444,3 @@ const specificity = getSpecificity(resList); | ||
case ':has': { | ||
const ruleset = new Ruleset(pseudo.nodes); | ||
const ruleset = new Ruleset(pseudo.nodes, tagNameCaseSensitive); | ||
const specificity = getSpecificity(ruleset.match(el, caller)); | ||
@@ -447,3 +455,3 @@ const descendants = getDescendants(el); | ||
case ':where': { | ||
const ruleset = new Ruleset(pseudo.nodes); | ||
const ruleset = new Ruleset(pseudo.nodes, tagNameCaseSensitive); | ||
const resList = ruleset.match(el, caller); | ||
@@ -450,0 +458,0 @@ const matched = resList.some(r => r.matched); |
@@ -27,2 +27,5 @@ { | ||
"disallowed": true | ||
}, | ||
"tabindex": { | ||
"enum": ["-1", "0"] | ||
} | ||
@@ -133,8 +136,11 @@ } | ||
"rules": { | ||
"required-attr": [ | ||
{ | ||
"name": "rel", | ||
"value": "noreferrer" | ||
} | ||
] | ||
"required-attr": { | ||
"value": [ | ||
{ | ||
"name": "rel", | ||
"value": "/(?<![^\\s]+)noreferrer(?![^\\s]+)/" | ||
} | ||
], | ||
"reason": "The \"rel\" attribute should be required with \"noreferrer\" if the \"a\" element has the \"target=_black\"" | ||
} | ||
} | ||
@@ -141,0 +147,0 @@ }, |
{ | ||
"name": "@markuplint/ml-core", | ||
"version": "2.0.0-rc.3", | ||
"version": "2.0.0-rc.5", | ||
"description": "The core module of markuplint", | ||
@@ -20,6 +20,6 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
"dependencies": { | ||
"@markuplint/i18n": "2.0.0-rc.3", | ||
"@markuplint/ml-ast": "2.0.0-rc.3", | ||
"@markuplint/ml-config": "2.0.0-rc.3", | ||
"@markuplint/ml-spec": "2.0.0-rc.3", | ||
"@markuplint/i18n": "2.0.0-rc.4", | ||
"@markuplint/ml-ast": "2.0.0-rc.5", | ||
"@markuplint/ml-config": "2.0.0-rc.5", | ||
"@markuplint/ml-spec": "2.0.0-rc.5", | ||
"debug": "^4.3.2", | ||
@@ -30,6 +30,6 @@ "postcss-selector-parser": "^6.0.6", | ||
"devDependencies": { | ||
"@markuplint/html-parser": "2.0.0-rc.3", | ||
"@markuplint/html-parser": "2.0.0-rc.5", | ||
"@types/debug": "^4.1.7" | ||
}, | ||
"gitHead": "fd98dfe75d24c63190f0fd578ef2633ff638e6ab" | ||
"gitHead": "6faa4e54f16d3700d23953330abea89ccb9d6150" | ||
} |
Sorry, the diff of this file is not supported yet
3464
194457
+ Added@markuplint/i18n@2.0.0-rc.4(transitive)
+ Added@markuplint/ml-ast@2.0.0-rc.5(transitive)
+ Added@markuplint/ml-config@2.0.0-rc.5(transitive)
+ Added@markuplint/ml-spec@2.0.0-rc.5(transitive)
- Removed@markuplint/i18n@2.0.0-rc.3(transitive)
- Removed@markuplint/ml-ast@2.0.0-rc.3(transitive)
- Removed@markuplint/ml-config@2.0.0-rc.3(transitive)
- Removed@markuplint/ml-spec@2.0.0-rc.3(transitive)
Updated@markuplint/i18n@2.0.0-rc.4