@markuplint/parser-utils 3.10.0 → 4.0.0-alpha.1

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/parse-attr.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tokenize = exports.parseAttr = exports.defaultValueDelimiters = void 0;
4
- const create_token_1 = require("./create-token");
5
- exports.defaultValueDelimiters = [
1
+ import { createTokenFromRawCode, tokenizer, uuid } from './create-token.js';
2
+ export const defaultValueDelimiters = [
6
3
  {
7
4
  start: "'",
8
5
  end: "'",
@@ -14,21 +11,21 @@ exports.defaultValueDelimiters = [
14
11
  ];
15
12
  const defaultEqual = '=';
16
13
  const spaceRegex = /^\s$/;
17
- function parseAttr(raw, offset, html, options) {
14
+ export function parseAttr(raw, offset, html, options) {
18
15
  const tokens = tokenize(raw, options);
19
16
  tokens.beforeName;
20
- const attrToken = (0, create_token_1.createTokenFromRawCode)(raw, offset, html);
21
- const spacesBeforeName = (0, create_token_1.tokenizer)(tokens.beforeName, attrToken.startLine, attrToken.startCol, attrToken.startOffset);
22
- const name = (0, create_token_1.tokenizer)(tokens.name, spacesBeforeName.endLine, spacesBeforeName.endCol, spacesBeforeName.endOffset);
23
- const spacesBeforeEqual = (0, create_token_1.tokenizer)(tokens.afterName, name.endLine, name.endCol, name.endOffset);
24
- const equal = (0, create_token_1.tokenizer)(tokens.equal, spacesBeforeEqual.endLine, spacesBeforeEqual.endCol, spacesBeforeEqual.endOffset);
25
- const spacesAfterEqual = (0, create_token_1.tokenizer)(tokens.beforeValue, equal.endLine, equal.endCol, equal.endOffset);
26
- const startQuote = (0, create_token_1.tokenizer)(tokens.startQuote, spacesAfterEqual.endLine, spacesAfterEqual.endCol, spacesAfterEqual.endOffset);
27
- const value = (0, create_token_1.tokenizer)(tokens.value, startQuote.endLine, startQuote.endCol, startQuote.endOffset);
28
- const endQuote = (0, create_token_1.tokenizer)(tokens.endQuote, value.endLine, value.endCol, value.endOffset);
17
+ const attrToken = createTokenFromRawCode(raw, offset, html);
18
+ const spacesBeforeName = tokenizer(tokens.beforeName, attrToken.startLine, attrToken.startCol, attrToken.startOffset);
19
+ const name = tokenizer(tokens.name, spacesBeforeName.endLine, spacesBeforeName.endCol, spacesBeforeName.endOffset);
20
+ const spacesBeforeEqual = tokenizer(tokens.afterName, name.endLine, name.endCol, name.endOffset);
21
+ const equal = tokenizer(tokens.equal, spacesBeforeEqual.endLine, spacesBeforeEqual.endCol, spacesBeforeEqual.endOffset);
22
+ const spacesAfterEqual = tokenizer(tokens.beforeValue, equal.endLine, equal.endCol, equal.endOffset);
23
+ const startQuote = tokenizer(tokens.startQuote, spacesAfterEqual.endLine, spacesAfterEqual.endCol, spacesAfterEqual.endOffset);
24
+ const value = tokenizer(tokens.value, startQuote.endLine, startQuote.endCol, startQuote.endOffset);
25
+ const endQuote = tokenizer(tokens.endQuote, value.endLine, value.endCol, value.endOffset);
29
26
  const attr = {
30
27
  type: 'html-attr',
31
- uuid: (0, create_token_1.uuid)(),
28
+ uuid: uuid(),
32
29
  raw: attrToken.raw,
33
30
  startOffset: attrToken.startOffset,
34
31
  endOffset: attrToken.endOffset,
@@ -54,11 +51,9 @@ function parseAttr(raw, offset, html, options) {
54
51
  };
55
52
  return attr;
56
53
  }
57
- exports.parseAttr = parseAttr;
58
- function tokenize(raw, options) {
59
- var _a, _b, _c;
60
- const valueDelimiters = (_a = options === null || options === void 0 ? void 0 : options.valueDelimiters) !== null && _a !== void 0 ? _a : exports.defaultValueDelimiters;
61
- const equalDelimiter = (_b = options === null || options === void 0 ? void 0 : options.equal) !== null && _b !== void 0 ? _b : defaultEqual;
54
+ export function tokenize(raw, options) {
55
+ const valueDelimiters = options?.valueDelimiters ?? defaultValueDelimiters;
56
+ const equalDelimiter = options?.equal ?? defaultEqual;
62
57
  let state = 'b-name';
63
58
  const charactors = raw.split('');
64
59
  let beforeName = '';
@@ -113,7 +108,7 @@ function tokenize(raw, options) {
113
108
  beforeValue += charactor;
114
109
  continue;
115
110
  }
116
- valueDelimiter = (_c = valueDelimiters.find(d => d.start === charactor)) !== null && _c !== void 0 ? _c : null;
111
+ valueDelimiter = valueDelimiters.find(d => d.start === charactor) ?? null;
117
112
  if (valueDelimiter) {
118
113
  startQuote += valueDelimiter.start;
119
114
  }
@@ -147,4 +142,3 @@ function tokenize(raw, options) {
147
142
  afterAttr,
148
143
  };
149
144
  }
150
- exports.tokenize = tokenize;
@@ -1,30 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfigParserError = exports.TargetParserError = exports.ParserError = void 0;
4
- class ParserError extends Error {
1
+ export class ParserError extends Error {
5
2
  constructor(message, info) {
6
- var _a, _b, _c;
7
3
  super(message);
8
4
  this.name = 'ParserError';
9
- this.line = (_a = info.line) !== null && _a !== void 0 ? _a : 1;
10
- this.col = (_b = info.col) !== null && _b !== void 0 ? _b : 0;
11
- this.raw = (_c = info.raw) !== null && _c !== void 0 ? _c : '';
5
+ this.line = info.line ?? 1;
6
+ this.col = info.col ?? 0;
7
+ this.raw = info.raw ?? '';
12
8
  }
13
9
  }
14
- exports.ParserError = ParserError;
15
- class TargetParserError extends ParserError {
10
+ export class TargetParserError extends ParserError {
16
11
  constructor(message, info) {
17
- var _a;
18
12
  const errMsg = info.nodeName
19
13
  ? `The ${info.nodeName} is invalid element (${info.line}:${info.col}): ${message}`
20
14
  : message;
21
15
  super(errMsg, info);
22
16
  this.name = 'TargetParserError';
23
- this.nodeName = (_a = info.nodeName) !== null && _a !== void 0 ? _a : null;
17
+ this.nodeName = info.nodeName ?? null;
24
18
  }
25
19
  }
26
- exports.TargetParserError = TargetParserError;
27
- class ConfigParserError extends ParserError {
20
+ export class ConfigParserError extends ParserError {
28
21
  constructor(message, info) {
29
22
  const pos = info.line != null && info.line != null ? `(${info.line}:${info.col})` : '';
30
23
  const file = ` in ${info.filePath}${pos}`;
@@ -34,4 +27,3 @@ class ConfigParserError extends ParserError {
34
27
  this.filePath = info.filePath;
35
28
  }
36
29
  }
37
- exports.ConfigParserError = ConfigParserError;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeDeprecatedNode = void 0;
4
1
  /**
5
2
  *
6
3
  * @disruptive
7
4
  * @param nodeOrders [Disruptive change]
8
5
  */
9
- function removeDeprecatedNode(
6
+ export function removeDeprecatedNode(
10
7
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
11
8
  nodeOrders) {
12
9
  /**
@@ -40,4 +37,3 @@ nodeOrders) {
40
37
  }
41
38
  }
42
39
  }
43
- exports.removeDeprecatedNode = removeDeprecatedNode;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.siblingsCorrection = void 0;
4
1
  /**
5
2
  * Correct the references to prevNode and nextNode in the order listed.
6
3
  *
@@ -8,19 +5,17 @@ exports.siblingsCorrection = void 0;
8
5
  * @affects nodeList[].prevNode
9
6
  * @affects nodeList[].nextNode
10
7
  */
11
- function siblingsCorrection(
8
+ export function siblingsCorrection(
12
9
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
13
10
  nodeList) {
14
- var _a, _b;
15
11
  for (let i = 0; i < nodeList.length; i++) {
16
- const prevNode = (_a = nodeList[i - 1]) !== null && _a !== void 0 ? _a : null;
12
+ const prevNode = nodeList[i - 1] ?? null;
17
13
  const node = nodeList[i];
18
14
  if (!node) {
19
15
  continue;
20
16
  }
21
- const nextNode = (_b = nodeList[i + 1]) !== null && _b !== void 0 ? _b : null;
17
+ const nextNode = nodeList[i + 1] ?? null;
22
18
  node.prevNode = prevNode;
23
19
  node.nextNode = nextNode;
24
20
  }
25
21
  }
26
- exports.siblingsCorrection = siblingsCorrection;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const const_1 = require("./const");
4
- const parser_utils_1 = require("@markuplint/parser-utils");
5
- function tagSplitter(raw, line, col) {
1
+ import { reSplitterTag, reTagName } from './const.js';
2
+ import { getEndCol, getEndLine } from '@markuplint/parser-utils';
3
+ export default function tagSplitter(raw, line, col) {
6
4
  return withLocation(tagSplitterAsString(raw), line, col);
7
5
  }
8
- exports.default = tagSplitter;
9
6
  function tagSplitterAsString(raw) {
10
- const tagMatches = raw.match(const_1.reSplitterTag);
7
+ const tagMatches = raw.match(reSplitterTag);
11
8
  if (!tagMatches) {
12
9
  return [raw];
13
10
  }
@@ -44,7 +41,7 @@ function withLocation(nodes, line, col) {
44
41
  }
45
42
  else {
46
43
  const label = node.slice(1).slice(0, -1);
47
- if (const_1.reTagName.test(label)) {
44
+ if (reTagName.test(label)) {
48
45
  result.push({
49
46
  type: 'starttag',
50
47
  raw: node,
@@ -85,8 +82,8 @@ function withLocation(nodes, line, col) {
85
82
  });
86
83
  }
87
84
  }
88
- line = (0, parser_utils_1.getEndLine)(node, line);
89
- col = (0, parser_utils_1.getEndCol)(node, col);
85
+ line = getEndLine(node, line);
86
+ col = getEndCol(node, col);
90
87
  }
91
88
  return result;
92
89
  }
package/lib/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/lib/walker.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.walk = void 0;
4
- function walk(
1
+ export function walk(
5
2
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
6
3
  nodeList, walker, depth = 0) {
7
4
  for (const node of nodeList) {
@@ -19,4 +16,3 @@ nodeList, walker, depth = 0) {
19
16
  }
20
17
  }
21
18
  }
22
- exports.walk = walk;
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@markuplint/parser-utils",
3
- "version": "3.10.0",
3
+ "version": "4.0.0-alpha.1",
4
4
  "description": "Utility module for markuplint parser plugin",
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",
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./lib/index.js"
13
+ }
14
+ },
10
15
  "types": "lib/index.d.ts",
11
16
  "publishConfig": {
12
17
  "access": "public"
@@ -19,12 +24,12 @@
19
24
  "clean": "tsc --build --clean"
20
25
  },
21
26
  "dependencies": {
22
- "@markuplint/ml-ast": "3.2.0",
23
- "@markuplint/types": "3.9.0",
27
+ "@markuplint/ml-ast": "4.0.0-alpha.1",
28
+ "@markuplint/types": "4.0.0-alpha.1",
24
29
  "@types/uuid": "^9.0.2",
25
- "tslib": "^2.6.0",
26
- "type-fest": "^3.12.0",
30
+ "tslib": "^2.6.1",
31
+ "type-fest": "^4.1.0",
27
32
  "uuid": "^9.0.0"
28
33
  },
29
- "gitHead": "4ab20276db48a6acb29a923ea8666890ca853442"
34
+ "gitHead": "22502ee22a378ae766033d687dbc0443e5ed35dc"
30
35
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const idl_attributes_1 = require("./idl-attributes");
4
- it('basic', () => {
5
- expect((0, idl_attributes_1.searchIDLAttribute)('class')).toStrictEqual({
6
- idlPropName: 'className',
7
- contentAttrName: 'class',
8
- });
9
- expect((0, idl_attributes_1.searchIDLAttribute)('for')).toStrictEqual({
10
- idlPropName: 'htmlFor',
11
- contentAttrName: 'for',
12
- });
13
- expect((0, idl_attributes_1.searchIDLAttribute)('className')).toStrictEqual({
14
- idlPropName: 'className',
15
- contentAttrName: 'class',
16
- });
17
- expect((0, idl_attributes_1.searchIDLAttribute)('htmlFor')).toStrictEqual({
18
- idlPropName: 'htmlFor',
19
- contentAttrName: 'for',
20
- });
21
- expect((0, idl_attributes_1.searchIDLAttribute)('tabindex')).toStrictEqual({
22
- idlPropName: 'tabIndex',
23
- contentAttrName: 'tabindex',
24
- });
25
- expect((0, idl_attributes_1.searchIDLAttribute)('tab-index')).toStrictEqual({
26
- idlPropName: 'tabIndex',
27
- contentAttrName: 'tabindex',
28
- });
29
- expect((0, idl_attributes_1.searchIDLAttribute)('TabIndex')).toStrictEqual({
30
- idlPropName: 'tabIndex',
31
- contentAttrName: 'tabindex',
32
- });
33
- expect((0, idl_attributes_1.searchIDLAttribute)('x')).toStrictEqual({
34
- idlPropName: 'x',
35
- contentAttrName: 'x',
36
- });
37
- expect((0, idl_attributes_1.searchIDLAttribute)('y')).toStrictEqual({
38
- idlPropName: 'y',
39
- contentAttrName: 'y',
40
- });
41
- expect((0, idl_attributes_1.searchIDLAttribute)('attribute-name')).toStrictEqual({
42
- idlPropName: 'attributeName',
43
- contentAttrName: 'attributeName',
44
- });
45
- });
@@ -1,17 +0,0 @@
1
- const { tokenizer } = require('../lib/create-token');
2
-
3
- describe('tokenizer', () => {
4
- it('empty', () => {
5
- expect(tokenizer('', 1, 1, 0)).toEqual(
6
- expect.objectContaining({
7
- raw: '',
8
- startLine: 1,
9
- startCol: 1,
10
- startOffset: 0,
11
- endLine: 1,
12
- endCol: 1,
13
- endOffset: 0,
14
- }),
15
- );
16
- });
17
- });
@@ -1,31 +0,0 @@
1
- const { isDocumentFragment, createTree } = require('@markuplint/html-parser');
2
-
3
- const { flattenNodes } = require('../lib/flatten-nodes');
4
-
5
- function toTree(rawCode) {
6
- const isFragment = isDocumentFragment(rawCode);
7
- return createTree(rawCode, isFragment, 0, 0, 0);
8
- }
9
-
10
- describe('flattenNodes', () => {
11
- it('a node', () => {
12
- const raw = '<div></div>';
13
- const tree = toTree(raw);
14
- const list = flattenNodes(tree, raw);
15
- expect(list.length).toStrictEqual(2);
16
- });
17
-
18
- it('one depth', () => {
19
- const raw = '<div><span></span></div>';
20
- const tree = toTree(raw);
21
- const list = flattenNodes(tree, raw);
22
- expect(list.length).toStrictEqual(4);
23
- });
24
-
25
- it('two depth', () => {
26
- const raw = '<div><span><span></span></span></div>';
27
- const tree = toTree(raw);
28
- const list = flattenNodes(tree, raw);
29
- expect(list.length).toStrictEqual(6);
30
- });
31
- });
@@ -1,38 +0,0 @@
1
- const { getEndCol, getEndLine } = require('../lib/get-location');
2
-
3
- describe('getEndLine', () => {
4
- it('empty', () => {
5
- expect(getEndLine('', 1)).toBe(1);
6
- expect(getEndLine('', 3)).toBe(3);
7
- });
8
-
9
- it('basic', () => {
10
- expect(getEndLine('\n\n', 2)).toBe(4);
11
- expect(getEndLine('\n\n', 4)).toBe(6);
12
- expect(getEndLine('\n\n \n \n foo', 1)).toBe(5);
13
- expect(getEndLine('\n\n \n \n foo', 6)).toBe(10);
14
- });
15
- });
16
-
17
- describe('getEndCol', () => {
18
- it('empty', () => {
19
- expect(getEndCol('', 1)).toBe(1);
20
- expect(getEndCol('', 3)).toBe(3);
21
- });
22
-
23
- it('basic', () => {
24
- expect(getEndCol(' ', 2)).toBe(4);
25
- expect(getEndCol(' ', 4)).toBe(6);
26
- expect(getEndCol('foo bar', 1)).toBe(8);
27
- expect(getEndCol('foo bar', 6)).toBe(13);
28
- });
29
-
30
- it('with line break', () => {
31
- expect(getEndCol('foo bar\n', 4)).toBe(1);
32
- expect(getEndCol('foo bar\n', 4)).toBe(1);
33
- expect(getEndCol('foo bar\n ', 4)).toBe(3);
34
- expect(getEndCol('foo bar\n ', 4)).toBe(3);
35
- expect(getEndCol('foo bar\nfoo bar', 1)).toBe(8);
36
- expect(getEndCol('foo bar\nfoo bar', 6)).toBe(8);
37
- });
38
- });
@@ -1,274 +0,0 @@
1
- const { parse } = require('@markuplint/html-parser');
2
-
3
- const { nodeListToDebugMaps } = require('../lib/debugger');
4
- const { ignoreBlock, restoreNode } = require('../lib/ignore-block');
5
-
6
- const tags = [
7
- {
8
- type: 'ejs-tag',
9
- start: /<%/,
10
- end: /%>/,
11
- },
12
- ];
13
-
14
- describe('ignoreBlock', () => {
15
- it('basic', () => {
16
- const result = ignoreBlock('<div><%= test %></div>', tags);
17
- expect(result).toStrictEqual({
18
- source: '<div><%= test %></div>',
19
- replaced: '<div><!></div>',
20
- stack: [
21
- {
22
- type: 'ejs-tag',
23
- index: 5,
24
- startTag: '<%',
25
- taggedCode: '= test ',
26
- endTag: '%>',
27
- },
28
- ],
29
- maskChar: '',
30
- });
31
- });
32
-
33
- it('2 tags', () => {
34
- const result = ignoreBlock('<div><%= test %></div><div><%= test2 %></div>', tags);
35
- expect(result).toStrictEqual({
36
- source: '<div><%= test %></div><div><%= test2 %></div>',
37
- replaced: '<div><!></div><div><!></div>',
38
- stack: [
39
- {
40
- type: 'ejs-tag',
41
- index: 5,
42
- startTag: '<%',
43
- taggedCode: '= test ',
44
- endTag: '%>',
45
- },
46
- {
47
- type: 'ejs-tag',
48
- index: 27,
49
- startTag: '<%',
50
- taggedCode: '= test2 ',
51
- endTag: '%>',
52
- },
53
- ],
54
- maskChar: '',
55
- });
56
- });
57
-
58
- it('without closing tag', () => {
59
- const result = ignoreBlock('<div><%= test', tags);
60
- expect(result).toStrictEqual({
61
- source: '<div><%= test',
62
- replaced: '<div><!>',
63
- stack: [
64
- {
65
- type: 'ejs-tag',
66
- index: 5,
67
- startTag: '<%',
68
- taggedCode: '= test',
69
- endTag: null,
70
- },
71
- ],
72
- maskChar: '',
73
- });
74
- });
75
-
76
- it('with line break', () => {
77
- const result = ignoreBlock('<div><% if () {\n\t\n} %></div>', tags);
78
- expect(result).toStrictEqual({
79
- source: '<div><% if () {\n\t\n} %></div>',
80
- replaced: '<div><!\n\n></div>',
81
- stack: [
82
- {
83
- type: 'ejs-tag',
84
- index: 5,
85
- startTag: '<%',
86
- taggedCode: ' if () {\n\t\n} ',
87
- endTag: '%>',
88
- },
89
- ],
90
- maskChar: '',
91
- });
92
- });
93
-
94
- it('multiple tags', () => {
95
- const result = ignoreBlock('<% 1 %>2<%= 3 %>4<%_ 5 _%>6<%- 7 -%>8<%% 9 %>', [
96
- {
97
- type: 'ejs-whitespace-slurping',
98
- start: /<%_/,
99
- end: /%>/,
100
- },
101
- {
102
- type: 'ejs-output-value',
103
- start: /<%=/,
104
- end: /%>/,
105
- },
106
- {
107
- type: 'ejs-output-unescaped',
108
- start: /<%-/,
109
- end: /%>/,
110
- },
111
- {
112
- type: 'ejs-comment',
113
- start: /<%#/,
114
- end: /%>/,
115
- },
116
- {
117
- type: 'ejs-scriptlet',
118
- start: /<%(?!%)/,
119
- end: /%>/,
120
- },
121
- ]);
122
-
123
- expect(result).toStrictEqual({
124
- source: '<% 1 %>2<%= 3 %>4<%_ 5 _%>6<%- 7 -%>8<%% 9 %>',
125
- replaced: '<!>2<!>4<!>6<!>8<%% 9 %>',
126
- stack: [
127
- {
128
- type: 'ejs-scriptlet',
129
- index: 0,
130
- startTag: '<%',
131
- taggedCode: ' 1 ',
132
- endTag: '%>',
133
- },
134
- {
135
- type: 'ejs-output-value',
136
- index: 8,
137
- startTag: '<%=',
138
- taggedCode: ' 3 ',
139
- endTag: '%>',
140
- },
141
- {
142
- type: 'ejs-whitespace-slurping',
143
- index: 17,
144
- startTag: '<%_',
145
- taggedCode: ' 5 _',
146
- endTag: '%>',
147
- },
148
- {
149
- type: 'ejs-output-unescaped',
150
- index: 27,
151
- startTag: '<%-',
152
- taggedCode: ' 7 -',
153
- endTag: '%>',
154
- },
155
- ],
156
- maskChar: '',
157
- });
158
- });
159
- });
160
-
161
- describe('restoreNode', () => {
162
- it('basic', () => {
163
- const code = '<div attr="<% attr %>"><% content %></div>';
164
- const masked = ignoreBlock(code, tags);
165
- const ast = parse(masked.replaced);
166
- const restoredAst = restoreNode(ast.nodeList, masked);
167
- const nodeMap = nodeListToDebugMaps(restoredAst, true);
168
- // TODO: Remove the masks from Element.raw and Attribute.raw
169
- expect(nodeMap).toStrictEqual([
170
- '[1:1]>[1:24](0,23)div: <div␣attr="">',
171
- '[1:6]>[1:23](5,22)attr: attr=""',
172
- ' [1:5]>[1:6](4,5)bN: ␣',
173
- ' [1:6]>[1:10](5,9)name: attr',
174
- ' [1:10]>[1:10](9,9)bE: ',
175
- ' [1:10]>[1:11](9,10)equal: =',
176
- ' [1:11]>[1:11](10,10)aE: ',
177
- ' [1:11]>[1:12](10,11)sQ: "',
178
- ' [1:12]>[1:22](11,21)value: <%␣attr␣%>',
179
- ' [1:22]>[1:23](21,22)eQ: "',
180
- ' isDirective: false',
181
- ' isDynamicValue: true',
182
- '[1:24]>[1:37](23,36)#ps:ejs-tag: <%␣content␣%>',
183
- '[1:37]>[1:43](36,42)div: </div>',
184
- ]);
185
- });
186
-
187
- it('tag', () => {
188
- const code = '<title><% content %></title>';
189
- const masked = ignoreBlock(code, tags);
190
- const ast = parse(masked.replaced);
191
- const restoredAst = restoreNode(ast.nodeList, masked);
192
- const nodeMap = nodeListToDebugMaps(restoredAst);
193
- expect(nodeMap).toStrictEqual([
194
- '[1:1]>[1:8](0,7)title: <title>',
195
- '[1:8]>[1:21](7,20)#ps:ejs-tag: <%␣content␣%>',
196
- '[1:21]>[1:29](20,28)title: </title>',
197
- ]);
198
- });
199
-
200
- it('attr', () => {
201
- const code = '<div attr="<% attr %><% attr2 %>"></div>';
202
- const masked = ignoreBlock(code, tags);
203
- const ast = parse(masked.replaced);
204
- const restoredAst = restoreNode(ast.nodeList, masked);
205
- expect(restoredAst[0].attributes[0].value.raw).toBe('<% attr %><% attr2 %>');
206
- });
207
-
208
- it('attr', () => {
209
- const code = '<div attr="<% attr %> <% attr2 %>"></div>';
210
- const masked = ignoreBlock(code, tags);
211
- const ast = parse(masked.replaced);
212
- const restoredAst = restoreNode(ast.nodeList, masked);
213
- expect(restoredAst[0].attributes[0].value.raw).toBe('<% attr %> <% attr2 %>');
214
- });
215
-
216
- it('attr', () => {
217
- const code = '<div attr="<% attr %>A<% attr2 %>"></div>';
218
- const masked = ignoreBlock(code, tags);
219
- const ast = parse(masked.replaced);
220
- const restoredAst = restoreNode(ast.nodeList, masked);
221
- expect(restoredAst[0].attributes[0].value.raw).toBe('<% attr %>A<% attr2 %>');
222
- });
223
-
224
- it('before space', () => {
225
- const code = '<div attr=" <% attr %>"></div>';
226
- const masked = ignoreBlock(code, tags);
227
- const ast = parse(masked.replaced);
228
- const restoredAst = restoreNode(ast.nodeList, masked);
229
- expect(restoredAst[0].attributes[0].value.raw).toBe(' <% attr %>');
230
- });
231
-
232
- it('after space', () => {
233
- const code = '<div attr=" <% attr %> "></div>';
234
- const masked = ignoreBlock(code, tags);
235
- const ast = parse(masked.replaced);
236
- const restoredAst = restoreNode(ast.nodeList, masked);
237
- expect(restoredAst[0].attributes[0].value.raw).toBe(' <% attr %> ');
238
- });
239
-
240
- it('before char', () => {
241
- const code = '<div attr="A<% attr %>"></div>';
242
- const masked = ignoreBlock(code, tags);
243
- const ast = parse(masked.replaced);
244
- const restoredAst = restoreNode(ast.nodeList, masked);
245
- expect(restoredAst[0].attributes[0].value.raw).toBe('A<% attr %>');
246
- });
247
-
248
- it('after char', () => {
249
- const code = '<div attr="A<% attr %>B"></div>';
250
- const masked = ignoreBlock(code, tags);
251
- const ast = parse(masked.replaced);
252
- const restoredAst = restoreNode(ast.nodeList, masked);
253
- expect(restoredAst[0].attributes[0].value.raw).toBe('A<% attr %>B');
254
- });
255
-
256
- it('unexpected parsing', () => {
257
- const code = '<div attr="<% attr %> "></div>';
258
- const masked = ignoreBlock(code, tags);
259
- const ast = parse(masked.replaced);
260
- const restoredAst = restoreNode(ast.nodeList, masked);
261
- expect(restoredAst).toStrictEqual([]);
262
- });
263
- });
264
-
265
- describe('Issues', () => {
266
- test('#607', () => {
267
- const code = '<div><% %><img/></div>';
268
- const masked = ignoreBlock(code, tags);
269
- const ast = parse(masked.replaced);
270
- const restoredAst = restoreNode(ast.nodeList, masked);
271
- expect(restoredAst[2].parentNode?.uuid).toBe(restoredAst[0].uuid);
272
- expect(restoredAst[2].prevNode?.uuid).toBe(restoredAst[1].uuid);
273
- });
274
- });