@markuplint/pug-parser 4.6.7 → 4.6.8
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/CHANGELOG.md +7 -4
- package/lib/parser.js +20 -1
- package/lib/pug-parser/index.d.ts +25 -7
- package/lib/pug-parser/index.js +34 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,21 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [4.6.
|
|
6
|
+
## [4.6.8](https://github.com/markuplint/markuplint/compare/@markuplint/pug-parser@4.6.7...@markuplint/pug-parser@4.6.8) (2024-10-14)
|
|
7
7
|
|
|
8
|
-
**Note:** Version bump only for package @markuplint/pug-parser
|
|
9
8
|
|
|
9
|
+
### Bug Fixes
|
|
10
10
|
|
|
11
|
+
* **pug-parser:** fix to support `BlockComment` node ([afa721c](https://github.com/markuplint/markuplint/commit/afa721cd29cab8a47fa27cefe808d3fb7066b42e))
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
## [4.6.6](https://github.com/markuplint/markuplint/compare/@markuplint/pug-parser@4.6.5...@markuplint/pug-parser@4.6.6) (2024-09-02)
|
|
15
15
|
|
|
16
|
-
**Note:** Version bump only for package @markuplint/pug-parser
|
|
17
16
|
|
|
17
|
+
## [4.6.7](https://github.com/markuplint/markuplint/compare/@markuplint/pug-parser@4.6.6...@markuplint/pug-parser@4.6.7) (2024-09-23)
|
|
18
18
|
|
|
19
|
+
**Note:** Version bump only for package @markuplint/pug-parser
|
|
19
20
|
|
|
21
|
+
## [4.6.6](https://github.com/markuplint/markuplint/compare/@markuplint/pug-parser@4.6.5...@markuplint/pug-parser@4.6.6) (2024-09-02)
|
|
20
22
|
|
|
23
|
+
**Note:** Version bump only for package @markuplint/pug-parser
|
|
21
24
|
|
|
22
25
|
## [4.6.5](https://github.com/markuplint/markuplint/compare/@markuplint/pug-parser@4.6.4...@markuplint/pug-parser@4.6.5) (2024-06-25)
|
|
23
26
|
|
package/lib/parser.js
CHANGED
|
@@ -95,6 +95,18 @@ class PugParser extends Parser {
|
|
|
95
95
|
isBogus: false,
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
|
+
case 'BlockComment': {
|
|
99
|
+
const lastBlock = originNode.block.nodes.at(-1);
|
|
100
|
+
const endOffset = lastBlock ? lastBlock.endOffset : originNode.endOffset;
|
|
101
|
+
const token = this.sliceFragment(originNode.offset, endOffset);
|
|
102
|
+
return this.visitComment({
|
|
103
|
+
...token,
|
|
104
|
+
depth,
|
|
105
|
+
parentNode,
|
|
106
|
+
}, {
|
|
107
|
+
isBogus: false,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
98
110
|
case 'Tag': {
|
|
99
111
|
const namespace = getNamespace(originNode.name, parentNamespace);
|
|
100
112
|
const attrs = originNode.attrs.map(attr => {
|
|
@@ -142,8 +154,15 @@ class PugParser extends Parser {
|
|
|
142
154
|
});
|
|
143
155
|
}
|
|
144
156
|
default: {
|
|
157
|
+
let tokenIncludesFile = token;
|
|
158
|
+
if ('file' in originNode) {
|
|
159
|
+
const interval = originNode.file.column - originNode.endColumn;
|
|
160
|
+
const fileOffset = originNode.endOffset + interval;
|
|
161
|
+
const fileEndOffset = fileOffset + originNode.file.path.length;
|
|
162
|
+
tokenIncludesFile = this.sliceFragment(originNode.offset, fileEndOffset);
|
|
163
|
+
}
|
|
145
164
|
return this.visitPsBlock({
|
|
146
|
-
...
|
|
165
|
+
...tokenIncludesFile,
|
|
147
166
|
depth,
|
|
148
167
|
parentNode,
|
|
149
168
|
nodeName: originNode.type,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
export declare function pugParse(pug: string, useOffset?: boolean): ASTBlock;
|
|
2
2
|
export type ASTBlock = PugAST<ASTNode>;
|
|
3
|
-
export type ASTNode = ASTTagNode | ASTTextNode | ASTEmptyPipeNode | ASTCodeNode | ASTComment | ASTDoctype | ASTIncludeNode | ASTMixinNode | ASTMixinSlotNode | ASTNamedBlockNode | ASTFilterNode | ASTEachNode | ASTConditionalNode | ASTCaseNode | ASTCaseWhenNode;
|
|
3
|
+
export type ASTNode = ASTTagNode | ASTTextNode | ASTEmptyPipeNode | ASTCodeNode | ASTComment | ASTBlockComment | ASTDoctype | ASTIncludeNode | ASTRawIncludeNode | ASTMixinNode | ASTMixinSlotNode | ASTNamedBlockNode | ASTFilterNode | ASTEachNode | ASTConditionalNode | ASTCaseNode | ASTCaseWhenNode;
|
|
4
4
|
export type ASTTagNode = Omit<PugASTTagNode<ASTAttr, ASTBlock>, 'selfClosing' | 'isInline'> & AdditionalASTData;
|
|
5
5
|
export type ASTTextNode = Omit<PugASTTextNode, 'val'> & AdditionalASTData;
|
|
6
6
|
export type ASTEmptyPipeNode = PugASTEmptyPipeNode & AdditionalASTData;
|
|
7
7
|
export type ASTCodeNode = PugASTCodeNode & AdditionalASTData;
|
|
8
8
|
export type ASTComment = PugASTCommentNode & AdditionalASTData;
|
|
9
|
+
export type ASTBlockComment = PugASTBlockCommentNode<ASTBlock> & AdditionalASTData;
|
|
9
10
|
export type ASTDoctype = PugASTDoctypeNode & AdditionalASTData;
|
|
10
11
|
export type ASTIncludeNode = PugASTIncludeNode<ASTBlock> & AdditionalASTData;
|
|
12
|
+
export type ASTRawIncludeNode = PugASTRawIncludeNode & AdditionalASTData;
|
|
11
13
|
export type ASTMixinNode = Omit<PugASTMixinNode<ASTAttr, ASTBlock>, 'attributeBlocks'> & AdditionalASTData;
|
|
12
14
|
export type ASTMixinSlotNode = PugASTMixinSlotNode & AdditionalASTData;
|
|
13
15
|
export type ASTNamedBlockNode = PugASTNamedBlockNode<ASTNode> & AdditionalASTData;
|
|
@@ -76,6 +78,14 @@ type PugASTCommentNode = {
|
|
|
76
78
|
line: number;
|
|
77
79
|
column: number;
|
|
78
80
|
};
|
|
81
|
+
type PugASTBlockCommentNode<B> = {
|
|
82
|
+
type: 'BlockComment';
|
|
83
|
+
val: string;
|
|
84
|
+
block: B;
|
|
85
|
+
buffer: boolean;
|
|
86
|
+
line: number;
|
|
87
|
+
column: number;
|
|
88
|
+
};
|
|
79
89
|
type PugASTDoctypeNode = {
|
|
80
90
|
type: 'Doctype';
|
|
81
91
|
val: string;
|
|
@@ -84,16 +94,24 @@ type PugASTDoctypeNode = {
|
|
|
84
94
|
};
|
|
85
95
|
type PugASTIncludeNode<B> = {
|
|
86
96
|
type: 'Include';
|
|
87
|
-
file:
|
|
88
|
-
type: 'FileReference';
|
|
89
|
-
path: string;
|
|
90
|
-
line: number;
|
|
91
|
-
column: number;
|
|
92
|
-
};
|
|
97
|
+
file: RugASTIncludeFile;
|
|
93
98
|
block: B;
|
|
94
99
|
line: number;
|
|
95
100
|
column: number;
|
|
96
101
|
};
|
|
102
|
+
type PugASTRawIncludeNode = {
|
|
103
|
+
type: 'RawInclude';
|
|
104
|
+
file: RugASTIncludeFile;
|
|
105
|
+
line: number;
|
|
106
|
+
column: number;
|
|
107
|
+
filters: unknown[];
|
|
108
|
+
};
|
|
109
|
+
type RugASTIncludeFile = {
|
|
110
|
+
type: 'FileReference';
|
|
111
|
+
path: string;
|
|
112
|
+
line: number;
|
|
113
|
+
column: number;
|
|
114
|
+
};
|
|
97
115
|
type PugASTEachNode<B> = {
|
|
98
116
|
type: 'Each';
|
|
99
117
|
obj: string;
|
package/lib/pug-parser/index.js
CHANGED
|
@@ -146,6 +146,22 @@ tokens, pug) {
|
|
|
146
146
|
nodes.push(includeNode);
|
|
147
147
|
continue;
|
|
148
148
|
}
|
|
149
|
+
case 'RawInclude': {
|
|
150
|
+
const includeNode = {
|
|
151
|
+
type: node.type,
|
|
152
|
+
file: node.file,
|
|
153
|
+
raw,
|
|
154
|
+
offset,
|
|
155
|
+
endOffset,
|
|
156
|
+
line,
|
|
157
|
+
endLine,
|
|
158
|
+
column,
|
|
159
|
+
endColumn,
|
|
160
|
+
filters: node.filters,
|
|
161
|
+
};
|
|
162
|
+
nodes.push(includeNode);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
149
165
|
case 'Mixin': {
|
|
150
166
|
// TODO: Attributes when call mixin
|
|
151
167
|
// const attrs = getAttrs(node.attrs, tokens, offsets, pug);
|
|
@@ -222,6 +238,24 @@ tokens, pug) {
|
|
|
222
238
|
nodes.push(commentNode);
|
|
223
239
|
continue;
|
|
224
240
|
}
|
|
241
|
+
case 'BlockComment': {
|
|
242
|
+
const block = optimizeAST(node.block, tokens, pug);
|
|
243
|
+
const commentNode = {
|
|
244
|
+
type: node.type,
|
|
245
|
+
val: node.val,
|
|
246
|
+
buffer: node.buffer,
|
|
247
|
+
block,
|
|
248
|
+
raw,
|
|
249
|
+
offset,
|
|
250
|
+
endOffset,
|
|
251
|
+
line,
|
|
252
|
+
endLine,
|
|
253
|
+
column,
|
|
254
|
+
endColumn,
|
|
255
|
+
};
|
|
256
|
+
nodes.push(commentNode);
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
225
259
|
case 'Code': {
|
|
226
260
|
const newNode = {
|
|
227
261
|
type: node.type,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/pug-parser",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.8",
|
|
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,11 +21,11 @@
|
|
|
21
21
|
"clean": "tsc --build --clean"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@markuplint/html-parser": "4.6.
|
|
25
|
-
"@markuplint/ml-ast": "4.4.
|
|
26
|
-
"@markuplint/parser-utils": "4.6.
|
|
24
|
+
"@markuplint/html-parser": "4.6.8",
|
|
25
|
+
"@markuplint/ml-ast": "4.4.5",
|
|
26
|
+
"@markuplint/parser-utils": "4.6.8",
|
|
27
27
|
"pug-lexer": "5.0.1",
|
|
28
28
|
"pug-parser": "6.0.0"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "e59d4e8b762c66c7e3fb8b0a0d9d99d5160b0afa"
|
|
31
31
|
}
|