@tolgee/cli 2.0.4 → 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.
- package/dist/cli.js +15 -23
- package/dist/commands/extract/check.js +2 -6
- package/dist/commands/extract/print.js +2 -6
- package/dist/commands/sync/compare.js +2 -6
- package/dist/commands/sync/sync.js +1 -5
- package/dist/commands/tag.js +1 -5
- package/dist/config/tolgeerc.js +4 -6
- package/dist/extractor/extractor.js +40 -66
- package/dist/extractor/parser/extractComment.js +78 -0
- package/dist/extractor/parser/generalMapper.js +82 -0
- package/dist/extractor/parser/generateReport.js +161 -0
- package/dist/extractor/parser/iterator.js +37 -0
- package/dist/extractor/parser/mergerMachine.js +66 -0
- package/dist/extractor/parser/nodeUtils.js +21 -0
- package/dist/extractor/parser/parser.js +129 -0
- package/dist/extractor/parser/rules/tComponentGeneral.js +45 -0
- package/dist/extractor/parser/rules/tFunctionGeneral.js +41 -0
- package/dist/extractor/parser/rules/tNsSourceGeneral.js +36 -0
- package/dist/extractor/parser/tokenMergers/closingTagMerger.js +27 -0
- package/dist/extractor/parser/tokenMergers/commentsMerger.js +36 -0
- package/dist/extractor/parser/tokenMergers/stringMerger.js +50 -0
- package/dist/extractor/parser/tokenMergers/templateStringMerger.js +55 -0
- package/dist/extractor/parser/tokenMergers/typesAsMergerer.js +40 -0
- package/dist/extractor/parser/tokenMergers/typesCastMerger.js +28 -0
- package/dist/extractor/parser/tree/getTranslateProps.js +54 -0
- package/dist/extractor/parser/tree/getValue.js +17 -0
- package/dist/extractor/parser/tree/parseGeneral.js +51 -0
- package/dist/extractor/parser/tree/parseList.js +33 -0
- package/dist/extractor/parser/tree/parseObject.js +130 -0
- package/dist/extractor/parser/tree/parseProps.js +56 -0
- package/dist/extractor/parser/tree/parseTag.js +26 -0
- package/dist/extractor/parser/types.js +1 -0
- package/dist/extractor/parserReact/ParserReact.js +30 -0
- package/dist/extractor/parserReact/jsxMapper.js +24 -0
- package/dist/extractor/parserReact/rules/createElement.js +62 -0
- package/dist/extractor/parserReact/rules/tComponent.js +9 -0
- package/dist/extractor/parserReact/rules/tFunction.js +7 -0
- package/dist/extractor/parserReact/rules/useTranslate.js +7 -0
- package/dist/extractor/parserReact/tokenMergers/createElementMerger.js +35 -0
- package/dist/extractor/parserReact/tokenMergers/tComponentMerger.js +20 -0
- package/dist/extractor/parserReact/tokenMergers/tFunctionMerger.js +23 -0
- package/dist/extractor/parserReact/tokenMergers/useTranslateMerger.js +20 -0
- package/dist/extractor/parserSvelte/ParserSvelte.js +32 -0
- package/dist/extractor/parserSvelte/contextConstants.js +1 -0
- package/dist/extractor/parserSvelte/rules/scriptTag.js +26 -0
- package/dist/extractor/parserSvelte/rules/tComponent.js +9 -0
- package/dist/extractor/parserSvelte/rules/tFunction.js +7 -0
- package/dist/extractor/parserSvelte/rules/useTranslate.js +7 -0
- package/dist/extractor/parserSvelte/svelteMapper.js +39 -0
- package/dist/extractor/parserSvelte/svelteTreeTransform.js +38 -0
- package/dist/extractor/parserSvelte/tokenMergers/getTranslateMerger.js +20 -0
- package/dist/extractor/parserSvelte/tokenMergers/scriptTagMerger.js +20 -0
- package/dist/extractor/parserSvelte/tokenMergers/tComponentMerger.js +20 -0
- package/dist/extractor/parserSvelte/tokenMergers/tFunctionMerger.js +29 -0
- package/dist/extractor/parserVue/ParserVue.js +45 -0
- package/dist/extractor/parserVue/contextConstants.js +3 -0
- package/dist/extractor/parserVue/rules/exportDefaultObject.js +14 -0
- package/dist/extractor/parserVue/rules/globalTFunction.js +7 -0
- package/dist/extractor/parserVue/rules/scriptTag.js +31 -0
- package/dist/extractor/parserVue/rules/tComponent.js +9 -0
- package/dist/extractor/parserVue/rules/tFunction.js +7 -0
- package/dist/extractor/parserVue/rules/useTranslate.js +7 -0
- package/dist/extractor/parserVue/tokenMergers/exportDefaultObjectMerger.js +25 -0
- package/dist/extractor/parserVue/tokenMergers/globalTFunctionMerger.js +36 -0
- package/dist/extractor/parserVue/tokenMergers/scriptTagMerger.js +20 -0
- package/dist/extractor/parserVue/tokenMergers/tComponentMerger.js +20 -0
- package/dist/extractor/parserVue/tokenMergers/tFunctionMerger.js +37 -0
- package/dist/extractor/parserVue/tokenMergers/useTranslateMerger.js +20 -0
- package/dist/extractor/parserVue/vueMapper.js +51 -0
- package/dist/extractor/parserVue/vueTreeTransform.js +109 -0
- package/dist/extractor/runner.js +52 -4
- package/dist/extractor/visualizers/printTokens.js +7 -0
- package/dist/extractor/visualizers/tokensToString.js +28 -0
- package/dist/extractor/visualizers/visualizeRules.js +40 -0
- package/dist/extractor/warnings.js +4 -0
- package/dist/extractor/worker.js +10 -7
- package/dist/options.js +5 -0
- package/extractor.d.ts +8 -1
- package/package.json +2 -4
- package/schema.json +18 -6
- package/dist/client/internal/requester.js +0 -130
- package/dist/extractor/machines/comments.js +0 -78
- package/dist/extractor/machines/react.js +0 -705
- package/dist/extractor/machines/shared/comments.js +0 -79
- package/dist/extractor/machines/shared/properties.js +0 -380
- package/dist/extractor/machines/shared/translateCall.js +0 -141
- package/dist/extractor/machines/svelte.js +0 -429
- package/dist/extractor/machines/vue/decoder.js +0 -194
- package/dist/extractor/machines/vue/extract.js +0 -491
- package/dist/extractor/processors/vueSfc.js +0 -55
@@ -1,79 +0,0 @@
|
|
1
|
-
import JSON5 from 'json5';
|
2
|
-
function isValidKeyOverride(data) {
|
3
|
-
if (!('key' in data)) {
|
4
|
-
return false;
|
5
|
-
}
|
6
|
-
if (typeof data.key !== 'string') {
|
7
|
-
return false;
|
8
|
-
}
|
9
|
-
if ('ns' in data && typeof data.ns !== 'string') {
|
10
|
-
return false;
|
11
|
-
}
|
12
|
-
if ('defaultValue' in data && typeof data.defaultValue !== 'string') {
|
13
|
-
return false;
|
14
|
-
}
|
15
|
-
return true;
|
16
|
-
}
|
17
|
-
// This service is responsible for emitting events when magic comments are encountered
|
18
|
-
export default function (callback, onReceive) {
|
19
|
-
onReceive((evt) => {
|
20
|
-
const comment = evt.data.trim();
|
21
|
-
if (comment.startsWith('@tolgee-ignore')) {
|
22
|
-
return callback({
|
23
|
-
type: 'MAGIC_COMMENT',
|
24
|
-
kind: 'ignore',
|
25
|
-
line: evt.line,
|
26
|
-
});
|
27
|
-
}
|
28
|
-
if (comment.startsWith('@tolgee-key')) {
|
29
|
-
const data = comment.slice(11).trim();
|
30
|
-
// Data is escaped; extract all as string
|
31
|
-
if (data.startsWith('\\')) {
|
32
|
-
return callback({
|
33
|
-
type: 'MAGIC_COMMENT',
|
34
|
-
kind: 'key',
|
35
|
-
keyName: data.slice(1),
|
36
|
-
line: evt.line,
|
37
|
-
});
|
38
|
-
}
|
39
|
-
// Data is a json5 struct
|
40
|
-
if (data.startsWith('{')) {
|
41
|
-
try {
|
42
|
-
const key = JSON5.parse(data);
|
43
|
-
if (!isValidKeyOverride(key)) {
|
44
|
-
// No key in the struct; invalid override
|
45
|
-
callback({
|
46
|
-
type: 'WARNING',
|
47
|
-
kind: 'W_INVALID_KEY_OVERRIDE',
|
48
|
-
line: evt.line,
|
49
|
-
});
|
50
|
-
}
|
51
|
-
else {
|
52
|
-
callback({
|
53
|
-
type: 'MAGIC_COMMENT',
|
54
|
-
kind: 'key',
|
55
|
-
keyName: key.key,
|
56
|
-
namespace: key.ns,
|
57
|
-
defaultValue: key.defaultValue,
|
58
|
-
line: evt.line,
|
59
|
-
});
|
60
|
-
}
|
61
|
-
}
|
62
|
-
catch {
|
63
|
-
callback({
|
64
|
-
type: 'WARNING',
|
65
|
-
kind: 'W_MALFORMED_KEY_OVERRIDE',
|
66
|
-
line: evt.line,
|
67
|
-
});
|
68
|
-
}
|
69
|
-
return;
|
70
|
-
}
|
71
|
-
callback({
|
72
|
-
type: 'MAGIC_COMMENT',
|
73
|
-
kind: 'key',
|
74
|
-
keyName: data,
|
75
|
-
line: evt.line,
|
76
|
-
});
|
77
|
-
}
|
78
|
-
});
|
79
|
-
}
|
@@ -1,380 +0,0 @@
|
|
1
|
-
import { createMachine, send, assign } from 'xstate';
|
2
|
-
// This state machine is responsible for extracting translation key properties from an object/props
|
3
|
-
export default createMachine({
|
4
|
-
predictableActionArguments: true,
|
5
|
-
id: 'properties',
|
6
|
-
initial: 'idle',
|
7
|
-
context: {
|
8
|
-
property: null,
|
9
|
-
depth: 0,
|
10
|
-
jsxDepth: 0,
|
11
|
-
static: false,
|
12
|
-
nextDynamic: false,
|
13
|
-
keyName: null,
|
14
|
-
defaultValue: null,
|
15
|
-
namespace: null,
|
16
|
-
},
|
17
|
-
states: {
|
18
|
-
idle: {
|
19
|
-
on: {
|
20
|
-
// JS/TS
|
21
|
-
'meta.brace.square.ts': {
|
22
|
-
target: 'complex_key',
|
23
|
-
cond: 'isOpenSquare',
|
24
|
-
},
|
25
|
-
'meta.object-literal.key.ts': {
|
26
|
-
actions: 'storePropertyType',
|
27
|
-
cond: 'isRootLevel',
|
28
|
-
},
|
29
|
-
'punctuation.separator.key-value.ts': {
|
30
|
-
target: 'value',
|
31
|
-
cond: 'isRootLevel',
|
32
|
-
},
|
33
|
-
'variable.other.readwrite.ts': {
|
34
|
-
actions: 'markImmediatePropertyAsDynamic',
|
35
|
-
cond: (_ctx, evt) => ['key', 'keyName', 'ns', 'defaultValue'].includes(evt.token),
|
36
|
-
},
|
37
|
-
// JSX/TSX
|
38
|
-
'entity.other.attribute-name.tsx': {
|
39
|
-
actions: ['markPropertyAsDynamic', 'storePropertyType'],
|
40
|
-
},
|
41
|
-
'keyword.operator.assignment.ts': {
|
42
|
-
target: 'value',
|
43
|
-
actions: 'markAsStatic',
|
44
|
-
},
|
45
|
-
// Svelte
|
46
|
-
'entity.other.attribute-name.svelte': {
|
47
|
-
actions: ['markPropertyAsDynamic', 'storePropertyType'],
|
48
|
-
},
|
49
|
-
'punctuation.separator.key-value.svelte': {
|
50
|
-
target: 'value',
|
51
|
-
},
|
52
|
-
// Vue
|
53
|
-
'punctuation.attribute-shorthand.event.html.vue': [
|
54
|
-
{
|
55
|
-
cond: (_, evt) => evt.token === '@',
|
56
|
-
actions: ['markPropertyAsDynamic', 'markNextPropertyAsDynamic'],
|
57
|
-
},
|
58
|
-
],
|
59
|
-
'entity.other.attribute-name.html.vue': [
|
60
|
-
{
|
61
|
-
cond: (ctx) => ctx.nextDynamic,
|
62
|
-
actions: 'markImmediatePropertyAsDynamic',
|
63
|
-
},
|
64
|
-
{
|
65
|
-
actions: [
|
66
|
-
'markPropertyAsDynamic',
|
67
|
-
'unmarkAsStatic',
|
68
|
-
'storePropertyType',
|
69
|
-
],
|
70
|
-
},
|
71
|
-
],
|
72
|
-
'punctuation.separator.key-value.html.vue': {
|
73
|
-
target: 'value',
|
74
|
-
},
|
75
|
-
'entity.other.attribute-name.html': [
|
76
|
-
{
|
77
|
-
actions: ['markPropertyAsDynamic', 'storePropertyType'],
|
78
|
-
},
|
79
|
-
],
|
80
|
-
'punctuation.separator.key-value.html': {
|
81
|
-
target: 'value',
|
82
|
-
},
|
83
|
-
},
|
84
|
-
},
|
85
|
-
complex_key: {
|
86
|
-
on: {
|
87
|
-
// On string
|
88
|
-
'punctuation.definition.string.begin.ts': 'complex_key_string',
|
89
|
-
'punctuation.definition.string.template.begin.ts': 'complex_key_string',
|
90
|
-
// Key end
|
91
|
-
'meta.brace.square.ts': {
|
92
|
-
target: 'idle',
|
93
|
-
cond: 'isCloseSquare',
|
94
|
-
},
|
95
|
-
},
|
96
|
-
},
|
97
|
-
complex_key_string: {
|
98
|
-
on: {
|
99
|
-
'*': {
|
100
|
-
target: 'idle',
|
101
|
-
actions: 'storePropertyType',
|
102
|
-
},
|
103
|
-
},
|
104
|
-
},
|
105
|
-
value: {
|
106
|
-
on: {
|
107
|
-
// Extract strings
|
108
|
-
'punctuation.definition.string.begin.ts': 'value_string',
|
109
|
-
'punctuation.definition.string.template.begin.ts': 'value_string',
|
110
|
-
'punctuation.definition.string.begin.svelte': 'value_string',
|
111
|
-
'punctuation.definition.string.template.begin.svelte': 'value_string',
|
112
|
-
'punctuation.definition.string.begin.html': 'value_string',
|
113
|
-
// Variable
|
114
|
-
'variable.other.readwrite.ts': {
|
115
|
-
target: 'idle',
|
116
|
-
actions: [
|
117
|
-
'unmarkAsStatic',
|
118
|
-
'markPropertyAsDynamic',
|
119
|
-
'clearPropertyType',
|
120
|
-
],
|
121
|
-
},
|
122
|
-
// JSX Expression
|
123
|
-
'punctuation.section.embedded.begin.tsx': {
|
124
|
-
actions: 'unmarkAsStatic',
|
125
|
-
},
|
126
|
-
// Svelte
|
127
|
-
'string.unquoted.svelte': {
|
128
|
-
target: 'idle',
|
129
|
-
actions: [
|
130
|
-
'storePropertyValue',
|
131
|
-
'clearPropertyType',
|
132
|
-
'unmarkAsStatic',
|
133
|
-
],
|
134
|
-
},
|
135
|
-
// Vue
|
136
|
-
'string.unquoted.html': {
|
137
|
-
target: 'idle',
|
138
|
-
actions: [
|
139
|
-
'storePropertyValue',
|
140
|
-
'clearPropertyType',
|
141
|
-
'unmarkAsStatic',
|
142
|
-
],
|
143
|
-
},
|
144
|
-
// Value end
|
145
|
-
'punctuation.separator.comma.ts': {
|
146
|
-
target: 'idle',
|
147
|
-
actions: [
|
148
|
-
'unmarkAsStatic',
|
149
|
-
'markPropertyAsDynamic',
|
150
|
-
'clearPropertyType',
|
151
|
-
],
|
152
|
-
},
|
153
|
-
'punctuation.definition.block.ts': {
|
154
|
-
target: 'idle',
|
155
|
-
// Replay the event to let depth update itself if necessary
|
156
|
-
actions: [
|
157
|
-
'unmarkAsStatic',
|
158
|
-
'markPropertyAsDynamic',
|
159
|
-
'clearPropertyType',
|
160
|
-
send((_ctx, evt) => evt),
|
161
|
-
],
|
162
|
-
},
|
163
|
-
},
|
164
|
-
},
|
165
|
-
value_string: {
|
166
|
-
on: {
|
167
|
-
'punctuation.definition.string.end.ts': {
|
168
|
-
target: 'idle',
|
169
|
-
actions: ['storeEmptyPropertyValue', 'clearPropertyType'],
|
170
|
-
},
|
171
|
-
'punctuation.definition.string.template.end.ts': {
|
172
|
-
target: 'idle',
|
173
|
-
actions: ['storeEmptyPropertyValue', 'clearPropertyType'],
|
174
|
-
},
|
175
|
-
'punctuation.definition.string.end.svelte': {
|
176
|
-
target: 'idle',
|
177
|
-
actions: ['storeEmptyPropertyValue', 'clearPropertyType'],
|
178
|
-
},
|
179
|
-
'punctuation.definition.string.template.end.svelte': {
|
180
|
-
target: 'idle',
|
181
|
-
actions: ['storeEmptyPropertyValue', 'clearPropertyType'],
|
182
|
-
},
|
183
|
-
'punctuation.definition.string.end.html': {
|
184
|
-
target: 'idle',
|
185
|
-
actions: ['storeEmptyPropertyValue', 'clearPropertyType'],
|
186
|
-
},
|
187
|
-
'*': [
|
188
|
-
{
|
189
|
-
target: 'idle',
|
190
|
-
actions: [
|
191
|
-
'storePropertyValue',
|
192
|
-
'clearPropertyType',
|
193
|
-
'unmarkAsStatic',
|
194
|
-
],
|
195
|
-
cond: (ctx) => ctx.static,
|
196
|
-
},
|
197
|
-
{
|
198
|
-
target: 'string_end',
|
199
|
-
actions: 'storePropertyValue',
|
200
|
-
},
|
201
|
-
],
|
202
|
-
},
|
203
|
-
},
|
204
|
-
string_end: {
|
205
|
-
on: {
|
206
|
-
'punctuation.separator.comma.ts': {
|
207
|
-
target: 'idle',
|
208
|
-
actions: 'clearPropertyType',
|
209
|
-
},
|
210
|
-
'punctuation.definition.template-expression.begin.ts': {
|
211
|
-
target: 'idle',
|
212
|
-
actions: ['markPropertyAsDynamic', 'clearPropertyType'],
|
213
|
-
},
|
214
|
-
'keyword.operator.arithmetic.ts': {
|
215
|
-
target: 'idle',
|
216
|
-
actions: ['markPropertyAsDynamic', 'clearPropertyType'],
|
217
|
-
},
|
218
|
-
// JSX
|
219
|
-
'punctuation.section.embedded.end.tsx': {
|
220
|
-
target: 'idle',
|
221
|
-
actions: 'clearPropertyType',
|
222
|
-
},
|
223
|
-
// Svelte
|
224
|
-
'punctuation.section.embedded.begin.svelte': {
|
225
|
-
target: 'idle',
|
226
|
-
actions: ['markPropertyAsDynamic', 'clearPropertyType'],
|
227
|
-
},
|
228
|
-
'punctuation.definition.string.end.svelte': {
|
229
|
-
target: 'idle',
|
230
|
-
actions: 'clearPropertyType',
|
231
|
-
},
|
232
|
-
'punctuation.section.embedded.end.svelte': {
|
233
|
-
target: 'idle',
|
234
|
-
actions: 'clearPropertyType',
|
235
|
-
},
|
236
|
-
// Vue
|
237
|
-
'punctuation.definition.string.end.html.vue': {
|
238
|
-
target: 'idle',
|
239
|
-
actions: 'clearPropertyType',
|
240
|
-
},
|
241
|
-
'punctuation.definition.string.end.html': {
|
242
|
-
target: 'idle',
|
243
|
-
actions: 'clearPropertyType',
|
244
|
-
},
|
245
|
-
},
|
246
|
-
},
|
247
|
-
end: {
|
248
|
-
type: 'final',
|
249
|
-
data: (ctx, evt) => ({
|
250
|
-
keyName: ctx.keyName,
|
251
|
-
defaultValue: ctx.defaultValue,
|
252
|
-
namespace: ctx.namespace,
|
253
|
-
lastEvent: evt,
|
254
|
-
}),
|
255
|
-
},
|
256
|
-
},
|
257
|
-
on: {
|
258
|
-
'punctuation.definition.block.ts': [
|
259
|
-
{
|
260
|
-
actions: 'incrementDepth',
|
261
|
-
cond: 'isOpenCurly',
|
262
|
-
},
|
263
|
-
{
|
264
|
-
target: 'end',
|
265
|
-
cond: 'isFinalCloseCurly',
|
266
|
-
},
|
267
|
-
{
|
268
|
-
actions: 'decrementDepth',
|
269
|
-
cond: 'isCloseCurly',
|
270
|
-
},
|
271
|
-
],
|
272
|
-
'punctuation.definition.tag.begin.tsx': {
|
273
|
-
actions: 'incrementJsxDepth',
|
274
|
-
cond: (_ctx, evt) => evt.token === '<',
|
275
|
-
},
|
276
|
-
'punctuation.definition.tag.end.tsx': [
|
277
|
-
{
|
278
|
-
target: 'end',
|
279
|
-
actions: 'markPropertyAsDynamic',
|
280
|
-
cond: (ctx) => ctx.jsxDepth === 0,
|
281
|
-
},
|
282
|
-
{
|
283
|
-
actions: 'decrementDoubleJsxDepth',
|
284
|
-
cond: (_ctx, e) => e.token === '/>',
|
285
|
-
},
|
286
|
-
{
|
287
|
-
actions: 'decrementJsxDepth',
|
288
|
-
},
|
289
|
-
],
|
290
|
-
'punctuation.definition.tag.end.svelte': {
|
291
|
-
target: 'end',
|
292
|
-
actions: 'markPropertyAsDynamic',
|
293
|
-
},
|
294
|
-
'punctuation.definition.tag.end.html.vue': {
|
295
|
-
target: 'end',
|
296
|
-
actions: 'markPropertyAsDynamic',
|
297
|
-
},
|
298
|
-
'punctuation.definition.tag.end.html': {
|
299
|
-
target: 'end',
|
300
|
-
actions: 'markPropertyAsDynamic',
|
301
|
-
},
|
302
|
-
},
|
303
|
-
}, {
|
304
|
-
guards: {
|
305
|
-
isOpenCurly: (_ctx, evt) => evt.token === '{' &&
|
306
|
-
!evt.scopes.includes('meta.embedded.expression.tsx') &&
|
307
|
-
!evt.scopes.includes('meta.embedded.expression.svelte') &&
|
308
|
-
(!evt.scopes.includes('source.ts.embedded.html.vue') ||
|
309
|
-
evt.scopes.includes('expression.embedded.vue')),
|
310
|
-
isCloseCurly: (_ctx, evt) => evt.token === '}' &&
|
311
|
-
!evt.scopes.includes('meta.embedded.expression.tsx') &&
|
312
|
-
!evt.scopes.includes('meta.embedded.expression.svelte') &&
|
313
|
-
(!evt.scopes.includes('source.ts.embedded.html.vue') ||
|
314
|
-
evt.scopes.includes('expression.embedded.vue')),
|
315
|
-
isFinalCloseCurly: (ctx, evt) => evt.token === '}' && ctx.depth === 1,
|
316
|
-
isOpenSquare: (_ctx, evt) => evt.token === '[',
|
317
|
-
isCloseSquare: (_ctx, evt) => evt.token === ']',
|
318
|
-
isRootLevel: (ctx) => ctx.depth === 1,
|
319
|
-
},
|
320
|
-
actions: {
|
321
|
-
storePropertyType: assign({
|
322
|
-
property: (_ctx, evt) => evt.token,
|
323
|
-
}),
|
324
|
-
clearPropertyType: assign({
|
325
|
-
property: (_ctx, _evt) => null,
|
326
|
-
}),
|
327
|
-
storePropertyValue: assign({
|
328
|
-
keyName: (ctx, evt) => ctx.property === 'key' || ctx.property === 'keyName'
|
329
|
-
? evt.token
|
330
|
-
: ctx.keyName,
|
331
|
-
defaultValue: (ctx, evt) => ctx.property === 'defaultValue' ? evt.token : ctx.defaultValue,
|
332
|
-
namespace: (ctx, evt) => ctx.property === 'ns' ? evt.token : ctx.namespace,
|
333
|
-
}),
|
334
|
-
storeEmptyPropertyValue: assign({
|
335
|
-
keyName: (ctx) => ctx.property === 'key' || ctx.property === 'keyName'
|
336
|
-
? ''
|
337
|
-
: ctx.keyName,
|
338
|
-
defaultValue: (ctx) => ctx.property === 'defaultValue' ? '' : ctx.defaultValue,
|
339
|
-
namespace: (ctx) => (ctx.property === 'ns' ? '' : ctx.namespace),
|
340
|
-
}),
|
341
|
-
markNextPropertyAsDynamic: assign({
|
342
|
-
nextDynamic: true,
|
343
|
-
}),
|
344
|
-
markPropertyAsDynamic: assign({
|
345
|
-
nextDynamic: false,
|
346
|
-
keyName: (ctx, _evt) => ctx.property === 'key' || ctx.property === 'keyName'
|
347
|
-
? false
|
348
|
-
: ctx.keyName,
|
349
|
-
defaultValue: (ctx, _evt) => ctx.property === 'defaultValue' ? false : ctx.defaultValue,
|
350
|
-
namespace: (ctx, _evt) => ctx.property === 'ns' ? false : ctx.namespace,
|
351
|
-
}),
|
352
|
-
markImmediatePropertyAsDynamic: assign({
|
353
|
-
nextDynamic: false,
|
354
|
-
keyName: (ctx, evt) => evt.token === 'key' || evt.token === 'keyName' ? false : ctx.keyName,
|
355
|
-
defaultValue: (ctx, evt) => evt.token === 'defaultValue' ? false : ctx.defaultValue,
|
356
|
-
namespace: (ctx, evt) => (evt.token === 'ns' ? false : ctx.namespace),
|
357
|
-
}),
|
358
|
-
incrementDepth: assign({
|
359
|
-
depth: (ctx, _evt) => ctx.depth + 1,
|
360
|
-
}),
|
361
|
-
decrementDepth: assign({
|
362
|
-
depth: (ctx, _evt) => ctx.depth - 1,
|
363
|
-
}),
|
364
|
-
incrementJsxDepth: assign({
|
365
|
-
jsxDepth: (ctx, _evt) => ctx.jsxDepth + 2,
|
366
|
-
}),
|
367
|
-
decrementDoubleJsxDepth: assign({
|
368
|
-
jsxDepth: (ctx, _evt) => ctx.jsxDepth - 2,
|
369
|
-
}),
|
370
|
-
decrementJsxDepth: assign({
|
371
|
-
jsxDepth: (ctx, _evt) => ctx.jsxDepth - 1,
|
372
|
-
}),
|
373
|
-
markAsStatic: assign({
|
374
|
-
static: true,
|
375
|
-
}),
|
376
|
-
unmarkAsStatic: assign({
|
377
|
-
static: false,
|
378
|
-
}),
|
379
|
-
},
|
380
|
-
});
|
@@ -1,141 +0,0 @@
|
|
1
|
-
// This machine is responsible for extracting data from
|
2
|
-
// calls to `t`. It is shared across multiple machines since
|
3
|
-
// all t functions share the same signature.
|
4
|
-
import { createMachine, assign, forwardTo } from 'xstate';
|
5
|
-
import propertiesMachine from './properties.js';
|
6
|
-
export default createMachine({
|
7
|
-
predictableActionArguments: true,
|
8
|
-
id: 'tCall',
|
9
|
-
initial: 'idle',
|
10
|
-
context: {
|
11
|
-
keyName: null,
|
12
|
-
defaultValue: null,
|
13
|
-
namespace: null,
|
14
|
-
dynamicOptions: false,
|
15
|
-
},
|
16
|
-
states: {
|
17
|
-
idle: {
|
18
|
-
on: {
|
19
|
-
'punctuation.definition.string.begin.ts': 'string',
|
20
|
-
'punctuation.definition.string.template.begin.ts': 'string',
|
21
|
-
'variable.other.readwrite.ts': [
|
22
|
-
{
|
23
|
-
target: 'done',
|
24
|
-
actions: 'dynamicOptions',
|
25
|
-
cond: (ctx) => !!ctx.keyName,
|
26
|
-
},
|
27
|
-
{
|
28
|
-
target: 'done',
|
29
|
-
actions: 'dynamicKeyName',
|
30
|
-
},
|
31
|
-
],
|
32
|
-
'punctuation.definition.block.ts': {
|
33
|
-
target: 'object',
|
34
|
-
cond: (_ctx, evt) => evt.token === '{',
|
35
|
-
},
|
36
|
-
'meta.brace.round.ts': {
|
37
|
-
target: 'done',
|
38
|
-
cond: (_ctx, evt) => evt.token === ')',
|
39
|
-
},
|
40
|
-
},
|
41
|
-
},
|
42
|
-
string: {
|
43
|
-
on: {
|
44
|
-
'*': [
|
45
|
-
{
|
46
|
-
target: 'string_end',
|
47
|
-
actions: 'storeKeyName',
|
48
|
-
cond: (ctx) => !ctx.keyName,
|
49
|
-
},
|
50
|
-
{
|
51
|
-
target: 'string_end',
|
52
|
-
actions: 'storeDefaultValue',
|
53
|
-
cond: (ctx) => !!ctx.keyName,
|
54
|
-
},
|
55
|
-
],
|
56
|
-
},
|
57
|
-
},
|
58
|
-
string_end: {
|
59
|
-
on: {
|
60
|
-
'punctuation.separator.comma.ts': 'idle',
|
61
|
-
'punctuation.definition.template-expression.begin.ts': [
|
62
|
-
{
|
63
|
-
target: 'string_end_warn',
|
64
|
-
actions: 'dynamicDefaultValue',
|
65
|
-
cond: (ctx) => !!ctx.defaultValue,
|
66
|
-
},
|
67
|
-
{
|
68
|
-
target: 'done',
|
69
|
-
actions: 'dynamicKeyName',
|
70
|
-
},
|
71
|
-
],
|
72
|
-
'keyword.operator.arithmetic.ts': [
|
73
|
-
{
|
74
|
-
target: 'string_end_warn',
|
75
|
-
actions: 'dynamicDefaultValue',
|
76
|
-
cond: (ctx) => !!ctx.defaultValue,
|
77
|
-
},
|
78
|
-
{
|
79
|
-
target: 'done',
|
80
|
-
actions: 'dynamicKeyName',
|
81
|
-
},
|
82
|
-
],
|
83
|
-
'meta.brace.round.ts': {
|
84
|
-
target: 'done',
|
85
|
-
cond: (_ctx, evt) => evt.token === ')',
|
86
|
-
},
|
87
|
-
},
|
88
|
-
},
|
89
|
-
string_end_warn: {
|
90
|
-
on: {
|
91
|
-
'punctuation.separator.comma.ts': 'idle',
|
92
|
-
'meta.brace.round.ts': {
|
93
|
-
target: 'done',
|
94
|
-
cond: (_ctx, evt) => evt.token === ')',
|
95
|
-
},
|
96
|
-
},
|
97
|
-
},
|
98
|
-
object: {
|
99
|
-
invoke: {
|
100
|
-
id: 'propertiesMachine',
|
101
|
-
src: propertiesMachine,
|
102
|
-
data: {
|
103
|
-
depth: 1,
|
104
|
-
},
|
105
|
-
onDone: {
|
106
|
-
target: 'done',
|
107
|
-
actions: 'consumeParameters',
|
108
|
-
},
|
109
|
-
},
|
110
|
-
on: {
|
111
|
-
'*': {
|
112
|
-
actions: forwardTo('propertiesMachine'),
|
113
|
-
},
|
114
|
-
},
|
115
|
-
},
|
116
|
-
done: { type: 'final', data: (ctx) => ctx },
|
117
|
-
},
|
118
|
-
}, {
|
119
|
-
actions: {
|
120
|
-
storeKeyName: assign({
|
121
|
-
keyName: (_, evt) => evt.token,
|
122
|
-
}),
|
123
|
-
storeDefaultValue: assign({
|
124
|
-
defaultValue: (_, evt) => evt.token,
|
125
|
-
}),
|
126
|
-
consumeParameters: assign({
|
127
|
-
keyName: (ctx, evt) => ctx.keyName === null ? evt.data.keyName : ctx.keyName,
|
128
|
-
namespace: (ctx, evt) => ctx.namespace === null ? evt.data.namespace : ctx.namespace,
|
129
|
-
defaultValue: (ctx, evt) => ctx.defaultValue === null ? evt.data.defaultValue : ctx.defaultValue,
|
130
|
-
}),
|
131
|
-
dynamicKeyName: assign({
|
132
|
-
keyName: () => false,
|
133
|
-
}),
|
134
|
-
dynamicDefaultValue: assign({
|
135
|
-
defaultValue: () => false,
|
136
|
-
}),
|
137
|
-
dynamicOptions: assign({
|
138
|
-
dynamicOptions: () => true,
|
139
|
-
}),
|
140
|
-
},
|
141
|
-
});
|