@tolgee/cli 2.0.3 → 2.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 (91) hide show
  1. package/dist/cli.js +15 -23
  2. package/dist/commands/extract/check.js +2 -6
  3. package/dist/commands/extract/print.js +2 -6
  4. package/dist/commands/pull.js +2 -4
  5. package/dist/commands/sync/compare.js +2 -6
  6. package/dist/commands/sync/sync.js +1 -5
  7. package/dist/commands/tag.js +1 -5
  8. package/dist/config/tolgeerc.js +4 -6
  9. package/dist/extractor/extractor.js +40 -66
  10. package/dist/extractor/parser/extractComment.js +78 -0
  11. package/dist/extractor/parser/generalMapper.js +82 -0
  12. package/dist/extractor/parser/generateReport.js +161 -0
  13. package/dist/extractor/parser/iterator.js +37 -0
  14. package/dist/extractor/parser/mergerMachine.js +66 -0
  15. package/dist/extractor/parser/nodeUtils.js +21 -0
  16. package/dist/extractor/parser/parser.js +129 -0
  17. package/dist/extractor/parser/rules/tComponentGeneral.js +45 -0
  18. package/dist/extractor/parser/rules/tFunctionGeneral.js +41 -0
  19. package/dist/extractor/parser/rules/tNsSourceGeneral.js +36 -0
  20. package/dist/extractor/parser/tokenMergers/closingTagMerger.js +27 -0
  21. package/dist/extractor/parser/tokenMergers/commentsMerger.js +36 -0
  22. package/dist/extractor/parser/tokenMergers/stringMerger.js +50 -0
  23. package/dist/extractor/parser/tokenMergers/templateStringMerger.js +55 -0
  24. package/dist/extractor/parser/tokenMergers/typesAsMergerer.js +40 -0
  25. package/dist/extractor/parser/tokenMergers/typesCastMerger.js +28 -0
  26. package/dist/extractor/parser/tree/getTranslateProps.js +54 -0
  27. package/dist/extractor/parser/tree/getValue.js +17 -0
  28. package/dist/extractor/parser/tree/parseGeneral.js +51 -0
  29. package/dist/extractor/parser/tree/parseList.js +33 -0
  30. package/dist/extractor/parser/tree/parseObject.js +130 -0
  31. package/dist/extractor/parser/tree/parseProps.js +56 -0
  32. package/dist/extractor/parser/tree/parseTag.js +26 -0
  33. package/dist/extractor/parser/types.js +1 -0
  34. package/dist/extractor/parserReact/ParserReact.js +30 -0
  35. package/dist/extractor/parserReact/jsxMapper.js +24 -0
  36. package/dist/extractor/parserReact/rules/createElement.js +62 -0
  37. package/dist/extractor/parserReact/rules/tComponent.js +9 -0
  38. package/dist/extractor/parserReact/rules/tFunction.js +7 -0
  39. package/dist/extractor/parserReact/rules/useTranslate.js +7 -0
  40. package/dist/extractor/parserReact/tokenMergers/createElementMerger.js +35 -0
  41. package/dist/extractor/parserReact/tokenMergers/tComponentMerger.js +20 -0
  42. package/dist/extractor/parserReact/tokenMergers/tFunctionMerger.js +23 -0
  43. package/dist/extractor/parserReact/tokenMergers/useTranslateMerger.js +20 -0
  44. package/dist/extractor/parserSvelte/ParserSvelte.js +32 -0
  45. package/dist/extractor/parserSvelte/contextConstants.js +1 -0
  46. package/dist/extractor/parserSvelte/rules/scriptTag.js +26 -0
  47. package/dist/extractor/parserSvelte/rules/tComponent.js +9 -0
  48. package/dist/extractor/parserSvelte/rules/tFunction.js +7 -0
  49. package/dist/extractor/parserSvelte/rules/useTranslate.js +7 -0
  50. package/dist/extractor/parserSvelte/svelteMapper.js +39 -0
  51. package/dist/extractor/parserSvelte/svelteTreeTransform.js +38 -0
  52. package/dist/extractor/parserSvelte/tokenMergers/getTranslateMerger.js +20 -0
  53. package/dist/extractor/parserSvelte/tokenMergers/scriptTagMerger.js +20 -0
  54. package/dist/extractor/parserSvelte/tokenMergers/tComponentMerger.js +20 -0
  55. package/dist/extractor/parserSvelte/tokenMergers/tFunctionMerger.js +29 -0
  56. package/dist/extractor/parserVue/ParserVue.js +45 -0
  57. package/dist/extractor/parserVue/contextConstants.js +3 -0
  58. package/dist/extractor/parserVue/rules/exportDefaultObject.js +14 -0
  59. package/dist/extractor/parserVue/rules/globalTFunction.js +7 -0
  60. package/dist/extractor/parserVue/rules/scriptTag.js +31 -0
  61. package/dist/extractor/parserVue/rules/tComponent.js +9 -0
  62. package/dist/extractor/parserVue/rules/tFunction.js +7 -0
  63. package/dist/extractor/parserVue/rules/useTranslate.js +7 -0
  64. package/dist/extractor/parserVue/tokenMergers/exportDefaultObjectMerger.js +25 -0
  65. package/dist/extractor/parserVue/tokenMergers/globalTFunctionMerger.js +36 -0
  66. package/dist/extractor/parserVue/tokenMergers/scriptTagMerger.js +20 -0
  67. package/dist/extractor/parserVue/tokenMergers/tComponentMerger.js +20 -0
  68. package/dist/extractor/parserVue/tokenMergers/tFunctionMerger.js +37 -0
  69. package/dist/extractor/parserVue/tokenMergers/useTranslateMerger.js +20 -0
  70. package/dist/extractor/parserVue/vueMapper.js +51 -0
  71. package/dist/extractor/parserVue/vueTreeTransform.js +109 -0
  72. package/dist/extractor/runner.js +52 -4
  73. package/dist/extractor/visualizers/printTokens.js +7 -0
  74. package/dist/extractor/visualizers/tokensToString.js +28 -0
  75. package/dist/extractor/visualizers/visualizeRules.js +40 -0
  76. package/dist/extractor/warnings.js +4 -0
  77. package/dist/extractor/worker.js +10 -7
  78. package/dist/options.js +5 -0
  79. package/extractor.d.ts +8 -1
  80. package/package.json +2 -4
  81. package/schema.json +18 -6
  82. package/dist/client/internal/requester.js +0 -130
  83. package/dist/extractor/machines/comments.js +0 -78
  84. package/dist/extractor/machines/react.js +0 -705
  85. package/dist/extractor/machines/shared/comments.js +0 -79
  86. package/dist/extractor/machines/shared/properties.js +0 -380
  87. package/dist/extractor/machines/shared/translateCall.js +0 -141
  88. package/dist/extractor/machines/svelte.js +0 -429
  89. package/dist/extractor/machines/vue/decoder.js +0 -194
  90. package/dist/extractor/machines/vue/extract.js +0 -491
  91. package/dist/extractor/processors/vueSfc.js +0 -55
