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.5.0 to 3.6.0

lib/get-space-before.d.ts

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

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;

@@ -7,3 +7,3 @@ "use strict";

function tokenizer(raw, startLine, startCol, startOffset) {
raw = raw || '';
raw = raw !== null && raw !== void 0 ? raw : '';
const endLine = (0, get_location_1.getEndLine)(raw, startLine);

@@ -25,3 +25,3 @@ const endCol = (0, get_location_1.getEndCol)(raw, startCol);

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

@@ -28,0 +28,0 @@ return {

@@ -57,5 +57,6 @@ "use strict";

function tokenDebug(n, type = '') {
var _a, _b, _c, _d;
return `[${n.startLine}:${n.startCol}]>[${n.endLine}:${n.endCol}](${n.startOffset},${n.endOffset})${
// @ts-ignore
n.potentialName || n.nodeName || n.name || n.type || type}: ${visibleWhiteSpace(n.raw)}`;
(_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)}`;
}

@@ -62,0 +63,0 @@ function visibleWhiteSpace(chars) {

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;

@@ -13,6 +13,6 @@ "use strict";

function distinguishAuthoredName(name, pattern, defaultPattern) {
if (pattern) {
if (pattern != null) {
return _distinguishAuthoredName(name, pattern);
}
if (defaultPattern) {
if (defaultPattern != null) {
return _distinguishAuthoredName(name, defaultPattern);

@@ -19,0 +19,0 @@ }

@@ -11,2 +11,3 @@ "use strict";

nodeTree, rawHtml, createLastText = true) {
var _a, _b, _c, _d;
const nodeOrders = arrayize(nodeTree, rawHtml);

@@ -30,17 +31,15 @@ {

const prevWreckagesText = prevToken;
if (prevWreckagesText) {
const wreckages = (0, tag_splitter_1.default)(prevWreckagesText.raw, prevWreckagesText.startLine, prevWreckagesText.startCol);
if (wreckages.length && wreckages[0]) {
// console.log('wreckages\n', wreckages);
const lastText = wreckages[0];
const raw = lastText.raw;
const startLine = lastText.line;
const startCol = lastText.col;
prevWreckagesText.raw = raw;
prevWreckagesText.endOffset = prevWreckagesText.startOffset + raw.length;
prevWreckagesText.startLine = startLine;
prevWreckagesText.endLine = (0, parser_utils_1.getEndLine)(raw, startLine);
prevWreckagesText.startCol = startCol;
prevWreckagesText.endCol = (0, parser_utils_1.getEndCol)(raw, startCol);
}
const wreckages = (0, tag_splitter_1.default)(prevWreckagesText.raw, prevWreckagesText.startLine, prevWreckagesText.startCol);
if (wreckages.length > 0 && wreckages[0]) {
// console.log('wreckages\n', wreckages);
const lastText = wreckages[0];
const raw = lastText.raw;
const startLine = lastText.line;
const startCol = lastText.col;
prevWreckagesText.raw = raw;
prevWreckagesText.endOffset = prevWreckagesText.startOffset + raw.length;
prevWreckagesText.startLine = startLine;
prevWreckagesText.endLine = (0, parser_utils_1.getEndLine)(raw, startLine);
prevWreckagesText.startCol = startCol;
prevWreckagesText.endCol = (0, parser_utils_1.getEndCol)(raw, startCol);
}

@@ -66,3 +65,3 @@ }

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

@@ -88,4 +87,4 @@ lastNode.prevNode.nextNode = lastNode;

if (lastTextContent) {
const line = lastNode ? lastNode.endLine : 0;
const col = lastNode ? lastNode.endCol : 0;
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 lastTextNode = {

@@ -108,7 +107,5 @@ uuid: (0, parser_utils_1.uuid)(),

};
if (lastNode) {
lastNode.nextNode = lastTextNode;
if ((lastNode.type === 'starttag' || lastNode.type === 'endtag') && lastNode.pearNode) {
lastNode.pearNode.nextNode = lastTextNode;
}
lastNode.nextNode = lastTextNode;
if ((lastNode.type === 'starttag' || lastNode.type === 'endtag') && lastNode.pearNode) {
lastNode.pearNode.nextNode = lastTextNode;
}

@@ -125,4 +122,5 @@ nodeOrders.push(lastTextNode);

nodeOrders.forEach(node => {
const prevNode = result[result.length - 1] || null;
if (node.type === 'text' && prevNode && prevNode.type === 'text') {
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') {
prevNode.raw = prevNode.raw + node.raw;

@@ -133,4 +131,12 @@ prevNode.endOffset = node.endOffset;

prevNode.nextNode = node.nextNode;
if (prevNode.parentNode && prevNode.parentNode.childNodes) {
prevNode.parentNode.childNodes = prevNode.parentNode.childNodes.filter(n => n.uuid !== node.uuid);
if (prevNode.parentNode) {
if (prevNode.parentNode.childNodes) {
if (prevNode.parentNode.childNodes.findIndex(currentChild => currentChild.uuid === prevNode.uuid) === -1) {
prevNode.parentNode.childNodes.unshift(prevNode);
}
else {
prevNode.parentNode.childNodes = [prevNode];
}
}
prevNode.parentNode.childNodes = (_b = prevNode.parentNode.childNodes) === null || _b === void 0 ? void 0 : _b.filter(n => n.uuid !== node.uuid);
}

@@ -200,2 +206,3 @@ if (node.nextNode) {

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

@@ -248,4 +255,3 @@ if (diff > 0) {

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

@@ -252,0 +258,0 @@ });

@@ -5,10 +5,14 @@ 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;
};
export declare function searchIDLAttribute(name: string): {
idlPropName: string | undefined;
contentAttrName: string | undefined;
idlPropName: string | undefined;
contentAttrName: string | undefined;
};

@@ -422,8 +422,9 @@ "use strict";

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

@@ -430,0 +431,0 @@ idlPropName,

@@ -16,3 +16,3 @@ "use strict";

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

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

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

@@ -57,3 +57,3 @@ return taggedMask;

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

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

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

@@ -74,3 +74,3 @@ return {

nodeList, ignoreBlock) {
var _a, _b, _c, _d;
var _a, _b, _c, _d, _e;
nodeList = nodeList.slice();

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

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

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

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

@@ -139,6 +139,6 @@ }

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

@@ -145,0 +145,0 @@ }

@@ -8,5 +8,7 @@ export * from './const';

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';

@@ -13,0 +15,0 @@ export * from './remove-deprecated-node';

@@ -11,5 +11,7 @@ "use strict";

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);

@@ -16,0 +18,0 @@ tslib_1.__exportStar(require("./remove-deprecated-node"), exports);

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 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;
},
);
}

@@ -37,3 +37,3 @@ "use strict";

let r = nodeOrders.length;
while (r--) {
while (r-- > 0) {
if (removeIndexes.includes(r)) {

@@ -40,0 +40,0 @@ nodeOrders.splice(r, 1);

@@ -14,4 +14,5 @@ "use strict";

nodeList) {
var _a, _b;
for (let i = 0; i < nodeList.length; i++) {
const prevNode = nodeList[i - 1] || null;
const prevNode = (_a = nodeList[i - 1]) !== null && _a !== void 0 ? _a : null;
const node = nodeList[i];

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

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

@@ -24,0 +25,0 @@ node.nextNode = nextNode;

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[];
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;
};

@@ -13,3 +13,3 @@ "use strict";

}
if (node.childNodes && node.childNodes.length) {
if (node.childNodes && node.childNodes.length > 0) {
walk(node.childNodes, walker, depth + 1);

@@ -16,0 +16,0 @@ }

{
"name": "@markuplint/parser-utils",
"version": "3.5.0",
"version": "3.6.0",
"description": "Utility module for markuplint parser plugin",

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

"@markuplint/ml-ast": "3.1.0",
"@markuplint/types": "3.4.0",
"@markuplint/types": "3.5.0",
"tslib": "^2.4.1",

@@ -35,3 +35,3 @@ "uuid": "^9.0.0"

},
"gitHead": "0c47b2c2722f6823a17f36edbab98486275f8ab4"
"gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
}
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