@markuplint/astro-parser 3.10.0 → 4.0.0-alpha.2

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.
@@ -1,3 +1,3 @@
1
- import type { RootNode } from '@astrojs/compiler';
2
- export type { RootNode, ElementNode, CustomElementNode, ComponentNode, FragmentNode, AttributeNode, Node, } from '@astrojs/compiler';
1
+ import type { RootNode } from '@astrojs/compiler/types';
2
+ export type { RootNode, ElementNode, CustomElementNode, ComponentNode, FragmentNode, AttributeNode, Node, } from '@astrojs/compiler/types';
3
3
  export declare function astroParse(code: string): RootNode;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.astroParse = void 0;
4
- const parser_utils_1 = require("@markuplint/parser-utils");
5
- const astro_eslint_parser_1 = require("astro-eslint-parser");
6
- function astroParse(code) {
7
- const { result } = (0, astro_eslint_parser_1.parseTemplate)(code);
1
+ import { ParserError } from '@markuplint/parser-utils';
2
+ import { parseTemplate } from 'astro-eslint-parser';
3
+ export function astroParse(code) {
4
+ const { result } = parseTemplate(code);
8
5
  if (result.diagnostics[0]) {
9
6
  const error = result.diagnostics[0];
10
- throw new parser_utils_1.ParserError(error.text, {
7
+ throw new ParserError(error.text, {
11
8
  line: error.location.line,
12
9
  col: error.location.column,
13
10
  });
14
11
  }
15
12
  return result.ast;
16
13
  }
17
- exports.astroParse = astroParse;
@@ -1,3 +1,3 @@
1
- import type { AttributeNode } from './astro-parser';
1
+ import type { AttributeNode } from './astro-parser.js';
2
2
  import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
3
3
  export declare function attrTokenizer(attr: AttributeNode, nextAttr: AttributeNode | null, rawHtml: string, startTag: string, startTagEndOffset: number): MLASTHTMLAttr;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.attrTokenizer = void 0;
4
- const parser_utils_1 = require("@markuplint/parser-utils");
1
+ import { defaultValueDelimiters, getSpaceBefore, parseAttr, sliceFragment } from '@markuplint/parser-utils';
5
2
  const mustacheTag = {
6
3
  start: '{',
7
4
  end: '}',
8
5
  };
9
- function attrTokenizer(
6
+ export function attrTokenizer(
10
7
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
11
8
  attr,
12
9
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
13
10
  nextAttr, rawHtml, startTag, startTagEndOffset) {
14
- var _a, _b, _c;
15
11
  if (!attr.position) {
16
12
  throw new TypeError("Attr doesn't have position");
17
13
  }
@@ -26,15 +22,15 @@ nextAttr, rawHtml, startTag, startTagEndOffset) {
26
22
  if (nextAttr.position.end) {
27
23
  throw new TypeError('NextAttr Node may is an attribute because it has end position');
28
24
  }
29
- nextAttrBeforeSpaceOffset = (0, parser_utils_1.getSpaceBefore)(nextAttr.position.start.offset, rawHtml).startOffset;
25
+ nextAttrBeforeSpaceOffset = getSpaceBefore(nextAttr.position.start.offset, rawHtml).startOffset;
30
26
  }
31
27
  else {
32
- const close = (_b = (_a = /(\/?>)$/.exec(startTag)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '';
28
+ const close = /(\/?>)$/.exec(startTag)?.[1] ?? '';
33
29
  nextAttrBeforeSpaceOffset = startTagEndOffset - close.length;
34
30
  }
35
- const { raw, startOffset } = (0, parser_utils_1.sliceFragment)(rawHtml, attr.position.start.offset, nextAttrBeforeSpaceOffset);
36
- const result = (0, parser_utils_1.parseAttr)(raw, startOffset, rawHtml, {
37
- valueDelimiters: [...parser_utils_1.defaultValueDelimiters, mustacheTag],
31
+ const { raw, startOffset } = sliceFragment(rawHtml, attr.position.start.offset, nextAttrBeforeSpaceOffset);
32
+ const result = parseAttr(raw, startOffset, rawHtml, {
33
+ valueDelimiters: [...defaultValueDelimiters, mustacheTag],
38
34
  });
39
35
  if (result.startQuote.raw === mustacheTag.start) {
40
36
  result.isDynamicValue = true;
@@ -44,7 +40,7 @@ nextAttr, rawHtml, startTag, startTagEndOffset) {
44
40
  *
45
41
  * @see https://docs.astro.build/en/reference/directives-reference/
46
42
  */
47
- const [, directive] = (_c = result.name.raw.match(/^([^:]+):([^:]+)$/)) !== null && _c !== void 0 ? _c : [];
43
+ const [, directive] = result.name.raw.match(/^([^:]+):([^:]+)$/) ?? [];
48
44
  if (directive) {
49
45
  const lowerCaseDirectiveName = directive.toLowerCase();
50
46
  switch (lowerCaseDirectiveName) {
@@ -59,4 +55,3 @@ nextAttr, rawHtml, startTag, startTagEndOffset) {
59
55
  }
60
56
  return result;
61
57
  }
62
- exports.attrTokenizer = attrTokenizer;
package/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { parse } from './parse';
1
+ export { parse } from './parse.js';
2
2
  export declare const endTag = "xml";
package/lib/index.js CHANGED
@@ -1,6 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.endTag = exports.parse = void 0;
4
- var parse_1 = require("./parse");
5
- Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } });
6
- exports.endTag = 'xml';
1
+ export { parse } from './parse.js';
2
+ export const endTag = 'xml';
package/lib/parse.js CHANGED
@@ -1,18 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parse = void 0;
4
- const html_parser_1 = require("@markuplint/html-parser");
5
- const parser_utils_1 = require("@markuplint/parser-utils");
6
- const astro_parser_1 = require("./astro-parser");
7
- const attr_tokenizer_1 = require("./attr-tokenizer");
8
- const parse = (rawCode, options = {}) => {
9
- var _a, _b;
10
- const ast = (0, astro_parser_1.astroParse)(rawCode);
1
+ import { parseRawTag, parse as htmlParse } from '@markuplint/html-parser';
2
+ import { flattenNodes, detectElementType, getEndCol, getEndLine, sliceFragment, uuid } from '@markuplint/parser-utils';
3
+ import { astroParse } from './astro-parser.js';
4
+ import { attrTokenizer } from './attr-tokenizer.js';
5
+ export const parse = (rawCode, options = {}) => {
6
+ const ast = astroParse(rawCode);
11
7
  const htmlRawNodeList = traverse(ast, null, 'http://www.w3.org/1999/xhtml', rawCode, 0, options);
12
- const firstOffset = (_b = (_a = htmlRawNodeList[0]) === null || _a === void 0 ? void 0 : _a.startOffset) !== null && _b !== void 0 ? _b : 0;
8
+ const firstOffset = htmlRawNodeList[0]?.startOffset ?? 0;
13
9
  if (firstOffset > 0) {
14
10
  const head = rawCode.slice(0, firstOffset);
15
- const ast = (0, html_parser_1.parse)(head, {
11
+ const ast = htmlParse(head, {
16
12
  ...options,
17
13
  ignoreFrontMatter: true,
18
14
  });
@@ -21,13 +17,12 @@ const parse = (rawCode, options = {}) => {
21
17
  });
22
18
  htmlRawNodeList.unshift(...headNodes);
23
19
  }
24
- const nodeList = (0, parser_utils_1.flattenNodes)(htmlRawNodeList, rawCode);
20
+ const nodeList = flattenNodes(htmlRawNodeList, rawCode);
25
21
  return {
26
22
  nodeList,
27
23
  isFragment: true,
28
24
  };
29
25
  };
30
- exports.parse = parse;
31
26
  function traverse(
32
27
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
33
28
  rootNode, parentNode = null, scopeNS, rawHtml, offset, options, inExpression) {
@@ -65,17 +60,16 @@ originNode,
65
60
  prevNode,
66
61
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
67
62
  parentNode, scopeNS, rawHtml, offset = 0, options, inExpression) {
68
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
69
63
  if (!originNode.position) {
70
64
  throw new TypeError("Node doesn't have position");
71
65
  }
72
66
  const nextNode = null;
73
67
  const startOffset = originNode.position.start.offset + offset;
74
- const endOffset = ((_b = (_a = originNode.position.end) === null || _a === void 0 ? void 0 : _a.offset) !== null && _b !== void 0 ? _b : originNode.position.start.offset) + offset;
75
- const { startLine, endLine, startCol, endCol, raw } = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, endOffset);
68
+ const endOffset = (originNode.position.end?.offset ?? originNode.position.start.offset) + offset;
69
+ const { startLine, endLine, startCol, endCol, raw } = sliceFragment(rawHtml, startOffset, endOffset);
76
70
  if (scopeNS === 'http://www.w3.org/1999/xhtml' &&
77
71
  originNode.type === 'element' &&
78
- ((_c = originNode.name) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === 'svg') {
72
+ originNode.name?.toLowerCase() === 'svg') {
79
73
  scopeNS = 'http://www.w3.org/2000/svg';
80
74
  }
81
75
  else if (scopeNS === 'http://www.w3.org/2000/svg' && parentNode && parentNode.nodeName === 'foreignObject') {
@@ -87,7 +81,7 @@ parentNode, scopeNS, rawHtml, offset = 0, options, inExpression) {
87
81
  return null;
88
82
  }
89
83
  const node = {
90
- uuid: (0, parser_utils_1.uuid)(),
84
+ uuid: uuid(),
91
85
  raw,
92
86
  startOffset,
93
87
  endOffset,
@@ -116,17 +110,17 @@ parentNode, scopeNS, rawHtml, offset = 0, options, inExpression) {
116
110
  const firstChild = originNode.children[0];
117
111
  const lastChild = originNode.children[originNode.children.length - 1];
118
112
  if (firstChild && lastChild && firstChild !== lastChild) {
119
- _endOffset = (_f = (_e = (_d = firstChild.position) === null || _d === void 0 ? void 0 : _d.end) === null || _e === void 0 ? void 0 : _e.offset) !== null && _f !== void 0 ? _f : endOffset;
120
- const startLoc = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, _endOffset);
113
+ _endOffset = firstChild.position?.end?.offset ?? endOffset;
114
+ const startLoc = sliceFragment(rawHtml, startOffset, _endOffset);
121
115
  _startLine = startLoc.startLine;
122
116
  _endLine = startLoc.endLine;
123
117
  _startCol = startLoc.startCol;
124
118
  _endCol = startLoc.endCol;
125
119
  _raw = startLoc.raw;
126
- const closeStartOffset = (_h = (_g = lastChild.position) === null || _g === void 0 ? void 0 : _g.start.offset) !== null && _h !== void 0 ? _h : startOffset;
127
- const closeLoc = (0, parser_utils_1.sliceFragment)(rawHtml, closeStartOffset, endOffset);
120
+ const closeStartOffset = lastChild.position?.start.offset ?? startOffset;
121
+ const closeLoc = sliceFragment(rawHtml, closeStartOffset, endOffset);
128
122
  closeExpression = {
129
- uuid: (0, parser_utils_1.uuid)(),
123
+ uuid: uuid(),
130
124
  raw: closeLoc.raw,
131
125
  startOffset: closeStartOffset,
132
126
  endOffset: closeLoc.endOffset,
@@ -144,7 +138,7 @@ parentNode, scopeNS, rawHtml, offset = 0, options, inExpression) {
144
138
  };
145
139
  }
146
140
  const node = {
147
- uuid: (0, parser_utils_1.uuid)(),
141
+ uuid: uuid(),
148
142
  raw: _raw,
149
143
  startOffset,
150
144
  endOffset: _endOffset,
@@ -170,7 +164,7 @@ parentNode, scopeNS, rawHtml, offset = 0, options, inExpression) {
170
164
  }
171
165
  case 'comment': {
172
166
  return {
173
- uuid: (0, parser_utils_1.uuid)(),
167
+ uuid: uuid(),
174
168
  raw,
175
169
  startOffset,
176
170
  endOffset,
@@ -191,9 +185,9 @@ parentNode, scopeNS, rawHtml, offset = 0, options, inExpression) {
191
185
  case 'custom-element':
192
186
  case 'fragment':
193
187
  case 'element': {
194
- if (((_j = originNode.name) === null || _j === void 0 ? void 0 : _j.toLowerCase()) === '!doctype') {
188
+ if (originNode.name?.toLowerCase() === '!doctype') {
195
189
  return {
196
- uuid: (0, parser_utils_1.uuid)(),
190
+ uuid: uuid(),
197
191
  raw,
198
192
  name: originNode.name,
199
193
  publicId: '',
@@ -229,7 +223,6 @@ parentNode,
229
223
  prevNode,
230
224
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
231
225
  nextNode, offset, options) {
232
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
233
226
  if (!originNode.position) {
234
227
  throw new TypeError("Node doesn't have position");
235
228
  }
@@ -237,14 +230,14 @@ nextNode, offset, options) {
237
230
  let childrenStart;
238
231
  let childrenEnd;
239
232
  if (originNode.children[0]) {
240
- childrenStart = ((_c = (_b = (_a = originNode.children[0].position) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.offset) !== null && _c !== void 0 ? _c : 0) + offset;
241
- childrenEnd = ((_g = (_f = (_e = (_d = originNode.children[originNode.children.length - 1]) === null || _d === void 0 ? void 0 : _d.position) === null || _e === void 0 ? void 0 : _e.end) === null || _f === void 0 ? void 0 : _f.offset) !== null && _g !== void 0 ? _g : 0) + offset;
233
+ childrenStart = (originNode.children[0].position?.start?.offset ?? 0) + offset;
234
+ childrenEnd = (originNode.children[originNode.children.length - 1]?.position?.end?.offset ?? 0) + offset;
242
235
  const startTagStartOffset = originNode.position.start.offset + offset;
243
236
  const startTagEndOffset = childrenStart;
244
237
  startTagRaw = rawHtml.slice(startTagStartOffset, startTagEndOffset);
245
238
  }
246
239
  else {
247
- childrenStart = offset + ((_k = (_j = (_h = originNode.position.end) === null || _h === void 0 ? void 0 : _h.offset) !== null && _j !== void 0 ? _j : nextNode === null || nextNode === void 0 ? void 0 : nextNode.endOffset) !== null && _k !== void 0 ? _k : rawHtml.length - offset);
240
+ childrenStart = offset + (originNode.position.end?.offset ?? nextNode?.endOffset ?? rawHtml.length - offset);
248
241
  childrenEnd = childrenStart;
249
242
  const startTagStartOffset = originNode.position.start.offset + offset;
250
243
  let startTagEndOffset = childrenStart;
@@ -276,15 +269,15 @@ nextNode, offset, options) {
276
269
  // childrenEnd,
277
270
  // });
278
271
  }
279
- const tagTokens = (0, html_parser_1.parseRawTag)(startTagRaw, startLine, startCol, startOffset);
272
+ const tagTokens = parseRawTag(startTagRaw, startLine, startCol, startOffset);
280
273
  const tagName = tagTokens.tagName;
281
274
  let endTag = null;
282
- if (childrenEnd < ((_m = (_l = originNode.position.end) === null || _l === void 0 ? void 0 : _l.offset) !== null && _m !== void 0 ? _m : 0) + offset) {
283
- const endTagLoc = (0, parser_utils_1.sliceFragment)(rawHtml, childrenEnd, ((_p = (_o = originNode.position.end) === null || _o === void 0 ? void 0 : _o.offset) !== null && _p !== void 0 ? _p : 0) + offset);
284
- const endTagTokens = (0, html_parser_1.parseRawTag)(endTagLoc.raw, endTagLoc.startLine, endTagLoc.startCol, endTagLoc.startOffset);
275
+ if (childrenEnd < (originNode.position.end?.offset ?? 0) + offset) {
276
+ const endTagLoc = sliceFragment(rawHtml, childrenEnd, (originNode.position.end?.offset ?? 0) + offset);
277
+ const endTagTokens = parseRawTag(endTagLoc.raw, endTagLoc.startLine, endTagLoc.startCol, endTagLoc.startOffset);
285
278
  const endTagName = endTagTokens.tagName;
286
279
  endTag = {
287
- uuid: (0, parser_utils_1.uuid)(),
280
+ uuid: uuid(),
288
281
  raw: endTagLoc.raw,
289
282
  startOffset: endTagLoc.startOffset,
290
283
  endOffset: endTagLoc.endOffset,
@@ -307,24 +300,21 @@ nextNode, offset, options) {
307
300
  };
308
301
  }
309
302
  const startTag = {
310
- uuid: (0, parser_utils_1.uuid)(),
303
+ uuid: uuid(),
311
304
  raw: startTagRaw,
312
305
  startOffset,
313
306
  endOffset: startOffset + startTagRaw.length,
314
307
  startLine,
315
- endLine: (0, parser_utils_1.getEndLine)(startTagRaw, startLine),
308
+ endLine: getEndLine(startTagRaw, startLine),
316
309
  startCol,
317
- endCol: (0, parser_utils_1.getEndCol)(startTagRaw, startCol),
310
+ endCol: getEndCol(startTagRaw, startCol),
318
311
  nodeName: tagName,
319
312
  type: 'starttag',
320
313
  namespace: scopeNS,
321
- elementType: (0, parser_utils_1.detectElementType)(tagName, options === null || options === void 0 ? void 0 : options.authoredElementName, /^[A-Z]|\./),
314
+ elementType: detectElementType(tagName, options?.authoredElementName, /^[A-Z]|\./),
322
315
  attributes: originNode.attributes.map((
323
316
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
324
- attr, i) => {
325
- var _a;
326
- return (0, attr_tokenizer_1.attrTokenizer)(attr, (_a = originNode.attributes[i + 1]) !== null && _a !== void 0 ? _a : null, rawHtml, startTagRaw, startOffset + startTagRaw.length);
327
- }),
317
+ attr, i) => attrTokenizer(attr, originNode.attributes[i + 1] ?? null, rawHtml, startTagRaw, startOffset + startTagRaw.length)),
328
318
  hasSpreadAttr: false,
329
319
  parentNode,
330
320
  prevNode,
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@markuplint/astro-parser",
3
- "version": "3.10.0",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "astro parser for markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
7
7
  "license": "MIT",
8
8
  "private": false,
9
- "main": "lib/index.js",
10
- "types": "lib/index.d.ts",
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./lib/index.js"
13
+ }
14
+ },
15
+ "types": "./lib/index.d.ts",
11
16
  "publishConfig": {
12
17
  "access": "public"
13
18
  },
@@ -17,11 +22,11 @@
17
22
  },
18
23
  "dependencies": {
19
24
  "@astrojs/parser": "0.22.2",
20
- "@markuplint/html-parser": "3.11.0",
21
- "@markuplint/ml-ast": "3.2.0",
22
- "@markuplint/parser-utils": "3.11.0",
23
- "astro-eslint-parser": "^0.15.0",
25
+ "@markuplint/html-parser": "4.0.0-alpha.2",
26
+ "@markuplint/ml-ast": "4.0.0-alpha.2",
27
+ "@markuplint/parser-utils": "4.0.0-alpha.2",
28
+ "astro-eslint-parser": "^0.16.0",
24
29
  "tslib": "^2.6.2"
25
30
  },
26
- "gitHead": "ef31aef8f2fff319d0f692feead332ec5fc5c7cf"
31
+ "gitHead": "51ad52c760435641f9bff8685707d8178b0787eb"
27
32
  }
@@ -1,456 +0,0 @@
1
- const { astroParse } = require('../lib/astro-parser');
2
-
3
- it('Basic', () => {
4
- const ast = astroParse(`---
5
- const name = "World";
6
- ---
7
- <!-- Comment -->
8
- <style>
9
- div {
10
- color: red;
11
- }
12
- </style>
13
- <div data-attr="v">Hello {name}!</div>
14
- `);
15
- expect(ast).toStrictEqual(
16
- expect.objectContaining({
17
- children: [
18
- {
19
- position: {
20
- end: {
21
- column: 4,
22
- line: 3,
23
- offset: 29,
24
- },
25
- start: {
26
- column: 1,
27
- line: 1,
28
- offset: 0,
29
- },
30
- },
31
- type: 'frontmatter',
32
- value: '\nconst name = "World";\n',
33
- },
34
- {
35
- position: {
36
- end: {
37
- column: 17,
38
- line: 4,
39
- offset: 46,
40
- },
41
- start: {
42
- column: 5,
43
- line: 4,
44
- offset: 30,
45
- },
46
- },
47
- type: 'comment',
48
- value: ' Comment ',
49
- },
50
- {
51
- attributes: [],
52
- children: [
53
- {
54
- position: {
55
- end: {
56
- column: 1,
57
- line: 9,
58
- offset: 79,
59
- },
60
- start: {
61
- column: 8,
62
- line: 5,
63
- offset: 54,
64
- },
65
- },
66
- type: 'text',
67
- value: '\ndiv {\n color: red;\n}\n',
68
- },
69
- ],
70
- name: 'style',
71
- position: {
72
- end: {
73
- column: 9,
74
- line: 9,
75
- offset: 87,
76
- },
77
- start: {
78
- column: 1,
79
- line: 5,
80
- offset: 47,
81
- },
82
- },
83
- type: 'element',
84
- },
85
- {
86
- position: {
87
- end: {
88
- column: 1,
89
- line: 10,
90
- offset: 88,
91
- },
92
- start: {
93
- column: 9,
94
- line: 9,
95
- offset: 87,
96
- },
97
- },
98
- type: 'text',
99
- value: '\n',
100
- },
101
- {
102
- attributes: [
103
- {
104
- kind: 'quoted',
105
- name: 'data-attr',
106
- position: {
107
- start: {
108
- column: 6,
109
- line: 10,
110
- offset: 93,
111
- },
112
- },
113
- raw: '"v"',
114
- type: 'attribute',
115
- value: 'v',
116
- },
117
- ],
118
- children: [
119
- {
120
- position: {
121
- end: {
122
- column: 26,
123
- line: 10,
124
- offset: 113,
125
- },
126
- start: {
127
- column: 20,
128
- line: 10,
129
- offset: 107,
130
- },
131
- },
132
- type: 'text',
133
- value: 'Hello ',
134
- },
135
- {
136
- children: [
137
- {
138
- position: {
139
- end: {
140
- column: 31,
141
- line: 10,
142
- offset: 118,
143
- },
144
- start: {
145
- column: 27,
146
- line: 10,
147
- offset: 114,
148
- },
149
- },
150
- type: 'text',
151
- value: 'name',
152
- },
153
- ],
154
- position: {
155
- end: {
156
- column: 9,
157
- line: 11,
158
- offset: 119,
159
- },
160
- start: {
161
- column: 25,
162
- line: 10,
163
- offset: 113,
164
- },
165
- },
166
- type: 'expression',
167
- },
168
- {
169
- position: {
170
- end: {
171
- column: 33,
172
- line: 10,
173
- offset: 120,
174
- },
175
- start: {
176
- column: 32,
177
- line: 10,
178
- offset: 119,
179
- },
180
- },
181
- type: 'text',
182
- value: '!',
183
- },
184
- ],
185
- name: 'div',
186
- position: {
187
- end: {
188
- column: 39,
189
- line: 10,
190
- offset: 126,
191
- },
192
- start: {
193
- column: 1,
194
- line: 10,
195
- offset: 88,
196
- },
197
- },
198
- type: 'element',
199
- },
200
- {
201
- position: {
202
- end: {
203
- column: 1,
204
- line: 11,
205
- offset: 127,
206
- },
207
- start: {
208
- column: 39,
209
- line: 10,
210
- offset: 126,
211
- },
212
- },
213
- type: 'text',
214
- value: '\n',
215
- },
216
- ],
217
- type: 'root',
218
- }),
219
- );
220
- });
221
-
222
- it('Attr and Template Directive', () => {
223
- const ast = astroParse('<div a b=c d="e" f=`g` x:y prop={ prop }></div>');
224
- expect(ast.children?.[0].attributes).toStrictEqual(
225
- expect.objectContaining([
226
- {
227
- type: 'attribute',
228
- kind: 'empty',
229
- name: 'a',
230
- value: '',
231
- raw: '',
232
- position: { start: { column: 6, line: 1, offset: 5 } },
233
- },
234
- {
235
- type: 'attribute',
236
- kind: 'quoted',
237
- name: 'b',
238
- value: 'c',
239
- raw: 'c',
240
- position: { start: { column: 8, line: 1, offset: 7 } },
241
- },
242
- {
243
- type: 'attribute',
244
- kind: 'quoted',
245
- name: 'd',
246
- value: 'e',
247
- raw: '"e"',
248
- position: { start: { column: 12, line: 1, offset: 11 } },
249
- },
250
- {
251
- type: 'attribute',
252
- kind: 'template-literal',
253
- name: 'f',
254
- value: 'g',
255
- raw: '',
256
- position: { start: { column: 18, line: 1, offset: 17 } },
257
- },
258
- {
259
- type: 'attribute',
260
- kind: 'empty',
261
- name: 'x:y',
262
- value: '',
263
- raw: '',
264
- position: { start: { column: 24, line: 1, offset: 23 } },
265
- },
266
- {
267
- type: 'attribute',
268
- kind: 'expression',
269
- name: 'prop',
270
- value: ' prop ',
271
- raw: '',
272
- position: { start: { column: 28, line: 1, offset: 27 } },
273
- },
274
- ]),
275
- );
276
- });
277
-
278
- test('Greater-than sign in attribute value', () => {
279
- const ast = astroParse('<div attr="a>b"></div>');
280
- expect(ast.children?.[0].attributes).toStrictEqual(
281
- expect.objectContaining([
282
- {
283
- kind: 'quoted',
284
- name: 'attr',
285
- position: { start: { column: 6, line: 1, offset: 5 } },
286
- type: 'attribute',
287
- value: 'a>b',
288
- raw: '"a>b"',
289
- },
290
- ]),
291
- );
292
- });
293
-
294
- describe('Issues', () => {
295
- test('#803', () => {
296
- const code = `<html lang="en">
297
- <head>
298
- <meta charset="utf-8" />
299
- <title>Title</title>
300
- <meta name="viewport" content="width=device-width" />
301
- </head>
302
- </html>
303
- `;
304
- const ast = astroParse(code);
305
- expect(ast).toStrictEqual(
306
- expect.objectContaining({
307
- type: 'root',
308
- children: [
309
- {
310
- type: 'element',
311
- name: 'html',
312
- position: { start: { line: 1, column: 2, offset: 0 } },
313
- attributes: [
314
- {
315
- type: 'attribute',
316
- kind: 'quoted',
317
- name: 'lang',
318
- value: 'en',
319
- raw: '"en"',
320
- position: { start: { line: 1, column: 7, offset: 6 } },
321
- },
322
- ],
323
- children: [
324
- {
325
- type: 'text',
326
- value: '\n\t',
327
- position: {
328
- start: { line: 1, column: 17, offset: 16 },
329
- end: { line: 2, column: 2, offset: 18 },
330
- },
331
- },
332
- {
333
- type: 'element',
334
- name: 'head',
335
- attributes: [],
336
- position: {
337
- start: { line: 2, column: 2, offset: 18 },
338
- end: { line: 6, column: 9, offset: 139 },
339
- },
340
- children: [
341
- {
342
- type: 'text',
343
- value: '\n\t\t',
344
- position: {
345
- start: { line: 2, column: 8, offset: 24 },
346
- end: { line: 3, column: 3, offset: 27 },
347
- },
348
- },
349
- {
350
- type: 'element',
351
- name: 'meta',
352
- position: { start: { line: 3, column: 4, offset: 27 } },
353
- attributes: [
354
- {
355
- type: 'attribute',
356
- kind: 'quoted',
357
- name: 'charset',
358
- value: 'utf-8',
359
- raw: '"utf-8"',
360
- position: { start: { line: 3, column: 9, offset: 33 } },
361
- },
362
- ],
363
- children: [],
364
- },
365
- {
366
- type: 'text',
367
- value: '\n\t\t',
368
- position: {
369
- start: { line: 3, column: 27, offset: 51 },
370
- end: { line: 4, column: 3, offset: 54 },
371
- },
372
- },
373
- {
374
- type: 'element',
375
- name: 'title',
376
- position: {
377
- start: { line: 4, column: 3, offset: 54 },
378
- end: { line: 4, column: 23, offset: 74 },
379
- },
380
- attributes: [],
381
- children: [
382
- {
383
- type: 'text',
384
- value: 'Title',
385
- position: {
386
- start: { line: 4, column: 10, offset: 61 },
387
- end: { line: 4, column: 15, offset: 66 },
388
- },
389
- },
390
- ],
391
- },
392
- {
393
- type: 'text',
394
- value: '\n\t\t',
395
- position: {
396
- start: { line: 4, column: 23, offset: 74 },
397
- end: { line: 5, column: 3, offset: 77 },
398
- },
399
- },
400
- {
401
- type: 'element',
402
- name: 'meta',
403
- attributes: [
404
- {
405
- type: 'attribute',
406
- kind: 'quoted',
407
- name: 'name',
408
- value: 'viewport',
409
- raw: '"viewport"',
410
- position: { start: { line: 5, column: 9, offset: 83 } },
411
- },
412
- {
413
- type: 'attribute',
414
- kind: 'quoted',
415
- name: 'content',
416
- value: 'width=device-width',
417
- raw: '"width=device-width"',
418
- position: { start: { line: 5, column: 25, offset: 99 } },
419
- },
420
- ],
421
- position: { start: { line: 5, column: 4, offset: 77 } },
422
- children: [],
423
- },
424
- {
425
- type: 'text',
426
- value: '\n\t',
427
- position: {
428
- start: { line: 5, column: 56, offset: 130 },
429
- end: { line: 6, column: 2, offset: 132 },
430
- },
431
- },
432
- ],
433
- },
434
- {
435
- type: 'text',
436
- value: '\n',
437
- position: {
438
- start: { line: 6, column: 9, offset: 139 },
439
- end: { line: 7, column: 1, offset: 140 },
440
- },
441
- },
442
- {
443
- type: 'text',
444
- value: '',
445
- position: {
446
- start: { line: 7, column: 8, offset: 140 },
447
- end: { line: 8, column: 1, offset: 140 },
448
- },
449
- },
450
- ],
451
- },
452
- ],
453
- }),
454
- );
455
- });
456
- });
@@ -1,483 +0,0 @@
1
- const { nodeListToDebugMaps } = require('@markuplint/parser-utils');
2
-
3
- const { parse } = require('../lib/parse');
4
-
5
- it('Basic', () => {
6
- const ast = parse(`---
7
- const name = "World";
8
- ---
9
- <!-- Comment -->
10
- <style>
11
- div {
12
- color: red;
13
- }
14
- </style>
15
- <div data-attr="value" data-dynamic={value}>Hello {name}!</div>
16
- <ul>
17
- {list.map(item => <li>{item}</li>)}
18
- </ul>
19
- `);
20
- const map = nodeListToDebugMaps(ast.nodeList, true);
21
- expect(map).toEqual([
22
- '[1:1]>[4:1](0,30)#text: ␣␣␣⏎␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣⏎␣␣␣⏎',
23
- '[4:1]>[4:17](30,46)#comment: <!--␣Comment␣-->',
24
- '[4:17]>[5:1](46,47)#text: ⏎',
25
- '[5:1]>[5:8](47,54)style: <style>',
26
- '[9:1]>[9:9](79,87)style: </style>',
27
- '[9:9]>[10:1](87,88)#text: ⏎',
28
- '[10:1]>[10:45](88,132)div: <div␣data-attr="value"␣data-dynamic={value}>',
29
- '[10:6]>[10:23](93,110)data-attr: data-attr="value"',
30
- ' [10:6]>[10:6](93,93)bN: ',
31
- ' [10:6]>[10:15](93,102)name: data-attr',
32
- ' [10:15]>[10:15](102,102)bE: ',
33
- ' [10:15]>[10:16](102,103)equal: =',
34
- ' [10:16]>[10:16](103,103)aE: ',
35
- ' [10:16]>[10:17](103,104)sQ: "',
36
- ' [10:17]>[10:22](104,109)value: value',
37
- ' [10:22]>[10:23](109,110)eQ: "',
38
- ' isDirective: false',
39
- ' isDynamicValue: false',
40
- '[10:24]>[10:44](111,131)data-dynamic: data-dynamic={value}',
41
- ' [10:24]>[10:24](111,111)bN: ',
42
- ' [10:24]>[10:36](111,123)name: data-dynamic',
43
- ' [10:36]>[10:36](123,123)bE: ',
44
- ' [10:36]>[10:37](123,124)equal: =',
45
- ' [10:37]>[10:37](124,124)aE: ',
46
- ' [10:37]>[10:38](124,125)sQ: {',
47
- ' [10:38]>[10:43](125,130)value: value',
48
- ' [10:43]>[10:44](130,131)eQ: }',
49
- ' isDirective: false',
50
- ' isDynamicValue: true',
51
- '[10:45]>[10:51](132,138)#text: Hello␣',
52
- '[10:51]>[10:57](138,144)MustacheTag: {name}',
53
- '[10:57]>[10:58](144,145)#text: !',
54
- '[10:58]>[10:64](145,151)div: </div>',
55
- '[10:64]>[11:1](151,152)#text: ⏎',
56
- '[11:1]>[11:5](152,156)ul: <ul>',
57
- '[11:5]>[12:1](156,157)#text: ⏎',
58
- '[12:1]>[12:19](157,175)MustacheTag: {list.map(item␣=>␣',
59
- '[12:19]>[12:23](175,179)li: <li>',
60
- '[12:23]>[12:29](179,185)MustacheTag: {item}',
61
- '[12:29]>[12:34](185,190)li: </li>',
62
- '[12:34]>[12:36](190,192)MustacheTag: )}',
63
- '[12:36]>[13:1](192,193)#text: ⏎',
64
- '[13:1]>[13:6](193,198)ul: </ul>',
65
- '[13:6]>[14:1](198,199)#text: ⏎',
66
- ]);
67
- });
68
-
69
- it('HTML', () => {
70
- const ast = parse(`<html>
71
- <head>
72
- <style>
73
- ...
74
- </style>
75
- </head>
76
- <body>...</body>
77
- </html>
78
- `);
79
- const map = nodeListToDebugMaps(ast.nodeList, true);
80
- expect(map).toEqual([
81
- '[1:1]>[1:7](0,6)html: <html>',
82
- '[1:7]>[2:3](6,9)#text: ⏎␣␣',
83
- '[2:3]>[2:9](9,15)head: <head>',
84
- '[2:9]>[3:5](15,20)#text: ⏎␣␣␣␣',
85
- '[3:5]>[3:12](20,27)style: <style>',
86
- '[5:5]>[5:13](42,50)style: </style>',
87
- '[5:13]>[6:3](50,53)#text: ⏎␣␣',
88
- '[6:3]>[6:10](53,60)head: </head>',
89
- '[6:10]>[7:3](60,63)#text: ⏎␣␣',
90
- '[7:3]>[7:9](63,69)body: <body>',
91
- '[7:9]>[7:12](69,72)#text: ...',
92
- '[7:12]>[7:19](72,79)body: </body>',
93
- '[7:19]>[8:1](79,80)#text: ⏎',
94
- '[8:1]>[8:8](80,87)html: </html>',
95
- '[8:8]>[9:1](87,88)#text: ⏎',
96
- ]);
97
- });
98
-
99
- it('Attributes', () => {
100
- const ast = parse('<CustomComponent prop1 prop2="value2" prop3={value3}></CustomComponent>');
101
- const map = nodeListToDebugMaps(ast.nodeList, true);
102
- expect(map).toEqual([
103
- '[1:1]>[1:54](0,53)CustomComponent: <CustomComponent␣prop1␣prop2="value2"␣prop3={value3}>',
104
- '[1:18]>[1:23](17,22)prop1: prop1',
105
- ' [1:18]>[1:18](17,17)bN: ',
106
- ' [1:18]>[1:23](17,22)name: prop1',
107
- ' [1:23]>[1:23](22,22)bE: ',
108
- ' [1:23]>[1:23](22,22)equal: ',
109
- ' [1:23]>[1:23](22,22)aE: ',
110
- ' [1:23]>[1:23](22,22)sQ: ',
111
- ' [1:23]>[1:23](22,22)value: ',
112
- ' [1:23]>[1:23](22,22)eQ: ',
113
- ' isDirective: false',
114
- ' isDynamicValue: false',
115
- '[1:24]>[1:38](23,37)prop2: prop2="value2"',
116
- ' [1:24]>[1:24](23,23)bN: ',
117
- ' [1:24]>[1:29](23,28)name: prop2',
118
- ' [1:29]>[1:29](28,28)bE: ',
119
- ' [1:29]>[1:30](28,29)equal: =',
120
- ' [1:30]>[1:30](29,29)aE: ',
121
- ' [1:30]>[1:31](29,30)sQ: "',
122
- ' [1:31]>[1:37](30,36)value: value2',
123
- ' [1:37]>[1:38](36,37)eQ: "',
124
- ' isDirective: false',
125
- ' isDynamicValue: false',
126
- '[1:39]>[1:53](38,52)prop3: prop3={value3}',
127
- ' [1:39]>[1:39](38,38)bN: ',
128
- ' [1:39]>[1:44](38,43)name: prop3',
129
- ' [1:44]>[1:44](43,43)bE: ',
130
- ' [1:44]>[1:45](43,44)equal: =',
131
- ' [1:45]>[1:45](44,44)aE: ',
132
- ' [1:45]>[1:46](44,45)sQ: {',
133
- ' [1:46]>[1:52](45,51)value: value3',
134
- ' [1:52]>[1:53](51,52)eQ: }',
135
- ' isDirective: false',
136
- ' isDynamicValue: true',
137
- '[1:54]>[1:72](53,71)CustomComponent: </CustomComponent>',
138
- ]);
139
- });
140
-
141
- it('CustomComponent', () => {
142
- const ast = parse('<CustomComponent />');
143
- const map = nodeListToDebugMaps(ast.nodeList);
144
- expect(map).toEqual(['[1:1]>[1:20](0,19)CustomComponent: <CustomComponent␣/>']);
145
- });
146
-
147
- it('Siblings', () => {
148
- const ast = parse('<tag1 /><tag2 /><tag3 />');
149
- const map = nodeListToDebugMaps(ast.nodeList);
150
- expect(map).toEqual([
151
- '[1:1]>[1:9](0,8)tag1: <tag1␣/>',
152
- '[1:9]>[1:17](8,16)tag2: <tag2␣/>',
153
- '[1:17]>[1:25](16,24)tag3: <tag3␣/>',
154
- ]);
155
- });
156
-
157
- it('Siblings2', () => {
158
- const ast = parse('<tag1></tag1><tag2 attr></tag2><tag3 attr2></tag3>');
159
- const map = nodeListToDebugMaps(ast.nodeList);
160
- expect(map).toEqual([
161
- '[1:1]>[1:7](0,6)tag1: <tag1>',
162
- '[1:7]>[1:14](6,13)tag1: </tag1>',
163
- '[1:14]>[1:25](13,24)tag2: <tag2␣attr>',
164
- '[1:25]>[1:32](24,31)tag2: </tag2>',
165
- '[1:32]>[1:44](31,43)tag3: <tag3␣attr2>',
166
- '[1:44]>[1:51](43,50)tag3: </tag3>',
167
- ]);
168
- });
169
-
170
- it('Pear', () => {
171
- expect(parse('<tag1></tag1>').nodeList[0].pearNode?.raw).toBe('</tag1>');
172
- expect(parse('<tag1><tag2 /></tag1>').nodeList[1].pearNode?.raw).toBeUndefined();
173
- expect(parse('<tag1><tag2></tag2></tag1>').nodeList[1].pearNode?.raw).toBe('</tag2>');
174
- });
175
-
176
- it('Missing end tag', () => {
177
- const ast = parse('<div><span><span /></div>');
178
- const map = nodeListToDebugMaps(ast.nodeList);
179
- expect(map).toEqual([
180
- '[1:1]>[1:6](0,5)div: <div>',
181
- '[1:6]>[1:12](5,11)span: <span>',
182
- '[1:12]>[1:20](11,19)span: <span␣/>',
183
- '[1:20]>[1:26](19,25)#text: </div>',
184
- ]);
185
- });
186
-
187
- it('Doctype', () => {
188
- const ast = parse('<!doctype html>\n<html></html>');
189
- const map = nodeListToDebugMaps(ast.nodeList);
190
- expect(map).toEqual([
191
- '[1:1]>[1:16](0,15)#doctype: <!doctype␣html>',
192
- '[1:16]>[2:1](15,16)#text: ⏎',
193
- '[2:1]>[2:7](16,22)html: <html>',
194
- '[2:7]>[2:14](22,29)html: </html>',
195
- ]);
196
- });
197
-
198
- it('namespace', () => {
199
- const doc = parse('<div><svg><text /></svg></div>');
200
- expect(doc.nodeList[0].nodeName).toBe('div');
201
- expect(doc.nodeList[0].namespace).toBe('http://www.w3.org/1999/xhtml');
202
- expect(doc.nodeList[1].nodeName).toBe('svg');
203
- expect(doc.nodeList[1].namespace).toBe('http://www.w3.org/2000/svg');
204
- expect(doc.nodeList[2].nodeName).toBe('text');
205
- expect(doc.nodeList[2].namespace).toBe('http://www.w3.org/2000/svg');
206
-
207
- const doc2 = parse('<svg><foreignObject><div></div></foreignObject></svg>');
208
- expect(doc2.nodeList[0].nodeName).toBe('svg');
209
- expect(doc2.nodeList[0].namespace).toBe('http://www.w3.org/2000/svg');
210
- expect(doc2.nodeList[1].nodeName).toBe('foreignObject');
211
- expect(doc2.nodeList[1].namespace).toBe('http://www.w3.org/2000/svg');
212
- expect(doc2.nodeList[2].nodeName).toBe('div');
213
- expect(doc2.nodeList[2].namespace).toBe('http://www.w3.org/1999/xhtml');
214
- });
215
-
216
- describe('Issue', () => {
217
- test('#549', () => {
218
- const ast = parse(`<ul>{
219
- list.map(() => <li></li>)
220
- }</ul>`);
221
- const map = nodeListToDebugMaps(ast.nodeList);
222
- expect(map).toEqual([
223
- '[1:1]>[1:5](0,4)ul: <ul>',
224
- '[1:5]>[2:17](4,22)MustacheTag: {⏎→list.map(()␣=>␣',
225
- '[2:17]>[2:21](22,26)li: <li>',
226
- '[2:21]>[2:26](26,31)li: </li>',
227
- '[2:26]>[3:2](31,34)MustacheTag: )⏎}',
228
- '[3:2]>[3:7](34,39)ul: </ul>',
229
- ]);
230
- });
231
-
232
- test('#575', () => {
233
- const ast = parse('<div class:list={["class-name"]}></div>');
234
- const map = nodeListToDebugMaps(ast.nodeList, true);
235
- expect(map).toEqual([
236
- '[1:1]>[1:34](0,33)div: <div␣class:list={["class-name"]}>',
237
- '[1:6]>[1:33](5,32)class: class:list={["class-name"]}',
238
- ' [1:6]>[1:6](5,5)bN: ',
239
- ' [1:6]>[1:16](5,15)name: class:list',
240
- ' [1:16]>[1:16](15,15)bE: ',
241
- ' [1:16]>[1:17](15,16)equal: =',
242
- ' [1:17]>[1:17](16,16)aE: ',
243
- ' [1:17]>[1:18](16,17)sQ: {',
244
- ' [1:18]>[1:32](17,31)value: ["class-name"]',
245
- ' [1:32]>[1:33](31,32)eQ: }',
246
- ' isDirective: false',
247
- ' isDynamicValue: true',
248
- ' potentialName: class',
249
- '[1:34]>[1:40](33,39)div: </div>',
250
- ]);
251
- });
252
-
253
- test('#739', () => {
254
- const ast = parse(`<div>
255
- {
256
- type === 'checkbox' ? (
257
- <fieldset>
258
- <legend>{label}</legend>
259
- <div>
260
- {values.map((value) => (
261
- <label>
262
- <input type="checkbox" value={value} />
263
- <span>{value}</span>
264
- </label>
265
- ))}
266
- </div>
267
- </fieldset>
268
- ) : (
269
- <label>
270
- <span>{label}</span>
271
- {type === 'textarea' ? <textarea /> : <input type={type} />}
272
- </label>
273
- )
274
- }
275
- </div>
276
- `);
277
- const map = nodeListToDebugMaps(ast.nodeList, true);
278
- expect(map).toEqual([
279
- '[1:1]>[1:6](0,5)div: <div>',
280
- '[1:6]>[2:2](5,7)#text: ⏎→',
281
- "[2:2]>[4:4](7,38)MustacheTag: {⏎→→type␣===␣'checkbox'␣?␣(⏎→→→",
282
- '[4:4]>[4:14](38,48)fieldset: <fieldset>',
283
- '[4:14]>[5:5](48,53)#text: ⏎→→→→',
284
- '[5:5]>[5:13](53,61)legend: <legend>',
285
- '[5:13]>[5:20](61,68)MustacheTag: {label}',
286
- '[5:20]>[5:29](68,77)legend: </legend>',
287
- '[5:29]>[6:5](77,82)#text: ⏎→→→→',
288
- '[6:5]>[6:10](82,87)div: <div>',
289
- '[6:10]>[7:6](87,93)#text: ⏎→→→→→',
290
- '[7:6]>[8:7](93,124)MustacheTag: {values.map((value)␣=>␣(⏎→→→→→→',
291
- '[8:7]>[8:14](124,131)label: <label>',
292
- '[8:14]>[9:8](131,139)#text: ⏎→→→→→→→',
293
- '[9:8]>[9:47](139,178)input: <input␣type="checkbox"␣value={value}␣/>',
294
- '[9:15]>[9:30](146,161)type: type="checkbox"',
295
- ' [9:15]>[9:15](146,146)bN: ',
296
- ' [9:15]>[9:19](146,150)name: type',
297
- ' [9:19]>[9:19](150,150)bE: ',
298
- ' [9:19]>[9:20](150,151)equal: =',
299
- ' [9:20]>[9:20](151,151)aE: ',
300
- ' [9:20]>[9:21](151,152)sQ: "',
301
- ' [9:21]>[9:29](152,160)value: checkbox',
302
- ' [9:29]>[9:30](160,161)eQ: "',
303
- ' isDirective: false',
304
- ' isDynamicValue: false',
305
- '[9:31]>[9:45](162,176)value: value={value}␣',
306
- ' [9:31]>[9:31](162,162)bN: ',
307
- ' [9:31]>[9:36](162,167)name: value',
308
- ' [9:36]>[9:36](167,167)bE: ',
309
- ' [9:36]>[9:37](167,168)equal: =',
310
- ' [9:37]>[9:37](168,168)aE: ',
311
- ' [9:37]>[9:38](168,169)sQ: {',
312
- ' [9:38]>[9:43](169,174)value: value',
313
- ' [9:43]>[9:44](174,175)eQ: }',
314
- ' isDirective: false',
315
- ' isDynamicValue: true',
316
- '[9:47]>[10:8](178,186)#text: ⏎→→→→→→→',
317
- '[10:8]>[10:14](186,192)span: <span>',
318
- '[10:14]>[10:21](192,199)MustacheTag: {value}',
319
- '[10:21]>[10:28](199,206)span: </span>',
320
- '[10:28]>[11:7](206,213)#text: ⏎→→→→→→',
321
- '[11:7]>[11:15](213,221)label: </label>',
322
- '[11:15]>[12:9](221,230)MustacheTag: ⏎→→→→→))}',
323
- '[12:9]>[13:5](230,235)#text: ⏎→→→→',
324
- '[13:5]>[13:11](235,241)div: </div>',
325
- '[13:11]>[14:4](241,245)#text: ⏎→→→',
326
- '[14:4]>[14:15](245,256)fieldset: </fieldset>',
327
- '[16:4]>[16:11](268,275)label: <label>',
328
- '[16:11]>[17:5](275,280)#text: ⏎→→→→',
329
- '[17:5]>[17:11](280,286)span: <span>',
330
- '[17:11]>[17:18](286,293)MustacheTag: {label}',
331
- '[17:18]>[17:25](293,300)span: </span>',
332
- '[17:25]>[18:5](300,305)#text: ⏎→→→→',
333
- "[18:5]>[18:28](305,328)MustacheTag: {type␣===␣'textarea'␣?␣",
334
- '[18:28]>[18:40](328,340)textarea: <textarea␣/>',
335
- '[18:43]>[18:64](343,364)input: <input␣type={type}␣/>',
336
- '[18:50]>[18:62](350,362)type: type={type}␣',
337
- ' [18:50]>[18:50](350,350)bN: ',
338
- ' [18:50]>[18:54](350,354)name: type',
339
- ' [18:54]>[18:54](354,354)bE: ',
340
- ' [18:54]>[18:55](354,355)equal: =',
341
- ' [18:55]>[18:55](355,355)aE: ',
342
- ' [18:55]>[18:56](355,356)sQ: {',
343
- ' [18:56]>[18:60](356,360)value: type',
344
- ' [18:60]>[18:61](360,361)eQ: }',
345
- ' isDirective: false',
346
- ' isDynamicValue: true',
347
- '[18:43]>[18:65](343,365)MustacheTag: <input␣type={type}␣/>}',
348
- '[18:65]>[19:4](365,369)#text: ⏎→→→',
349
- '[19:4]>[19:12](369,377)label: </label>',
350
- '[19:12]>[21:3](377,384)MustacheTag: ⏎→→)⏎→}',
351
- '[21:3]>[22:1](384,385)#text: ⏎',
352
- '[22:1]>[22:7](385,391)div: </div>',
353
- '[22:7]>[23:1](391,392)#text: ⏎',
354
- ]);
355
- });
356
-
357
- test('#803', () => {
358
- const ast = parse(`<html lang="en">
359
- <head>
360
- <meta charset="utf-8" />
361
- <title>Title</title>
362
- <meta name="viewport" content="width=device-width" />
363
- </head>
364
- </html>`);
365
- const map = nodeListToDebugMaps(ast.nodeList, true);
366
- expect(map).toEqual([
367
- '[1:1]>[1:17](0,16)html: <html␣lang="en">',
368
- '[1:7]>[1:16](6,15)lang: lang="en"',
369
- ' [1:7]>[1:7](6,6)bN: ',
370
- ' [1:7]>[1:11](6,10)name: lang',
371
- ' [1:11]>[1:11](10,10)bE: ',
372
- ' [1:11]>[1:12](10,11)equal: =',
373
- ' [1:12]>[1:12](11,11)aE: ',
374
- ' [1:12]>[1:13](11,12)sQ: "',
375
- ' [1:13]>[1:15](12,14)value: en',
376
- ' [1:15]>[1:16](14,15)eQ: "',
377
- ' isDirective: false',
378
- ' isDynamicValue: false',
379
- '[1:17]>[2:2](16,18)#text: ⏎→',
380
- '[2:2]>[2:8](18,24)head: <head>',
381
- '[2:8]>[3:3](24,27)#text: ⏎→→',
382
- '[3:3]>[3:27](27,51)meta: <meta␣charset="utf-8"␣/>',
383
- '[3:9]>[3:25](33,49)charset: charset="utf-8"␣',
384
- ' [3:9]>[3:9](33,33)bN: ',
385
- ' [3:9]>[3:16](33,40)name: charset',
386
- ' [3:16]>[3:16](40,40)bE: ',
387
- ' [3:16]>[3:17](40,41)equal: =',
388
- ' [3:17]>[3:17](41,41)aE: ',
389
- ' [3:17]>[3:18](41,42)sQ: "',
390
- ' [3:18]>[3:23](42,47)value: utf-8',
391
- ' [3:23]>[3:24](47,48)eQ: "',
392
- ' isDirective: false',
393
- ' isDynamicValue: false',
394
- '[3:27]>[4:3](51,54)#text: ⏎→→',
395
- '[4:3]>[4:10](54,61)title: <title>',
396
- '[4:10]>[4:15](61,66)#text: Title',
397
- '[4:15]>[4:23](66,74)title: </title>',
398
- '[4:23]>[5:3](74,77)#text: ⏎→→',
399
- '[5:3]>[5:56](77,130)meta: <meta␣name="viewport"␣content="width=device-width"␣/>',
400
- '[5:9]>[5:24](83,98)name: name="viewport"',
401
- ' [5:9]>[5:9](83,83)bN: ',
402
- ' [5:9]>[5:13](83,87)name: name',
403
- ' [5:13]>[5:13](87,87)bE: ',
404
- ' [5:13]>[5:14](87,88)equal: =',
405
- ' [5:14]>[5:14](88,88)aE: ',
406
- ' [5:14]>[5:15](88,89)sQ: "',
407
- ' [5:15]>[5:23](89,97)value: viewport',
408
- ' [5:23]>[5:24](97,98)eQ: "',
409
- ' isDirective: false',
410
- ' isDynamicValue: false',
411
- '[5:25]>[5:54](99,128)content: content="width=device-width"␣',
412
- ' [5:25]>[5:25](99,99)bN: ',
413
- ' [5:25]>[5:32](99,106)name: content',
414
- ' [5:32]>[5:32](106,106)bE: ',
415
- ' [5:32]>[5:33](106,107)equal: =',
416
- ' [5:33]>[5:33](107,107)aE: ',
417
- ' [5:33]>[5:34](107,108)sQ: "',
418
- ' [5:34]>[5:52](108,126)value: width=device-width',
419
- ' [5:52]>[5:53](126,127)eQ: "',
420
- ' isDirective: false',
421
- ' isDynamicValue: false',
422
- '[5:56]>[6:2](130,132)#text: ⏎→',
423
- '[6:2]>[6:9](132,139)head: </head>',
424
- '[6:9]>[7:1](139,140)#text: ⏎',
425
- ]);
426
-
427
- const ast2 = parse(`<html>
428
- <head>
429
- <meta attr=">" />
430
- <meta attr={a>b} />
431
- <meta attr={<tag>text</tag>} />
432
- </head>
433
- </html>`);
434
- const map2 = nodeListToDebugMaps(ast2.nodeList, true);
435
- expect(map2).toEqual([
436
- '[1:1]>[1:7](0,6)html: <html>',
437
- '[1:7]>[2:2](6,8)#text: ⏎→',
438
- '[2:2]>[2:8](8,14)head: <head>',
439
- '[2:8]>[3:3](14,17)#text: ⏎→→',
440
- '[3:3]>[3:20](17,34)meta: <meta␣attr=">"␣/>',
441
- '[3:9]>[3:18](23,32)attr: attr=">"␣',
442
- ' [3:9]>[3:9](23,23)bN: ',
443
- ' [3:9]>[3:13](23,27)name: attr',
444
- ' [3:13]>[3:13](27,27)bE: ',
445
- ' [3:13]>[3:14](27,28)equal: =',
446
- ' [3:14]>[3:14](28,28)aE: ',
447
- ' [3:14]>[3:15](28,29)sQ: "',
448
- ' [3:15]>[3:16](29,30)value: >',
449
- ' [3:16]>[3:17](30,31)eQ: "',
450
- ' isDirective: false',
451
- ' isDynamicValue: false',
452
- '[3:20]>[4:3](34,37)#text: ⏎→→',
453
- '[4:3]>[4:22](37,56)meta: <meta␣attr={a>b}␣/>',
454
- '[4:9]>[4:20](43,54)attr: attr={a>b}␣',
455
- ' [4:9]>[4:9](43,43)bN: ',
456
- ' [4:9]>[4:13](43,47)name: attr',
457
- ' [4:13]>[4:13](47,47)bE: ',
458
- ' [4:13]>[4:14](47,48)equal: =',
459
- ' [4:14]>[4:14](48,48)aE: ',
460
- ' [4:14]>[4:15](48,49)sQ: {',
461
- ' [4:15]>[4:18](49,52)value: a>b',
462
- ' [4:18]>[4:19](52,53)eQ: }',
463
- ' isDirective: false',
464
- ' isDynamicValue: true',
465
- '[4:22]>[5:3](56,59)#text: ⏎→→',
466
- '[5:3]>[5:34](59,90)meta: <meta␣attr={<tag>text</tag>}␣/>',
467
- '[5:9]>[5:32](65,88)attr: attr={<tag>text</tag>}␣',
468
- ' [5:9]>[5:9](65,65)bN: ',
469
- ' [5:9]>[5:13](65,69)name: attr',
470
- ' [5:13]>[5:13](69,69)bE: ',
471
- ' [5:13]>[5:14](69,70)equal: =',
472
- ' [5:14]>[5:14](70,70)aE: ',
473
- ' [5:14]>[5:15](70,71)sQ: {',
474
- ' [5:15]>[5:30](71,86)value: <tag>text</tag>',
475
- ' [5:30]>[5:31](86,87)eQ: }',
476
- ' isDirective: false',
477
- ' isDynamicValue: true',
478
- '[5:34]>[6:2](90,92)#text: ⏎→',
479
- '[6:2]>[6:9](92,99)head: </head>',
480
- '[6:9]>[7:1](99,100)#text: ⏎',
481
- ]);
482
- });
483
- });