@markuplint/ejs-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.
package/lib/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { parse } from './parse';
1
+ export { parse } from './parse.js';
package/lib/index.js CHANGED
@@ -1,5 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parse = void 0;
4
- var parse_1 = require("./parse");
5
- Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } });
1
+ export { parse } from './parse.js';
package/lib/parse.js CHANGED
@@ -1,10 +1,7 @@
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 parse = (rawCode, options) => {
7
- const blocks = (0, parser_utils_1.ignoreBlock)(rawCode, [
1
+ import { parse as htmlParse } from '@markuplint/html-parser';
2
+ import { ignoreBlock, restoreNode } from '@markuplint/parser-utils';
3
+ export const parse = (rawCode, options) => {
4
+ const blocks = ignoreBlock(rawCode, [
8
5
  {
9
6
  type: 'ejs-whitespace-slurping',
10
7
  start: /<%_/,
@@ -31,8 +28,7 @@ const parse = (rawCode, options) => {
31
28
  end: /%>/,
32
29
  },
33
30
  ]);
34
- const doc = (0, html_parser_1.parse)(blocks.replaced, options);
35
- doc.nodeList = (0, parser_utils_1.restoreNode)(doc.nodeList, blocks);
31
+ const doc = htmlParse(blocks.replaced, options);
32
+ doc.nodeList = restoreNode(doc.nodeList, blocks);
36
33
  return doc;
37
34
  };
38
- exports.parse = parse;
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@markuplint/ejs-parser",
3
- "version": "3.10.0",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "EJS 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",
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"
@@ -16,9 +21,9 @@
16
21
  "clean": "tsc --build --clean"
17
22
  },
18
23
  "dependencies": {
19
- "@markuplint/html-parser": "3.11.0",
20
- "@markuplint/ml-ast": "3.2.0",
21
- "@markuplint/parser-utils": "3.11.0"
24
+ "@markuplint/html-parser": "4.0.0-alpha.2",
25
+ "@markuplint/ml-ast": "4.0.0-alpha.2",
26
+ "@markuplint/parser-utils": "4.0.0-alpha.2"
22
27
  },
23
- "gitHead": "ef31aef8f2fff319d0f692feead332ec5fc5c7cf"
28
+ "gitHead": "51ad52c760435641f9bff8685707d8178b0787eb"
24
29
  }
@@ -1,168 +0,0 @@
1
- const { nodeListToDebugMaps } = require('@markuplint/parser-utils');
2
-
3
- const { parse } = require('../lib/');
4
-
5
- describe('Node list', () => {
6
- it('a code', () => {
7
- const doc = parse('<div>abc<%= efg %>hij</div>');
8
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
9
- '[1:1]>[1:6](0,5)div: <div>',
10
- '[1:6]>[1:9](5,8)#text: abc',
11
- '[1:9]>[1:19](8,18)#ps:ejs-output-value: <%=␣efg␣%>',
12
- '[1:19]>[1:22](18,21)#text: hij',
13
- '[1:22]>[1:28](21,27)div: </div>',
14
- ]);
15
- });
16
-
17
- it('two codes', () => {
18
- const doc = parse('<div>abc<%= efg %>hij<%= klm %></div>');
19
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
20
- '[1:1]>[1:6](0,5)div: <div>',
21
- '[1:6]>[1:9](5,8)#text: abc',
22
- '[1:9]>[1:19](8,18)#ps:ejs-output-value: <%=␣efg␣%>',
23
- '[1:19]>[1:22](18,21)#text: hij',
24
- '[1:22]>[1:32](21,31)#ps:ejs-output-value: <%=␣klm␣%>',
25
- '[1:32]>[1:38](31,37)div: </div>',
26
- ]);
27
- });
28
-
29
- it('two codes2', () => {
30
- const doc = parse('<div>abc<%= efg %>hij<%= klm %>nop</div>');
31
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
32
- '[1:1]>[1:6](0,5)div: <div>',
33
- '[1:6]>[1:9](5,8)#text: abc',
34
- '[1:9]>[1:19](8,18)#ps:ejs-output-value: <%=␣efg␣%>',
35
- '[1:19]>[1:22](18,21)#text: hij',
36
- '[1:22]>[1:32](21,31)#ps:ejs-output-value: <%=␣klm␣%>',
37
- '[1:32]>[1:35](31,34)#text: nop',
38
- '[1:35]>[1:41](34,40)div: </div>',
39
- ]);
40
- });
41
-
42
- it('two codes2 on bare', () => {
43
- const doc = parse('abc<%= efg %>hij<%= klm %>nop');
44
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
45
- '[1:1]>[1:4](0,3)#text: abc',
46
- '[1:4]>[1:14](3,13)#ps:ejs-output-value: <%=␣efg␣%>',
47
- '[1:14]>[1:17](13,16)#text: hij',
48
- '[1:17]>[1:27](16,26)#ps:ejs-output-value: <%=␣klm␣%>',
49
- '[1:27]>[1:30](26,29)#text: nop',
50
- ]);
51
- });
52
-
53
- it('nest block', () => {
54
- const doc = parse('<% if (foo) { %>abcdef<% } %>');
55
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
56
- '[1:1]>[1:17](0,16)#ps:ejs-scriptlet: <%␣if␣(foo)␣{␣%>',
57
- '[1:17]>[1:23](16,22)#text: abcdef',
58
- '[1:23]>[1:30](22,29)#ps:ejs-scriptlet: <%␣}␣%>',
59
- ]);
60
- });
61
-
62
- it('nest block', () => {
63
- const doc = parse('<% if (foo) { %>abc<%= foo %>def<% } %>');
64
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
65
- '[1:1]>[1:17](0,16)#ps:ejs-scriptlet: <%␣if␣(foo)␣{␣%>',
66
- '[1:17]>[1:20](16,19)#text: abc',
67
- '[1:20]>[1:30](19,29)#ps:ejs-output-value: <%=␣foo␣%>',
68
- '[1:30]>[1:33](29,32)#text: def',
69
- '[1:33]>[1:40](32,39)#ps:ejs-scriptlet: <%␣}␣%>',
70
- ]);
71
- });
72
-
73
- it('nest block', () => {
74
- const doc = parse(`<% if (user) { %>
75
- <div><%= user.name %></div>
76
- <% } %>
77
- `);
78
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
79
- '[1:1]>[1:18](0,17)#ps:ejs-scriptlet: <%␣if␣(user)␣{␣%>',
80
- '[1:18]>[2:1](17,18)#text: ⏎',
81
- '[2:1]>[2:6](18,23)div: <div>',
82
- '[2:6]>[2:22](23,39)#ps:ejs-output-value: <%=␣user.name␣%>',
83
- '[2:22]>[2:28](39,45)div: </div>',
84
- '[2:28]>[3:1](45,46)#text: ⏎',
85
- '[3:1]>[3:8](46,53)#ps:ejs-scriptlet: <%␣}␣%>',
86
- '[3:8]>[4:1](53,54)#text: ⏎',
87
- ]);
88
-
89
- const el = doc.nodeList[3];
90
- const el2 = doc.nodeList[3].parentNode.childNodes[0];
91
- expect(el.nodeName).toBe(el2.nodeName);
92
- expect(el.uuid).toBe(el2.uuid);
93
- });
94
-
95
- it('Full HTML', () => {
96
- const doc = parse(`<!DOCTYPE html>
97
- <html lang="en">
98
- <head>
99
- <%- include('path/to') _%>
100
- <meta />
101
- </head>
102
- <body></body>
103
- </html>
104
- `);
105
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
106
- '[1:1]>[1:16](0,15)#doctype: <!DOCTYPE␣html>',
107
- '[1:16]>[2:1](15,16)#text: ⏎',
108
- '[2:1]>[2:17](16,32)html: <html␣lang="en">',
109
- '[2:17]>[3:2](32,34)#text: ⏎→',
110
- '[3:2]>[3:8](34,40)head: <head>',
111
- '[3:8]>[4:3](40,43)#text: ⏎→→',
112
- "[4:3]>[4:29](43,69)#ps:ejs-output-unescaped: <%-␣include('path/to')␣_%>",
113
- '[4:29]>[5:3](69,72)#text: ⏎→→',
114
- '[5:3]>[5:11](72,80)meta: <meta␣/>',
115
- '[5:11]>[6:2](80,82)#text: ⏎→',
116
- '[6:2]>[6:9](82,89)head: </head>',
117
- '[6:9]>[7:2](89,91)#text: ⏎→',
118
- '[7:2]>[7:8](91,97)body: <body>',
119
- '[7:8]>[7:15](97,104)body: </body>',
120
- '[7:15]>[8:1](104,105)#text: ⏎',
121
- '[8:1]>[8:8](105,112)html: </html>',
122
- '[8:8]>[9:1](112,113)#text: ⏎',
123
- ]);
124
- });
125
-
126
- it('mutable text node', () => {
127
- const doc = parse('<title><%= title %></title>');
128
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
129
- '[1:1]>[1:8](0,7)title: <title>',
130
- '[1:8]>[1:20](7,19)#ps:ejs-output-value: <%=␣title␣%>',
131
- '[1:20]>[1:28](19,27)title: </title>',
132
- ]);
133
- });
134
- });
135
-
136
- describe('Tags', () => {
137
- it('ejs-whitespace-slurping', () => {
138
- expect(parse('<%_ any _%>').nodeList[0].nodeName).toBe('#ps:ejs-whitespace-slurping');
139
- });
140
-
141
- it('ejs-output-value', () => {
142
- expect(parse('<%= any %>').nodeList[0].nodeName).toBe('#ps:ejs-output-value');
143
- });
144
-
145
- it('ejs-output-unescaped', () => {
146
- expect(parse('<%- any -%>').nodeList[0].nodeName).toBe('#ps:ejs-output-unescaped');
147
- });
148
-
149
- it('ejs-comment', () => {
150
- expect(parse('<%# any %>').nodeList[0].nodeName).toBe('#ps:ejs-comment');
151
- });
152
-
153
- it('ejs-scriptlet', () => {
154
- expect(parse('<% any %>').nodeList[0].nodeName).toBe('#ps:ejs-scriptlet');
155
- });
156
-
157
- it('text node', () => {
158
- expect(parse('<%% any %>').nodeList[0].nodeName).toBe('#text');
159
- });
160
- });
161
-
162
- describe('Issues', () => {
163
- test('#607', () => {
164
- const ast = parse('<% %><div></div>');
165
- expect(ast.nodeList.length).toBe(3);
166
- expect(ast.nodeList[1].prevNode?.uuid).toBe(ast.nodeList[0].uuid);
167
- });
168
- });