esrap 1.4.5 → 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 +16 -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':
|
|
@@ -715,8 +711,7 @@ const shared = {
|
|
|
715
711
|
state.commands.push('?.');
|
|
716
712
|
}
|
|
717
713
|
|
|
718
|
-
|
|
719
|
-
if (node.typeParameters) handle_type_annotation(node.typeParameters, state);
|
|
714
|
+
if (node.typeArguments) handle_type_annotation(node.typeArguments, state);
|
|
720
715
|
|
|
721
716
|
const open = create_sequence();
|
|
722
717
|
const join = create_sequence();
|
|
@@ -852,7 +847,7 @@ const shared = {
|
|
|
852
847
|
state.commands.push('...');
|
|
853
848
|
handle(node.argument, state);
|
|
854
849
|
|
|
855
|
-
// @ts-expect-error `acorn-typescript` and `@typescript-
|
|
850
|
+
// @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
|
|
856
851
|
if (node.typeAnnotation) handle_type_annotation(node.typeAnnotation, state);
|
|
857
852
|
}
|
|
858
853
|
};
|
|
@@ -1054,7 +1049,8 @@ const handlers = {
|
|
|
1054
1049
|
if (
|
|
1055
1050
|
node.expression.type === 'ObjectExpression' ||
|
|
1056
1051
|
(node.expression.type === 'AssignmentExpression' &&
|
|
1057
|
-
node.expression.left.type === 'ObjectPattern')
|
|
1052
|
+
node.expression.left.type === 'ObjectPattern') ||
|
|
1053
|
+
node.expression.type === 'FunctionExpression'
|
|
1058
1054
|
) {
|
|
1059
1055
|
// is an AssignmentExpression to an ObjectPattern
|
|
1060
1056
|
state.commands.push('(');
|
|
@@ -1518,7 +1514,7 @@ const handlers = {
|
|
|
1518
1514
|
|
|
1519
1515
|
TSModuleBlock(node, state) {
|
|
1520
1516
|
state.commands.push(' {', indent, newline);
|
|
1521
|
-
|
|
1517
|
+
handle_body(node.body, state);
|
|
1522
1518
|
state.commands.push(dedent, newline, '}');
|
|
1523
1519
|
},
|
|
1524
1520
|
|
|
@@ -1538,7 +1534,7 @@ const handlers = {
|
|
|
1538
1534
|
},
|
|
1539
1535
|
|
|
1540
1536
|
TSInterfaceBody(node, state) {
|
|
1541
|
-
sequence(node.body, state,
|
|
1537
|
+
sequence(node.body, state, true, handle_type_annotation, ';');
|
|
1542
1538
|
},
|
|
1543
1539
|
|
|
1544
1540
|
TSInterfaceDeclaration(node, state) {
|