@@ -1,705 +0,0 @@
1
- import { createMachine, assign, send, forwardTo } from 'xstate';
2
- import translateCallMachine from './shared/translateCall.js';
3
- import propertiesMachine from './shared/properties.js';
4
- import commentsService from './shared/comments.js';
5
- const VOID_KEY = { keyName: '', line: -1 };
6
- export default createMachine({
7
- predictableActionArguments: true,
8
- id: 'reactExtractor',
9
- type: 'parallel',
10
- context: {
11
- blockDepth: 0,
12
- children: '',
13
- line: 0,
14
- key: VOID_KEY,
15
- hooks: [],
16
- ignore: null,
17
- keys: [],
18
- warnings: [],
19
- },
20
- states: {
21
- comments: {
22
- invoke: {
23
- id: 'comments',
24
- src: () => commentsService,
25
- },
26
- on: {
27
- // Service messages
28
- MAGIC_COMMENT: [
29
- {
30
- actions: 'ignoreNextLine',
31
- cond: (_ctx, evt) => evt.kind === 'ignore',
32
- },
33
- {
34
- actions: 'pushImmediateKey',
35
- cond: (_ctx, evt) => evt.kind === 'key',
36
- },
37
- ],
38
- WARNING: {
39
- actions: 'pushWarning',
40
- },
41
- // Code messages
42
- 'comment.line.double-slash.ts': {
43
- actions: send((_ctx, evt) => ({
44
- type: 'COMMENT',
45
- data: evt.token,
46
- line: evt.line,
47
- }), { to: 'comments' }),
48
- },
49
- 'comment.block.ts': {
50
- actions: send((_ctx, evt) => ({
51
- type: 'COMMENT',
52
- data: evt.token,
53
- line: evt.line,
54
- }), { to: 'comments' }),
55
- },
56
- newline: {
57
- actions: 'warnUnusedIgnore',
58
- cond: (ctx, evt) => ctx.ignore?.type === 'ignore' && ctx.ignore.line === evt.line,
59
- },
60
- },
61
- },
62
- useTranslate: {
63
- initial: 'idle',
64
- states: {
65
- idle: {
66
- on: {
67
- 'entity.name.function.ts': {
68
- target: 'func',
69
- actions: 'storeLine',
70
- cond: (_ctx, evt) => evt.token === 'useTranslate',
71
- },
72
- },
73
- },
74
- func: {
75
- on: {
76
- '*': 'idle',
77
- newline: undefined,
78
- 'meta.block.ts': undefined,
79
- 'meta.var.expr.ts': undefined,
80
- 'meta.brace.round.ts': [
81
- {
82
- target: 'idle',
83
- actions: 'consumeIgnoredLine',
84
- cond: (ctx, evt) => ctx.ignore?.line === ctx.line &&
85
- ctx.ignore.type === 'ignore' &&
86
- evt.token === '(',
87
- },
88
- {
89
- target: 'call',
90
- cond: (_ctx, evt) => evt.token === '(',
91
- },
92
- ],
93
- },
94
- },
95
- call: {
96
- on: {
97
- 'punctuation.definition.string.begin.ts': 'namespace',
98
- 'punctuation.definition.string.template.begin.ts': 'namespace',
99
- 'variable.other.readwrite.ts': {
100
- target: 'idle',
101
- actions: ['pushHook', 'markHookAsDynamic'],
102
- },
103
- 'meta.brace.round.ts': {
104
- target: 'idle',
105
- cond: (_ctx, evt) => evt.token === ')',
106
- actions: 'pushHook',
107
- },
108
- },
109
- },
110
- namespace: {
111
- on: {
112
- '*': {
113
- target: 'namespace_end',
114
- actions: 'pushNamespacedHook',
115
- },
116
- },
117
- },
118
- namespace_end: {
119
- on: {
120
- 'punctuation.separator.comma.ts': 'idle',
121
- 'meta.brace.round.ts': 'idle',
122
- 'punctuation.definition.template-expression.begin.ts': {
123
- target: 'idle',
124
- actions: 'markHookAsDynamic',
125
- },
126
- 'keyword.operator.arithmetic.ts': {
127
- target: 'idle',
128
- actions: 'markHookAsDynamic',
129
- },
130
- },
131
- },
132
- },
133
- on: {
134
- 'punctuation.definition.block.ts': [
135
- {
136
- cond: (_ctx, evt) => evt.token === '{',
137
- actions: 'incrementDepth',
138
- },
139
- {
140
- cond: (_ctx, evt) => evt.token === '}',
141
- actions: 'decrementDepth',
142
- },
143
- ],
144
- },
145
- },
146
- createElement: {
147
- initial: 'idle',
148
- states: {
149
- idle: {
150
- on: {
151
- 'variable.other.object.ts': {
152
- target: 'func1',
153
- actions: 'storeLine',
154
- cond: (_ctx, evt) => evt.token === 'React',
155
- },
156
- },
157
- },
158
- func1: {
159
- on: {
160
- '*': 'idle',
161
- newline: undefined,
162
- 'meta.function-call.ts': undefined,
163
- 'punctuation.accessor.ts': {
164
- target: 'func2',
165
- cond: (_ctx, evt) => evt.token === '.',
166
- },
167
- },
168
- },
169
- func2: {
170
- on: {
171
- '*': 'idle',
172
- newline: undefined,
173
- 'meta.function-call.ts': undefined,
174
- 'support.function.dom.ts': {
175
- target: 'func3',
176
- cond: (_ctx, evt) => evt.token === 'createElement',
177
- },
178
- },
179
- },
180
- func3: {
181
- on: {
182
- '*': 'idle',
183
- newline: undefined,
184
- 'meta.function-call.ts': undefined,
185
- 'meta.brace.round.ts': {
186
- target: 'call',
187
- cond: (_ctx, evt) => evt.token === '(',
188
- },
189
- },
190
- },
191
- call: {
192
- on: {
193
- '*': 'idle',
194
- newline: undefined,
195
- 'variable.other.constant.ts': [
196
- {
197
- target: 'idle',
198
- actions: 'consumeIgnoredLine',
199
- cond: (ctx, evt) => ctx.ignore?.line === ctx.line && evt.token === 'T',
200
- },
201
- {
202
- target: 'props',
203
- cond: (_ctx, evt) => evt.token === 'T',
204
- },
205
- ],
206
- },
207
- },
208
- props: {
209
- on: {
210
- 'constant.language.null.ts': 'children',
211
- 'punctuation.definition.block.ts': {
212
- target: 'props_object',
213
- cond: (_ctx, evt) => evt.token === '{',
214
- },
215
- },
216
- },
217
- props_object: {
218
- invoke: {
219
- id: 'propertiesMachine',
220
- src: propertiesMachine,
221
- data: {
222
- depth: 1,
223
- },
224
- onDone: [
225
- {
226
- target: 'idle',
227
- actions: 'emitWarningFromParameters',
228
- cond: 'isPropertiesDataDynamic',
229
- },
230
- {
231
- target: 'children',
232
- actions: 'consumeParameters',
233
- cond: (ctx, evt) => (!ctx.key.keyName && !evt.data.keyName) ||
234
- (!ctx.key.defaultValue && !evt.data.defaultValue),
235
- },
236
- {
237
- target: 'idle',
238
- actions: ['consumeParameters', 'pushKey'],
239
- },
240
- ],
241
- },
242
- on: {
243
- '*': {
244
- actions: forwardTo('propertiesMachine'),
245
- },
246
- },
247
- },
248
- children: {
249
- on: {
250
- '*': [
251
- {
252
- target: 'idle',
253
- actions: 'pushKey',
254
- cond: (ctx) => !!ctx.key.keyName,
255
- },
256
- {
257
- target: 'idle',
258
- },
259
- ],
260
- 'variable.other.readwrite.ts': {
261
- target: 'idle',
262
- actions: ['dynamicKeyDefault', 'pushKey'],
263
- },
264
- // Void & punctuation
265
- newline: undefined,
266
- 'meta.objectliteral.ts': undefined,
267
- 'punctuation.separator.comma.ts': undefined,
268
- // String
269
- 'punctuation.definition.string.begin.ts': 'children_string',
270
- 'punctuation.definition.string.template.begin.ts': 'children_string',
271
- },
272
- },
273
- children_string: {
274
- on: {
275
- '*': [
276
- {
277
- target: 'children_end',
278
- actions: 'storeKeyName',
279
- cond: (ctx) => !ctx.key.keyName,
280
- },
281
- {
282
- target: 'children_end',
283
- actions: 'storeKeyDefault',
284
- cond: (ctx) => !!ctx.key.keyName,
285
- },
286
- ],
287
- },
288
- },
289
- children_end: {
290
- on: {
291
- 'punctuation.separator.comma.ts': {
292
- target: 'idle',
293
- actions: 'pushKey',
294
- },
295
- 'meta.brace.round.ts': {
296
- target: 'idle',
297
- actions: 'pushKey',
298
- },
299
- 'punctuation.definition.template-expression.begin.ts': {
300
- target: 'idle',
301
- actions: ['dynamicKeyDefault', 'pushKey'],
302
- },
303
- 'keyword.operator.arithmetic.ts': {
304
- target: 'idle',
305
- actions: ['dynamicKeyDefault', 'pushKey'],
306
- },
307
- },
308
- },
309
- },
310
- },
311
- jsx: {
312
- initial: 'idle',
313
- states: {
314
- idle: {
315
- on: {
316
- 'punctuation.definition.tag.begin.tsx': {
317
- target: 'tag',
318
- actions: 'storeLine',
319
- cond: (_ctx, evt) => evt.token === '<',
320
- },
321
- },
322
- },
323
- tag: {
324
- on: {
325
- '*': 'idle',
326
- newline: undefined,
327
- 'meta.tag.ts': undefined,
328
- 'support.class.component.tsx': [
329
- {
330
- target: 'idle',
331
- actions: 'consumeIgnoredLine',
332
- cond: (ctx, evt) => ctx.ignore?.line === ctx.line && evt.token === 'T',
333
- },
334
- {
335
- target: 'props',
336
- cond: (_ctx, evt) => evt.token === 'T',
337
- },
338
- ],
339
- },
340
- },
341
- props: {
342
- invoke: {
343
- id: 'propertiesMachine',
344
- src: propertiesMachine,
345
- onDone: [
346
- {
347
- target: 'idle',
348
- actions: 'emitWarningFromParameters',
349
- cond: 'isPropertiesDataDynamic',
350
- },
351
- {
352
- target: 'children',
353
- actions: 'consumeParameters',
354
- cond: (ctx, evt) => evt.data.lastEvent.token !== '/>' &&
355
- ((!ctx.key.keyName && !evt.data.keyName) ||
356
- (!ctx.key.defaultValue && !evt.data.defaultValue)),
357
- },
358
- {
359
- target: 'idle',
360
- actions: ['consumeParameters', 'pushKey'],
361
- },
362
- ],
363
- },
364
- on: {
365
- '*': {
366
- actions: forwardTo('propertiesMachine'),
367
- },
368
- },
369
- },
370
- children: {
371
- on: {
372
- 'punctuation.definition.tag.begin.tsx': {
373
- target: 'idle',
374
- actions: ['consumeChildren', 'pushKey'],
375
- },
376
- 'meta.jsx.children.tsx': {
377
- actions: 'appendChildren',
378
- },
379
- 'string.quoted.single.ts': {
380
- actions: 'appendChildren',
381
- },
382
- 'string.quoted.double.ts': {
383
- actions: 'appendChildren',
384
- },
385
- 'string.template.ts': {
386
- actions: 'appendChildren',
387
- },
388
- 'variable.other.readwrite.ts': {
389
- target: 'idle',
390
- actions: ['dynamicChildren', 'pushKey'],
391
- },
392
- 'variable.other.object.ts': {
393
- target: 'idle',
394
- actions: ['dynamicChildren', 'pushKey'],
395
- },
396
- 'entity.name.function.ts': {
397
- target: 'idle',
398
- actions: ['dynamicChildren', 'pushKey'],
399
- },
400
- 'storage.type.function.ts': {
401
- target: 'idle',
402
- actions: ['dynamicChildren', 'pushKey'],
403
- },
404
- 'storage.type.class.ts': {
405
- target: 'idle',
406
- actions: ['dynamicChildren', 'pushKey'],
407
- },
408
- 'keyword.operator.new.ts': {
409
- target: 'idle',
410
- actions: ['dynamicChildren', 'pushKey'],
411
- },
412
- 'punctuation.definition.block.ts': {
413
- target: 'idle',
414
- actions: ['dynamicChildren', 'pushKey'],
415
- },
416
- 'punctuation.definition.template-expression.begin.ts': {
417
- target: 'idle',
418
- actions: ['dynamicChildren', 'pushKey'],
419
- },
420
- 'keyword.operator.arithmetic.ts': {
421
- target: 'idle',
422
- actions: ['dynamicChildren', 'pushKey'],
423
- },
424
- },
425
- },
426
- },
427
- },
428
- t: {
429
- initial: 'idle',
430
- states: {
431
- idle: {
432
- on: {
433
- 'entity.name.function.ts': {
434
- target: 'func',
435
- actions: 'storeLine',
436
- cond: (ctx, evt) => !!ctx.hooks.length && evt.token === 't',
437
- },
438
- },
439
- },
440
- func: {
441
- on: {
442
- '*': 'idle',
443
- newline: undefined,
444
- 'meta.block.ts': undefined,
445
- 'meta.var.expr.ts': undefined,
446
- 'meta.brace.round.ts': [
447
- {
448
- target: 'idle',
449
- actions: 'consumeIgnoredLine',
450
- cond: (ctx, evt) => ctx.ignore?.line === ctx.line && evt.token === '(',
451
- },
452
- {
453
- target: 'call',
454
- cond: (_ctx, evt) => evt.token === '(',
455
- },
456
- ],
457
- },
458
- },
459
- call: {
460
- invoke: {
461
- id: 'tCall',
462
- src: translateCallMachine,
463
- onDone: [
464
- {
465
- target: 'idle',
466
- actions: 'dynamicKeyName',
467
- cond: (_, evt) => evt.data.keyName === false,
468
- },
469
- {
470
- target: 'idle',
471
- actions: 'dynamicNamespace',
472
- cond: (_, evt) => evt.data.namespace === false,
473
- },
474
- {
475
- target: 'idle',
476
- actions: 'dynamicOptions',
477
- cond: (_, evt) => evt.data.dynamicOptions,
478
- },
479
- {
480
- target: 'idle',
481
- cond: (_, evt) => !evt.data.keyName,
482
- },
483
- {
484
- target: 'idle',
485
- actions: 'consumeTranslateCall',
486
- },
487
- ],
488
- },
489
- on: {
490
- '*': {
491
- actions: forwardTo('tCall'),
492
- },
493
- },
494
- },
495
- },
496
- },
497
- },
498
- }, {
499
- guards: {
500
- isPropertiesDataDynamic: (_ctx, evt) => evt.data.keyName === false || evt.data.namespace === false,
501
- },
502
- actions: {
503
- incrementDepth: assign({
504
- blockDepth: (ctx) => ctx.blockDepth + 1,
505
- }),
506
- decrementDepth: assign({
507
- blockDepth: (ctx) => ctx.blockDepth - 1,
508
- hooks: (ctx) => ctx.hooks.filter((n) => n.depth !== ctx.blockDepth),
509
- }),
510
- storeLine: assign({
511
- line: (_ctx, evt) => evt.line,
512
- }),
513
- ignoreNextLine: assign({
514
- ignore: (_ctx, evt) => ({ type: 'ignore', line: evt.line + 1 }),
515
- }),
516
- consumeIgnoredLine: assign({
517
- ignore: (_ctx, _evt) => null,
518
- }),
519
- warnUnusedIgnore: assign({
520
- warnings: (ctx, evt) => [
521
- ...ctx.warnings,
522
- { warning: 'W_UNUSED_IGNORE', line: evt.line - 1 },
523
- ],
524
- }),
525
- pushHook: assign({
526
- hooks: (ctx) => [...ctx.hooks, { depth: ctx.blockDepth }],
527
- }),
528
- pushNamespacedHook: assign({
529
- hooks: (ctx, evt) => [
530
- ...ctx.hooks,
531
- { namespace: evt.token, depth: ctx.blockDepth },
532
- ],
533
- }),
534
- markHookAsDynamic: assign({
535
- hooks: (ctx, _evt) => [
536
- ...ctx.hooks.slice(0, -1),
537
- { namespace: false, depth: ctx.blockDepth },
538
- ],
539
- warnings: (ctx, _evt) => [
540
- ...ctx.warnings,
541
- { warning: 'W_DYNAMIC_NAMESPACE', line: ctx.line },
542
- ],
543
- }),
544
- consumeTranslateCall: assign({
545
- warnings: (ctx, evt) => {
546
- const utNamespace = ctx.hooks.length
547
- ? ctx.hooks[ctx.hooks.length - 1].namespace
548
- : undefined;
549
- if (!evt.data.namespace && utNamespace === false) {
550
- return [
551
- ...ctx.warnings,
552
- { warning: 'W_UNRESOLVABLE_NAMESPACE', line: ctx.line },
553
- ];
554
- }
555
- if (evt.data.defaultValue === false) {
556
- return [
557
- ...ctx.warnings,
558
- { warning: 'W_DYNAMIC_DEFAULT_VALUE', line: ctx.line },
559
- ];
560
- }
561
- return ctx.warnings;
562
- },
563
- keys: (ctx, evt) => {
564
- const utNamespace = ctx.hooks.length
565
- ? ctx.hooks[ctx.hooks.length - 1].namespace
566
- : undefined;
567
- const ns = evt.data.namespace === null ? utNamespace : evt.data.namespace;
568
- if (!evt.data.keyName || ns === false)
569
- return ctx.keys;
570
- return [
571
- ...ctx.keys,
572
- {
573
- keyName: evt.data.keyName,
574
- namespace: ns || undefined,
575
- defaultValue: evt.data.defaultValue || undefined,
576
- line: ctx.line,
577
- },
578
- ];
579
- },
580
- }),
581
- consumeParameters: assign({
582
- key: (ctx, evt) => ({
583
- // We don't want the key and default value to be overridable
584
- // But we DO want the namespace to be overridable
585
- keyName: ctx.key.keyName || evt.data.keyName,
586
- defaultValue: ctx.key.defaultValue || evt.data.defaultValue || undefined,
587
- namespace: evt.data.namespace === ''
588
- ? undefined
589
- : evt.data.namespace ?? ctx.key.namespace,
590
- line: ctx.line,
591
- }),
592
- warnings: (ctx, evt) => {
593
- if (evt.data.defaultValue !== false)
594
- return ctx.warnings;
595
- return [
596
- ...ctx.warnings,
597
- { warning: 'W_DYNAMIC_DEFAULT_VALUE', line: ctx.line },
598
- ];
599
- },
600
- }),
601
- emitWarningFromParameters: assign({
602
- warnings: (ctx, evt) => [
603
- ...ctx.warnings,
604
- {
605
- warning: evt.data.keyName === false
606
- ? 'W_DYNAMIC_KEY'
607
- : 'W_DYNAMIC_NAMESPACE',
608
- line: ctx.line,
609
- },
610
- ],
611
- key: VOID_KEY,
612
- }),
613
- appendChildren: assign({
614
- children: (ctx, evt) => (ctx.children ?? '') + evt.token,
615
- }),
616
- consumeChildren: assign({
617
- key: (ctx, _evt) => ({
618
- ...ctx.key,
619
- keyName: ctx.key.keyName ? ctx.key.keyName : ctx.children,
620
- defaultValue: !ctx.key.keyName ? ctx.key.defaultValue : ctx.children,
621
- }),
622
- children: (_ctx, _evt) => '',
623
- }),
624
- storeKeyName: assign({
625
- key: (ctx, evt) => ({ ...ctx.key, keyName: evt.token }),
626
- }),
627
- storeKeyDefault: assign({
628
- key: (ctx, evt) => ({ ...ctx.key, defaultValue: evt.token }),
629
- }),
630
- dynamicKeyName: assign({
631
- warnings: (ctx, _evt) => [
632
- ...ctx.warnings,
633
- { warning: 'W_DYNAMIC_KEY', line: ctx.line },
634
- ],
635
- key: VOID_KEY,
636
- }),
637
- dynamicNamespace: assign({
638
- warnings: (ctx, _evt) => [
639
- ...ctx.warnings,
640
- { warning: 'W_DYNAMIC_NAMESPACE', line: ctx.line },
641
- ],
642
- key: VOID_KEY,
643
- }),
644
- dynamicKeyDefault: assign({
645
- key: (ctx, _evt) => ({ ...ctx.key, defaultValue: undefined }),
646
- warnings: (ctx, _evt) => [
647
- ...ctx.warnings,
648
- { warning: 'W_DYNAMIC_DEFAULT_VALUE', line: ctx.line },
649
- ],
650
- }),
651
- dynamicOptions: assign({
652
- key: VOID_KEY,
653
- warnings: (ctx, _evt) => [
654
- ...ctx.warnings,
655
- { warning: 'W_DYNAMIC_OPTIONS', line: ctx.line },
656
- ],
657
- }),
658
- dynamicChildren: assign({
659
- key: (ctx, _evt) => ctx.key.keyName ? { ...ctx.key, defaultValue: undefined } : VOID_KEY,
660
- warnings: (ctx, _evt) => [
661
- ...ctx.warnings,
662
- {
663
- warning: ctx.key.keyName
664
- ? 'W_DYNAMIC_DEFAULT_VALUE'
665
- : 'W_DYNAMIC_KEY',
666
- line: ctx.line,
667
- },
668
- ],
669
- }),
670
- pushKey: assign({
671
- keys: (ctx, _evt) => {
672
- if (!ctx.key.keyName || ctx.key.namespace === false)
673
- return ctx.keys;
674
- return [
675
- ...ctx.keys,
676
- {
677
- keyName: ctx.key.keyName.trim(),
678
- namespace: ctx.key.namespace?.trim(),
679
- defaultValue: ctx.key.defaultValue?.trim().replace(/\s+/g, ' '),
680
- line: ctx.line,
681
- },
682
- ];
683
- },
684
- key: (_ctx, _evt) => ({ keyName: '', line: 0 }),
685
- }),
686
- pushImmediateKey: assign({
687
- ignore: (_ctx, evt) => ({ type: 'key', line: evt.line + 1 }),
688
- keys: (ctx, evt) => [
689
- ...ctx.keys,
690
- {
691
- keyName: evt.keyName,
692
- namespace: evt.namespace,
693
- defaultValue: evt.defaultValue,
694
- line: evt.line,
695
- },
696
- ],
697
- }),
698
- pushWarning: assign({
699
- warnings: (ctx, evt) => [
700
- ...ctx.warnings,
701
- { warning: evt.kind, line: evt.line },
702
- ],
703
- }),
704
- },
705
- });