@markuplint/pug-parser 3.10.0 → 3.12.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/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { parse } from './parse';
2
- export declare const endTag = "never";
2
+ export declare const endTag = 'never';
package/lib/parse.js CHANGED
@@ -127,12 +127,9 @@ class Parser {
127
127
  offsetLine: originNode.line - 1,
128
128
  offsetColumn: originNode.column - 1,
129
129
  });
130
- const nodes = htmlDoc.nodeList;
131
- for (const node of nodes) {
132
- if (!node.parentNode) {
133
- node.parentNode = parentNode;
134
- }
135
- }
130
+ const nodes = htmlDoc.nodeList.filter(node => {
131
+ return node.parentNode == null && node.type !== 'endtag';
132
+ });
136
133
  return nodes;
137
134
  }
138
135
  case 'Comment': {
@@ -1,7 +1,21 @@
1
1
  export declare function pugParse(pug: string): ASTBlock;
2
2
  export type ASTBlock = PugAST<ASTNode>;
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;
3
+ export type ASTNode =
4
+ | ASTTagNode
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;
5
19
  export type ASTTextNode = Omit<PugASTTextNode, 'val'> & AdditionalASTData;
6
20
  export type ASTCodeNode = PugASTCodeNode & AdditionalASTData;
7
21
  export type ASTComment = PugASTCommentNode & AdditionalASTData;
@@ -12,135 +26,135 @@ export type ASTMixinSlotNode = PugASTMixinSlotNode & AdditionalASTData;
12
26
  export type ASTFilterNode = PugASTFilterNode<ASTAttr, ASTBlock> & AdditionalASTData;
13
27
  export type ASTEachNode = PugASTEachNode<ASTBlock> & AdditionalASTData;
14
28
  export type ASTConditionalNode = Omit<PugASTConditionalNode<ASTBlock>, 'consequent' | 'alternate'> & {
15
- block: ASTBlock;
29
+ block: ASTBlock;
16
30
  } & AdditionalASTData;
17
31
  export type ASTCaseNode = PugASTCaseNode<ASTBlock> & AdditionalASTData;
18
32
  export type ASTCaseWhenNode = PugASTCaseWhenNode<ASTBlock> & AdditionalASTData;
19
33
  export type ASTAttr = PugASTAttr & AdditionalASTData;
20
34
  type AdditionalASTData = {
21
- raw: string;
22
- offset: number;
23
- endOffset: number;
24
- endLine: number;
25
- endColumn: number;
35
+ raw: string;
36
+ offset: number;
37
+ endOffset: number;
38
+ endLine: number;
39
+ endColumn: number;
26
40
  };
27
41
  interface PugAST<N> {
28
- type: 'Block';
29
- nodes: N[];
30
- line: number;
42
+ type: 'Block';
43
+ nodes: N[];
44
+ line: number;
31
45
  }
32
46
  type PugASTTagNode<A, B> = {
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;
47
+ type: 'Tag';
48
+ name: string;
49
+ selfClosing: boolean;
50
+ attrs: A[];
51
+ attributeBlocks: never[];
52
+ isInline: boolean;
53
+ line: number;
54
+ column: number;
55
+ block: B;
42
56
  };
43
57
  type PugASTTextNode = {
44
- type: 'Text';
45
- val: string;
46
- isHtml?: true;
47
- line: number;
48
- column: number;
58
+ type: 'Text';
59
+ val: string;
60
+ isHtml?: true;
61
+ line: number;
62
+ column: number;
49
63
  };
50
64
  type PugASTCodeNode = {
51
- type: 'Code';
52
- val: string;
53
- buffer: boolean;
54
- mustEscape: boolean;
55
- isInline: boolean;
56
- line: number;
57
- column: number;
65
+ type: 'Code';
66
+ val: string;
67
+ buffer: boolean;
68
+ mustEscape: boolean;
69
+ isInline: boolean;
70
+ line: number;
71
+ column: number;
58
72
  };
59
73
  type PugASTCommentNode = {
60
- type: 'Comment';
61
- val: string;
62
- buffer: boolean;
63
- line: number;
64
- column: number;
74
+ type: 'Comment';
75
+ val: string;
76
+ buffer: boolean;
77
+ line: number;
78
+ column: number;
65
79
  };
66
80
  type PugASTDoctypeNode = {
67
- type: 'Doctype';
68
- val: string;
69
- line: number;
70
- column: number;
81
+ type: 'Doctype';
82
+ val: string;
83
+ line: number;
84
+ column: number;
71
85
  };
72
86
  type PugASTIncludeNode<B> = {
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;
87
+ type: 'Include';
88
+ file: {
89
+ type: 'FileReference';
90
+ path: string;
91
+ line: number;
92
+ column: number;
93
+ };
94
+ block: B;
95
+ line: number;
96
+ column: number;
83
97
  };
84
98
  type PugASTEachNode<B> = {
85
- type: 'Each';
86
- obj: string;
87
- val: string;
88
- key: string | null;
89
- block: B;
90
- line: number;
91
- column: number;
99
+ type: 'Each';
100
+ obj: string;
101
+ val: string;
102
+ key: string | null;
103
+ block: B;
104
+ line: number;
105
+ column: number;
92
106
  };
93
107
  type PugASTMixinNode<A, B> = {
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;
108
+ type: 'Mixin';
109
+ name: string;
110
+ args: string;
111
+ call: boolean;
112
+ block: B | null;
113
+ attrs?: A[];
114
+ attributeBlocks: never[];
115
+ line: number;
116
+ column: number;
103
117
  };
104
118
  type PugASTMixinSlotNode = {
105
- type: 'MixinBlock';
106
- line: number;
107
- column: number;
119
+ type: 'MixinBlock';
120
+ line: number;
121
+ column: number;
108
122
  };
109
123
  type PugASTFilterNode<A, B> = {
110
- type: 'Filter';
111
- name: string;
112
- block: B;
113
- attrs: A[];
114
- line: number;
115
- column: number;
124
+ type: 'Filter';
125
+ name: string;
126
+ block: B;
127
+ attrs: A[];
128
+ line: number;
129
+ column: number;
116
130
  };
117
131
  type PugASTConditionalNode<B> = {
118
- type: 'Conditional';
119
- test: string;
120
- consequent: B;
121
- alternate?: B | PugASTConditionalNode<B>;
122
- line: number;
123
- column: number;
132
+ type: 'Conditional';
133
+ test: string;
134
+ consequent: B;
135
+ alternate?: B | PugASTConditionalNode<B>;
136
+ line: number;
137
+ column: number;
124
138
  };
125
139
  type PugASTCaseNode<B> = {
126
- type: 'Case';
127
- expr: string;
128
- block: B;
129
- line: number;
130
- column: number;
140
+ type: 'Case';
141
+ expr: string;
142
+ block: B;
143
+ line: number;
144
+ column: number;
131
145
  };
132
146
  type PugASTCaseWhenNode<B> = {
133
- type: 'When';
134
- expr: string;
135
- block: B;
136
- line: number;
137
- column: number;
147
+ type: 'When';
148
+ expr: string;
149
+ block: B;
150
+ line: number;
151
+ column: number;
138
152
  };
139
153
  type PugASTAttr = {
140
- name: string;
141
- val: string | true;
142
- mustEscape: boolean;
143
- line: number;
144
- column: number;
154
+ name: string;
155
+ val: string | true;
156
+ mustEscape: boolean;
157
+ line: number;
158
+ column: number;
145
159
  };
146
160
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/pug-parser",
3
- "version": "3.10.0",
3
+ "version": "3.12.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.11.0",
19
+ "@markuplint/html-parser": "3.13.0",
20
20
  "@markuplint/ml-ast": "3.2.0",
21
- "@markuplint/parser-utils": "3.11.0",
21
+ "@markuplint/parser-utils": "3.13.0",
22
22
  "pug-lexer": "^5.0.1",
23
23
  "pug-parser": "^6.0.0",
24
24
  "tslib": "^2.6.2"
25
25
  },
