@markdoc/markdoc 0.1.0

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.
Files changed (112) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -0
  3. package/dist/index.d.ts +120 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +7961 -0
  6. package/dist/index.js.map +7 -0
  7. package/dist/index.mjs +7959 -0
  8. package/dist/index.mjs.map +7 -0
  9. package/dist/react.js +40 -0
  10. package/dist/react.js.map +7 -0
  11. package/dist/src/ast/base.d.ts +6 -0
  12. package/dist/src/ast/base.d.ts.map +1 -0
  13. package/dist/src/ast/function.d.ts +9 -0
  14. package/dist/src/ast/function.d.ts.map +1 -0
  15. package/dist/src/ast/index.d.ts +26 -0
  16. package/dist/src/ast/index.d.ts.map +1 -0
  17. package/dist/src/ast/node.d.ts +21 -0
  18. package/dist/src/ast/node.d.ts.map +1 -0
  19. package/dist/src/ast/tag.d.ts +9 -0
  20. package/dist/src/ast/tag.d.ts.map +1 -0
  21. package/dist/src/ast/variable.d.ts +8 -0
  22. package/dist/src/ast/variable.d.ts.map +1 -0
  23. package/dist/src/functions/index.d.ts +11 -0
  24. package/dist/src/functions/index.d.ts.map +1 -0
  25. package/dist/src/parser.d.ts +4 -0
  26. package/dist/src/parser.d.ts.map +1 -0
  27. package/dist/src/renderers/html.d.ts +3 -0
  28. package/dist/src/renderers/html.d.ts.map +1 -0
  29. package/dist/src/renderers/index.d.ts +10 -0
  30. package/dist/src/renderers/index.d.ts.map +1 -0
  31. package/dist/src/renderers/react/react.d.ts +11 -0
  32. package/dist/src/renderers/react/react.d.ts.map +1 -0
  33. package/dist/src/renderers/react/shared.d.ts +5 -0
  34. package/dist/src/renderers/react/shared.d.ts.map +1 -0
  35. package/dist/src/renderers/react/static.d.ts +3 -0
  36. package/dist/src/renderers/react/static.d.ts.map +1 -0
  37. package/dist/src/schema-types/class.d.ts +6 -0
  38. package/dist/src/schema-types/class.d.ts.map +1 -0
  39. package/dist/src/schema.d.ts +27 -0
  40. package/dist/src/schema.d.ts.map +1 -0
  41. package/dist/src/tags/conditional.d.ts +5 -0
  42. package/dist/src/tags/conditional.d.ts.map +1 -0
  43. package/dist/src/tags/index.d.ts +44 -0
  44. package/dist/src/tags/index.d.ts.map +1 -0
  45. package/dist/src/tags/partial.d.ts +3 -0
  46. package/dist/src/tags/partial.d.ts.map +1 -0
  47. package/dist/src/tags/table.d.ts +3 -0
  48. package/dist/src/tags/table.d.ts.map +1 -0
  49. package/dist/src/tokenizer/index.d.ts +10 -0
  50. package/dist/src/tokenizer/index.d.ts.map +1 -0
  51. package/dist/src/tokenizer/plugins/annotations.d.ts +3 -0
  52. package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -0
  53. package/dist/src/tokenizer/plugins/frontmatter.d.ts +3 -0
  54. package/dist/src/tokenizer/plugins/frontmatter.d.ts.map +1 -0
  55. package/dist/src/transformer.d.ts +12 -0
  56. package/dist/src/transformer.d.ts.map +1 -0
  57. package/dist/src/transforms/index.d.ts +4 -0
  58. package/dist/src/transforms/index.d.ts.map +1 -0
  59. package/dist/src/transforms/table.d.ts +3 -0
  60. package/dist/src/transforms/table.d.ts.map +1 -0
  61. package/dist/src/types.d.ts +88 -0
  62. package/dist/src/types.d.ts.map +1 -0
  63. package/dist/src/utils.d.ts +6 -0
  64. package/dist/src/utils.d.ts.map +1 -0
  65. package/dist/src/validator.d.ts +6 -0
  66. package/dist/src/validator.d.ts.map +1 -0
  67. package/global.d.ts +11 -0
  68. package/index.ts +138 -0
  69. package/package.json +63 -0
  70. package/spec/support/matchers.d.ts +6 -0
  71. package/src/ast/base.ts +41 -0
  72. package/src/ast/function.ts +22 -0
  73. package/src/ast/index.ts +28 -0
  74. package/src/ast/node.test.ts +307 -0
  75. package/src/ast/node.ts +71 -0
  76. package/src/ast/tag.ts +19 -0
  77. package/src/ast/variable.test.ts +35 -0
  78. package/src/ast/variable.ts +17 -0
  79. package/src/functions/index.test.ts +34 -0
  80. package/src/functions/index.ts +45 -0
  81. package/src/grammar/tag.d.ts +23 -0
  82. package/src/grammar/tag.js +1836 -0
  83. package/src/grammar/tag.pegjs +170 -0
  84. package/src/grammar/tag.test.ts +364 -0
  85. package/src/parser.test.ts +597 -0
  86. package/src/parser.ts +158 -0
  87. package/src/renderers/html.test.ts +62 -0
  88. package/src/renderers/html.ts +46 -0
  89. package/src/renderers/index.ts +5 -0
  90. package/src/renderers/react/react.test.ts +204 -0
  91. package/src/renderers/react/react.ts +51 -0
  92. package/src/renderers/react/shared.ts +16 -0
  93. package/src/renderers/react/static.ts +52 -0
  94. package/src/schema-types/class.ts +23 -0
  95. package/src/schema.ts +233 -0
  96. package/src/tags/conditional.ts +45 -0
  97. package/src/tags/index.ts +10 -0
  98. package/src/tags/partial.ts +33 -0
  99. package/src/tags/table.ts +5 -0
  100. package/src/tokenizer/index.ts +21 -0
  101. package/src/tokenizer/plugins/annotations.test.ts +337 -0
  102. package/src/tokenizer/plugins/annotations.ts +133 -0
  103. package/src/tokenizer/plugins/frontmatter.test.ts +86 -0
  104. package/src/tokenizer/plugins/frontmatter.ts +39 -0
  105. package/src/transformer.ts +72 -0
  106. package/src/transforms/index.ts +2 -0
  107. package/src/transforms/table.ts +51 -0
  108. package/src/types.ts +142 -0
  109. package/src/utils.test.ts +173 -0
  110. package/src/utils.ts +116 -0
  111. package/src/validator.test.ts +298 -0
  112. package/src/validator.ts +233 -0
