@markuplint/ml-core
Advanced tools
Comparing version 4.0.0-dev.20 to 4.0.0-dev.23
@@ -6,3 +6,2 @@ export { RuleInfo, RuleConfig, RuleConfigValue } from '@markuplint/ml-config'; | ||
export { getIndent } from './ml-dom/helper/get-indent.js'; | ||
export * from './configs.js'; | ||
export * from './convert-ruleset.js'; | ||
@@ -9,0 +8,0 @@ export * from './ml-core.js'; |
@@ -5,3 +5,2 @@ export { ariaSpecs, contentModelCategoryToTagNames, getAttrSpecs, getComputedRole, getImplicitRole, getPermittedRoles, getRoleSpec, getSpec, resolveNamespace, } from '@markuplint/ml-spec'; | ||
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'; |
@@ -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}"`); | ||
} |
@@ -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; | ||
} |
@@ -19,6 +19,4 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
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.potentialValue ?? this.valueNode?.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 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 { 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); |
@@ -1482,3 +1482,3 @@ import type { MLAttr } from './attr.js'; | ||
*/ | ||
getTokenList(): readonly MLToken<import("@markuplint/ml-ast").MLToken>[]; | ||
getTokenList(): readonly MLToken<import("@markuplint/ml-ast").MLASTToken>[]; | ||
/** | ||
@@ -1570,3 +1570,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; | ||
/** | ||
@@ -1579,3 +1579,3 @@ * @implements `@markuplint/ml-core` API: `MLDocument` | ||
*/ | ||
toString(): string; | ||
toString(fixed?: boolean): string; | ||
/** | ||
@@ -1582,0 +1582,0 @@ * @implements `@markuplint/ml-core` API: `MLDocument` |
@@ -13,3 +13,3 @@ 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 { getCol, getLine } from '@markuplint/parser-utils/location'; | ||
import { UnexpectedCallError } from './unexpected-call-error.js'; | ||
@@ -16,0 +16,0 @@ export class MLDomTokenList extends Array { |
@@ -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.** |
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 @@ /** |
@@ -178,7 +178,13 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
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 | ||
@@ -227,6 +233,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; | ||
} | ||
@@ -373,6 +378,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; | ||
} | ||
@@ -472,2 +476,5 @@ /** | ||
get syntacticalParentNode() { | ||
if (this._astToken.type === 'attr' || this._astToken.type === 'spread') { | ||
return null; | ||
} | ||
if (!this._astToken.parentNode) { | ||
@@ -474,0 +481,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 @@ /** |
@@ -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 @@ | ||
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(); |
@@ -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; |
@@ -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 { 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>[]; |
{ | ||
"name": "@markuplint/ml-core", | ||
"version": "4.0.0-dev.20+6b35da16", | ||
"version": "4.0.0-dev.23+d6f2aa9bc", | ||
"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.20+6b35da16", | ||
"@markuplint/html-parser": "4.0.0-dev.20+6b35da16", | ||
"@markuplint/html-spec": "4.0.0-dev.20+6b35da16", | ||
"@markuplint/i18n": "4.0.0-dev.20+6b35da16", | ||
"@markuplint/ml-ast": "4.0.0-dev.20+6b35da16", | ||
"@markuplint/ml-config": "4.0.0-dev.20+6b35da16", | ||
"@markuplint/ml-spec": "4.0.0-dev.20+6b35da16", | ||
"@markuplint/parser-utils": "4.0.0-dev.20+6b35da16", | ||
"@markuplint/selector": "4.0.0-dev.20+6b35da16", | ||
"@markuplint/config-presets": "4.0.0-dev.23+d6f2aa9bc", | ||
"@markuplint/html-parser": "4.0.0-dev.23+d6f2aa9bc", | ||
"@markuplint/html-spec": "4.0.0-dev.23+d6f2aa9bc", | ||
"@markuplint/i18n": "4.0.0-dev.23+d6f2aa9bc", | ||
"@markuplint/ml-ast": "4.0.0-dev.23+d6f2aa9bc", | ||
"@markuplint/ml-config": "4.0.0-dev.23+d6f2aa9bc", | ||
"@markuplint/ml-spec": "4.0.0-dev.23+d6f2aa9bc", | ||
"@markuplint/parser-utils": "4.0.0-dev.23+d6f2aa9bc", | ||
"@markuplint/selector": "4.0.0-dev.23+d6f2aa9bc", | ||
"@types/debug": "^4.1.12", | ||
"debug": "^4.3.4", | ||
"is-plain-object": "^5.0.0", | ||
"type-fest": "^4.8.3" | ||
"type-fest": "^4.9.0" | ||
}, | ||
"gitHead": "6b35da161d94f784953d0adecc2d28502052d92a" | ||
"gitHead": "d6f2aa9bc287768466f23b5340e4e0eecfa30d59" | ||
} |
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
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
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
419588
12984
Updatedtype-fest@^4.9.0