esrap 1.4.4 → 1.4.6
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 +2 -2
- package/src/handlers.js +26 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esrap",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6",
|
|
4
4
|
"description": "Parse in reverse",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"types": "./types/index.d.ts",
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@changesets/cli": "^2.27.11",
|
|
23
|
+
"@sveltejs/acorn-typescript": "^1.0.5",
|
|
23
24
|
"@typescript-eslint/types": "^8.2.0",
|
|
24
25
|
"@vitest/ui": "^2.1.1",
|
|
25
26
|
"acorn": "^8.11.3",
|
|
26
|
-
"acorn-typescript": "^1.4.13",
|
|
27
27
|
"dts-buddy": "^0.5.4",
|
|
28
28
|
"prettier": "^3.0.3",
|
|
29
29
|
"typescript": "^5.7.2",
|
package/src/handlers.js
CHANGED
|
@@ -116,15 +116,10 @@ function prepend_comments(comments, state, newlines) {
|
|
|
116
116
|
*/
|
|
117
117
|
function quote(string, char) {
|
|
118
118
|
let out = char;
|
|
119
|
-
let escaped = false;
|
|
120
119
|
|
|
121
120
|
for (const c of string) {
|
|
122
|
-
if (
|
|
123
|
-
out += c;
|
|
124
|
-
escaped = false;
|
|
125
|
-
} else if (c === '\\') {
|
|
121
|
+
if (c === '\\') {
|
|
126
122
|
out += '\\\\';
|
|
127
|
-
escaped = true;
|
|
128
123
|
} else if (c === char) {
|
|
129
124
|
out += '\\' + c;
|
|
130
125
|
} else if (c === '\n') {
|
|
@@ -501,8 +496,9 @@ function handle_type_annotation(node, state) {
|
|
|
501
496
|
case 'TSTypeReference':
|
|
502
497
|
handle(node.typeName, state);
|
|
503
498
|
|
|
504
|
-
|
|
505
|
-
|
|
499
|
+
if (node.typeArguments) {
|
|
500
|
+
handle_type_annotation(node.typeArguments, state);
|
|
501
|
+
}
|
|
506
502
|
break;
|
|
507
503
|
case 'TSTypeParameterInstantiation':
|
|
508
504
|
case 'TSTypeParameterDeclaration':
|
|
@@ -514,7 +510,7 @@ function handle_type_annotation(node, state) {
|
|
|
514
510
|
state.commands.push('>');
|
|
515
511
|
break;
|
|
516
512
|
case 'TSTypeParameter':
|
|
517
|
-
// @ts-expect-error `acorn-typescript` and `@typescript-
|
|
513
|
+
// @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
|
|
518
514
|
state.commands.push(node.name);
|
|
519
515
|
|
|
520
516
|
if (node.constraint) {
|
|
@@ -536,14 +532,14 @@ function handle_type_annotation(node, state) {
|
|
|
536
532
|
case 'TSFunctionType':
|
|
537
533
|
if (node.typeParameters) handle_type_annotation(node.typeParameters, state);
|
|
538
534
|
|
|
539
|
-
// @ts-expect-error `acorn-typescript` and `@typescript-
|
|
535
|
+
// @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
|
|
540
536
|
const parameters = node.parameters;
|
|
541
537
|
state.commands.push('(');
|
|
542
538
|
sequence(parameters, state, false, handle);
|
|
543
539
|
|
|
544
540
|
state.commands.push(') => ');
|
|
545
541
|
|
|
546
|
-
// @ts-expect-error `acorn-typescript` and `@typescript-
|
|
542
|
+
// @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
|
|
547
543
|
handle_type_annotation(node.typeAnnotation.typeAnnotation, state);
|
|
548
544
|
break;
|
|
549
545
|
case 'TSIndexSignature':
|
|
@@ -552,19 +548,19 @@ function handle_type_annotation(node, state) {
|
|
|
552
548
|
sequence(indexParameters, state, false, handle);
|
|
553
549
|
state.commands.push(']');
|
|
554
550
|
|
|
555
|
-
// @ts-expect-error `acorn-typescript` and `@typescript-
|
|
551
|
+
// @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
|
|
556
552
|
handle_type_annotation(node.typeAnnotation, state);
|
|
557
553
|
break;
|
|
558
554
|
case 'TSMethodSignature':
|
|
559
555
|
handle(node.key, state);
|
|
560
556
|
|
|
561
|
-
// @ts-expect-error `acorn-typescript` and `@typescript-
|
|
557
|
+
// @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
|
|
562
558
|
const parametersSignature = node.parameters;
|
|
563
559
|
state.commands.push('(');
|
|
564
560
|
sequence(parametersSignature, state, false, handle);
|
|
565
561
|
state.commands.push(')');
|
|
566
562
|
|
|
567
|
-
// @ts-expect-error `acorn-typescript` and `@typescript-
|
|
563
|
+
// @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
|
|
568
564
|
handle_type_annotation(node.typeAnnotation, state);
|
|
569
565
|
break;
|
|
570
566
|
case 'TSExpressionWithTypeArguments':
|
|
@@ -605,6 +601,16 @@ function handle_type_annotation(node, state) {
|
|
|
605
601
|
handle_type_annotation(node.indexType, state);
|
|
606
602
|
state.commands.push(']');
|
|
607
603
|
break;
|
|
604
|
+
case 'TSImportType':
|
|
605
|
+
state.commands.push('import(');
|
|
606
|
+
handle(node.argument, state);
|
|
607
|
+
state.commands.push(')');
|
|
608
|
+
|
|
609
|
+
if (node.qualifier) {
|
|
610
|
+
state.commands.push('.');
|
|
611
|
+
handle(node.qualifier, state);
|
|
612
|
+
}
|
|
613
|
+
break;
|
|
608
614
|
default:
|
|
609
615
|
throw new Error(`Not implemented type annotation ${node.type}`);
|
|
610
616
|
}
|
|
@@ -705,8 +711,7 @@ const shared = {
|
|
|
705
711
|
state.commands.push('?.');
|
|
706
712
|
}
|
|
707
713
|
|
|
708
|
-
|
|
709
|
-
if (node.typeParameters) handle_type_annotation(node.typeParameters, state);
|
|
714
|
+
if (node.typeArguments) handle_type_annotation(node.typeArguments, state);
|
|
710
715
|
|
|
711
716
|
const open = create_sequence();
|
|
712
717
|
const join = create_sequence();
|
|
@@ -842,7 +847,7 @@ const shared = {
|
|
|
842
847
|
state.commands.push('...');
|
|
843
848
|
handle(node.argument, state);
|
|
844
849
|
|
|
845
|
-
// @ts-expect-error `acorn-typescript` and `@typescript-
|
|
850
|
+
// @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
|
|
846
851
|
if (node.typeAnnotation) handle_type_annotation(node.typeAnnotation, state);
|
|
847
852
|
}
|
|
848
853
|
};
|
|
@@ -1044,7 +1049,8 @@ const handlers = {
|
|
|
1044
1049
|
if (
|
|
1045
1050
|
node.expression.type === 'ObjectExpression' ||
|
|
1046
1051
|
(node.expression.type === 'AssignmentExpression' &&
|
|
1047
|
-
node.expression.left.type === 'ObjectPattern')
|
|
1052
|
+
node.expression.left.type === 'ObjectPattern') ||
|
|
1053
|
+
node.expression.type === 'FunctionExpression'
|
|
1048
1054
|
) {
|
|
1049
1055
|
// is an AssignmentExpression to an ObjectPattern
|
|
1050
1056
|
state.commands.push('(');
|
|
@@ -1508,7 +1514,7 @@ const handlers = {
|
|
|
1508
1514
|
|
|
1509
1515
|
TSModuleBlock(node, state) {
|
|
1510
1516
|
state.commands.push(' {', indent, newline);
|
|
1511
|
-
|
|
1517
|
+
handle_body(node.body, state);
|
|
1512
1518
|
state.commands.push(dedent, newline, '}');
|
|
1513
1519
|
},
|
|
1514
1520
|
|
|
@@ -1528,7 +1534,7 @@ const handlers = {
|
|
|
1528
1534
|
},
|
|
1529
1535
|
|
|
1530
1536
|
TSInterfaceBody(node, state) {
|
|
1531
|
-
sequence(node.body, state,
|
|
1537
|
+
sequence(node.body, state, true, handle_type_annotation, ';');
|
|
1532
1538
|
},
|
|
1533
1539
|
|
|
1534
1540
|
TSInterfaceDeclaration(node, state) {
|