Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@markuplint/parser-utils

Package Overview
Dependencies
Maintainers
1
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@markuplint/parser-utils - npm Package Compare versions

Comparing version 3.0.0-dev.186 to 3.0.0-dev.290

2

lib/const.d.ts

@@ -1,2 +0,2 @@

export declare const MASK_CHAR = '\uE000';
export declare const MASK_CHAR = "\uE000";
/**

@@ -3,0 +3,0 @@ * SVG Element list

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.reSplitterTag = exports.reTagName = exports.reTag = exports.svgElementList = exports.MASK_CHAR = void 0;
exports.MASK_CHAR = '\uE000';
export const MASK_CHAR = '\uE000';
/**

@@ -10,3 +7,3 @@ * SVG Element list

*/
exports.svgElementList = [
export const svgElementList = [
'a',

@@ -101,5 +98,5 @@ 'animate',

];
exports.reTag = /^<((?:.|\s|\n)+)>\s*$/;
export const reTag = /^<((?:.|\s|\n)+)>\s*$/;
// eslint-disable-next-line no-control-regex
exports.reTagName = /^(?:[a-z][^\u0000\u0009\u000A\u000C\u0020/>]*)/i;
exports.reSplitterTag = /<[^>]+>/g;
export const reTagName = /^(?:[a-z][^\u0000\u0009\u000A\u000C\u0020/>]*)/i;
export const reSplitterTag = /<[^>]+>/g;
import type { MLToken } from '@markuplint/ml-ast';
export declare function tokenizer(
raw: string | null,
startLine: number,
startCol: number,
startOffset: number,
): MLToken;
export declare function tokenizer(raw: string | null, startLine: number, startCol: number, startOffset: number): MLToken;
export declare function createTokenFromRawCode(raw: string | null, startOffset: number, rawCode: string): MLToken;
export declare function uuid(): string;

@@ -1,10 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.uuid = exports.createTokenFromRawCode = exports.tokenizer = void 0;
const uuid_1 = require("uuid");
const get_location_1 = require("./get-location");
function tokenizer(raw, startLine, startCol, startOffset) {
raw = raw !== null && raw !== void 0 ? raw : '';
const endLine = (0, get_location_1.getEndLine)(raw, startLine);
const endCol = (0, get_location_1.getEndCol)(raw, startCol);
import { v4 as uuid4 } from 'uuid';
import { getEndCol, getEndLine, sliceFragment } from './get-location.js';
export function tokenizer(raw, startLine, startCol, startOffset) {
raw = raw ?? '';
const endLine = getEndLine(raw, startLine);
const endCol = getEndCol(raw, startCol);
const endOffset = startOffset + raw.length;

@@ -22,6 +19,5 @@ return {

}
exports.tokenizer = tokenizer;
function createTokenFromRawCode(raw, startOffset, rawCode) {
raw = raw !== null && raw !== void 0 ? raw : '';
const loc = (0, get_location_1.sliceFragment)(rawCode, startOffset, startOffset + raw.length);
export function createTokenFromRawCode(raw, startOffset, rawCode) {
raw = raw ?? '';
const loc = sliceFragment(rawCode, startOffset, startOffset + raw.length);
return {

@@ -32,6 +28,4 @@ uuid: uuid(),

}
exports.createTokenFromRawCode = createTokenFromRawCode;
function uuid() {
return (0, uuid_1.v4)();
export function uuid() {
return uuid4();
}
exports.uuid = uuid;

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.attributesToDebugMaps = exports.nodeListToDebugMaps = void 0;
function nodeListToDebugMaps(
export function nodeListToDebugMaps(
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types

@@ -23,4 +20,3 @@ nodeList, withAttr = false) {

}
exports.nodeListToDebugMaps = nodeListToDebugMaps;
function attributesToDebugMaps(
export function attributesToDebugMaps(
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types

@@ -56,8 +52,6 @@ attributes) {

}
exports.attributesToDebugMaps = attributesToDebugMaps;
function tokenDebug(n, type = '') {
var _a, _b, _c, _d;
return `[${n.startLine}:${n.startCol}]>[${n.endLine}:${n.endCol}](${n.startOffset},${n.endOffset})${
// @ts-ignore
(_d = (_c = (_b = (_a = n.potentialName) !== null && _a !== void 0 ? _a : n.nodeName) !== null && _b !== void 0 ? _b : n.name) !== null && _c !== void 0 ? _c : n.type) !== null && _d !== void 0 ? _d : type}: ${visibleWhiteSpace(n.raw)}`;
n.potentialName ?? n.nodeName ?? n.name ?? n.type ?? type}: ${visibleWhiteSpace(n.raw)}`;
}

@@ -64,0 +58,0 @@ function visibleWhiteSpace(chars) {

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPotentialCustomElementName = exports.isSVGElement = void 0;
const types_1 = require("@markuplint/types");
const const_1 = require("./const");
import { isCustomElementName } from '@markuplint/types';
import { svgElementList } from './const.js';
/**

@@ -12,10 +9,8 @@ *

*/
function isSVGElement(nodeName) {
return const_1.svgElementList.includes(nodeName);
export function isSVGElement(nodeName) {
return svgElementList.includes(nodeName);
}
exports.isSVGElement = isSVGElement;
const isCEN = (0, types_1.isCustomElementName)();
function isPotentialCustomElementName(tagName) {
const isCEN = isCustomElementName();
export function isPotentialCustomElementName(tagName) {
return isCEN(tagName);
}
exports.isPotentialCustomElementName = isPotentialCustomElementName;
import type { ElementType, ParserAuthoredElementNameDistinguishing } from '@markuplint/ml-ast';
export declare function detectElementType(
name: string,
option?: ParserAuthoredElementNameDistinguishing,
defaultPattern?: ParserAuthoredElementNameDistinguishing,
): ElementType;
export declare function detectElementType(name: string, option?: ParserAuthoredElementNameDistinguishing, defaultPattern?: ParserAuthoredElementNameDistinguishing): ElementType;

@@ -1,12 +0,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.detectElementType = void 0;
const decision_1 = require("./decision");
function detectElementType(name, option, defaultPattern) {
import { isPotentialCustomElementName } from './decision.js';
export function detectElementType(name, option, defaultPattern) {
if (distinguishAuthoredName(name, option, defaultPattern)) {
return 'authored';
}
return (0, decision_1.isPotentialCustomElementName)(name) ? 'web-component' : 'html';
return isPotentialCustomElementName(name) ? 'web-component' : 'html';
}
exports.detectElementType = detectElementType;
function distinguishAuthoredName(name, pattern, defaultPattern) {

@@ -13,0 +9,0 @@ if (pattern != null) {

@@ -1,12 +0,9 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.flattenNodes = void 0;
const tslib_1 = require("tslib");
const remove_deprecated_node_1 = require("./remove-deprecated-node");
const tag_splitter_1 = tslib_1.__importDefault(require("./tag-splitter"));
const parser_utils_1 = require("@markuplint/parser-utils");
function flattenNodes(
import { uuid } from './create-token.js';
import { getEndCol, getEndLine } from './get-location.js';
import { removeDeprecatedNode } from './remove-deprecated-node.js';
import tagSplitter from './tag-splitter.js';
import { walk } from './walker.js';
export function flattenNodes(
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
nodeTree, rawHtml, createLastText = true) {
var _a, _b, _c, _d;
const nodeOrders = arrayize(nodeTree, rawHtml);

@@ -30,3 +27,3 @@ {

const prevWreckagesText = prevToken;
const wreckages = (0, tag_splitter_1.default)(prevWreckagesText.raw, prevWreckagesText.startLine, prevWreckagesText.startCol);
const wreckages = tagSplitter(prevWreckagesText.raw, prevWreckagesText.startLine, prevWreckagesText.startCol);
if (wreckages.length > 0 && wreckages[0]) {

@@ -41,5 +38,5 @@ // console.log('wreckages\n', wreckages);

prevWreckagesText.startLine = startLine;
prevWreckagesText.endLine = (0, parser_utils_1.getEndLine)(raw, startLine);
prevWreckagesText.endLine = getEndLine(raw, startLine);
prevWreckagesText.startCol = startCol;
prevWreckagesText.endCol = (0, parser_utils_1.getEndCol)(raw, startCol);
prevWreckagesText.endCol = getEndCol(raw, startCol);
}

@@ -49,3 +46,3 @@ }

}
(0, remove_deprecated_node_1.removeDeprecatedNode)(nodeOrders);
removeDeprecatedNode(nodeOrders);
{

@@ -66,3 +63,3 @@ /**

// prev node: ? -> html
lastNode.prevNode = (_b = (_a = lastNode.parentNode) === null || _a === void 0 ? void 0 : _a.parentNode) !== null && _b !== void 0 ? _b : lastNode.parentNode;
lastNode.prevNode = lastNode.parentNode?.parentNode ?? lastNode.parentNode;
if (lastNode.prevNode) {

@@ -88,6 +85,6 @@ lastNode.prevNode.nextNode = lastNode;

if (lastTextContent) {
const line = (_c = lastNode === null || lastNode === void 0 ? void 0 : lastNode.endLine) !== null && _c !== void 0 ? _c : 0;
const col = (_d = lastNode === null || lastNode === void 0 ? void 0 : lastNode.endCol) !== null && _d !== void 0 ? _d : 0;
const line = lastNode?.endLine ?? 0;
const col = lastNode?.endCol ?? 0;
const lastTextNode = {
uuid: (0, parser_utils_1.uuid)(),
uuid: uuid(),
raw: lastTextContent,

@@ -97,5 +94,5 @@ startOffset: lastOffset,

startLine: line,
endLine: (0, parser_utils_1.getEndLine)(lastTextContent, line),
endLine: getEndLine(lastTextContent, line),
startCol: col,
endCol: (0, parser_utils_1.getEndCol)(lastTextContent, col),
endCol: getEndCol(lastTextContent, col),
nodeName: '#text',

@@ -123,5 +120,4 @@ type: 'text',

nodeOrders.forEach(node => {
var _a, _b;
const prevNode = (_a = result[result.length - 1]) !== null && _a !== void 0 ? _a : null;
if (node.type === 'text' && (prevNode === null || prevNode === void 0 ? void 0 : prevNode.type) === 'text') {
const prevNode = result[result.length - 1] ?? null;
if (node.type === 'text' && prevNode?.type === 'text') {
prevNode.raw = prevNode.raw + node.raw;

@@ -141,3 +137,3 @@ prevNode.endOffset = node.endOffset;

}
prevNode.parentNode.childNodes = (_b = prevNode.parentNode.childNodes) === null || _b === void 0 ? void 0 : _b.filter(n => n.uuid !== node.uuid);
prevNode.parentNode.childNodes = prevNode.parentNode.childNodes?.filter(n => n.uuid !== node.uuid);
}

@@ -195,3 +191,2 @@ if (node.nextNode) {

}
exports.flattenNodes = flattenNodes;
function arrayize(

@@ -207,4 +202,3 @@ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types

*/
(0, parser_utils_1.walk)(nodeTree, node => {
var _a;
walk(nodeTree, node => {
const diff = node.startOffset - currentEndOffset;

@@ -219,3 +213,3 @@ if (diff > 0) {

const textNode = {
uuid: (0, parser_utils_1.uuid)(),
uuid: uuid(),
raw: spaces,

@@ -225,5 +219,5 @@ startOffset: currentEndOffset,

startLine: prevLine,
endLine: (0, parser_utils_1.getEndLine)(spaces, prevLine),
endLine: getEndLine(spaces, prevLine),
startCol: prevCol,
endCol: (0, parser_utils_1.getEndCol)(spaces, prevCol),
endCol: getEndCol(spaces, prevCol),
nodeName: '#text',

@@ -259,3 +253,3 @@ type: 'text',

// for ghost nodes
node.endOffset = (_a = node.endOffset) !== null && _a !== void 0 ? _a : currentEndOffset;
node.endOffset = node.endOffset ?? currentEndOffset;
nodeOrders.push(node);

@@ -262,0 +256,0 @@ });

@@ -5,14 +5,10 @@ export declare function getLine(html: string, startOffset: number): number;

export declare function getEndCol(html: string, col: number): number;
export declare function sliceFragment(
rawHtml: string,
start: number,
end: number,
): {
startOffset: number;
endOffset: number;
startLine: number;
endLine: number;
startCol: number;
endCol: number;
raw: string;
export declare function sliceFragment(rawHtml: string, start: number, end: number): {
startOffset: number;
endOffset: number;
startLine: number;
endLine: number;
startCol: number;
endCol: number;
raw: string;
};

@@ -1,19 +0,12 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sliceFragment = exports.getEndCol = exports.getEndLine = exports.getCol = exports.getLine = void 0;
function getLine(html, startOffset) {
export function getLine(html, startOffset) {
return html.slice(0, startOffset).split(/\n/g).length;
}
exports.getLine = getLine;
function getCol(html, startOffset) {
var _a;
export function getCol(html, startOffset) {
const lines = html.slice(0, startOffset).split(/\n/g);
return ((_a = lines[lines.length - 1]) !== null && _a !== void 0 ? _a : '').length + 1;
return (lines[lines.length - 1] ?? '').length + 1;
}
exports.getCol = getCol;
function getEndLine(html, line) {
export function getEndLine(html, line) {
return html.split(/\r?\n/).length - 1 + line;
}
exports.getEndLine = getEndLine;
function getEndCol(html, col) {
export function getEndCol(html, col) {
const lines = html.split(/\r?\n/);

@@ -24,4 +17,3 @@ const lineCount = lines.length;

}
exports.getEndCol = getEndCol;
function sliceFragment(rawHtml, start, end) {
export function sliceFragment(rawHtml, start, end) {
const raw = rawHtml.slice(start, end);

@@ -38,2 +30,1 @@ return {

}
exports.sliceFragment = sliceFragment;

@@ -1,1 +0,1 @@

export declare function getSpaceBefore(offset: number, rawCode: string): import('@markuplint/ml-ast').MLToken;
export declare function getSpaceBefore(offset: number, rawCode: string): import("packages/@markuplint/ml-ast/lib/types.js").MLToken;

@@ -1,13 +0,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSpaceBefore = void 0;
const create_token_1 = require("./create-token");
function getSpaceBefore(offset, rawCode) {
var _a;
import { createTokenFromRawCode } from './create-token.js';
export function getSpaceBefore(offset, rawCode) {
const aboveCode = rawCode.slice(0, offset);
const aboveAttrMatched = aboveCode.match(/\s+$/m);
const aboveAttrChar = (_a = aboveAttrMatched === null || aboveAttrMatched === void 0 ? void 0 : aboveAttrMatched[0]) !== null && _a !== void 0 ? _a : '';
const spacesBefore = (0, create_token_1.createTokenFromRawCode)(aboveAttrChar, offset - aboveAttrChar.length, rawCode);
const aboveAttrChar = aboveAttrMatched?.[0] ?? '';
const spacesBefore = createTokenFromRawCode(aboveAttrChar, offset - aboveAttrChar.length, rawCode);
return spacesBefore;
}
exports.getSpaceBefore = getSpaceBefore;
export declare function searchIDLAttribute(name: string): {
idlPropName: string | undefined;
contentAttrName: string | undefined;
idlPropName: string | undefined;
contentAttrName: string | undefined;
};

@@ -1,4 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.searchIDLAttribute = void 0;
/**

@@ -421,10 +418,9 @@ * IDL attributes VS Content attributes

const list = Object.entries(idlContentMap);
function searchIDLAttribute(name) {
var _a;
export function searchIDLAttribute(name) {
const camelizedName = camelize(name);
const [idlPropName, contentAttrName] = /^on[a-z]/.test(name)
? [name.toLowerCase(), name.toLowerCase()]
: (_a = list.find(([idlPropName, contentAttrName]) => idlPropName.toLowerCase() === camelizedName.toLowerCase() ||
: list.find(([idlPropName, contentAttrName]) => idlPropName.toLowerCase() === camelizedName.toLowerCase() ||
contentAttrName.toLowerCase() === name.toLowerCase() ||
hyphenize(idlPropName) === name.toLowerCase())) !== null && _a !== void 0 ? _a : [];
hyphenize(idlPropName) === name.toLowerCase()) ?? [];
return {

@@ -435,5 +431,4 @@ idlPropName,

}
exports.searchIDLAttribute = searchIDLAttribute;
function camelize(str) {
return str.replace(/[:-][a-z]/g, $0 => { var _a, _b; return (_b = (_a = $0[1]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : ''; });
return str.replace(/[:-][a-z]/g, $0 => $0[1]?.toUpperCase() ?? '');
}

@@ -440,0 +435,0 @@ function hyphenize(str) {

@@ -1,4 +0,4 @@

import type { IgnoreBlock, IgnoreTag } from './types';
import type { IgnoreBlock, IgnoreTag } from './types.js';
import type { MLASTNode } from '@markuplint/ml-ast';
export declare function ignoreBlock(source: string, tags: readonly IgnoreTag[], maskChar?: string): IgnoreBlock;
export declare function restoreNode(nodeList: MLASTNode[], ignoreBlock: IgnoreBlock): MLASTNode[];

@@ -1,9 +0,6 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.restoreNode = exports.ignoreBlock = void 0;
const const_1 = require("./const");
const create_token_1 = require("./create-token");
const get_location_1 = require("./get-location");
const siblings_correction_1 = require("./siblings-correction");
function ignoreBlock(source, tags, maskChar = const_1.MASK_CHAR) {
import { MASK_CHAR } from './const.js';
import { uuid } from './create-token.js';
import { sliceFragment } from './get-location.js';
import { siblingsCorrection } from './siblings-correction.js';
export function ignoreBlock(source, tags, maskChar = MASK_CHAR) {
let replaced = source;

@@ -16,3 +13,3 @@ const stack = [];

taggedCode.replace(/[^\n]/g, maskChar) +
maskChar.repeat((endTag !== null && endTag !== void 0 ? endTag : '').length);
maskChar.repeat((endTag ?? '').length);
return mask;

@@ -26,3 +23,3 @@ });

taggedCode.replace(/[^\n]/g, maskChar) +
maskChar.repeat((endTag !== null && endTag !== void 0 ? endTag : '').length);
maskChar.repeat((endTag ?? '').length);
const taggedMask = `<!${mask.slice(2).slice(0, -1)}>`;

@@ -42,3 +39,2 @@ return taggedMask;

}
exports.ignoreBlock = ignoreBlock;
function maskText(start, end, replaced, masking) {

@@ -58,3 +54,3 @@ const stack = [];

taggedCode,
endTag: endTag !== null && endTag !== void 0 ? endTag : null,
endTag: endTag ?? null,
});

@@ -64,3 +60,3 @@ /**

*/
replaced = above + masking(startTag, taggedCode, endTag) + (below !== null && below !== void 0 ? below : '');
replaced = above + masking(startTag, taggedCode, endTag) + (below ?? '');
}

@@ -72,6 +68,5 @@ return {

}
function restoreNode(
export function restoreNode(
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
nodeList, ignoreBlock) {
var _a, _b, _c, _d, _e;
nodeList = nodeList.slice();

@@ -92,3 +87,3 @@ const { source, stack, maskChar } = ignoreBlock;

const start = tag.index - node.startOffset;
const body = tag.startTag + tag.taggedCode + ((_a = tag.endTag) !== null && _a !== void 0 ? _a : '');
const body = tag.startTag + tag.taggedCode + (tag.endTag ?? '');
const above = node.raw.slice(pointer, start);

@@ -98,6 +93,6 @@ const below = text.slice(above.length + body.length);

const offset = node.startOffset + pointer;
const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = (0, get_location_1.sliceFragment)(source, offset, offset + above.length);
const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = sliceFragment(source, offset, offset + above.length);
const textNode = {
...node,
uuid: (0, create_token_1.uuid)(),
uuid: uuid(),
type: 'text',

@@ -112,6 +107,6 @@ raw,

};
if ((_b = node.prevNode) === null || _b === void 0 ? void 0 : _b.nextNode) {
if (node.prevNode?.nextNode) {
node.prevNode.nextNode = textNode;
}
if ((_c = node.nextNode) === null || _c === void 0 ? void 0 : _c.prevNode) {
if (node.nextNode?.prevNode) {
node.nextNode.prevNode = textNode;

@@ -123,5 +118,5 @@ }

const offset = node.startOffset + pointer + above.length;
const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = (0, get_location_1.sliceFragment)(source, offset, offset + body.length);
const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = sliceFragment(source, offset, offset + body.length);
const bodyNode = {
uuid: (0, create_token_1.uuid)(),
uuid: uuid(),
type: 'psblock',

@@ -142,6 +137,6 @@ nodeName: `#ps:${tag.type}`,

};
if ((_d = node.prevNode) === null || _d === void 0 ? void 0 : _d.nextNode) {
if (node.prevNode?.nextNode) {
node.prevNode.nextNode = bodyNode;
}
if ((_e = node.nextNode) === null || _e === void 0 ? void 0 : _e.prevNode) {
if (node.nextNode?.prevNode) {
node.nextNode.prevNode = bodyNode;

@@ -157,6 +152,6 @@ }

const offset = node.endOffset - text.length;
const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = (0, get_location_1.sliceFragment)(source, offset, offset + text.length);
const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = sliceFragment(source, offset, offset + text.length);
const textNode = {
...node,
uuid: (0, create_token_1.uuid)(),
uuid: uuid(),
type: 'text',

@@ -173,3 +168,3 @@ raw,

}
(0, siblings_correction_1.siblingsCorrection)(insertList);
siblingsCorrection(insertList);
if (parentNode) {

@@ -201,3 +196,2 @@ parentNode.childNodes = insertList;

}
exports.restoreNode = restoreNode;
function snap(str, reg) {

@@ -204,0 +198,0 @@ const matched = reg.exec(str);

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ignoreFrontMatter = void 0;
function ignoreFrontMatter(code) {
export function ignoreFrontMatter(code) {
const reStart = /^(?:\s*\r?\n)?---\r?\n/.exec(code);

@@ -21,2 +18,1 @@ if (!reStart) {

}
exports.ignoreFrontMatter = ignoreFrontMatter;

@@ -1,16 +0,16 @@

export * from './const';
export * from './create-token';
export * from './debugger';
export * from './decision';
export * from './detect-element-type';
export * from './flatten-nodes';
export * from './get-location';
export * from './get-space-before';
export * from './idl-attributes';
export * from './ignore-block';
export * from './ignore-front-matter';
export * from './parse-attr';
export * from './parser-error';
export * from './remove-deprecated-node';
export * from './tag-splitter';
export * from './walker';
export * from './const.js';
export * from './create-token.js';
export * from './debugger.js';
export * from './decision.js';
export * from './detect-element-type.js';
export * from './flatten-nodes.js';
export * from './get-location.js';
export * from './get-space-before.js';
export * from './idl-attributes.js';
export * from './ignore-block.js';
export * from './ignore-front-matter.js';
export * from './parse-attr.js';
export * from './parser-error.js';
export * from './remove-deprecated-node.js';
export * from './tag-splitter.js';
export * from './walker.js';

@@ -1,19 +0,16 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./const"), exports);
tslib_1.__exportStar(require("./create-token"), exports);
tslib_1.__exportStar(require("./debugger"), exports);
tslib_1.__exportStar(require("./decision"), exports);
tslib_1.__exportStar(require("./detect-element-type"), exports);
tslib_1.__exportStar(require("./flatten-nodes"), exports);
tslib_1.__exportStar(require("./get-location"), exports);
tslib_1.__exportStar(require("./get-space-before"), exports);
tslib_1.__exportStar(require("./idl-attributes"), exports);
tslib_1.__exportStar(require("./ignore-block"), exports);
tslib_1.__exportStar(require("./ignore-front-matter"), exports);
tslib_1.__exportStar(require("./parse-attr"), exports);
tslib_1.__exportStar(require("./parser-error"), exports);
tslib_1.__exportStar(require("./remove-deprecated-node"), exports);
tslib_1.__exportStar(require("./tag-splitter"), exports);
tslib_1.__exportStar(require("./walker"), exports);
export * from './const.js';
export * from './create-token.js';
export * from './debugger.js';
export * from './decision.js';
export * from './detect-element-type.js';
export * from './flatten-nodes.js';
export * from './get-location.js';
export * from './get-space-before.js';
export * from './idl-attributes.js';
export * from './ignore-block.js';
export * from './ignore-front-matter.js';
export * from './parse-attr.js';
export * from './parser-error.js';
export * from './remove-deprecated-node.js';
export * from './tag-splitter.js';
export * from './walker.js';
import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
type ParseAttrOptions = {
readonly booleanish?: boolean;
readonly valueDelimiters?: readonly ValueDelimiter[];
readonly equal?: string;
readonly booleanish?: boolean;
readonly valueDelimiters?: readonly ValueDelimiter[];
readonly equal?: string;
};
type ValueDelimiter = {
readonly start: string;
readonly end: string;
readonly start: string;
readonly end: string;
};
export declare const defaultValueDelimiters: readonly ValueDelimiter[];
export declare function parseAttr(raw: string, offset: number, html: string, options?: ParseAttrOptions): MLASTHTMLAttr;
export declare function tokenize(
raw: string,
options?: ParseAttrOptions,
): {
beforeName: string;
name: string;
afterName: string;
equal: string;
beforeValue: string;
startQuote: string;
value: string;
endQuote: string;
afterAttr: string;
export declare function tokenize(raw: string, options?: ParseAttrOptions): {
beforeName: string;
name: string;
afterName: string;
equal: string;
beforeValue: string;
startQuote: string;
value: string;
endQuote: string;
afterAttr: string;
};
export {};

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tokenize = exports.parseAttr = exports.defaultValueDelimiters = void 0;
const create_token_1 = require("./create-token");
exports.defaultValueDelimiters = [
import { createTokenFromRawCode, tokenizer, uuid } from './create-token.js';
export const defaultValueDelimiters = [
{

@@ -17,17 +14,17 @@ start: "'",

const spaceRegex = /^\s$/;
function parseAttr(raw, offset, html, options) {
export function parseAttr(raw, offset, html, options) {
const tokens = tokenize(raw, options);
tokens.beforeName;
const attrToken = (0, create_token_1.createTokenFromRawCode)(raw, offset, html);
const spacesBeforeName = (0, create_token_1.tokenizer)(tokens.beforeName, attrToken.startLine, attrToken.startCol, attrToken.startOffset);
const name = (0, create_token_1.tokenizer)(tokens.name, spacesBeforeName.endLine, spacesBeforeName.endCol, spacesBeforeName.endOffset);
const spacesBeforeEqual = (0, create_token_1.tokenizer)(tokens.afterName, name.endLine, name.endCol, name.endOffset);
const equal = (0, create_token_1.tokenizer)(tokens.equal, spacesBeforeEqual.endLine, spacesBeforeEqual.endCol, spacesBeforeEqual.endOffset);
const spacesAfterEqual = (0, create_token_1.tokenizer)(tokens.beforeValue, equal.endLine, equal.endCol, equal.endOffset);
const startQuote = (0, create_token_1.tokenizer)(tokens.startQuote, spacesAfterEqual.endLine, spacesAfterEqual.endCol, spacesAfterEqual.endOffset);
const value = (0, create_token_1.tokenizer)(tokens.value, startQuote.endLine, startQuote.endCol, startQuote.endOffset);
const endQuote = (0, create_token_1.tokenizer)(tokens.endQuote, value.endLine, value.endCol, value.endOffset);
const attrToken = createTokenFromRawCode(raw, offset, html);
const spacesBeforeName = tokenizer(tokens.beforeName, attrToken.startLine, attrToken.startCol, attrToken.startOffset);
const name = tokenizer(tokens.name, spacesBeforeName.endLine, spacesBeforeName.endCol, spacesBeforeName.endOffset);
const spacesBeforeEqual = tokenizer(tokens.afterName, name.endLine, name.endCol, name.endOffset);
const equal = tokenizer(tokens.equal, spacesBeforeEqual.endLine, spacesBeforeEqual.endCol, spacesBeforeEqual.endOffset);
const spacesAfterEqual = tokenizer(tokens.beforeValue, equal.endLine, equal.endCol, equal.endOffset);
const startQuote = tokenizer(tokens.startQuote, spacesAfterEqual.endLine, spacesAfterEqual.endCol, spacesAfterEqual.endOffset);
const value = tokenizer(tokens.value, startQuote.endLine, startQuote.endCol, startQuote.endOffset);
const endQuote = tokenizer(tokens.endQuote, value.endLine, value.endCol, value.endOffset);
const attr = {
type: 'html-attr',
uuid: (0, create_token_1.uuid)(),
uuid: uuid(),
raw: attrToken.raw,

@@ -58,7 +55,5 @@ startOffset: attrToken.startOffset,

}
exports.parseAttr = parseAttr;
function tokenize(raw, options) {
var _a, _b, _c;
const valueDelimiters = (_a = options === null || options === void 0 ? void 0 : options.valueDelimiters) !== null && _a !== void 0 ? _a : exports.defaultValueDelimiters;
const equalDelimiter = (_b = options === null || options === void 0 ? void 0 : options.equal) !== null && _b !== void 0 ? _b : defaultEqual;
export function tokenize(raw, options) {
const valueDelimiters = options?.valueDelimiters ?? defaultValueDelimiters;
const equalDelimiter = options?.equal ?? defaultEqual;
let state = 'b-name';

@@ -118,3 +113,3 @@ const charactors = raw.split('');

}
valueDelimiter = (_c = valueDelimiters.find(d => d.start === charactor)) !== null && _c !== void 0 ? _c : null;
valueDelimiter = valueDelimiters.find(d => d.start === charactor) ?? null;
if (valueDelimiter) {

@@ -153,2 +148,1 @@ startQuote += valueDelimiter.start;

}
exports.tokenize = tokenize;

@@ -0,21 +1,26 @@

export type ParserErrorInfo = {
readonly line?: number;
readonly col?: number;
readonly raw?: string;
};
export declare class ParserError extends Error {
readonly col: number;
readonly line: number;
name: string;
readonly nodeName: string | null;
readonly raw: string;
constructor(
message: string,
{
line,
col,
raw,
nodeName,
}: {
readonly line?: number;
readonly col?: number;
readonly raw?: string;
readonly nodeName?: string | null;
},
);
readonly col: number;
readonly line: number;
name: string;
readonly raw: string;
constructor(message: string, info: ParserErrorInfo);
}
export declare class TargetParserError extends ParserError {
name: string;
readonly nodeName: string | null;
constructor(message: string, info: ParserErrorInfo & {
readonly nodeName?: string | null;
});
}
export declare class ConfigParserError extends ParserError {
readonly filePath: string;
name: string;
constructor(message: string, info: ParserErrorInfo & {
readonly filePath: string;
});
}

@@ -1,14 +0,29 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParserError = void 0;
class ParserError extends Error {
constructor(message, { line = 1, col = 0, raw = '', nodeName = null, }) {
super(nodeName ? `The ${nodeName} is invalid element (${line}:${col}): ${message}` : message);
export class ParserError extends Error {
constructor(message, info) {
super(message);
this.name = 'ParserError';
this.line = line;
this.col = col;
this.raw = raw;
this.nodeName = nodeName;
this.line = info.line ?? 1;
this.col = info.col ?? 0;
this.raw = info.raw ?? '';
}
}
exports.ParserError = ParserError;
export class TargetParserError extends ParserError {
constructor(message, info) {
const errMsg = info.nodeName
? `The ${info.nodeName} is invalid element (${info.line}:${info.col}): ${message}`
: message;
super(errMsg, info);
this.name = 'TargetParserError';
this.nodeName = info.nodeName ?? null;
}
}
export class ConfigParserError extends ParserError {
constructor(message, info) {
const pos = info.line != null && info.line != null ? `(${info.line}:${info.col})` : '';
const file = ` in ${info.filePath}${pos}`;
const errMsg = `${message}${file}`;
super(errMsg, info);
this.name = 'ConfigParserError';
this.filePath = info.filePath;
}
}

@@ -1,4 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeDeprecatedNode = void 0;
/**

@@ -9,3 +6,3 @@ *

*/
function removeDeprecatedNode(
export function removeDeprecatedNode(
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types

@@ -44,2 +41,1 @@ nodeOrders) {

}
exports.removeDeprecatedNode = removeDeprecatedNode;

@@ -1,4 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.siblingsCorrection = void 0;
/**

@@ -11,8 +8,7 @@ * Correct the references to prevNode and nextNode in the order listed.

*/
function siblingsCorrection(
export function siblingsCorrection(
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
nodeList) {
var _a, _b;
for (let i = 0; i < nodeList.length; i++) {
const prevNode = (_a = nodeList[i - 1]) !== null && _a !== void 0 ? _a : null;
const prevNode = nodeList[i - 1] ?? null;
const node = nodeList[i];

@@ -22,3 +18,3 @@ if (!node) {

}
const nextNode = (_b = nodeList[i + 1]) !== null && _b !== void 0 ? _b : null;
const nextNode = nodeList[i + 1] ?? null;
node.prevNode = prevNode;

@@ -28,2 +24,1 @@ node.nextNode = nextNode;

}
exports.siblingsCorrection = siblingsCorrection;
export interface N {
type: 'text' | 'starttag' | 'endtag' | 'comment' | 'boguscomment';
raw: string;
line: number;
col: number;
type: 'text' | 'starttag' | 'endtag' | 'comment' | 'boguscomment';
raw: string;
line: number;
col: number;
}
export default function tagSplitter(raw: string, line: number, col: number): N[];

@@ -1,11 +0,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const const_1 = require("./const");
const parser_utils_1 = require("@markuplint/parser-utils");
function tagSplitter(raw, line, col) {
import { reSplitterTag, reTagName } from './const.js';
import { getEndCol, getEndLine } from '@markuplint/parser-utils';
export default function tagSplitter(raw, line, col) {
return withLocation(tagSplitterAsString(raw), line, col);
}
exports.default = tagSplitter;
function tagSplitterAsString(raw) {
const tagMatches = raw.match(const_1.reSplitterTag);
const tagMatches = raw.match(reSplitterTag);
if (!tagMatches) {

@@ -47,3 +44,3 @@ return [raw];

const label = node.slice(1).slice(0, -1);
if (const_1.reTagName.test(label)) {
if (reTagName.test(label)) {
result.push({

@@ -89,6 +86,6 @@ type: 'starttag',

}
line = (0, parser_utils_1.getEndLine)(node, line);
col = (0, parser_utils_1.getEndCol)(node, col);
line = getEndLine(node, line);
col = getEndCol(node, col);
}
return result;
}
export type Code = {
readonly type: string;
readonly index: number;
readonly startTag: string;
readonly taggedCode: string;
readonly endTag: string | null;
readonly type: string;
readonly index: number;
readonly startTag: string;
readonly taggedCode: string;
readonly endTag: string | null;
};
export type IgnoreTag = {
readonly type: string;
readonly start: Readonly<RegExp>;
readonly end: Readonly<RegExp>;
readonly type: string;
readonly start: Readonly<RegExp>;
readonly end: Readonly<RegExp>;
};
export type IgnoreBlock = {
readonly source: string;
readonly replaced: string;
readonly stack: readonly Code[];
readonly maskChar: string;
readonly source: string;
readonly replaced: string;
readonly stack: readonly Code[];
readonly maskChar: string;
};

@@ -1,2 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.walk = void 0;
function walk(
export function walk(
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types

@@ -22,2 +19,1 @@ nodeList, walker, depth = 0) {

}
exports.walk = walk;
{
"name": "@markuplint/parser-utils",
"version": "3.0.0-dev.186+37ceba57",
"version": "3.0.0-dev.290+af676442",
"description": "Utility module for markuplint parser plugin",

@@ -9,3 +9,8 @@ "repository": "git@github.com:markuplint/markuplint.git",

"private": false,
"main": "lib/index.js",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js"
}
},
"types": "lib/index.d.ts",

@@ -23,13 +28,10 @@ "publishConfig": {

"dependencies": {
"@markuplint/ml-ast": "3.0.0-dev.186+37ceba57",
"@markuplint/types": "3.0.0-dev.186+37ceba57",
"@types/uuid": "^9.0.0",
"tslib": "^2.4.1",
"type-fest": "^3.8.0",
"uuid": "^9.0.0"
"@markuplint/ml-ast": "3.0.0-dev.290+af676442",
"@markuplint/types": "3.0.0-dev.290+af676442",
"@types/uuid": "^9.0.4",
"tslib": "^2.6.2",
"type-fest": "^4.3.1",
"uuid": "^9.0.1"
},
"peerDependencies": {
"@markuplint/ml-core": "3.x"
},
"gitHead": "37ceba578aff49e0326c5e374cef3da6be303b25"
"gitHead": "af6764422feecb56d1d84659028f53daf685bb78"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc