@markuplint/pug-parser 4.6.8 → 4.6.10
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 +12 -3
- package/lib/pug-parser/index.d.ts +1 -8
- package/lib/pug-parser/index.js +61 -57
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,16 +3,25 @@
|
|
|
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.10](https://github.com/markuplint/markuplint/compare/@markuplint/pug-parser@4.6.9...@markuplint/pug-parser@4.6.10) (2024-10-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @markuplint/pug-parser
|
|
9
|
+
|
|
7
10
|
|
|
8
11
|
|
|
9
|
-
### Bug Fixes
|
|
10
12
|
|
|
11
|
-
* **pug-parser:** fix to support `BlockComment` node ([afa721c](https://github.com/markuplint/markuplint/commit/afa721cd29cab8a47fa27cefe808d3fb7066b42e))
|
|
12
13
|
|
|
14
|
+
## [4.6.9](https://github.com/markuplint/markuplint/compare/@markuplint/pug-parser@4.6.8...@markuplint/pug-parser@4.6.9) (2024-10-15)
|
|
13
15
|
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
- **pug-parser:** fix parsing outdent code ([dd50bb4](https://github.com/markuplint/markuplint/commit/dd50bb423bbd1c466fe10c59a1778b5572d60457))
|
|
14
19
|
|
|
20
|
+
## [4.6.8](https://github.com/markuplint/markuplint/compare/@markuplint/pug-parser@4.6.7...@markuplint/pug-parser@4.6.8) (2024-10-14)
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
15
23
|
|
|
24
|
+
- **pug-parser:** fix to support `BlockComment` node ([afa721c](https://github.com/markuplint/markuplint/commit/afa721cd29cab8a47fa27cefe808d3fb7066b42e))
|
|
16
25
|
|
|
17
26
|
## [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
27
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export declare function pugParse(pug: string, useOffset?: boolean): ASTBlock;
|
|
2
2
|
export type ASTBlock = PugAST<ASTNode>;
|
|
3
|
-
export type ASTNode = ASTTagNode | ASTTextNode |
|
|
3
|
+
export type ASTNode = ASTTagNode | ASTTextNode | 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
|
-
export type ASTEmptyPipeNode = PugASTEmptyPipeNode & AdditionalASTData;
|
|
7
6
|
export type ASTCodeNode = PugASTCodeNode & AdditionalASTData;
|
|
8
7
|
export type ASTComment = PugASTCommentNode & AdditionalASTData;
|
|
9
8
|
export type ASTBlockComment = PugASTBlockCommentNode<ASTBlock> & AdditionalASTData;
|
|
@@ -56,12 +55,6 @@ type PugASTTextNode = {
|
|
|
56
55
|
line: number;
|
|
57
56
|
column: number;
|
|
58
57
|
};
|
|
59
|
-
type PugASTEmptyPipeNode = {
|
|
60
|
-
type: 'EmptyPipe';
|
|
61
|
-
val: string;
|
|
62
|
-
line: number;
|
|
63
|
-
column: number;
|
|
64
|
-
};
|
|
65
58
|
type PugASTCodeNode = {
|
|
66
59
|
type: 'Code';
|
|
67
60
|
val: string;
|
package/lib/pug-parser/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import lexer from 'pug-lexer';
|
|
|
2
2
|
// @ts-ignore
|
|
3
3
|
import parser from 'pug-parser';
|
|
4
4
|
import { getOffsetFromLineAndCol } from '../utils/get-offset-from-line-and-col.js';
|
|
5
|
+
import { getOffsetsFromCode } from '@markuplint/parser-utils/location';
|
|
5
6
|
export function pugParse(pug, useOffset = false) {
|
|
6
7
|
let lexOrigin = lexer(pug);
|
|
7
8
|
/**
|
|
@@ -284,41 +285,8 @@ tokens, pug) {
|
|
|
284
285
|
nodes.push(textNode);
|
|
285
286
|
break;
|
|
286
287
|
}
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
// console.log({ v: node.val, r: raw });
|
|
290
|
-
/**
|
|
291
|
-
*
|
|
292
|
-
* Empty piped line
|
|
293
|
-
*
|
|
294
|
-
* @see https://pugjs.org/language/plain-text.html#recommended-solutions
|
|
295
|
-
*/
|
|
296
|
-
if (raw === '|') {
|
|
297
|
-
const newNode = {
|
|
298
|
-
type: 'EmptyPipe',
|
|
299
|
-
raw,
|
|
300
|
-
val: node.val,
|
|
301
|
-
offset,
|
|
302
|
-
endOffset,
|
|
303
|
-
line,
|
|
304
|
-
endLine,
|
|
305
|
-
column,
|
|
306
|
-
endColumn,
|
|
307
|
-
};
|
|
308
|
-
nodes.push(newNode);
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
const textNode = {
|
|
312
|
-
type: node.type,
|
|
313
|
-
raw,
|
|
314
|
-
offset,
|
|
315
|
-
endOffset,
|
|
316
|
-
line,
|
|
317
|
-
endLine,
|
|
318
|
-
column,
|
|
319
|
-
endColumn,
|
|
320
|
-
};
|
|
321
|
-
nodes.push(textNode);
|
|
288
|
+
const textNodes = getRawTextAndLocationEnd(node.val, offset, line, column, tokens, pug);
|
|
289
|
+
nodes.push(...textNodes);
|
|
322
290
|
continue;
|
|
323
291
|
}
|
|
324
292
|
case 'Doctype': {
|
|
@@ -592,29 +560,65 @@ tokens) {
|
|
|
592
560
|
}
|
|
593
561
|
function getRawTextAndLocationEnd(val, offset, line, column,
|
|
594
562
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
595
|
-
tokens,
|
|
596
|
-
|
|
563
|
+
tokens, pug) {
|
|
564
|
+
if (val.trim() === '') {
|
|
565
|
+
return [];
|
|
566
|
+
}
|
|
567
|
+
let depth = 0;
|
|
568
|
+
let endLine = line;
|
|
569
|
+
let endColumn = column;
|
|
570
|
+
const result = [];
|
|
597
571
|
for (const token of tokens) {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
572
|
+
if (token.loc.start.line < line || (token.loc.start.line === line && token.loc.start.column < column)) {
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
switch (token.type) {
|
|
576
|
+
case 'text':
|
|
577
|
+
case 'text-html': {
|
|
578
|
+
endLine = token.loc.end.line;
|
|
579
|
+
endColumn = token.loc.end.column;
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
case 'indent': {
|
|
583
|
+
depth++;
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
case 'outdent': {
|
|
587
|
+
depth--;
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
590
|
+
case 'newline': {
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
default: {
|
|
594
|
+
depth = -1;
|
|
595
|
+
break;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const rawLoc = getOffsetsFromCode(pug, line, column, endLine, endColumn);
|
|
599
|
+
const raw = pug.slice(offset, rawLoc.endOffset);
|
|
600
|
+
if (raw.trim().startsWith('|')) {
|
|
601
|
+
// It is a piped text
|
|
602
|
+
break;
|
|
603
|
+
}
|
|
604
|
+
if (raw !== '') {
|
|
605
|
+
result.push({
|
|
606
|
+
type: 'Text',
|
|
607
|
+
raw,
|
|
608
|
+
offset,
|
|
609
|
+
endOffset: rawLoc.endOffset,
|
|
610
|
+
line,
|
|
611
|
+
endLine,
|
|
612
|
+
column,
|
|
613
|
+
endColumn,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
offset = rawLoc.endOffset;
|
|
617
|
+
line = endLine;
|
|
618
|
+
column = endColumn;
|
|
619
|
+
if (depth <= -1) {
|
|
620
|
+
break;
|
|
612
621
|
}
|
|
613
|
-
beforeNewlineToken = token;
|
|
614
622
|
}
|
|
615
|
-
return
|
|
616
|
-
endOffset: offset + val.length,
|
|
617
|
-
endLine: line,
|
|
618
|
-
endColumn: column + val.length,
|
|
619
|
-
};
|
|
623
|
+
return result;
|
|
620
624
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/pug-parser",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.10",
|
|
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.
|
|
24
|
+
"@markuplint/html-parser": "4.6.10",
|
|
25
|
+
"@markuplint/ml-ast": "4.4.7",
|
|
26
|
+
"@markuplint/parser-utils": "4.7.1",
|
|
27
27
|
"pug-lexer": "5.0.1",
|
|
28
28
|
"pug-parser": "6.0.0"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "fab5b494f0bdc491aa83cb2c8722738d557fbefd"
|
|
31
31
|
}
|