@openrewrite/rewrite 8.62.0 → 8.62.2

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 (97) hide show
  1. package/dist/java/rpc.d.ts +3 -3
  2. package/dist/java/rpc.d.ts.map +1 -1
  3. package/dist/java/rpc.js +6 -6
  4. package/dist/java/rpc.js.map +1 -1
  5. package/dist/java/tree.d.ts +31 -33
  6. package/dist/java/tree.d.ts.map +1 -1
  7. package/dist/java/tree.js +125 -7
  8. package/dist/java/tree.js.map +1 -1
  9. package/dist/java/type.d.ts +70 -57
  10. package/dist/java/type.d.ts.map +1 -1
  11. package/dist/java/type.js +454 -25
  12. package/dist/java/type.js.map +1 -1
  13. package/dist/java/visitor.d.ts +4 -4
  14. package/dist/java/visitor.d.ts.map +1 -1
  15. package/dist/java/visitor.js +34 -28
  16. package/dist/java/visitor.js.map +1 -1
  17. package/dist/javascript/assertions.d.ts +3 -0
  18. package/dist/javascript/assertions.d.ts.map +1 -1
  19. package/dist/javascript/assertions.js +78 -1
  20. package/dist/javascript/assertions.js.map +1 -1
  21. package/dist/javascript/format.js +4 -4
  22. package/dist/javascript/format.js.map +1 -1
  23. package/dist/javascript/parser.d.ts +1 -1
  24. package/dist/javascript/parser.d.ts.map +1 -1
  25. package/dist/javascript/parser.js +38 -11
  26. package/dist/javascript/parser.js.map +1 -1
  27. package/dist/javascript/rpc.js +1 -4
  28. package/dist/javascript/rpc.js.map +1 -1
  29. package/dist/javascript/tree.d.ts +33 -35
  30. package/dist/javascript/tree.d.ts.map +1 -1
  31. package/dist/javascript/tree.js +70 -17
  32. package/dist/javascript/tree.js.map +1 -1
  33. package/dist/javascript/type-mapping.d.ts +44 -8
  34. package/dist/javascript/type-mapping.d.ts.map +1 -1
  35. package/dist/javascript/type-mapping.js +571 -101
  36. package/dist/javascript/type-mapping.js.map +1 -1
  37. package/dist/javascript/visitor.d.ts +2 -2
  38. package/dist/javascript/visitor.d.ts.map +1 -1
  39. package/dist/javascript/visitor.js.map +1 -1
  40. package/dist/json/tree.d.ts +0 -2
  41. package/dist/json/tree.d.ts.map +1 -1
  42. package/dist/json/tree.js +12 -2
  43. package/dist/json/tree.js.map +1 -1
  44. package/dist/reference.js +1 -1
  45. package/dist/reference.js.map +1 -1
  46. package/dist/rpc/chrome-profiler.d.ts +25 -0
  47. package/dist/rpc/chrome-profiler.d.ts.map +1 -0
  48. package/dist/rpc/chrome-profiler.js +405 -0
  49. package/dist/rpc/chrome-profiler.js.map +1 -0
  50. package/dist/rpc/queue.d.ts +0 -3
  51. package/dist/rpc/queue.d.ts.map +1 -1
  52. package/dist/rpc/queue.js +6 -6
  53. package/dist/rpc/queue.js.map +1 -1
  54. package/dist/rpc/request/parse.d.ts.map +1 -1
  55. package/dist/rpc/request/parse.js.map +1 -1
  56. package/dist/rpc/rewrite-rpc.d.ts +1 -0
  57. package/dist/rpc/rewrite-rpc.d.ts.map +1 -1
  58. package/dist/rpc/rewrite-rpc.js +1 -1
  59. package/dist/rpc/rewrite-rpc.js.map +1 -1
  60. package/dist/rpc/server.d.ts.map +1 -1
  61. package/dist/rpc/server.js +26 -1
  62. package/dist/rpc/server.js.map +1 -1
  63. package/dist/test/rewrite-test.d.ts +1 -1
  64. package/dist/test/rewrite-test.d.ts.map +1 -1
  65. package/dist/test/rewrite-test.js +18 -2
  66. package/dist/test/rewrite-test.js.map +1 -1
  67. package/dist/text/tree.d.ts +0 -2
  68. package/dist/text/tree.d.ts.map +1 -1
  69. package/dist/text/tree.js +4 -17
  70. package/dist/text/tree.js.map +1 -1
  71. package/dist/tree.d.ts +1 -0
  72. package/dist/tree.d.ts.map +1 -1
  73. package/dist/tree.js +14 -0
  74. package/dist/tree.js.map +1 -1
  75. package/dist/version.txt +1 -1
  76. package/package.json +3 -3
  77. package/src/java/rpc.ts +18 -15
  78. package/src/java/tree.ts +68 -38
  79. package/src/java/type.ts +475 -74
  80. package/src/java/visitor.ts +45 -39
  81. package/src/javascript/assertions.ts +52 -1
  82. package/src/javascript/format.ts +4 -4
  83. package/src/javascript/parser.ts +51 -18
  84. package/src/javascript/rpc.ts +8 -10
  85. package/src/javascript/tree.ts +34 -35
  86. package/src/javascript/type-mapping.ts +582 -47
  87. package/src/javascript/visitor.ts +5 -5
  88. package/src/json/tree.ts +1 -2
  89. package/src/reference.ts +1 -1
  90. package/src/rpc/chrome-profiler.ts +373 -0
  91. package/src/rpc/queue.ts +8 -12
  92. package/src/rpc/request/parse.ts +1 -1
  93. package/src/rpc/rewrite-rpc.ts +3 -2
  94. package/src/rpc/server.ts +30 -1
  95. package/src/test/rewrite-test.ts +19 -3
  96. package/src/text/tree.ts +0 -1
  97. package/src/tree.ts +15 -0
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import {isTree, SourceFile} from "../tree";
16
+ import {Cursor, isTree, SourceFile} from "../tree";
17
17
  import {mapAsync} from "../util";
18
18
  import {produceAsync, TreeVisitor, ValidImmerRecipeReturnType} from "../visitor";
19
19
  import {
@@ -25,7 +25,7 @@ import {
25
25
  Statement, TypedTree, TypeTree
26
26
  } from "./tree";
27
27
  import {createDraft, Draft, finishDraft} from "immer";
28
- import {JavaType} from "./type";
28
+ import {Type} from "./type";
29
29
 
30
30
  export class JavaVisitor<P> extends TreeVisitor<J, P> {
31
31
  // protected javadocVisitor: any | null = null;
@@ -50,7 +50,7 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
50
50
  }
51
51
 
52
52
  // noinspection JSUnusedLocalSymbols
53
- protected async visitType(javaType: JavaType | undefined, p: P): Promise<JavaType | undefined> {
53
+ protected async visitType(javaType: Type | undefined, p: P): Promise<Type | undefined> {
54
54
  return javaType;
55
55
  }
56
56
 
@@ -241,7 +241,7 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
241
241
  draft.implements = await this.visitOptionalContainer(classDecl.implements, p);
242
242
  draft.permitting = await this.visitOptionalContainer(classDecl.permitting, p);
243
243
  draft.body = await this.visitDefined(classDecl.body, p) as J.Block;
244
- draft.type = await this.visitType(classDecl.type, p) as JavaType.Class | undefined;
244
+ draft.type = await this.visitType(classDecl.type, p) as Type.Class | undefined;
245
245
  });
246
246
  }
247
247
 
@@ -426,7 +426,7 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
426
426
  return this.produceJava<J.Identifier>(ident, p, async draft => {
427
427
  draft.annotations = await mapAsync(ident.annotations, a => this.visitDefined<J.Annotation>(a, p));
428
428
  draft.type = await this.visitType(ident.type, p);
429
- draft.fieldType = await this.visitType(ident.fieldType, p) as JavaType.Variable | undefined;
429
+ draft.fieldType = await this.visitType(ident.fieldType, p) as Type.Variable | undefined;
430
430
  });
431
431
  }
432
432
 
@@ -540,7 +540,7 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
540
540
  literal = expression as J.Literal;
541
541
 
542
542
  return this.produceJava<J.Literal>(literal, p, async draft => {
543
- draft.type = await this.visitType(literal.type, p) as JavaType.Primitive | undefined;
543
+ draft.type = await this.visitType(literal.type, p) as Type.Primitive | undefined;
544
544
  });
545
545
  }
546
546
 
@@ -556,59 +556,59 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
556
556
  draft.typeParameters = await this.visitOptionalContainer(memberRef.typeParameters, p);
557
557
  draft.reference = await this.visitLeftPadded(memberRef.reference, p);
558
558
  draft.type = await this.visitType(memberRef.type, p);
559
- draft.methodType = await this.visitType(memberRef.methodType, p) as JavaType.Method | undefined;
560
- draft.variableType = await this.visitType(memberRef.variableType, p) as JavaType.Variable | undefined;
559
+ draft.methodType = await this.visitType(memberRef.methodType, p) as Type.Method | undefined;
560
+ draft.variableType = await this.visitType(memberRef.variableType, p) as Type.Variable | undefined;
561
561
  });
562
562
  }
563
563
 
