@markuplint/ml-core
Advanced tools
Comparing version 4.0.0-dev.28 to 4.0.0-rc.0
export async function getPreset(name) { | ||
const res = await fetch(`@markuplint/config-presets/preset.${name}.json`).catch(() => | ||
// eslint-disable-next-line unicorn/error-message | ||
new Error()); | ||
if (res instanceof Error) { | ||
throw new ReferenceError(`Preset markuplint:${name} is not found`); | ||
} | ||
const json = await res.json(); | ||
return json; | ||
const res = await fetch(`@markuplint/config-presets/preset.${name}.json`).catch( | ||
() => | ||
// eslint-disable-next-line unicorn/error-message | ||
new Error(), | ||
); | ||
if (res instanceof Error) { | ||
throw new ReferenceError(`Preset markuplint:${name} is not found`); | ||
} | ||
const json = await res.json(); | ||
return json; | ||
} |
import type { Config } from '@markuplint/ml-config'; | ||
import Ruleset from './ruleset/index.js'; | ||
import { Ruleset } from './ruleset/index.js'; | ||
export declare function convertRuleset(config?: Config): Ruleset; |
@@ -1,4 +0,4 @@ | ||
import Ruleset from './ruleset/index.js'; | ||
import { Ruleset } from './ruleset/index.js'; | ||
export function convertRuleset(config = {}) { | ||
return new Ruleset(config); | ||
} |
export { RuleInfo, RuleConfig, RuleConfigValue } from '@markuplint/ml-config'; | ||
export { ariaSpecs, contentModelCategoryToTagNames, getAttrSpecs, getComputedRole, getImplicitRole, getPermittedRoles, getRoleSpec, getSpec, resolveNamespace, } from '@markuplint/ml-spec'; | ||
export { default as Ruleset } from './ruleset/index.js'; | ||
export { Ruleset } from './ruleset/index.js'; | ||
export { enableDebug } from './debug.js'; | ||
export { getIndent } from './ml-dom/helper/get-indent.js'; | ||
export * from './configs.js'; | ||
export * from './convert-ruleset.js'; | ||
@@ -8,0 +7,0 @@ export * from './ml-core.js'; |
export { ariaSpecs, contentModelCategoryToTagNames, getAttrSpecs, getComputedRole, getImplicitRole, getPermittedRoles, getRoleSpec, getSpec, resolveNamespace, } from '@markuplint/ml-spec'; | ||
export { default as Ruleset } from './ruleset/index.js'; | ||
export { Ruleset } from './ruleset/index.js'; | ||
export { enableDebug } from './debug.js'; | ||
export { getIndent } from './ml-dom/helper/get-indent.js'; | ||
export * from './configs.js'; | ||
export * from './convert-ruleset.js'; | ||
@@ -7,0 +6,0 @@ export * from './ml-core.js'; |
@@ -13,3 +13,3 @@ import type { MLFabric } from './types.js'; | ||
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, configErrors, }: MLCoreParams); | ||
get document(): ParserError | Document<RuleConfigValue, PlainData>; | ||
get document(): Document<RuleConfigValue, PlainData> | ParserError; | ||
setCode(sourceCode: string): void; | ||
@@ -16,0 +16,0 @@ update({ parser, ruleset, rules, locale, schemas, parserOptions, configErrors }: Partial<MLFabric>): void; |
import type { MLDocument } from '../node/document.js'; | ||
import type { MappedNode } from '../node/types.js'; | ||
import type { MLASTAbstractNode } from '@markuplint/ml-ast'; | ||
import type { MLASTNode } from '@markuplint/ml-ast'; | ||
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config'; | ||
export declare function createNode<N extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: N, document: MLDocument<T, O>): MappedNode<N, T, O>; | ||
export declare function createNode<N extends MLASTNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: N, document: MLDocument<T, O>): MappedNode<N, T, O>; |
@@ -9,21 +9,46 @@ import { MLBlock } from '../node/block.js'; | ||
document) { | ||
const _astNode = astNode; | ||
switch (_astNode.type) { | ||
switch (astNode.type) { | ||
case 'doctype': { | ||
return new MLDocumentType(_astNode, document); | ||
return new MLDocumentType(astNode, document); | ||
} | ||
case 'starttag': { | ||
return new MLElement(_astNode, document); | ||
return new MLElement(astNode, document); | ||
} | ||
case 'psblock': { | ||
return new MLBlock(_astNode, document); | ||
return new MLBlock(astNode, document); | ||
} | ||
case 'comment': { | ||
return new MLComment(_astNode, document); | ||
return new MLComment(astNode, document); | ||
} | ||
case 'text': { | ||
return new MLText(_astNode, document); | ||
return new MLText(astNode, document); | ||
} | ||
case 'invalid': { | ||
switch (astNode.kind) { | ||
case 'starttag': { | ||
return new MLElement({ | ||
...astNode, | ||
type: 'starttag', | ||
nodeName: 'x-invalid', | ||
namespace: 'http://www.w3.org/1999/xhtml', | ||
elementType: 'web-component', | ||
attributes: [], | ||
childNodes: [], | ||
pairNode: null, | ||
tagOpenChar: '', | ||
tagCloseChar: '', | ||
isGhost: false, | ||
}, document); | ||
} | ||
default: { | ||
return new MLText({ | ||
...astNode, | ||
type: 'text', | ||
nodeName: '#text', | ||
}, document); | ||
} | ||
} | ||
} | ||
} | ||
throw new TypeError(`Invalid AST node types "${astNode.type}"`); | ||
} |
@@ -29,3 +29,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
} | ||
const matched = node.raw.match(/^(\s*(?:\r?\n)+\s*)\S+/); | ||
const matched = node.raw.match(/^([\t\v\f\r \u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*\n\s*)\S+/); | ||
if (matched) { | ||
@@ -32,0 +32,0 @@ const spaces = matched[1]; |
@@ -1,2 +0,2 @@ | ||
import UnexpectedCallError from '../node/unexpected-call-error.js'; | ||
import { UnexpectedCallError } from '../node/unexpected-call-error.js'; | ||
/** | ||
@@ -3,0 +3,0 @@ * |
@@ -95,5 +95,23 @@ import type { MLElement } from './element.js'; | ||
/** | ||
* Fixes the attribute value. | ||
* If the attribute is not a spread attribute, it calls the `fix` method of the `valueNode`. | ||
* | ||
* @implements `@markuplint/ml-core` API: `MLAttr` | ||
* | ||
* @param raw - The raw attribute value. | ||
*/ | ||
fix(raw: string): void; | ||
/** | ||
* @implements `@markuplint/ml-core` API: `MLAttr` | ||
*/ | ||
toNormalizeString(): string; | ||
/** | ||
* Returns a string representation of the attribute. | ||
* | ||
* @implements DOM API: `Attr` | ||
* | ||
* @param includesSpacesBeforeName - Whether to include spaces before the attribute name. | ||
* @returns The string representation of the attribute. | ||
*/ | ||
toString(fixed?: boolean): string; | ||
} |
@@ -17,8 +17,6 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
import { MLNode } from './node.js'; | ||
import UnexpectedCallError from './unexpected-call-error.js'; | ||
import { UnexpectedCallError } from './unexpected-call-error.js'; | ||
export class MLAttr extends MLNode { | ||
constructor( | ||
constructor(astToken, | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
astToken, | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
ownElement) { | ||
@@ -45,28 +43,31 @@ super(astToken, ownElement.ownerMLDocument); | ||
this.valueType = 'string'; | ||
if (this._astToken.type === 'html-attr') { | ||
this.spacesBeforeName = new MLToken(this._astToken.spacesBeforeName); | ||
this.nameNode = new MLToken(this._astToken.name); | ||
this.spacesBeforeEqual = new MLToken(this._astToken.spacesBeforeEqual); | ||
this.equal = new MLToken(this._astToken.equal); | ||
this.spacesAfterEqual = new MLToken(this._astToken.spacesAfterEqual); | ||
this.startQuote = new MLToken(this._astToken.startQuote); | ||
this.valueNode = new MLToken(this._astToken.value); | ||
this.endQuote = new MLToken(this._astToken.endQuote); | ||
this.isDynamicValue = this._astToken.isDynamicValue; | ||
this.isDirective = this._astToken.isDirective; | ||
this.candidate = this._astToken.candidate; | ||
__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName ?? this.nameNode?.raw ?? '', "f"); | ||
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.value.raw ?? '', "f"); | ||
this.ownerElement = ownElement; | ||
if (this._astToken.type === 'spread') { | ||
__classPrivateFieldSet(this, _MLAttr_namespaceURI, ownElement.namespaceURI, "f"); | ||
this.valueType = 'code'; | ||
__classPrivateFieldSet(this, _MLAttr_localName, '#spread', "f"); | ||
__classPrivateFieldSet(this, _MLAttr_potentialName, '#spread', "f"); | ||
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.raw, "f"); | ||
this.isDirective = true; | ||
this.isDynamicValue = true; | ||
this.isDuplicatable = true; | ||
return; | ||
} | ||
else { | ||
this.valueType = this._astToken.valueType; | ||
this.isDuplicatable = this._astToken.isDuplicatable; | ||
__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName, "f"); | ||
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.potentialValue, "f"); | ||
} | ||
this.spacesBeforeName = new MLToken(this._astToken.spacesBeforeName); | ||
this.nameNode = new MLToken(this._astToken.name); | ||
this.spacesBeforeEqual = new MLToken(this._astToken.spacesBeforeEqual); | ||
this.equal = new MLToken(this._astToken.equal); | ||
this.spacesAfterEqual = new MLToken(this._astToken.spacesAfterEqual); | ||
this.startQuote = new MLToken(this._astToken.startQuote); | ||
this.valueNode = new MLToken(this._astToken.value); | ||
this.endQuote = new MLToken(this._astToken.endQuote); | ||
this.isDynamicValue = this._astToken.isDynamicValue; | ||
this.isDirective = this._astToken.isDirective; | ||
this.candidate = this._astToken.candidate; | ||
__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName ?? this.nameNode?.raw ?? '', "f"); | ||
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.potentialValue ?? this.valueNode?.raw ?? '', "f"); | ||
this.isDuplicatable = this._astToken.isDuplicatable; | ||
const ns = resolveNamespace(__classPrivateFieldGet(this, _MLAttr_potentialName, "f"), ownElement.namespaceURI); | ||
__classPrivateFieldSet(this, _MLAttr_localName, ns.localName, "f"); | ||
__classPrivateFieldSet(this, _MLAttr_namespaceURI, ns.namespaceURI, "f"); | ||
this.ownerElement = ownElement; | ||
this.isDuplicatable = this._astToken.isDuplicatable; | ||
} | ||
@@ -155,15 +156,52 @@ /** | ||
/** | ||
* Fixes the attribute value. | ||
* If the attribute is not a spread attribute, it calls the `fix` method of the `valueNode`. | ||
* | ||
* @implements `@markuplint/ml-core` API: `MLAttr` | ||
* | ||
* @param raw - The raw attribute value. | ||
*/ | ||
fix(raw) { | ||
if (this.localName === '#spread') { | ||
return; | ||
} | ||
// `valueNode` is not null when it is no spread. | ||
this.valueNode?.fix(raw); | ||
} | ||
/** | ||
* @implements `@markuplint/ml-core` API: `MLAttr` | ||
*/ | ||
toNormalizeString() { | ||
if (this.nameNode && this.equal && this.startQuote && this.valueNode && this.endQuote) { | ||
return (this.nameNode.originRaw + | ||
this.equal.originRaw + | ||
this.startQuote.originRaw + | ||
this.valueNode.originRaw + | ||
this.endQuote.originRaw); | ||
return this.nameNode.raw + this.equal.raw + this.startQuote.raw + this.valueNode.raw + this.endQuote.raw; | ||
} | ||
return this.raw; | ||
} | ||
/** | ||
* Returns a string representation of the attribute. | ||
* | ||
* @implements DOM API: `Attr` | ||
* | ||
* @param includesSpacesBeforeName - Whether to include spaces before the attribute name. | ||
* @returns The string representation of the attribute. | ||
*/ | ||
toString(fixed = false) { | ||
if (!fixed) { | ||
return this.raw; | ||
} | ||
if (this.localName === '#spread') { | ||
return this.raw; | ||
} | ||
const tokens = [this.nameNode?.toString(true) ?? '']; | ||
if (this.equal && this.equal.toString(true) !== '') { | ||
tokens.push(this.spacesBeforeEqual?.toString(true) ?? '', this.equal?.toString(true) ?? '', this.spacesAfterEqual?.toString(true) ?? '', this.startQuote?.toString(true) ?? '', this.valueNode?.toString(true) ?? '', this.endQuote?.toString(true) ?? ''); | ||
} | ||
else if (this.valueNode && this.valueNode.toString(true) !== '') { | ||
tokens.push( | ||
// | ||
'=', this.startQuote?.toString(true) || '"', this.valueNode.toString(true), this.endQuote?.toString(true) || '"'); | ||
} | ||
return tokens.join(''); | ||
} | ||
} | ||
_MLAttr_localName = new WeakMap(), _MLAttr_namespaceURI = new WeakMap(), _MLAttr_potentialName = new WeakMap(), _MLAttr_potentialValue = new WeakMap(); |
import { after, before, remove, replaceWith } from '../manipulations/child-node-methods.js'; | ||
import { MLNode } from './node.js'; | ||
export class MLBlock extends MLNode { | ||
constructor( | ||
constructor(astNode, | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
astNode, | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
document) { | ||
@@ -9,0 +7,0 @@ super(astNode, document); |
import type { MLElement } from './element.js'; | ||
import type { MLASTAbstractNode } from '@markuplint/ml-ast'; | ||
import type { MLASTNode } from '@markuplint/ml-ast'; | ||
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config'; | ||
import { MLNode } from './node.js'; | ||
export declare abstract class MLCharacterData<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTAbstractNode = MLASTAbstractNode> extends MLNode<T, O, A> implements CharacterData { | ||
export declare abstract class MLCharacterData<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTNode = MLASTNode> extends MLNode<T, O, A> implements CharacterData { | ||
/** | ||
@@ -7,0 +7,0 @@ * @implements DOM API: `CharacterData` |
import { after, before, nextElementSibling, previousElementSibling, remove, replaceWith, } from '../manipulations/child-node-methods.js'; | ||
import { MLNode } from './node.js'; | ||
import UnexpectedCallError from './unexpected-call-error.js'; | ||
import { UnexpectedCallError } from './unexpected-call-error.js'; | ||
export class MLCharacterData extends MLNode { | ||
@@ -5,0 +5,0 @@ /** |
import type { MLBlock } from './block.js'; | ||
import type { MLCharacterData } from './character-data.js'; | ||
import type { MLDocumentType } from './document-type.js'; | ||
import type { MLComment } from './comment.js'; | ||
import type { MLElement } from './element.js'; | ||
@@ -8,3 +8,3 @@ import type { MLNode } from './node.js'; | ||
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config'; | ||
export type MLChildNode<T extends RuleConfigValue, O extends PlainData = undefined> = MLDocumentType<T, O> | MLCharacterData<T, O> | MLText<T, O> | MLElement<T, O> | MLBlock<T, O>; | ||
export type MLChildNode<T extends RuleConfigValue, O extends PlainData = undefined> = MLCharacterData<T, O> | MLComment<T, O> | MLText<T, O> | MLElement<T, O> | MLBlock<T, O>; | ||
export declare function isChildNode<T extends RuleConfigValue, O extends PlainData = undefined>(node: MLNode<T, O>): node is MLChildNode<T, O>; |
import type { DocumentFragmentNodeType } from './types.js'; | ||
import type { MLASTAbstractNode } from '@markuplint/ml-ast'; | ||
import type { MLASTNode } from '@markuplint/ml-ast'; | ||
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config'; | ||
import { MLParentNode } from './parent-node.js'; | ||
export declare class MLDocumentFragment<T extends RuleConfigValue, O extends PlainData = undefined> extends MLParentNode<T, O, MLASTAbstractNode> implements DocumentFragment { | ||
export declare class MLDocumentFragment<T extends RuleConfigValue, O extends PlainData = undefined> extends MLParentNode<T, O, MLASTNode> implements DocumentFragment { | ||
/** | ||
@@ -7,0 +7,0 @@ * Returns a string appropriate for the type of node as `DocumentFragment` |
import { MLParentNode } from './parent-node.js'; | ||
import UnexpectedCallError from './unexpected-call-error.js'; | ||
import { UnexpectedCallError } from './unexpected-call-error.js'; | ||
export class MLDocumentFragment extends MLParentNode { | ||
@@ -4,0 +4,0 @@ /** |
import { after, before, remove, replaceWith } from '../manipulations/child-node-methods.js'; | ||
import { MLNode } from './node.js'; | ||
export class MLDocumentType extends MLNode { | ||
constructor( | ||
constructor(astNode, | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
astNode, | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
document) { | ||
@@ -9,0 +7,0 @@ super(astNode, document); |
@@ -9,3 +9,3 @@ import type { MLAttr } from './attr.js'; | ||
import type { MLRule } from '../../ml-rule/index.js'; | ||
import type Ruleset from '../../ruleset/index.js'; | ||
import type { Ruleset } from '../../ruleset/index.js'; | ||
import type { MLSchema } from '../../types.js'; | ||
@@ -1483,3 +1483,3 @@ import type { Walker } from '../helper/walkers.js'; | ||
*/ | ||
getTokenList(): readonly MLToken<import("@markuplint/ml-ast").MLToken>[]; | ||
getTokenList(): readonly MLToken<import("@markuplint/ml-ast").MLASTToken>[]; | ||
/** | ||
@@ -1571,3 +1571,3 @@ * **IT THROWS AN ERROR WHEN CALLING THIS.** | ||
*/ | ||
searchNodeByLocation(line: number, col: number): MLNode<T, O, import("@markuplint/ml-ast").MLASTAbstractNode> | null; | ||
searchNodeByLocation(line: number, col: number): MLNode<T, O, import("@markuplint/ml-ast").MLASTNode> | null; | ||
/** | ||
@@ -1580,3 +1580,3 @@ * @implements `@markuplint/ml-core` API: `MLDocument` | ||
*/ | ||
toString(): string; | ||
toString(fixed?: boolean): string; | ||
/** | ||
@@ -1583,0 +1583,0 @@ * @implements `@markuplint/ml-core` API: `MLDocument` |
@@ -13,4 +13,4 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _MLDomTokenList_origin, _MLDomTokenList_ownerAttrs, _MLDomTokenList_set; | ||
import { getCol, getLine } from '@markuplint/parser-utils'; | ||
import UnexpectedCallError from './unexpected-call-error.js'; | ||
import { getCol, getLine } from '@markuplint/parser-utils/location'; | ||
import { UnexpectedCallError } from './unexpected-call-error.js'; | ||
export class MLDomTokenList extends Array { | ||
@@ -118,3 +118,3 @@ constructor(tokens, | ||
_pick(token, _offset = 0) { | ||
token = token.trim().split(/\s+/g)[0] ?? ''; | ||
token = token.trim().split(/\s+/)[0] ?? ''; | ||
if (!token) { | ||
@@ -121,0 +121,0 @@ return null; |
@@ -11,9 +11,15 @@ import type { MLDocument } from './document.js'; | ||
import { MLDomTokenList } from './dom-token-list.js'; | ||
import { MLElementCloseTag } from './element-close-tag.js'; | ||
import { MLParentNode } from './parent-node.js'; | ||
export declare class MLElement<T extends RuleConfigValue, O extends PlainData = undefined> extends MLParentNode<T, O, MLASTElement> implements Element, HTMLOrSVGElement, HTMLElement { | ||
#private; | ||
readonly closeTag: MLToken | null; | ||
readonly closeTag: MLElementCloseTag<T, O> | null; | ||
/** | ||
* Element type | ||
* | ||
* - `html`: From native HTML Standard | ||
* - `web-component`: As the Web Component according to HTML Standard | ||
* - `authored`: Authored element (JSX Element etc.) through the view framework or the template engine. | ||
*/ | ||
readonly elementType: ElementType; | ||
readonly endSpace: MLToken | null; | ||
readonly hasSpreadAttr: boolean; | ||
readonly isForeignElement: boolean; | ||
@@ -28,2 +34,4 @@ readonly isOmitted: boolean; | ||
readonly selfClosingSolidus: MLToken | null; | ||
readonly tagCloseChar: string; | ||
readonly tagOpenChar: string; | ||
constructor(astNode: MLASTElement, document: MLDocument<T, O>); | ||
@@ -474,2 +482,3 @@ /** | ||
get fixedNodeName(): string; | ||
get hasSpreadAttr(): boolean; | ||
/** | ||
@@ -1404,3 +1413,2 @@ * **IT THROWS AN ERROR WHEN CALLING THIS.** | ||
get previousElementSibling(): MLElement<T, O> | null; | ||
get raw(): string; | ||
/** | ||
@@ -1788,3 +1796,3 @@ * @implements `@markuplint/ml-core` API: `MLElement` | ||
*/ | ||
pretending(pretenders: readonly Pretender[]): void; | ||
pretending(pretenders?: readonly Pretender[]): void; | ||
/** | ||
@@ -1933,3 +1941,3 @@ * **IT THROWS AN ERROR WHEN CALLING THIS.** | ||
*/ | ||
toString(): string; | ||
toString(fixed?: boolean): string; | ||
/** | ||
@@ -1936,0 +1944,0 @@ * **IT THROWS AN ERROR WHEN CALLING THIS.** |
@@ -1,2 +0,2 @@ | ||
import UnexpectedCallError from './unexpected-call-error.js'; | ||
import { UnexpectedCallError } from './unexpected-call-error.js'; | ||
export class MLNamedNodeMap extends Array { | ||
@@ -3,0 +3,0 @@ getNamedItem(qualifiedName) { |
import type { MLNode } from './node.js'; | ||
import type { MappedNode } from './types.js'; | ||
import type { MLASTAbstractNode } from '@markuplint/ml-ast'; | ||
import type { MLASTNode } from '@markuplint/ml-ast'; | ||
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config'; | ||
declare class NodeStore { | ||
#private; | ||
getNode<N extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: N): MappedNode<N, T, O>; | ||
setNode<A extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: A, node: MLNode<T, O, A>): void; | ||
getNode<N extends MLASTNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: N): MappedNode<N, T, O>; | ||
setNode<A extends MLASTNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: A, node: MLNode<T, O, A>): void; | ||
} | ||
@@ -10,0 +10,0 @@ /** |
@@ -8,6 +8,6 @@ import type { MLBlock } from './block.js'; | ||
import type { RuleInfo } from '../../index.js'; | ||
import type { MLASTAbstractNode } from '@markuplint/ml-ast'; | ||
import type { MLASTNode } from '@markuplint/ml-ast'; | ||
import type { AnyRule, PlainData, RuleConfigValue } from '@markuplint/ml-config'; | ||
import { MLToken } from '../token/token.js'; | ||
export declare abstract class MLNode<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTAbstractNode = MLASTAbstractNode> extends MLToken<A> implements Node { | ||
export declare abstract class MLNode<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTNode = MLASTNode> extends MLToken<A> implements Node { | ||
#private; | ||
@@ -14,0 +14,0 @@ /** |
@@ -17,3 +17,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
import { nodeStore } from './node-store.js'; | ||
import UnexpectedCallError from './unexpected-call-error.js'; | ||
import { UnexpectedCallError } from './unexpected-call-error.js'; | ||
export class MLNode extends MLToken { | ||
@@ -179,7 +179,13 @@ constructor(astNode, | ||
this.is(this.MARKUPLINT_PREPROCESSOR_BLOCK)) { | ||
const astChildren = | ||
// @ts-ignore | ||
const astChildren = this._astToken.childNodes ?? []; | ||
this._astToken?.childNodes?.filter(node => { | ||
if (node.type === 'endtag' || node.type === 'invalid') { | ||
return null; | ||
} | ||
return node; | ||
}) ?? []; | ||
const childNodes = astChildren | ||
.map(node => nodeStore.getNode(node)) | ||
.filter((node) => isChildNode(node)); | ||
.filter(node => isChildNode(node)); | ||
// Cache | ||
@@ -228,6 +234,5 @@ __classPrivateFieldSet(this, _MLNode_childNodes, toNodeList(childNodes), "f"); | ||
get nextNode() { | ||
if (!this._astToken.nextNode) { | ||
return null; | ||
} | ||
return nodeStore.getNode(this._astToken.nextNode); | ||
const siblings = [...(this.syntacticalParentNode?.childNodes ?? __classPrivateFieldGet(this, _MLNode_ownerDocument, "f").nodeList)]; | ||
const index = siblings.findIndex(node => node.uuid === this.uuid); | ||
return siblings[index + 1] ?? null; | ||
} | ||
@@ -374,6 +379,5 @@ /** | ||
get prevNode() { | ||
if (!this._astToken.prevNode) { | ||
return null; | ||
} | ||
return nodeStore.getNode(this._astToken.prevNode); | ||
const siblings = [...(this.syntacticalParentNode?.childNodes ?? __classPrivateFieldGet(this, _MLNode_ownerDocument, "f").nodeList)]; | ||
const index = siblings.findIndex(node => node.uuid === this.uuid); | ||
return siblings[index - 1] ?? null; | ||
} | ||
@@ -473,2 +477,5 @@ /** | ||
get syntacticalParentNode() { | ||
if (this._astToken.type === 'attr' || this._astToken.type === 'spread') { | ||
return null; | ||
} | ||
if (!this._astToken.parentNode) { | ||
@@ -475,0 +482,0 @@ return this.ownerMLDocument; |
import type { MLElement } from './element.js'; | ||
import type { MLASTAbstractNode } from '@markuplint/ml-ast'; | ||
import type { MLASTNode } from '@markuplint/ml-ast'; | ||
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config'; | ||
@@ -9,3 +9,3 @@ import { MLNode } from './node.js'; | ||
*/ | ||
export declare abstract class MLParentNode<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTAbstractNode = MLASTAbstractNode> extends MLNode<T, O, A> implements ParentNode { | ||
export declare abstract class MLParentNode<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTNode = MLASTNode> extends MLNode<T, O, A> implements ParentNode { | ||
#private; | ||
@@ -12,0 +12,0 @@ /** |
@@ -17,3 +17,3 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
import { MLNode } from './node.js'; | ||
import UnexpectedCallError from './unexpected-call-error.js'; | ||
import { UnexpectedCallError } from './unexpected-call-error.js'; | ||
/** | ||
@@ -20,0 +20,0 @@ * |
import { MLCharacterData } from './character-data.js'; | ||
import UnexpectedCallError from './unexpected-call-error.js'; | ||
import { UnexpectedCallError } from './unexpected-call-error.js'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Raw text elements |
@@ -8,8 +8,7 @@ import type { MLAttr } from './attr.js'; | ||
import type { MLElement } from './element.js'; | ||
import type { MLNode } from './node.js'; | ||
import type { MLText } from './text.js'; | ||
import type { MLToken } from '../token/token.js'; | ||
import type { MLASTAbstractNode, MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLToken as MLASTToken } from '@markuplint/ml-ast/'; | ||
import type { MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTInvalid, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLASTToken as MLASTToken } from '@markuplint/ml-ast/'; | ||
import type { PlainData, PretenderARIA, RuleConfigValue } from '@markuplint/ml-config'; | ||
export type MappedNode<N, T extends RuleConfigValue, O extends PlainData = undefined> = N extends MLASTElement ? MLElement<T, O> : N extends MLASTParentNode ? MLElement<T, O> : N extends MLASTComment ? MLComment<T, O> : N extends MLASTText ? MLText<T, O> : N extends MLASTDoctype ? MLDocumentType<T, O> : N extends MLASTPreprocessorSpecificBlock ? MLBlock<T, O> : N extends MLASTAbstractNode ? MLNode<T, O, MLASTAbstractNode> : N extends MLASTAttr ? MLAttr<T, O> : N extends MLASTToken ? MLToken : never; | ||
export type MappedNode<N, T extends RuleConfigValue, O extends PlainData = undefined> = N extends MLASTElement ? MLElement<T, O> : N extends MLASTParentNode ? MLElement<T, O> : N extends MLASTComment ? MLComment<T, O> : N extends MLASTText ? MLText<T, O> : N extends MLASTDoctype ? MLDocumentType<T, O> : N extends MLASTPreprocessorSpecificBlock ? MLBlock<T, O> : N extends MLASTAttr ? MLAttr<T, O> : N extends MLASTInvalid ? MLText<T, O> : N extends MLASTToken ? MLToken : never; | ||
export type NodeTypeOf<NT extends NodeType, T extends RuleConfigValue, O extends PlainData = undefined> = NT extends ElementNodeType ? MLElement<T, O> : NT extends CommentNodeType ? MLComment<T, O> : NT extends TextNodeType ? MLText<T, O> : NT extends DocumentNodeType ? MLDocument<T, O> : NT extends DocumentTypeNodeType ? MLDocumentType<T, O> : NT extends DocumentFragmentNodeType ? MLDocumentFragment<T, O> : NT extends MarkuplintPreprocessorBlockType ? MLBlock<T, O> : NT extends AttributeNodeType ? MLAttr<T, O> : never; | ||
@@ -16,0 +15,0 @@ export type ElementNodeType = 1; |
@@ -1,2 +0,2 @@ | ||
export default class UnexpectedCallError extends Error { | ||
export declare class UnexpectedCallError extends Error { | ||
} |
@@ -1,2 +0,2 @@ | ||
export default class UnexpectedCallError extends Error { | ||
export class UnexpectedCallError extends Error { | ||
} |
@@ -1,2 +0,2 @@ | ||
import type { MLToken as MLASTToken } from '@markuplint/ml-ast'; | ||
import type { MLASTToken } from '@markuplint/ml-ast'; | ||
export declare class MLToken<A extends MLASTToken = MLASTToken> { | ||
@@ -22,3 +22,3 @@ #private; | ||
*/ | ||
get originRaw(): string; | ||
get fixed(): string; | ||
/** | ||
@@ -47,3 +47,3 @@ * @implements `@markuplint/ml-core` API: `MLDOMToken` | ||
*/ | ||
toString(): string; | ||
toString(fixed?: boolean): string; | ||
} |
@@ -55,4 +55,4 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
*/ | ||
get originRaw() { | ||
return __classPrivateFieldGet(this, _MLToken_raw, "f"); | ||
get fixed() { | ||
return __classPrivateFieldGet(this, _MLToken_fixed, "f"); | ||
} | ||
@@ -63,3 +63,3 @@ /** | ||
get raw() { | ||
return __classPrivateFieldGet(this, _MLToken_fixed, "f"); | ||
return __classPrivateFieldGet(this, _MLToken_raw, "f"); | ||
} | ||
@@ -93,6 +93,6 @@ /** | ||
*/ | ||
toString() { | ||
return this.raw; | ||
toString(fixed = false) { | ||
return fixed ? __classPrivateFieldGet(this, _MLToken_fixed, "f") : __classPrivateFieldGet(this, _MLToken_raw, "f"); | ||
} | ||
} | ||
_MLToken_endCol = new WeakMap(), _MLToken_endLine = new WeakMap(), _MLToken_endOffset = new WeakMap(), _MLToken_fixed = new WeakMap(), _MLToken_raw = new WeakMap(), _MLToken_startCol = new WeakMap(), _MLToken_startLine = new WeakMap(), _MLToken_startOffset = new WeakMap(); |
import type { RuleSeed } from './types.js'; | ||
import type { MLDocument } from '../ml-dom/node/document.js'; | ||
import type Ruleset from '../ruleset/index.js'; | ||
import type { Ruleset } from '../ruleset/index.js'; | ||
import type { LocaleSet } from '@markuplint/i18n'; | ||
@@ -5,0 +5,0 @@ import type { GlobalRuleInfo, PlainData, Rule, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config'; |
@@ -6,2 +6,5 @@ import type { MLRuleContext } from './ml-rule-context.js'; | ||
export type RuleSeed<T extends RuleConfigValue = boolean, O extends PlainData = undefined> = { | ||
readonly meta?: { | ||
readonly category?: 'validation' | 'style' | 'naming-convention' | 'a11y' | 'maintainability'; | ||
}; | ||
readonly defaultSeverity?: Severity; | ||
@@ -8,0 +11,0 @@ readonly defaultValue?: T; |
import type { ChildNodeRule, Config, NodeRule, Rules } from '@markuplint/ml-config'; | ||
export default class Ruleset { | ||
export declare class Ruleset { | ||
readonly childNodeRules: readonly ChildNodeRule[]; | ||
@@ -4,0 +4,0 @@ readonly nodeRules: readonly NodeRule[]; |
@@ -1,2 +0,2 @@ | ||
export default class Ruleset { | ||
export class Ruleset { | ||
constructor(config) { | ||
@@ -3,0 +3,0 @@ this.rules = config.rules ?? {}; |
@@ -1,2 +0,2 @@ | ||
import type { MLMarkupLanguageParser } from '@markuplint/ml-ast'; | ||
import type { MLParser } from '@markuplint/ml-ast'; | ||
import type { Config, PlainData, RuleConfigValue } from '@markuplint/ml-config'; | ||
@@ -7,8 +7,10 @@ import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec'; | ||
readonly config?: Config; | ||
readonly parser?: Readonly<MLMarkupLanguageParser>; | ||
readonly parser?: { | ||
readonly parser: Readonly<MLParser>; | ||
} | Readonly<MLParser>; | ||
readonly specs?: MLMLSpec; | ||
}; | ||
export declare function createTestDocument<T extends RuleConfigValue = any, O extends PlainData = any>(sourceCode: string, options?: CreateTestOptions): Document<T, O>; | ||
export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/node/node.js").MLNode<any, any, import("@markuplint/ml-ast").MLASTAbstractNode>[]; | ||
export declare function createTestTokenList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/token/token.js").MLToken<import("@markuplint/ml-ast").MLToken>[]; | ||
export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/node/node.js").MLNode<any, any, import("@markuplint/ml-ast").MLASTNode>[]; | ||
export declare function createTestTokenList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/token/token.js").MLToken<import("@markuplint/ml-ast").MLASTToken>[]; | ||
export declare function createTestElement(sourceCode: string, options?: CreateTestOptions): import("../ml-dom/index.js").Element<any, any>; | ||
@@ -15,0 +17,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { parse } from '@markuplint/html-parser'; | ||
import { parser } from '@markuplint/html-parser'; | ||
import spec from '@markuplint/html-spec'; | ||
@@ -6,3 +6,7 @@ import { convertRuleset } from '../convert-ruleset.js'; | ||
export function createTestDocument(sourceCode, options) { | ||
const ast = options?.parser ? options.parser.parse(sourceCode) : parse(sourceCode); | ||
const ast = options?.parser | ||
? 'parser' in options.parser | ||
? options.parser.parser.parse(sourceCode, options.config?.parserOptions) | ||
: options.parser.parse(sourceCode, options.config?.parserOptions) | ||
: parser.parse(sourceCode, options?.config?.parserOptions); | ||
const ruleset = convertRuleset(options?.config); | ||
@@ -9,0 +13,0 @@ const document = new Document(ast, ruleset, [options?.specs ?? {}, {}]); |
import type { AnyMLRule } from './ml-rule/index.js'; | ||
import type Ruleset from './ruleset/index.js'; | ||
import type { Ruleset } from './ruleset/index.js'; | ||
import type { LocaleSet } from '@markuplint/i18n'; | ||
import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast'; | ||
import type { MLParser, ParserOptions } from '@markuplint/ml-ast'; | ||
import type { Pretender } from '@markuplint/ml-config'; | ||
@@ -9,3 +9,3 @@ import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec'; | ||
export type MLFabric = { | ||
readonly parser: Readonly<MLMarkupLanguageParser>; | ||
readonly parser: Readonly<MLParser>; | ||
readonly ruleset: Partial<Readonly<Ruleset>>; | ||
@@ -12,0 +12,0 @@ readonly rules: readonly Readonly<AnyMLRule>[]; |
export function getLocationFromChars(searches, text, currentLine, currentCol) { | ||
const lines = text.split(/\r?\n/g); | ||
const lines = text.split(/\r?\n/); | ||
const foundLocations = []; | ||
@@ -4,0 +4,0 @@ for (const [i, lineText] of lines.entries()) { |
{ | ||
"name": "@markuplint/ml-core", | ||
"version": "4.0.0-dev.28+0131de5e", | ||
"version": "4.0.0-rc.0", | ||
"description": "The core module of markuplint", | ||
@@ -31,17 +31,17 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
"dependencies": { | ||
"@markuplint/config-presets": "4.0.0-dev.28+0131de5e", | ||
"@markuplint/html-parser": "4.0.0-dev.28+0131de5e", | ||
"@markuplint/html-spec": "4.0.0-dev.28+0131de5e", | ||
"@markuplint/i18n": "4.0.0-dev.28+0131de5e", | ||
"@markuplint/ml-ast": "4.0.0-dev.28+0131de5e", | ||
"@markuplint/ml-config": "4.0.0-dev.28+0131de5e", | ||
"@markuplint/ml-spec": "4.0.0-dev.28+0131de5e", | ||
"@markuplint/parser-utils": "4.0.0-dev.28+0131de5e", | ||
"@markuplint/selector": "4.0.0-dev.28+0131de5e", | ||
"@types/debug": "^4.1.10", | ||
"@markuplint/config-presets": "4.0.0-rc.0", | ||
"@markuplint/html-parser": "4.0.0-rc.0", | ||
"@markuplint/html-spec": "4.0.0-rc.0", | ||
"@markuplint/i18n": "4.0.0-rc.0", | ||
"@markuplint/ml-ast": "4.0.0-rc.0", | ||
"@markuplint/ml-config": "4.0.0-rc.0", | ||
"@markuplint/ml-spec": "4.0.0-rc.0", | ||
"@markuplint/parser-utils": "4.0.0-rc.0", | ||
"@markuplint/selector": "4.0.0-rc.0", | ||
"@types/debug": "^4.1.12", | ||
"debug": "^4.3.4", | ||
"is-plain-object": "^5.0.0", | ||
"type-fest": "^4.5.0" | ||
"type-fest": "^4.10.2" | ||
}, | ||
"gitHead": "0131de5ea9dd6d3fd5472d7b414b66644c758881" | ||
"gitHead": "3fdeb45cb69ed52b3a215a7520cea1181601443f" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
419451
12986
1
+ Added@markuplint/config-presets@4.0.0-rc.0(transitive)
+ Added@markuplint/html-parser@4.0.0-rc.0(transitive)
+ Added@markuplint/html-spec@4.0.0-rc.0(transitive)
+ Added@markuplint/i18n@4.0.0-rc.0(transitive)
+ Added@markuplint/ml-ast@4.0.0-rc.0(transitive)
+ Added@markuplint/ml-config@4.0.0-rc.0(transitive)
+ Added@markuplint/ml-spec@4.0.0-rc.0(transitive)
+ Added@markuplint/parser-utils@4.0.0-rc.0(transitive)
+ Added@markuplint/selector@4.0.0-rc.0(transitive)
+ Added@markuplint/shared@4.0.0-rc.0(transitive)
+ Added@markuplint/types@4.0.0-rc.0(transitive)
+ Added@types/css-tree@2.3.9(transitive)
+ Added@types/mustache@4.2.5(transitive)
+ Added@types/uuid@9.0.8(transitive)
+ Added@types/whatwg-mimetype@3.0.2(transitive)
+ Addedacorn@8.14.0(transitive)
+ Addedacorn-jsx@5.3.2(transitive)
+ Addedbcp-47@2.1.0(transitive)
+ Addedcss-tree@2.3.1(transitive)
+ Addedcssesc@3.0.0(transitive)
+ Addeddeepmerge@4.3.1(transitive)
+ Addeddom-accessibility-api@0.6.3(transitive)
+ Addedentities@4.5.0(transitive)
+ Addedeslint-visitor-keys@4.2.0(transitive)
+ Addedespree@10.3.0(transitive)
+ Addedhtml-entities@2.5.2(transitive)
+ Addedis-alphabetical@2.0.1(transitive)
+ Addedis-alphanumerical@2.0.1(transitive)
+ Addedis-decimal@2.0.1(transitive)
+ Addedleven@4.0.0(transitive)
+ Addedmdn-data@2.0.30(transitive)
+ Addedmustache@4.2.0(transitive)
+ Addedparse5@7.1.2(transitive)
+ Addedpostcss-selector-parser@6.1.2(transitive)
+ Addedsource-map-js@1.2.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addeduuid@9.0.1(transitive)
+ Addedwhatwg-mimetype@4.0.0(transitive)
Updated@markuplint/i18n@4.0.0-rc.0
Updated@types/debug@^4.1.12
Updatedtype-fest@^4.10.2