@tsrx/core 0.1.19 → 0.1.22
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/package.json +3 -3
- package/src/analyze/prune.js +119 -61
- package/src/analyze/validation.js +122 -5
- package/src/index.js +11 -3
- package/src/parse/index.js +157 -99
- package/src/plugin.js +2417 -956
- package/src/runtime/iterable.js +15 -13
- package/src/scope.js +25 -10
- package/src/source-map-utils.js +1 -1
- package/src/transform/await.js +5 -1
- package/src/transform/jsx/ast-builders.js +46 -62
- package/src/transform/jsx/helpers.js +8 -5
- package/src/transform/jsx/index.js +756 -358
- package/src/transform/jsx-interleave.js +1 -2
- package/src/transform/scoping.js +26 -63
- package/src/transform/segments.js +53 -5
- package/src/transform/style-ref.js +3 -11
- package/src/utils/builders.js +2 -3
- package/types/index.d.ts +181 -125
- package/types/jsx-platform.d.ts +6 -11
- package/types/parse.d.ts +36 -10
- package/types/runtime/ref.d.ts +1 -0
package/types/index.d.ts
CHANGED
|
@@ -59,7 +59,6 @@ export interface CompileOptions {
|
|
|
59
59
|
minify_css?: boolean;
|
|
60
60
|
dev?: boolean;
|
|
61
61
|
hmr?: boolean;
|
|
62
|
-
compat_kinds?: string[];
|
|
63
62
|
/**
|
|
64
63
|
* When true, non-fatal errors are collected on the result's `errors`
|
|
65
64
|
* array instead of being thrown. Defaults to false (strict mode: throws).
|
|
@@ -83,6 +82,19 @@ interface BaseNodeMetaData {
|
|
|
83
82
|
is_capitalized?: boolean;
|
|
84
83
|
commentContainerId?: number;
|
|
85
84
|
parenthesized?: boolean;
|
|
85
|
+
native_tsrx?: boolean;
|
|
86
|
+
native_tsrx_template_block?: boolean;
|
|
87
|
+
templateMode?: 'script' | 'template';
|
|
88
|
+
script_only?: boolean;
|
|
89
|
+
tsrxDirective?: 'if' | 'for' | 'switch' | 'try';
|
|
90
|
+
ts_name?: string;
|
|
91
|
+
delegated?: any;
|
|
92
|
+
returned_tsrx_return?: AST.ReturnStatement;
|
|
93
|
+
styleScopeHash?: string;
|
|
94
|
+
css?: {
|
|
95
|
+
scopedClasses: Map<string, { start: number; end: number; selector: any }>;
|
|
96
|
+
hash: string;
|
|
97
|
+
};
|
|
86
98
|
elementLeadingComments?: AST.Comment[];
|
|
87
99
|
returns?: AST.ReturnStatement[];
|
|
88
100
|
has_return?: boolean;
|
|
@@ -93,6 +105,7 @@ interface BaseNodeMetaData {
|
|
|
93
105
|
regular_js?: boolean;
|
|
94
106
|
returned_tsrx_child?: boolean;
|
|
95
107
|
forceMapping?: boolean;
|
|
108
|
+
generated_loop_skip_if?: boolean;
|
|
96
109
|
lazy_id?: string;
|
|
97
110
|
disable_verification?: boolean;
|
|
98
111
|
lazy_param_binding_mappings?: Array<{
|
|
@@ -171,6 +184,8 @@ declare module 'estree' {
|
|
|
171
184
|
metadata: BaseNodeMetaData & {
|
|
172
185
|
hook_split_block?: boolean;
|
|
173
186
|
native_return_block?: boolean;
|
|
187
|
+
native_tsrx_template_block?: boolean;
|
|
188
|
+
allows_native_return?: boolean;
|
|
174
189
|
};
|
|
175
190
|
}
|
|
176
191
|
|
|
@@ -236,27 +251,175 @@ declare module 'estree' {
|
|
|
236
251
|
|
|
237
252
|
// Include TypeScript node types and TSRX-specific nodes in NodeMap
|
|
238
253
|
interface NodeMap {
|
|
239
|
-
Tsx: Tsx;
|
|
240
|
-
Tsrx: Tsrx;
|
|
241
|
-
TsxCompat: TsxCompat;
|
|
242
|
-
TSRXExpression: TSRXExpression;
|
|
243
254
|
Element: Element;
|
|
244
|
-
|
|
255
|
+
TsrxFragment: TsrxFragment;
|
|
256
|
+
Text: Text;
|
|
257
|
+
TSRXJSXElement: TSRXJSXElement;
|
|
258
|
+
TSRXExpression: TSRXExpression;
|
|
245
259
|
Attribute: Attribute;
|
|
246
260
|
SpreadAttribute: SpreadAttribute;
|
|
261
|
+
JSXCodeBlock: JSXCodeBlock;
|
|
262
|
+
JSXStyleElement: JSXStyleElement;
|
|
263
|
+
JSXIfExpression: JSXIfExpression;
|
|
264
|
+
JSXForExpression: JSXForExpression;
|
|
265
|
+
JSXSwitchExpression: JSXSwitchExpression;
|
|
266
|
+
JSXTryExpression: JSXTryExpression;
|
|
247
267
|
ParenthesizedExpression: ParenthesizedExpression;
|
|
248
|
-
ScriptContent: ScriptContent;
|
|
249
268
|
}
|
|
250
269
|
|
|
251
270
|
interface ExpressionMap {
|
|
252
|
-
|
|
253
|
-
|
|
271
|
+
Element: Element;
|
|
272
|
+
TsrxFragment: TsrxFragment;
|
|
273
|
+
Text: Text;
|
|
274
|
+
TSRXExpression: TSRXExpression;
|
|
275
|
+
JSXCodeBlock: JSXCodeBlock;
|
|
276
|
+
JSXStyleElement: JSXStyleElement;
|
|
277
|
+
JSXIfExpression: JSXIfExpression;
|
|
278
|
+
JSXForExpression: JSXForExpression;
|
|
279
|
+
JSXSwitchExpression: JSXSwitchExpression;
|
|
280
|
+
JSXTryExpression: JSXTryExpression;
|
|
254
281
|
JSXEmptyExpression: ESTreeJSX.JSXEmptyExpression;
|
|
255
282
|
ParenthesizedExpression: ParenthesizedExpression;
|
|
256
283
|
TSAsExpression: TSAsExpression;
|
|
257
284
|
}
|
|
258
285
|
|
|
259
|
-
//
|
|
286
|
+
// Ripple-normalized template node shapes. The core parser emits JSX-shaped
|
|
287
|
+
// TSRX nodes; @tsrx/ripple creates these during its normalization pass.
|
|
288
|
+
interface Attribute extends AST.BaseNode {
|
|
289
|
+
type: 'Attribute';
|
|
290
|
+
name: AST.Identifier;
|
|
291
|
+
value: any;
|
|
292
|
+
shorthand?: boolean;
|
|
293
|
+
metadata: BaseNodeMetaData;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
interface SpreadAttribute extends AST.BaseNode {
|
|
297
|
+
type: 'SpreadAttribute';
|
|
298
|
+
argument: AST.Expression;
|
|
299
|
+
metadata: BaseNodeMetaData;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
interface Element extends AST.BaseExpression {
|
|
303
|
+
type: 'Element';
|
|
304
|
+
id: AST.Identifier | AST.MemberExpression | AST.Literal;
|
|
305
|
+
attributes: Array<Attribute | SpreadAttribute>;
|
|
306
|
+
children: AST.Node[];
|
|
307
|
+
openingElement: ESTreeJSX.JSXOpeningElement;
|
|
308
|
+
closingElement: ESTreeJSX.JSXClosingElement | null;
|
|
309
|
+
selfClosing?: boolean;
|
|
310
|
+
unclosed?: boolean;
|
|
311
|
+
css?: string;
|
|
312
|
+
metadata: BaseNodeMetaData;
|
|
313
|
+
start: number;
|
|
314
|
+
end: number;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
interface TsrxFragment extends AST.BaseExpression {
|
|
318
|
+
type: 'TsrxFragment';
|
|
319
|
+
children: AST.Node[];
|
|
320
|
+
openingElement?: ESTreeJSX.JSXOpeningFragment;
|
|
321
|
+
closingElement?: ESTreeJSX.JSXClosingFragment | null;
|
|
322
|
+
selfClosing?: boolean;
|
|
323
|
+
attributes?: Array<Attribute | SpreadAttribute>;
|
|
324
|
+
metadata: BaseNodeMetaData;
|
|
325
|
+
start: number;
|
|
326
|
+
end: number;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
interface Text extends AST.BaseExpression {
|
|
330
|
+
type: 'Text';
|
|
331
|
+
expression: AST.Expression;
|
|
332
|
+
metadata: BaseNodeMetaData;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
interface TSRXExpression extends AST.BaseExpression {
|
|
336
|
+
type: 'TSRXExpression';
|
|
337
|
+
expression: AST.Expression;
|
|
338
|
+
metadata: BaseNodeMetaData;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
type TSRXJSXChild =
|
|
342
|
+
| ESTreeJSX.JSXText
|
|
343
|
+
| ESTreeJSX.JSXExpressionContainer
|
|
344
|
+
| ESTreeJSX.JSXSpreadChild
|
|
345
|
+
| TSRXJSXElement
|
|
346
|
+
| TSRXJSXFragment
|
|
347
|
+
| AST.JSXCodeBlock;
|
|
348
|
+
|
|
349
|
+
interface TSRXJSXElement
|
|
350
|
+
extends Omit<ESTreeJSX.JSXElement, 'children'>, AST.NodeWithMaybeComments {
|
|
351
|
+
children: TSRXJSXChild[];
|
|
352
|
+
metadata: BaseNodeMetaData & {
|
|
353
|
+
ts_name?: string;
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
interface TSRXJSXFragment
|
|
358
|
+
extends Omit<ESTreeJSX.JSXFragment, 'children'>, AST.NodeWithMaybeComments {
|
|
359
|
+
children: TSRXJSXChild[];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
interface JSXCodeBlock extends AST.BaseExpression {
|
|
363
|
+
type: 'JSXCodeBlock';
|
|
364
|
+
body: AST.Statement[];
|
|
365
|
+
render: AST.Node | null;
|
|
366
|
+
metadata: BaseNodeMetaData;
|
|
367
|
+
innerComments?: AST.Comment[] | undefined;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
interface JSXStyleElement extends AST.BaseExpression {
|
|
371
|
+
type: 'JSXStyleElement';
|
|
372
|
+
openingElement: ESTreeJSX.JSXOpeningElement;
|
|
373
|
+
closingElement: ESTreeJSX.JSXClosingElement | null;
|
|
374
|
+
children: AST.CSS.StyleSheet[];
|
|
375
|
+
css?: string;
|
|
376
|
+
metadata: BaseNodeMetaData;
|
|
377
|
+
unclosed?: boolean;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
interface JSXIfExpression extends AST.BaseExpression {
|
|
381
|
+
type: 'JSXIfExpression';
|
|
382
|
+
statementType: 'IfStatement';
|
|
383
|
+
test: AST.Expression;
|
|
384
|
+
consequent: AST.Statement;
|
|
385
|
+
alternate: AST.Statement | null;
|
|
386
|
+
metadata: BaseNodeMetaData;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
interface JSXForExpression extends AST.BaseExpression {
|
|
390
|
+
type: 'JSXForExpression';
|
|
391
|
+
statementType: 'ForStatement' | 'ForInStatement' | 'ForOfStatement';
|
|
392
|
+
body: AST.Statement;
|
|
393
|
+
init?: AST.VariableDeclaration | AST.Expression | null;
|
|
394
|
+
test?: AST.Expression | null;
|
|
395
|
+
update?: AST.Expression | null;
|
|
396
|
+
left?: AST.VariableDeclaration | AST.Pattern;
|
|
397
|
+
right?: AST.Expression;
|
|
398
|
+
await?: boolean;
|
|
399
|
+
index?: AST.Identifier | null;
|
|
400
|
+
key?: AST.Expression | null;
|
|
401
|
+
empty?: AST.BlockStatement | null;
|
|
402
|
+
metadata: BaseNodeMetaData;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
interface JSXSwitchExpression extends AST.BaseExpression {
|
|
406
|
+
type: 'JSXSwitchExpression';
|
|
407
|
+
statementType: 'SwitchStatement';
|
|
408
|
+
discriminant: AST.Expression;
|
|
409
|
+
cases: AST.SwitchCase[];
|
|
410
|
+
metadata: BaseNodeMetaData;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
interface JSXTryExpression extends AST.BaseExpression {
|
|
414
|
+
type: 'JSXTryExpression';
|
|
415
|
+
statementType: 'TryStatement';
|
|
416
|
+
block: AST.BlockStatement;
|
|
417
|
+
handler: AST.CatchClause | null;
|
|
418
|
+
finalizer: AST.BlockStatement | null;
|
|
419
|
+
pending?: AST.BlockStatement | null;
|
|
420
|
+
metadata: BaseNodeMetaData;
|
|
421
|
+
}
|
|
422
|
+
|
|
260
423
|
interface ParenthesizedExpression extends AST.BaseNode {
|
|
261
424
|
type: 'ParenthesizedExpression';
|
|
262
425
|
expression: AST.Expression;
|
|
@@ -294,6 +457,7 @@ declare module 'estree' {
|
|
|
294
457
|
interface ForOfStatement {
|
|
295
458
|
index?: AST.Identifier | null;
|
|
296
459
|
key?: AST.Expression | null;
|
|
460
|
+
empty?: AST.BlockStatement | null;
|
|
297
461
|
}
|
|
298
462
|
|
|
299
463
|
interface ImportDeclaration {
|
|
@@ -345,109 +509,7 @@ declare module 'estree' {
|
|
|
345
509
|
trailingComments?: AST.Comment[] | undefined;
|
|
346
510
|
}
|
|
347
511
|
|
|
348
|
-
|
|
349
|
-
type: 'Tsx';
|
|
350
|
-
attributes: Array<any>;
|
|
351
|
-
children: ESTreeJSX.JSXElement['children'];
|
|
352
|
-
selfClosing?: boolean;
|
|
353
|
-
unclosed?: boolean;
|
|
354
|
-
openingElement: ESTreeJSX.JSXOpeningElement;
|
|
355
|
-
closingElement: ESTreeJSX.JSXClosingElement;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
interface Tsrx extends AST.BaseExpression {
|
|
359
|
-
type: 'Tsrx';
|
|
360
|
-
attributes: Array<any>;
|
|
361
|
-
children: AST.Node[];
|
|
362
|
-
selfClosing?: boolean;
|
|
363
|
-
unclosed?: boolean;
|
|
364
|
-
openingElement: ESTreeJSX.JSXOpeningElement;
|
|
365
|
-
closingElement: ESTreeJSX.JSXClosingElement;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
interface TsxCompat extends AST.BaseNode {
|
|
369
|
-
type: 'TsxCompat';
|
|
370
|
-
kind: string;
|
|
371
|
-
attributes: Array<any>;
|
|
372
|
-
children: ESTreeJSX.JSXElement['children'];
|
|
373
|
-
selfClosing?: boolean;
|
|
374
|
-
unclosed?: boolean;
|
|
375
|
-
openingElement: ESTreeJSX.JSXOpeningElement;
|
|
376
|
-
closingElement: ESTreeJSX.JSXClosingElement;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
export interface TSRXExpression extends AST.BaseExpression {
|
|
380
|
-
type: 'TSRXExpression';
|
|
381
|
-
expression: AST.Expression;
|
|
382
|
-
loc?: AST.SourceLocation;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
interface Element extends AST.BaseNode {
|
|
386
|
-
type: 'Element';
|
|
387
|
-
// MemberExpression for namespaced or dynamic elements
|
|
388
|
-
id: AST.Identifier | AST.MemberExpression;
|
|
389
|
-
attributes: TSRXAttribute[];
|
|
390
|
-
children: AST.Node[];
|
|
391
|
-
selfClosing?: boolean;
|
|
392
|
-
unclosed?: boolean;
|
|
393
|
-
loc: SourceLocation;
|
|
394
|
-
metadata: BaseNodeMetaData & {
|
|
395
|
-
ts_name?: string;
|
|
396
|
-
// for <style> tag
|
|
397
|
-
styleScopeHash?: string;
|
|
398
|
-
// for elements with scoped style classes
|
|
399
|
-
css?: {
|
|
400
|
-
scopedClasses: Map<
|
|
401
|
-
string,
|
|
402
|
-
{
|
|
403
|
-
start: number;
|
|
404
|
-
end: number;
|
|
405
|
-
selector: CSS.ClassSelector;
|
|
406
|
-
}
|
|
407
|
-
>;
|
|
408
|
-
hash: string;
|
|
409
|
-
};
|
|
410
|
-
};
|
|
411
|
-
openingElement: ESTreeJSX.JSXOpeningElement;
|
|
412
|
-
closingElement: ESTreeJSX.JSXClosingElement;
|
|
413
|
-
// for <style> tags
|
|
414
|
-
css?: string;
|
|
415
|
-
innerComments?: Comment[];
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
export interface TextNode extends AST.BaseExpression {
|
|
419
|
-
type: 'Text';
|
|
420
|
-
expression: AST.Expression;
|
|
421
|
-
raw?: string;
|
|
422
|
-
loc?: AST.SourceLocation;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
interface ScriptContent extends Omit<AST.Element, 'type'> {
|
|
426
|
-
type: 'ScriptContent';
|
|
427
|
-
content: string;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* TSRX attribute nodes
|
|
432
|
-
*/
|
|
433
|
-
interface Attribute extends AST.BaseNode {
|
|
434
|
-
type: 'Attribute';
|
|
435
|
-
name: AST.Identifier;
|
|
436
|
-
value: AST.Expression | null;
|
|
437
|
-
loc?: AST.SourceLocation;
|
|
438
|
-
shorthand?: boolean;
|
|
439
|
-
metadata: BaseNodeMetaData & {
|
|
440
|
-
delegated?: boolean;
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
interface SpreadAttribute extends AST.BaseNode {
|
|
445
|
-
type: 'SpreadAttribute';
|
|
446
|
-
argument: AST.Expression;
|
|
447
|
-
loc?: AST.SourceLocation;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
export type TSRXDeclaration = AST.Declaration | AST.TSDeclareFunction;
|
|
512
|
+
type TSRXDeclaration = AST.Declaration | AST.TSDeclareFunction;
|
|
451
513
|
|
|
452
514
|
interface TSRXExportNamedDeclaration extends Omit<AST.ExportNamedDeclaration, 'declaration'> {
|
|
453
515
|
declaration?: TSRXDeclaration | null | undefined;
|
|
@@ -457,11 +519,9 @@ declare module 'estree' {
|
|
|
457
519
|
body: (Program['body'][number] | FunctionExpression)[];
|
|
458
520
|
}
|
|
459
521
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
export type TSRXStatement = AST.Statement | TSESTree.Statement;
|
|
522
|
+
type TSRXStatement = AST.Statement | TSESTree.Statement;
|
|
463
523
|
|
|
464
|
-
|
|
524
|
+
type NodeWithChildren = TSRXJSXElement | TSRXJSXFragment | JSXStyleElement;
|
|
465
525
|
|
|
466
526
|
export namespace CSS {
|
|
467
527
|
export interface BaseNode extends AST.NodeWithMaybeComments {
|
|
@@ -1143,8 +1203,7 @@ export interface ParseOptions {
|
|
|
1143
1203
|
/**
|
|
1144
1204
|
* Analyze options
|
|
1145
1205
|
*/
|
|
1146
|
-
export interface AnalyzeOptions
|
|
1147
|
-
extends ParseOptions, Pick<CompileOptions, 'mode' | 'compat_kinds'> {
|
|
1206
|
+
export interface AnalyzeOptions extends ParseOptions, Pick<CompileOptions, 'mode'> {
|
|
1148
1207
|
errors?: CompileError[];
|
|
1149
1208
|
to_ts?: boolean;
|
|
1150
1209
|
}
|
|
@@ -1222,8 +1281,7 @@ export interface Binding {
|
|
|
1222
1281
|
| AST.ClassDeclaration
|
|
1223
1282
|
| AST.ImportDeclaration
|
|
1224
1283
|
| AST.TSModuleDeclaration
|
|
1225
|
-
|
|
|
1226
|
-
| AST.Tsrx;
|
|
1284
|
+
| ESTreeJSX.JSXFragment;
|
|
1227
1285
|
/** Whether this binding has been reassigned */
|
|
1228
1286
|
reassigned: boolean;
|
|
1229
1287
|
/** Whether this binding has been mutated (property access) */
|
|
@@ -1323,8 +1381,7 @@ export interface ScopeInterface {
|
|
|
1323
1381
|
| AST.ClassDeclaration
|
|
1324
1382
|
| AST.ImportDeclaration
|
|
1325
1383
|
| AST.TSModuleDeclaration
|
|
1326
|
-
|
|
|
1327
|
-
| AST.Tsrx,
|
|
1384
|
+
| ESTreeJSX.JSXFragment,
|
|
1328
1385
|
): Binding;
|
|
1329
1386
|
/** Get binding by name */
|
|
1330
1387
|
get(name: string): Binding | null;
|
|
@@ -1369,10 +1426,9 @@ export interface AnalysisState extends BaseState {
|
|
|
1369
1426
|
filename: string;
|
|
1370
1427
|
};
|
|
1371
1428
|
};
|
|
1372
|
-
elements?: AST.Element
|
|
1429
|
+
elements?: Array<ESTreeJSX.JSXElement | AST.Element>;
|
|
1373
1430
|
function_depth?: number;
|
|
1374
1431
|
collect?: boolean;
|
|
1375
|
-
configured_compat_kinds?: Set<string>;
|
|
1376
1432
|
metadata: BaseStateMetaData & {
|
|
1377
1433
|
styleClasses?: StyleClasses;
|
|
1378
1434
|
};
|
package/types/jsx-platform.d.ts
CHANGED
|
@@ -197,7 +197,7 @@ export interface JsxPlatformHooks {
|
|
|
197
197
|
renderForOf?: (node: any, loopParams: any[], bodyStatements: any[], ctx: any) => any | null;
|
|
198
198
|
/**
|
|
199
199
|
* Optionally replace the default React-style pending lowering for
|
|
200
|
-
*
|
|
200
|
+
* `@try { ... } @pending { ... }`. The default emits
|
|
201
201
|
* `<Suspense fallback={fallbackContent}>tryContent</Suspense>`.
|
|
202
202
|
* Vue Vapor uses this to provide `default` and `fallback` slots via
|
|
203
203
|
* `v-slots`.
|
|
@@ -241,11 +241,11 @@ export interface JsxPlatformHooks {
|
|
|
241
241
|
*/
|
|
242
242
|
createErrorBoundaryContent?: (tryContent: any, ctx: any, node: any) => any | null;
|
|
243
243
|
/**
|
|
244
|
-
*
|
|
244
|
+
* Customize lowering for a native JSX element. Default is the
|
|
245
245
|
* factory's `to_jsx_element`. The hook receives the walker-transformed
|
|
246
246
|
* node (`inner`, with children already lowered) plus the element's
|
|
247
247
|
* raw pre-walk children — Solid uses the latter to detect a lone
|
|
248
|
-
* `
|
|
248
|
+
* `JSXText` child it can hoist to a `textContent` attribute before the
|
|
249
249
|
* generic text→JSXExpressionContainer transform runs.
|
|
250
250
|
*/
|
|
251
251
|
transformElement?: (inner: any, ctx: any, rawChildren: any[]) => any;
|
|
@@ -314,12 +314,12 @@ export interface JsxPlatform {
|
|
|
314
314
|
*/
|
|
315
315
|
fragment?: string;
|
|
316
316
|
/**
|
|
317
|
-
* Module to import `Suspense` from when
|
|
317
|
+
* Module to import `Suspense` from when an `@try { ... } @pending { ... }`
|
|
318
318
|
* block appears. React: `'react'`. Preact: `'preact/compat'`.
|
|
319
319
|
*/
|
|
320
320
|
suspense: string;
|
|
321
321
|
/**
|
|
322
|
-
* Module to import `TsrxErrorBoundary` from when
|
|
322
|
+
* Module to import `TsrxErrorBoundary` from when an `@try { ... } @catch (...)`
|
|
323
323
|
* block appears. Usually `'@tsrx/<platform>/error-boundary'`.
|
|
324
324
|
*/
|
|
325
325
|
errorBoundary: string;
|
|
@@ -357,11 +357,6 @@ export interface JsxPlatform {
|
|
|
357
357
|
* not rewrite authored attributes.
|
|
358
358
|
*/
|
|
359
359
|
classAttrName?: 'class' | 'className';
|
|
360
|
-
/**
|
|
361
|
-
* Accepted values of `kind` in `<tsx:kind>` compat blocks. React accepts
|
|
362
|
-
* only `'react'`. Preact accepts both `'preact'` and `'react'`.
|
|
363
|
-
*/
|
|
364
|
-
acceptedTsxKinds: readonly string[];
|
|
365
360
|
/**
|
|
366
361
|
* How to collapse multiple `ref` attributes on the same element into
|
|
367
362
|
* one. React's and Preact's runtimes treat duplicate `ref` props as
|
|
@@ -408,7 +403,7 @@ export interface JsxPlatform {
|
|
|
408
403
|
scanUseServerDirectiveForAwaitWithCustomValidator?: boolean;
|
|
409
404
|
/**
|
|
410
405
|
* Optional branded compiler error for targets that cannot lower
|
|
411
|
-
*
|
|
406
|
+
* `@try { ... } @pending { ... }` in component template context.
|
|
412
407
|
*
|
|
413
408
|
* When provided, the shared try-block lowering rejects any `pending`
|
|
414
409
|
* block with this message instead of emitting a React-style
|
package/types/parse.d.ts
CHANGED
|
@@ -422,6 +422,11 @@ export namespace Parse {
|
|
|
422
422
|
tokContexts: AcornTypeScriptTokContexts;
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
+
export interface AcornTypeScriptFunctionBodyConfig {
|
|
426
|
+
isFunctionDeclaration?: boolean | number;
|
|
427
|
+
isClassMethod?: boolean;
|
|
428
|
+
}
|
|
429
|
+
|
|
425
430
|
interface Scope {
|
|
426
431
|
flags: number;
|
|
427
432
|
var: string[];
|
|
@@ -489,6 +494,8 @@ export namespace Parse {
|
|
|
489
494
|
inAsync: boolean;
|
|
490
495
|
/** Whether we're inside a function */
|
|
491
496
|
inFunction: boolean;
|
|
497
|
+
/** Whether @sveltejs/acorn-typescript is currently parsing a TypeScript type */
|
|
498
|
+
inType: boolean;
|
|
492
499
|
/** Stack of label names for break/continue statements */
|
|
493
500
|
labels: Array<{ kind: string | null; name?: string; statementStart?: number }>;
|
|
494
501
|
/** Current scope flags stack */
|
|
@@ -600,6 +607,12 @@ export namespace Parse {
|
|
|
600
607
|
*/
|
|
601
608
|
getTokenFromCode(code: number): void;
|
|
602
609
|
|
|
610
|
+
/**
|
|
611
|
+
* Get token from character code while in a TypeScript type context
|
|
612
|
+
* Added by @sveltejs/acorn-typescript
|
|
613
|
+
*/
|
|
614
|
+
getTokenFromCodeInType(code: number): void;
|
|
615
|
+
|
|
603
616
|
/**
|
|
604
617
|
* Get current position as Position object
|
|
605
618
|
* @returns { line: number, column: number, index: number }
|
|
@@ -1116,6 +1129,16 @@ export namespace Parse {
|
|
|
1116
1129
|
|
|
1117
1130
|
tsCheckTypeAnnotationForReadOnly(node: AST.TSTypeOperator): void;
|
|
1118
1131
|
|
|
1132
|
+
/**
|
|
1133
|
+
* Run a parser callback with @sveltejs/acorn-typescript's type-context flag enabled
|
|
1134
|
+
*/
|
|
1135
|
+
tsInType<T>(cb: () => T): T;
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Parse a TypeScript return type or type predicate annotation
|
|
1139
|
+
*/
|
|
1140
|
+
tsParseTypeOrTypePredicateAnnotation(returnToken: TokenType): AST.TSTypeAnnotation;
|
|
1141
|
+
|
|
1119
1142
|
tsParseTypeArguments(): AST.Node;
|
|
1120
1143
|
|
|
1121
1144
|
tsTryParseTypeAnnotation(): AST.TSTypeAnnotation;
|
|
@@ -1172,9 +1195,7 @@ export namespace Parse {
|
|
|
1172
1195
|
*/
|
|
1173
1196
|
parseTopLevel(node: AST.Program): AST.Program;
|
|
1174
1197
|
|
|
1175
|
-
parseElement():
|
|
1176
|
-
|
|
1177
|
-
parseDoubleQuotedTextChild(): AST.TextNode;
|
|
1198
|
+
parseElement(): ESTreeJSX.JSXElement | ESTreeJSX.JSXFragment | AST.JSXStyleElement;
|
|
1178
1199
|
|
|
1179
1200
|
parseTemplateBody(
|
|
1180
1201
|
body: (AST.Statement | AST.Node | ESTreeJSX.JSXText | ESTreeJSX.JSXElement['children'])[],
|
|
@@ -1192,10 +1213,11 @@ export namespace Parse {
|
|
|
1192
1213
|
topLevel?: boolean,
|
|
1193
1214
|
exports?: AST.ExportSpecifier,
|
|
1194
1215
|
):
|
|
1195
|
-
| AST.TSRXExpression
|
|
1196
|
-
| AST.TextNode
|
|
1197
|
-
| ESTreeJSX.JSXEmptyExpression
|
|
1198
1216
|
| ESTreeJSX.JSXExpressionContainer
|
|
1217
|
+
| ESTreeJSX.JSXElement
|
|
1218
|
+
| ESTreeJSX.JSXFragment
|
|
1219
|
+
| AST.JSXStyleElement
|
|
1220
|
+
| ESTreeJSX.JSXText
|
|
1199
1221
|
| AST.ExpressionStatement
|
|
1200
1222
|
| ReturnType<Parser['parseElement']>
|
|
1201
1223
|
| AST.Statement;
|
|
@@ -1351,11 +1373,15 @@ export namespace Parse {
|
|
|
1351
1373
|
* Parse function body
|
|
1352
1374
|
*/
|
|
1353
1375
|
parseFunctionBody(
|
|
1354
|
-
node: AST.
|
|
1376
|
+
node: AST.FunctionDeclaration | AST.FunctionExpression | AST.ArrowFunctionExpression,
|
|
1355
1377
|
isArrowFunction: boolean,
|
|
1356
1378
|
isMethod: boolean,
|
|
1357
1379
|
forInit?: ForInit,
|
|
1358
|
-
|
|
1380
|
+
tsConfig?: AcornTypeScriptFunctionBodyConfig,
|
|
1381
|
+
): AST.Node;
|
|
1382
|
+
|
|
1383
|
+
/** Check function parameters for duplicate names and invalid bindings */
|
|
1384
|
+
checkParams(node: AST.Node, allowDuplicates: boolean): void;
|
|
1359
1385
|
|
|
1360
1386
|
/** Initialize function node properties */
|
|
1361
1387
|
initFunction(node: AST.Node): void;
|
|
@@ -1627,7 +1653,7 @@ export namespace Parse {
|
|
|
1627
1653
|
* Parse JSX attribute (name="value" or {spread})
|
|
1628
1654
|
* @returns JSXAttribute or JSXSpreadAttribute
|
|
1629
1655
|
*/
|
|
1630
|
-
jsx_parseAttribute():
|
|
1656
|
+
jsx_parseAttribute(): ESTreeJSX.JSXAttribute | ESTreeJSX.JSXSpreadAttribute;
|
|
1631
1657
|
|
|
1632
1658
|
/**
|
|
1633
1659
|
* Parse JSX opening element at position
|
|
@@ -1670,7 +1696,7 @@ export namespace Parse {
|
|
|
1670
1696
|
* Parse complete JSX element
|
|
1671
1697
|
* @returns JSXElement or JSXFragment
|
|
1672
1698
|
*/
|
|
1673
|
-
jsx_parseElement(): ESTreeJSX.JSXElement;
|
|
1699
|
+
jsx_parseElement(): ESTreeJSX.JSXElement | AST.JSXStyleElement;
|
|
1674
1700
|
|
|
1675
1701
|
// ============================================================
|
|
1676
1702
|
// Try-Parse for Recovery
|
package/types/runtime/ref.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type MergeableVueRef<T> = { value: T | null };
|
|
|
6
6
|
export type RefProp<T = unknown> = (node: T | null) => void | (() => void);
|
|
7
7
|
export type RefValue<T = Element> =
|
|
8
8
|
| ((node: T) => void | (() => void))
|
|
9
|
+
| readonly RefValue<T>[]
|
|
9
10
|
| { current: T | null }
|
|
10
11
|
| { value: T | null }
|
|
11
12
|
| T
|