564
- protected async visitMethodDeclaration(methodDecl: J.MethodDeclaration, p: P): Promise<J | undefined> {
565
- const statement = await this.visitStatement(methodDecl, p);
564
+ protected async visitMethodDeclaration(method: J.MethodDeclaration, p: P): Promise<J | undefined> {
565
+ const statement = await this.visitStatement(method, p);
566
566
  if (!statement?.kind || statement.kind !== J.Kind.MethodDeclaration) {
567
567
  return statement;
568
568
  }
569
- methodDecl = statement as J.MethodDeclaration;
569
+ method = statement as J.MethodDeclaration;
570
570
 
571
- return this.produceJava<J.MethodDeclaration>(methodDecl, p, async draft => {
572
- draft.leadingAnnotations = await mapAsync(methodDecl.leadingAnnotations, a => this.visitDefined<J.Annotation>(a, p));
573
- draft.modifiers = await mapAsync(methodDecl.modifiers, m => this.visitDefined<J.Modifier>(m, p));
571
+ return this.produceJava<J.MethodDeclaration>(method, p, async draft => {
572
+ draft.leadingAnnotations = await mapAsync(method.leadingAnnotations, a => this.visitDefined<J.Annotation>(a, p));
573
+ draft.modifiers = await mapAsync(method.modifiers, m => this.visitDefined<J.Modifier>(m, p));
574
574
 
575
- if (methodDecl.typeParameters) {
576
- draft.typeParameters = await this.visitDefined(methodDecl.typeParameters, p) as J.TypeParameters;
575
+ if (method.typeParameters) {
576
+ draft.typeParameters = await this.visitDefined(method.typeParameters, p) as J.TypeParameters;
577
577
  }
578
578
 
579
- if (methodDecl.returnTypeExpression) {
580
- draft.returnTypeExpression = await this.visitDefined(methodDecl.returnTypeExpression, p) as TypedTree;
579
+ if (method.returnTypeExpression) {
580
+ draft.returnTypeExpression = await this.visitDefined(method.returnTypeExpression, p) as TypedTree;
581
581
  }
582
582
 
583
- draft.nameAnnotations = await mapAsync(methodDecl.nameAnnotations, a => this.visitDefined<J.Annotation>(a, p));
584
- draft.name = await this.visitDefined(methodDecl.name, p);
585
- draft.parameters = await this.visitContainer(methodDecl.parameters, p);
586
- draft.throws = methodDecl.throws && await this.visitContainer(methodDecl.throws, p);
587
- draft.body = methodDecl.body && await this.visitDefined(methodDecl.body, p) as J.Block;
588
- draft.defaultValue = await this.visitOptionalLeftPadded(methodDecl.defaultValue, p);
589
- draft.methodType = await this.visitType(methodDecl.methodType, p) as JavaType.Method | undefined;
583
+ draft.nameAnnotations = await mapAsync(method.nameAnnotations, a => this.visitDefined<J.Annotation>(a, p));
584
+ draft.name = await this.visitDefined(method.name, p);
585
+ draft.parameters = await this.visitContainer(method.parameters, p);
586
+ draft.throws = method.throws && await this.visitContainer(method.throws, p);
587
+ draft.body = method.body && await this.visitDefined(method.body, p) as J.Block;
588
+ draft.defaultValue = await this.visitOptionalLeftPadded(method.defaultValue, p);
589
+ draft.methodType = await this.visitType(method.methodType, p) as Type.Method | undefined;
590
590
  });
591
591
  }
592
592
 
593
- protected async visitMethodInvocation(methodInv: J.MethodInvocation, p: P): Promise<J | undefined> {
594
- const expression = await this.visitExpression(methodInv, p);
593
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: P): Promise<J | undefined> {
594
+ const expression = await this.visitExpression(method, p);
595
595
  if (!expression?.kind || expression.kind !== J.Kind.MethodInvocation) {
596
596
  return expression;
597
597
  }
598
- methodInv = expression as J.MethodInvocation;
598
+ method = expression as J.MethodInvocation;
599
599
 
600
- const statement = await this.visitStatement(methodInv, p);
600
+ const statement = await this.visitStatement(method, p);
601
601
  if (!statement?.kind || statement.kind !== J.Kind.MethodInvocation) {
602
602
  return statement;
603
603
  }
604
- methodInv = statement as J.MethodInvocation;
604
+ method = statement as J.MethodInvocation;
605
605
 
606
- return this.produceJava<J.MethodInvocation>(methodInv, p, async draft => {
607
- draft.select = await this.visitOptionalRightPadded(methodInv.select, p);
608
- draft.typeParameters = await this.visitOptionalContainer(methodInv.typeParameters, p);
609
- draft.name = await this.visitDefined(methodInv.name, p) as J.Identifier;
610
- draft.arguments = await this.visitContainer(methodInv.arguments, p);
611
- draft.methodType = await this.visitType(methodInv.methodType, p) as JavaType.Method | undefined;
606
+ return this.produceJava<J.MethodInvocation>(method, p, async draft => {
607
+ draft.select = await this.visitOptionalRightPadded(method.select, p);
608
+ draft.typeParameters = await this.visitOptionalContainer(method.typeParameters, p);
609
+ draft.name = await this.visitDefined(method.name, p) as J.Identifier;
610
+ draft.arguments = await this.visitContainer(method.arguments, p);
611
+ draft.methodType = await this.visitType(method.methodType, p) as Type.Method | undefined;
612
612
  });
613
613
  }
614
614
 
@@ -668,7 +668,7 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
668
668
  draft.body = await this.visitDefined(newClass.body, p) as J.Block;
669
669
  }
670
670
 
671
- draft.constructorType = await this.visitType(newClass.constructorType, p) as JavaType.Method | undefined;
671
+ draft.constructorType = await this.visitType(newClass.constructorType, p) as Type.Method | undefined;
672
672
  });
673
673
  }
674
674
 
@@ -729,7 +729,7 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
729
729
  primitive = expression as J.Primitive;
730
730
 
731
731
  return this.produceJava<J.Primitive>(primitive, p, async draft => {
732
- draft.type = await this.visitType(primitive.type, p) as JavaType.Primitive;
732
+ draft.type = await this.visitType(primitive.type, p) as Type.Primitive;
733
733
  });
734
734
  }
735
735
 
@@ -947,7 +947,7 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
947
947
  draft.name = await this.visitDefined(variable.name, p) as J.Identifier;
948
948
  draft.dimensionsAfterName = await mapAsync(variable.dimensionsAfterName, dim => this.visitLeftPadded(dim, p));
949
949
  draft.initializer = await this.visitOptionalLeftPadded(variable.initializer, p);
950
- draft.variableType = await this.visitType(variable.variableType, p) as JavaType.Variable | undefined;
950
+ draft.variableType = await this.visitType(variable.variableType, p) as Type.Variable | undefined;
951
951
  });
