Skip to content

Commit 47bfaec

Browse files
committed
Added source location specification in each syntax type
1 parent 71c8b6b commit 47bfaec

File tree

7 files changed

+98
-7
lines changed

7 files changed

+98
-7
lines changed

rocket-chatter-ingestion-server/src/process/prepare/processor/syntax/classes.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ export namespace Classes {
1111
n.id?.name.toString() ?? "",
1212
"Class",
1313
n.body.body.map((e) => print(e).code).join("\n"),
14-
""
14+
"",
15+
{
16+
start: {
17+
line: n.loc?.start.line ?? 0,
18+
column: n.loc?.start.column ?? 0,
19+
index: (n as any).start ?? 0,
20+
},
21+
end: {
22+
line: n.loc?.end.line ?? 0,
23+
column: n.loc?.end.column ?? 0,
24+
index: (n as any).end ?? 0,
25+
},
26+
}
1527
)
1628

1729
// Check for type parameters

rocket-chatter-ingestion-server/src/process/prepare/processor/syntax/enums.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ import { Functions } from "./functions"
55

66
export namespace Enums {
77
export function Handle(n: namedTypes.EnumDeclaration) {
8-
const node = new TreeNode(n.id?.name.toString() ?? "", "Enum", "", "")
8+
const node = new TreeNode(n.id?.name.toString() ?? "", "Enum", "", "", {
9+
start: {
10+
line: n.loc?.start.line ?? 0,
11+
column: n.loc?.start.column ?? 0,
12+
index: (n as any).start ?? 0,
13+
},
14+
end: {
15+
line: n.loc?.end.line ?? 0,
16+
column: n.loc?.end.column ?? 0,
17+
index: (n as any).end ?? 0,
18+
},
19+
})
920

1021
// Check for external references while initializing the enum members
1122
for (const m of (n as any).members as namedTypes.TSEnumMember[]) {

rocket-chatter-ingestion-server/src/process/prepare/processor/syntax/functions.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ export namespace Functions {
1111
n.id?.name.toString() ?? "",
1212
"Function",
1313
n.body.body.map((e) => print(e).code).join("\n"),
14-
""
14+
"",
15+
{
16+
start: {
17+
line: n.loc?.start.line ?? 0,
18+
column: n.loc?.start.column ?? 0,
19+
index: (n as any).start ?? 0,
20+
},
21+
end: {
22+
line: n.loc?.end.line ?? 0,
23+
column: n.loc?.end.column ?? 0,
24+
index: (n as any).end ?? 0,
25+
},
26+
}
1527
)
1628

1729
// Check for type parameters

rocket-chatter-ingestion-server/src/process/prepare/processor/syntax/interface.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@ export namespace Interface {
1010
n.id?.name.toString() ?? "",
1111
"Interface",
1212
(n.body as any).body.map((e: any) => print(e).code).join("\n"),
13-
""
13+
"",
14+
{
15+
start: {
16+
line: n.loc?.start.line ?? 0,
17+
column: n.loc?.start.column ?? 0,
18+
index: (n as any).start ?? 0,
19+
},
20+
end: {
21+
line: n.loc?.end.line ?? 0,
22+
column: n.loc?.end.column ?? 0,
23+
index: (n as any).end ?? 0,
24+
},
25+
}
1426
)
1527

1628
// Check for type parameters

rocket-chatter-ingestion-server/src/process/prepare/processor/syntax/namespaces.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ export namespace Namespaces {
1111
(n.id as any)?.name.toString() ?? "",
1212
"Namespace",
1313
"",
14-
""
14+
"",
15+
{
16+
start: {
17+
line: n.loc?.start.line ?? 0,
18+
column: n.loc?.start.column ?? 0,
19+
index: (n as any).start ?? 0,
20+
},
21+
end: {
22+
line: n.loc?.end.line ?? 0,
23+
column: n.loc?.end.column ?? 0,
24+
index: (n as any).end ?? 0,
25+
},
26+
}
1527
)
1628

1729
const body = ((n as any).declaration?.body?.body ??

rocket-chatter-ingestion-server/src/process/prepare/processor/syntax/typeAlias.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
import { namedTypes } from "ast-types"
2+
import { writeFileSync } from "fs"
23
import { TreeNode } from "../core/treeNode"
34
import { TypeAnnotation } from "../core/typeAnnotation"
45

56
export namespace TypeAlias {
67
export function Handle(n: namedTypes.TSTypeAliasDeclaration) {
7-
const node = new TreeNode(n.id?.name.toString() ?? "", "TypeAlias", "", "")
8+
const node = new TreeNode(
9+
n.id?.name.toString() ?? "",
10+
"TypeAlias",
11+
"",
12+
"",
13+
{
14+
start: {
15+
line: n.loc?.start.line ?? 0,
16+
column: n.loc?.start.column ?? 0,
17+
index: (n as any).start ?? 0,
18+
},
19+
end: {
20+
line: n.loc?.end.line ?? 0,
21+
column: n.loc?.end.column ?? 0,
22+
index: (n as any).end ?? 0,
23+
},
24+
}
25+
)
26+
27+
// extract body of the type alias
28+
writeFileSync("test.json", JSON.stringify(n, null, 2))
829

930
// Check for type parameters
1031
const typeParameters: string[] = []

rocket-chatter-ingestion-server/src/process/prepare/processor/syntax/variableDeclarations.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@ export namespace VariableDeclarations {
1010
// For variable declarations
1111
for (const d of n.declarations) {
1212
if (namedTypes.VariableDeclarator.check(d)) {
13-
const node = new TreeNode((d.id as any).name, "variable", "", "")
13+
const node = new TreeNode((d.id as any).name, "variable", "", "", {
14+
start: {
15+
line: n.loc?.start.line ?? 0,
16+
column: n.loc?.start.column ?? 0,
17+
index: (n as any).start ?? 0,
18+
},
19+
end: {
20+
line: n.loc?.end.line ?? 0,
21+
column: n.loc?.end.column ?? 0,
22+
index: (n as any).end ?? 0,
23+
},
24+
})
1425

1526
// For variables declared using other variables
1627
if (namedTypes.Identifier.check(d.init)) {

0 commit comments

Comments
 (0)