@markuplint/pug-parser 3.4.0 → 3.5.0
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 +3 -1
- package/lib/index.d.ts +1 -1
- package/lib/parse.js +14 -4
- package/lib/pug-parser/index.d.ts +97 -111
- package/lib/pug-parser/index.js +32 -8
- package/package.json +5 -5
package/lib/attr-tokenizer.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const parser_utils_1 = require("@markuplint/parser-utils");
|
|
4
|
-
function attrTokenizer(
|
|
4
|
+
function attrTokenizer(
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
6
|
+
attr) {
|
|
5
7
|
if (attr.raw[0] === '#' || attr.raw[0] === '.') {
|
|
6
8
|
let value = '';
|
|
7
9
|
if (typeof attr.val === 'string') {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { parse } from './parse';
|
|
2
|
-
export declare const endTag =
|
|
2
|
+
export declare const endTag = "never";
|
package/lib/parse.js
CHANGED
|
@@ -46,19 +46,27 @@ class Parser {
|
|
|
46
46
|
tslib_1.__classPrivateFieldSet(this, _Parser_ast, (0, pug_parser_1.pugParse)(raw), "f");
|
|
47
47
|
// console.log(JSON.stringify(this.#ast, null, 2));
|
|
48
48
|
}
|
|
49
|
-
flattenNodes(
|
|
49
|
+
flattenNodes(
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
51
|
+
nodeTree) {
|
|
50
52
|
const nodeOrders = [];
|
|
51
53
|
(0, parser_utils_1.walk)(nodeTree, node => {
|
|
52
54
|
nodeOrders.push(node);
|
|
53
55
|
});
|
|
54
|
-
(0,
|
|
56
|
+
(0, parser_utils_1.removeDeprecatedNode)(nodeOrders);
|
|
55
57
|
return nodeOrders;
|
|
56
58
|
}
|
|
57
59
|
getNodeList() {
|
|
58
60
|
const nodeTree = this.traverse(tslib_1.__classPrivateFieldGet(this, _Parser_ast, "f").nodes, null);
|
|
59
61
|
return this.flattenNodes(nodeTree);
|
|
60
62
|
}
|
|
61
|
-
nodeize(
|
|
63
|
+
nodeize(
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
65
|
+
originNode,
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
67
|
+
prevNode,
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
69
|
+
parentNode) {
|
|
62
70
|
var _a;
|
|
63
71
|
const nextNode = null;
|
|
64
72
|
const startOffset = originNode.offset;
|
|
@@ -204,7 +212,9 @@ class Parser {
|
|
|
204
212
|
}
|
|
205
213
|
}
|
|
206
214
|
}
|
|
207
|
-
traverse(
|
|
215
|
+
traverse(
|
|
216
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
217
|
+
astNodes, parentNode = null) {
|
|
208
218
|
const nodeList = [];
|
|
209
219
|
let prevNode = null;
|
|
210
220
|
for (const astNode of astNodes) {
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
export declare function pugParse(pug: string): ASTBlock;
|
|
2
2
|
export type ASTBlock = PugAST<ASTNode>;
|
|
3
|
-
export type ASTNode =
|
|
4
|
-
|
|
5
|
-
| ASTTextNode
|
|
6
|
-
| ASTCodeNode
|
|
7
|
-
| ASTComment
|
|
8
|
-
| ASTDoctype
|
|
9
|
-
| ASTIncludeNode
|
|
10
|
-
| ASTMixinNode
|
|
11
|
-
| ASTMixinSlotNode
|
|
12
|
-
| ASTFilterNode
|
|
13
|
-
| ASTEachNode
|
|
14
|
-
| ASTConditionalNode
|
|
15
|
-
| ASTCaseNode
|
|
16
|
-
| ASTCaseWhenNode;
|
|
17
|
-
export type ASTTagNode = Omit<PugASTTagNode<ASTAttr, ASTBlock>, 'attributeBlocks' | 'selfClosing' | 'isInline'> &
|
|
18
|
-
AdditionalASTData;
|
|
3
|
+
export type ASTNode = ASTTagNode | ASTTextNode | ASTCodeNode | ASTComment | ASTDoctype | ASTIncludeNode | ASTMixinNode | ASTMixinSlotNode | ASTFilterNode | ASTEachNode | ASTConditionalNode | ASTCaseNode | ASTCaseWhenNode;
|
|
4
|
+
export type ASTTagNode = Omit<PugASTTagNode<ASTAttr, ASTBlock>, 'attributeBlocks' | 'selfClosing' | 'isInline'> & AdditionalASTData;
|
|
19
5
|
export type ASTTextNode = Omit<PugASTTextNode, 'val'> & AdditionalASTData;
|
|
20
6
|
export type ASTCodeNode = PugASTCodeNode & AdditionalASTData;
|
|
21
7
|
export type ASTComment = PugASTCommentNode & AdditionalASTData;
|
|
@@ -26,135 +12,135 @@ export type ASTMixinSlotNode = PugASTMixinSlotNode & AdditionalASTData;
|
|
|
26
12
|
export type ASTFilterNode = PugASTFilterNode<ASTAttr, ASTBlock> & AdditionalASTData;
|
|
27
13
|
export type ASTEachNode = PugASTEachNode<ASTBlock> & AdditionalASTData;
|
|
28
14
|
export type ASTConditionalNode = Omit<PugASTConditionalNode<ASTBlock>, 'consequent' | 'alternate'> & {
|
|
29
|
-
|
|
15
|
+
block: ASTBlock;
|
|
30
16
|
} & AdditionalASTData;
|
|
31
17
|
export type ASTCaseNode = PugASTCaseNode<ASTBlock> & AdditionalASTData;
|
|
32
18
|
export type ASTCaseWhenNode = PugASTCaseWhenNode<ASTBlock> & AdditionalASTData;
|
|
33
19
|
export type ASTAttr = PugASTAttr & AdditionalASTData;
|
|
34
20
|
type AdditionalASTData = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
raw: string;
|
|
22
|
+
offset: number;
|
|
23
|
+
endOffset: number;
|
|
24
|
+
endLine: number;
|
|
25
|
+
endColumn: number;
|
|
40
26
|
};
|
|
41
27
|
interface PugAST<N> {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
type: 'Block';
|
|
29
|
+
nodes: N[];
|
|
30
|
+
line: number;
|
|
45
31
|
}
|
|
46
32
|
type PugASTTagNode<A, B> = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
33
|
+
type: 'Tag';
|
|
34
|
+
name: string;
|
|
35
|
+
selfClosing: boolean;
|
|
36
|
+
attrs: A[];
|
|
37
|
+
attributeBlocks: never[];
|
|
38
|
+
isInline: boolean;
|
|
39
|
+
line: number;
|
|
40
|
+
column: number;
|
|
41
|
+
block: B;
|
|
56
42
|
};
|
|
57
43
|
type PugASTTextNode = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
44
|
+
type: 'Text';
|
|
45
|
+
val: string;
|
|
46
|
+
isHtml?: true;
|
|
47
|
+
line: number;
|
|
48
|
+
column: number;
|
|
63
49
|
};
|
|
64
50
|
type PugASTCodeNode = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
type: 'Code';
|
|
52
|
+
val: string;
|
|
53
|
+
buffer: boolean;
|
|
54
|
+
mustEscape: boolean;
|
|
55
|
+
isInline: boolean;
|
|
56
|
+
line: number;
|
|
57
|
+
column: number;
|
|
72
58
|
};
|
|
73
59
|
type PugASTCommentNode = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
60
|
+
type: 'Comment';
|
|
61
|
+
val: string;
|
|
62
|
+
buffer: boolean;
|
|
63
|
+
line: number;
|
|
64
|
+
column: number;
|
|
79
65
|
};
|
|
80
66
|
type PugASTDoctypeNode = {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
type: 'Doctype';
|
|
68
|
+
val: string;
|
|
69
|
+
line: number;
|
|
70
|
+
column: number;
|
|
85
71
|
};
|
|
86
72
|
type PugASTIncludeNode<B> = {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
73
|
+
type: 'Include';
|
|
74
|
+
file: {
|
|
75
|
+
type: 'FileReference';
|
|
76
|
+
path: string;
|
|
77
|
+
line: number;
|
|
78
|
+
column: number;
|
|
79
|
+
};
|
|
80
|
+
block: B;
|
|
81
|
+
line: number;
|
|
82
|
+
column: number;
|
|
97
83
|
};
|
|
98
84
|
type PugASTEachNode<B> = {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
85
|
+
type: 'Each';
|
|
86
|
+
obj: string;
|
|
87
|
+
val: string;
|
|
88
|
+
key: string | null;
|
|
89
|
+
block: B;
|
|
90
|
+
line: number;
|
|
91
|
+
column: number;
|
|
106
92
|
};
|
|
107
93
|
type PugASTMixinNode<A, B> = {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
94
|
+
type: 'Mixin';
|
|
95
|
+
name: string;
|
|
96
|
+
args: string;
|
|
97
|
+
call: boolean;
|
|
98
|
+
block: B | null;
|
|
99
|
+
attrs?: A[];
|
|
100
|
+
attributeBlocks: never[];
|
|
101
|
+
line: number;
|
|
102
|
+
column: number;
|
|
117
103
|
};
|
|
118
104
|
type PugASTMixinSlotNode = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
105
|
+
type: 'MixinBlock';
|
|
106
|
+
line: number;
|
|
107
|
+
column: number;
|
|
122
108
|
};
|
|
123
109
|
type PugASTFilterNode<A, B> = {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
110
|
+
type: 'Filter';
|
|
111
|
+
name: string;
|
|
112
|
+
block: B;
|
|
113
|
+
attrs: A[];
|
|
114
|
+
line: number;
|
|
115
|
+
column: number;
|
|
130
116
|
};
|
|
131
117
|
type PugASTConditionalNode<B> = {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
118
|
+
type: 'Conditional';
|
|
119
|
+
test: string;
|
|
120
|
+
consequent: B;
|
|
121
|
+
alternate?: B | PugASTConditionalNode<B>;
|
|
122
|
+
line: number;
|
|
123
|
+
column: number;
|
|
138
124
|
};
|
|
139
125
|
type PugASTCaseNode<B> = {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
126
|
+
type: 'Case';
|
|
127
|
+
expr: string;
|
|
128
|
+
block: B;
|
|
129
|
+
line: number;
|
|
130
|
+
column: number;
|
|
145
131
|
};
|
|
146
132
|
type PugASTCaseWhenNode<B> = {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
133
|
+
type: 'When';
|
|
134
|
+
expr: string;
|
|
135
|
+
block: B;
|
|
136
|
+
line: number;
|
|
137
|
+
column: number;
|
|
152
138
|
};
|
|
153
139
|
type PugASTAttr = {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
140
|
+
name: string;
|
|
141
|
+
val: string | true;
|
|
142
|
+
mustEscape: boolean;
|
|
143
|
+
line: number;
|
|
144
|
+
column: number;
|
|
159
145
|
};
|
|
160
146
|
export {};
|
package/lib/pug-parser/index.js
CHANGED
|
@@ -26,7 +26,9 @@ function getOffsetsFromLines(pug) {
|
|
|
26
26
|
});
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
|
-
function mergeTextNode(
|
|
29
|
+
function mergeTextNode(
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
31
|
+
nodes, pug) {
|
|
30
32
|
const baseNodes = [];
|
|
31
33
|
for (const node of nodes) {
|
|
32
34
|
const prevNode = baseNodes[baseNodes.length - 1] || null;
|
|
@@ -47,7 +49,11 @@ function mergeTextNode(nodes, pug) {
|
|
|
47
49
|
* @param tokens Lexed token list
|
|
48
50
|
* @param pug Raw code
|
|
49
51
|
*/
|
|
50
|
-
function optimizeAST(
|
|
52
|
+
function optimizeAST(
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
54
|
+
originalAST,
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
56
|
+
tokens, pug) {
|
|
51
57
|
var _a;
|
|
52
58
|
const nodes = [];
|
|
53
59
|
for (const node of originalAST.nodes) {
|
|
@@ -304,7 +310,11 @@ function optimizeAST(originalAST, tokens, pug) {
|
|
|
304
310
|
line: originalAST.line,
|
|
305
311
|
};
|
|
306
312
|
}
|
|
307
|
-
function optimizeASTOfConditionalNode(
|
|
313
|
+
function optimizeASTOfConditionalNode(
|
|
314
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
315
|
+
node,
|
|
316
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
317
|
+
tokens, pug, offsets, depth) {
|
|
308
318
|
var _a, _b;
|
|
309
319
|
const altNodes = [];
|
|
310
320
|
let tokenOfCurrentNode = null;
|
|
@@ -376,7 +386,9 @@ function optimizeASTOfConditionalNode(node, tokens, pug, offsets, depth) {
|
|
|
376
386
|
}
|
|
377
387
|
return altNodes;
|
|
378
388
|
}
|
|
379
|
-
function getLocationFromToken(offset, line, column,
|
|
389
|
+
function getLocationFromToken(offset, line, column,
|
|
390
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
391
|
+
tokens, tokenType = '') {
|
|
380
392
|
let tokenOfCurrentNode = null;
|
|
381
393
|
for (const token of tokens) {
|
|
382
394
|
if ((tokenType
|
|
@@ -401,7 +413,11 @@ function getLocationFromToken(offset, line, column, tokens, tokenType = '') {
|
|
|
401
413
|
length,
|
|
402
414
|
};
|
|
403
415
|
}
|
|
404
|
-
function getAttrs(
|
|
416
|
+
function getAttrs(
|
|
417
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
418
|
+
originalAttrs,
|
|
419
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
420
|
+
tokens, offsets, pug) {
|
|
405
421
|
const attrs = [];
|
|
406
422
|
for (const attr of originalAttrs) {
|
|
407
423
|
const attrLineOffset = offsets[attr.line - 2] || 0;
|
|
@@ -434,7 +450,9 @@ function getAttrs(originalAttrs, tokens, offsets, pug) {
|
|
|
434
450
|
}
|
|
435
451
|
return attrs;
|
|
436
452
|
}
|
|
437
|
-
function getEndAttributeLocation(nodeName, offset, line, column,
|
|
453
|
+
function getEndAttributeLocation(nodeName, offset, line, column,
|
|
454
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
455
|
+
tokens, offsets) {
|
|
438
456
|
var _a;
|
|
439
457
|
let beforeNewlineToken = null;
|
|
440
458
|
for (const token of tokens) {
|
|
@@ -462,7 +480,11 @@ function getEndAttributeLocation(nodeName, offset, line, column, tokens, offsets
|
|
|
462
480
|
endColumn: column + nodeName.length,
|
|
463
481
|
};
|
|
464
482
|
}
|
|
465
|
-
function getPipelessText(
|
|
483
|
+
function getPipelessText(
|
|
484
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
485
|
+
node, pug,
|
|
486
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
487
|
+
tokens) {
|
|
466
488
|
let startPipelessText = null;
|
|
467
489
|
let endPipelessText = null;
|
|
468
490
|
for (const token of tokens) {
|
|
@@ -494,7 +516,9 @@ function getPipelessText(node, pug, tokens) {
|
|
|
494
516
|
}
|
|
495
517
|
return null;
|
|
496
518
|
}
|
|
497
|
-
function getRawTextAndLocationEnd(val, offset, line, column,
|
|
519
|
+
function getRawTextAndLocationEnd(val, offset, line, column,
|
|
520
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
521
|
+
tokens, offsets, pug) {
|
|
498
522
|
var _a;
|
|
499
523
|
let beforeNewlineToken = null;
|
|
500
524
|
for (const token of tokens) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/pug-parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Pug parser for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"clean": "tsc --build --clean"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@markuplint/html-parser": "3.
|
|
20
|
-
"@markuplint/ml-ast": "3.
|
|
21
|
-
"@markuplint/parser-utils": "3.
|
|
19
|
+
"@markuplint/html-parser": "3.5.0",
|
|
20
|
+
"@markuplint/ml-ast": "3.1.0",
|
|
21
|
+
"@markuplint/parser-utils": "3.5.0",
|
|
22
22
|
"pug-lexer": "^5.0.1",
|
|
23
23
|
"pug-parser": "^6.0.0",
|
|
24
24
|
"tslib": "^2.4.1"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "0c47b2c2722f6823a17f36edbab98486275f8ab4"
|
|
27
27
|
}
|