952
952
  }
953
953
 
@@ -997,11 +997,13 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
997
997
 
998
998
  protected async visitRightPadded<T extends J | boolean>(right: J.RightPadded<T>, p: P): Promise<J.RightPadded<T>> {
999
999
  return produceAsync<J.RightPadded<T>>(right, async draft => {
1000
+ this.cursor = new Cursor(right, this.cursor);
1000
1001
  if (isTree(right.element)) {
1001
1002
  (draft.element as J) = await this.visitDefined(right.element, p);
1002
1003
  }
1003
1004
  draft.after = await this.visitSpace(right.after, p);
1004
1005
  draft.markers = await this.visitMarkers(right.markers, p);
1006
+ this.cursor = this.cursor.parent!;
1005
1007
  });
1006
1008
  }
1007
1009
 
@@ -1011,6 +1013,7 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
1011
1013
 
1012
1014
  protected async visitLeftPadded<T extends J | J.Space | number | string | boolean>(left: J.LeftPadded<T>, p: P): Promise<J.LeftPadded<T>> {
1013
1015
  return produceAsync<J.LeftPadded<T>>(left, async draft => {
1016
+ this.cursor = new Cursor(left, this.cursor);
1014
1017
  draft.before = await this.visitSpace(left.before, p);
1015
1018
  if (isTree(left.element)) {
1016
1019
  draft.element = await this.visitDefined(left.element, p) as Draft<T>;
@@ -1018,6 +1021,7 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
1018
1021
  draft.element = await this.visitSpace(left.element, p) as Draft<T>;
1019
1022
  }
1020
1023
  draft.markers = await this.visitMarkers(left.markers, p);
1024
+ this.cursor = this.cursor.parent!;
1021
1025
  });
1022
1026
  }
1023
1027
 
@@ -1027,9 +1031,11 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
1027
1031
 
1028
1032
  protected async visitContainer<T extends J>(container: J.Container<T>, p: P): Promise<J.Container<T>> {
1029
1033
  return produceAsync<J.Container<T>>(container, async draft => {
1034
+ this.cursor = new Cursor(container, this.cursor);
1030
1035
  draft.before = await this.visitSpace(container.before, p);
1031
1036
  (draft.elements as J.RightPadded<J>[]) = await mapAsync(container.elements, e => this.visitRightPadded(e, p));
1032
1037
  draft.markers = await this.visitMarkers(container.markers, p);
1038
+ this.cursor = this.cursor.parent!;
1033
1039
  });
1034
1040
  }
1035
1041
 
