@motifx/compiler 1.0.1
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 +21 -0
- package/README.md +91 -0
- package/bin/motif-explain.cjs +47 -0
- package/bin/motif-lint.cjs +33 -0
- package/dist/index.cjs +3422 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +83 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.esm.js +3388 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +95 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,3422 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var t = require('@babel/types');
|
|
6
|
+
var babel = require('@babel/core');
|
|
7
|
+
var syntax_jsx = require('@babel/plugin-syntax-jsx');
|
|
8
|
+
var syntax_flow = require('@babel/plugin-syntax-flow');
|
|
9
|
+
var preset_flow = require('@babel/preset-flow');
|
|
10
|
+
var preset_typescript = require('@babel/preset-typescript');
|
|
11
|
+
var proposal_decorators = require('@babel/plugin-proposal-decorators');
|
|
12
|
+
var transform_class_properties = require('@babel/plugin-transform-class-properties');
|
|
13
|
+
var transform_class_static_block = require('@babel/plugin-transform-class-static-block');
|
|
14
|
+
var htmlTags = require('html-tags');
|
|
15
|
+
var svgTags = require('svg-tags');
|
|
16
|
+
var generatorNs = require('@babel/generator');
|
|
17
|
+
var path = require('node:path');
|
|
18
|
+
var ts = require('typescript');
|
|
19
|
+
var pPath = require('path');
|
|
20
|
+
|
|
21
|
+
function _interopNamespaceDefault(e) {
|
|
22
|
+
var n = Object.create(null);
|
|
23
|
+
if (e) {
|
|
24
|
+
Object.keys(e).forEach(function (k) {
|
|
25
|
+
if (k !== 'default') {
|
|
26
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return e[k]; }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
n.default = e;
|
|
35
|
+
return Object.freeze(n);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var t__namespace = /*#__PURE__*/_interopNamespaceDefault(t);
|
|
39
|
+
var babel__namespace = /*#__PURE__*/_interopNamespaceDefault(babel);
|
|
40
|
+
var generatorNs__namespace = /*#__PURE__*/_interopNamespaceDefault(generatorNs);
|
|
41
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
42
|
+
var ts__namespace = /*#__PURE__*/_interopNamespaceDefault(ts);
|
|
43
|
+
|
|
44
|
+
const htmlAttributes = new Map();
|
|
45
|
+
htmlAttributes.set('accept', false);
|
|
46
|
+
htmlAttributes.set('bind', false);
|
|
47
|
+
htmlAttributes.set("accept-charset", false);
|
|
48
|
+
htmlAttributes.set('accesskey', false);
|
|
49
|
+
htmlAttributes.set('action', false);
|
|
50
|
+
htmlAttributes.set('align', false);
|
|
51
|
+
htmlAttributes.set('allow', false);
|
|
52
|
+
htmlAttributes.set('alt', false);
|
|
53
|
+
htmlAttributes.set('async', false);
|
|
54
|
+
htmlAttributes.set('autocapitalize', false);
|
|
55
|
+
htmlAttributes.set('autofocus', false);
|
|
56
|
+
htmlAttributes.set('autoplay', false);
|
|
57
|
+
htmlAttributes.set('background', false);
|
|
58
|
+
htmlAttributes.set('bgcolor', false);
|
|
59
|
+
htmlAttributes.set('border', false);
|
|
60
|
+
htmlAttributes.set('buffered', false);
|
|
61
|
+
htmlAttributes.set('capture', false);
|
|
62
|
+
htmlAttributes.set('challenge', false);
|
|
63
|
+
htmlAttributes.set('charset', false);
|
|
64
|
+
htmlAttributes.set('checked', false);
|
|
65
|
+
htmlAttributes.set('cite', false);
|
|
66
|
+
htmlAttributes.set('class', false);
|
|
67
|
+
htmlAttributes.set('code', false);
|
|
68
|
+
htmlAttributes.set('codebase', false);
|
|
69
|
+
htmlAttributes.set('color', false);
|
|
70
|
+
htmlAttributes.set('cols', false);
|
|
71
|
+
htmlAttributes.set('colspan', false);
|
|
72
|
+
htmlAttributes.set('content', false);
|
|
73
|
+
htmlAttributes.set('contenteditable', false);
|
|
74
|
+
htmlAttributes.set('contextmenu', false);
|
|
75
|
+
htmlAttributes.set('controls', false);
|
|
76
|
+
htmlAttributes.set('coords', false);
|
|
77
|
+
htmlAttributes.set('crossorigin', false);
|
|
78
|
+
htmlAttributes.set('csp', false);
|
|
79
|
+
htmlAttributes.set('data', false);
|
|
80
|
+
htmlAttributes.set('data-*', false);
|
|
81
|
+
htmlAttributes.set('datetime', false);
|
|
82
|
+
htmlAttributes.set('decoding', false);
|
|
83
|
+
htmlAttributes.set('default', false);
|
|
84
|
+
htmlAttributes.set('defer', false);
|
|
85
|
+
htmlAttributes.set('dir', false);
|
|
86
|
+
htmlAttributes.set('dirname', false);
|
|
87
|
+
htmlAttributes.set('disabled', false);
|
|
88
|
+
htmlAttributes.set('download', false);
|
|
89
|
+
htmlAttributes.set('draggable', false);
|
|
90
|
+
htmlAttributes.set('enctype', false);
|
|
91
|
+
htmlAttributes.set('enterkeyhint', false);
|
|
92
|
+
htmlAttributes.set('for', false);
|
|
93
|
+
htmlAttributes.set('form', false);
|
|
94
|
+
htmlAttributes.set('formaction', false);
|
|
95
|
+
htmlAttributes.set('formenctype', false);
|
|
96
|
+
htmlAttributes.set('formmethod', false);
|
|
97
|
+
htmlAttributes.set('formnovalidate', false);
|
|
98
|
+
htmlAttributes.set('formtarget', false);
|
|
99
|
+
htmlAttributes.set('headers', false);
|
|
100
|
+
htmlAttributes.set('height', false);
|
|
101
|
+
htmlAttributes.set('hidden', false);
|
|
102
|
+
htmlAttributes.set('high', false);
|
|
103
|
+
htmlAttributes.set('href', false);
|
|
104
|
+
htmlAttributes.set('hreflang', false);
|
|
105
|
+
htmlAttributes.set('http-equiv', false);
|
|
106
|
+
htmlAttributes.set('icon', false);
|
|
107
|
+
htmlAttributes.set('id', false);
|
|
108
|
+
htmlAttributes.set('importance', false);
|
|
109
|
+
htmlAttributes.set('integrity', false);
|
|
110
|
+
htmlAttributes.set('intrinsicsize', false);
|
|
111
|
+
htmlAttributes.set('inputmode', false);
|
|
112
|
+
htmlAttributes.set('ismap', false);
|
|
113
|
+
htmlAttributes.set('itemprop', false);
|
|
114
|
+
htmlAttributes.set('keytype', false);
|
|
115
|
+
htmlAttributes.set('kind', false);
|
|
116
|
+
htmlAttributes.set('label', false);
|
|
117
|
+
htmlAttributes.set('lang', false);
|
|
118
|
+
htmlAttributes.set('language', false);
|
|
119
|
+
htmlAttributes.set('loading', false);
|
|
120
|
+
htmlAttributes.set('list', false);
|
|
121
|
+
htmlAttributes.set('loop', false);
|
|
122
|
+
htmlAttributes.set('low', false);
|
|
123
|
+
htmlAttributes.set('manifest', false);
|
|
124
|
+
htmlAttributes.set('max', false);
|
|
125
|
+
htmlAttributes.set('maxlength', false);
|
|
126
|
+
htmlAttributes.set('minlength', false);
|
|
127
|
+
htmlAttributes.set('media', false);
|
|
128
|
+
htmlAttributes.set('method', false);
|
|
129
|
+
htmlAttributes.set('min', false);
|
|
130
|
+
htmlAttributes.set('multiple', false);
|
|
131
|
+
htmlAttributes.set('muted', false);
|
|
132
|
+
htmlAttributes.set('name', false);
|
|
133
|
+
htmlAttributes.set('novalidate', false);
|
|
134
|
+
htmlAttributes.set('open', false);
|
|
135
|
+
htmlAttributes.set('optimum', false);
|
|
136
|
+
htmlAttributes.set('pattern', false);
|
|
137
|
+
htmlAttributes.set('ping', false);
|
|
138
|
+
htmlAttributes.set('placeholder', false);
|
|
139
|
+
htmlAttributes.set('poster', false);
|
|
140
|
+
htmlAttributes.set('preload', false);
|
|
141
|
+
htmlAttributes.set('radiogroup', false);
|
|
142
|
+
htmlAttributes.set('readonly', false);
|
|
143
|
+
htmlAttributes.set('referrerpolicy', false);
|
|
144
|
+
htmlAttributes.set('rel', false);
|
|
145
|
+
htmlAttributes.set('required', false);
|
|
146
|
+
htmlAttributes.set('reversed', false);
|
|
147
|
+
htmlAttributes.set('role', false);
|
|
148
|
+
htmlAttributes.set('rows', false);
|
|
149
|
+
htmlAttributes.set('rowspan', false);
|
|
150
|
+
htmlAttributes.set('sandbox', false);
|
|
151
|
+
htmlAttributes.set('scope', false);
|
|
152
|
+
htmlAttributes.set('scoped', false);
|
|
153
|
+
htmlAttributes.set('selected', false);
|
|
154
|
+
htmlAttributes.set('shape', false);
|
|
155
|
+
htmlAttributes.set('size', false);
|
|
156
|
+
htmlAttributes.set('sizes', false);
|
|
157
|
+
htmlAttributes.set('slot', false);
|
|
158
|
+
htmlAttributes.set('span', false);
|
|
159
|
+
htmlAttributes.set('spellcheck', false);
|
|
160
|
+
htmlAttributes.set('src', false);
|
|
161
|
+
htmlAttributes.set('srcdoc', false);
|
|
162
|
+
htmlAttributes.set('srclang', false);
|
|
163
|
+
htmlAttributes.set('srcset', false);
|
|
164
|
+
htmlAttributes.set('start', false);
|
|
165
|
+
htmlAttributes.set('step', false);
|
|
166
|
+
htmlAttributes.set('style', false);
|
|
167
|
+
htmlAttributes.set('summary', false);
|
|
168
|
+
htmlAttributes.set('tabindex', false);
|
|
169
|
+
htmlAttributes.set('target', false);
|
|
170
|
+
htmlAttributes.set('title', false);
|
|
171
|
+
htmlAttributes.set('translate', false);
|
|
172
|
+
htmlAttributes.set('type', false);
|
|
173
|
+
htmlAttributes.set('usemap', false);
|
|
174
|
+
htmlAttributes.set('value', false);
|
|
175
|
+
htmlAttributes.set('width', false);
|
|
176
|
+
htmlAttributes.set('wrap', false);
|
|
177
|
+
htmlAttributes.set('aria-readonly', true);
|
|
178
|
+
htmlAttributes.set('className', false);
|
|
179
|
+
htmlAttributes.set('xml:base', false);
|
|
180
|
+
htmlAttributes.set('xml:lang', false);
|
|
181
|
+
htmlAttributes.set('xml:space', false);
|
|
182
|
+
htmlAttributes.set('xmlns:xlink', false);
|
|
183
|
+
htmlAttributes.set('xmlns', false);
|
|
184
|
+
htmlAttributes.set('alignment-baseline', false);
|
|
185
|
+
htmlAttributes.set('baseline-shift', false);
|
|
186
|
+
htmlAttributes.set('clip', false);
|
|
187
|
+
htmlAttributes.set('clip-path', false);
|
|
188
|
+
htmlAttributes.set('clip-rule', false);
|
|
189
|
+
htmlAttributes.set('color', false);
|
|
190
|
+
htmlAttributes.set('color-interpolation', false);
|
|
191
|
+
htmlAttributes.set('color-interpolation-filters', false);
|
|
192
|
+
htmlAttributes.set('color-profile', false);
|
|
193
|
+
htmlAttributes.set('color-rendering', false);
|
|
194
|
+
htmlAttributes.set('cursor', false);
|
|
195
|
+
htmlAttributes.set('direction', false);
|
|
196
|
+
htmlAttributes.set('display', false);
|
|
197
|
+
htmlAttributes.set('dominant-baseline', false);
|
|
198
|
+
htmlAttributes.set('enable-background', false);
|
|
199
|
+
htmlAttributes.set('fill', false);
|
|
200
|
+
htmlAttributes.set('fill-opacity', false);
|
|
201
|
+
htmlAttributes.set('fill-rule', false);
|
|
202
|
+
htmlAttributes.set('filter', false);
|
|
203
|
+
htmlAttributes.set('flood-color', false);
|
|
204
|
+
htmlAttributes.set('flood-opacity', false);
|
|
205
|
+
htmlAttributes.set('font-family', false);
|
|
206
|
+
htmlAttributes.set('font-size', false);
|
|
207
|
+
htmlAttributes.set('font-size-adjust', false);
|
|
208
|
+
htmlAttributes.set('font-stretch', false);
|
|
209
|
+
htmlAttributes.set('font-style', false);
|
|
210
|
+
htmlAttributes.set('font-variant', false);
|
|
211
|
+
htmlAttributes.set('font-weight', false);
|
|
212
|
+
htmlAttributes.set('glyph-orientation-horizontal', false);
|
|
213
|
+
htmlAttributes.set('glyph-orientation-vertical', false);
|
|
214
|
+
htmlAttributes.set('image-rendering', false);
|
|
215
|
+
htmlAttributes.set('kerning', false);
|
|
216
|
+
htmlAttributes.set('letter-spacing', false);
|
|
217
|
+
htmlAttributes.set('lighting-color', false);
|
|
218
|
+
htmlAttributes.set('marker-end', false);
|
|
219
|
+
htmlAttributes.set('marker-mid', false);
|
|
220
|
+
htmlAttributes.set('marker-start', false);
|
|
221
|
+
htmlAttributes.set('mask', false);
|
|
222
|
+
htmlAttributes.set('opacity', false);
|
|
223
|
+
htmlAttributes.set('overflow', false);
|
|
224
|
+
htmlAttributes.set('pointer-events', false);
|
|
225
|
+
htmlAttributes.set('shape-rendering', false);
|
|
226
|
+
htmlAttributes.set('stop-color', false);
|
|
227
|
+
htmlAttributes.set('stop-opacity', false);
|
|
228
|
+
htmlAttributes.set('stroke', false);
|
|
229
|
+
htmlAttributes.set('stroke-dasharray', false);
|
|
230
|
+
htmlAttributes.set('stroke-dashoffset', false);
|
|
231
|
+
htmlAttributes.set('stroke-linecap', false);
|
|
232
|
+
htmlAttributes.set('stroke-linejoin', false);
|
|
233
|
+
htmlAttributes.set('stroke-miterlimit', false);
|
|
234
|
+
htmlAttributes.set('stroke-opacity', false);
|
|
235
|
+
htmlAttributes.set('stroke-width', false);
|
|
236
|
+
htmlAttributes.set('text-anchor', false);
|
|
237
|
+
htmlAttributes.set('text-decoration', false);
|
|
238
|
+
htmlAttributes.set('text-rendering', false);
|
|
239
|
+
htmlAttributes.set('transform', false);
|
|
240
|
+
htmlAttributes.set('transform-origin', false);
|
|
241
|
+
htmlAttributes.set('unicode-bidi', false);
|
|
242
|
+
htmlAttributes.set('vector-effect', false);
|
|
243
|
+
htmlAttributes.set('visibility', false);
|
|
244
|
+
htmlAttributes.set('word-spacing', false);
|
|
245
|
+
htmlAttributes.set('writing-mode', false);
|
|
246
|
+
htmlAttributes.set('x1', false);
|
|
247
|
+
htmlAttributes.set('x2', false);
|
|
248
|
+
htmlAttributes.set('y1', false);
|
|
249
|
+
htmlAttributes.set('y2', false);
|
|
250
|
+
htmlAttributes.set('offset', false);
|
|
251
|
+
htmlAttributes.set('d', false);
|
|
252
|
+
htmlAttributes.set('preserveaspectratio', false);
|
|
253
|
+
htmlAttributes.set('viewbox', false);
|
|
254
|
+
htmlAttributes.set('viewBox', false);
|
|
255
|
+
const htmlEvents = new Map();
|
|
256
|
+
htmlEvents.set("onafterprint", false);
|
|
257
|
+
htmlEvents.set("onbeforeprint", false);
|
|
258
|
+
htmlEvents.set("onbeforeunload", false);
|
|
259
|
+
htmlEvents.set("onerror", false);
|
|
260
|
+
htmlEvents.set("onhashchange", false);
|
|
261
|
+
htmlEvents.set("onload", false);
|
|
262
|
+
htmlEvents.set("onmessage", false);
|
|
263
|
+
htmlEvents.set("onoffline", false);
|
|
264
|
+
htmlEvents.set("ononline", false);
|
|
265
|
+
htmlEvents.set("onpagehide", false);
|
|
266
|
+
htmlEvents.set("onpageshow", false);
|
|
267
|
+
htmlEvents.set("onpopstate", false);
|
|
268
|
+
htmlEvents.set("onresize", false);
|
|
269
|
+
htmlEvents.set("onstorage", false);
|
|
270
|
+
htmlEvents.set("onunload", false);
|
|
271
|
+
htmlEvents.set("onblur", false);
|
|
272
|
+
htmlEvents.set("onchange", false);
|
|
273
|
+
htmlEvents.set("oncontextmenu", false);
|
|
274
|
+
htmlEvents.set("onfocus", false);
|
|
275
|
+
htmlEvents.set("oninput", false);
|
|
276
|
+
htmlEvents.set("oninvalid", false);
|
|
277
|
+
htmlEvents.set("onreset", false);
|
|
278
|
+
htmlEvents.set("onsearch", false);
|
|
279
|
+
htmlEvents.set("onselect", false);
|
|
280
|
+
htmlEvents.set("onsubmit", false);
|
|
281
|
+
htmlEvents.set("onkeydown", false);
|
|
282
|
+
htmlEvents.set("onkeypress", false);
|
|
283
|
+
htmlEvents.set("onkeyup", false);
|
|
284
|
+
htmlEvents.set("onclick", false);
|
|
285
|
+
htmlEvents.set("ondblclick", false);
|
|
286
|
+
htmlEvents.set("onmousedown", false);
|
|
287
|
+
htmlEvents.set("onmousemove", false);
|
|
288
|
+
htmlEvents.set("onmouseout", false);
|
|
289
|
+
htmlEvents.set("onmouseover", false);
|
|
290
|
+
htmlEvents.set("onmouseup", false);
|
|
291
|
+
htmlEvents.set("onmousewheel", false);
|
|
292
|
+
htmlEvents.set("onwheel", false);
|
|
293
|
+
htmlEvents.set("ondrag", false);
|
|
294
|
+
htmlEvents.set("ondragend", false);
|
|
295
|
+
htmlEvents.set("ondragenter", false);
|
|
296
|
+
htmlEvents.set("ondragleave", false);
|
|
297
|
+
htmlEvents.set("ondragover", false);
|
|
298
|
+
htmlEvents.set("ondragstart", false);
|
|
299
|
+
htmlEvents.set("ondrop", false);
|
|
300
|
+
htmlEvents.set("onscroll", false);
|
|
301
|
+
htmlEvents.set("oncopy", false);
|
|
302
|
+
htmlEvents.set("oncut", false);
|
|
303
|
+
htmlEvents.set("onpaste", false);
|
|
304
|
+
htmlEvents.set("onabort", false);
|
|
305
|
+
htmlEvents.set("oncanplay", false);
|
|
306
|
+
htmlEvents.set("oncanplaythrough", false);
|
|
307
|
+
htmlEvents.set("oncuechange", false);
|
|
308
|
+
htmlEvents.set("ondurationchange", false);
|
|
309
|
+
htmlEvents.set("onemptied", false);
|
|
310
|
+
htmlEvents.set("onended", false);
|
|
311
|
+
htmlEvents.set("onerror", false);
|
|
312
|
+
htmlEvents.set("onloadeddata", false);
|
|
313
|
+
htmlEvents.set("onloadedmetadata", false);
|
|
314
|
+
htmlEvents.set("onloadstart", false);
|
|
315
|
+
htmlEvents.set("onpause", false);
|
|
316
|
+
htmlEvents.set("onplay", false);
|
|
317
|
+
htmlEvents.set("onplaying", false);
|
|
318
|
+
htmlEvents.set("onprogress", false);
|
|
319
|
+
htmlEvents.set("onratechange", false);
|
|
320
|
+
htmlEvents.set("onseeked", false);
|
|
321
|
+
htmlEvents.set("onseeking", false);
|
|
322
|
+
htmlEvents.set("onstalled", false);
|
|
323
|
+
htmlEvents.set("onsuspend", false);
|
|
324
|
+
htmlEvents.set("ontimeupdate", false);
|
|
325
|
+
htmlEvents.set("onvolumechange", false);
|
|
326
|
+
htmlEvents.set("onwaiting", false);
|
|
327
|
+
htmlEvents.set("ontoggle", false);
|
|
328
|
+
var types = [
|
|
329
|
+
':once',
|
|
330
|
+
':once:passive',
|
|
331
|
+
':once:passive:prevent',
|
|
332
|
+
':once:passive:stop',
|
|
333
|
+
':once:passive:trusted',
|
|
334
|
+
':once:passive:capture',
|
|
335
|
+
':once:passive:self',
|
|
336
|
+
':once:prevent',
|
|
337
|
+
':once:prevent:stop',
|
|
338
|
+
':once:prevent:trusted',
|
|
339
|
+
':once:prevent:trusted:capture',
|
|
340
|
+
':once:prevent:trusted:self',
|
|
341
|
+
':once:stop',
|
|
342
|
+
':once:stop:trusted',
|
|
343
|
+
':once:stop:capture',
|
|
344
|
+
':once:stop:self',
|
|
345
|
+
':once:trusted',
|
|
346
|
+
':once:trusted:capture',
|
|
347
|
+
':once:trusted:self',
|
|
348
|
+
':passive',
|
|
349
|
+
':passive:prevent',
|
|
350
|
+
':passive:prevent:stop',
|
|
351
|
+
':passive:prevent:trusted',
|
|
352
|
+
':passive:prevent:capture',
|
|
353
|
+
':passive:prevent:self',
|
|
354
|
+
':passive:stop',
|
|
355
|
+
':passive:stop:trusted',
|
|
356
|
+
':passive:stop:capture',
|
|
357
|
+
':passive:stop:self',
|
|
358
|
+
':passive:trusted',
|
|
359
|
+
':passive:trusted:capture',
|
|
360
|
+
':passive:trusted:self',
|
|
361
|
+
':passive:capture',
|
|
362
|
+
':passive:capture:self',
|
|
363
|
+
':passive:self',
|
|
364
|
+
':prevent',
|
|
365
|
+
':prevent:stop',
|
|
366
|
+
':prevent:trusted',
|
|
367
|
+
':prevent:capture',
|
|
368
|
+
':prevent:self',
|
|
369
|
+
':stop',
|
|
370
|
+
':stop:trusted',
|
|
371
|
+
':stop:capture',
|
|
372
|
+
':stop:self',
|
|
373
|
+
':trusted',
|
|
374
|
+
':trusted:capture',
|
|
375
|
+
':trusted:self',
|
|
376
|
+
':capture',
|
|
377
|
+
':capture:self',
|
|
378
|
+
':self'
|
|
379
|
+
];
|
|
380
|
+
types.forEach(element => {
|
|
381
|
+
htmlEvents.set(`onafterprint${element}`, false);
|
|
382
|
+
htmlEvents.set(`onbeforeprint${element}`, false);
|
|
383
|
+
htmlEvents.set(`onbeforeunload${element}`, false);
|
|
384
|
+
htmlEvents.set(`onerror${element}`, false);
|
|
385
|
+
htmlEvents.set(`onhashchange${element}`, false);
|
|
386
|
+
htmlEvents.set(`onload${element}`, false);
|
|
387
|
+
htmlEvents.set(`onmessage${element}`, false);
|
|
388
|
+
htmlEvents.set(`onoffline${element}`, false);
|
|
389
|
+
htmlEvents.set(`ononline${element}`, false);
|
|
390
|
+
htmlEvents.set(`onpagehide${element}`, false);
|
|
391
|
+
htmlEvents.set(`onpageshow${element}`, false);
|
|
392
|
+
htmlEvents.set(`onpopstate${element}`, false);
|
|
393
|
+
htmlEvents.set(`onresize${element}`, false);
|
|
394
|
+
htmlEvents.set(`onstorage${element}`, false);
|
|
395
|
+
htmlEvents.set(`onunload${element}`, false);
|
|
396
|
+
htmlEvents.set(`onblur${element}`, false);
|
|
397
|
+
htmlEvents.set(`onchange${element}`, false);
|
|
398
|
+
htmlEvents.set(`oncontextmenu${element}`, false);
|
|
399
|
+
htmlEvents.set(`onfocus${element}`, false);
|
|
400
|
+
htmlEvents.set(`oninput${element}`, false);
|
|
401
|
+
htmlEvents.set(`oninvalid${element}`, false);
|
|
402
|
+
htmlEvents.set(`onreset${element}`, false);
|
|
403
|
+
htmlEvents.set(`onsearch${element}`, false);
|
|
404
|
+
htmlEvents.set(`onselect${element}`, false);
|
|
405
|
+
htmlEvents.set(`onsubmit${element}`, false);
|
|
406
|
+
htmlEvents.set(`onkeydown${element}`, false);
|
|
407
|
+
htmlEvents.set(`onkeypress${element}`, false);
|
|
408
|
+
htmlEvents.set(`onkeyup${element}`, false);
|
|
409
|
+
htmlEvents.set(`onclick${element}`, false);
|
|
410
|
+
htmlEvents.set(`ondblclick${element}`, false);
|
|
411
|
+
htmlEvents.set(`onmousedown${element}`, false);
|
|
412
|
+
htmlEvents.set(`onmousemove${element}`, false);
|
|
413
|
+
htmlEvents.set(`onmouseout${element}`, false);
|
|
414
|
+
htmlEvents.set(`onmouseover${element}`, false);
|
|
415
|
+
htmlEvents.set(`onmouseup${element}`, false);
|
|
416
|
+
htmlEvents.set(`onmousewheel${element}`, false);
|
|
417
|
+
htmlEvents.set(`onwheel${element}`, false);
|
|
418
|
+
htmlEvents.set(`ondrag${element}`, false);
|
|
419
|
+
htmlEvents.set(`ondragend${element}`, false);
|
|
420
|
+
htmlEvents.set(`ondragenter${element}`, false);
|
|
421
|
+
htmlEvents.set(`ondragleave${element}`, false);
|
|
422
|
+
htmlEvents.set(`ondragover${element}`, false);
|
|
423
|
+
htmlEvents.set(`ondragstart${element}`, false);
|
|
424
|
+
htmlEvents.set(`ondrop${element}`, false);
|
|
425
|
+
htmlEvents.set(`onscroll${element}`, false);
|
|
426
|
+
htmlEvents.set(`oncopy${element}`, false);
|
|
427
|
+
htmlEvents.set(`oncut${element}`, false);
|
|
428
|
+
htmlEvents.set(`onpaste${element}`, false);
|
|
429
|
+
htmlEvents.set(`onabort${element}`, false);
|
|
430
|
+
htmlEvents.set(`oncanplay${element}`, false);
|
|
431
|
+
htmlEvents.set(`oncanplaythrough${element}`, false);
|
|
432
|
+
htmlEvents.set(`oncuechange${element}`, false);
|
|
433
|
+
htmlEvents.set(`ondurationchange${element}`, false);
|
|
434
|
+
htmlEvents.set(`onemptied${element}`, false);
|
|
435
|
+
htmlEvents.set(`onended${element}`, false);
|
|
436
|
+
htmlEvents.set(`onerror${element}`, false);
|
|
437
|
+
htmlEvents.set(`onloadeddata${element}`, false);
|
|
438
|
+
htmlEvents.set(`onloadedmetadata${element}`, false);
|
|
439
|
+
htmlEvents.set(`onloadstart${element}`, false);
|
|
440
|
+
htmlEvents.set(`onpause${element}`, false);
|
|
441
|
+
htmlEvents.set(`onplay${element}`, false);
|
|
442
|
+
htmlEvents.set(`onplaying${element}`, false);
|
|
443
|
+
htmlEvents.set(`onprogress${element}`, false);
|
|
444
|
+
htmlEvents.set(`onratechange${element}`, false);
|
|
445
|
+
htmlEvents.set(`onseeked${element}`, false);
|
|
446
|
+
htmlEvents.set(`onseeking${element}`, false);
|
|
447
|
+
htmlEvents.set(`onstalled${element}`, false);
|
|
448
|
+
htmlEvents.set(`onsuspend${element}`, false);
|
|
449
|
+
htmlEvents.set(`ontimeupdate${element}`, false);
|
|
450
|
+
htmlEvents.set(`onvolumechange${element}`, false);
|
|
451
|
+
htmlEvents.set(`onwaiting${element}`, false);
|
|
452
|
+
htmlEvents.set(`ontoggle${element}`, false);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
const motifComponent = () => { return "_mc"; };
|
|
456
|
+
const motifFragment = () => { return "_mf"; };
|
|
457
|
+
const motifFunctionComponent = () => { return "_mfc"; };
|
|
458
|
+
const motifCompiled = () => { return "_mv"; };
|
|
459
|
+
const COMPILER_CONTRACT = 1;
|
|
460
|
+
|
|
461
|
+
let active$1 = null;
|
|
462
|
+
let seen = null;
|
|
463
|
+
function beginCollect() {
|
|
464
|
+
active$1 = [];
|
|
465
|
+
seen = new Set();
|
|
466
|
+
}
|
|
467
|
+
function endCollect() {
|
|
468
|
+
const out = active$1 ?? [];
|
|
469
|
+
active$1 = null;
|
|
470
|
+
seen = null;
|
|
471
|
+
return out;
|
|
472
|
+
}
|
|
473
|
+
/** Uyarıları terminale yazar. Vite/Rollup eklentileri derleme sonunda çağırır. */
|
|
474
|
+
function printDiagnostics(list) {
|
|
475
|
+
for (const d of list) {
|
|
476
|
+
const where = d.line === null ? d.file : `${d.file}:${d.line}`;
|
|
477
|
+
console.warn(`[motifjs] ${d.code}: ${d.message}\n ${where}${d.frame ? '\n' + d.frame : ''}`);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
function fail(code, message, path) {
|
|
481
|
+
const error = path.buildCodeFrameError(`[motifjs] ${code}: ${message}`);
|
|
482
|
+
error.code = code;
|
|
483
|
+
throw error;
|
|
484
|
+
}
|
|
485
|
+
function warn(code, message, path, filename) {
|
|
486
|
+
if (!active$1 || !seen)
|
|
487
|
+
return;
|
|
488
|
+
const line = path?.node?.loc?.start?.line ?? null;
|
|
489
|
+
const key = `${filename}:${line}:${code}`;
|
|
490
|
+
if (seen.has(key))
|
|
491
|
+
return;
|
|
492
|
+
seen.add(key);
|
|
493
|
+
let frame;
|
|
494
|
+
try {
|
|
495
|
+
frame = path ? path.buildCodeFrameError('').message.replace(/^[^\n]*\n/, '') : undefined;
|
|
496
|
+
if (frame !== undefined && frame.trim() === '')
|
|
497
|
+
frame = undefined;
|
|
498
|
+
}
|
|
499
|
+
catch {
|
|
500
|
+
frame = undefined;
|
|
501
|
+
}
|
|
502
|
+
active$1.push({ code, message, file: filename, line, frame });
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const makeHtmlAttr = (prop, name, value, path) => {
|
|
506
|
+
if (t__namespace.isStringLiteral(value) && value !== null) {
|
|
507
|
+
return t__namespace.objectProperty(t__namespace.stringLiteral(name), value);
|
|
508
|
+
}
|
|
509
|
+
else if (t__namespace.isBooleanLiteral(value)) {
|
|
510
|
+
return t__namespace.objectProperty(t__namespace.stringLiteral(name), value || t__namespace.booleanLiteral(true));
|
|
511
|
+
}
|
|
512
|
+
else if (t__namespace.isArrowFunctionExpression(value) && value !== null) {
|
|
513
|
+
if (t__namespace.isBlockStatement(value.body)) {
|
|
514
|
+
t__namespace.functionExpression(null, value.params, value.body);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
t__namespace.functionExpression(null, value.params, t__namespace.blockStatement([t__namespace.returnStatement(value.body)]));
|
|
518
|
+
}
|
|
519
|
+
return t__namespace.objectProperty(t__namespace.stringLiteral(name), value);
|
|
520
|
+
}
|
|
521
|
+
else if (t__namespace.isFunctionExpression(value)) {
|
|
522
|
+
return t__namespace.objectProperty(t__namespace.stringLiteral(name), value);
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
if (value != null) {
|
|
526
|
+
if (t__namespace.isCallExpression(value) && t__namespace.isIdentifier(value.callee)) {
|
|
527
|
+
if (value.callee.name !== 'motifComponent' && value.callee.name !== motifComponent()) {
|
|
528
|
+
return t__namespace.objectProperty(t__namespace.stringLiteral(name), value);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
else if (t__namespace.isIdentifier(value)) {
|
|
532
|
+
return t__namespace.objectProperty(t__namespace.stringLiteral(name), value);
|
|
533
|
+
}
|
|
534
|
+
else if (t__namespace.isUnaryExpression(value) && !t__namespace.isLiteral(value.argument)) {
|
|
535
|
+
return t__namespace.objectProperty(t__namespace.stringLiteral(name), t__namespace.arrowFunctionExpression([], value));
|
|
536
|
+
}
|
|
537
|
+
else if (t__namespace.isExpression(value)) {
|
|
538
|
+
return t__namespace.objectProperty(t__namespace.stringLiteral(name), returnIfStatement(value, false));
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return null;
|
|
543
|
+
};
|
|
544
|
+
const mergeHtmlAttributes = (htmlAttrlist) => {
|
|
545
|
+
const htmlProps = [];
|
|
546
|
+
if (htmlAttrlist.length > 0) {
|
|
547
|
+
var totalAttr = [];
|
|
548
|
+
var totalClass = [];
|
|
549
|
+
var totalBindClass = [];
|
|
550
|
+
var totalStringClass = [];
|
|
551
|
+
htmlAttrlist.forEach(attr => {
|
|
552
|
+
if (t__namespace.isStringLiteral(attr.key) || t__namespace.isTemplateLiteral(attr.key)) {
|
|
553
|
+
const keyValue = t__namespace.isStringLiteral(attr.key)
|
|
554
|
+
? attr.key.value.toLowerCase()
|
|
555
|
+
: attr.key.quasis.map(q => q.value.raw).join("").toLowerCase();
|
|
556
|
+
if (keyValue === "class" || keyValue === "classname") {
|
|
557
|
+
if (t__namespace.isObjectExpression(attr.value)) {
|
|
558
|
+
const objectProperties = [];
|
|
559
|
+
attr.value.properties.forEach(p => {
|
|
560
|
+
if (t__namespace.isObjectProperty(p)) {
|
|
561
|
+
const val = p.value;
|
|
562
|
+
if (t__namespace.isStringLiteral(val)) {
|
|
563
|
+
totalStringClass.push(p.key);
|
|
564
|
+
}
|
|
565
|
+
else if (t__namespace.isBooleanLiteral(val)) {
|
|
566
|
+
totalStringClass.push(p.key);
|
|
567
|
+
}
|
|
568
|
+
else if (t__namespace.isFunctionExpression(val) || t__namespace.isArrowFunctionExpression(val)) {
|
|
569
|
+
objectProperties.push(p);
|
|
570
|
+
}
|
|
571
|
+
else if (t__namespace.isTemplateLiteral(val)) {
|
|
572
|
+
if (val.expressions.length === 0) {
|
|
573
|
+
totalStringClass.push(t__namespace.stringLiteral(val.quasis.map(q => q.value.raw).join("")));
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
totalBindClass.push(t__namespace.arrowFunctionExpression([], val));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
totalClass.push(p);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
else if (t__namespace.isFunctionExpression(p) || t__namespace.isArrowFunctionExpression(p)) {
|
|
584
|
+
totalBindClass.push(p);
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
if (objectProperties.length > 0) {
|
|
588
|
+
totalBindClass.push(t__namespace.objectExpression(objectProperties));
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
else if (t__namespace.isMemberExpression(attr.value) || t__namespace.isCallExpression(attr.value)) {
|
|
592
|
+
totalBindClass.push(attr.value);
|
|
593
|
+
}
|
|
594
|
+
else if (t__namespace.isFunctionExpression(attr.value) || t__namespace.isArrowFunctionExpression(attr.value)) {
|
|
595
|
+
totalBindClass.push(attr.value);
|
|
596
|
+
}
|
|
597
|
+
else if (t__namespace.isIdentifier(attr.value)) {
|
|
598
|
+
totalBindClass.push(attr.value);
|
|
599
|
+
}
|
|
600
|
+
else if (t__namespace.isStringLiteral(attr.value)) {
|
|
601
|
+
totalStringClass.push(t__namespace.stringLiteral(attr.value.value));
|
|
602
|
+
}
|
|
603
|
+
else if (t__namespace.isTemplateLiteral(attr.value)) {
|
|
604
|
+
if (attr.value.expressions.length === 0) {
|
|
605
|
+
totalStringClass.push(t__namespace.stringLiteral(attr.value.quasis.map(q => q.value.raw).join("")));
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
totalBindClass.push(t__namespace.arrowFunctionExpression([], attr.value));
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
else if (t__namespace.isArrayExpression(attr.value)) {
|
|
612
|
+
attr.value.elements.forEach(element => {
|
|
613
|
+
if (!element)
|
|
614
|
+
return;
|
|
615
|
+
if (t__namespace.isObjectExpression(element)) {
|
|
616
|
+
element.properties.forEach(p => {
|
|
617
|
+
if (t__namespace.isObjectProperty(p)) {
|
|
618
|
+
const val = p.value;
|
|
619
|
+
if (t__namespace.isStringLiteral(val)) {
|
|
620
|
+
totalStringClass.push(p.key);
|
|
621
|
+
}
|
|
622
|
+
else if (t__namespace.isBooleanLiteral(val)) {
|
|
623
|
+
totalStringClass.push(p.key);
|
|
624
|
+
}
|
|
625
|
+
else if (t__namespace.isFunctionExpression(val) || t__namespace.isArrowFunctionExpression(val)) {
|
|
626
|
+
totalBindClass.push(val);
|
|
627
|
+
}
|
|
628
|
+
else if (t__namespace.isTemplateLiteral(val)) {
|
|
629
|
+
if (val.expressions.length === 0) {
|
|
630
|
+
totalStringClass.push(t__namespace.stringLiteral(val.quasis.map(q => q.value.raw).join("")));
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
totalBindClass.push(t__namespace.arrowFunctionExpression([], val));
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
else {
|
|
637
|
+
totalClass.push(p);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
else if (t__namespace.isFunctionExpression(p) || t__namespace.isArrowFunctionExpression(p)) {
|
|
641
|
+
totalBindClass.push(p);
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
else if (t__namespace.isStringLiteral(element)) {
|
|
646
|
+
totalStringClass.push(element);
|
|
647
|
+
}
|
|
648
|
+
else if (t__namespace.isTemplateLiteral(element)) {
|
|
649
|
+
if (element.expressions.length === 0) {
|
|
650
|
+
totalStringClass.push(t__namespace.stringLiteral(element.quasis.map(q => q.value.raw).join("")));
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
totalBindClass.push(t__namespace.arrowFunctionExpression([], element));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
else if (t__namespace.isFunctionExpression(element) || t__namespace.isArrowFunctionExpression(element)) {
|
|
657
|
+
totalBindClass.push(element);
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
else if (keyValue === "style") {
|
|
663
|
+
if (t__namespace.isObjectExpression(attr.value)) {
|
|
664
|
+
htmlProps.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier("sender.style"), [attr.value])));
|
|
665
|
+
}
|
|
666
|
+
else if (t__namespace.isStringLiteral(attr.value)) {
|
|
667
|
+
htmlProps.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier("sender.style"), [attr.value])));
|
|
668
|
+
}
|
|
669
|
+
else if (t__namespace.isTemplateLiteral(attr.value)) {
|
|
670
|
+
if (attr.value.expressions.length === 0) {
|
|
671
|
+
htmlProps.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier("sender.style"), [t__namespace.stringLiteral(attr.value.quasis.map(q => q.value.raw).join(""))])));
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
htmlProps.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier("sender.style"), [t__namespace.arrowFunctionExpression([], attr.value)])));
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
else if (t__namespace.isExpression(attr.value)) {
|
|
678
|
+
htmlProps.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier("sender.style"), [attr.value])));
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
else if (keyValue === 'checked' || keyValue === 'value' || keyValue === 'selected') {
|
|
682
|
+
const val = attr.value;
|
|
683
|
+
if (t__namespace.isArrowFunctionExpression(val) || t__namespace.isExpression(val)) {
|
|
684
|
+
htmlProps.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.bindings.add'), [t__namespace.stringLiteral(keyValue), val])));
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
let keyName;
|
|
689
|
+
if (t__namespace.isStringLiteral(attr.key)) {
|
|
690
|
+
keyName = t__namespace.stringLiteral(attr.key.value);
|
|
691
|
+
}
|
|
692
|
+
else if (t__namespace.isTemplateLiteral(attr.key)) {
|
|
693
|
+
keyName = t__namespace.stringLiteral(attr.key.quasis.map(q => q.value.raw).join(""));
|
|
694
|
+
}
|
|
695
|
+
else {
|
|
696
|
+
keyName = t__namespace.stringLiteral("unknown");
|
|
697
|
+
}
|
|
698
|
+
let valueExpr;
|
|
699
|
+
const val = attr.value;
|
|
700
|
+
if (t__namespace.isStringLiteral(val)) {
|
|
701
|
+
valueExpr = val;
|
|
702
|
+
}
|
|
703
|
+
else if (t__namespace.isTemplateLiteral(val)) {
|
|
704
|
+
valueExpr =
|
|
705
|
+
val.expressions.length === 0
|
|
706
|
+
? t__namespace.stringLiteral(val.quasis.map(q => q.value.raw).join(""))
|
|
707
|
+
: t__namespace.arrowFunctionExpression([], val);
|
|
708
|
+
}
|
|
709
|
+
else if (t__namespace.isObjectExpression(val) ||
|
|
710
|
+
t__namespace.isCallExpression(val) ||
|
|
711
|
+
t__namespace.isArrowFunctionExpression(val) ||
|
|
712
|
+
t__namespace.isMemberExpression(val) ||
|
|
713
|
+
t__namespace.isIdentifier(val)) {
|
|
714
|
+
valueExpr = val;
|
|
715
|
+
}
|
|
716
|
+
else if (t__namespace.isExpression(val)) {
|
|
717
|
+
valueExpr = val;
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
valueExpr = t__namespace.stringLiteral("");
|
|
721
|
+
}
|
|
722
|
+
totalAttr.push(t__namespace.objectProperty(keyName, valueExpr));
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
if (totalAttr.length > 0) {
|
|
727
|
+
htmlProps.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.attr.add'), [t__namespace.objectExpression(totalAttr)])));
|
|
728
|
+
}
|
|
729
|
+
if (totalBindClass.length > 0) {
|
|
730
|
+
htmlProps.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.class.add'), [t__namespace.arrayExpression(totalBindClass)])));
|
|
731
|
+
}
|
|
732
|
+
if (totalClass.length > 0) {
|
|
733
|
+
htmlProps.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.class.add'), [t__namespace.objectExpression(totalClass)])));
|
|
734
|
+
}
|
|
735
|
+
if (totalStringClass.length > 0) {
|
|
736
|
+
htmlProps.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.class.add'), [...totalStringClass])));
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return htmlProps;
|
|
740
|
+
};
|
|
741
|
+
const makeHtmlEvents = (prop, name, value, path) => {
|
|
742
|
+
if (!t__namespace.isStringLiteral(value) && !t__namespace.isBooleanLiteral(value) && value !== null) {
|
|
743
|
+
if (t__namespace.isArrowFunctionExpression(value)) {
|
|
744
|
+
var el;
|
|
745
|
+
if (t__namespace.isBlockStatement(value.body)) {
|
|
746
|
+
el = t__namespace.arrowFunctionExpression(value.params, value.body);
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
el = t__namespace.arrowFunctionExpression(value.params, t__namespace.blockStatement([t__namespace.returnStatement(value.body)]));
|
|
750
|
+
}
|
|
751
|
+
var evName = name.toLowerCase().replace("on", '').replace('doubleclick', 'dblclick');
|
|
752
|
+
return t__namespace.callExpression(t__namespace.identifier("sender.motif.on"), [t__namespace.stringLiteral(evName), el]);
|
|
753
|
+
}
|
|
754
|
+
else if (t__namespace.isFunctionExpression(value)) {
|
|
755
|
+
var el;
|
|
756
|
+
if (t__namespace.isBlockStatement(value.body)) {
|
|
757
|
+
el = t__namespace.functionExpression(null, value.params, value.body);
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
el = t__namespace.functionExpression(null, value.params, t__namespace.blockStatement([t__namespace.returnStatement(value.body)]));
|
|
761
|
+
}
|
|
762
|
+
var evName = name.toLowerCase().replace("on", '').replace('doubleclick', 'dblclick');
|
|
763
|
+
return t__namespace.callExpression(t__namespace.identifier("sender.motif.on"), [t__namespace.stringLiteral(evName), el]);
|
|
764
|
+
}
|
|
765
|
+
else {
|
|
766
|
+
if (t__namespace.isExpression(value)) {
|
|
767
|
+
var evName = name.toLowerCase().replace("on", '').replace('doubleclick', 'dblclick');
|
|
768
|
+
return t__namespace.callExpression(t__namespace.identifier("sender.motif.on"), [t__namespace.stringLiteral(evName), value]);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
else {
|
|
773
|
+
fail('MJX009', `Event handler "${name}" must be a function; string and boolean values are not allowed.`, prop);
|
|
774
|
+
}
|
|
775
|
+
return null;
|
|
776
|
+
};
|
|
777
|
+
const makeComponentTraps = (prop, name, value, path) => {
|
|
778
|
+
if (t__namespace.isFunctionExpression(value) ||
|
|
779
|
+
t__namespace.isArrowFunctionExpression(value) && value !== null ||
|
|
780
|
+
t__namespace.isObjectExpression(value) ||
|
|
781
|
+
t__namespace.isMemberExpression(value) ||
|
|
782
|
+
t__namespace.isObjectMethod(value) ||
|
|
783
|
+
t__namespace.isIdentifier(value)) {
|
|
784
|
+
if (t__namespace.isExpression(value)) {
|
|
785
|
+
return t__namespace.objectProperty(t__namespace.identifier(name), value);
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
else {
|
|
792
|
+
fail('MJX010', `Lifecycle hook "${name}" must be a function, an object, or a reference to one.`, prop);
|
|
793
|
+
return null;
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
const SUPPORTED_DIRECTIVES = ['wait', 'display', 'model', 'text', 'html', 'value', 'watch'];
|
|
797
|
+
const UNSUPPORTED_DIRECTIVES = new Set(['reload', 'bind', 'effect', 'focus', 'interrupt', 'to', 'list', 'loop']);
|
|
798
|
+
const directiveNames = new Set(SUPPORTED_DIRECTIVES);
|
|
799
|
+
function supportedDirectivesText() {
|
|
800
|
+
return [...SUPPORTED_DIRECTIVES, 'style', 'ref', 'key'].map(d => 'x-' + d).join(', ') + ' and the lifecycle hooks (x-mounted, x-built, x-disposed, …)';
|
|
801
|
+
}
|
|
802
|
+
const ParentIfStatement = (path, state) => {
|
|
803
|
+
if (t__namespace.isExpression(path)) {
|
|
804
|
+
state.push(path);
|
|
805
|
+
}
|
|
806
|
+
if (t__namespace.isFunctionExpression(path)) {
|
|
807
|
+
state = ParentIfStatement(path.body, state);
|
|
808
|
+
}
|
|
809
|
+
else if (t__namespace.isArrowFunctionExpression(path)) {
|
|
810
|
+
state = ParentIfStatement(path.body, state);
|
|
811
|
+
}
|
|
812
|
+
else if (t__namespace.isObjectExpression(path)) ;
|
|
813
|
+
else if (t__namespace.isMemberExpression(path)) {
|
|
814
|
+
state = ParentIfStatement(path.object, state);
|
|
815
|
+
}
|
|
816
|
+
else if (t__namespace.isObjectMethod(path)) ;
|
|
817
|
+
else if (t__namespace.isIdentifier(path)) ;
|
|
818
|
+
else if (t__namespace.isCallExpression(path)) {
|
|
819
|
+
if (t__namespace.isExpression(path.callee)) {
|
|
820
|
+
state = ParentIfStatement(path.callee, state);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
else ;
|
|
824
|
+
return state;
|
|
825
|
+
};
|
|
826
|
+
const returnIfStatement = (value, enableDefaultreturn = true, defaultLiteral = t__namespace.booleanLiteral(false)) => {
|
|
827
|
+
var ifStatement = findIfStatements(value);
|
|
828
|
+
var mx = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', value), t__namespace.stringLiteral('function'));
|
|
829
|
+
var rtrn;
|
|
830
|
+
if (t__namespace.isLogicalExpression(value)) {
|
|
831
|
+
rtrn = t__namespace.returnStatement(value);
|
|
832
|
+
if (enableDefaultreturn) {
|
|
833
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrn, t__namespace.returnStatement(defaultLiteral)]));
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrn]));
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
else if (t__namespace.isMemberExpression(value) || t__namespace.isIdentifier(value)) {
|
|
840
|
+
rtrn = t__namespace.returnStatement(value);
|
|
841
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
842
|
+
if (enableDefaultreturn) {
|
|
843
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns, t__namespace.returnStatement(defaultLiteral)]));
|
|
844
|
+
}
|
|
845
|
+
else {
|
|
846
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
else if (t__namespace.isFunctionExpression(value)) {
|
|
850
|
+
rtrn = t__namespace.returnStatement(value);
|
|
851
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
852
|
+
if (enableDefaultreturn) {
|
|
853
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns, t__namespace.returnStatement(defaultLiteral)]));
|
|
854
|
+
}
|
|
855
|
+
else {
|
|
856
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
else if (t__namespace.isBinaryExpression(value)) {
|
|
860
|
+
var ifStatementA = findIfStatements(value.left);
|
|
861
|
+
var ifStatementB = findIfStatements(value.right);
|
|
862
|
+
var le = t__namespace.logicalExpression('&&', ifStatementA, ifStatementB);
|
|
863
|
+
rtrn = t__namespace.returnStatement(value);
|
|
864
|
+
if (enableDefaultreturn) {
|
|
865
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.ifStatement(le, t__namespace.blockStatement([rtrn])), t__namespace.returnStatement(defaultLiteral)]));
|
|
866
|
+
}
|
|
867
|
+
else {
|
|
868
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.ifStatement(le, t__namespace.blockStatement([rtrn]))]));
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
else if (t__namespace.isCallExpression(value)) {
|
|
872
|
+
rtrn = t__namespace.returnStatement(t__namespace.conditionalExpression(mx, t__namespace.callExpression(value, []), value));
|
|
873
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
874
|
+
if (enableDefaultreturn) {
|
|
875
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns, t__namespace.returnStatement(defaultLiteral)]));
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
878
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
return value;
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
const findIfStatements = (value) => {
|
|
886
|
+
var ifs = [];
|
|
887
|
+
if (t__namespace.isExpression(value)) {
|
|
888
|
+
ifs = ParentIfStatement(value, ifs);
|
|
889
|
+
}
|
|
890
|
+
if (ifs.length == 1) {
|
|
891
|
+
ifs[0] = t__namespace.logicalExpression('&&', t__namespace.binaryExpression('!==', ifs[0], t__namespace.nullLiteral()), t__namespace.binaryExpression('!==', ifs[0], t__namespace.identifier('undefined')));
|
|
892
|
+
}
|
|
893
|
+
const setRight = (l, x, current) => {
|
|
894
|
+
if (t__namespace.isLogicalExpression(l) && t__namespace.isNullLiteral(l.right)) {
|
|
895
|
+
l.right = x;
|
|
896
|
+
}
|
|
897
|
+
else {
|
|
898
|
+
if (t__namespace.isLogicalExpression(l)) {
|
|
899
|
+
setRight(l.right, x);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
ifs.reverse();
|
|
904
|
+
var ifStatement = null;
|
|
905
|
+
if (ifs.length > 1) {
|
|
906
|
+
ifs.forEach((ttt, index) => {
|
|
907
|
+
if (!t__namespace.isArrowFunctionExpression(ttt) || !t__namespace.isFunctionExpression(ttt)) {
|
|
908
|
+
if (ifStatement) {
|
|
909
|
+
setRight(ifStatement, t__namespace.logicalExpression('&&', ttt, t__namespace.nullLiteral()));
|
|
910
|
+
}
|
|
911
|
+
else {
|
|
912
|
+
ifStatement = t__namespace.logicalExpression('&&', ttt, t__namespace.nullLiteral());
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
else {
|
|
916
|
+
ifStatement = ttt;
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
ifStatement = ifs[0];
|
|
922
|
+
}
|
|
923
|
+
const latestRightFind = (x, p) => {
|
|
924
|
+
if (t__namespace.isLogicalExpression(x)) {
|
|
925
|
+
if (t__namespace.isNullLiteral(x.right)) {
|
|
926
|
+
if (p === null) {
|
|
927
|
+
x.right = x.left;
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
930
|
+
p.right = t__namespace.logicalExpression('&&', t__namespace.binaryExpression('!==', x.left, t__namespace.nullLiteral()), t__namespace.binaryExpression('!==', x.left, t__namespace.identifier('undefined')));
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
else {
|
|
934
|
+
latestRightFind(x.right, x);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
if (ifStatement && t__namespace.isLogicalExpression(ifStatement)) {
|
|
939
|
+
latestRightFind(ifStatement, null);
|
|
940
|
+
if (t__namespace.isArrowFunctionExpression(ifStatement.right)) {
|
|
941
|
+
{
|
|
942
|
+
ifStatement = ifStatement.left;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return ifStatement;
|
|
947
|
+
};
|
|
948
|
+
const makeDirectives = (prop, name, value, path, state) => {
|
|
949
|
+
var result = null;
|
|
950
|
+
if (value != null) {
|
|
951
|
+
var clearedName = name.toLowerCase().replace("x:", "").replace("x-", "").replace("on:", "");
|
|
952
|
+
var callerName = `sender.bindings.${clearedName}`;
|
|
953
|
+
if (directiveNames.has(clearedName)) {
|
|
954
|
+
if (clearedName !== 'wait') {
|
|
955
|
+
findIfStatements(value);
|
|
956
|
+
if (t__namespace.isFunctionExpression(value) ||
|
|
957
|
+
t__namespace.isArrowFunctionExpression(value) && value !== null ||
|
|
958
|
+
t__namespace.isObjectExpression(value) ||
|
|
959
|
+
t__namespace.isMemberExpression(value) ||
|
|
960
|
+
t__namespace.isObjectMethod(value) ||
|
|
961
|
+
t__namespace.isIdentifier(value) ||
|
|
962
|
+
t__namespace.isCallExpression(value) && value !== null) {
|
|
963
|
+
if (t__namespace.isFunctionExpression(value)) {
|
|
964
|
+
result = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier(callerName), [value]));
|
|
965
|
+
}
|
|
966
|
+
else if (t__namespace.isArrowFunctionExpression(value)) {
|
|
967
|
+
var el;
|
|
968
|
+
if (t__namespace.isBlockStatement(value.body)) {
|
|
969
|
+
var kx = t__namespace.functionExpression(null, [], value.body);
|
|
970
|
+
el = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier(callerName), [kx]));
|
|
971
|
+
}
|
|
972
|
+
else {
|
|
973
|
+
if (t__namespace.isStringLiteral(value.body)) {
|
|
974
|
+
var rtrn = t__namespace.returnStatement(value.body);
|
|
975
|
+
var kx = t__namespace.functionExpression(null, [], t__namespace.blockStatement([rtrn]));
|
|
976
|
+
el = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier(callerName), [kx]));
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
el = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier(callerName), [returnIfStatement(value, false)]));
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
result = el;
|
|
983
|
+
}
|
|
984
|
+
else {
|
|
985
|
+
if (t__namespace.isExpression(value)) {
|
|
986
|
+
result = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier(callerName), [returnIfStatement(value, false)]));
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
else if (t__namespace.isBinaryExpression(value)) {
|
|
991
|
+
result = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier(callerName), [returnIfStatement(value, false, t__namespace.booleanLiteral(false))]));
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
fail('MJX011', `Directive "${name}" does not accept this value; pass a function, an object, or a reference to one.`, prop);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
if (result && clearedName === 'model') {
|
|
999
|
+
const setter = buildModelSetter(value, path);
|
|
1000
|
+
if (setter)
|
|
1001
|
+
result.expression.arguments.push(setter);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
return result;
|
|
1005
|
+
};
|
|
1006
|
+
function unwrapTypeWrappers(node) {
|
|
1007
|
+
let current = node;
|
|
1008
|
+
while (current && (t__namespace.isTSNonNullExpression(current) ||
|
|
1009
|
+
t__namespace.isTSAsExpression(current) ||
|
|
1010
|
+
t__namespace.isTSSatisfiesExpression(current) ||
|
|
1011
|
+
t__namespace.isTSTypeAssertion(current) ||
|
|
1012
|
+
t__namespace.isTypeCastExpression(current) ||
|
|
1013
|
+
t__namespace.isParenthesizedExpression(current))) {
|
|
1014
|
+
current = current.expression;
|
|
1015
|
+
}
|
|
1016
|
+
return current;
|
|
1017
|
+
}
|
|
1018
|
+
function modelTargetOf(value) {
|
|
1019
|
+
let expression = value;
|
|
1020
|
+
if (t__namespace.isArrowFunctionExpression(value)) {
|
|
1021
|
+
if (value.params.length > 0 || value.async)
|
|
1022
|
+
return null;
|
|
1023
|
+
if (t__namespace.isBlockStatement(value.body)) {
|
|
1024
|
+
const statements = value.body.body;
|
|
1025
|
+
if (statements.length !== 1 || !t__namespace.isReturnStatement(statements[0]))
|
|
1026
|
+
return null;
|
|
1027
|
+
expression = statements[0].argument;
|
|
1028
|
+
}
|
|
1029
|
+
else {
|
|
1030
|
+
expression = value.body;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
expression = unwrapTypeWrappers(expression);
|
|
1034
|
+
if (!expression)
|
|
1035
|
+
return null;
|
|
1036
|
+
if (!t__namespace.isMemberExpression(expression) && !t__namespace.isOptionalMemberExpression(expression))
|
|
1037
|
+
return null;
|
|
1038
|
+
if (t__namespace.isPrivateName(expression.property) || t__namespace.isSuper(expression.object))
|
|
1039
|
+
return null;
|
|
1040
|
+
return expression;
|
|
1041
|
+
}
|
|
1042
|
+
function buildModelSetter(value, path) {
|
|
1043
|
+
const target = modelTargetOf(value);
|
|
1044
|
+
if (!target)
|
|
1045
|
+
return null;
|
|
1046
|
+
const valueId = path.scope.generateUidIdentifier('value');
|
|
1047
|
+
const ownerId = path.scope.generateUidIdentifier('owner');
|
|
1048
|
+
const owner = t__namespace.cloneNode(target.object, true);
|
|
1049
|
+
const member = () => t__namespace.memberExpression(t__namespace.cloneNode(ownerId), t__namespace.cloneNode(target.property, true), target.computed);
|
|
1050
|
+
const ownerMissing = t__namespace.logicalExpression('||', t__namespace.binaryExpression('===', t__namespace.cloneNode(ownerId), t__namespace.nullLiteral()), t__namespace.binaryExpression('===', t__namespace.cloneNode(ownerId), t__namespace.identifier('undefined')));
|
|
1051
|
+
const holdsGetter = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', member()), t__namespace.stringLiteral('function'));
|
|
1052
|
+
return t__namespace.arrowFunctionExpression([valueId], t__namespace.blockStatement([
|
|
1053
|
+
t__namespace.variableDeclaration('const', [t__namespace.variableDeclarator(ownerId, owner)]),
|
|
1054
|
+
t__namespace.ifStatement(t__namespace.logicalExpression('||', ownerMissing, holdsGetter), t__namespace.returnStatement()),
|
|
1055
|
+
t__namespace.expressionStatement(t__namespace.assignmentExpression('=', member(), t__namespace.cloneNode(valueId)))
|
|
1056
|
+
]));
|
|
1057
|
+
}
|
|
1058
|
+
const makePreDirectives = (prop, name, value, path) => {
|
|
1059
|
+
var result = null;
|
|
1060
|
+
if (value != null) {
|
|
1061
|
+
var clearedName = name.toLowerCase().replace("x:", "").replace("x-", "").replace("on:", "");
|
|
1062
|
+
var callerName = `sender.bindings.${clearedName}`;
|
|
1063
|
+
if (clearedName === 'wait' || clearedName === 'display') {
|
|
1064
|
+
if (t__namespace.isObjectExpression(value)) {
|
|
1065
|
+
fail('MJX012', `Directive "${name}" does not accept an object literal.`, prop);
|
|
1066
|
+
}
|
|
1067
|
+
else if (t__namespace.isExpression(value)) {
|
|
1068
|
+
result = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier(callerName), [returnIfStatement(value, true, t__namespace.booleanLiteral(true))]));
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
else {
|
|
1072
|
+
fail('MJX006', `Directive "${name}" is not supported. Supported: ${supportedDirectivesText()}.`, prop);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
return result;
|
|
1076
|
+
};
|
|
1077
|
+
|
|
1078
|
+
// CJS/ESM ikili paketlemede `default` bazen sarmalanır; iki biçimi de kabul et.
|
|
1079
|
+
const generate = (generatorNs__namespace.default?.default ?? generatorNs__namespace.default ?? generatorNs__namespace);
|
|
1080
|
+
let active = null;
|
|
1081
|
+
/** Üretilmiş düğüm → kaynak konumu. getChildren'da not edilir, emisyon noktasında okunur. */
|
|
1082
|
+
const origins = new WeakMap();
|
|
1083
|
+
function beginExplain() {
|
|
1084
|
+
active = [];
|
|
1085
|
+
}
|
|
1086
|
+
function endExplain() {
|
|
1087
|
+
const out = active ?? [];
|
|
1088
|
+
active = null;
|
|
1089
|
+
const key = (e) => (e.line ?? 1e9) * 10000 + (e.column ?? 0);
|
|
1090
|
+
return out.map((e, i) => ({ e, i })).sort((a, b) => key(a.e) - key(b.e) || a.i - b.i).map(x => x.e);
|
|
1091
|
+
}
|
|
1092
|
+
function isExplaining() {
|
|
1093
|
+
return active !== null;
|
|
1094
|
+
}
|
|
1095
|
+
const MAX_SOURCE = 90;
|
|
1096
|
+
const MAX_LOWERED = 220;
|
|
1097
|
+
function oneLine(s, max) {
|
|
1098
|
+
const flat = s.replace(/\s+/g, ' ').trim();
|
|
1099
|
+
return flat.length > max ? flat.slice(0, max - 1) + '…' : flat;
|
|
1100
|
+
}
|
|
1101
|
+
/** Kaynak parçayı orijinal koddan alır (`{…}` süslüleri dahil). JSX elemanında yalnızca açılış etiketi. */
|
|
1102
|
+
function sourceOf(path, originalCode) {
|
|
1103
|
+
let n = path?.node;
|
|
1104
|
+
if (n && t__namespace.isJSXElement(n))
|
|
1105
|
+
n = n.openingElement;
|
|
1106
|
+
if (!n || typeof n.start !== 'number' || typeof n.end !== 'number' || !originalCode)
|
|
1107
|
+
return '';
|
|
1108
|
+
return oneLine(originalCode.slice(n.start, n.end), MAX_SOURCE);
|
|
1109
|
+
}
|
|
1110
|
+
/** Konumu ve kaynak parçayı ANINDA alır (yol daha sonra değişebilir). */
|
|
1111
|
+
function captureOrigin(path, originalCode) {
|
|
1112
|
+
return {
|
|
1113
|
+
line: path.node?.loc?.start?.line ?? null,
|
|
1114
|
+
column: path.node?.loc?.start?.column ?? null,
|
|
1115
|
+
source: sourceOf(path, originalCode),
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
/** Üretilmiş bir düğümü tek satır koda çevirir. Yalnızca gösterim içindir. */
|
|
1119
|
+
function codeOf(node) {
|
|
1120
|
+
if (!node)
|
|
1121
|
+
return '';
|
|
1122
|
+
try {
|
|
1123
|
+
const out = generate(node, { concise: true, comments: false }).code;
|
|
1124
|
+
return oneLine(out.replace(/;$/, ''), MAX_LOWERED);
|
|
1125
|
+
}
|
|
1126
|
+
catch {
|
|
1127
|
+
return `<${node.type}>`;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
function noteOrigin(node, path, originalCode) {
|
|
1131
|
+
if (!active || !node || typeof node !== 'object')
|
|
1132
|
+
return;
|
|
1133
|
+
if (origins.has(node))
|
|
1134
|
+
return;
|
|
1135
|
+
origins.set(node, captureOrigin(path, originalCode));
|
|
1136
|
+
}
|
|
1137
|
+
/** Konumu önceden alınmış düğüm için (derleyicinin JSXElement exit'i). */
|
|
1138
|
+
function noteOriginRaw(node, origin) {
|
|
1139
|
+
if (!active || !node || typeof node !== 'object')
|
|
1140
|
+
return;
|
|
1141
|
+
if (origins.has(node))
|
|
1142
|
+
return;
|
|
1143
|
+
origins.set(node, origin);
|
|
1144
|
+
}
|
|
1145
|
+
/** `sender.repeater` → `_mc({initializeComponent: list})` gibi yeniden sarmalarda kaynağı taşır. */
|
|
1146
|
+
function transferOrigin(from, to) {
|
|
1147
|
+
if (!active || !from || !to || typeof from !== 'object' || typeof to !== 'object')
|
|
1148
|
+
return;
|
|
1149
|
+
const o = origins.get(from);
|
|
1150
|
+
if (o)
|
|
1151
|
+
origins.set(to, o);
|
|
1152
|
+
}
|
|
1153
|
+
/** Konumu doğrudan bilinen kayıt (öznitelikler). */
|
|
1154
|
+
function explainAt(path, filename, originalCode, e) {
|
|
1155
|
+
if (!active)
|
|
1156
|
+
return;
|
|
1157
|
+
active.push({
|
|
1158
|
+
file: filename,
|
|
1159
|
+
line: path?.node?.loc?.start?.line ?? null,
|
|
1160
|
+
column: path?.node?.loc?.start?.column ?? null,
|
|
1161
|
+
site: e.site,
|
|
1162
|
+
shape: e.shape,
|
|
1163
|
+
source: sourceOf(path, originalCode),
|
|
1164
|
+
lowered: typeof e.lowered === 'string' ? oneLine(e.lowered, MAX_LOWERED) : codeOf(e.lowered),
|
|
1165
|
+
reactive: e.reactive,
|
|
1166
|
+
deps: e.deps,
|
|
1167
|
+
note: e.note,
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
/** Konumu `noteOrigin` ile kaydedilmiş bir çocuk düğüm için kayıt (emisyon noktası). */
|
|
1171
|
+
function explainChild(produced, filename, e) {
|
|
1172
|
+
if (!active || !produced || typeof produced !== 'object')
|
|
1173
|
+
return;
|
|
1174
|
+
const o = origins.get(produced);
|
|
1175
|
+
if (!o)
|
|
1176
|
+
return;
|
|
1177
|
+
active.push({
|
|
1178
|
+
file: filename,
|
|
1179
|
+
line: o.line,
|
|
1180
|
+
column: o.column,
|
|
1181
|
+
site: e.site,
|
|
1182
|
+
shape: e.shape,
|
|
1183
|
+
source: o.source,
|
|
1184
|
+
lowered: typeof e.lowered === 'string' ? oneLine(e.lowered, MAX_LOWERED) : codeOf(e.lowered),
|
|
1185
|
+
reactive: e.reactive,
|
|
1186
|
+
deps: e.deps,
|
|
1187
|
+
note: e.note,
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
const DEPS = {
|
|
1191
|
+
none: 'none — no binding is created',
|
|
1192
|
+
once: 'none — evaluated once during setup, then frozen',
|
|
1193
|
+
getter: 'ALL reactive fields read inside the getter; collected again on every run',
|
|
1194
|
+
field: (obj, prop) => `${obj}.${prop} — this field only (exact)`,
|
|
1195
|
+
cond: 'fields read in the condition getter; bindings inside a branch are the branch\'s own effects, and the branch is rebuilt on every switch',
|
|
1196
|
+
list: 'the array source (length + item identity/key); bindings inside an item are the item\'s own effects',
|
|
1197
|
+
receiver: 'wherever the receiving component reads the getter; nowhere if it does not',
|
|
1198
|
+
runtime: 'if the value is a function, the fields read inside it; otherwise none (once)',
|
|
1199
|
+
model: 'model field ↔ DOM value, two-way',
|
|
1200
|
+
modelOneWay: 'ALL reactive fields read inside the getter; the expression is not assignable, so the DOM value is not written back (one-way)',
|
|
1201
|
+
};
|
|
1202
|
+
function describeTextNode(node) {
|
|
1203
|
+
if (!t__namespace.isCallExpression(node))
|
|
1204
|
+
return null;
|
|
1205
|
+
const args = node.arguments;
|
|
1206
|
+
if (args.length < 2 || !t__namespace.isStringLiteral(args[0]) || args[0].value !== 'text' || !t__namespace.isObjectExpression(args[1]))
|
|
1207
|
+
return null;
|
|
1208
|
+
const init = args[1].properties.find(p => t__namespace.isObjectProperty(p) && t__namespace.isIdentifier(p.key) && p.key.name === 'initializeComponent');
|
|
1209
|
+
if (!init || !t__namespace.isArrowFunctionExpression(init.value) || !t__namespace.isBlockStatement(init.value.body))
|
|
1210
|
+
return null;
|
|
1211
|
+
const stmt = init.value.body.body[0];
|
|
1212
|
+
if (!stmt || !t__namespace.isExpressionStatement(stmt) || !t__namespace.isCallExpression(stmt.expression))
|
|
1213
|
+
return null;
|
|
1214
|
+
const call = stmt.expression;
|
|
1215
|
+
const callee = t__namespace.isIdentifier(call.callee) ? call.callee.name : codeOf(call.callee);
|
|
1216
|
+
const lowered = codeOf(call);
|
|
1217
|
+
if (callee === 'sender.setText') {
|
|
1218
|
+
return { lowered, shape: 'text.static', reactive: 'static', deps: DEPS.none };
|
|
1219
|
+
}
|
|
1220
|
+
if (callee === 'sender.bindings.add') {
|
|
1221
|
+
if (call.arguments.length === 3 && t__namespace.isStringLiteral(call.arguments[2])) {
|
|
1222
|
+
return {
|
|
1223
|
+
lowered, shape: 'text.field', reactive: 'live',
|
|
1224
|
+
deps: DEPS.field(codeOf(call.arguments[1]), call.arguments[2].value),
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
const probe = args[1].properties.some(p => t__namespace.isObjectProperty(p) && t__namespace.isIdentifier(p.key) && p.key.name === '__childExpr');
|
|
1228
|
+
return {
|
|
1229
|
+
lowered, shape: 'text.getter', reactive: 'live', deps: DEPS.getter,
|
|
1230
|
+
note: probe ? 'if the variable holds a component (or an array of components), it is placed with controls.add instead of as text (__childExpr probe, untracked)' : undefined,
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
if (callee === 'sender.bindings.when') {
|
|
1234
|
+
return { lowered, shape: 'when', reactive: 'live', deps: DEPS.cond };
|
|
1235
|
+
}
|
|
1236
|
+
return { lowered, shape: 'text', reactive: 'live', deps: DEPS.getter };
|
|
1237
|
+
}
|
|
1238
|
+
const REACTIVE_LABEL = {
|
|
1239
|
+
live: 'LIVE', static: 'STATIC', once: 'ONCE', receiver: 'RECEIVER', runtime: 'RUNTIME', 'n/a': '—',
|
|
1240
|
+
};
|
|
1241
|
+
function formatExplanations(list) {
|
|
1242
|
+
if (list.length === 0)
|
|
1243
|
+
return '';
|
|
1244
|
+
const byFile = new Map();
|
|
1245
|
+
for (const e of list) {
|
|
1246
|
+
const arr = byFile.get(e.file) ?? [];
|
|
1247
|
+
arr.push(e);
|
|
1248
|
+
byFile.set(e.file, arr);
|
|
1249
|
+
}
|
|
1250
|
+
const out = [];
|
|
1251
|
+
for (const [file, items] of byFile) {
|
|
1252
|
+
out.push(`[motifjs explain] ${file} — ${items.length} expressions`);
|
|
1253
|
+
for (const e of items) {
|
|
1254
|
+
const where = e.line === null ? '?' : `${e.line}:${(e.column ?? 0) + 1}`;
|
|
1255
|
+
out.push(` ${where.padEnd(8)} ${(e.site + '/' + e.shape).padEnd(24)} ${e.source}`);
|
|
1256
|
+
out.push(` => ${e.lowered}`);
|
|
1257
|
+
out.push(` ${REACTIVE_LABEL[e.reactive]} · deps: ${e.deps}`);
|
|
1258
|
+
if (e.note)
|
|
1259
|
+
out.push(` note: ${e.note}`);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
return out.join('\n');
|
|
1263
|
+
}
|
|
1264
|
+
function printExplanations(list) {
|
|
1265
|
+
const text = formatExplanations(list);
|
|
1266
|
+
if (text)
|
|
1267
|
+
console.info(text);
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
const FRAGMENT = 'Fragment';
|
|
1271
|
+
const isFunctionNode = (n) => !!n && (t__namespace.isArrowFunctionExpression(n) || t__namespace.isFunctionExpression(n));
|
|
1272
|
+
const isPlainValueNode = (n) => !n || t__namespace.isLiteral(n) || t__namespace.isObjectExpression(n) || t__namespace.isArrayExpression(n) || t__namespace.isNewExpression(n) || t__namespace.isClassExpression(n);
|
|
1273
|
+
function enclosingClassOfThis(path) {
|
|
1274
|
+
let cur = path.parentPath;
|
|
1275
|
+
while (cur) {
|
|
1276
|
+
if (cur.isClassDeclaration() || cur.isClassExpression())
|
|
1277
|
+
return cur;
|
|
1278
|
+
if (cur.isFunctionDeclaration() || cur.isFunctionExpression() || cur.isObjectMethod())
|
|
1279
|
+
return null;
|
|
1280
|
+
cur = cur.parentPath;
|
|
1281
|
+
}
|
|
1282
|
+
return null;
|
|
1283
|
+
}
|
|
1284
|
+
const classMemberKinds = new WeakMap();
|
|
1285
|
+
function memberKindsOf(cls) {
|
|
1286
|
+
const kinds = new Map();
|
|
1287
|
+
for (const m of cls.body.body) {
|
|
1288
|
+
if (!t__namespace.isClassMethod(m) && !t__namespace.isClassProperty(m))
|
|
1289
|
+
continue;
|
|
1290
|
+
if (m.computed)
|
|
1291
|
+
continue;
|
|
1292
|
+
const key = t__namespace.isIdentifier(m.key) ? m.key.name : t__namespace.isStringLiteral(m.key) ? m.key.value : null;
|
|
1293
|
+
if (key === null || key === 'constructor' || kinds.has(key))
|
|
1294
|
+
continue;
|
|
1295
|
+
if (t__namespace.isClassMethod(m)) {
|
|
1296
|
+
kinds.set(key, m.kind === 'method' ? 'call' : 'runtime');
|
|
1297
|
+
continue;
|
|
1298
|
+
}
|
|
1299
|
+
const ann = t__namespace.isTSTypeAnnotation(m.typeAnnotation) ? m.typeAnnotation.typeAnnotation : null;
|
|
1300
|
+
if (isFunctionNode(m.value))
|
|
1301
|
+
kinds.set(key, 'call');
|
|
1302
|
+
else if (ann && t__namespace.isTSFunctionType(ann))
|
|
1303
|
+
kinds.set(key, 'runtime');
|
|
1304
|
+
else
|
|
1305
|
+
kinds.set(key, isPlainValueNode(m.value) ? 'assign' : 'runtime');
|
|
1306
|
+
}
|
|
1307
|
+
return kinds;
|
|
1308
|
+
}
|
|
1309
|
+
function recordClassMembers(program) {
|
|
1310
|
+
program.traverse({
|
|
1311
|
+
Class(path) {
|
|
1312
|
+
classMemberKinds.set(path.node, memberKindsOf(path.node));
|
|
1313
|
+
}
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
function classMemberKind(cls, name) {
|
|
1317
|
+
const kinds = classMemberKinds.get(cls.node) ?? memberKindsOf(cls.node);
|
|
1318
|
+
return kinds.get(name) ?? 'runtime';
|
|
1319
|
+
}
|
|
1320
|
+
function refTargetKind(prop, value) {
|
|
1321
|
+
if (t__namespace.isMemberExpression(value) && t__namespace.isThisExpression(value.object) && !value.computed && t__namespace.isIdentifier(value.property)) {
|
|
1322
|
+
const cls = enclosingClassOfThis(prop);
|
|
1323
|
+
return cls ? classMemberKind(cls, value.property.name) : 'runtime';
|
|
1324
|
+
}
|
|
1325
|
+
if (t__namespace.isIdentifier(value)) {
|
|
1326
|
+
const binding = prop.scope.getBinding(value.name);
|
|
1327
|
+
if (!binding)
|
|
1328
|
+
return 'runtime';
|
|
1329
|
+
const node = binding.path.node;
|
|
1330
|
+
if (t__namespace.isFunctionDeclaration(node))
|
|
1331
|
+
return 'call';
|
|
1332
|
+
if (t__namespace.isVariableDeclarator(node)) {
|
|
1333
|
+
if (!node.init)
|
|
1334
|
+
return 'assign';
|
|
1335
|
+
if (isFunctionNode(node.init) && binding.constant)
|
|
1336
|
+
return 'call';
|
|
1337
|
+
}
|
|
1338
|
+
return 'runtime';
|
|
1339
|
+
}
|
|
1340
|
+
return 'runtime';
|
|
1341
|
+
}
|
|
1342
|
+
const componentEvents = new Set(['oncreating', 'onconfig', 'oncreated', 'onbuilding', 'onbuilt', 'ondisposing', 'ondisposed', "oninitializecomponent"]);
|
|
1343
|
+
function isComponentEvent(name) {
|
|
1344
|
+
return componentEvents.has(name);
|
|
1345
|
+
}
|
|
1346
|
+
function isContextHandler(name) {
|
|
1347
|
+
return name.toLowerCase().startsWith("on-") || name.toLowerCase().startsWith("on:") || name.toLowerCase().startsWith("on_");
|
|
1348
|
+
}
|
|
1349
|
+
function isDirective(name) {
|
|
1350
|
+
return name.toLowerCase().startsWith("x-") || name.toLowerCase().startsWith("x:");
|
|
1351
|
+
}
|
|
1352
|
+
const LIFECYCLE_HOOKS = new Set(['built', 'building', 'mounted', 'config', 'configured', 'initializing', 'initialized', 'disposing', 'disposed', 'visibilitychanged', 'activated', 'deactivated']);
|
|
1353
|
+
function lifecycleHookOf(name) {
|
|
1354
|
+
const lower = name.toLowerCase();
|
|
1355
|
+
let hook = null;
|
|
1356
|
+
if (lower.startsWith('x-') || lower.startsWith('x:'))
|
|
1357
|
+
hook = lower.slice(2);
|
|
1358
|
+
else if (lower.startsWith('on'))
|
|
1359
|
+
hook = lower.slice(2);
|
|
1360
|
+
return hook !== null && LIFECYCLE_HOOKS.has(hook) ? hook : null;
|
|
1361
|
+
}
|
|
1362
|
+
/** `.some/.every/.find/...` gibi KISA DEVRE yapan dizi yüklemleri (MJX004). */
|
|
1363
|
+
const SHORT_CIRCUIT_ARRAY_METHODS = new Set(['some', 'every', 'find', 'findindex', 'findlast', 'findlastindex']);
|
|
1364
|
+
/** Bir üye zincirinin kökü `this` mi? (`this.state.rows.some(...)` → evet) */
|
|
1365
|
+
function isThisRooted(node) {
|
|
1366
|
+
let cur = node;
|
|
1367
|
+
while (cur) {
|
|
1368
|
+
if (t__namespace.isThisExpression(cur))
|
|
1369
|
+
return true;
|
|
1370
|
+
if (t__namespace.isMemberExpression(cur)) {
|
|
1371
|
+
cur = cur.object;
|
|
1372
|
+
continue;
|
|
1373
|
+
}
|
|
1374
|
+
if (t__namespace.isCallExpression(cur)) {
|
|
1375
|
+
cur = cur.callee;
|
|
1376
|
+
continue;
|
|
1377
|
+
}
|
|
1378
|
+
return false;
|
|
1379
|
+
}
|
|
1380
|
+
return false;
|
|
1381
|
+
}
|
|
1382
|
+
function findShortCircuitPredicate(node) {
|
|
1383
|
+
let found = null;
|
|
1384
|
+
const visit = (n) => {
|
|
1385
|
+
if (found !== null || n === null || typeof n !== 'object')
|
|
1386
|
+
return;
|
|
1387
|
+
if (t__namespace.isCallExpression(n) && t__namespace.isMemberExpression(n.callee) && t__namespace.isIdentifier(n.callee.property)) {
|
|
1388
|
+
if (SHORT_CIRCUIT_ARRAY_METHODS.has(n.callee.property.name.toLowerCase()) && isThisRooted(n.callee.object)) {
|
|
1389
|
+
found = n.callee.property.name;
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
for (const key of Object.keys(n)) {
|
|
1394
|
+
if (key === 'loc' || key === 'leadingComments' || key === 'trailingComments')
|
|
1395
|
+
continue;
|
|
1396
|
+
const v = n[key];
|
|
1397
|
+
if (Array.isArray(v)) {
|
|
1398
|
+
v.forEach(visit);
|
|
1399
|
+
}
|
|
1400
|
+
else if (v && typeof v === 'object' && typeof v.type === 'string') {
|
|
1401
|
+
visit(v);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
};
|
|
1405
|
+
visit(node);
|
|
1406
|
+
return found;
|
|
1407
|
+
}
|
|
1408
|
+
function missingListKey(mapper) {
|
|
1409
|
+
if (!mapper)
|
|
1410
|
+
return false;
|
|
1411
|
+
if (!t__namespace.isArrowFunctionExpression(mapper) && !t__namespace.isFunctionExpression(mapper))
|
|
1412
|
+
return false;
|
|
1413
|
+
let body = mapper.body;
|
|
1414
|
+
if (t__namespace.isBlockStatement(body)) {
|
|
1415
|
+
const ret = body.body.find(st => t__namespace.isReturnStatement(st));
|
|
1416
|
+
body = ret?.argument;
|
|
1417
|
+
}
|
|
1418
|
+
while (body && t__namespace.isParenthesizedExpression(body))
|
|
1419
|
+
body = body.expression;
|
|
1420
|
+
if (!body || !t__namespace.isCallExpression(body))
|
|
1421
|
+
return false;
|
|
1422
|
+
if (!t__namespace.isIdentifier(body.callee) || body.callee.name !== motifComponent())
|
|
1423
|
+
return false;
|
|
1424
|
+
const propsArg = body.arguments.length > 1 ? body.arguments[1] : body.arguments[0];
|
|
1425
|
+
if (!propsArg || !t__namespace.isObjectExpression(propsArg))
|
|
1426
|
+
return false;
|
|
1427
|
+
if (propsArg.properties.some(p => t__namespace.isSpreadElement(p)))
|
|
1428
|
+
return false;
|
|
1429
|
+
const hasKey = propsArg.properties.some(p => {
|
|
1430
|
+
if (!t__namespace.isObjectProperty(p))
|
|
1431
|
+
return false;
|
|
1432
|
+
const n = t__namespace.isIdentifier(p.key) ? p.key.name : (t__namespace.isStringLiteral(p.key) ? p.key.value : '');
|
|
1433
|
+
return n === 'indexkey' || n === 'key';
|
|
1434
|
+
});
|
|
1435
|
+
return !hasKey;
|
|
1436
|
+
}
|
|
1437
|
+
function startAttr(v) {
|
|
1438
|
+
if (v.includes("-")) {
|
|
1439
|
+
return true;
|
|
1440
|
+
}
|
|
1441
|
+
return false;
|
|
1442
|
+
}
|
|
1443
|
+
function getAttributeName(attribute) {
|
|
1444
|
+
const label = attribute.node.name;
|
|
1445
|
+
return t__namespace.isJSXNamespacedName(label) ? label.namespace.name + ':' + label.name.name : label.name;
|
|
1446
|
+
}
|
|
1447
|
+
function getAttributeValue(attribute, state) {
|
|
1448
|
+
const slot = attribute.get('value');
|
|
1449
|
+
switch (slot.node?.type) {
|
|
1450
|
+
case 'JSXElement':
|
|
1451
|
+
return ParseComponent(slot, state);
|
|
1452
|
+
case 'StringLiteral':
|
|
1453
|
+
return slot.node;
|
|
1454
|
+
case 'JSXExpressionContainer':
|
|
1455
|
+
return transformJSXExpressionContainer(slot);
|
|
1456
|
+
default:
|
|
1457
|
+
return null;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
function collapseJsxWhitespace(raw) {
|
|
1461
|
+
const rows = raw.split(/\r\n|\n|\r/);
|
|
1462
|
+
const lastRow = rows.length - 1;
|
|
1463
|
+
const kept = [];
|
|
1464
|
+
rows.forEach((row, index) => {
|
|
1465
|
+
let text = row.replace(/\t/g, ' ');
|
|
1466
|
+
if (index > 0)
|
|
1467
|
+
text = text.replace(/^ +/, '');
|
|
1468
|
+
if (index < lastRow)
|
|
1469
|
+
text = text.replace(/ +$/, '');
|
|
1470
|
+
if (text !== '')
|
|
1471
|
+
kept.push(text);
|
|
1472
|
+
});
|
|
1473
|
+
return kept.join(' ');
|
|
1474
|
+
}
|
|
1475
|
+
function transformJSXText(text) {
|
|
1476
|
+
const collapsed = collapseJsxWhitespace(text.node.value);
|
|
1477
|
+
return collapsed === '' ? null : t__namespace.stringLiteral(collapsed);
|
|
1478
|
+
}
|
|
1479
|
+
function memberTagToExpression(tag) {
|
|
1480
|
+
const segments = [];
|
|
1481
|
+
let head = tag;
|
|
1482
|
+
while (t__namespace.isJSXMemberExpression(head)) {
|
|
1483
|
+
segments.unshift(head.property.name);
|
|
1484
|
+
head = head.object;
|
|
1485
|
+
}
|
|
1486
|
+
let built = t__namespace.isJSXIdentifier(head) ? t__namespace.identifier(head.name) : t__namespace.nullLiteral();
|
|
1487
|
+
for (const segment of segments) {
|
|
1488
|
+
built = t__namespace.memberExpression(built, t__namespace.identifier(segment));
|
|
1489
|
+
}
|
|
1490
|
+
return built;
|
|
1491
|
+
}
|
|
1492
|
+
function transformJSXExpressionContainer(container) {
|
|
1493
|
+
const inner = container.node.expression;
|
|
1494
|
+
const lazyAttribute = t__namespace.isConditionalExpression(inner) && container.parentPath?.isJSXAttribute();
|
|
1495
|
+
return lazyAttribute ? t__namespace.arrowFunctionExpression([], inner) : inner;
|
|
1496
|
+
}
|
|
1497
|
+
const isMarkupTagName = (name) => name.includes('-') || name === 'center' || htmlTags.includes(name) || svgTags.includes(name);
|
|
1498
|
+
function getTag(element) {
|
|
1499
|
+
const tagPath = element.get('openingElement').get('name');
|
|
1500
|
+
const tag = tagPath.node;
|
|
1501
|
+
if (t__namespace.isJSXIdentifier(tag)) {
|
|
1502
|
+
return isMarkupTagName(tag.name) ? t__namespace.stringLiteral(tag.name) : t__namespace.identifier(tag.name);
|
|
1503
|
+
}
|
|
1504
|
+
if (t__namespace.isJSXMemberExpression(tag)) {
|
|
1505
|
+
return memberTagToExpression(tag);
|
|
1506
|
+
}
|
|
1507
|
+
return fail('MJX013', `Unsupported JSX tag name: ${tagPath.type}.`, tagPath);
|
|
1508
|
+
}
|
|
1509
|
+
const getProps = (props, path, state) => {
|
|
1510
|
+
const objectProps = [];
|
|
1511
|
+
const objectExpression = [];
|
|
1512
|
+
const eventProps = [];
|
|
1513
|
+
const directives = [];
|
|
1514
|
+
const preDirectives = [];
|
|
1515
|
+
const componentEvents = [];
|
|
1516
|
+
let htmlAttrlist = [];
|
|
1517
|
+
const thisStatement = [];
|
|
1518
|
+
const spreadProps = [];
|
|
1519
|
+
const fileName = String(state.get('filename') ?? '');
|
|
1520
|
+
const originalCode = state.get('originalCode');
|
|
1521
|
+
/** explain kanalı: bu özniteliğin neye indiğini kaydet. */
|
|
1522
|
+
const explainProp = (prop, site, shape, lowered, reactive, deps, note) => explainAt(prop, fileName, originalCode, { site, shape, lowered, reactive, deps, note });
|
|
1523
|
+
/** Bileşen prop'una geçen ifadenin sınıfı. */
|
|
1524
|
+
const classifyPropValue = (raw, value) => {
|
|
1525
|
+
const v = raw.get('value');
|
|
1526
|
+
const inner = v.isJSXExpressionContainer() ? v.node.expression : null;
|
|
1527
|
+
if (inner && t__namespace.isConditionalExpression(inner)) {
|
|
1528
|
+
return { shape: 'prop.ternary', reactive: 'receiver', deps: DEPS.receiver,
|
|
1529
|
+
note: 'ternary wrapped lazily (by design): the receiving component should declare the prop as Bind<T> and read it with read()/toGetter()' };
|
|
1530
|
+
}
|
|
1531
|
+
if (t__namespace.isArrowFunctionExpression(value) || t__namespace.isFunctionExpression(value)) {
|
|
1532
|
+
return { shape: 'prop.getter', reactive: 'receiver', deps: DEPS.receiver };
|
|
1533
|
+
}
|
|
1534
|
+
if (t__namespace.isStringLiteral(value) || t__namespace.isNumericLiteral(value) || t__namespace.isBooleanLiteral(value) || t__namespace.isNullLiteral(value) || (t__namespace.isTemplateLiteral(value) && value.expressions.length === 0)) {
|
|
1535
|
+
return { shape: 'prop.literal', reactive: 'static', deps: DEPS.none };
|
|
1536
|
+
}
|
|
1537
|
+
if (t__namespace.isCallExpression(value) && t__namespace.isIdentifier(value.callee) && value.callee.name === motifComponent()) {
|
|
1538
|
+
return { shape: 'prop.element', reactive: 'static', deps: DEPS.none, note: 'JSX-valued prop: the component instance is built once and passed' };
|
|
1539
|
+
}
|
|
1540
|
+
return { shape: 'prop.value', reactive: 'once', deps: DEPS.once,
|
|
1541
|
+
note: 'passed as a value; if the object is a reactive proxy, the receiver stays live by reading its fields inside a getter' };
|
|
1542
|
+
};
|
|
1543
|
+
/** DOM özniteliğine yazılan ifadenin sınıfı (makeHtmlAttr'ın gerçek dalları). */
|
|
1544
|
+
const classifyAttrValue = (raw, value, emitted) => {
|
|
1545
|
+
const v = raw.get('value');
|
|
1546
|
+
const inner = v.isJSXExpressionContainer() ? v.node.expression : null;
|
|
1547
|
+
if (t__namespace.isStringLiteral(value) || t__namespace.isBooleanLiteral(value) || t__namespace.isNumericLiteral(value) || t__namespace.isNullLiteral(value)
|
|
1548
|
+
|| (t__namespace.isUnaryExpression(value) && t__namespace.isLiteral(value.argument))
|
|
1549
|
+
|| (t__namespace.isTemplateLiteral(value) && value.expressions.length === 0)) {
|
|
1550
|
+
return { shape: 'attr.literal', reactive: 'static', deps: DEPS.none };
|
|
1551
|
+
}
|
|
1552
|
+
if (inner && t__namespace.isConditionalExpression(inner)) {
|
|
1553
|
+
return { shape: 'attr.ternary', reactive: 'live', deps: DEPS.getter, note: 'ternary wrapped lazily (by design); attr.add calls the getter inside an effect' };
|
|
1554
|
+
}
|
|
1555
|
+
if (t__namespace.isArrowFunctionExpression(value) || t__namespace.isFunctionExpression(value)) {
|
|
1556
|
+
return { shape: 'attr.getter', reactive: 'live', deps: DEPS.getter };
|
|
1557
|
+
}
|
|
1558
|
+
if (t__namespace.isIdentifier(value)) {
|
|
1559
|
+
return { shape: 'attr.identifier', reactive: 'runtime', deps: DEPS.runtime };
|
|
1560
|
+
}
|
|
1561
|
+
if (t__namespace.isCallExpression(value) && t__namespace.isIdentifier(value.callee)) {
|
|
1562
|
+
return { shape: 'attr.call', reactive: 'once', deps: DEPS.once, note: 'a plain function call is passed as a VALUE; write `() => f(x)` to keep it live' };
|
|
1563
|
+
}
|
|
1564
|
+
const ev = emitted?.value;
|
|
1565
|
+
if (ev && (t__namespace.isArrowFunctionExpression(ev) || t__namespace.isFunctionExpression(ev))) {
|
|
1566
|
+
return { shape: 'attr.expr', reactive: 'live', deps: DEPS.getter, note: 'expression wrapped in a guarded getter (nothing is written while an intermediate link is null)' };
|
|
1567
|
+
}
|
|
1568
|
+
return { shape: 'attr.value', reactive: 'once', deps: DEPS.once };
|
|
1569
|
+
};
|
|
1570
|
+
/** Etiket bir BİLEŞEN mi (büyük harfle başlıyor ya da üye ifadesi)? */
|
|
1571
|
+
const tagIsComponent = () => {
|
|
1572
|
+
if (!t__namespace.isJSXElement(path.node))
|
|
1573
|
+
return false;
|
|
1574
|
+
const nameNode = path.node.openingElement.name;
|
|
1575
|
+
if (t__namespace.isJSXMemberExpression(nameNode))
|
|
1576
|
+
return true;
|
|
1577
|
+
if (!t__namespace.isJSXIdentifier(nameNode))
|
|
1578
|
+
return false;
|
|
1579
|
+
const n = nameNode.name;
|
|
1580
|
+
return n.length > 0 && n[0].toUpperCase() === n[0] && n !== FRAGMENT;
|
|
1581
|
+
};
|
|
1582
|
+
/** Değersiz öznitelik (`<Comp flag />`) → `flag: true` prop'u. */
|
|
1583
|
+
const pushBooleanProp = (name) => {
|
|
1584
|
+
const key = (name.includes('-') || name.includes(':'))
|
|
1585
|
+
? t__namespace.stringLiteral(name)
|
|
1586
|
+
: id(name);
|
|
1587
|
+
objectExpression.push(t__namespace.objectProperty(key, t__namespace.booleanLiteral(true)));
|
|
1588
|
+
};
|
|
1589
|
+
const plainTag = t__namespace.isStringLiteral(getTag(path));
|
|
1590
|
+
let userInit = null;
|
|
1591
|
+
const refEntries = [];
|
|
1592
|
+
const pushRef = (prop, value) => {
|
|
1593
|
+
if (t__namespace.isIdentifier(value) || t__namespace.isMemberExpression(value)) {
|
|
1594
|
+
const kind = refTargetKind(prop, value);
|
|
1595
|
+
const callTarget = t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.cloneNode(value), [t__namespace.identifier('sender')]));
|
|
1596
|
+
const assignTarget = t__namespace.expressionStatement(t__namespace.assignmentExpression("=", t__namespace.cloneNode(value), t__namespace.identifier('sender')));
|
|
1597
|
+
const refStmt = kind === 'call'
|
|
1598
|
+
? callTarget
|
|
1599
|
+
: kind === 'assign'
|
|
1600
|
+
? assignTarget
|
|
1601
|
+
: t__namespace.ifStatement(t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', t__namespace.cloneNode(value)), t__namespace.stringLiteral('function')), callTarget, assignTarget);
|
|
1602
|
+
const body = [refStmt];
|
|
1603
|
+
if (enclosingClassOfThis(prop)) {
|
|
1604
|
+
body.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('if(this.onRefCreated) this.onRefCreated'), [t__namespace.identifier('sender')])));
|
|
1605
|
+
}
|
|
1606
|
+
refEntries.push({ prop, lowered: t__namespace.arrowFunctionExpression([t__namespace.identifier('sender')], t__namespace.blockStatement(body)) });
|
|
1607
|
+
}
|
|
1608
|
+
else if (t__namespace.isFunctionExpression(value) || t__namespace.isArrowFunctionExpression(value)) {
|
|
1609
|
+
refEntries.push({ prop, lowered: t__namespace.arrowFunctionExpression(value.params, value.body) });
|
|
1610
|
+
}
|
|
1611
|
+
else if (t__namespace.isExpression(value)) {
|
|
1612
|
+
var cx = t__namespace.expressionStatement(value);
|
|
1613
|
+
refEntries.push({ prop, lowered: t__namespace.arrowFunctionExpression([t__namespace.identifier('sender')], t__namespace.blockStatement([cx])) });
|
|
1614
|
+
}
|
|
1615
|
+
else {
|
|
1616
|
+
objectProps.push(value);
|
|
1617
|
+
}
|
|
1618
|
+
};
|
|
1619
|
+
const hookCounts = new Map();
|
|
1620
|
+
props.forEach(prop => {
|
|
1621
|
+
if (!prop.isJSXAttribute() || prop.node.value == null)
|
|
1622
|
+
return;
|
|
1623
|
+
const hook = lifecycleHookOf(getAttributeName(prop));
|
|
1624
|
+
if (hook !== null)
|
|
1625
|
+
hookCounts.set(hook, (hookCounts.get(hook) ?? 0) + 1);
|
|
1626
|
+
});
|
|
1627
|
+
const mergedHooks = new Map();
|
|
1628
|
+
hookCounts.forEach((count, hook) => { if (count > 1)
|
|
1629
|
+
mergedHooks.set(hook, []); });
|
|
1630
|
+
if (props.length > 0) {
|
|
1631
|
+
props.forEach(prop => {
|
|
1632
|
+
if (prop.isSpreadElement()) {
|
|
1633
|
+
spreadProps.push(prop);
|
|
1634
|
+
}
|
|
1635
|
+
else if (prop.isJSXSpreadChild()) {
|
|
1636
|
+
spreadProps.push(prop);
|
|
1637
|
+
}
|
|
1638
|
+
else if (prop.isJSXSpreadAttribute()) {
|
|
1639
|
+
spreadProps.push(t__namespace.spreadElement(prop.node.argument));
|
|
1640
|
+
}
|
|
1641
|
+
else if (prop.isJSXAttribute()) {
|
|
1642
|
+
let name = getAttributeName(prop);
|
|
1643
|
+
let value = getAttributeValue(prop, state);
|
|
1644
|
+
const mergedHook = lifecycleHookOf(name);
|
|
1645
|
+
if (mergedHook !== null && mergedHooks.has(mergedHook) && value != null) {
|
|
1646
|
+
if (t__namespace.isExpression(value)) {
|
|
1647
|
+
mergedHooks.get(mergedHook).push({ prop, value });
|
|
1648
|
+
}
|
|
1649
|
+
else {
|
|
1650
|
+
objectProps.push(value);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
else if (name === 'initializeComponent' && value != null) {
|
|
1654
|
+
if (t__namespace.isExpression(value)) {
|
|
1655
|
+
userInit = value;
|
|
1656
|
+
explainProp(prop, 'component-event', 'lifecycle', `initializeComponent: ${codeOf(value)}`, 'n/a', DEPS.none, plainTag
|
|
1657
|
+
? 'called once during setup with the tag\'s component as sender (same as initializeComponent on a component tag)'
|
|
1658
|
+
: 'passed via runover; called once during setup with the tag\'s component (the returned root for a function component) as sender');
|
|
1659
|
+
}
|
|
1660
|
+
else {
|
|
1661
|
+
objectProps.push(value);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
else if (name === 'ref' && value != null) {
|
|
1665
|
+
pushRef(prop, value);
|
|
1666
|
+
}
|
|
1667
|
+
else if (isComponentEvent(name.toLowerCase())) {
|
|
1668
|
+
if (value != null) {
|
|
1669
|
+
var ce = makeComponentTraps(prop, name, value);
|
|
1670
|
+
if (ce !== null) {
|
|
1671
|
+
componentEvents.push(ce);
|
|
1672
|
+
explainProp(prop, 'component-event', 'lifecycle', ce, 'n/a', DEPS.none, 'lifecycle hook; called once during component setup/build/dispose');
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
else if (!plainTag && mergedHook !== null && value != null && t__namespace.isExpression(value)) {
|
|
1677
|
+
const key = name.toLowerCase().startsWith('on') ? name : 'on' + mergedHook;
|
|
1678
|
+
const lifecycleProp = t__namespace.objectProperty(t__namespace.isValidIdentifier(key) ? id(key) : t__namespace.stringLiteral(key), value);
|
|
1679
|
+
componentEvents.push(lifecycleProp);
|
|
1680
|
+
explainProp(prop, 'component-event', 'lifecycle', lifecycleProp, 'n/a', DEPS.none, 'lifecycle hook; on a component tag it is applied via runover to the tag\'s component (the returned root for a function component)');
|
|
1681
|
+
}
|
|
1682
|
+
else if (isContextHandler(name.toLowerCase()) && value != null) {
|
|
1683
|
+
const newName = name.slice(3);
|
|
1684
|
+
const onCall = t__namespace.callExpression(id('sender.motif.on'), [t__namespace.stringLiteral(newName), value]);
|
|
1685
|
+
directives.push(t__namespace.expressionStatement(onCall));
|
|
1686
|
+
explainProp(prop, 'event', 'event.context', onCall, 'n/a', DEPS.none, 'context event (on:/on-/on_): the handler is passed to motif.on as is; with ≤ 1 declared parameter it is called as fn(event), with 2 or more as fn(sender, event)');
|
|
1687
|
+
}
|
|
1688
|
+
else if (name.toLowerCase() === "key" || name.toLowerCase() === "indexkey") {
|
|
1689
|
+
var clearedName = 'indexkey';
|
|
1690
|
+
if (t__namespace.isIdentifier(value)) {
|
|
1691
|
+
var cex = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.returnStatement(value)]));
|
|
1692
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1693
|
+
}
|
|
1694
|
+
else if (t__namespace.isMemberExpression(value)) {
|
|
1695
|
+
var cex = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.returnStatement(value)]));
|
|
1696
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1697
|
+
}
|
|
1698
|
+
else if (t__namespace.isFunctionExpression(value) || t__namespace.isArrowFunctionExpression(value)) {
|
|
1699
|
+
var cex = t__namespace.arrowFunctionExpression(value.params, value.body);
|
|
1700
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1701
|
+
}
|
|
1702
|
+
else if (t__namespace.isExpression(value)) {
|
|
1703
|
+
var cex = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.returnStatement(value)]));
|
|
1704
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1705
|
+
}
|
|
1706
|
+
else ;
|
|
1707
|
+
explainProp(prop, 'key', 'key', objectExpression[objectExpression.length - 1], 'n/a', 'item identity — ListBinding matches DOM nodes by it', undefined);
|
|
1708
|
+
}
|
|
1709
|
+
else if (isDirective(name.toLowerCase())) {
|
|
1710
|
+
const directiveName = name.toLowerCase().replace("x:", "").replace("x-", "");
|
|
1711
|
+
if (UNSUPPORTED_DIRECTIVES.has(directiveName)) {
|
|
1712
|
+
fail('MJX006', `Directive "${name}" is not supported. Supported: ${supportedDirectivesText()}.`, prop);
|
|
1713
|
+
}
|
|
1714
|
+
if (value != null) {
|
|
1715
|
+
var clearedName = name.toLowerCase().replace("x:", "").replace("x-", "").replace("on:", "");
|
|
1716
|
+
if (SUPPORTED_DIRECTIVES.includes(clearedName)) {
|
|
1717
|
+
if (clearedName !== 'wait' && clearedName !== 'display') {
|
|
1718
|
+
var directive = makeDirectives(prop, name, value, path);
|
|
1719
|
+
if (directive != null) {
|
|
1720
|
+
directives.push(directive);
|
|
1721
|
+
const twoWay = clearedName === 'model' && t__namespace.isCallExpression(directive.expression) && directive.expression.arguments.length > 1;
|
|
1722
|
+
explainProp(prop, 'directive', 'directive.' + clearedName, directive.expression, 'live', twoWay ? DEPS.model : clearedName === 'model' ? DEPS.modelOneWay : DEPS.getter);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
else {
|
|
1726
|
+
var directive = makePreDirectives(prop, name, value);
|
|
1727
|
+
if (directive != null) {
|
|
1728
|
+
preDirectives.push(directive);
|
|
1729
|
+
explainProp(prop, 'directive', 'directive.' + clearedName, directive.expression, 'live', DEPS.getter, clearedName === 'wait' ? 'true → hidden; if true at start, the element and its children are never built (preconfig, before build)'
|
|
1730
|
+
: 'removes/reinserts in the DOM; the instance is kept (preconfig)');
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
else if (clearedName === 'style') {
|
|
1735
|
+
const styleAttr = makeHtmlAttr(prop, 'style', value);
|
|
1736
|
+
if (styleAttr !== null) {
|
|
1737
|
+
htmlAttrlist.push(styleAttr);
|
|
1738
|
+
const c = classifyAttrValue(prop, value, styleAttr);
|
|
1739
|
+
explainProp(prop, 'attr', 'style', `sender.style(${codeOf(styleAttr.value)})`, c.reactive, c.deps, c.note);
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
else if (clearedName === "ref") {
|
|
1743
|
+
pushRef(prop, value);
|
|
1744
|
+
}
|
|
1745
|
+
else if (clearedName === "inject") {
|
|
1746
|
+
if (t__namespace.isIdentifier(value)) {
|
|
1747
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), value));
|
|
1748
|
+
}
|
|
1749
|
+
else if (t__namespace.isMemberExpression(value)) {
|
|
1750
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), value));
|
|
1751
|
+
}
|
|
1752
|
+
else if (t__namespace.isFunctionExpression(value) || t__namespace.isArrowFunctionExpression(value)) {
|
|
1753
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), value));
|
|
1754
|
+
}
|
|
1755
|
+
else if (t__namespace.isExpression(value)) {
|
|
1756
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), value));
|
|
1757
|
+
}
|
|
1758
|
+
else {
|
|
1759
|
+
objectProps.push(value);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
else if (name.toLowerCase() === "key" || name.toLowerCase() === "indexkey") {
|
|
1763
|
+
var clearedName = 'indexkey';
|
|
1764
|
+
if (t__namespace.isIdentifier(value)) {
|
|
1765
|
+
var cex = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.returnStatement(value)]));
|
|
1766
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1767
|
+
}
|
|
1768
|
+
else if (t__namespace.isMemberExpression(value)) {
|
|
1769
|
+
var cex = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.returnStatement(value)]));
|
|
1770
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1771
|
+
}
|
|
1772
|
+
else if (t__namespace.isFunctionExpression(value) || t__namespace.isArrowFunctionExpression(value)) {
|
|
1773
|
+
var cex = t__namespace.arrowFunctionExpression(value.params, value.body);
|
|
1774
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1775
|
+
}
|
|
1776
|
+
else if (t__namespace.isExpression(value)) {
|
|
1777
|
+
var cex = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.returnStatement(value)]));
|
|
1778
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1779
|
+
}
|
|
1780
|
+
else {
|
|
1781
|
+
objectProps.push(value);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
else if (clearedName === "key" || clearedName === "indexkey") {
|
|
1785
|
+
clearedName = 'indexkey';
|
|
1786
|
+
if (t__namespace.isIdentifier(value)) {
|
|
1787
|
+
var cex = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.returnStatement(value)]));
|
|
1788
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1789
|
+
}
|
|
1790
|
+
else if (t__namespace.isMemberExpression(value)) {
|
|
1791
|
+
var cex = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.returnStatement(value)]));
|
|
1792
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1793
|
+
}
|
|
1794
|
+
else if (t__namespace.isFunctionExpression(value) || t__namespace.isArrowFunctionExpression(value)) {
|
|
1795
|
+
var cex = t__namespace.arrowFunctionExpression(value.params, value.body);
|
|
1796
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1797
|
+
}
|
|
1798
|
+
else if (t__namespace.isExpression(value)) {
|
|
1799
|
+
var cex = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([t__namespace.returnStatement(value)]));
|
|
1800
|
+
objectExpression.push(t__namespace.objectProperty(id(clearedName), cex));
|
|
1801
|
+
}
|
|
1802
|
+
else {
|
|
1803
|
+
objectProps.push(value);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
else {
|
|
1807
|
+
if (!isComponentEvent('on' + clearedName) && !LIFECYCLE_HOOKS.has(clearedName) && clearedName !== 'initializecomponent') {
|
|
1808
|
+
warn('MJX007', `Unknown directive "${name}": it is passed on as the prop "on${clearedName}". Supported: ${supportedDirectivesText()}.`, prop, fileName);
|
|
1809
|
+
}
|
|
1810
|
+
if (t__namespace.isExpression(value)) {
|
|
1811
|
+
objectExpression.push(t__namespace.objectProperty(id("on" + clearedName), value));
|
|
1812
|
+
}
|
|
1813
|
+
else {
|
|
1814
|
+
objectProps.push(value);
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
else if ((htmlAttributes.has(name) || startAttr(name))
|
|
1820
|
+
||
|
|
1821
|
+
(path.node.openingElement.name.name == String(path.node.openingElement.name.name).toLowerCase() &&
|
|
1822
|
+
name.toLowerCase().startsWith("on") == false &&
|
|
1823
|
+
name.toLowerCase() != 'indexkey' &&
|
|
1824
|
+
name.toLowerCase() != 'key' &&
|
|
1825
|
+
name.toLowerCase() != 'props' &&
|
|
1826
|
+
name.toLowerCase() != 'settings')) {
|
|
1827
|
+
var isComponent = tagIsComponent();
|
|
1828
|
+
if (isComponent) {
|
|
1829
|
+
if (value != null) {
|
|
1830
|
+
if (t__namespace.isExpression(value)) {
|
|
1831
|
+
if (name.includes("-") || name.includes(":")) {
|
|
1832
|
+
objectExpression.push(t__namespace.objectProperty(t__namespace.stringLiteral(name), value));
|
|
1833
|
+
}
|
|
1834
|
+
else {
|
|
1835
|
+
objectExpression.push(t__namespace.objectProperty(id(name), value));
|
|
1836
|
+
}
|
|
1837
|
+
{
|
|
1838
|
+
const c = classifyPropValue(prop, value);
|
|
1839
|
+
explainProp(prop, 'prop', c.shape, objectExpression[objectExpression.length - 1], c.reactive, c.deps, c.note);
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
else {
|
|
1843
|
+
objectProps.push(value);
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
else {
|
|
1847
|
+
pushBooleanProp(name);
|
|
1848
|
+
explainProp(prop, 'prop', 'prop.flag', objectExpression[objectExpression.length - 1], 'static', DEPS.none);
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
else if (name === 'transition' && value !== null && t__namespace.isExpression(value)) {
|
|
1852
|
+
objectExpression.push(t__namespace.objectProperty(id('transition'), value));
|
|
1853
|
+
explainProp(prop, 'prop', 'prop.transition', objectExpression[objectExpression.length - 1], 'static', DEPS.none, 'bound to the transition engine (options.transition); no HTML attribute is written');
|
|
1854
|
+
}
|
|
1855
|
+
else if (name === 'options' && value !== null && t__namespace.isExpression(value)) {
|
|
1856
|
+
objectExpression.push(t__namespace.objectProperty(id('options'), value));
|
|
1857
|
+
explainProp(prop, 'prop', 'prop.options', objectExpression[objectExpression.length - 1], 'static', DEPS.none, 'copied into motif.options (hideStrategy, disableDisposal); no HTML attribute is written');
|
|
1858
|
+
}
|
|
1859
|
+
else if (value !== null) {
|
|
1860
|
+
var atr = makeHtmlAttr(prop, name, value);
|
|
1861
|
+
if (atr !== null) {
|
|
1862
|
+
htmlAttrlist.push(atr);
|
|
1863
|
+
const lname = name.toLowerCase();
|
|
1864
|
+
const c = classifyAttrValue(prop, value, atr);
|
|
1865
|
+
const call = lname === 'class' || lname === 'classname' ? 'sender.class.add' : lname === 'style' ? 'sender.style' : 'sender.attr.add';
|
|
1866
|
+
const shown = call === 'sender.attr.add' ? `${call}({ "${name}": ${codeOf(atr.value)} })` : `${call}(${codeOf(atr.value)})`;
|
|
1867
|
+
explainProp(prop, 'attr', c.shape, shown, c.reactive, c.deps, c.note);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
else {
|
|
1871
|
+
var atr = makeHtmlAttr(prop, name, t__namespace.booleanLiteral(true));
|
|
1872
|
+
if (atr !== null) {
|
|
1873
|
+
htmlAttrlist.push(atr);
|
|
1874
|
+
explainProp(prop, 'attr', 'attr.flag', `sender.attr.add({ "${name}": true })`, 'static', DEPS.none);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
else if (name.toLowerCase().startsWith("on") && htmlEvents.has(name.toLowerCase())) {
|
|
1879
|
+
if (tagIsComponent() && name !== name.toLowerCase()) {
|
|
1880
|
+
warn('MJX002', `"${name}" is a DOM event name; on a component tag this prop is NOT passed as a callback but bound as a DOM listener on the root element, so "this.props.${name}" stays undefined. For a callback, choose a name that does not collide with DOM events (e.g. "onValueChange", "onConfirm", "onSwitch").`, prop, fileName);
|
|
1881
|
+
}
|
|
1882
|
+
if (value != null) {
|
|
1883
|
+
var evp = makeHtmlEvents(prop, name, value);
|
|
1884
|
+
if (evp !== null) {
|
|
1885
|
+
eventProps.push(t__namespace.expressionStatement(evp));
|
|
1886
|
+
explainProp(prop, 'event', 'event.dom', evp, 'n/a', DEPS.none, tagIsComponent() ? 'DOM event on a component tag: bound as a listener on the root element, it does NOT reach this.props' : undefined);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
else if (!name.startsWith("x")) {
|
|
1891
|
+
if (value != null) {
|
|
1892
|
+
if (t__namespace.isExpression(value)) {
|
|
1893
|
+
if (name.includes("-") || name.includes(":")) {
|
|
1894
|
+
objectExpression.push(t__namespace.objectProperty(t__namespace.stringLiteral(name), value));
|
|
1895
|
+
}
|
|
1896
|
+
else {
|
|
1897
|
+
objectExpression.push(t__namespace.objectProperty(id(name), value));
|
|
1898
|
+
}
|
|
1899
|
+
{
|
|
1900
|
+
const c = classifyPropValue(prop, value);
|
|
1901
|
+
explainProp(prop, 'prop', c.shape, objectExpression[objectExpression.length - 1], c.reactive, c.deps, c.note);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
else {
|
|
1905
|
+
objectProps.push(value);
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
else {
|
|
1909
|
+
pushBooleanProp(name);
|
|
1910
|
+
explainProp(prop, 'prop', 'prop.flag', objectExpression[objectExpression.length - 1], 'static', DEPS.none);
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
if (refEntries.length > 0) {
|
|
1917
|
+
const refProp = t__namespace.objectProperty(id('ref'), refEntries.length === 1 ? refEntries[0].lowered : t__namespace.arrayExpression(refEntries.map(e => e.lowered)));
|
|
1918
|
+
objectExpression.push(refProp);
|
|
1919
|
+
refEntries.forEach(e => explainProp(e.prop, 'prop', 'ref', refProp, 'n/a', DEPS.none, refEntries.length === 1
|
|
1920
|
+
? 'the tag\'s component is passed to the ref once, while it is being built'
|
|
1921
|
+
: 'all ref spellings on the same tag are merged into one list; each is called once, in source order'));
|
|
1922
|
+
}
|
|
1923
|
+
mergedHooks.forEach((entries, hook) => {
|
|
1924
|
+
if (entries.length === 0)
|
|
1925
|
+
return;
|
|
1926
|
+
const merged = t__namespace.objectProperty(id('on' + hook), t__namespace.arrayExpression(entries.map(e => e.value)));
|
|
1927
|
+
componentEvents.push(merged);
|
|
1928
|
+
entries.forEach(e => explainProp(e.prop, 'component-event', 'lifecycle', merged, 'n/a', DEPS.none, 'all spellings of the same hook on this tag are merged into one list; each is called once, in source order'));
|
|
1929
|
+
});
|
|
1930
|
+
const htmlProps = mergeHtmlAttributes(htmlAttrlist);
|
|
1931
|
+
return { htmlProps, eventProps, objectExpression, objectProps, componentEvents, directives, preDirectives, thisStatement, spreadProps, userInit: userInit };
|
|
1932
|
+
};
|
|
1933
|
+
const getChildren = (paths, state) => {
|
|
1934
|
+
const originalCode = state.get('originalCode');
|
|
1935
|
+
const transformOne = (path) => {
|
|
1936
|
+
if (path.isJSXText()) {
|
|
1937
|
+
const literal = transformJSXText(path);
|
|
1938
|
+
return literal === null ? null : mkText(literal);
|
|
1939
|
+
}
|
|
1940
|
+
if (path.isJSXExpressionContainer()) {
|
|
1941
|
+
// "{ () => { return cond ? <A/> : <B/> } }".
|
|
1942
|
+
let expression = transformJSXExpressionContainer(path);
|
|
1943
|
+
// Detect: {(() => { switch(expr) { case ... } })()}
|
|
1944
|
+
if (t__namespace.isCallExpression(expression) && (t__namespace.isArrowFunctionExpression(expression.callee) || t__namespace.isFunctionExpression(expression.callee)) &&
|
|
1945
|
+
expression.callee.body && t__namespace.isBlockStatement(expression.callee.body)) {
|
|
1946
|
+
const switchStmt = expression.callee.body.body.find((s) => t__namespace.isSwitchStatement(s));
|
|
1947
|
+
if (switchStmt) {
|
|
1948
|
+
const discriminant = switchStmt.discriminant;
|
|
1949
|
+
const callee = expression.callee;
|
|
1950
|
+
const callArgs = expression.arguments;
|
|
1951
|
+
const params = callee.params;
|
|
1952
|
+
let discriminatorFn;
|
|
1953
|
+
const casesObjProps = [];
|
|
1954
|
+
let defaultFn = undefined;
|
|
1955
|
+
for (const caseNode of switchStmt.cases) {
|
|
1956
|
+
const ret = caseNode.consequent.find((s) => t__namespace.isReturnStatement(s));
|
|
1957
|
+
const handlerBody = ret && ret.argument ? [t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.identifier('frame'), t__namespace.identifier('navigate')), [ret.argument]))] : [t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.identifier('frame'), t__namespace.identifier('navigate')), [t__namespace.callExpression(t__namespace.identifier(motifFragment()), [])]))];
|
|
1958
|
+
if (!state.get(motifFragment())) {
|
|
1959
|
+
state.set(motifFragment(), motifFragment());
|
|
1960
|
+
}
|
|
1961
|
+
const handlerFn = t__namespace.arrowFunctionExpression([t__namespace.identifier('frame')], t__namespace.blockStatement(handlerBody));
|
|
1962
|
+
if (caseNode.test) {
|
|
1963
|
+
if (t__namespace.isStringLiteral(caseNode.test) || t__namespace.isNumericLiteral(caseNode.test) || t__namespace.isBooleanLiteral(caseNode.test)) {
|
|
1964
|
+
casesObjProps.push(t__namespace.objectProperty(caseNode.test, handlerFn));
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
else {
|
|
1968
|
+
defaultFn = handlerFn;
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
if (params.length === 1 &&
|
|
1972
|
+
t__namespace.isIdentifier(params[0]) &&
|
|
1973
|
+
t__namespace.isIdentifier(discriminant) &&
|
|
1974
|
+
params[0].name === discriminant.name &&
|
|
1975
|
+
callArgs.length >= 1) {
|
|
1976
|
+
// Özel durum (tek parametre): () => arg0
|
|
1977
|
+
discriminatorFn = t__namespace.arrowFunctionExpression([], callArgs[0]);
|
|
1978
|
+
}
|
|
1979
|
+
else if (params.length > 0) {
|
|
1980
|
+
discriminatorFn = t__namespace.arrowFunctionExpression([], t__namespace.callExpression(t__namespace.arrowFunctionExpression(params, discriminant), callArgs));
|
|
1981
|
+
}
|
|
1982
|
+
else {
|
|
1983
|
+
discriminatorFn = t__namespace.arrowFunctionExpression([], discriminant);
|
|
1984
|
+
}
|
|
1985
|
+
const args = [discriminatorFn, t__namespace.objectExpression(casesObjProps)];
|
|
1986
|
+
if (defaultFn)
|
|
1987
|
+
args.push(defaultFn);
|
|
1988
|
+
// return t.callExpression(
|
|
1989
|
+
return t__namespace.callExpression(t__namespace.identifier('sender.bindings.switchCase'), args);
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
if ((t__namespace.isArrowFunctionExpression(expression) || t__namespace.isFunctionExpression(expression)) && expression.body && t__namespace.isBlockStatement(expression.body)) {
|
|
1993
|
+
const switchStmt = expression.body.body.find((s) => t__namespace.isSwitchStatement(s));
|
|
1994
|
+
if (switchStmt) {
|
|
1995
|
+
const discriminant = switchStmt.discriminant;
|
|
1996
|
+
const casesObjProps = [];
|
|
1997
|
+
let defaultFn = undefined;
|
|
1998
|
+
for (const caseNode of switchStmt.cases) {
|
|
1999
|
+
const ret = caseNode.consequent.find((s) => t__namespace.isReturnStatement(s));
|
|
2000
|
+
const handlerBody = ret && ret.argument ? [t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.identifier('frame'), t__namespace.identifier('navigate')), [ret.argument]))] : [t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(t__namespace.identifier('frame'), t__namespace.identifier('navigate')), [t__namespace.callExpression(t__namespace.identifier(motifFragment()), [])]))];
|
|
2001
|
+
if (!state.get(motifFragment())) {
|
|
2002
|
+
state.set(motifFragment(), motifFragment());
|
|
2003
|
+
}
|
|
2004
|
+
const handlerFn = t__namespace.arrowFunctionExpression([t__namespace.identifier('frame')], t__namespace.blockStatement(handlerBody));
|
|
2005
|
+
if (caseNode.test) {
|
|
2006
|
+
if (t__namespace.isStringLiteral(caseNode.test) || t__namespace.isNumericLiteral(caseNode.test) || t__namespace.isBooleanLiteral(caseNode.test)) {
|
|
2007
|
+
casesObjProps.push(t__namespace.objectProperty(caseNode.test, handlerFn));
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
else {
|
|
2011
|
+
defaultFn = handlerFn;
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
const discriminatorFn = t__namespace.arrowFunctionExpression([], discriminant);
|
|
2015
|
+
const args = [discriminatorFn, t__namespace.objectExpression(casesObjProps)];
|
|
2016
|
+
if (defaultFn)
|
|
2017
|
+
args.push(defaultFn);
|
|
2018
|
+
return t__namespace.callExpression(t__namespace.identifier('sender.bindings.switchCase'), args);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
const unwrapConditionalFromFunction = (expr) => {
|
|
2022
|
+
let current = expr;
|
|
2023
|
+
while (current) {
|
|
2024
|
+
if (t__namespace.isArrowFunctionExpression(current) && t__namespace.isConditionalExpression(current.body)) {
|
|
2025
|
+
current = current.body;
|
|
2026
|
+
continue;
|
|
2027
|
+
}
|
|
2028
|
+
if ((t__namespace.isArrowFunctionExpression(current) || t__namespace.isFunctionExpression(current)) && t__namespace.isBlockStatement(current.body)) {
|
|
2029
|
+
const ret = current.body.body.find(s => t__namespace.isReturnStatement(s) && s.argument && t__namespace.isConditionalExpression(s.argument));
|
|
2030
|
+
if (ret && t__namespace.isReturnStatement(ret) && ret.argument && t__namespace.isConditionalExpression(ret.argument)) {
|
|
2031
|
+
const locals = current.body.body
|
|
2032
|
+
.filter(s => t__namespace.isVariableDeclaration(s))
|
|
2033
|
+
.flatMap(s => s.declarations
|
|
2034
|
+
.map(d => (t__namespace.isIdentifier(d.id) ? d.id.name : null))
|
|
2035
|
+
.filter((n) => n !== null));
|
|
2036
|
+
if (locals.length > 0) {
|
|
2037
|
+
warn('MJX001', `In a block-bodied function in JSX child position the condition is moved out of the closure; ${locals.map(n => '"' + n + '"').join(', ')} declared inside it are not visible in the branches and throw ReferenceError. Use an expression-bodied arrow function (\`{() => cond ? <A t={compute()}/> : <B/>}\`) or move the logic into a named method.`, path, String(state.get('filename') ?? ''));
|
|
2038
|
+
}
|
|
2039
|
+
current = ret.argument;
|
|
2040
|
+
continue;
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
if (t__namespace.isParenthesizedExpression(current) && current.expression) {
|
|
2044
|
+
current = current.expression;
|
|
2045
|
+
continue;
|
|
2046
|
+
}
|
|
2047
|
+
break;
|
|
2048
|
+
}
|
|
2049
|
+
return current || expr;
|
|
2050
|
+
};
|
|
2051
|
+
if (t__namespace.isArrowFunctionExpression(expression) || t__namespace.isFunctionExpression(expression)) {
|
|
2052
|
+
const hit = findShortCircuitPredicate(expression.body);
|
|
2053
|
+
if (hit !== null) {
|
|
2054
|
+
warn('MJX004', `"${hit}()" short-circuits inside a reactive getter: the predicate stops at the first match, so the rest of the array is not tracked as a dependency and the binding does not update when those items change. Keep the result in a computed value or field and read that, or traverse the whole array first (e.g. "arr.filter(...).length > 0").`, path, String(state.get('filename') ?? ''));
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
expression = unwrapConditionalFromFunction(expression);
|
|
2058
|
+
if (isChildsSlot(expression)) {
|
|
2059
|
+
return expression;
|
|
2060
|
+
}
|
|
2061
|
+
if (t__namespace.isIdentifier(expression)) {
|
|
2062
|
+
return mkText(expression);
|
|
2063
|
+
}
|
|
2064
|
+
if (t__namespace.isBinaryExpression(expression)) {
|
|
2065
|
+
return mkText(expression);
|
|
2066
|
+
}
|
|
2067
|
+
if (t__namespace.isConditionalExpression(expression)) {
|
|
2068
|
+
const frameId = t__namespace.identifier('frame');
|
|
2069
|
+
const isMotifCall = (e) => t__namespace.isCallExpression(e) && t__namespace.isIdentifier(e.callee) && (e.callee.name === motifComponent() || e.callee.name === motifFragment());
|
|
2070
|
+
const normalize = (e) => {
|
|
2071
|
+
if (isMotifCall(e))
|
|
2072
|
+
return e;
|
|
2073
|
+
return mkText(e);
|
|
2074
|
+
};
|
|
2075
|
+
const buildBranch = (node) => {
|
|
2076
|
+
if (t__namespace.isConditionalExpression(node)) {
|
|
2077
|
+
const trueBody = buildBranch(node.consequent);
|
|
2078
|
+
const falseBody = buildBranch(node.alternate);
|
|
2079
|
+
return [
|
|
2080
|
+
t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.bindings.ternaryCall'), [
|
|
2081
|
+
t__namespace.arrowFunctionExpression([], node.test),
|
|
2082
|
+
t__namespace.arrowFunctionExpression([], t__namespace.blockStatement(trueBody)),
|
|
2083
|
+
t__namespace.arrowFunctionExpression([], t__namespace.blockStatement(falseBody))
|
|
2084
|
+
]))
|
|
2085
|
+
];
|
|
2086
|
+
}
|
|
2087
|
+
return [t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.memberExpression(frameId, t__namespace.identifier('navigate')), [normalize(node)]))];
|
|
2088
|
+
};
|
|
2089
|
+
const trueFn = t__namespace.arrowFunctionExpression([frameId], t__namespace.blockStatement(buildBranch(expression.consequent)));
|
|
2090
|
+
const falseFn = t__namespace.arrowFunctionExpression([frameId], t__namespace.blockStatement(buildBranch(expression.alternate)));
|
|
2091
|
+
const condFn = t__namespace.arrowFunctionExpression([], expression.test);
|
|
2092
|
+
if (!state.get(motifFragment())) {
|
|
2093
|
+
state.set(motifFragment(), motifFragment());
|
|
2094
|
+
}
|
|
2095
|
+
return t__namespace.callExpression(id('sender.bindings.ternary'), [condFn, trueFn, falseFn]);
|
|
2096
|
+
}
|
|
2097
|
+
if (t__namespace.isMemberExpression(expression)) {
|
|
2098
|
+
return mkText(expression);
|
|
2099
|
+
}
|
|
2100
|
+
if (t__namespace.isFunctionExpression(expression)) {
|
|
2101
|
+
return expression;
|
|
2102
|
+
}
|
|
2103
|
+
if (t__namespace.isCallExpression(expression)) {
|
|
2104
|
+
if (t__namespace.isCallExpression(expression)) {
|
|
2105
|
+
var b = expression.arguments;
|
|
2106
|
+
if (t__namespace.isMemberExpression(expression.callee)) {
|
|
2107
|
+
if (t__namespace.isIdentifier(expression.callee.property)) {
|
|
2108
|
+
if (expression.callee.property.name === 'map' || expression.callee.property.name === 'forEach') {
|
|
2109
|
+
if (missingListKey(b[0])) {
|
|
2110
|
+
warn('MJX003', 'List item has no "key". Rows are matched by the item object (primitive items by value), not by key, so a key does not change DOM reuse; a stable key such as `key={item.id}` is checked for duplicates (MJX202).', path, String(state.get('filename') ?? ''));
|
|
2111
|
+
}
|
|
2112
|
+
state.set('loop-waiter', expression.callee.object);
|
|
2113
|
+
return t__namespace.callExpression(id('sender.repeater'), [expression.callee.object, ...b]);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
if (t__namespace.isMemberExpression(expression.callee)) {
|
|
2119
|
+
return makeMemberCallChild(expression);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
if (t__namespace.isStringLiteral(expression)) {
|
|
2123
|
+
return mkText(expression);
|
|
2124
|
+
}
|
|
2125
|
+
if (t__namespace.isTemplateLiteral(expression) && expression.expressions.length > 0) {
|
|
2126
|
+
return t__namespace.arrowFunctionExpression([], expression);
|
|
2127
|
+
}
|
|
2128
|
+
return expression;
|
|
2129
|
+
}
|
|
2130
|
+
const childNode = path.node;
|
|
2131
|
+
if (t__namespace.isCallExpression(childNode))
|
|
2132
|
+
return childNode;
|
|
2133
|
+
if (path.isJSXElement())
|
|
2134
|
+
return ParseComponent(path, state);
|
|
2135
|
+
fail('MJX013', `Unsupported JSX child: ${path.type}.`, path);
|
|
2136
|
+
};
|
|
2137
|
+
const lowered = [];
|
|
2138
|
+
for (const child of paths) {
|
|
2139
|
+
const result = transformOne(child);
|
|
2140
|
+
if (result && !child.isJSXText())
|
|
2141
|
+
noteOrigin(result, child, originalCode);
|
|
2142
|
+
if (result == null || t__namespace.isJSXEmptyExpression(result))
|
|
2143
|
+
continue;
|
|
2144
|
+
lowered.push(result);
|
|
2145
|
+
}
|
|
2146
|
+
return lowered;
|
|
2147
|
+
};
|
|
2148
|
+
function id(name) {
|
|
2149
|
+
return t__namespace.identifier(name);
|
|
2150
|
+
}
|
|
2151
|
+
const isChildsSlot = (e) => (t__namespace.isMemberExpression(e) && !e.computed && t__namespace.isIdentifier(e.property) && e.property.name === 'childs')
|
|
2152
|
+
|| (t__namespace.isIdentifier(e) && e.name === 'childs');
|
|
2153
|
+
/** `??` / `||` mi? (C1: bunlar `&&` gibi `when`'e çevrilmemeli) */
|
|
2154
|
+
const isCoalesceLogical = (e) => t__namespace.isLogicalExpression(e) && (e.operator === '??' || e.operator === '||');
|
|
2155
|
+
const coalesceFn = (cx) => {
|
|
2156
|
+
const l = t__namespace.identifier('__l');
|
|
2157
|
+
return t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([
|
|
2158
|
+
t__namespace.variableDeclaration('let', [t__namespace.variableDeclarator(t__namespace.identifier('__l'))]),
|
|
2159
|
+
t__namespace.tryStatement(t__namespace.blockStatement([t__namespace.expressionStatement(t__namespace.assignmentExpression('=', l, cx.left))]), t__namespace.catchClause(null, t__namespace.blockStatement([t__namespace.expressionStatement(t__namespace.assignmentExpression('=', t__namespace.identifier('__l'), t__namespace.identifier('undefined')))]))),
|
|
2160
|
+
t__namespace.returnStatement(t__namespace.logicalExpression(cx.operator, t__namespace.identifier('__l'), cx.right))
|
|
2161
|
+
]));
|
|
2162
|
+
};
|
|
2163
|
+
const makeCoalesceChild = (cx) => t__namespace.callExpression(id('sender.bindings.method'), [coalesceFn(cx)]);
|
|
2164
|
+
const makeMemberCallChild = (call) => t__namespace.callExpression(id('sender.bindings.method'), [t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([
|
|
2165
|
+
t__namespace.tryStatement(t__namespace.blockStatement([t__namespace.returnStatement(call)]), t__namespace.catchClause(null, t__namespace.blockStatement([t__namespace.returnStatement(t__namespace.identifier('undefined'))])))
|
|
2166
|
+
]))]);
|
|
2167
|
+
/** JSXElement'in etiket adı (yalnızca basit tanımlayıcı; `<Foo.Bar>` için null). */
|
|
2168
|
+
const jsxTagName = (p) => {
|
|
2169
|
+
const n = p.node.openingElement.name;
|
|
2170
|
+
return t__namespace.isJSXIdentifier(n) ? n.name : null;
|
|
2171
|
+
};
|
|
2172
|
+
const isInsideSvgTree = (path) => {
|
|
2173
|
+
let p = path.parentPath;
|
|
2174
|
+
while (p) {
|
|
2175
|
+
if (p.isJSXElement()) {
|
|
2176
|
+
const n = jsxTagName(p);
|
|
2177
|
+
if (n === 'foreignObject')
|
|
2178
|
+
return false;
|
|
2179
|
+
if (n === 'svg' || (n && svgTags.includes(n) && !htmlTags.includes(n)))
|
|
2180
|
+
return true;
|
|
2181
|
+
}
|
|
2182
|
+
p = p.parentPath;
|
|
2183
|
+
}
|
|
2184
|
+
return false;
|
|
2185
|
+
};
|
|
2186
|
+
const listSource = (src) => {
|
|
2187
|
+
if (t__namespace.isArrowFunctionExpression(src) || t__namespace.isFunctionExpression(src))
|
|
2188
|
+
return src;
|
|
2189
|
+
if (t__namespace.isMemberExpression(src) || t__namespace.isIdentifier(src) || t__namespace.isLogicalExpression(src) || t__namespace.isBinaryExpression(src) || t__namespace.isCallExpression(src)) {
|
|
2190
|
+
return returnIfStatement(src, true, t__namespace.arrayExpression());
|
|
2191
|
+
}
|
|
2192
|
+
return t__namespace.arrowFunctionExpression([], src);
|
|
2193
|
+
};
|
|
2194
|
+
const listRender = (args) => {
|
|
2195
|
+
const render = args[1];
|
|
2196
|
+
const thisArg = args[2];
|
|
2197
|
+
if (!thisArg || !t__namespace.isExpression(thisArg))
|
|
2198
|
+
return render;
|
|
2199
|
+
return t__namespace.callExpression(t__namespace.memberExpression(render, t__namespace.identifier('bind')), [thisArg]);
|
|
2200
|
+
};
|
|
2201
|
+
const extractMemberExpressionFromFunction = (exp) => {
|
|
2202
|
+
if (t__namespace.isArrowFunctionExpression(exp) && exp.params.length === 0 && t__namespace.isMemberExpression(exp.body)) {
|
|
2203
|
+
return exp.body;
|
|
2204
|
+
}
|
|
2205
|
+
if ((t__namespace.isArrowFunctionExpression(exp) || t__namespace.isFunctionExpression(exp)) && exp.params.length === 0 && t__namespace.isBlockStatement(exp.body)) {
|
|
2206
|
+
const statements = exp.body.body;
|
|
2207
|
+
if (statements.length === 1 && t__namespace.isReturnStatement(statements[0]) && statements[0].argument && t__namespace.isMemberExpression(statements[0].argument)) {
|
|
2208
|
+
return statements[0].argument;
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
return null;
|
|
2212
|
+
};
|
|
2213
|
+
const splitMemberExpression = (exp) => {
|
|
2214
|
+
if (t__namespace.isIdentifier(exp.property)) {
|
|
2215
|
+
return {
|
|
2216
|
+
object: exp.object,
|
|
2217
|
+
property: exp.property.name
|
|
2218
|
+
};
|
|
2219
|
+
}
|
|
2220
|
+
return null;
|
|
2221
|
+
};
|
|
2222
|
+
const mkText = (exp) => {
|
|
2223
|
+
var a1;
|
|
2224
|
+
const childProbe = (t__namespace.isIdentifier(exp) || t__namespace.isMemberExpression(exp)) ? t__namespace.arrowFunctionExpression([], exp) : null;
|
|
2225
|
+
if (t__namespace.isStringLiteral(exp)) {
|
|
2226
|
+
a1 = t__namespace.callExpression(id('sender.setText'), [exp]);
|
|
2227
|
+
}
|
|
2228
|
+
else if (t__namespace.isMemberExpression(exp)) {
|
|
2229
|
+
const split = splitMemberExpression(exp);
|
|
2230
|
+
if (split) {
|
|
2231
|
+
a1 = t__namespace.callExpression(id('sender.bindings.add'), [
|
|
2232
|
+
t__namespace.stringLiteral("textContent"),
|
|
2233
|
+
split.object,
|
|
2234
|
+
t__namespace.stringLiteral(split.property)
|
|
2235
|
+
]);
|
|
2236
|
+
}
|
|
2237
|
+
else {
|
|
2238
|
+
var ifStatement = findIfStatements(exp);
|
|
2239
|
+
var mx = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', exp), t__namespace.stringLiteral('function'));
|
|
2240
|
+
var rtrn = t__namespace.returnStatement(t__namespace.conditionalExpression(mx, t__namespace.callExpression(exp, []), t__namespace.arrowFunctionExpression([], exp)));
|
|
2241
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
2242
|
+
var kx = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
2243
|
+
a1 = t__namespace.callExpression(id('sender.bindings.add'), [t__namespace.stringLiteral("textContent"), kx]);
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
else if (t__namespace.isObjectExpression(exp) || t__namespace.isIdentifier(exp)) {
|
|
2247
|
+
var ifStatement = findIfStatements(exp);
|
|
2248
|
+
var mx = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', exp), t__namespace.stringLiteral('function'));
|
|
2249
|
+
var rtrn = t__namespace.returnStatement(t__namespace.conditionalExpression(mx, t__namespace.callExpression(exp, []), t__namespace.arrowFunctionExpression([], exp)));
|
|
2250
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
2251
|
+
var kx = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
2252
|
+
a1 = t__namespace.callExpression(id('sender.bindings.add'), [t__namespace.stringLiteral("textContent"), kx]);
|
|
2253
|
+
}
|
|
2254
|
+
else if (t__namespace.isArrowFunctionExpression(exp)) {
|
|
2255
|
+
const memberExp = extractMemberExpressionFromFunction(exp);
|
|
2256
|
+
if (memberExp) {
|
|
2257
|
+
const split = splitMemberExpression(memberExp);
|
|
2258
|
+
if (split) {
|
|
2259
|
+
a1 = t__namespace.callExpression(id('sender.bindings.add'), [
|
|
2260
|
+
t__namespace.stringLiteral("textContent"),
|
|
2261
|
+
split.object,
|
|
2262
|
+
t__namespace.stringLiteral(split.property)
|
|
2263
|
+
]);
|
|
2264
|
+
}
|
|
2265
|
+
else {
|
|
2266
|
+
var ifStatement = findIfStatements(exp);
|
|
2267
|
+
var mx = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', exp), t__namespace.stringLiteral('function'));
|
|
2268
|
+
var rtrn = t__namespace.returnStatement(t__namespace.conditionalExpression(mx, t__namespace.callExpression(exp, []), t__namespace.arrowFunctionExpression([], exp)));
|
|
2269
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
2270
|
+
var kx = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
2271
|
+
a1 = t__namespace.callExpression(id('sender.bindings.add'), [t__namespace.stringLiteral("textContent"), kx]);
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
else {
|
|
2275
|
+
var ifStatement = findIfStatements(exp);
|
|
2276
|
+
var mx = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', exp), t__namespace.stringLiteral('function'));
|
|
2277
|
+
var rtrn = t__namespace.returnStatement(t__namespace.conditionalExpression(mx, t__namespace.callExpression(exp, []), t__namespace.arrowFunctionExpression([], exp)));
|
|
2278
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
2279
|
+
var kx = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
2280
|
+
a1 = t__namespace.callExpression(id('sender.bindings.add'), [t__namespace.stringLiteral("textContent"), kx]);
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
else if (isCoalesceLogical(exp)) {
|
|
2284
|
+
a1 = t__namespace.callExpression(id('sender.bindings.add'), [t__namespace.stringLiteral("textContent"), coalesceFn(exp)]);
|
|
2285
|
+
}
|
|
2286
|
+
else if (t__namespace.isLogicalExpression(exp)) {
|
|
2287
|
+
var ifStatement = findIfStatements(exp.left);
|
|
2288
|
+
if (t__namespace.isFunction(exp.left) || t__namespace.isArrowFunctionExpression(exp.left) || t__namespace.isFunctionExpression(exp.left) || t__namespace.isFunctionDeclaration(exp.left)) {
|
|
2289
|
+
var mx = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', exp.left), t__namespace.stringLiteral('function'));
|
|
2290
|
+
var rtrn = t__namespace.returnStatement(t__namespace.conditionalExpression(mx, t__namespace.callExpression(exp.left, []), t__namespace.arrowFunctionExpression([], exp.left)));
|
|
2291
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
2292
|
+
var kx = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
2293
|
+
if (!t__namespace.isFunctionDeclaration(exp.right) && !t__namespace.isArrowFunctionExpression(exp.right)) {
|
|
2294
|
+
t__namespace.ifStatement(t__namespace.identifier('__v'), t__namespace.blockStatement([t__namespace.returnStatement(exp.right)]), t__namespace.blockStatement([t__namespace.returnStatement(t__namespace.callExpression(t__namespace.identifier(motifComponent()), [t__namespace.objectExpression([])]))]));
|
|
2295
|
+
exp.right = t__namespace.arrowFunctionExpression([t__namespace.identifier("__v")], t__namespace.blockStatement([t__namespace.returnStatement(exp.right)]));
|
|
2296
|
+
}
|
|
2297
|
+
var a1 = t__namespace.callExpression(id('sender.bindings.when'), [kx, exp.right]);
|
|
2298
|
+
}
|
|
2299
|
+
else {
|
|
2300
|
+
// var rtrn = t.returnStatement(t.arrowFunctionExpression([], exp.left));
|
|
2301
|
+
// //var rtrns = t.ifStatement(ifStatement!, t.blockStatement([rtrn]));
|
|
2302
|
+
// var kx = t.arrowFunctionExpression([], t.blockStatement([rtrn]));
|
|
2303
|
+
// if (!t.isFunctionDeclaration(exp.right) && !t.isArrowFunctionExpression(exp.right)) {
|
|
2304
|
+
// var ifst = t.ifStatement(t.identifier('val'),
|
|
2305
|
+
// var a1 = t.callExpression(id('sender.bind.logic'), [kx, exp.right]);
|
|
2306
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([t__namespace.returnStatement(exp.left)]));
|
|
2307
|
+
var tryStatement = t__namespace.tryStatement(t__namespace.blockStatement([rtrns]), t__namespace.catchClause(null, t__namespace.blockStatement([t__namespace.returnStatement(t__namespace.nullLiteral())])), null);
|
|
2308
|
+
var kx = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([tryStatement]));
|
|
2309
|
+
if (!t__namespace.isFunctionDeclaration(exp.right) && !t__namespace.isArrowFunctionExpression(exp.right)) {
|
|
2310
|
+
t__namespace.ifStatement(t__namespace.identifier('__v'), t__namespace.blockStatement([t__namespace.returnStatement(exp.right)]), t__namespace.blockStatement([t__namespace.returnStatement(t__namespace.callExpression(t__namespace.identifier(motifComponent()), [t__namespace.objectExpression([])]))]));
|
|
2311
|
+
exp.right = t__namespace.arrowFunctionExpression([t__namespace.identifier("__v")], t__namespace.blockStatement([t__namespace.returnStatement(exp.right)]));
|
|
2312
|
+
}
|
|
2313
|
+
var a1 = t__namespace.callExpression(id('sender.bindings.when'), [kx, exp.right]);
|
|
2314
|
+
}
|
|
2315
|
+
// var mx = t.binaryExpression('===', t.unaryExpression('typeof', exp.left), t.stringLiteral('function'));
|
|
2316
|
+
// var rtrn = t.returnStatement(t.conditionalExpression(mx, t.callExpression(exp.left, []), t.arrowFunctionExpression([], exp.left)));
|
|
2317
|
+
// var rtrns = t.ifStatement(ifStatement!, t.blockStatement([rtrn]));
|
|
2318
|
+
// var kx = t.arrowFunctionExpression([], t.blockStatement([rtrns]));
|
|
2319
|
+
// if (!t.isFunctionDeclaration(exp.right) && !t.isArrowFunctionExpression(exp.right)) {
|
|
2320
|
+
// var ifst = t.ifStatement(t.identifier('val'),
|
|
2321
|
+
// var a1 = t.callExpression(id('sender.bind.logic'), [kx, exp.right]);
|
|
2322
|
+
}
|
|
2323
|
+
else if (t__namespace.isBinaryExpression(exp)) {
|
|
2324
|
+
var ifStatement = findIfStatements(exp);
|
|
2325
|
+
var mx = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', exp), t__namespace.stringLiteral('function'));
|
|
2326
|
+
var rtrn = t__namespace.returnStatement(t__namespace.conditionalExpression(mx, t__namespace.callExpression(exp, []), t__namespace.arrowFunctionExpression([], exp)));
|
|
2327
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
2328
|
+
var kx = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
2329
|
+
a1 = t__namespace.callExpression(id('sender.bindings.add'), [t__namespace.stringLiteral("textContent"), kx]);
|
|
2330
|
+
}
|
|
2331
|
+
else {
|
|
2332
|
+
var ifStatement = findIfStatements(exp);
|
|
2333
|
+
var mx = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', exp), t__namespace.stringLiteral('function'));
|
|
2334
|
+
var rtrn = t__namespace.returnStatement(t__namespace.conditionalExpression(mx, t__namespace.callExpression(exp, []), t__namespace.arrowFunctionExpression([], exp)));
|
|
2335
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
2336
|
+
var kx = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
2337
|
+
a1 = t__namespace.callExpression(id('sender.bindings.add'), [t__namespace.stringLiteral("textContent"), kx]);
|
|
2338
|
+
}
|
|
2339
|
+
var arrayBody = t__namespace.arrowFunctionExpression([id('sender')], t__namespace.blockStatement([t__namespace.expressionStatement(a1)]));
|
|
2340
|
+
const bodyProps = [t__namespace.objectProperty(id('initializeComponent'), arrayBody)];
|
|
2341
|
+
if (childProbe) {
|
|
2342
|
+
bodyProps.push(t__namespace.objectProperty(id('__childExpr'), childProbe));
|
|
2343
|
+
}
|
|
2344
|
+
var body = t__namespace.objectExpression(bodyProps);
|
|
2345
|
+
return t__namespace.callExpression(id(motifComponent()), [t__namespace.stringLiteral('text'), body]);
|
|
2346
|
+
};
|
|
2347
|
+
/** `sender.bindings.*` çağrısı olarak gelen çocuk (ternary, switchCase, method, list…). */
|
|
2348
|
+
function explainBindingCall(cx, fileName, where) {
|
|
2349
|
+
const name = t__namespace.isIdentifier(cx.callee) ? cx.callee.name.replace(/^sender\.bindings\./, '') : '';
|
|
2350
|
+
const suffix = where ? ` — ${where}` : '';
|
|
2351
|
+
const lowered = codeOf(cx) + suffix;
|
|
2352
|
+
if (name === 'ternary') {
|
|
2353
|
+
explainChild(cx, fileName, { site: 'child', shape: 'ternary', lowered, reactive: 'live', deps: DEPS.cond, note: 'Frame: the first branch is built SYNCHRONOUSLY, later switches in a microtask; a new instance on every switch' });
|
|
2354
|
+
}
|
|
2355
|
+
else if (name === 'switchCase') {
|
|
2356
|
+
explainChild(cx, fileName, { site: 'child', shape: 'switch', lowered, reactive: 'live', deps: 'fields read in the discriminant getter; branches are rebuilt inside a Frame' });
|
|
2357
|
+
}
|
|
2358
|
+
else if (name === 'method') {
|
|
2359
|
+
explainChild(cx, fileName, { site: 'child', shape: 'method', lowered, reactive: 'live', deps: DEPS.getter, note: 'reactive text if the result is text, a Frame if it is a component' });
|
|
2360
|
+
}
|
|
2361
|
+
else if (name === 'list') {
|
|
2362
|
+
explainChild(cx, fileName, { site: 'child', shape: 'list', lowered, reactive: 'live', deps: DEPS.list });
|
|
2363
|
+
}
|
|
2364
|
+
else if (name === 'when') {
|
|
2365
|
+
explainChild(cx, fileName, { site: 'child', shape: 'when', lowered, reactive: 'live', deps: DEPS.cond });
|
|
2366
|
+
}
|
|
2367
|
+
else {
|
|
2368
|
+
explainChild(cx, fileName, { site: 'child', shape: name || 'binding', lowered, reactive: 'live', deps: DEPS.getter });
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
/** `const _comp = cx; sender.controls.add(_comp)` yoluyla yerleştirilen çocuk. */
|
|
2372
|
+
function explainPlaced(cx, fileName, where) {
|
|
2373
|
+
const suffix = where ? ` — ${where}` : '';
|
|
2374
|
+
if (t__namespace.isCallExpression(cx) && t__namespace.isIdentifier(cx.callee) && cx.callee.name === motifComponent() && cx.arguments.length === 1 && t__namespace.isObjectExpression(cx.arguments[0])) {
|
|
2375
|
+
const init = cx.arguments[0].properties.find(p => t__namespace.isObjectProperty(p) && t__namespace.isIdentifier(p.key) && p.key.name === 'initializeComponent');
|
|
2376
|
+
const st = init && t__namespace.isArrowFunctionExpression(init.value) && t__namespace.isBlockStatement(init.value.body) ? init.value.body.body[0] : null;
|
|
2377
|
+
if (st && t__namespace.isExpressionStatement(st) && t__namespace.isCallExpression(st.expression) && t__namespace.isIdentifier(st.expression.callee) && st.expression.callee.name === 'sender.bindings.list') {
|
|
2378
|
+
explainChild(cx, fileName, { site: 'child', shape: 'list', lowered: codeOf(st.expression) + suffix, reactive: 'live', deps: DEPS.list, note: 'rows are matched by the item object (primitive items by value), not by key; a key is only checked for duplicates (MJX202)' });
|
|
2379
|
+
return;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
const text = describeTextNode(cx);
|
|
2383
|
+
if (text) {
|
|
2384
|
+
explainChild(cx, fileName, { site: 'child', shape: text.shape, lowered: text.lowered + suffix, reactive: text.reactive, deps: text.deps, note: text.note });
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
if (t__namespace.isCallExpression(cx) && t__namespace.isIdentifier(cx.callee) && (cx.callee.name === motifComponent() || cx.callee.name === motifFragment())) {
|
|
2388
|
+
const tagArg = cx.arguments[0];
|
|
2389
|
+
const tagName = t__namespace.isStringLiteral(tagArg) ? `<${tagArg.value}>` : t__namespace.isIdentifier(tagArg) || t__namespace.isMemberExpression(tagArg) ? `<${codeOf(tagArg)}>` : 'fragment';
|
|
2390
|
+
explainChild(cx, fileName, { site: 'element', shape: t__namespace.isStringLiteral(tagArg) ? 'element.dom' : cx.callee.name === motifFragment() ? 'fragment' : 'element.component', lowered: `sender.controls.add(${cx.callee.name}(${tagName}, …))${suffix}`, reactive: 'static', deps: 'none — the element itself is built once; bindings inside it are their own effects' });
|
|
2391
|
+
return;
|
|
2392
|
+
}
|
|
2393
|
+
explainChild(cx, fileName, { site: 'child', shape: 'value', lowered: `sender.controls.add(${codeOf(cx)})${suffix}`, reactive: 'once', deps: DEPS.once, note: 'the raw expression is placed once (components/arrays/undefined are filtered)' });
|
|
2394
|
+
}
|
|
2395
|
+
function makeInitializeComponentProp(statements, userInit) {
|
|
2396
|
+
if (statements.length > 0) {
|
|
2397
|
+
const compiled = t__namespace.arrowFunctionExpression([id('sender')], t__namespace.blockStatement([...statements]));
|
|
2398
|
+
return t__namespace.objectProperty(t__namespace.identifier('initializeComponent'), userInit ? t__namespace.arrayExpression([userInit, compiled]) : compiled);
|
|
2399
|
+
}
|
|
2400
|
+
return userInit ? t__namespace.objectProperty(t__namespace.identifier('initializeComponent'), userInit) : null;
|
|
2401
|
+
}
|
|
2402
|
+
function ParseComponent(path, state) {
|
|
2403
|
+
const props = path.get('openingElement').get('attributes');
|
|
2404
|
+
var tag = getTag(path);
|
|
2405
|
+
let isSvgHere = false;
|
|
2406
|
+
if (t__namespace.isStringLiteral(tag)) {
|
|
2407
|
+
const tagName = tag.value;
|
|
2408
|
+
if (tagName === 'svg')
|
|
2409
|
+
isSvgHere = true;
|
|
2410
|
+
else if (svgTags.includes(tagName) && (!htmlTags.includes(tagName) || isInsideSvgTree(path)))
|
|
2411
|
+
isSvgHere = true;
|
|
2412
|
+
}
|
|
2413
|
+
const { htmlProps, eventProps, objectExpression, componentEvents, directives, preDirectives, thisStatement, spreadProps, userInit } = getProps(props, path, state);
|
|
2414
|
+
const fileName = String(state.get('filename') ?? '');
|
|
2415
|
+
const isComponentTag = !t__namespace.isStringLiteral(tag);
|
|
2416
|
+
const children = getChildren(path.get('children'), state);
|
|
2417
|
+
if (isSvgHere) {
|
|
2418
|
+
objectExpression.push(t__namespace.objectProperty(t__namespace.identifier('__isSvgElement'), t__namespace.booleanLiteral(true)));
|
|
2419
|
+
}
|
|
2420
|
+
var callArgs = [];
|
|
2421
|
+
let statements = [];
|
|
2422
|
+
var childs = [];
|
|
2423
|
+
if (thisStatement.length > 0) {
|
|
2424
|
+
statements.push(thisStatement[0]);
|
|
2425
|
+
}
|
|
2426
|
+
children.forEach(exp => {
|
|
2427
|
+
if (t__namespace.isExpression(exp)) {
|
|
2428
|
+
if (exp !== null) {
|
|
2429
|
+
if (t__namespace.isCallExpression(exp) && t__namespace.isIdentifier(exp.callee) && exp.callee.name === 'sender.repeater') {
|
|
2430
|
+
var callerFn = t__namespace.objectProperty(t__namespace.identifier('initializeComponent'), t__namespace.arrowFunctionExpression([id('sender')], t__namespace.blockStatement([t__namespace.expressionStatement(t__namespace.callExpression(id('sender.bindings.list'), [
|
|
2431
|
+
listSource(exp.arguments[0]),
|
|
2432
|
+
listRender(exp.arguments)
|
|
2433
|
+
]))])));
|
|
2434
|
+
var cex = t__namespace.callExpression(id('_mc'), [t__namespace.objectExpression([callerFn])]);
|
|
2435
|
+
transferOrigin(exp, cex);
|
|
2436
|
+
childs.push(cex);
|
|
2437
|
+
}
|
|
2438
|
+
else {
|
|
2439
|
+
childs.push(exp);
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
});
|
|
2444
|
+
if (htmlProps.length > 0) {
|
|
2445
|
+
htmlProps.forEach(d => {
|
|
2446
|
+
statements.push(d);
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2449
|
+
if (eventProps.length > 0) {
|
|
2450
|
+
eventProps.forEach(d => {
|
|
2451
|
+
statements.push(d);
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
if (directives.length > 0) {
|
|
2455
|
+
directives.forEach(d => {
|
|
2456
|
+
statements.push(d);
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
var bodyExpression = t__namespace.objectExpression([]);
|
|
2460
|
+
var existThis = false;
|
|
2461
|
+
if (childs.length > 0) {
|
|
2462
|
+
childs.forEach(cx => {
|
|
2463
|
+
if (t__namespace.isCallExpression(cx) && t__namespace.isIdentifier(cx.callee) && cx.callee.name.startsWith('sender.bindings.')) {
|
|
2464
|
+
statements.push(t__namespace.expressionStatement(cx));
|
|
2465
|
+
explainBindingCall(cx, fileName);
|
|
2466
|
+
}
|
|
2467
|
+
else if (t__namespace.isArrayExpression(cx)) {
|
|
2468
|
+
statements.push(t__namespace.expressionStatement(t__namespace.callExpression(id('sender.controls.add'), [cx])));
|
|
2469
|
+
explainChild(cx, fileName, { site: 'child', shape: 'array', lowered: statements[statements.length - 1], reactive: 'static', deps: DEPS.none, note: 'the component array is placed once' });
|
|
2470
|
+
}
|
|
2471
|
+
else if (t__namespace.isFunctionExpression(cx)) {
|
|
2472
|
+
fail('MJX008', 'A function expression cannot be a JSX child; use an arrow function: {() => …}.', path);
|
|
2473
|
+
}
|
|
2474
|
+
// else if (t.isArrowFunctionExpression(cx)) {
|
|
2475
|
+
else if (t__namespace.isAssignmentExpression(cx)) {
|
|
2476
|
+
statements.push(t__namespace.expressionStatement(cx));
|
|
2477
|
+
}
|
|
2478
|
+
else if (isCoalesceLogical(cx)) {
|
|
2479
|
+
// C1: `{a ?? b}` / `{a || b}` — `when` DEĞİL
|
|
2480
|
+
statements.push(t__namespace.expressionStatement(makeCoalesceChild(cx)));
|
|
2481
|
+
explainChild(cx, fileName, { site: 'child', shape: 'coalesce', lowered: statements[statements.length - 1], reactive: 'live', deps: DEPS.getter, note: 'reactive text if the result is text, a Frame if it is a component' });
|
|
2482
|
+
}
|
|
2483
|
+
else if (t__namespace.isLogicalExpression(cx)) {
|
|
2484
|
+
var ifStatement = findIfStatements(cx.left);
|
|
2485
|
+
if (t__namespace.isFunction(cx.left) || t__namespace.isArrowFunctionExpression(cx.left) || t__namespace.isFunctionExpression(cx.left) || t__namespace.isFunctionDeclaration(cx.left)) {
|
|
2486
|
+
var mx = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', cx.left), t__namespace.stringLiteral('function'));
|
|
2487
|
+
var rtrn = t__namespace.returnStatement(t__namespace.conditionalExpression(mx, t__namespace.callExpression(cx.left, []), t__namespace.arrowFunctionExpression([], cx.left)));
|
|
2488
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
2489
|
+
var kx = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
2490
|
+
var tryStatement = t__namespace.tryStatement(t__namespace.blockStatement([rtrns]), null, null);
|
|
2491
|
+
if (!t__namespace.isFunctionDeclaration(cx.right) && !t__namespace.isArrowFunctionExpression(cx.right)) {
|
|
2492
|
+
t__namespace.ifStatement(t__namespace.identifier('__v'), t__namespace.blockStatement([t__namespace.returnStatement(cx.right)]), t__namespace.blockStatement([t__namespace.returnStatement(t__namespace.callExpression(t__namespace.identifier(motifComponent()), [t__namespace.objectExpression([])]))]));
|
|
2493
|
+
cx.right = t__namespace.arrowFunctionExpression([t__namespace.identifier("__v")], t__namespace.blockStatement([t__namespace.returnStatement(cx.right)]));
|
|
2494
|
+
}
|
|
2495
|
+
var a1 = t__namespace.callExpression(id('sender.bindings.when'), [kx, cx.right]);
|
|
2496
|
+
}
|
|
2497
|
+
else {
|
|
2498
|
+
// var mx = t.binaryExpression('===', t.unaryExpression('typeof', cx.left), t.stringLiteral('function'));
|
|
2499
|
+
// var rtrn = t.returnStatement(t.conditionalExpression(mx, t.callExpression(cx.left, []), t.arrowFunctionExpression([], cx.left)));
|
|
2500
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([t__namespace.returnStatement(cx.left)]));
|
|
2501
|
+
var tryStatement = t__namespace.tryStatement(t__namespace.blockStatement([rtrns]), t__namespace.catchClause(null, t__namespace.blockStatement([t__namespace.returnStatement(t__namespace.nullLiteral())])), null);
|
|
2502
|
+
var kx = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([tryStatement]));
|
|
2503
|
+
if (!t__namespace.isFunctionDeclaration(cx.right) && !t__namespace.isArrowFunctionExpression(cx.right)) {
|
|
2504
|
+
t__namespace.ifStatement(t__namespace.identifier('__v'), t__namespace.blockStatement([t__namespace.returnStatement(cx.right)]), t__namespace.blockStatement([t__namespace.returnStatement(t__namespace.callExpression(t__namespace.identifier(motifComponent()), [t__namespace.objectExpression([])]))]));
|
|
2505
|
+
cx.right = t__namespace.arrowFunctionExpression([t__namespace.identifier("__v")], t__namespace.blockStatement([t__namespace.returnStatement(cx.right)]));
|
|
2506
|
+
}
|
|
2507
|
+
var a1 = t__namespace.callExpression(id('sender.bindings.when'), [kx, cx.right]);
|
|
2508
|
+
}
|
|
2509
|
+
// var mx = t.binaryExpression('===', t.unaryExpression('typeof', cx.left), t.stringLiteral('function'));
|
|
2510
|
+
// var rtrn = t.returnStatement(t.conditionalExpression(mx, t.callExpression(cx.left, []), t.arrowFunctionExpression([], cx.left)));
|
|
2511
|
+
// var rtrns = t.ifStatement(ifStatement!, t.blockStatement([rtrn]), t.blockStatement([t.returnStatement(t.arrowFunctionExpression([], t.nullLiteral()))]));
|
|
2512
|
+
// var kx = t.arrowFunctionExpression([], t.blockStatement([rtrns]));
|
|
2513
|
+
// if (!t.isFunctionDeclaration(cx.right) && !t.isArrowFunctionExpression(cx.right)) {
|
|
2514
|
+
// var ifst = t.ifStatement(t.identifier('val'),
|
|
2515
|
+
// var a1 = t.callExpression(id('sender.bind.logic'), [kx, cx.right]);
|
|
2516
|
+
statements.push(t__namespace.expressionStatement(a1));
|
|
2517
|
+
explainChild(cx, fileName, { site: 'child', shape: 'when', lowered: a1, reactive: 'live', deps: DEPS.cond, note: 'JS truthiness; false → never built, a NEW instance is built on each switch to true. Deliberate alternative: x-wait' });
|
|
2518
|
+
}
|
|
2519
|
+
else {
|
|
2520
|
+
if (t__namespace.isStringLiteral(tag)) {
|
|
2521
|
+
if (t__namespace.isCallExpression(cx) && t__namespace.isIdentifier(cx.callee) && cx.callee.name === 'sender.motif.on' && existThis == false) {
|
|
2522
|
+
existThis = true;
|
|
2523
|
+
}
|
|
2524
|
+
if (t__namespace.isCallExpression(cx) && t__namespace.isIdentifier(cx.callee) && cx.callee.name === 'sender.bindings.list') {
|
|
2525
|
+
statements.push(t__namespace.expressionStatement(cx));
|
|
2526
|
+
}
|
|
2527
|
+
else {
|
|
2528
|
+
if (((t__namespace.isFunctionExpression(cx)) && t__namespace.isJSXElement(cx.returnType)) || ((t__namespace.isArrowFunctionExpression(cx)) && t__namespace.isJSXElement(cx.returnType))) {
|
|
2529
|
+
statements.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.bindings.method'), [cx])));
|
|
2530
|
+
explainChild(cx, fileName, { site: 'child', shape: 'method', lowered: statements[statements.length - 1], reactive: 'live', deps: DEPS.getter, note: 'reactive text if the result is text, a Frame if it is a component (the instance is rebuilt on every change)' });
|
|
2531
|
+
}
|
|
2532
|
+
else if ((t__namespace.isArrowFunctionExpression(cx))) {
|
|
2533
|
+
statements.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.bindings.method'), [cx])));
|
|
2534
|
+
explainChild(cx, fileName, { site: 'child', shape: 'method', lowered: statements[statements.length - 1], reactive: 'live', deps: DEPS.getter, note: 'reactive text if the result is text, a Frame if it is a component (the instance is rebuilt on every change)' });
|
|
2535
|
+
}
|
|
2536
|
+
else {
|
|
2537
|
+
var uid = path.scope.generateUid('_comp');
|
|
2538
|
+
statements.push(t__namespace.variableDeclaration('const', [t__namespace.variableDeclarator(t__namespace.identifier(uid), cx)]));
|
|
2539
|
+
statements.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.controls.add'), [t__namespace.identifier(uid)])));
|
|
2540
|
+
explainPlaced(cx, fileName);
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
});
|
|
2546
|
+
}
|
|
2547
|
+
if (isComponentTag) {
|
|
2548
|
+
childs.forEach(cx => {
|
|
2549
|
+
if (t__namespace.isCallExpression(cx) && t__namespace.isIdentifier(cx.callee) && cx.callee.name.startsWith('sender.bindings.')) {
|
|
2550
|
+
explainBindingCall(cx, fileName, 'inside the childs slot');
|
|
2551
|
+
return;
|
|
2552
|
+
}
|
|
2553
|
+
if (t__namespace.isLogicalExpression(cx)) {
|
|
2554
|
+
explainChild(cx, fileName, { site: 'child', shape: 'when', lowered: 'bindings.when(…) — inside the childs slot', reactive: 'live', deps: DEPS.cond });
|
|
2555
|
+
return;
|
|
2556
|
+
}
|
|
2557
|
+
if (t__namespace.isArrowFunctionExpression(cx)) {
|
|
2558
|
+
explainChild(cx, fileName, { site: 'child', shape: 'method', lowered: 'childs: [fn] — bindings.method when the component places it', reactive: 'live', deps: DEPS.getter });
|
|
2559
|
+
return;
|
|
2560
|
+
}
|
|
2561
|
+
explainPlaced(cx, fileName, 'childs: […] — the component places it with {this.childs}');
|
|
2562
|
+
});
|
|
2563
|
+
}
|
|
2564
|
+
if (t__namespace.isStringLiteral(tag)) {
|
|
2565
|
+
let preStatements = [];
|
|
2566
|
+
if (preDirectives.length > 0) {
|
|
2567
|
+
preStatements.push(...preDirectives);
|
|
2568
|
+
}
|
|
2569
|
+
if (preStatements.length > 0) {
|
|
2570
|
+
var preconfigProp = t__namespace.objectProperty(t__namespace.identifier('preconfig'), t__namespace.arrowFunctionExpression([id('sender')], t__namespace.blockStatement([...preStatements])));
|
|
2571
|
+
bodyExpression.properties.push(preconfigProp);
|
|
2572
|
+
}
|
|
2573
|
+
if (componentEvents.length > 0) {
|
|
2574
|
+
bodyExpression.properties.push(...componentEvents);
|
|
2575
|
+
}
|
|
2576
|
+
if (objectExpression.length > 0) {
|
|
2577
|
+
// var expr = t.objectProperty(t.identifier('props'), t.objectExpression(objectExpression));
|
|
2578
|
+
bodyExpression.properties.push(...objectExpression);
|
|
2579
|
+
}
|
|
2580
|
+
if (spreadProps.length > 0) {
|
|
2581
|
+
bodyExpression.properties.push(...spreadProps);
|
|
2582
|
+
}
|
|
2583
|
+
const initProp = makeInitializeComponentProp(statements, userInit);
|
|
2584
|
+
if (initProp) {
|
|
2585
|
+
bodyExpression.properties.push(initProp);
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
else {
|
|
2589
|
+
var tts = t__namespace.objectProperty(id('childs'), t__namespace.arrayExpression(childs));
|
|
2590
|
+
if (objectExpression.length > 0) {
|
|
2591
|
+
//var expr = t.objectProperty(t.identifier('props'), t.objectExpression({ ...objectExpression, ...spreadProps }));
|
|
2592
|
+
bodyExpression.properties.push(...objectExpression);
|
|
2593
|
+
}
|
|
2594
|
+
if (spreadProps.length > 0) {
|
|
2595
|
+
bodyExpression.properties.push(...spreadProps);
|
|
2596
|
+
}
|
|
2597
|
+
var takedown = t__namespace.objectExpression([]);
|
|
2598
|
+
const initProp = makeInitializeComponentProp(statements, userInit);
|
|
2599
|
+
if (initProp) {
|
|
2600
|
+
takedown.properties.push(initProp);
|
|
2601
|
+
}
|
|
2602
|
+
if (preDirectives.length > 0) {
|
|
2603
|
+
let preStatements = [];
|
|
2604
|
+
preStatements.push(...preDirectives);
|
|
2605
|
+
var preconfigProp = t__namespace.objectProperty(t__namespace.identifier('preconfig'), t__namespace.arrowFunctionExpression([id('sender')], t__namespace.blockStatement([...preStatements])));
|
|
2606
|
+
takedown.properties.push(preconfigProp);
|
|
2607
|
+
}
|
|
2608
|
+
if (componentEvents.length > 0) {
|
|
2609
|
+
takedown.properties.push(...componentEvents);
|
|
2610
|
+
}
|
|
2611
|
+
var exp = t__namespace.objectProperty(id('runover'), takedown);
|
|
2612
|
+
bodyExpression.properties.push(exp);
|
|
2613
|
+
bodyExpression.properties.push(tts);
|
|
2614
|
+
}
|
|
2615
|
+
callArgs.push(bodyExpression);
|
|
2616
|
+
return t__namespace.callExpression(t__namespace.identifier(motifComponent()), [tag, ...callArgs]);
|
|
2617
|
+
}
|
|
2618
|
+
function ParseFrament(path, state) {
|
|
2619
|
+
const fileName = String(state.get('filename') ?? '');
|
|
2620
|
+
const children = getChildren(path.get('children'), state);
|
|
2621
|
+
var childs = [];
|
|
2622
|
+
var initBody = t__namespace.blockStatement([]);
|
|
2623
|
+
children.forEach(exp => {
|
|
2624
|
+
if (t__namespace.isExpression(exp)) {
|
|
2625
|
+
if (exp !== null) {
|
|
2626
|
+
var uid = path.scope.generateUid('_comp');
|
|
2627
|
+
if (t__namespace.isCallExpression(exp) && t__namespace.isIdentifier(exp.callee) && exp.callee.name === 'sender.repeater') {
|
|
2628
|
+
initBody.body.push(t__namespace.expressionStatement(t__namespace.callExpression(id('sender.bindings.list'), [listSource(exp.arguments[0]), listRender(exp.arguments)])));
|
|
2629
|
+
explainChild(exp, fileName, { site: 'child', shape: 'list', lowered: initBody.body[initBody.body.length - 1], reactive: 'live', deps: DEPS.list });
|
|
2630
|
+
}
|
|
2631
|
+
else if (isCoalesceLogical(exp)) {
|
|
2632
|
+
initBody.body.push(t__namespace.expressionStatement(makeCoalesceChild(exp)));
|
|
2633
|
+
explainChild(exp, fileName, { site: 'child', shape: 'coalesce', lowered: initBody.body[initBody.body.length - 1], reactive: 'live', deps: DEPS.getter });
|
|
2634
|
+
}
|
|
2635
|
+
else if (t__namespace.isLogicalExpression(exp)) {
|
|
2636
|
+
var ifStatement = findIfStatements(exp.left);
|
|
2637
|
+
var condFn;
|
|
2638
|
+
if (t__namespace.isFunction(exp.left) || t__namespace.isArrowFunctionExpression(exp.left) || t__namespace.isFunctionExpression(exp.left) || t__namespace.isFunctionDeclaration(exp.left)) {
|
|
2639
|
+
var mx = t__namespace.binaryExpression('===', t__namespace.unaryExpression('typeof', exp.left), t__namespace.stringLiteral('function'));
|
|
2640
|
+
var rtrn = t__namespace.returnStatement(t__namespace.conditionalExpression(mx, t__namespace.callExpression(exp.left, []), exp.left));
|
|
2641
|
+
var rtrns = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([rtrn]));
|
|
2642
|
+
condFn = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([rtrns]));
|
|
2643
|
+
}
|
|
2644
|
+
else {
|
|
2645
|
+
var rtrnsPlain = t__namespace.ifStatement(ifStatement, t__namespace.blockStatement([t__namespace.returnStatement(exp.left)]));
|
|
2646
|
+
var tryStatement = t__namespace.tryStatement(t__namespace.blockStatement([rtrnsPlain]), t__namespace.catchClause(null, t__namespace.blockStatement([t__namespace.returnStatement(t__namespace.nullLiteral())])), null);
|
|
2647
|
+
condFn = t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([tryStatement]));
|
|
2648
|
+
}
|
|
2649
|
+
if (!t__namespace.isFunctionDeclaration(exp.right) && !t__namespace.isArrowFunctionExpression(exp.right)) {
|
|
2650
|
+
exp.right = t__namespace.arrowFunctionExpression([t__namespace.identifier("val")], t__namespace.blockStatement([t__namespace.returnStatement(exp.right)]));
|
|
2651
|
+
}
|
|
2652
|
+
var a1 = t__namespace.callExpression(id('sender.bindings.when'), [condFn, exp.right]);
|
|
2653
|
+
initBody.body.push(t__namespace.expressionStatement(a1));
|
|
2654
|
+
explainChild(exp, fileName, { site: 'child', shape: 'when', lowered: a1, reactive: 'live', deps: DEPS.cond, note: 'at a fragment root; JS truthiness. Deliberate alternative: x-wait' });
|
|
2655
|
+
}
|
|
2656
|
+
else {
|
|
2657
|
+
childs.push(exp);
|
|
2658
|
+
initBody.body.push(t__namespace.variableDeclaration('const', [t__namespace.variableDeclarator(t__namespace.identifier(uid), exp)]));
|
|
2659
|
+
if ((t__namespace.isFunctionExpression(exp)) && t__namespace.isJSXElement(exp.returnType)) {
|
|
2660
|
+
initBody.body.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.bindings.method'), [t__namespace.identifier(uid)])));
|
|
2661
|
+
explainChild(exp, fileName, { site: 'child', shape: 'method', lowered: `sender.bindings.method(${codeOf(exp)})`, reactive: 'live', deps: DEPS.getter });
|
|
2662
|
+
}
|
|
2663
|
+
else if ((t__namespace.isArrowFunctionExpression(exp)) && t__namespace.isJSXElement(exp.returnType)) {
|
|
2664
|
+
initBody.body.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.bindings.method'), [t__namespace.identifier(uid)])));
|
|
2665
|
+
explainChild(exp, fileName, { site: 'child', shape: 'method', lowered: `sender.bindings.method(${codeOf(exp)})`, reactive: 'live', deps: DEPS.getter });
|
|
2666
|
+
}
|
|
2667
|
+
else if ((t__namespace.isArrowFunctionExpression(exp))) {
|
|
2668
|
+
initBody.body.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.bindings.method'), [t__namespace.identifier(uid)])));
|
|
2669
|
+
explainChild(exp, fileName, { site: 'child', shape: 'method', lowered: `sender.bindings.method(${codeOf(exp)})`, reactive: 'live', deps: DEPS.getter, note: 'reactive text if the result is text, a Frame if it is a component' });
|
|
2670
|
+
}
|
|
2671
|
+
else if (t__namespace.isCallExpression(exp) && t__namespace.isIdentifier(exp.callee) && exp.callee.name.startsWith('sender.bindings.')) {
|
|
2672
|
+
initBody.body.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.controls.add'), [t__namespace.identifier(uid)])));
|
|
2673
|
+
explainBindingCall(exp, fileName, 'at a fragment root');
|
|
2674
|
+
}
|
|
2675
|
+
else {
|
|
2676
|
+
initBody.body.push(t__namespace.expressionStatement(t__namespace.callExpression(t__namespace.identifier('sender.controls.add'), [t__namespace.identifier(uid)])));
|
|
2677
|
+
explainPlaced(exp, fileName);
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
});
|
|
2683
|
+
if (!state.get(motifFragment())) {
|
|
2684
|
+
state.set(motifFragment(), motifFragment());
|
|
2685
|
+
}
|
|
2686
|
+
t__namespace.objectProperty(id('nodes'), t__namespace.arrayExpression(childs));
|
|
2687
|
+
var objExp = t__namespace.objectExpression([]);
|
|
2688
|
+
if (initBody !== null) {
|
|
2689
|
+
var initProp = t__namespace.objectProperty(t__namespace.identifier('initializeComponent'), t__namespace.arrowFunctionExpression([id('sender')], t__namespace.blockStatement([initBody])));
|
|
2690
|
+
objExp.properties.push(initProp);
|
|
2691
|
+
}
|
|
2692
|
+
return t__namespace.callExpression(t__namespace.identifier(motifFragment()), [objExp]);
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
const ASYNC_TRACKING_LOCAL = '__motifAsyncTracking';
|
|
2696
|
+
function isVirtualizationDataRequest(path) {
|
|
2697
|
+
const attr = path.node;
|
|
2698
|
+
if (!t__namespace.isJSXIdentifier(attr.name) || attr.name.name !== 'dataRequest')
|
|
2699
|
+
return false;
|
|
2700
|
+
const opening = path.parentPath;
|
|
2701
|
+
if (!opening || !t__namespace.isJSXOpeningElement(opening.node))
|
|
2702
|
+
return false;
|
|
2703
|
+
const name = opening.node.name;
|
|
2704
|
+
if (t__namespace.isJSXIdentifier(name))
|
|
2705
|
+
return name.name === 'Virtualization';
|
|
2706
|
+
if (t__namespace.isJSXMemberExpression(name))
|
|
2707
|
+
return name.property.name === 'Virtualization';
|
|
2708
|
+
return false;
|
|
2709
|
+
}
|
|
2710
|
+
function wrapAwaitsForTracking(fn) {
|
|
2711
|
+
if (!fn.node.async)
|
|
2712
|
+
return false;
|
|
2713
|
+
const token = fn.scope.generateUidIdentifier('mt');
|
|
2714
|
+
const call = (method, args) => t__namespace.callExpression(t__namespace.memberExpression(t__namespace.identifier(ASYNC_TRACKING_LOCAL), t__namespace.identifier(method)), args);
|
|
2715
|
+
const wrapped = new WeakSet();
|
|
2716
|
+
let count = 0;
|
|
2717
|
+
fn.traverse({
|
|
2718
|
+
Function(inner) {
|
|
2719
|
+
inner.skip();
|
|
2720
|
+
},
|
|
2721
|
+
AwaitExpression: {
|
|
2722
|
+
exit(p) {
|
|
2723
|
+
if (wrapped.has(p.node))
|
|
2724
|
+
return;
|
|
2725
|
+
const awaited = t__namespace.awaitExpression(call('suspend', [t__namespace.cloneNode(token), p.node.argument]));
|
|
2726
|
+
wrapped.add(awaited);
|
|
2727
|
+
p.replaceWith(call('resume', [t__namespace.cloneNode(token), awaited]));
|
|
2728
|
+
count++;
|
|
2729
|
+
},
|
|
2730
|
+
},
|
|
2731
|
+
});
|
|
2732
|
+
if (count === 0)
|
|
2733
|
+
return false;
|
|
2734
|
+
const body = fn.node.body;
|
|
2735
|
+
const statements = t__namespace.isBlockStatement(body) ? body.body : [t__namespace.returnStatement(body)];
|
|
2736
|
+
fn.node.body = t__namespace.blockStatement([
|
|
2737
|
+
t__namespace.variableDeclaration('const', [t__namespace.variableDeclarator(token, call('capture', []))]),
|
|
2738
|
+
t__namespace.tryStatement(t__namespace.blockStatement(statements), null, t__namespace.blockStatement([t__namespace.expressionStatement(call('end', [t__namespace.cloneNode(token)]))])),
|
|
2739
|
+
]);
|
|
2740
|
+
return true;
|
|
2741
|
+
}
|
|
2742
|
+
|
|
2743
|
+
const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
2744
|
+
const HTML_TAGS = {
|
|
2745
|
+
HTMLAnchorElement: 'a',
|
|
2746
|
+
HTMLAreaElement: 'area',
|
|
2747
|
+
HTMLAudioElement: 'audio',
|
|
2748
|
+
HTMLBRElement: 'br',
|
|
2749
|
+
HTMLBaseElement: 'base',
|
|
2750
|
+
HTMLBodyElement: 'body',
|
|
2751
|
+
HTMLButtonElement: 'button',
|
|
2752
|
+
HTMLCanvasElement: 'canvas',
|
|
2753
|
+
HTMLDListElement: 'dl',
|
|
2754
|
+
HTMLDataElement: 'data',
|
|
2755
|
+
HTMLDataListElement: 'datalist',
|
|
2756
|
+
HTMLDetailsElement: 'details',
|
|
2757
|
+
HTMLDialogElement: 'dialog',
|
|
2758
|
+
HTMLDivElement: 'div',
|
|
2759
|
+
HTMLEmbedElement: 'embed',
|
|
2760
|
+
HTMLFieldSetElement: 'fieldset',
|
|
2761
|
+
HTMLFormElement: 'form',
|
|
2762
|
+
HTMLHRElement: 'hr',
|
|
2763
|
+
HTMLHeadElement: 'head',
|
|
2764
|
+
HTMLHeadingElement: 'h1',
|
|
2765
|
+
HTMLHtmlElement: 'html',
|
|
2766
|
+
HTMLIFrameElement: 'iframe',
|
|
2767
|
+
HTMLImageElement: 'img',
|
|
2768
|
+
HTMLInputElement: 'input',
|
|
2769
|
+
HTMLLIElement: 'li',
|
|
2770
|
+
HTMLLabelElement: 'label',
|
|
2771
|
+
HTMLLegendElement: 'legend',
|
|
2772
|
+
HTMLLinkElement: 'link',
|
|
2773
|
+
HTMLMapElement: 'map',
|
|
2774
|
+
HTMLMenuElement: 'menu',
|
|
2775
|
+
HTMLMetaElement: 'meta',
|
|
2776
|
+
HTMLMeterElement: 'meter',
|
|
2777
|
+
HTMLModElement: 'ins',
|
|
2778
|
+
HTMLOListElement: 'ol',
|
|
2779
|
+
HTMLObjectElement: 'object',
|
|
2780
|
+
HTMLOptGroupElement: 'optgroup',
|
|
2781
|
+
HTMLOptionElement: 'option',
|
|
2782
|
+
HTMLOutputElement: 'output',
|
|
2783
|
+
HTMLParagraphElement: 'p',
|
|
2784
|
+
HTMLPictureElement: 'picture',
|
|
2785
|
+
HTMLPreElement: 'pre',
|
|
2786
|
+
HTMLProgressElement: 'progress',
|
|
2787
|
+
HTMLQuoteElement: 'blockquote',
|
|
2788
|
+
HTMLScriptElement: 'script',
|
|
2789
|
+
HTMLSelectElement: 'select',
|
|
2790
|
+
HTMLSlotElement: 'slot',
|
|
2791
|
+
HTMLSourceElement: 'source',
|
|
2792
|
+
HTMLSpanElement: 'span',
|
|
2793
|
+
HTMLStyleElement: 'style',
|
|
2794
|
+
HTMLTableCaptionElement: 'caption',
|
|
2795
|
+
HTMLTableCellElement: 'td',
|
|
2796
|
+
HTMLTableColElement: 'col',
|
|
2797
|
+
HTMLTableElement: 'table',
|
|
2798
|
+
HTMLTableRowElement: 'tr',
|
|
2799
|
+
HTMLTableSectionElement: 'tbody',
|
|
2800
|
+
HTMLTemplateElement: 'template',
|
|
2801
|
+
HTMLTextAreaElement: 'textarea',
|
|
2802
|
+
HTMLTimeElement: 'time',
|
|
2803
|
+
HTMLTitleElement: 'title',
|
|
2804
|
+
HTMLTrackElement: 'track',
|
|
2805
|
+
HTMLUListElement: 'ul',
|
|
2806
|
+
HTMLVideoElement: 'video',
|
|
2807
|
+
HTMLElement: 'div',
|
|
2808
|
+
};
|
|
2809
|
+
const SVG_TAGS = {
|
|
2810
|
+
SVGSVGElement: 'svg',
|
|
2811
|
+
SVGGElement: 'g',
|
|
2812
|
+
SVGPathElement: 'path',
|
|
2813
|
+
SVGCircleElement: 'circle',
|
|
2814
|
+
SVGRectElement: 'rect',
|
|
2815
|
+
SVGLineElement: 'line',
|
|
2816
|
+
SVGTextElement: 'text',
|
|
2817
|
+
SVGTSpanElement: 'tspan',
|
|
2818
|
+
SVGPolygonElement: 'polygon',
|
|
2819
|
+
SVGPolylineElement: 'polyline',
|
|
2820
|
+
SVGEllipseElement: 'ellipse',
|
|
2821
|
+
SVGUseElement: 'use',
|
|
2822
|
+
SVGDefsElement: 'defs',
|
|
2823
|
+
SVGImageElement: 'image',
|
|
2824
|
+
SVGMaskElement: 'mask',
|
|
2825
|
+
SVGSymbolElement: 'symbol',
|
|
2826
|
+
SVGMarkerElement: 'marker',
|
|
2827
|
+
SVGForeignObjectElement: 'foreignObject',
|
|
2828
|
+
SVGLinearGradientElement: 'linearGradient',
|
|
2829
|
+
SVGRadialGradientElement: 'radialGradient',
|
|
2830
|
+
SVGStopElement: 'stop',
|
|
2831
|
+
SVGClipPathElement: 'clipPath',
|
|
2832
|
+
};
|
|
2833
|
+
function resolveElementType(typeName) {
|
|
2834
|
+
if (!typeName)
|
|
2835
|
+
return undefined;
|
|
2836
|
+
const html = HTML_TAGS[typeName];
|
|
2837
|
+
if (html)
|
|
2838
|
+
return { tag: html };
|
|
2839
|
+
const svg = SVG_TAGS[typeName];
|
|
2840
|
+
if (svg)
|
|
2841
|
+
return { tag: svg, namespace: SVG_NAMESPACE };
|
|
2842
|
+
return undefined;
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
function absorbGeneratedCoreImports(statements, into) {
|
|
2846
|
+
const fromCore = statements.filter(statement => t__namespace.isImportDeclaration(statement.node) && statement.node.source.value === '@motifx/core');
|
|
2847
|
+
for (const statement of fromCore) {
|
|
2848
|
+
let absorbed = false;
|
|
2849
|
+
for (const specifier of statement.node.specifiers) {
|
|
2850
|
+
if (specifier.loc || !t__namespace.isImportSpecifier(specifier) || !t__namespace.isIdentifier(specifier.imported))
|
|
2851
|
+
continue;
|
|
2852
|
+
const importedName = specifier.imported.name;
|
|
2853
|
+
if (into.has(importedName))
|
|
2854
|
+
continue;
|
|
2855
|
+
into.set(importedName, specifier);
|
|
2856
|
+
absorbed = true;
|
|
2857
|
+
}
|
|
2858
|
+
if (absorbed)
|
|
2859
|
+
statement.remove();
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
function hasStaticMember(node, name) {
|
|
2863
|
+
return node.body.body.some(m => (t__namespace.isClassProperty(m) || t__namespace.isClassMethod(m)) &&
|
|
2864
|
+
m.static === true &&
|
|
2865
|
+
t__namespace.isIdentifier(m.key) &&
|
|
2866
|
+
m.key.name === name);
|
|
2867
|
+
}
|
|
2868
|
+
function injectDeclaredElementTag(path) {
|
|
2869
|
+
try {
|
|
2870
|
+
const node = path.node;
|
|
2871
|
+
if (!t__namespace.isIdentifier(node.superClass) || node.superClass.name !== 'Component')
|
|
2872
|
+
return;
|
|
2873
|
+
if (hasStaticMember(node, 'elementTag'))
|
|
2874
|
+
return;
|
|
2875
|
+
const typeArgs = node.superTypeParameters ?? node.superTypeArguments;
|
|
2876
|
+
const first = typeArgs?.params?.[0];
|
|
2877
|
+
if (!first || !t__namespace.isTSTypeReference(first) || !t__namespace.isIdentifier(first.typeName))
|
|
2878
|
+
return;
|
|
2879
|
+
const resolved = resolveElementType(first.typeName.name);
|
|
2880
|
+
if (!resolved)
|
|
2881
|
+
return;
|
|
2882
|
+
const members = [
|
|
2883
|
+
t__namespace.classProperty(t__namespace.identifier('elementTag'), t__namespace.stringLiteral(resolved.tag), null, null, false, true)
|
|
2884
|
+
];
|
|
2885
|
+
if (resolved.namespace && !hasStaticMember(node, 'elementNamespace')) {
|
|
2886
|
+
members.push(t__namespace.classProperty(t__namespace.identifier('elementNamespace'), t__namespace.stringLiteral(resolved.namespace), null, null, false, true));
|
|
2887
|
+
}
|
|
2888
|
+
node.body.body.unshift(...members);
|
|
2889
|
+
}
|
|
2890
|
+
catch { /* enjeksiyon başarısızsa derleme bozulmasın */ }
|
|
2891
|
+
}
|
|
2892
|
+
const elementTagPlugin = () => ({
|
|
2893
|
+
name: 'motifjs-element-tag',
|
|
2894
|
+
visitor: {
|
|
2895
|
+
Class: {
|
|
2896
|
+
enter(path) {
|
|
2897
|
+
injectDeclaredElementTag(path);
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
});
|
|
2902
|
+
class Compiler {
|
|
2903
|
+
motifCompile(code, filename) {
|
|
2904
|
+
return this.start(code, filename);
|
|
2905
|
+
}
|
|
2906
|
+
diagnostics = [];
|
|
2907
|
+
explanations = [];
|
|
2908
|
+
start(code, filename) {
|
|
2909
|
+
beginCollect();
|
|
2910
|
+
try {
|
|
2911
|
+
return this._run(code, filename);
|
|
2912
|
+
}
|
|
2913
|
+
finally {
|
|
2914
|
+
this.diagnostics = endCollect();
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
lowerDecorators(code, filename) {
|
|
2918
|
+
const file = filename.split('?')[0];
|
|
2919
|
+
return babel__namespace.transformSync(code, {
|
|
2920
|
+
sourceType: 'module',
|
|
2921
|
+
babelrc: false,
|
|
2922
|
+
configFile: false,
|
|
2923
|
+
code: true,
|
|
2924
|
+
sourceMaps: true,
|
|
2925
|
+
comments: true,
|
|
2926
|
+
highlightCode: false,
|
|
2927
|
+
filename: file,
|
|
2928
|
+
sourceFileName: file,
|
|
2929
|
+
parserOpts: { plugins: /\.[mc]?ts$/.test(file) ? ['typescript'] : [] },
|
|
2930
|
+
plugins: [[proposal_decorators, { "version": "2023-11" }]],
|
|
2931
|
+
});
|
|
2932
|
+
}
|
|
2933
|
+
explain(code, filename) {
|
|
2934
|
+
beginCollect();
|
|
2935
|
+
beginExplain();
|
|
2936
|
+
try {
|
|
2937
|
+
return this._run(code, filename);
|
|
2938
|
+
}
|
|
2939
|
+
finally {
|
|
2940
|
+
this.diagnostics = endCollect();
|
|
2941
|
+
this.explanations = endExplain();
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
_run(code, filename) {
|
|
2945
|
+
return babel__namespace.transformSync(code, {
|
|
2946
|
+
sourceType: 'module',
|
|
2947
|
+
ast: true,
|
|
2948
|
+
babelrc: false,
|
|
2949
|
+
configFile: false,
|
|
2950
|
+
cloneInputAst: false,
|
|
2951
|
+
code: true,
|
|
2952
|
+
sourceMaps: true,
|
|
2953
|
+
comments: true,
|
|
2954
|
+
highlightCode: false,
|
|
2955
|
+
minified: false,
|
|
2956
|
+
compact: false,
|
|
2957
|
+
filename: filename,
|
|
2958
|
+
sourceFileName: filename,
|
|
2959
|
+
presets: [
|
|
2960
|
+
preset_flow,
|
|
2961
|
+
[preset_typescript, {
|
|
2962
|
+
onlyRemoveTypeImports: true,
|
|
2963
|
+
isTSX: true,
|
|
2964
|
+
allExtensions: true,
|
|
2965
|
+
}]
|
|
2966
|
+
],
|
|
2967
|
+
plugins: [
|
|
2968
|
+
elementTagPlugin,
|
|
2969
|
+
[proposal_decorators, { "version": "2023-11" }],
|
|
2970
|
+
[transform_class_properties, { "loose": true }],
|
|
2971
|
+
transform_class_static_block,
|
|
2972
|
+
syntax_flow,
|
|
2973
|
+
syntax_jsx,
|
|
2974
|
+
function () {
|
|
2975
|
+
return {
|
|
2976
|
+
visitor: {
|
|
2977
|
+
JSXAttribute(path, state) {
|
|
2978
|
+
if (!isVirtualizationDataRequest(path))
|
|
2979
|
+
return;
|
|
2980
|
+
const value = path.get('value');
|
|
2981
|
+
if (!value.isJSXExpressionContainer())
|
|
2982
|
+
return;
|
|
2983
|
+
const fn = value.get('expression');
|
|
2984
|
+
if (!fn.isArrowFunctionExpression() && !fn.isFunctionExpression())
|
|
2985
|
+
return;
|
|
2986
|
+
if (wrapAwaitsForTracking(fn))
|
|
2987
|
+
state.set(ASYNC_TRACKING_LOCAL, true);
|
|
2988
|
+
},
|
|
2989
|
+
JSXElement: {
|
|
2990
|
+
exit(path, state) {
|
|
2991
|
+
state.set('filename', filename);
|
|
2992
|
+
const origin = isExplaining() ? captureOrigin(path, code) : null;
|
|
2993
|
+
const out = ParseComponent(path, state);
|
|
2994
|
+
if (origin)
|
|
2995
|
+
noteOriginRaw(out, origin);
|
|
2996
|
+
path.replaceWith(out);
|
|
2997
|
+
if (!state.get(motifFunctionComponent())) {
|
|
2998
|
+
state.set(motifFunctionComponent(), motifFunctionComponent());
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
},
|
|
3002
|
+
GenericTypeAnnotation: {
|
|
3003
|
+
exit(path, state) {
|
|
3004
|
+
}
|
|
3005
|
+
},
|
|
3006
|
+
TypeParameterInstantiation: {
|
|
3007
|
+
exit(path, state) {
|
|
3008
|
+
}
|
|
3009
|
+
},
|
|
3010
|
+
JSXFragment: {
|
|
3011
|
+
exit(path, state) {
|
|
3012
|
+
state.set('filename', filename);
|
|
3013
|
+
const origin = isExplaining() ? captureOrigin(path, code) : null;
|
|
3014
|
+
const out = ParseFrament(path, state);
|
|
3015
|
+
if (origin)
|
|
3016
|
+
noteOriginRaw(out, origin);
|
|
3017
|
+
path.replaceWith(out);
|
|
3018
|
+
}
|
|
3019
|
+
},
|
|
3020
|
+
Program: {
|
|
3021
|
+
enter(path, state) {
|
|
3022
|
+
state.set('originalCode', code);
|
|
3023
|
+
recordClassMembers(path);
|
|
3024
|
+
},
|
|
3025
|
+
exit(path, state) {
|
|
3026
|
+
const topLevel = path.get('body');
|
|
3027
|
+
const coreImports = new Map();
|
|
3028
|
+
coreImports.set('motifComponent', t__namespace.importSpecifier(t__namespace.identifier(motifComponent()), t__namespace.identifier("motifComponent")));
|
|
3029
|
+
if (state.get(motifFragment())) {
|
|
3030
|
+
coreImports.set('motifFragment', t__namespace.importSpecifier(t__namespace.identifier(motifFragment()), t__namespace.identifier("motifFragment")));
|
|
3031
|
+
}
|
|
3032
|
+
coreImports.set('FNComponent', t__namespace.importSpecifier(t__namespace.identifier(motifFunctionComponent()), t__namespace.identifier("FNComponent")));
|
|
3033
|
+
coreImports.set('motifCompiled', t__namespace.importSpecifier(t__namespace.identifier(motifCompiled()), t__namespace.identifier('motifCompiled')));
|
|
3034
|
+
if (state.get(ASYNC_TRACKING_LOCAL)) {
|
|
3035
|
+
coreImports.set('asyncTracking', t__namespace.importSpecifier(t__namespace.identifier(ASYNC_TRACKING_LOCAL), t__namespace.identifier('asyncTracking')));
|
|
3036
|
+
}
|
|
3037
|
+
var isSFC = false;
|
|
3038
|
+
var viewReturn = null;
|
|
3039
|
+
var setInternal = [];
|
|
3040
|
+
var setOriginal = [];
|
|
3041
|
+
path.node.body.forEach(tx => {
|
|
3042
|
+
if (t__namespace.isVariableDeclaration(tx)) {
|
|
3043
|
+
// if (t.isObjectExpression(y.init)) {
|
|
3044
|
+
setInternal.push(tx);
|
|
3045
|
+
}
|
|
3046
|
+
else if (t__namespace.isIfStatement(tx)) {
|
|
3047
|
+
setInternal.push(tx);
|
|
3048
|
+
}
|
|
3049
|
+
else if (t__namespace.isExpressionStatement(tx) && t__namespace.isAssignmentExpression(tx.expression)) {
|
|
3050
|
+
setInternal.push(tx);
|
|
3051
|
+
}
|
|
3052
|
+
else if (t__namespace.isExpressionStatement(tx) && t__namespace.isCallExpression(tx.expression) && t__namespace.isMemberExpression(tx.expression.callee)) {
|
|
3053
|
+
setInternal.push(tx);
|
|
3054
|
+
}
|
|
3055
|
+
else if (t__namespace.isExpressionStatement(tx) && t__namespace.isCallExpression(tx.expression) && t__namespace.isIdentifier(tx.expression.callee)) {
|
|
3056
|
+
if (tx.expression.callee.name === motifComponent() || tx.expression.callee.name === motifFragment()) {
|
|
3057
|
+
isSFC = true;
|
|
3058
|
+
viewReturn = tx.expression;
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
else {
|
|
3062
|
+
setOriginal.push(tx);
|
|
3063
|
+
}
|
|
3064
|
+
});
|
|
3065
|
+
if (isSFC) {
|
|
3066
|
+
var rtrn = t__namespace.returnStatement(viewReturn);
|
|
3067
|
+
coreImports.set('Component', t__namespace.importSpecifier(t__namespace.identifier("_mC"), t__namespace.identifier("Component")));
|
|
3068
|
+
var cls = t__namespace.exportDefaultDeclaration(t__namespace.classDeclaration(t__namespace.identifier('runtimeClass'), t__namespace.identifier('_mC'), t__namespace.classBody([t__namespace.classMethod('method', t__namespace.identifier('view'), [t__namespace.identifier('sender')], t__namespace.blockStatement([...setInternal, rtrn]))])));
|
|
3069
|
+
path.node.body = [...setOriginal, cls];
|
|
3070
|
+
}
|
|
3071
|
+
state.set('filename', filename);
|
|
3072
|
+
absorbGeneratedCoreImports(topLevel, coreImports);
|
|
3073
|
+
if (coreImports.size > 0) {
|
|
3074
|
+
const contractCall = t__namespace.callExpression(t__namespace.identifier(motifCompiled()), [t__namespace.numericLiteral(COMPILER_CONTRACT)]);
|
|
3075
|
+
t__namespace.addComment(contractCall, 'leading', '#__PURE__');
|
|
3076
|
+
const coreImport = t__namespace.importDeclaration(Array.from(coreImports.values()), t__namespace.stringLiteral('@motifx/core'));
|
|
3077
|
+
path.unshiftContainer('body', [coreImport, t__namespace.expressionStatement(contractCall)]);
|
|
3078
|
+
}
|
|
3079
|
+
// if (injectableRegistry.length > 0) {
|
|
3080
|
+
// const output = `
|
|
3081
|
+
// export const GeneratedInjectables: any[] = [
|
|
3082
|
+
// if (allClassesRegistry.length > 0) {
|
|
3083
|
+
// const output = `
|
|
3084
|
+
// export const ClassReferences: any[] = [
|
|
3085
|
+
// fs.writeFileSync(pPath.join(process.cwd(), "generated-class.ts"), output);
|
|
3086
|
+
}
|
|
3087
|
+
},
|
|
3088
|
+
},
|
|
3089
|
+
};
|
|
3090
|
+
},
|
|
3091
|
+
function devOnlyStrip() {
|
|
3092
|
+
let isDev = true;
|
|
3093
|
+
try {
|
|
3094
|
+
const flag = (0, eval)('typeof __MOTIF_DEV__ !== "undefined" ? __MOTIF_DEV__ : undefined');
|
|
3095
|
+
if (typeof flag === 'boolean')
|
|
3096
|
+
isDev = flag;
|
|
3097
|
+
}
|
|
3098
|
+
catch { /* ignore */ }
|
|
3099
|
+
if (typeof process !== 'undefined' && process?.env?.MOTIF_DEV === 'false')
|
|
3100
|
+
isDev = false;
|
|
3101
|
+
const consumed = new WeakSet();
|
|
3102
|
+
const hasMarker = (node, pattern) => {
|
|
3103
|
+
const comments = [].concat(node.leadingComments || []);
|
|
3104
|
+
return comments.some(c => typeof c.value === 'string' && pattern.test(c.value) && !consumed.has(c));
|
|
3105
|
+
};
|
|
3106
|
+
const consumeMarkers = (node) => {
|
|
3107
|
+
const comments = [].concat(node.leadingComments || []);
|
|
3108
|
+
for (const c of comments) {
|
|
3109
|
+
if (typeof c.value === 'string' && /@DEV-ONLY/.test(c.value))
|
|
3110
|
+
consumed.add(c);
|
|
3111
|
+
}
|
|
3112
|
+
};
|
|
3113
|
+
const stripIfMarked = (path) => {
|
|
3114
|
+
if (isDev)
|
|
3115
|
+
return;
|
|
3116
|
+
try {
|
|
3117
|
+
if (hasMarker(path.node, /@DEV-ONLY/)) {
|
|
3118
|
+
consumeMarkers(path.node);
|
|
3119
|
+
path.remove();
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
catch { /* ignore single node */ }
|
|
3123
|
+
};
|
|
3124
|
+
return {
|
|
3125
|
+
visitor: {
|
|
3126
|
+
Program(path) {
|
|
3127
|
+
if (isDev)
|
|
3128
|
+
return;
|
|
3129
|
+
const bodyPaths = path.get('body');
|
|
3130
|
+
for (const stmtPath of bodyPaths) {
|
|
3131
|
+
try {
|
|
3132
|
+
const node = stmtPath.node;
|
|
3133
|
+
if (hasMarker(node, /@DEV-ONLY/)) {
|
|
3134
|
+
consumeMarkers(node);
|
|
3135
|
+
stmtPath.remove();
|
|
3136
|
+
continue;
|
|
3137
|
+
}
|
|
3138
|
+
const allComments = [].concat(node.leadingComments || [], node.trailingComments || []);
|
|
3139
|
+
if (allComments.some(c => /@DEV-ONLY-BEGIN/.test(c.value) && !consumed.has(c))) {
|
|
3140
|
+
consumeMarkers(node);
|
|
3141
|
+
stmtPath.remove();
|
|
3142
|
+
continue;
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
catch { /* ignore single node */ }
|
|
3146
|
+
}
|
|
3147
|
+
},
|
|
3148
|
+
ClassDeclaration: stripIfMarked,
|
|
3149
|
+
FunctionDeclaration: stripIfMarked,
|
|
3150
|
+
VariableDeclaration: stripIfMarked
|
|
3151
|
+
}
|
|
3152
|
+
};
|
|
3153
|
+
}
|
|
3154
|
+
],
|
|
3155
|
+
});
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3159
|
+
const fileRegex = /\.(jsx|tsx|aio|mjsx|mtsx)$/;
|
|
3160
|
+
const decoratorFileRegex = /\.(ts|mts|cts|js|mjs|cjs)$/;
|
|
3161
|
+
const declarationFileRegex = /\.d\.[mc]?ts$/;
|
|
3162
|
+
const decoratorSyntaxRegex = /(?:^|[\s(,;{}])@[A-Za-z_$]/;
|
|
3163
|
+
const assetQueryRegex = /(?:^|&)(?:raw|url|worker|sharedworker|inline)(?:[&=]|$)/;
|
|
3164
|
+
function sourceFile(id) {
|
|
3165
|
+
if (id.charCodeAt(0) === 0)
|
|
3166
|
+
return null;
|
|
3167
|
+
const queryStart = id.indexOf('?');
|
|
3168
|
+
if (queryStart !== -1 && assetQueryRegex.test(id.slice(queryStart + 1)))
|
|
3169
|
+
return null;
|
|
3170
|
+
return queryStart === -1 ? id : id.slice(0, queryStart);
|
|
3171
|
+
}
|
|
3172
|
+
function shouldTransform(id) {
|
|
3173
|
+
const file = sourceFile(id);
|
|
3174
|
+
return file !== null && fileRegex.test(file);
|
|
3175
|
+
}
|
|
3176
|
+
function shouldLowerDecorators(id, src) {
|
|
3177
|
+
const file = sourceFile(id);
|
|
3178
|
+
if (file === null || !decoratorFileRegex.test(file) || declarationFileRegex.test(file))
|
|
3179
|
+
return false;
|
|
3180
|
+
if (file.includes('/node_modules/'))
|
|
3181
|
+
return false;
|
|
3182
|
+
return decoratorSyntaxRegex.test(src);
|
|
3183
|
+
}
|
|
3184
|
+
function legacyDecoratorsChecker() {
|
|
3185
|
+
const byConfig = new Map();
|
|
3186
|
+
return (file) => {
|
|
3187
|
+
const configPath = ts__namespace.findConfigFile(path__namespace.dirname(file), ts__namespace.sys.fileExists);
|
|
3188
|
+
if (!configPath)
|
|
3189
|
+
return false;
|
|
3190
|
+
let legacy = byConfig.get(configPath);
|
|
3191
|
+
if (legacy === undefined) {
|
|
3192
|
+
const read = ts__namespace.readConfigFile(configPath, ts__namespace.sys.readFile);
|
|
3193
|
+
legacy = !read.error && ts__namespace.parseJsonConfigFileContent(read.config, ts__namespace.sys, path__namespace.dirname(configPath)).options.experimentalDecorators === true;
|
|
3194
|
+
byConfig.set(configPath, legacy);
|
|
3195
|
+
}
|
|
3196
|
+
return legacy;
|
|
3197
|
+
};
|
|
3198
|
+
}
|
|
3199
|
+
function explainMatches(opt, id) {
|
|
3200
|
+
if (!opt)
|
|
3201
|
+
return false;
|
|
3202
|
+
if (opt === true)
|
|
3203
|
+
return true;
|
|
3204
|
+
if (typeof opt === 'string')
|
|
3205
|
+
return id.includes(opt);
|
|
3206
|
+
return opt.test(id);
|
|
3207
|
+
}
|
|
3208
|
+
function vitePlugin(options = {}) {
|
|
3209
|
+
const showDiagnostics = options.diagnostics !== false;
|
|
3210
|
+
const usesLegacyDecorators = legacyDecoratorsChecker();
|
|
3211
|
+
return {
|
|
3212
|
+
name: 'transform-file-motif-jsx',
|
|
3213
|
+
enforce: 'pre',
|
|
3214
|
+
transform(src, id) {
|
|
3215
|
+
if (shouldLowerDecorators(id, src)) {
|
|
3216
|
+
if (usesLegacyDecorators(sourceFile(id)))
|
|
3217
|
+
return;
|
|
3218
|
+
const result = new Compiler().lowerDecorators(src, id);
|
|
3219
|
+
if (result && result.code) {
|
|
3220
|
+
return {
|
|
3221
|
+
code: result.code,
|
|
3222
|
+
map: result.map
|
|
3223
|
+
};
|
|
3224
|
+
}
|
|
3225
|
+
return;
|
|
3226
|
+
}
|
|
3227
|
+
if (shouldTransform(id)) {
|
|
3228
|
+
if (!src.includes("//useReact") && !src.includes("//useVue")) {
|
|
3229
|
+
try {
|
|
3230
|
+
const compiler = new Compiler();
|
|
3231
|
+
const doExplain = explainMatches(options.explain, id);
|
|
3232
|
+
var result = doExplain ? compiler.explain(src, id) : compiler.start(src, id);
|
|
3233
|
+
if (doExplain)
|
|
3234
|
+
printExplanations(compiler.explanations);
|
|
3235
|
+
if (showDiagnostics && compiler.diagnostics.length > 0) {
|
|
3236
|
+
printDiagnostics(compiler.diagnostics);
|
|
3237
|
+
}
|
|
3238
|
+
if (result && result.code) {
|
|
3239
|
+
return {
|
|
3240
|
+
code: result.code,
|
|
3241
|
+
map: result.map
|
|
3242
|
+
};
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
catch (error) {
|
|
3246
|
+
throw error;
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
};
|
|
3252
|
+
}
|
|
3253
|
+
|
|
3254
|
+
/** `() => X` bu tipe geçebilir mi? Union'da tek bir çağrılabilir bileşen yeter. */
|
|
3255
|
+
function acceptsFunction(type, checker, depth = 0) {
|
|
3256
|
+
if (depth > 8)
|
|
3257
|
+
return true;
|
|
3258
|
+
const f = type.flags;
|
|
3259
|
+
if (f & (ts__namespace.TypeFlags.Any | ts__namespace.TypeFlags.Unknown | ts__namespace.TypeFlags.Never))
|
|
3260
|
+
return true;
|
|
3261
|
+
if (f & ts__namespace.TypeFlags.NonPrimitive)
|
|
3262
|
+
return true;
|
|
3263
|
+
if (type.isUnion())
|
|
3264
|
+
return type.types.some(t => acceptsFunction(t, checker, depth + 1));
|
|
3265
|
+
if (type.isIntersection())
|
|
3266
|
+
return type.types.every(t => acceptsFunction(t, checker, depth + 1));
|
|
3267
|
+
if (f & ts__namespace.TypeFlags.TypeParameter) {
|
|
3268
|
+
const c = type.getConstraint?.() ?? checker.getBaseConstraintOfType(type);
|
|
3269
|
+
return c ? acceptsFunction(c, checker, depth + 1) : true;
|
|
3270
|
+
}
|
|
3271
|
+
if (checker.getSignaturesOfType(type, ts__namespace.SignatureKind.Call).length > 0)
|
|
3272
|
+
return true;
|
|
3273
|
+
if (checker.getSignaturesOfType(type, ts__namespace.SignatureKind.Construct).length > 0)
|
|
3274
|
+
return true;
|
|
3275
|
+
const sym = type.getSymbol();
|
|
3276
|
+
if (sym && (sym.name === 'Function' || sym.name === 'CallableFunction'))
|
|
3277
|
+
return true;
|
|
3278
|
+
if (f & ts__namespace.TypeFlags.Object) {
|
|
3279
|
+
const props = checker.getPropertiesOfType(type);
|
|
3280
|
+
const idx = checker.getIndexInfosOfType?.(type) ?? [];
|
|
3281
|
+
if (props.length === 0 && idx.length === 0 && checker.getSignaturesOfType(type, ts__namespace.SignatureKind.Call).length === 0) {
|
|
3282
|
+
const decl = sym?.declarations?.[0];
|
|
3283
|
+
if (!decl || ts__namespace.isTypeLiteralNode(decl) || ts__namespace.isInterfaceDeclaration(decl))
|
|
3284
|
+
return true;
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
return false;
|
|
3288
|
+
}
|
|
3289
|
+
function stripParens(e) {
|
|
3290
|
+
let cur = e;
|
|
3291
|
+
while (ts__namespace.isParenthesizedExpression(cur))
|
|
3292
|
+
cur = cur.expression;
|
|
3293
|
+
return cur;
|
|
3294
|
+
}
|
|
3295
|
+
/** Etiket bir bileşen mi? `div` gibi küçük harfli tanımlayıcı DOM'dur; üye ifadesi ve büyük harf bileşendir. */
|
|
3296
|
+
function isComponentTag(name) {
|
|
3297
|
+
if (ts__namespace.isIdentifier(name)) {
|
|
3298
|
+
const n = name.text;
|
|
3299
|
+
return n.length > 0 && n[0] !== n[0].toLowerCase();
|
|
3300
|
+
}
|
|
3301
|
+
return ts__namespace.isPropertyAccessExpression(name);
|
|
3302
|
+
}
|
|
3303
|
+
function tagText(name) {
|
|
3304
|
+
return name.getText();
|
|
3305
|
+
}
|
|
3306
|
+
function lintProgram(program, files) {
|
|
3307
|
+
const checker = program.getTypeChecker();
|
|
3308
|
+
const out = [];
|
|
3309
|
+
const wanted = files ? new Set(files.map(f => normalize(f))) : null;
|
|
3310
|
+
for (const sf of program.getSourceFiles()) {
|
|
3311
|
+
if (sf.isDeclarationFile)
|
|
3312
|
+
continue;
|
|
3313
|
+
if (sf.fileName.includes('/node_modules/'))
|
|
3314
|
+
continue;
|
|
3315
|
+
if (wanted && !wanted.has(normalize(sf.fileName)))
|
|
3316
|
+
continue;
|
|
3317
|
+
if (!/\.(tsx|jsx|mtsx|mjsx)$/.test(sf.fileName))
|
|
3318
|
+
continue;
|
|
3319
|
+
const visit = (node) => {
|
|
3320
|
+
if (ts__namespace.isJsxAttribute(node) && node.initializer && ts__namespace.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
3321
|
+
const expr = stripParens(node.initializer.expression);
|
|
3322
|
+
if (ts__namespace.isConditionalExpression(expr)) {
|
|
3323
|
+
const attrs = node.parent;
|
|
3324
|
+
const opening = attrs.parent;
|
|
3325
|
+
if ((ts__namespace.isJsxOpeningElement(opening) || ts__namespace.isJsxSelfClosingElement(opening)) && isComponentTag(opening.tagName)) {
|
|
3326
|
+
check(node, expr, opening);
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
ts__namespace.forEachChild(node, visit);
|
|
3331
|
+
};
|
|
3332
|
+
const check = (attr, expr, opening) => {
|
|
3333
|
+
const propName = ts__namespace.isIdentifier(attr.name) ? attr.name.text : attr.name.getText();
|
|
3334
|
+
if (propName === 'key' || propName === 'indexkey' || /^x[-:]/i.test(propName) || /^on[-:_]/i.test(propName))
|
|
3335
|
+
return;
|
|
3336
|
+
let type;
|
|
3337
|
+
try {
|
|
3338
|
+
const propsType = checker.getContextualType(opening.attributes);
|
|
3339
|
+
const propSym = propsType ? checker.getPropertyOfType(propsType, propName) : undefined;
|
|
3340
|
+
const decl = propSym?.declarations?.find(d => (ts__namespace.isPropertySignature(d) || ts__namespace.isPropertyDeclaration(d)) && !!d.type);
|
|
3341
|
+
if (decl?.type)
|
|
3342
|
+
type = checker.getTypeFromTypeNode(decl.type);
|
|
3343
|
+
else if (propSym)
|
|
3344
|
+
type = checker.getTypeOfSymbolAtLocation(propSym, opening);
|
|
3345
|
+
else
|
|
3346
|
+
type = checker.getContextualType(attr.initializer.expression);
|
|
3347
|
+
}
|
|
3348
|
+
catch {
|
|
3349
|
+
type = undefined;
|
|
3350
|
+
}
|
|
3351
|
+
if (!type)
|
|
3352
|
+
return;
|
|
3353
|
+
if (acceptsFunction(type, checker))
|
|
3354
|
+
return;
|
|
3355
|
+
const typeText = checker.typeToString(type, undefined, ts__namespace.TypeFormatFlags.NoTruncation);
|
|
3356
|
+
const { line } = sf.getLineAndCharacterOfPosition(attr.getStart(sf));
|
|
3357
|
+
out.push({
|
|
3358
|
+
code: 'MJX005',
|
|
3359
|
+
file: sf.fileName,
|
|
3360
|
+
line: line + 1,
|
|
3361
|
+
message: `<${tagText(opening.tagName)} ${propName}={… ? … : …}>: the component declares "${propName}" as "${typeText}", ` +
|
|
3362
|
+
`but the compiler ALWAYS wraps an attribute ternary in "() => …" (by design, for reactivity), so the component receives ` +
|
|
3363
|
+
`a FUNCTION at runtime; TypeScript does not see this. Declare the prop as Bind<T> (T | (() => T)) and read it with read()/toGetter(). ` +
|
|
3364
|
+
`If the value is really static, compute the ternary outside JSX and pass the variable.`,
|
|
3365
|
+
frame: codeFrame(sf, attr),
|
|
3366
|
+
});
|
|
3367
|
+
};
|
|
3368
|
+
visit(sf);
|
|
3369
|
+
}
|
|
3370
|
+
return out;
|
|
3371
|
+
}
|
|
3372
|
+
/** tsconfig'den program kurup denetler. CLI bunu kullanır. */
|
|
3373
|
+
function lintProject(options = {}) {
|
|
3374
|
+
const projectPath = options.project ?? 'tsconfig.json';
|
|
3375
|
+
const configFile = ts__namespace.findConfigFile(process.cwd(), ts__namespace.sys.fileExists, projectPath) ?? projectPath;
|
|
3376
|
+
const read = ts__namespace.readConfigFile(configFile, ts__namespace.sys.readFile);
|
|
3377
|
+
if (read.error) {
|
|
3378
|
+
const error = new Error(`[motifjs] MJX014: Cannot read ${configFile}: ${ts__namespace.flattenDiagnosticMessageText(read.error.messageText, '\n')}`);
|
|
3379
|
+
error.code = 'MJX014';
|
|
3380
|
+
throw error;
|
|
3381
|
+
}
|
|
3382
|
+
const basePath = pPath.dirname(pPath.resolve(configFile));
|
|
3383
|
+
const parsed = ts__namespace.parseJsonConfigFileContent(read.config, ts__namespace.sys, basePath);
|
|
3384
|
+
const program = ts__namespace.createProgram({ rootNames: parsed.fileNames, options: { ...parsed.options, noEmit: true } });
|
|
3385
|
+
const files = options.files?.map(f => pPath.resolve(basePath, f));
|
|
3386
|
+
return lintProgram(program, files);
|
|
3387
|
+
}
|
|
3388
|
+
function normalize(p) {
|
|
3389
|
+
return p.replace(/\\/g, '/').toLowerCase();
|
|
3390
|
+
}
|
|
3391
|
+
function codeFrame(sf, node) {
|
|
3392
|
+
const start = sf.getLineAndCharacterOfPosition(node.getStart(sf));
|
|
3393
|
+
const lines = sf.text.split(/\r?\n/);
|
|
3394
|
+
const from = Math.max(0, start.line - 1);
|
|
3395
|
+
const to = Math.min(lines.length - 1, start.line + 1);
|
|
3396
|
+
const width = String(to + 1).length;
|
|
3397
|
+
const outLines = [];
|
|
3398
|
+
for (let i = from; i <= to; i++) {
|
|
3399
|
+
const mark = i === start.line ? '>' : ' ';
|
|
3400
|
+
outLines.push(`${mark} ${String(i + 1).padStart(width)} | ${lines[i]}`);
|
|
3401
|
+
if (i === start.line)
|
|
3402
|
+
outLines.push(` ${' '.repeat(width)} | ${' '.repeat(start.character)}^`);
|
|
3403
|
+
}
|
|
3404
|
+
return outLines.join('\n');
|
|
3405
|
+
}
|
|
3406
|
+
|
|
3407
|
+
/** Kaynağı derleyip her JSX ifadesinin neye indiğini döndürür (kod üretilmez, yalnızca kayıt). */
|
|
3408
|
+
function explain(code, filename) {
|
|
3409
|
+
const c = new Compiler();
|
|
3410
|
+
c.explain(code, filename);
|
|
3411
|
+
return c.explanations;
|
|
3412
|
+
}
|
|
3413
|
+
|
|
3414
|
+
exports.Compiler = Compiler;
|
|
3415
|
+
exports.default = vitePlugin;
|
|
3416
|
+
exports.explain = explain;
|
|
3417
|
+
exports.formatExplanations = formatExplanations;
|
|
3418
|
+
exports.lintProgram = lintProgram;
|
|
3419
|
+
exports.lintProject = lintProject;
|
|
3420
|
+
exports.printDiagnostics = printDiagnostics;
|
|
3421
|
+
exports.printExplanations = printExplanations;
|
|
3422
|
+
//# sourceMappingURL=index.cjs.map
|