@markuplint/pug-parser 4.0.0-alpha.3 → 4.0.0-dev.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/attr-tokenizer.js
CHANGED
|
@@ -5,7 +5,7 @@ attr) {
|
|
|
5
5
|
if (attr.raw[0] === '#' || attr.raw[0] === '.') {
|
|
6
6
|
let value = '';
|
|
7
7
|
if (typeof attr.val === 'string') {
|
|
8
|
-
|
|
8
|
+
value = attr.val.match(/(["'`]?)([^\1]+)(\1)/)?.[2] ?? '';
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
11
|
value = `${attr.val}`;
|
|
@@ -52,7 +52,7 @@ attr) {
|
|
|
52
52
|
const valueOffset = withoutName.indexOf(attr.val);
|
|
53
53
|
const equalAndBeforeSpaceAfterSpace = withoutName.slice(0, valueOffset);
|
|
54
54
|
const [, before, equal, after] = equalAndBeforeSpaceAfterSpace.match(/^(\s*)(=)(\s*)$/) ?? ['', '', '', ''];
|
|
55
|
-
const [, quote, coreValue] = attr.val.match(/(['
|
|
55
|
+
const [, quote, coreValue] = attr.val.match(/(["'`]?)([^\1]+)(\1)/) ?? ['', '', ''];
|
|
56
56
|
spacesBeforeEqualChars = before ?? '';
|
|
57
57
|
equalChars = equal ?? '';
|
|
58
58
|
spacesAfterEqualChars = after ?? '';
|
|
@@ -62,7 +62,7 @@ attr) {
|
|
|
62
62
|
isDynamicValue = true;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
const invalid = !!(valueChars && quoteChars === null && /["'
|
|
65
|
+
const invalid = !!(valueChars && quoteChars === null && /["'<=>`]/.test(valueChars)) ||
|
|
66
66
|
!!(equalChars && quoteChars === null && valueChars === null);
|
|
67
67
|
if (invalid) {
|
|
68
68
|
throw new Error('Parse error: It has invalid attribute');
|
package/lib/parse.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
1
12
|
var _Parser_ast;
|
|
2
|
-
import {
|
|
3
|
-
import { getNamespace, parse as htmlParser, isDocumentFragment } from '@markuplint/html-parser';
|
|
13
|
+
import { getNamespace, parse as htmlParse, isDocumentFragment } from '@markuplint/html-parser';
|
|
4
14
|
import { detectElementType, ignoreFrontMatter, ParserError, tokenizer, uuid, walk, removeDeprecatedNode, } from '@markuplint/parser-utils';
|
|
5
15
|
import attrTokenizer from './attr-tokenizer.js';
|
|
6
16
|
import { pugParse } from './pug-parser/index.js';
|
|
@@ -14,21 +24,21 @@ export const parse = (rawCode, options) => {
|
|
|
14
24
|
const parser = new Parser(rawCode);
|
|
15
25
|
nodeList = parser.getNodeList();
|
|
16
26
|
}
|
|
17
|
-
catch (
|
|
27
|
+
catch (error) {
|
|
18
28
|
nodeList = [];
|
|
19
|
-
if (
|
|
29
|
+
if (error instanceof Error && 'msg' in error && 'line' in error && 'column' in error && 'src' in error) {
|
|
20
30
|
throw new ParserError(
|
|
21
31
|
// @ts-ignore
|
|
22
|
-
|
|
32
|
+
error.msg, {
|
|
23
33
|
// @ts-ignore
|
|
24
|
-
line:
|
|
34
|
+
line: error.line,
|
|
25
35
|
// @ts-ignore
|
|
26
|
-
col:
|
|
36
|
+
col: error.column,
|
|
27
37
|
// @ts-ignore
|
|
28
|
-
raw:
|
|
38
|
+
raw: error.src,
|
|
29
39
|
});
|
|
30
40
|
}
|
|
31
|
-
unknownParseError =
|
|
41
|
+
unknownParseError = error instanceof Error ? error.message : new Error(`${error}`).message;
|
|
32
42
|
}
|
|
33
43
|
return {
|
|
34
44
|
nodeList,
|
|
@@ -117,17 +127,14 @@ class Parser {
|
|
|
117
127
|
isGhost: false,
|
|
118
128
|
};
|
|
119
129
|
}
|
|
120
|
-
const htmlDoc =
|
|
130
|
+
const htmlDoc = htmlParse(originNode.raw, {
|
|
121
131
|
offsetOffset: originNode.offset,
|
|
122
132
|
offsetLine: originNode.line - 1,
|
|
123
133
|
offsetColumn: originNode.column - 1,
|
|
124
134
|
});
|
|
125
|
-
const nodes = htmlDoc.nodeList
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
node.parentNode = parentNode;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
135
|
+
const nodes = htmlDoc.nodeList.filter(node => {
|
|
136
|
+
return node.parentNode == null && node.type !== 'endtag';
|
|
137
|
+
});
|
|
131
138
|
return nodes;
|
|
132
139
|
}
|
|
133
140
|
case 'Comment': {
|
|
@@ -219,7 +226,7 @@ class Parser {
|
|
|
219
226
|
}
|
|
220
227
|
let node;
|
|
221
228
|
if (Array.isArray(nodes)) {
|
|
222
|
-
const lastNode = nodes
|
|
229
|
+
const lastNode = nodes.at(-1);
|
|
223
230
|
if (!lastNode) {
|
|
224
231
|
continue;
|
|
225
232
|
}
|
package/lib/pug-parser/index.js
CHANGED
|
@@ -26,7 +26,7 @@ function mergeTextNode(
|
|
|
26
26
|
nodes, pug) {
|
|
27
27
|
const baseNodes = [];
|
|
28
28
|
for (const node of nodes) {
|
|
29
|
-
const prevNode = baseNodes
|
|
29
|
+
const prevNode = baseNodes.at(-1) ?? null;
|
|
30
30
|
if (prevNode && prevNode.type === 'Text' && node.type === 'Text') {
|
|
31
31
|
prevNode.raw = pug.slice(prevNode.offset, node.endOffset);
|
|
32
32
|
prevNode.endColumn = node.endColumn;
|
|
@@ -382,7 +382,7 @@ tokens, pug, offsets, depth) {
|
|
|
382
382
|
function getLocationFromToken(offset, line, column,
|
|
383
383
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
384
384
|
tokens, tokenType) {
|
|
385
|
-
const tokenTypes = typeof tokenType === 'string' ? (tokenType
|
|
385
|
+
const tokenTypes = typeof tokenType === 'string' ? (tokenType === '' ? null : [tokenType]) : tokenType ?? null;
|
|
386
386
|
let tokenOfCurrentNode = null;
|
|
387
387
|
for (const token of tokens) {
|
|
388
388
|
if ((tokenTypes == null || tokenTypes.includes(token.type)) &&
|
|
@@ -2,7 +2,7 @@ export function getOffsetFromLineAndCol(str, line, col) {
|
|
|
2
2
|
const lines = str.split('\n').slice(0, line);
|
|
3
3
|
const lastLine = lines.pop();
|
|
4
4
|
if (lastLine) {
|
|
5
|
-
lines.push(lastLine.
|
|
5
|
+
lines.push([...lastLine].slice(0, col).join(''));
|
|
6
6
|
}
|
|
7
7
|
return lines.join('\n').length;
|
|
8
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/pug-parser",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-dev.28+0131de5e",
|
|
4
4
|
"description": "Pug parser for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -21,12 +21,11 @@
|
|
|
21
21
|
"clean": "tsc --build --clean"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@markuplint/html-parser": "4.0.0-
|
|
25
|
-
"@markuplint/ml-ast": "4.0.0-
|
|
26
|
-
"@markuplint/parser-utils": "4.0.0-
|
|
24
|
+
"@markuplint/html-parser": "4.0.0-dev.28+0131de5e",
|
|
25
|
+
"@markuplint/ml-ast": "4.0.0-dev.28+0131de5e",
|
|
26
|
+
"@markuplint/parser-utils": "4.0.0-dev.28+0131de5e",
|
|
27
27
|
"pug-lexer": "^5.0.1",
|
|
28
|
-
"pug-parser": "^6.0.0"
|
|
29
|
-
"tslib": "^2.6.2"
|
|
28
|
+
"pug-parser": "^6.0.0"
|
|
30
29
|
},
|
|
31
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "0131de5ea9dd6d3fd5472d7b414b66644c758881"
|
|
32
31
|
}
|