26
- "gitHead": "ef31aef8f2fff319d0f692feead332ec5fc5c7cf"
26
+ "gitHead": "b37b749d7ac0f9e6cbd022ee7031bc020c6677d3"
27
27
  }
@@ -554,3 +554,32 @@ html
554
554
  expect(doc.nodeList[2].namespace).toBe('http://www.w3.org/2000/svg');
555
555
  });
556
556
  });
557
+
558
+ describe('Issues', () => {
559
+ test('#1221', () => {
560
+ const doc = parse('html: p <span>text</span>');
561
+ const map = nodeListToDebugMaps(doc.nodeList);
562
+ expect(map).toStrictEqual([
563
+ '[1:1]>[1:5](0,4)html: html',
564
+ '[1:7]>[1:8](6,7)p: p',
565
+ '[1:9]>[1:15](8,14)span: <span>',
566
+ '[1:15]>[1:19](14,18)#text: text',
567
+ '[1:19]>[1:26](18,25)span: </span>',
568
+ ]);
569
+
570
+ const html = doc.nodeList[0];
571
+ const p = doc.nodeList[1];
572
+ const span = doc.nodeList[2];
573
+ const text = doc.nodeList[3];
574
+ const spanClose = doc.nodeList[4];
575
+
576
+ expect(html.uuid).toBe(p.parentNode.uuid);
577
+ expect(html.childNodes.length).toBe(1);
578
+ expect(p.uuid).toBe(html.childNodes[0].uuid);
579
+ expect(p.childNodes.length).toBe(1);
580
+ expect(span.uuid).toBe(p.childNodes[0].uuid);
581
+ expect(span.childNodes.length).toBe(1);
582
+ expect(text.uuid).toBe(span.childNodes[0].uuid);
583
+ expect(spanClose.uuid).toBe(span.pearNode.uuid);
584
+ });
585
+ });