lc-test3 1.1.12 → 1.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/p.js +132 -753
  2. package/package.json +1 -1
package/p.js CHANGED
@@ -1,753 +1,132 @@
1
- /**
2
- * SWC ��������װ
3
- *
4
- * SWC ���� Rust ��д�ij��� JavaScript/TypeScript ������
5
- * �� Babel �� 20-70 ��
6
- *
7
- * ��ģ���ṩ��
8
- * 1. SWC WASM ��ʼ��
9
- * 2. SWC AST �� Babel AST ��ת��
10
- * 3. ���˵� Babel �ļ��ݻ���
11
- */
12
-
13
- import * as t from '@babel/types';
14
- import { parse as babelParse, ParserOptions } from '@babel/parser';
15
-
16
- // SWC WASM �
17
- let swcModule: typeof import('@swc/wasm-web') | null = null;
18
- let swcInitPromise: Promise<void> | null = null;
19
- let swcAvailable = false;
20
-
21
- // Babel �������ã������ã�
22
- const babelParserConfig: ParserOptions = {
23
- sourceType: 'module',
24
- plugins: [
25
- 'jsx',
26
- 'doExpressions',
27
- 'objectRestSpread',
28
- 'decorators-legacy',
29
- 'classProperties',
30
- 'asyncGenerators',
31
- 'functionBind',
32
- 'dynamicImport',
33
- 'optionalChaining',
34
- ],
35
- };
36
-
37
- // SWC ��������
38
- const swcParserConfig = {
39
- syntax: 'typescript' as const,
40
- tsx: true,
41
- decorators: true,
42
- dynamicImport: true,
43
- };
44
-
45
- const permissionCommentPattern = /\/\*\*[\s\S]*?RESOURCESTREE-START[\s\S]*?RESOURCESTREE-END[\s\S]*?\*\//g;
46
-
47
- function sanitizePermissionCommentsForJSX(code: string) {
48
- return code.replace(permissionCommentPattern, (comment, offset) => {
49
- const rest = code.slice(offset + comment.length);
50
- // SWC �� "return (/**...*/<JSX" �Ľ������ȶ���ֱ���Ƴ�������� JSX ��ʼ��ǩ��Ȩ��ע��
51
- if (/^\s*</.test(rest)) {
52
- return '';
53
- }
54
- return comment;
55
- });
56
- }
57
-
58
- // ����ͳ��
59
- const swcStats = {
60
- swcParseCount: 0,
61
- swcTotalTime: 0,
62
- babelFallbackCount: 0,
63
- babelTotalTime: 0,
64
- conversionCount: 0,
65
- conversionTotalTime: 0,
66
- };
67
-
68
- /**
69
- * ��ʼ�� SWC WASM ģ��
70
- */
71
- export async function initSWC(): Promise<boolean> {
72
- if (swcAvailable) return true;
73
- if (swcInitPromise) {
74
- await swcInitPromise;
75
- return swcAvailable;
76
- }
77
-
78
- swcInitPromise = (async () => {
79
- try {
80
- // ��̬���� SWC WASM
81
- const swc = await import('@swc/wasm-web');
82
-
83
- // ��ʼ�� WASM����Ҫ���� .wasm �ļ���
84
- await swc.default();
85
-
86
- swcModule = swc;
87
- swcAvailable = true;
88
- console.log('%c[SWC] ? WASM ģ���ʼ���ɹ�', 'color: #4CAF50; font-weight: bold;');
89
- } catch (error) {
90
- console.warn('[SWC] ?? WASM ģ�����ʧ�ܣ���ʹ�� Babel ��Ϊ����:', error);
91
- swcAvailable = false;
92
- }
93
- })();
94
-
95
- await swcInitPromise;
96
- return swcAvailable;
97
- }
98
-
99
- /**
100
- * ��� SWC �Ƿ����
101
- */
102
- export function isSWCAvailable(): boolean {
103
- return swcAvailable;
104
- }
105
-
106
- /**
107
- * SWC AST �ڵ�����ӳ�䵽 Babel ����
108
- */
109
- const SWC_TO_BABEL_TYPE: Record<string, string> = {
110
- 'Module': 'File',
111
- 'Script': 'File',
112
- 'ImportDeclaration': 'ImportDeclaration',
113
- 'ExportDeclaration': 'ExportDeclaration',
114
- 'ExportDefaultDeclaration': 'ExportDefaultDeclaration',
115
- 'ExportDefaultExpression': 'ExportDefaultDeclaration',
116
- 'ExportNamedDeclaration': 'ExportNamedDeclaration',
117
- 'ExportAllDeclaration': 'ExportAllDeclaration',
118
- 'VariableDeclaration': 'VariableDeclaration',
119
- 'VariableDeclarator': 'VariableDeclarator',
120
- 'FunctionDeclaration': 'FunctionDeclaration',
121
- 'FunctionExpression': 'FunctionExpression',
122
- 'ArrowFunctionExpression': 'ArrowFunctionExpression',
123
- 'ClassDeclaration': 'ClassDeclaration',
124
- 'ClassExpression': 'ClassExpression',
125
- 'ClassMethod': 'ClassMethod',
126
- 'ClassPrivateMethod': 'ClassPrivateMethod',
127
- 'ClassProperty': 'ClassProperty',
128
- 'ClassPrivateProperty': 'ClassPrivateProperty',
129
- 'Constructor': 'ClassMethod',
130
- 'PrivateName': 'PrivateName',
131
- 'Identifier': 'Identifier',
132
- 'StringLiteral': 'StringLiteral',
133
- 'NumericLiteral': 'NumericLiteral',
134
- 'BooleanLiteral': 'BooleanLiteral',
135
- 'NullLiteral': 'NullLiteral',
136
- 'RegExpLiteral': 'RegExpLiteral',
137
- 'TemplateLiteral': 'TemplateLiteral',
138
- 'ArrayExpression': 'ArrayExpression',
139
- 'ObjectExpression': 'ObjectExpression',
140
- 'CallExpression': 'CallExpression',
141
- 'MemberExpression': 'MemberExpression',
142
- 'BinaryExpression': 'BinaryExpression',
143
- 'UnaryExpression': 'UnaryExpression',
144
- 'ConditionalExpression': 'ConditionalExpression',
145
- 'AssignmentExpression': 'AssignmentExpression',
146
- 'LogicalExpression': 'LogicalExpression',
147
- 'SequenceExpression': 'SequenceExpression',
148
- 'NewExpression': 'NewExpression',
149
- 'ThisExpression': 'ThisExpression',
150
- 'SpreadElement': 'SpreadElement',
151
- 'RestElement': 'RestElement',
152
- 'ObjectPattern': 'ObjectPattern',
153
- 'ArrayPattern': 'ArrayPattern',
154
- 'AssignmentPattern': 'AssignmentPattern',
155
- 'BlockStatement': 'BlockStatement',
156
- 'ReturnStatement': 'ReturnStatement',
157
- 'IfStatement': 'IfStatement',
158
- 'SwitchStatement': 'SwitchStatement',
159
- 'SwitchCase': 'SwitchCase',
160
- 'ForStatement': 'ForStatement',
161
- 'ForInStatement': 'ForInStatement',
162
- 'ForOfStatement': 'ForOfStatement',
163
- 'WhileStatement': 'WhileStatement',
164
- 'DoWhileStatement': 'DoWhileStatement',
165
- 'TryStatement': 'TryStatement',
166
- 'CatchClause': 'CatchClause',
167
- 'ThrowStatement': 'ThrowStatement',
168
- 'BreakStatement': 'BreakStatement',
169
- 'ContinueStatement': 'ContinueStatement',
170
- 'ExpressionStatement': 'ExpressionStatement',
171
- 'EmptyStatement': 'EmptyStatement',
172
- 'DebuggerStatement': 'DebuggerStatement',
173
- 'LabeledStatement': 'LabeledStatement',
174
- 'WithStatement': 'WithStatement',
175
- // JSX
176
- 'JSXElement': 'JSXElement',
177
- 'JSXFragment': 'JSXFragment',
178
- 'JSXOpeningElement': 'JSXOpeningElement',
179
- 'JSXClosingElement': 'JSXClosingElement',
180
- 'JSXOpeningFragment': 'JSXOpeningFragment',
181
- 'JSXClosingFragment': 'JSXClosingFragment',
182
- 'JSXAttribute': 'JSXAttribute',
183
- 'JSXSpreadAttribute': 'JSXSpreadAttribute',
184
- 'JSXExpressionContainer': 'JSXExpressionContainer',
185
- 'JSXText': 'JSXText',
186
- 'JSXIdentifier': 'JSXIdentifier',
187
- 'JSXMemberExpression': 'JSXMemberExpression',
188
- 'JSXNamespacedName': 'JSXNamespacedName',
189
- 'JSXEmptyExpression': 'JSXEmptyExpression',
190
- // ����
191
- 'AwaitExpression': 'AwaitExpression',
192
- 'YieldExpression': 'YieldExpression',
193
- 'TaggedTemplateExpression': 'TaggedTemplateExpression',
194
- 'TemplateElement': 'TemplateElement',
195
- 'OptionalMemberExpression': 'OptionalMemberExpression',
196
- 'OptionalCallExpression': 'OptionalCallExpression',
197
- 'ParenthesisExpression': 'ParenthesizedExpression',
198
- // Property ������Ҫ���⴦��
199
- 'KeyValueProperty': 'ObjectProperty',
200
- 'AssignmentProperty': 'ObjectProperty',
201
- 'GetterProperty': 'ObjectMethod',
202
- 'SetterProperty': 'ObjectMethod',
203
- 'MethodProperty': 'ObjectMethod',
204
- 'SpreadProperty': 'SpreadElement',
205
- 'ShorthandProperty': 'ObjectProperty',
206
- // Import/Export specifiers
207
- 'ImportDefaultSpecifier': 'ImportDefaultSpecifier',
208
- 'ImportSpecifier': 'ImportSpecifier',
209
- 'ImportNamespaceSpecifier': 'ImportNamespaceSpecifier',
210
- 'ExportSpecifier': 'ExportSpecifier',
211
- 'ExportDefaultSpecifier': 'ExportDefaultSpecifier',
212
- 'ExportNamespaceSpecifier': 'ExportNamespaceSpecifier',
213
- 'Computed': 'Computed',
214
- 'SuperPropExpression': 'MemberExpression',
215
- 'AssignmentPatternProperty': 'ObjectProperty',
216
- };
217
-
218
- /**
219
- * �淶�����������б�
220
- */
221
- function normalizeParams(params: any): any[] {
222
- if (Array.isArray(params)) {
223
- return params.map((p) => p?.pat || p);
224
- }
225
- if (params && Array.isArray(params.params)) {
226
- return params.params.map((p: any) => p?.pat || p);
227
- }
228
- return [];
229
- }
230
-
231
- /**
232
- * �淶����Ա���ԣ����� MemberExpression.property Ϊ MemberExpression ��������ʧ��
233
- */
234
- function normalizeMemberProperty(prop: any, computedFlag?: boolean): { property: any; computed: boolean } {
235
- if (!prop) {
236
- return { property: prop, computed: Boolean(computedFlag) };
237
- }
238
-
239
- if (prop.type === 'Computed') {
240
- return { property: convertSWCNode(prop.expression), computed: true };
241
- }
242
-
243
- const converted = convertSWCNode(prop);
244
- const needsComputed = converted?.type === 'MemberExpression';
245
- return { property: converted, computed: Boolean(computedFlag) || needsComputed };
246
- }
247
-
248
- /**
249
- * �ݹ�ת�� SWC AST �ڵ㵽 Babel AST ��ʽ
250
- */
251
- function convertSWCNode(node: any): any {
252
- if (!node || typeof node !== 'object') {
253
- return node;
254
- }
255
-
256
- // ��������
257
- if (Array.isArray(node)) {
258
- return node.map(convertSWCNode);
259
- }
260
-
261
- // ��ȡ�ڵ�����
262
- const swcType = node.type;
263
- if (!swcType) {
264
- // ���� SWC ExprOrSpread �ṹ��{ spread: null|{...}, expression: {...} }
265
- if ('expression' in node && 'spread' in node) {
266
- if (node.spread) {
267
- return {
268
- type: 'SpreadElement',
269
- argument: convertSWCNode(node.expression),
270
- };
271
- }
272
- return convertSWCNode(node.expression);
273
- }
274
- // ������ AST �ڵ�Ķ���
275
- const result: any = {};
276
- for (const key of Object.keys(node)) {
277
- result[key] = convertSWCNode(node[key]);
278
- }
279
- return result;
280
- }
281
-
282
- // ӳ������
283
- const babelType = SWC_TO_BABEL_TYPE[swcType] || swcType;
284
-
285
- // �����½ڵ�
286
- const babelNode: any = {
287
- type: babelType,
288
- };
289
-
290
- // �����������
291
- switch (swcType) {
292
- case 'SuperPropExpression':
293
- const superProp = normalizeMemberProperty(node.property, node.computed);
294
- return {
295
- type: 'MemberExpression',
296
- object: { type: 'Super' },
297
- property: superProp.property,
298
- computed: superProp.computed,
299
- };
300
-
301
- case 'AssignmentPatternProperty':
302
- return {
303
- type: 'ObjectProperty',
304
- key: convertSWCNode(node.key),
305
- value: convertSWCNode(node.value),
306
- computed: node.key?.type === 'Computed' || node.computed || false,
307
- shorthand: false,
308
- };
309
- case 'SuperPropExpression':
310
- return {
311
- type: 'MemberExpression',
312
- object: { type: 'Super' },
313
- property: convertSWCNode(node.property),
314
- computed: node.property?.type === 'Computed' || node.computed || false,
315
- };
316
-
317
- case 'AssignmentPatternProperty':
318
- return {
319
- type: 'ObjectProperty',
320
- key: convertSWCNode(node.key),
321
- value: convertSWCNode(node.value),
322
- computed: node.key?.type === 'Computed' || node.computed || false,
323
- shorthand: false,
324
- };
325
- case 'Computed':
326
- // SWC computed property wrapper
327
- return convertSWCNode(node.expression);
328
- case 'Program':
329
- return {
330
- type: 'Program',
331
- sourceType: node.sourceType || 'module',
332
- body: convertSWCNode(node.body || node.stmts || []),
333
- directives: [],
334
- };
335
- case 'Module':
336
- case 'Script':
337
- // ת��Ϊ Babel �� File �ṹ
338
- return {
339
- type: 'File',
340
- program: {
341
- type: 'Program',
342
- sourceType: 'module',
343
- body: convertSWCNode(node.body || node.stmts || []),
344
- directives: [],
345
- },
346
- };
347
-
348
- case 'ExportDefaultExpression':
349
- return {
350
- type: 'ExportDefaultDeclaration',
351
- declaration: convertSWCNode(node.expression || node.expr || node.decl),
352
- };
353
-
354
- case 'StringLiteral':
355
- babelNode.value = node.value;
356
- babelNode.raw = node.raw;
357
- break;
358
-
359
- case 'TemplateLiteral':
360
- babelNode.expressions = convertSWCNode(node.expressions || node.exprs || []);
361
- babelNode.quasis = convertSWCNode(node.quasis || []);
362
- if (!babelNode.quasis || babelNode.quasis.length === 0) {
363
- babelNode.quasis = [
364
- {
365
- type: 'TemplateElement',
366
- value: { raw: '', cooked: '' },
367
- tail: true,
368
- },
369
- ];
370
- }
371
- if (Array.isArray(babelNode.quasis) && Array.isArray(babelNode.expressions)) {
372
- if (babelNode.quasis.length === babelNode.expressions.length) {
373
- babelNode.quasis.push({
374
- type: 'TemplateElement',
375
- value: { raw: '', cooked: '' },
376
- tail: true,
377
- });
378
- }
379
- const last = babelNode.quasis[babelNode.quasis.length - 1];
380
- if (last) last.tail = true;
381
- }
382
- break;
383
-
384
- case 'NumericLiteral':
385
- babelNode.value = node.value;
386
- babelNode.raw = String(node.value);
387
- break;
388
-
389
- case 'BooleanLiteral':
390
- babelNode.value = node.value;
391
- break;
392
-
393
- case 'Identifier':
394
- babelNode.name = node.value;
395
- break;
396
-
397
- case 'PrivateName':
398
- return {
399
- type: 'PrivateName',
400
- id: convertSWCNode(node.id || { type: 'Identifier', value: node.name }),
401
- };
402
-
403
- case 'KeyValueProperty':
404
- case 'ShorthandProperty':
405
- babelNode.type = 'ObjectProperty';
406
- const keyNode = node.key;
407
- const isComputedKey = keyNode?.type === 'Computed';
408
- const normalizedKey = normalizeMemberProperty(isComputedKey ? keyNode.expression : keyNode, node.computed);
409
- babelNode.key = normalizedKey.property;
410
- babelNode.value = convertSWCNode(node.value);
411
- babelNode.computed = normalizedKey.computed || isComputedKey || node.computed || false;
412
- babelNode.shorthand = swcType === 'ShorthandProperty';
413
- babelNode.method = false;
414
- break;
415
-
416
- case 'GetterProperty':
417
- case 'SetterProperty':
418
- case 'MethodProperty':
419
- babelNode.type = 'ObjectMethod';
420
- const objMethodKey = node.key;
421
- const objMethodComputed = objMethodKey?.type === 'Computed';
422
- const normalizedObjMethodKey = normalizeMemberProperty(objMethodComputed ? objMethodKey.expression : objMethodKey, node.computed);
423
- babelNode.key = normalizedObjMethodKey.property;
424
- babelNode.kind = swcType === 'GetterProperty' ? 'get' :
425
- swcType === 'SetterProperty' ? 'set' : 'method';
426
- babelNode.params = convertSWCNode(normalizeParams(node.params));
427
- babelNode.body = convertSWCNode(node.body);
428
- babelNode.computed = normalizedObjMethodKey.computed || objMethodComputed || node.computed || false;
429
- babelNode.generator = node.generator || false;
430
- babelNode.async = node.async || false;
431
- break;
432
-
433
- case 'ImportDeclaration':
434
- babelNode.source = convertSWCNode(node.source);
435
- babelNode.specifiers = convertSWCNode(node.specifiers || []);
436
- babelNode.importKind = node.typeOnly ? 'type' : 'value';
437
- break;
438
- case 'BlockStatement':
439
- babelNode.body = convertSWCNode(node.body || node.stmts || []);
440
- break;
441
-
442
- case 'ReturnStatement':
443
- babelNode.argument = convertSWCNode(node.argument ?? node.value ?? node.expr ?? null);
444
- break;
445
-
446
- case 'ExpressionStatement':
447
- babelNode.expression = convertSWCNode(node.expression ?? node.expr);
448
- break;
449
-
450
- case 'ImportSpecifier':
451
- babelNode.imported = convertSWCNode(node.imported || node.local);
452
- babelNode.local = convertSWCNode(node.local);
453
- break;
454
-
455
- case 'ImportDefaultSpecifier':
456
- babelNode.local = convertSWCNode(node.local);
457
- break;
458
-
459
- case 'ImportNamespaceSpecifier':
460
- babelNode.local = convertSWCNode(node.local);
461
- break;
462
-
463
- case 'ExportNamedDeclaration':
464
- babelNode.declaration = convertSWCNode(node.declaration);
465
- babelNode.specifiers = convertSWCNode(node.specifiers || []);
466
- babelNode.source = convertSWCNode(node.source);
467
- break;
468
-
469
- case 'ExportDefaultDeclaration':
470
- babelNode.declaration = convertSWCNode(node.decl || node.declaration);
471
- break;
472
-
473
- case 'VariableDeclaration':
474
- babelNode.kind = node.kind;
475
- babelNode.declarations = convertSWCNode(node.declarations);
476
- break;
477
-
478
- case 'VariableDeclarator':
479
- babelNode.id = convertSWCNode(node.id);
480
- babelNode.init = convertSWCNode(node.init);
481
- break;
482
-
483
- case 'FunctionDeclaration':
484
- case 'FunctionExpression':
485
- babelNode.id = convertSWCNode(node.identifier);
486
- babelNode.params = convertSWCNode(normalizeParams(node.params));
487
- babelNode.body = convertSWCNode(node.body);
488
- babelNode.generator = node.generator || false;
489
- babelNode.async = node.async || false;
490
- break;
491
-
492
- case 'ArrowFunctionExpression':
493
- babelNode.params = convertSWCNode(normalizeParams(node.params));
494
- babelNode.body = convertSWCNode(node.body);
495
- babelNode.async = node.async || false;
496
- babelNode.expression = node.body?.type !== 'BlockStatement';
497
- break;
498
-
499
- case 'ClassDeclaration':
500
- case 'ClassExpression':
501
- babelNode.id = convertSWCNode(node.identifier || node.id);
502
- babelNode.superClass = convertSWCNode(node.superClass);
503
- babelNode.decorators = convertSWCNode(node.decorators || []);
504
- babelNode.body = {
505
- type: 'ClassBody',
506
- body: convertSWCNode(node.body?.body || node.body || []),
507
- };
508
- break;
509
-
510
- case 'ClassMethod':
511
- case 'ClassPrivateMethod':
512
- case 'Constructor':
513
- const classMethodKey = node.key;
514
- const classMethodComputed = classMethodKey?.type === 'Computed';
515
- const normalizedClassMethodKey = normalizeMemberProperty(classMethodComputed ? classMethodKey.expression : classMethodKey, node.computed);
516
- babelNode.key = normalizedClassMethodKey.property;
517
- babelNode.kind = swcType === 'Constructor' ? 'constructor' : (node.kind || 'method');
518
- babelNode.params = convertSWCNode(normalizeParams(node.function?.params || node.params));
519
- babelNode.body = convertSWCNode(node.function?.body || node.body);
520
- babelNode.computed = normalizedClassMethodKey.computed || classMethodComputed || node.computed || false;
521
- babelNode.static = node.isStatic || node.static || false;
522
- babelNode.async = node.function?.isAsync || node.async || false;
523
- babelNode.generator = node.function?.isGenerator || node.generator || false;
524
- break;
525
-
526
- case 'ClassProperty':
527
- case 'ClassPrivateProperty':
528
- const classPropKey = node.key;
529
- const classPropComputed = classPropKey?.type === 'Computed';
530
- const normalizedClassPropKey = normalizeMemberProperty(classPropComputed ? classPropKey.expression : classPropKey, node.computed);
531
- babelNode.key = normalizedClassPropKey.property;
532
- babelNode.value = convertSWCNode(node.value);
533
- babelNode.computed = normalizedClassPropKey.computed || classPropComputed || node.computed || false;
534
- babelNode.static = node.isStatic || node.static || false;
535
- break;
536
-
537
- case 'CallExpression':
538
- babelNode.callee = convertSWCNode(node.callee);
539
- babelNode.arguments = convertSWCNode(node.arguments || []);
540
- break;
541
-
542
- case 'OptionalChainingExpression': {
543
- const base = node.base || node.expression || node.expr || node.argument;
544
- const converted = convertSWCNode(base);
545
-
546
- if (converted && (converted.type === 'MemberExpression' || converted.type === 'OptionalMemberExpression')) {
547
- converted.type = 'OptionalMemberExpression';
548
- converted.optional = true;
549
- }
550
-
551
- if (converted && (converted.type === 'CallExpression' || converted.type === 'OptionalCallExpression')) {
552
- converted.type = 'OptionalCallExpression';
553
- converted.optional = true;
554
- }
555
-
556
- return converted;
557
- }
558
-
559
- case 'MemberExpression':
560
- babelNode.object = convertSWCNode(node.object);
561
- const memberProp = normalizeMemberProperty(node.property, node.computed);
562
- babelNode.property = memberProp.property;
563
- babelNode.computed = memberProp.computed;
564
- babelNode.optional = node.optional || false;
565
- break;
566
- case 'NewExpression':
567
- babelNode.callee = convertSWCNode(node.callee);
568
- babelNode.arguments = convertSWCNode(node.arguments || []);
569
- break;
570
- case 'OptionalCallExpression':
571
- babelNode.callee = convertSWCNode(node.callee);
572
- babelNode.arguments = convertSWCNode(node.arguments || []);
573
- babelNode.optional = true;
574
- break;
575
-
576
- case 'JSXElement':
577
- babelNode.openingElement = convertSWCNode(node.opening);
578
- babelNode.closingElement = convertSWCNode(node.closing);
579
- babelNode.children = convertSWCNode(node.children || []);
580
- babelNode.selfClosing = !node.closing;
581
- break;
582
-
583
- case 'JSXOpeningElement':
584
- babelNode.name = convertSWCNode(node.name);
585
- babelNode.attributes = convertSWCNode(node.attributes || []);
586
- babelNode.selfClosing = node.selfClosing || false;
587
- break;
588
-
589
- case 'JSXClosingElement':
590
- babelNode.name = convertSWCNode(node.name);
591
- break;
592
-
593
- case 'JSXAttribute':
594
- babelNode.name = convertSWCNode(node.name);
595
- babelNode.value = convertSWCNode(node.value);
596
- break;
597
-
598
- case 'JSXIdentifier':
599
- babelNode.name = node.value;
600
- break;
601
-
602
- case 'JSXText':
603
- babelNode.value = node.value;
604
- babelNode.raw = node.raw || node.value;
605
- break;
606
-
607
- case 'TemplateElement':
608
- return {
609
- type: 'TemplateElement',
610
- value: {
611
- raw: node.raw ?? node.value?.raw ?? node.cooked ?? '',
612
- cooked: node.cooked ?? node.value?.cooked ?? node.raw ?? '',
613
- },
614
- tail: node.tail ?? false,
615
- };
616
-
617
- case 'JSXExpressionContainer':
618
- babelNode.expression = convertSWCNode(node.expression);
619
- break;
620
-
621
- case 'JSXFragment':
622
- babelNode.openingFragment = { type: 'JSXOpeningFragment' };
623
- babelNode.closingFragment = { type: 'JSXClosingFragment' };
624
- babelNode.children = convertSWCNode(node.children || []);
625
- break;
626
-
627
- default:
628
- // ͨ�ô������ݹ�ת����������
629
- for (const key of Object.keys(node)) {
630
- if (key === 'type' || key === 'span' || key === 'ctxt') continue;
631
- babelNode[key] = convertSWCNode(node[key]);
632
- }
633
- }
634
-
635
- return babelNode;
636
- }
637
-
638
- /**
639
- * �� SWC AST ת��Ϊ Babel ���ݸ�ʽ
640
- */
641
- export function convertSWCToBabel(swcAst: any): t.File {
642
- const startTime = performance.now();
643
- const result = convertSWCNode(swcAst) as t.File;
644
- const duration = performance.now() - startTime;
645
-
646
- swcStats.conversionCount++;
647
- swcStats.conversionTotalTime += duration;
648
-
649
- return result;
650
- }
651
-
652
- /**
653
- * ʹ�� SWC ��������
654
- * ��� SWC �����ã����˵� Babel
655
- */
656
- export function parseWithSWC(code: string): t.File {
657
- const safeCode = sanitizePermissionCommentsForJSX(code);
658
- if (!swcAvailable || !swcModule) {
659
- // ���˵� Babel
660
- const startTime = performance.now();
661
- const ast = babelParse(safeCode, babelParserConfig);
662
- swcStats.babelFallbackCount++;
663
- swcStats.babelTotalTime += performance.now() - startTime;
664
- return ast;
665
- }
666
-
667
- try {
668
- // ʹ�� SWC ����
669
- const startTime = performance.now();
670
- const swcAst = swcModule.parseSync(safeCode, swcParserConfig);
671
- const parseTime = performance.now() - startTime;
672
-
673
- swcStats.swcParseCount++;
674
- swcStats.swcTotalTime += parseTime;
675
-
676
- // ת��Ϊ Babel ��ʽ
677
- return convertSWCToBabel(swcAst);
678
- } catch (error) {
679
- // ����ʧ�ܣ����˵� Babel
680
- console.warn('[SWC] ����ʧ�ܣ����˵� Babel:', error);
681
- const startTime = performance.now();
682
- const ast = babelParse(safeCode, babelParserConfig);
683
- swcStats.babelFallbackCount++;
684
- swcStats.babelTotalTime += performance.now() - startTime;
685
- return ast;
686
- }
687
- }
688
-
689
- /**
690
- * �첽ʹ�� SWC ��������
691
- */
692
- export async function parseWithSWCAsync(code: string): Promise<t.File> {
693
- // ȷ�� SWC �ѳ�ʼ��
694
- await initSWC();
695
- return parseWithSWC(code);
696
- }
697
-
698
- /**
699
- * ��ȡ SWC ����ͳ��
700
- */
701
- export function getSWCStats() {
702
- return {
703
- ...swcStats,
704
- swcAvailable,
705
- swcAverageParseTime: swcStats.swcParseCount > 0
706
- ? swcStats.swcTotalTime / swcStats.swcParseCount
707
- : 0,
708
- babelAverageTime: swcStats.babelFallbackCount > 0
709
- ? swcStats.babelTotalTime / swcStats.babelFallbackCount
710
- : 0,
711
- conversionAverageTime: swcStats.conversionCount > 0
712
- ? swcStats.conversionTotalTime / swcStats.conversionCount
713
- : 0,
714
- speedup: swcStats.babelFallbackCount > 0 && swcStats.swcParseCount > 0
715
- ? (swcStats.babelTotalTime / swcStats.babelFallbackCount) /
716
- ((swcStats.swcTotalTime + swcStats.conversionTotalTime) / swcStats.swcParseCount)
717
- : 0,
718
- };
719
- }
720
-
721
- /**
722
- * ��ӡ SWC ���ܱ���
723
- */
724
- export function printSWCReport(): void {
725
- const stats = getSWCStats();
726
-
727
- console.log('%c=== SWC Parser Report ===', 'color: #FF5722; font-weight: bold;');
728
- console.log(`SWC ����: ${stats.swcAvailable ? '?' : '?'}`);
729
- console.log(`%cSWC ��������: ${stats.swcParseCount}`, 'color: #4CAF50;');
730
- console.log(`%cSWC �ܺ�ʱ: ${stats.swcTotalTime.toFixed(2)}ms`, 'color: #4CAF50;');
731
- console.log(`%cSWC ƽ����ʱ: ${stats.swcAverageParseTime.toFixed(2)}ms`, 'color: #4CAF50;');
732
- console.log(`%cBabel ���˴���: ${stats.babelFallbackCount}`, 'color: #FF9800;');
733
- console.log(`%cBabel �ܺ�ʱ: ${stats.babelTotalTime.toFixed(2)}ms`, 'color: #FF9800;');
734
- console.log(`%cBabel ƽ����ʱ: ${stats.babelAverageTime.toFixed(2)}ms`, 'color: #FF9800;');
735
- console.log(`AST ת������: ${stats.conversionCount}`);
736
- console.log(`AST ת��ƽ����ʱ: ${stats.conversionAverageTime.toFixed(2)}ms`);
737
- if (stats.speedup > 0) {
738
- console.log(`%c���ٱ�: ${stats.speedup.toFixed(1)}x`, 'color: #E91E63; font-weight: bold;');
739
- }
740
- console.log('%c=========================', 'color: #FF5722; font-weight: bold;');
741
- }
742
-
743
- // ��¶��ȫ�֣��������
744
- if (typeof window !== 'undefined') {
745
- (window as any).__SWC_PARSER__ = {
746
- initSWC,
747
- isSWCAvailable,
748
- parseWithSWC,
749
- parseWithSWCAsync,
750
- getSWCStats,
751
- printSWCReport,
752
- };
753
- }
1
+ [ASTCache] Parse miss (SWC) - /src/pages/Login/index.js (2.10ms)
2
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/Home.js (1.90ms)
3
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/TaskPending.js (2.60ms)
4
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/TaskCompleted.js (2.30ms)
5
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/CirculatePending.js (2.40ms)
6
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/CirculateCompleted.js (2.70ms)
7
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/MyProcess.js (2.30ms)
8
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/SyncProcess.js (2.40ms)
9
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/ImportRecord.js (3.00ms)
10
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/PositionMgt.js (2.30ms)
11
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/DepartmentMgt.js (2.70ms)
12
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/UserMgt.js (2.90ms)
13
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/ResourceMgt.js (1.30ms)
14
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/createItem.js (5.30ms)
15
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/traceTask.js (5.80ms)
16
+ swc-parser.ts:682 [SWC] ����ʧ�ܣ����˵� Babel:
17
+ x Unexpected token `Page`. Expected jsx identifier
18
+ ,-[1:1]
19
+ 1 | import React from "react";import { definePage } from "@loview/lowcode-react-boot";import { Page } from "@loview/lowcode-react-antd";import WorkFlowProcessConfigPage from "../components/WorkFlowProcessTrace/index.js";class App extends React.Component {render() {const { match} = this.props;const id = match.params?.id;return (<Page data-dnd="%2Fsrc%2Fpages%2FTraceProcess.js:Page:pagea998" onMount={() => {$function.process.fetchInitProcessTrace(id);}} access={{ relatedInterfaces: [{ label: "����׷�ٽӿ�", value: "/los/${appName}.traceProcess" }, { label: "����׷��-�����������־���ӿ�", value: "/los/${appName}.listComments" }, { label: "����׷��-����ʵ������ӿ�", value: "/los/${appName}.processInstanceDetail" }] }}>
20
+ :  ^^^^
21
+ 2 |
22
+ 3 |
23
+ `----
24
+
25
+
26
+ Caused by:
27
+ 0: failed to parse code
28
+ 1: Syntax Error
29
+ parseWithSWC @ swc-parser.ts:682
30
+ parseCode @ ast-cache.ts:740
31
+ parseSync @ ast-cache.ts:933
32
+ code2astWithCache @ ast-cache.ts:1277
33
+ code2astCached @ parse.ts:112
34
+ get @ light-module.ts:91
35
+ get @ light-module.ts:107
36
+ trackDerivedFunction @ mobx.esm.js:1842
37
+ computeValue_ @ mobx.esm.js:1636
38
+ trackAndCompute @ mobx.esm.js:1613
39
+ get @ mobx.esm.js:1582
40
+ getObservablePropValue_ @ mobx.esm.js:4744
41
+ get @ mobx.esm.js:5243
42
+ hasModelDiff @ workspace.ts:3262
43
+ (anonymous) @ useFolder.tsx:71
44
+ makeFileTree @ useFolder.tsx:64
45
+ useFolder @ useFolder.tsx:303
46
+ (anonymous) @ index.tsx:65
47
+ (anonymous) @ observer.js:44
48
+ (anonymous) @ useObserver.js:80
49
+ trackDerivedFunction @ mobx.esm.js:1842
50
+ track @ mobx.esm.js:2360
51
+ useObserver @ useObserver.js:78
52
+ (anonymous) @ observer.js:44
53
+ renderWithHooks @ react-dom.development.js:15015
54
+ updateFunctionComponent @ react-dom.development.js:17386
55
+ updateSimpleMemoComponent @ react-dom.development.js:17245
56
+ beginWork @ react-dom.development.js:19170
57
+ beginWork$1 @ react-dom.development.js:23970
58
+ performUnitOfWork @ react-dom.development.js:22809
59
+ workLoopSync @ react-dom.development.js:22737
60
+ renderRootSync @ react-dom.development.js:22700
61
+ performSyncWorkOnRoot @ react-dom.development.js:22323
62
+ (anonymous) @ react-dom.development.js:11357
63
+ unstable_runWithPriority @ react.development.js:2764
64
+ runWithPriority$1 @ react-dom.development.js:11306
65
+ flushSyncCallbackQueueImpl @ react-dom.development.js:11352
66
+ flushSyncCallbackQueue @ react-dom.development.js:11339
67
+ discreteUpdates$1 @ react-dom.development.js:22450
68
+ discreteUpdates @ react-dom.development.js:3753
69
+ dispatchDiscreteEvent @ react-dom.development.js:5919
70
+ light-module.ts:99 SyntaxError: Unexpected token (5:135) (at index.js:363:1)
71
+ at constructor (index.js:363:1)
72
+ at JSXParserMixin.raise (index.js:6609:1)
73
+ at JSXParserMixin.unexpected (index.js:6629:1)
74
+ at JSXParserMixin.jsxParseIdentifier (index.js:4581:1)
75
+ at JSXParserMixin.jsxParseNamespacedName (index.js:4588:1)
76
+ at JSXParserMixin.jsxParseAttribute (index.js:4664:1)
77
+ at JSXParserMixin.jsxParseOpeningElementAfterName (index.js:4679:1)
78
+ at JSXParserMixin.jsxParseOpeningElementAt (index.js:4674:1)
79
+ at JSXParserMixin.jsxParseElementAt (index.js:4698:1)
80
+ at JSXParserMixin.jsxParseElementAt (index.js:4710:1)
81
+ at JSXParserMixin.jsxParseElement (index.js:4761:1)
82
+ at JSXParserMixin.parseExprAtom (index.js:4771:1)
83
+ at JSXParserMixin.parseExprSubscripts (index.js:11012:1)
84
+ at JSXParserMixin.parseUpdate (index.js:10997:1)
85
+ at JSXParserMixin.parseMaybeUnary (index.js:10977:1)
86
+ at JSXParserMixin.parseMaybeUnaryOrPrivate (index.js:10830:1)
87
+ at JSXParserMixin.parseExprOps (index.js:10835:1)
88
+ at JSXParserMixin.parseMaybeConditional (index.js:10812:1)
89
+ at JSXParserMixin.parseMaybeAssign (index.js:10765:1)
90
+ at index.js:10734:1
91
+ at JSXParserMixin.allowInAnd (index.js:12361:1)
92
+ at JSXParserMixin.parseMaybeAssignAllowIn (index.js:10734:1)
93
+ at JSXParserMixin.parseParenAndDistinguishExpression (index.js:11608:1)
94
+ at JSXParserMixin.parseExprAtom (index.js:11262:1)
95
+ at JSXParserMixin.parseExprAtom (index.js:4776:1)
96
+ at JSXParserMixin.parseExprSubscripts (index.js:11012:1)
97
+ at JSXParserMixin.parseUpdate (index.js:10997:1)
98
+ at JSXParserMixin.parseMaybeUnary (index.js:10977:1)
99
+ at JSXParserMixin.parseMaybeUnaryOrPrivate (index.js:10830:1)
100
+ at JSXParserMixin.parseExprOps (index.js:10835:1)
101
+ at JSXParserMixin.parseMaybeConditional (index.js:10812:1)
102
+ at JSXParserMixin.parseMaybeAssign (index.js:10765:1)
103
+ at JSXParserMixin.parseExpressionBase (index.js:10718:1)
104
+ at index.js:10714:1
105
+ at JSXParserMixin.allowInAnd (index.js:12356:1)
106
+ at JSXParserMixin.parseExpression (index.js:10714:1)
107
+ at JSXParserMixin.parseReturnStatement (index.js:13061:1)
108
+ at JSXParserMixin.parseStatementContent (index.js:12716:1)
109
+ at JSXParserMixin.parseStatementLike (index.js:12685:1)
110
+ at JSXParserMixin.parseStatementListItem (index.js:12665:1)
111
+ at JSXParserMixin.parseBlockOrModuleBlockBody (index.js:13235:1)
112
+ at JSXParserMixin.parseBlockBody (index.js:13228:1)
113
+ at JSXParserMixin.parseBlock (index.js:13216:1)
114
+ at JSXParserMixin.parseFunctionBody (index.js:12035:1)
115
+ at JSXParserMixin.parseFunctionBodyAndFinish (index.js:12021:1)
116
+ at JSXParserMixin.parseMethod (index.js:11979:1)
117
+ at JSXParserMixin.pushClassMethod (index.js:13642:1)
118
+ at JSXParserMixin.parseClassMemberWithIsStatic (index.js:13530:1)
119
+ at JSXParserMixin.parseClassMember (index.js:13478:1)
120
+ at index.js:13432:1
121
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/ImportDetail.js (5.40ms)
122
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/UpdatePwd.js (1.10ms)
123
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/getTechItem.js (9.60ms)
124
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/createDemo.js (1.50ms)
125
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/createTechRequirement.js (4.30ms)
126
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/techReqDemo.js (9.50ms)
127
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/techReqCreateDemo.js (7.60ms)
128
+ ast-cache.ts:944 [ASTCache] Parse miss (SWC) - /src/pages/techReqDetail.js (1.90ms)
129
+ sandbox.tsx:193 [useSandbox] Setting eventHandlers to sandboxProps, count: 13
130
+ index.tsx:92 [CodeSandbox] eventHandlers comparison: {changed: false, prevKeys: Array(13), nextKeys: Array(13), iframeReady: true}
131
+ sandbox.tsx:193 [useSandbox] Setting eventHandlers to sandboxProps, count: 13
132
+ index.tsx:92 [CodeSandbox] eventHandlers comparison: {changed: false, prevKeys: Array(13), nextKeys: Array(13), iframeReady: true}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lc-test3",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {