@markuplint/erb-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 +1 -1
- package/lib/index.js +1 -5
- package/lib/parse.js +6 -10
- package/package.json +11 -6
- package/test/index.spec.js +0 -112
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
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: 'erb-ruby-expression',
|
|
10
7
|
start: /<%=/,
|
|
@@ -27,8 +24,7 @@ const parse = (rawCode, options) => {
|
|
|
27
24
|
// end: /\n|$/
|
|
28
25
|
// }
|
|
29
26
|
]);
|
|
30
|
-
const doc = (
|
|
31
|
-
doc.nodeList =
|
|
27
|
+
const doc = htmlParse(blocks.replaced, options);
|
|
28
|
+
doc.nodeList = restoreNode(doc.nodeList, blocks);
|
|
32
29
|
return doc;
|
|
33
30
|
};
|
|
34
|
-
exports.parse = parse;
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/erb-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.2",
|
|
4
4
|
"description": "eRuby template 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
|
-
"
|
|
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": "
|
|
20
|
-
"@markuplint/ml-ast": "
|
|
21
|
-
"@markuplint/parser-utils": "
|
|
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": "
|
|
28
|
+
"gitHead": "51ad52c760435641f9bff8685707d8178b0787eb"
|
|
24
29
|
}
|
package/test/index.spec.js
DELETED
|
@@ -1,112 +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:erb-ruby-expression: <%=␣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:erb-ruby-expression: <%=␣efg␣%>',
|
|
23
|
-
'[1:19]>[1:22](18,21)#text: hij',
|
|
24
|
-
'[1:22]>[1:32](21,31)#ps:erb-ruby-expression: <%=␣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:erb-ruby-expression: <%=␣efg␣%>',
|
|
35
|
-
'[1:19]>[1:22](18,21)#text: hij',
|
|
36
|
-
'[1:22]>[1:32](21,31)#ps:erb-ruby-expression: <%=␣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:erb-ruby-expression: <%=␣efg␣%>',
|
|
47
|
-
'[1:14]>[1:17](13,16)#text: hij',
|
|
48
|
-
'[1:17]>[1:27](16,26)#ps:erb-ruby-expression: <%=␣klm␣%>',
|
|
49
|
-
'[1:27]>[1:30](26,29)#text: nop',
|
|
50
|
-
]);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('nest block', () => {
|
|
54
|
-
const doc = parse('<% if foo then %>abcdef<% end %>');
|
|
55
|
-
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
56
|
-
'[1:1]>[1:18](0,17)#ps:erb-ruby-code: <%␣if␣foo␣then␣%>',
|
|
57
|
-
'[1:18]>[1:24](17,23)#text: abcdef',
|
|
58
|
-
'[1:24]>[1:33](23,32)#ps:erb-ruby-code: <%␣end␣%>',
|
|
59
|
-
]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('nest block', () => {
|
|
63
|
-
const doc = parse('<% if foo then %>abc<%= foo %>def<% end %>');
|
|
64
|
-
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
65
|
-
'[1:1]>[1:18](0,17)#ps:erb-ruby-code: <%␣if␣foo␣then␣%>',
|
|
66
|
-
'[1:18]>[1:21](17,20)#text: abc',
|
|
67
|
-
'[1:21]>[1:31](20,30)#ps:erb-ruby-expression: <%=␣foo␣%>',
|
|
68
|
-
'[1:31]>[1:34](30,33)#text: def',
|
|
69
|
-
'[1:34]>[1:43](33,42)#ps:erb-ruby-code: <%␣end␣%>',
|
|
70
|
-
]);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('nest block', () => {
|
|
74
|
-
const doc = parse(`<% if user then %>
|
|
75
|
-
<div><%= user.name %></div>
|
|
76
|
-
<% end %>
|
|
77
|
-
`);
|
|
78
|
-
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
79
|
-
'[1:1]>[1:19](0,18)#ps:erb-ruby-code: <%␣if␣user␣then␣%>',
|
|
80
|
-
'[1:19]>[2:1](18,19)#text: ⏎',
|
|
81
|
-
'[2:1]>[2:6](19,24)div: <div>',
|
|
82
|
-
'[2:6]>[2:22](24,40)#ps:erb-ruby-expression: <%=␣user.name␣%>',
|
|
83
|
-
'[2:22]>[2:28](40,46)div: </div>',
|
|
84
|
-
'[2:28]>[3:1](46,47)#text: ⏎',
|
|
85
|
-
'[3:1]>[3:10](47,56)#ps:erb-ruby-code: <%␣end␣%>',
|
|
86
|
-
'[3:10]>[4:1](56,57)#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
|
-
|
|
96
|
-
describe('Tags', () => {
|
|
97
|
-
it('erb-ruby-expression', () => {
|
|
98
|
-
expect(parse('<%= any %>').nodeList[0].nodeName).toBe('#ps:erb-ruby-expression');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('erb-comment', () => {
|
|
102
|
-
expect(parse('<%# any %>').nodeList[0].nodeName).toBe('#ps:erb-comment');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('erb-ruby-code', () => {
|
|
106
|
-
expect(parse('<% any %>').nodeList[0].nodeName).toBe('#ps:erb-ruby-code');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('text node', () => {
|
|
110
|
-
expect(parse('<%% any %>').nodeList[0].nodeName).toBe('#text');
|
|
111
|
-
});
|
|
112
|
-
});
|