@markuplint/php-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 -119
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: 'php-tag',
|
|
10
7
|
start: /<\?php/,
|
|
@@ -21,8 +18,7 @@ const parse = (rawCode, options) => {
|
|
|
21
18
|
end: /\?>|$/,
|
|
22
19
|
},
|
|
23
20
|
]);
|
|
24
|
-
const doc = (
|
|
25
|
-
doc.nodeList =
|
|
21
|
+
const doc = htmlParse(blocks.replaced, options);
|
|
22
|
+
doc.nodeList = restoreNode(doc.nodeList, blocks);
|
|
26
23
|
return doc;
|
|
27
24
|
};
|
|
28
|
-
exports.parse = parse;
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/php-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.2",
|
|
4
4
|
"description": "PHP 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,119 +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:php-echo: <?=␣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:php-echo: <?=␣efg␣?>',
|
|
23
|
-
'[1:19]>[1:22](18,21)#text: hij',
|
|
24
|
-
'[1:22]>[1:32](21,31)#ps:php-echo: <?=␣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:php-echo: <?=␣efg␣?>',
|
|
35
|
-
'[1:19]>[1:22](18,21)#text: hij',
|
|
36
|
-
'[1:22]>[1:32](21,31)#ps:php-echo: <?=␣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:php-echo: <?=␣efg␣?>',
|
|
47
|
-
'[1:14]>[1:17](13,16)#text: hij',
|
|
48
|
-
'[1:17]>[1:27](16,26)#ps:php-echo: <?=␣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:php-short-tag: <?␣if␣(foo)␣{␣?>',
|
|
57
|
-
'[1:17]>[1:23](16,22)#text: abcdef',
|
|
58
|
-
'[1:23]>[1:30](22,29)#ps:php-short-tag: <?␣}␣?>',
|
|
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:php-short-tag: <?␣if␣(foo)␣{␣?>',
|
|
66
|
-
'[1:17]>[1:20](16,19)#text: abc',
|
|
67
|
-
'[1:20]>[1:30](19,29)#ps:php-echo: <?=␣foo␣?>',
|
|
68
|
-
'[1:30]>[1:33](29,32)#text: def',
|
|
69
|
-
'[1:33]>[1:40](32,39)#ps:php-short-tag: <?␣}␣?>',
|
|
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:php-short-tag: <?␣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:php-echo: <?=␣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:php-short-tag: <?␣}␣?>',
|
|
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('omitted close tag', () => {
|
|
96
|
-
const doc = parse('<div></div><?php include("path/to")');
|
|
97
|
-
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
98
|
-
'[1:1]>[1:6](0,5)div: <div>',
|
|
99
|
-
'[1:6]>[1:12](5,11)div: </div>',
|
|
100
|
-
'[1:12]>[1:36](11,35)#ps:php-tag: <?php␣include("path/to")',
|
|
101
|
-
]);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('Tags', () => {
|
|
106
|
-
it('php-tag', () => {
|
|
107
|
-
expect(parse('<?php any; ?>').nodeList[0].nodeName).toBe('#ps:php-tag');
|
|
108
|
-
expect(parse('<?php any;').nodeList[0].nodeName).toBe('#ps:php-tag');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('php-echo', () => {
|
|
112
|
-
expect(parse('<?= any ?>').nodeList[0].nodeName).toBe('#ps:php-echo');
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('php-short-tag', () => {
|
|
116
|
-
expect(parse('<? any; ?>').nodeList[0].nodeName).toBe('#ps:php-short-tag');
|
|
117
|
-
expect(parse('<? any;').nodeList[0].nodeName).toBe('#ps:php-short-tag');
|
|
118
|
-
});
|
|
119
|
-
});
|