@markuplint/smarty-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2019 Yusuke Hirao
3
+ Copyright (c) 2017-2024 Yusuke Hirao
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -53,13 +53,3 @@ If it doesn't nest by quotations.
53
53
  <div attr={ $value }></div>
54
54
  ```
55
55
  <!-- prettier-ignore-end -->
56
-
57
- If it mixes the tags and spaces.
58
-
59
- ```html
60
- <div attr=" { $value } "></div>
61
- ```
62
-
63
- ```html
64
- <div attr="{ $value } { $value2 }"></div>
65
- ```
package/lib/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { parse } from './parse';
1
+ export { parser } from './parser.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 { parser } from './parser.js';
@@ -0,0 +1,6 @@
1
+ import { HtmlParser } from '@markuplint/html-parser';
2
+ declare class SmartyParser extends HtmlParser {
3
+ constructor();
4
+ }
5
+ export declare const parser: SmartyParser;
6
+ export {};
package/lib/parser.js ADDED
@@ -0,0 +1,25 @@
1
+ import { HtmlParser } from '@markuplint/html-parser';
2
+ class SmartyParser extends HtmlParser {
3
+ constructor() {
4
+ super({
5
+ ignoreTags: [
6
+ {
7
+ type: 'smarty-literal',
8
+ start: '{literal}',
9
+ end: '{/literal}',
10
+ },
11
+ {
12
+ type: 'smarty-comment',
13
+ start: '{*',
14
+ end: '*}',
15
+ },
16
+ {
17
+ type: 'smarty-scriptlet',
18
+ start: '{',
19
+ end: '}',
20
+ },
21
+ ],
22
+ });
23
+ }
24
+ }
25
+ export const parser = new SmartyParser();
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@markuplint/smarty-parser",
3
- "version": "3.12.0",
3
+ "version": "4.0.0-alpha.10",
4
4
  "description": "Smarty 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,10 @@
16
21
  "clean": "tsc --build --clean"
17
22
  },
18
23
  "dependencies": {
19
- "@markuplint/html-parser": "3.13.0",
20
- "@markuplint/ml-ast": "3.2.0",
21
- "@markuplint/parser-utils": "3.13.0"
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": "b37b749d7ac0f9e6cbd022ee7031bc020c6677d3"
29
+ "gitHead": "b41153ea665aa8f091daf6114a06047f4ccb8350"
24
30
  }
package/lib/parse.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { Parse } from '@markuplint/ml-ast';
2
- export declare const parse: Parse;
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: 'smarty-literal',
10
- start: /{literal}/,
11
- end: /{\/literal}/,
12
- },
13
- {
14
- type: 'smarty-comment',
15
- start: /{\*/,
16
- end: /\*}/,
17
- },
18
- {
19
- type: 'smarty-scriptlet',
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;
@@ -1,155 +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:16](8,15)#ps:smarty-scriptlet: {␣efg␣}',
12
- '[1:16]>[1:19](15,18)#text: hij',
13
- '[1:19]>[1:25](18,24)div: </div>',
14
- ]);
15
- });
16
-
17
- it('two codes', () => {
18
- const doc = parse('<div>abc{ efg }hij{ kim }</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:16](8,15)#ps:smarty-scriptlet: {␣efg␣}',
23
- '[1:16]>[1:19](15,18)#text: hij',
24
- '[1:19]>[1:26](18,25)#ps:smarty-scriptlet: {␣kim␣}',
25
- '[1:26]>[1:32](25,31)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:16](8,15)#ps:smarty-scriptlet: {␣efg␣}',
35
- '[1:16]>[1:19](15,18)#text: hij',
36
- '[1:19]>[1:26](18,25)#ps:smarty-scriptlet: {␣klm␣}',
37
- '[1:26]>[1:29](25,28)#text: nop',
38
- '[1:29]>[1:35](28,34)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:11](3,10)#ps:smarty-scriptlet: {␣efg␣}',
47
- '[1:11]>[1:14](10,13)#text: hij',
48
- '[1:14]>[1:21](13,20)#ps:smarty-scriptlet: {␣klm␣}',
49
- '[1:21]>[1:24](20,23)#text: nop',
50
- ]);
51
- });
52
-
53
- it('nest block', () => {
54
- const doc = parse('{if foo}abcdef{/if}');
55
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
56
- '[1:1]>[1:9](0,8)#ps:smarty-scriptlet: {if␣foo}',
57
- '[1:9]>[1:15](8,14)#text: abcdef',
58
- '[1:15]>[1:20](14,19)#ps:smarty-scriptlet: {/if}',
59
- ]);
60
- });
61
-
62
- it('nest block', () => {
63
- const doc = parse('{if foo}abc{ foo }def{/if}');
64
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
65
- '[1:1]>[1:9](0,8)#ps:smarty-scriptlet: {if␣foo}',
66
- '[1:9]>[1:12](8,11)#text: abc',
67
- '[1:12]>[1:19](11,18)#ps:smarty-scriptlet: {␣foo␣}',
68
- '[1:19]>[1:22](18,21)#text: def',
69
- '[1:22]>[1:27](21,26)#ps:smarty-scriptlet: {/if}',
70
- ]);
71
- });
72
-
73
- it('nest block', () => {
74
- const doc = parse(`{if user}
75
- <div>{ user.name }</div>
76
- {/if}
77
- `);
78
- expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
79
- '[1:1]>[1:10](0,9)#ps:smarty-scriptlet: {if␣user}',
80
- '[1:10]>[2:1](9,10)#text: ⏎',
81
- '[2:1]>[2:6](10,15)div: <div>',
82
- '[2:6]>[2:19](15,28)#ps:smarty-scriptlet: {␣user.name␣}',
83
- '[2:19]>[2:25](28,34)div: </div>',
84
- '[2:25]>[3:1](34,35)#text: ⏎',
85
- '[3:1]>[3:6](35,40)#ps:smarty-scriptlet: {/if}',
86
- '[3:6]>[4:1](40,41)#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 file='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:27](43,67)#ps:smarty-scriptlet: {include␣file='path/to'}",
113
- '[4:27]>[5:3](67,70)#text: ⏎→→',
114
- '[5:3]>[5:11](70,78)meta: <meta␣/>',
115
- '[5:11]>[6:2](78,80)#text: ⏎→',
116
- '[6:2]>[6:9](80,87)head: </head>',
117
- '[6:9]>[7:2](87,89)#text: ⏎→',
118
- '[7:2]>[7:8](89,95)body: <body>',
119
- '[7:8]>[7:15](95,102)body: </body>',
120
- '[7:15]>[8:1](102,103)#text: ⏎',
121
- '[8:1]>[8:8](103,110)html: </html>',
122
- '[8:8]>[9:1](110,111)#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:17](7,16)#ps:smarty-scriptlet: {␣title␣}',
131
- '[1:17]>[1:25](16,24)title: </title>',
132
- ]);
133
- });
134
- });
135
-
136
- describe('Tags', () => {
137
- it('smarty-comment', () => {
138
- expect(parse('{* any *}').nodeList[0].nodeName).toBe('#ps:smarty-comment');
139
- });
140
-
141
- it('smarty-scriptlet', () => {
142
- expect(parse('{ any }').nodeList[0].nodeName).toBe('#ps:smarty-scriptlet');
143
- });
144
- });
145
-
146
- describe('Issues', () => {
147
- test('#470', () => {
148
- const ast = parse("<script>{literal}const obj = { foo: 'bar' };{/literal}</script>");
149
- expect(nodeListToDebugMaps(ast.nodeList)).toStrictEqual([
150
- '[1:1]>[1:9](0,8)script: <script>',
151
- "[1:9]>[1:55](8,54)#ps:smarty-literal: {literal}const␣obj␣=␣{␣foo:␣'bar'␣};{/literal}",
152
- '[1:55]>[1:64](54,63)script: </script>',
153
- ]);
154
- });
155
- });