@@ -0,0 +1,170 @@
1
+ {
2
+
3
+ const {Variable, Function} = options;
4
+
5
+ }
6
+
7
+ Top = TopLevelValue / Annotation / TagOpen / TagClose
8
+
9
+ TopLevelValue =
10
+ variable:(Variable / Function) {
11
+ return {type: 'variable', meta: {variable}}
12
+ }
13
+
14
+ Annotation =
15
+ attributes:TagAttributes _* {
16
+ return {type: 'annotation', meta: {attributes}}
17
+ }
18
+
19
+ TagOpen =
20
+ tag:TagName _*
21
+ primary:(
22
+ value:Value _? { return value; }
23
+ )?
24
+ attributes:TagAttributes? _*
25
+ close:'/'? {
26
+ if (primary) {
27
+ attributes = attributes || [];
28
+ attributes.unshift({type: 'attribute', name: 'primary', value: primary});
29
+ }
30
+
31
+ const [type, nesting] = close ? ['tag', 0] : ['tag_open', 1];
32
+ return {type, nesting, meta: {tag, attributes}};
33
+ }
34
+
35
+ TagClose =
36
+ '/' tag:TagName { return {type: 'tag_close', nesting: -1, meta: {tag}}; }
37
+
38
+ TagName 'tag name' =
39
+ name:Identifier
40
+
41
+ TagAttributes =
42
+ head:TagAttributesItem
43
+ tail:TagAttributesTail* {
44
+ return !head ? [] : [head, ...tail];
45
+ }
46
+
47
+ TagAttributesTail =
48
+ _+ item:TagAttributesItem { return item; }
49
+
50
+ TagAttributesItem =
51
+ ids:TagShortcutId { return ids } /
52
+ classes:TagShortcutClass { return classes } /
53
+ attribute:TagAttribute { return attribute }
54
+
55
+ TagShortcutClass 'class' =
56
+ '.'
57
+ name:Identifier {
58
+ return {type: 'class', name, value: true};
59
+ }
60
+
61
+ TagShortcutId 'id' =
62
+ '#'
63
+ value:Identifier {
64
+ return {type: 'attribute', name: 'id', value};
65
+ }
66
+
67
+ TagAttribute =
68
+ name:Identifier
69
+ '='
70
+ value:Value {
71
+ return {type: 'attribute', name, value};
72
+ }
73
+
74
+ Function =
75
+ name:Identifier '(' _*
76
+ params:(
77
+ head:FunctionParameter?
78
+ tail:FunctionParameterTail* { return head ? [head, ...tail] : []; }
79
+ )?
80
+ ')' {
81
+ let parameters = {};
82
+ for (let [index, {name, value}] of params.entries())
83
+ parameters[name || index] = value;
84
+ return new Function(name, parameters);
85
+ }
86
+
87
+ FunctionParameter =
88
+ name:(
89
+ name:Identifier '=' { return name; }
90
+ )?
91
+ value:Value {
92
+ return {name, value};
93
+ }
94
+
95
+ FunctionParameterTail =
96
+ _* ',' _* value:FunctionParameter { return value; }
97
+
98
+ TrailingComma = (_*',')?
99
+
100
+ Variable 'variable' =
101
+ prefix:[$@]
102
+ head:Identifier
103
+ tail:VariableTail* {
104
+ if (prefix === '@')
105
+ return [head, ...tail];
106
+ return new Variable([head, ...tail]);
107
+ }
108
+
109
+ VariableTail =
110
+ '.' name:Identifier { return name; } /
111
+ '[' value:(ValueNumber / ValueString) ']' { return value; }
112
+
113
+ Value =
114
+ ValueNull / ValueBoolean /
115
+ ValueString / ValueNumber /
116
+ ValueArray / ValueHash /
117
+ Function / Variable
118
+
119
+ ValueNull 'null' =
120
+ 'null' { return null; }
121
+
122
+ ValueBoolean 'boolean' =
123
+ 'true' { return true; } /
124
+ 'false' { return false; }
125
+
126
+ ValueArray =
127
+ '[' _*
128
+ value:(
129
+ head:Value
130
+ tail:ValueArrayTail*
131
+ TrailingComma { return [head, ...tail]; }
132
+ )?
133
+ _* ']' { return value || []; }
134
+
135
+ ValueArrayTail =
136
+ _* ',' _* value:Value { return value; }
137
+
138
+ ValueHash =
139
+ '{' _*
140
+ value:(
141
+ head:ValueHashItem
142
+ tail:ValueHashTail*
143
+ TrailingComma { return Object.assign(head, ...tail); }
144
+ )?
145
+ _* '}' { return value || {}; }
146
+
147
+ ValueHashTail =
148
+ _* ',' _* item:ValueHashItem { return item; }
149
+
150
+ ValueHashItem =
151
+ key:(Identifier / ValueString)
152
+ ':'
153
+ _* value:Value { return key === "$$mdtype" ? {} : {[key]: value}; }
154
+
155
+ ValueNumber 'number' =
156
+ '-'? [0-9]+ ('.'[0-9]+)? { return parseFloat(text()); }
157
+
158
+ ValueString 'string' =
159
+ '"' value:ValueStringChars* '"' { return value.join(''); }
160
+
161
+ ValueStringChars =
162
+ [^\0-\x1F\x22\x5C] / ValueStringEscapes
163
+
164
+ ValueStringEscapes =
165
+ '\\' sequence:('"' / '\\') { return sequence; }
166
+
167
+ Identifier 'identifier' =
168
+ $([a-zA-Z0-9_-]+)
169
+
170
+ _ 'whitespace' = [ \n\t]
@@ -0,0 +1,364 @@
1
+ import { parse, SyntaxError } from '../../src/grammar/tag';
2
+ import Variable from '../../src/ast/variable';
3
+
4
+ describe('Markdoc tag parser', function () {
5
+ describe('tag parsing', function () {
6
+ it('with a simple opening tag', function () {
7
+ const example = parse('foo');
8
+ expect(example).toDeepEqual({
9
+ type: 'tag_open',
10
+ nesting: 1,
11
+ meta: { tag: 'foo', attributes: null },
12
+ });
13
+ });
14
+
15
+ it('with an opening tag that has attributes', function () {
16
+ const example = parse('foo foo=1 bar=true');
17
+ expect(example).toDeepEqual({
18
+ type: 'tag_open',
19
+ nesting: 1,
20
+ meta: {
21
+ tag: 'foo',
22
+ attributes: [
23
+ { type: 'attribute', name: 'foo', value: 1 },
24
+ { type: 'attribute', name: 'bar', value: true },
25
+ ],
26
+ },
27
+ });
28
+ });
29
+
30
+ it('with a self-closing tag', function () {
31
+ const example = parse('foo /');
32
+ expect(example).toDeepEqual({
33
+ type: 'tag',
34
+ nesting: 0,
35
+ meta: { tag: 'foo', attributes: null },
36
+ });
37
+ });
38
+
39
+ it('with a self-closing tag that has attributes', function () {
40
+ const example = parse('foo foo=1 bar=true /');
41
+ expect(example).toDeepEqual({
42
+ type: 'tag',
43
+ nesting: 0,
44
+ meta: {
45
+ tag: 'foo',
46
+ attributes: [
47
+ { type: 'attribute', name: 'foo', value: 1 },
48
+ { type: 'attribute', name: 'bar', value: true },
49
+ ],
50
+ },
51
+ });
52
+ });
53
+
54
+ it('with a closing tag', function () {
55
+ const example = parse('/foo');
56
+ expect(example).toDeepEqual({
57
+ type: 'tag_close',
58
+ nesting: -1,
59
+ meta: { tag: 'foo' },
60
+ });
61
+ });
62
+
63
+ it('with an invalid closing tag', function () {
64
+ expect(() => parse('/foo/')).toThrowError(SyntaxError);
65
+ });
66
+
67
+ it('with an invalid closing tag that has attributes', function () {
68
+ expect(() => parse('/foo test=1')).toThrowError(SyntaxError);
69
+ });
70
+ });
71
+
72
+ describe('variable parsing', function () {
73
+ it('with a simple variable', function () {
74
+ const example = parse('$foo', { Variable });
75
+ expect(example).toDeepEqual({
76
+ type: 'variable',
77
+ meta: { variable: new Variable(['foo'], null) },
78
+ });
79
+ });
80
+
81
+ it('with multiple levels of depth', function () {
82
+ const example = parse('$foo.bar.baz', { Variable });
83
+ expect(example).toDeepEqual({
84
+ type: 'variable',
85
+ meta: { variable: new Variable(['foo', 'bar', 'baz'], null) },
86
+ });
87
+ });
88
+
89
+ it('with an array index', function () {
90
+ const example = parse('$foo[1]', { Variable });
91
+ expect(example).toDeepEqual({
92
+ type: 'variable',
93
+ meta: { variable: new Variable(['foo', 1], null) },
94
+ });
95
+ });
96
+
97
+ it('with multiple array indexes', function () {
98
+ const example = parse('$foo[1][2]', { Variable });
99
+ expect(example).toDeepEqual({
100
+ type: 'variable',
101
+ meta: { variable: new Variable(['foo', 1, 2], null) },
102
+ });
103
+ });
104
+
105
+ it('with array indexes and properties', function () {
106
+ const example = parse('$foo[1].bar.baz[2].test', { Variable });
107
+ expect(example).toDeepEqual({
108
+ type: 'variable',
109
+ meta: {
110
+ variable: new Variable(['foo', 1, 'bar', 'baz', 2, 'test'], null),
111
+ },
112
+ });
113
+ });
114
+
115
+ it('with an invalid array index', function () {
116
+ expect(() => parse('$foo[asdf]', { Variable })).toThrowError(SyntaxError);
117
+ });
118
+
119
+ it('with an invalid namespace', function () {
120
+ expect(() => parse('$.foo:bar.baz', { Variable })).toThrowError(
121
+ SyntaxError
122
+ );
123
+ });
124
+ });
125
+
126
+ describe('parsing attributes', function () {
127
+ it('parsing annotation with a single attribute', function () {
128
+ const example = parse('test=1');
129
+ expect(example.meta.attributes).toDeepEqual([
130
+ { type: 'attribute', name: 'test', value: 1 },
131
+ ]);
132
+ });
133
+
134
+ it('with an id', function () {
135
+ const example = parse('#test');
136
+ expect(example.meta.attributes).toDeepEqual([
137
+ { type: 'attribute', name: 'id', value: 'test' },
138
+ ]);
139
+ });
140
+
141
+ it('with hyphens', function () {
142
+ const example = parse('#test-1 .foo-bar');
143
+ expect(example.meta.attributes).toDeepEqual([
144
+ { type: 'attribute', name: 'id', value: 'test-1' },
145
+ { type: 'class', name: 'foo-bar', value: true },
146
+ ]);
147
+ });
148
+
149
+ it('with chained classes', function () {
150
+ const example = parse('.foo .bar');
151
+ expect(example.meta.attributes).toDeepEqual([
152
+ { type: 'class', name: 'foo', value: true },
153
+ { type: 'class', name: 'bar', value: true },
154
+ ]);
155
+ });
156
+
157
+ it('with chained id and classes', function () {
158
+ const example = parse('#test-1 .foo .bar');
159
+ expect(example.meta.attributes).toDeepEqual([
160
+ { type: 'attribute', name: 'id', value: 'test-1' },
161
+ { type: 'class', name: 'foo', value: true },
162
+ { type: 'class', name: 'bar', value: true },
163
+ ]);
164
+ });
165
+
166
+ it('with an invalid id', () => {
167
+ expect(() => parse('#foo@bar.baz@test')).toThrowError(SyntaxError);
168
+ });
169
+
170
+ it('with key/value pairs', function () {
171
+ const example = parse('foo="bar" baz=3 test=true');
172
+ expect(example.meta.attributes).toDeepEqual([
173
+ { type: 'attribute', name: 'foo', value: 'bar' },
174
+ { type: 'attribute', name: 'baz', value: 3 },
175
+ { type: 'attribute', name: 'test', value: true },
176
+ ]);
177
+ });
178
+
179
+ it('with shortcuts and key/value pairs', function () {
180
+ const example = parse('#foo .bar test="asdf"', { Variable });
181
+ expect(example.meta.attributes).toDeepEqual([
182
+ { type: 'attribute', name: 'id', value: 'foo' },
183
+ { type: 'class', name: 'bar', value: true },
184
+ { type: 'attribute', name: 'test', value: 'asdf' },
185
+ ]);
186
+ });
187
+
188
+ it('with boolean key/value pairs', function () {
189
+ const example = parse('test=true foo=false bar=true');
190
+ expect(example.meta.attributes).toDeepEqual([
191
+ { type: 'attribute', name: 'test', value: true },
192
+ { type: 'attribute', name: 'foo', value: false },
193
+ { type: 'attribute', name: 'bar', value: true },
194
+ ]);
195
+ });
196
+
197
+ it('with null key/value pair', function () {
198
+ const example = parse('foo=null');
199
+ expect(example.meta.attributes).toDeepEqual([
200
+ { type: 'attribute', name: 'foo', value: null },
201
+ ]);
202
+ });
203
+
204
+ describe('with variables as values', function () {
205
+ it('with a simple variable', function () {
206
+ const example = parse('test=$foo', { Variable });
207
+ expect(example.meta.attributes).toDeepEqual([
208
+ {
209
+ type: 'attribute',
210
+ name: 'test',
211
+ value: new Variable(['foo'], null),
212
+ },
213
+ ]);
214
+ });
215
+
216
+ it('with multiple levels of depth', function () {
217
+ const example = parse('test=$foo.bar.baz', { Variable });
218
+ expect(example.meta.attributes).toDeepEqual([
219
+ {
220
+ type: 'attribute',
221
+ name: 'test',
222
+ value: new Variable(['foo', 'bar', 'baz'], null),
223
+ },
224
+ ]);
225
+ });
226
+
227
+ it('with an array index', function () {
228
+ const example = parse('test=$foo[1]', { Variable });
229
+ expect(example.meta.attributes).toDeepEqual([
230
+ {
231
+ type: 'attribute',
232
+ name: 'test',
233
+ value: new Variable(['foo', 1], null),
234
+ },
235
+ ]);
236
+ });
237
+
238
+ it('with multiple array indexes', function () {
239
+ const example = parse('test=$foo[1][2]', { Variable });
240
+ expect(example.meta.attributes).toDeepEqual([
241
+ {
242
+ type: 'attribute',
243
+ name: 'test',
244
+ value: new Variable(['foo', 1, 2], null),
245
+ },
246
+ ]);
247
+ });
248
+
249
+ it('with array indexes and properties', function () {
250
+ const example = parse('test=$foo[1].bar.baz[2].test', { Variable });
251
+ expect(example.meta.attributes).toDeepEqual([
252
+ {
253
+ type: 'attribute',
254
+ name: 'test',
255
+ value: new Variable(['foo', 1, 'bar', 'baz', 2, 'test'], null),
256
+ },
257
+ ]);
258
+ });
259
+
260
+ it('with an invalid array index', function () {
261
+ expect(() => parse('test=$foo[asdf]', { Variable })).toThrowError(
262
+ SyntaxError
263
+ );
264
+ });
265
+ });
266
+
267
+ describe('with complex values', function () {
268
+ it('with a simple hash literal value', function () {
269
+ const example = parse('foo={bar: true}');
270
+ expect(example.meta.attributes).toDeepEqual([
271
+ { type: 'attribute', name: 'foo', value: { bar: true } },
272
+ ]);
273
+ });
274
+
275
+ it('with a nested hash literal value', function () {
276
+ const example1 = parse(
277
+ 'foo={bar: true, baz: {test: "this is a test"}}'
278
+ );
279
+ const example2 = parse('foo={bar:true,baz:{test:"this is a test"}}');
280
+ const expected = [
281
+ {
282
+ type: 'attribute',
283
+ name: 'foo',
284
+ value: {
285
+ bar: true,
286
+ baz: { test: 'this is a test' },
287
+ },
288
+ },
289
+ ];
290
+
291
+ expect(example1.meta.attributes).toDeepEqual(expected);
292
+ expect(example2.meta.attributes).toDeepEqual(expected);
293
+ });
294
+
295
+ it('with a hash literal that has string keys', function () {
296
+ const example = parse('foo={bar: true, "baz": 1}');
297
+ expect(example.meta.attributes).toDeepEqual([
298
+ { type: 'attribute', name: 'foo', value: { bar: true, baz: 1 } },
299
+ ]);
300
+ });
301
+
302
+ it('with multiple hash literal values', function () {
303
+ const example = parse('foo={bar: true} baz={test: "testing"}');
304
+ expect(example.meta.attributes).toDeepEqual([
305
+ { type: 'attribute', name: 'foo', value: { bar: true } },
306
+ { type: 'attribute', name: 'baz', value: { test: 'testing' } },
307
+ ]);
308
+ });
309
+
310
+ it('with an array literal value', function () {
311
+ const example1 = parse('foo=[1, 2, 3]');
312
+ const example2 = parse('foo=[1,2,3]');
313
+ const expected = [{ type: 'attribute', name: 'foo', value: [1, 2, 3] }];
314
+
315
+ expect(example1.meta.attributes).toDeepEqual(expected);
316
+ expect(example2.meta.attributes).toDeepEqual(expected);
317
+ });
318
+
319
+ it('with nested array literal values', function () {
320
+ const example1 = parse('foo=[1, 2, ["test", true, null]]');
321
+ const example2 = parse('foo=[1,2,["test",true,null]]');
322
+ const expected = [
323
+ {
324
+ type: 'attribute',
325
+ name: 'foo',
326
+ value: [1, 2, ['test', true, null]],
327
+ },
328
+ ];
329
+
330
+ expect(example1.meta.attributes).toDeepEqual(expected);
331
+ expect(example2.meta.attributes).toDeepEqual(expected);
332
+ });
333
+
334
+ it('with multiple nested array literal values', function () {
335
+ const example = parse('foo=[1, 2, ["test", true, null]] bar=["baz"]');
336
+ expect(example.meta.attributes).toDeepEqual([
337
+ {
338
+ type: 'attribute',
339
+ name: 'foo',
340
+ value: [1, 2, ['test', true, null]],
341
+ },
342
+ { type: 'attribute', name: 'bar', value: ['baz'] },
343
+ ]);
344
+ });
345
+
346
+ it('with array and object literals', function () {
347
+ const example = parse('foo=[1, 2, {bar: "baz", test: [1, 2, 3]}]');
348
+ expect(example.meta.attributes).toDeepEqual([
349
+ {
350
+ type: 'attribute',
351
+ name: 'foo',
352
+ value: [1, 2, { bar: 'baz', test: [1, 2, 3] }],
353
+ },
354
+ ]);
355
+ });
356
+ });
357
+
358
+ it('with an invalid value', function () {
359
+ const examples = ['foo=bar', 'foo=a1', 'foo=1a'];
360
+ for (const example of examples)
361
+ expect(() => parse(example)).toThrowError(SyntaxError);
362
+ });
363
+ });
364
+ });