@@ -17,16 +17,67 @@ import {AfterRecipeText, dedentAfter, SourceSpec} from "../test";
17
17
  import {JavaScriptParser} from "./parser";
18
18
  import {JS} from "./tree";
19
19
  import ts from 'typescript';
20
+ import {json, Json} from "../json";
21
+ import * as fs from "fs";
22
+ import * as path from "path";
23
+ import {execSync} from "child_process";
20
24
 
21
25
  const sourceFileCache: Map<string, ts.SourceFile> = new Map();
22
26
 
27
+ export function* npm(relativeTo: string, ...sourceSpecs: SourceSpec<any>[]): Generator<SourceSpec<any>, void, unknown> {
28
+ for (const spec of sourceSpecs) {
29
+ if (spec.path === 'package.json') {
30
+ // Write package.json to disk so npm install can be run
31
+ fs.mkdirSync(relativeTo, {recursive: true});
32
+ const packageJsonPath = path.join(relativeTo, 'package.json');
33
+
34
+ // Check if package.json already exists with the same content
35
+ let needsInstall = true;
36
+ if (fs.existsSync(packageJsonPath)) {
37
+ const existingContent = fs.readFileSync(packageJsonPath, 'utf-8');
38
+ if (existingContent === spec.before) {
39
+ needsInstall = false;
40
+ }
41
+ }
42
+
43
+ if (needsInstall) {
44
+ fs.writeFileSync(packageJsonPath, spec.before!);
45
+ execSync('npm install', {
46
+ cwd: relativeTo,
47
+ stdio: 'inherit' // Show npm output for debugging
48
+ });
49
+ }
50
+ yield spec;
51
+ }
52
+ }
53
+ for (const spec of sourceSpecs) {
54
+ if (spec.path !== 'package.json') {
55
+ if (spec.kind === JS.Kind.CompilationUnit) {
56
+ yield {
57
+ ...spec,
58
+ parser: () => new JavaScriptParser({sourceFileCache, relativeTo})
59
+ }
60
+ } else {
61
+ yield spec;
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+ export function packageJson(before: string, after?: AfterRecipeText): SourceSpec<Json.Document> {
68
+ return {
69
+ ...json(before, after),
70
+ path: 'package.json'
71
+ };
72
+ }
73
+
23
74
  export function javascript(before: string | null, after?: AfterRecipeText): SourceSpec<JS.CompilationUnit> {
24
75
  return {
25
76
  kind: JS.Kind.CompilationUnit,
26
77
  before: before,
27
78
  after: dedentAfter(after),
28
79
  ext: 'js',
29
- parser: () => new JavaScriptParser({sourceFileCache})
80
+ parser: ctx => new JavaScriptParser({sourceFileCache})
30
81
  };
31
82
  }
32
83
 
@@ -524,7 +524,7 @@ export class WrappingAndBracesVisitor<P> extends JavaScriptVisitor<P> {
524
524
  public async visitStatement(statement: Statement, p: P): Promise<Statement> {
525
525
  const j = await super.visitStatement(statement, p) as Statement;
526
526
  // TODO is it needed?
527
- // const parent = this.cursor.parent?.value;
527
+ // const parent = this.cursor.parentTree()?.value;
528
528
  // if (parent?.kind === J.Kind.Block && j.kind !== J.Kind.EnumValueSet) {
529
529
  // if (!j.prefix.whitespace.includes("\n")) {
530
530
  // return produce(j, draft => {
@@ -537,7 +537,7 @@ export class WrappingAndBracesVisitor<P> extends JavaScriptVisitor<P> {
537
537
 
538
538
  protected async visitVariableDeclarations(multiVariable: J.VariableDeclarations, p: P): Promise<J.VariableDeclarations> {
539
539
  const v = await super.visitVariableDeclarations(multiVariable, p) as J.VariableDeclarations;
540
- const parent = this.cursor.parent?.value;
540
+ const parent = this.cursor.parentTree()?.value;
541
541
  if (parent?.kind === J.Kind.Block) {
542
542
  return produce(v, draft => {
543
543
  draft.leadingAnnotations = this.withNewlines(draft.leadingAnnotations);
@@ -939,8 +939,8 @@ export class BlankLinesVisitor<P> extends JavaScriptVisitor<P> {
939
939
 
940
940
  override async visitStatement(statement: Statement, p: P): Promise<Statement> {
941
941
  const ret = await super.visitStatement(statement, p) as Statement;
942
- const parent = this.cursor.parent?.value;
943
- const grandparent = this.cursor.parent?.parent?.value;
942
+ const parent = this.cursor.parentTree()?.value;
943
+ const grandparent = this.cursor.parentTree()?.parent?.value;
944
944
 
945
945
  return produce(ret, draft => {
946
946
  if (grandparent?.kind === J.Kind.ClassDeclaration && parent?.kind === J.Kind.Block) {
@@ -20,15 +20,15 @@ import {
20
20
  emptySpace,
21
21
  Expression,
22
22
  J,
23
- JavaType,
24
23
  NameTree,
25
24
  Statement,
26
25
  TextComment,
27
26
  TrailingComma,
27
+ Type,
28
28
  TypeTree,
29
29
  VariableDeclarator,
30
30
  } from '../java';
31
- import {Generator, DelegatedYield, FunctionDeclaration, JS, JSX, NonNullAssertion, Optional, Spread} from '.';
31
+ import {DelegatedYield, FunctionDeclaration, Generator, JS, JSX, NonNullAssertion, Optional, Spread} from '.';
32
32
  import {emptyMarkers, markers, Markers, MarkersKind, ParseExceptionResult} from "../markers";
33
33
  import {NamedStyles} from "../style";
34
34
  import {Parser, ParserInput, parserInputFile, parserInputRead, ParserOptions, Parsers, SourcePath} from "../parser";
@@ -76,11 +76,15 @@ export class JavaScriptParser extends Parser {
76
76
  this.compilerOptions = {
77
77
  target: ts.ScriptTarget.Latest,
78
78
  module: ts.ModuleKind.CommonJS,
79
+ moduleResolution: ts.ModuleResolutionKind.Node10,
79
80
  allowJs: true,
81
+ checkJs: true,
80
82
  esModuleInterop: true,
83
+ allowSyntheticDefaultImports: true,
81
84
  experimentalDecorators: true,
82
85
  emitDecoratorMetadata: true,
83
- jsx: ts.JsxEmit.Preserve
86
+ jsx: ts.JsxEmit.Preserve,
87
+ baseUrl: relativeTo || process.cwd()
84
88
  };
85
89
  this.styles = styles;
86
90
  this.sourceFileCache = sourceFileCache;
@@ -107,6 +111,12 @@ export class JavaScriptParser extends Parser {
107
111
  // Create a new CompilerHost within parseInputs
108
112
  const host = ts.createCompilerHost(this.compilerOptions);
109
113
 
114
+ // Set the current directory for module resolution
115
+ if (this.relativeTo) {
116
+ const originalGetCurrentDirectory = host.getCurrentDirectory;
117
+ host.getCurrentDirectory = () => this.relativeTo || originalGetCurrentDirectory();
118
+ }
119
+
110
120
  // Override getSourceFile
111
121
  host.getSourceFile = (fileName, languageVersion, onError) => {
112
122
  // Check if the SourceFile is in the cache
@@ -159,6 +169,7 @@ export class JavaScriptParser extends Parser {
159
169
 
160
170
  const typeChecker = program.getTypeChecker();
161
171
 
172
+
162
173
  for (const input of inputFiles.values()) {
163
174
  const filePath = parserInputFile(input);
164
175
  const sourceFile = program.getSourceFile(filePath);
@@ -181,7 +192,7 @@ export class JavaScriptParser extends Parser {
181
192
 
182
193
  try {
183
194
  yield produce(
184
- new JavaScriptParserVisitor(sourceFile, this.relativePath(input), typeChecker)
195
+ new JavaScriptParserVisitor(sourceFile, this.relativePath(input), typeChecker, this.relativeTo || process.cwd())
185
196
  .visit(sourceFile) as SourceFile,
186
197
  draft => {
187
198
  if (this.styles) {
@@ -211,8 +222,9 @@ export class JavaScriptParserVisitor {
211
222
  constructor(
212
223
  private readonly sourceFile: ts.SourceFile,
213
224
  private readonly sourcePath: string,
214
- typeChecker: ts.TypeChecker) {
215
- this.typeMapping = new JavaScriptTypeMapping(typeChecker);
225
+ typeChecker: ts.TypeChecker,
226
+ projectRoot?: string) {
227
+ this.typeMapping = new JavaScriptTypeMapping(typeChecker, projectRoot);
216
228
  }
217
229
 
218
230
  visit = (node: ts.Node): any => {
@@ -569,7 +581,22 @@ export class JavaScriptParserVisitor {
569
581
  }
570
582
 
571
583
  visitNumericLiteral(node: ts.NumericLiteral): J.Literal {
572
- return this.mapLiteral(node, node.text); // FIXME value not in AST
584
+ // Parse the numeric value from the text
585
+ const text = node.text;
586
+ let value: number | bigint;
587
+
588
+ // Check if it's a BigInt literal (ends with 'n')
589
+ if (text.endsWith('n')) {
590
+ value = BigInt(text.slice(0, -1));
591
+ } else if (text.includes('.') || text.toLowerCase().includes('e')) {
592
+ // Floating point number
593
+ value = parseFloat(text);
594
+ } else {
595
+ // Integer - but JavaScript doesn't distinguish, so use number
596
+ value = parseInt(text, text.startsWith('0x') ? 16 : text.startsWith('0o') ? 8 : text.startsWith('0b') ? 2 : 10);
597
+ }
598
+
599
+ return this.mapLiteral(node, value);
573
600
  }
574
601
 
575
602
  visitTrueKeyword(node: ts.TrueLiteral): J.Literal {
@@ -653,11 +680,14 @@ export class JavaScriptParserVisitor {
653
680
  }
654
681
 
655
682
  visitBigIntLiteral(node: ts.BigIntLiteral): J.Literal {
656
- return this.mapLiteral(node, node.text); // FIXME value not in AST
683
+ // Parse BigInt value, removing the 'n' suffix
684
+ const text = node.text;
685
+ const value = BigInt(text.slice(0, -1));
686
+ return this.mapLiteral(node, value);
657
687
  }
658
688
 
659
689
  visitStringLiteral(node: ts.StringLiteral): J.Literal {
660
- return this.mapLiteral(node, node.text); // FIXME value not in AST
690
+ return this.mapLiteral(node, node.text);
661
691
  }
662
692
 
663
693
  visitRegularExpressionLiteral(node: ts.RegularExpressionLiteral): J.Literal {
@@ -693,8 +723,8 @@ export class JavaScriptParserVisitor {
693
723
  markers: emptyMarkers,
694
724
  annotations: [], // FIXME decorators
695
725
  simpleName: name,
696
- type: type?.kind === JavaType.Kind.Variable ? (type as JavaType.Variable).type : type,
697
- fieldType: type?.kind === JavaType.Kind.Variable ? type as JavaType.Variable : undefined
726
+ type: type?.kind === Type.Kind.Variable ? (type as Type.Variable).type : type,
727
+ fieldType: type?.kind === Type.Kind.Variable ? type as Type.Variable : undefined
698
728
  };
699
729
  }
700
730
 
@@ -1838,7 +1868,10 @@ export class JavaScriptParserVisitor {
1838
1868
  markers: emptyMarkers,
1839
1869
  select,
1840
1870
  typeParameters: typeArguments,
1841
- name,
1871
+ name: {
1872
+ ...name,
1873
+ type: undefined
1874
+ },
1842
1875
  arguments: this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)),
1843
1876
  methodType: this.mapMethodType(node)
1844
1877
  }
@@ -3155,7 +3188,7 @@ export class JavaScriptParserVisitor {
3155
3188
  emptySpace)],
3156
3189
  end: this.prefix(node.getLastToken()!)
3157
3190
  },
3158
- type: this.mapType(node) as JavaType.Class
3191
+ type: this.mapType(node) as Type.Class
3159
3192
  };
3160
3193
  }
3161
3194
 
@@ -4060,19 +4093,19 @@ export class JavaScriptParserVisitor {
4060
4093
  return this.prefix(getNextSibling(node)!, consume);
4061
4094
  }
4062
4095
 
4063
- private mapType(node: ts.Node): JavaType | undefined {
4064
- return Object.freeze(this.typeMapping.type(node));
4096
+ private mapType(node: ts.Node): Type | undefined {
4097
+ return this.typeMapping.type(node);
4065
4098
  }
4066
4099
 
4067
- private mapPrimitiveType(node: ts.Node): JavaType.Primitive {
4100
+ private mapPrimitiveType(node: ts.Node): Type.Primitive {
4068
4101
  return this.typeMapping.primitiveType(node);
4069
4102
  }
4070
4103
 
4071
- private mapVariableType(node: ts.NamedDeclaration): JavaType.Variable | undefined {
4104
+ private mapVariableType(node: ts.NamedDeclaration): Type.Variable | undefined {
4072
4105
  return this.typeMapping.variableType(node);
4073
4106
  }
4074
4107
 
4075
- private mapMethodType(node: ts.Node): JavaType.Method | undefined {
4108
+ private mapMethodType(node: ts.Node): Type.Method | undefined {
4076
4109
  return this.typeMapping.methodType(node);
4077
4110
  }
4078
4111
 
@@ -16,10 +16,10 @@
16
16
  import {JavaScriptVisitor} from "./visitor";
17
17
  import {asRef, RpcCodec, RpcCodecs, RpcReceiveQueue, RpcSendQueue} from "../rpc";
18
18
  import {isJavaScript, JS, JSX} from "./tree";
19
- import {Expression, J, JavaType, Statement, TypedTree, TypeTree} from "../java";
19
+ import {Expression, J, Statement, Type, TypedTree, TypeTree} from "../java";
20
20
  import {createDraft, finishDraft} from "immer";
21
21
  import {JavaReceiver, JavaSender} from "../java/rpc";
22
- import {Cursor, Tree, TreeKind} from "../tree";
22
+ import {Cursor, Tree} from "../tree";
23
23
  import ComputedPropertyName = JS.ComputedPropertyName;
24
24
 
25
25
  class JavaScriptSender extends JavaScriptVisitor<RpcSendQueue> {
@@ -522,7 +522,7 @@ class JavaScriptSender extends JavaScriptVisitor<RpcSendQueue> {
522
522
  return this.javaSender.visitSpace(space, q);
523
523
  }
524
524
 
525
- override async visitType(javaType: JavaType | undefined, q: RpcSendQueue): Promise<JavaType | undefined> {
525
+ override async visitType(javaType: Type | undefined, q: RpcSendQueue): Promise<Type | undefined> {
526
526
  return this.javaSender.visitType(javaType, q);
527
527
  }
528
528
  }
@@ -643,7 +643,7 @@ class JavaScriptReceiver extends JavaScriptVisitor<RpcReceiveQueue> {
643
643
  draft.function = await q.receive(functionCall.function, select => this.visitRightPadded(select, q));
644
644
  draft.typeParameters = await q.receive(functionCall.typeParameters, typeParams => this.visitContainer(typeParams, q));
645
645
  draft.arguments = await q.receive(functionCall.arguments, args => this.visitContainer(args, q));
646
- draft.functionType = await q.receive(functionCall.functionType, type => this.visitType(type, q) as unknown as JavaType.Method);
646
+ draft.functionType = await q.receive(functionCall.functionType, type => this.visitType(type, q) as unknown as Type.Method);
647
647
 
648
648
  return finishDraft(draft);
649
649
  }
@@ -1020,7 +1020,7 @@ class JavaScriptReceiver extends JavaScriptVisitor<RpcReceiveQueue> {
1020
1020
  draft.name = await q.receive(draft.name, el => this.visitDefined<ComputedPropertyName>(el, q));
1021
1021
  draft.parameters = await q.receive(draft.parameters, el => this.visitContainer(el, q));
1022
1022
  draft.body = await q.receive(draft.body, el => this.visitDefined<J.Block>(el, q));
1023
- draft.methodType = await q.receive(draft.methodType, el => this.visitType(el, q) as any as JavaType.Method);
1023
+ draft.methodType = await q.receive(draft.methodType, el => this.visitType(el, q) as any as Type.Method);
1024
1024
  return finishDraft(draft);
1025
1025
  }
1026
1026
 
@@ -1066,7 +1066,7 @@ class JavaScriptReceiver extends JavaScriptVisitor<RpcReceiveQueue> {
1066
1066
  draft.propertyName = await q.receive(draft.propertyName, el => this.visitRightPadded(el, q));
1067
1067
  draft.name = await q.receive(draft.name, el => this.visitDefined<TypedTree>(el, q));
1068
1068
  draft.initializer = await q.receive(draft.initializer, el => this.visitLeftPadded(el, q));
1069
- draft.variableType = await q.receive(draft.variableType, el => this.visitType(el, q) as any as JavaType.Variable);
1069
+ draft.variableType = await q.receive(draft.variableType, el => this.visitType(el, q) as any as Type.Variable);
1070
1070
  return finishDraft(draft);
1071
1071
  }
1072
1072
 
@@ -1118,7 +1118,7 @@ class JavaScriptReceiver extends JavaScriptVisitor<RpcReceiveQueue> {
1118
1118
  return this.javaReceiverDelegate.visitSpace(space, q);
1119
1119
  }
1120
1120
 
1121
- override async visitType(javaType: JavaType | undefined, q: RpcReceiveQueue): Promise<JavaType | undefined> {
1121
+ override async visitType(javaType: Type | undefined, q: RpcReceiveQueue): Promise<Type | undefined> {
1122
1122
  return this.javaReceiverDelegate.visitType(javaType, q);
1123
1123
  }
1124
1124
  }
@@ -1151,7 +1151,5 @@ const javaScriptCodec: RpcCodec<JS> = {
1151
1151
 
1152
1152
  // Register codec for all JavaScript AST node types
1153
1153
  Object.values(JS.Kind).forEach(kind => {
1154
- if (!Object.values(TreeKind).includes(kind as any)) {
1155
- RpcCodecs.registerCodec(kind, javaScriptCodec);
1156
- }
1154
+ RpcCodecs.registerCodec(kind, javaScriptCodec);
1157
1155
  });