@markuplint/php-parser 3.12.0 → 4.0.0-alpha.10
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/LICENSE +1 -1
- package/README.md +0 -10
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -5
- package/lib/parser.d.ts +6 -0
- package/lib/parser.js +25 -0
- package/package.json +12 -6
- package/lib/parse.d.ts +0 -2
- package/lib/parse.js +0 -28
- package/test/index.spec.js +0 -119
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -53,13 +53,3 @@ If it doesn't nest by quotations.
|
|
|
53
53
|
<div attr=<?php echo value; ?>></div>
|
|
54
54
|
```
|
|
55
55
|
<!-- prettier-ignore-end -->
|
|
56
|
-
|
|
57
|
-
If it mixes the tags and spaces.
|
|
58
|
-
|
|
59
|
-
```html
|
|
60
|
-
<div attr=" <?php echo value; ?> "></div>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
```html
|
|
64
|
-
<div attr="<?php echo value; ?> <?php echo value2; ?>"></div>
|
|
65
|
-
```
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { parser } from './parser.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 { parser } from './parser.js';
|
package/lib/parser.d.ts
ADDED
package/lib/parser.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { HtmlParser } from '@markuplint/html-parser';
|
|
2
|
+
class PHPParser extends HtmlParser {
|
|
3
|
+
constructor() {
|
|
4
|
+
super({
|
|
5
|
+
ignoreTags: [
|
|
6
|
+
{
|
|
7
|
+
type: 'php-tag',
|
|
8
|
+
start: '<?php',
|
|
9
|
+
end: /\?>|$/,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
type: 'php-echo',
|
|
13
|
+
start: '<?=',
|
|
14
|
+
end: '?>',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
type: 'php-short-tag',
|
|
18
|
+
start: '<?',
|
|
19
|
+
end: /\?>|$/,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export const parser = new PHPParser();
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/php-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.10",
|
|
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,10 @@
|
|
|
16
21
|
"clean": "tsc --build --clean"
|
|
17
22
|
},
|
|
18
23
|
"dependencies": {
|
|
19
|
-
"@markuplint/html-parser": "
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
"@markuplint/html-parser": "4.0.0-alpha.10"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@markuplint/parser-utils": "4.0.0-alpha.10"
|
|
22
28
|
},
|
|
23
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "b41153ea665aa8f091daf6114a06047f4ccb8350"
|
|
24
30
|
}
|
package/lib/parse.d.ts
DELETED
package/lib/parse.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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, [
|
|
8
|
-
{
|
|
9
|
-
type: 'php-tag',
|
|
10
|
-
start: /<\?php/,
|
|
11
|
-
end: /\?>|$/,
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
type: 'php-echo',
|
|
15
|
-
start: /<\?=/,
|
|
16
|
-
end: /\?>/,
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
type: 'php-short-tag',
|
|
20
|
-
start: /<\?/,
|
|
21
|
-
end: /\?>|$/,
|
|
22
|
-
},
|
|
23
|
-
]);
|
|
24
|
-
const doc = (0, html_parser_1.parse)(blocks.replaced, options);
|
|
25
|
-
doc.nodeList = (0, parser_utils_1.restoreNode)(doc.nodeList, blocks);
|
|
26
|
-
return doc;
|
|
27
|
-
};
|
|
28
|
-
exports.parse = parse;
|
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
|
-
});
|