Skip to content

Commit af73975

Browse files
committed
Fix #107
1 parent b8f1ad3 commit af73975

File tree

4 files changed

+62
-34
lines changed

4 files changed

+62
-34
lines changed

lib/Parser.fs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,8 @@ let private getAllLocalReferences (ctx: #IContext<#IOptions>) (sourceFiles: Ts.S
10851085
| _ -> ()
10861086
n.forEachChild(go sourceFile)
10871087

1088-
and goSourceFile sourceFile =
1089-
for statement in sourceFile.statements do
1090-
go sourceFile statement |> ignore
1088+
and goSourceFile (sourceFile: Ts.SourceFile) =
1089+
sourceFile.forEachChild(go sourceFile) |> ignore
10911090

10921091
for sourceFile in sourceFiles do goSourceFile sourceFile
10931092

@@ -1111,33 +1110,30 @@ let createDependencyGraph (sourceFiles: Ts.SourceFile seq) =
11111110
let specifier = (!!e : Ts.StringLiteral).text
11121111
if specifier.StartsWith(".") then
11131112
tryFindDefinitionFile sourceFile specifier
1114-
|> Option.map (fun target ->
1115-
graph <- graph |> Graph.add sourceFile.fileName target.fileName
1116-
target)
1117-
else None
1118-
else None
1119-
1120-
let rec go (sourceFile: Ts.SourceFile) (n: Ts.Node) : unit option =
1121-
match n.kind with
1122-
| Ts.SyntaxKind.ImportEqualsDeclaration ->
1123-
let n = n :?> Ts.ImportEqualsDeclaration
1124-
if (!!n.moduleReference : Ts.Node).kind = Ts.SyntaxKind.ExternalModuleReference then
1125-
(!!n.moduleReference : Ts.ExternalModuleReference).expression
1113+
|> Option.iter (fun target ->
1114+
graph <- graph |> Graph.add sourceFile.fileName target.fileName)
1115+
1116+
let go (sourceFile: Ts.SourceFile) (ns: Ts.Node seq) =
1117+
for n in ns do
1118+
match n.kind with
1119+
| Ts.SyntaxKind.ImportEqualsDeclaration ->
1120+
let n = n :?> Ts.ImportEqualsDeclaration
1121+
if (!!n.moduleReference : Ts.Node).kind = Ts.SyntaxKind.ExternalModuleReference then
1122+
(!!n.moduleReference : Ts.ExternalModuleReference).expression
1123+
|> handleModuleSpecifier sourceFile
1124+
| Ts.SyntaxKind.ImportDeclaration ->
1125+
let n = n :?> Ts.ImportDeclaration
1126+
n.moduleSpecifier
11261127
|> handleModuleSpecifier sourceFile
1127-
|> Option.iter goSourceFile
1128-
| Ts.SyntaxKind.ImportDeclaration ->
1129-
let n = n :?> Ts.ImportDeclaration
1130-
n.moduleSpecifier
1131-
|> handleModuleSpecifier sourceFile
1132-
|> Option.iter goSourceFile
1133-
| _ -> ()
1134-
n.forEachChild(go sourceFile)
1128+
| _ -> ()
1129+
ns |> Seq.collect (fun n -> n.getChildren(sourceFile))
11351130

1136-
and goSourceFile (sourceFile: Ts.SourceFile) =
1137-
for statement in sourceFile.statements do
1138-
go sourceFile statement |> ignore
1131+
let goSourceFile (sourceFile: Ts.SourceFile) =
1132+
let mutable nodes : Ts.Node seq = !!sourceFile.statements
1133+
while not (nodes |> Seq.isEmpty) do
1134+
nodes <- go sourceFile nodes
11391135

1140-
for sourceFile in sourceFiles do goSourceFile sourceFile
1136+
for source in sourceFiles do goSourceFile source
11411137
graph
11421138

11431139
let assertFileExistsAndHasCorrectExtension (fileName: string) =
@@ -1198,8 +1194,7 @@ let parse (ctx: ParserContext) : Input =
11981194
|> Seq.filter (fun sf -> targets |> Set.contains sf.fileName)
11991195
let sources =
12001196
srcs
1201-
|> Seq.toList
1202-
|> List.map (fun src ->
1197+
|> Seq.map (fun src ->
12031198
ctx.logger.tracef "* parsing %s..." src.fileName
12041199
let references =
12051200
Seq.concat [
@@ -1217,6 +1212,7 @@ let parse (ctx: ParserContext) : Input =
12171212
fileName = src.fileName
12181213
hasNoDefaultLib = src.hasNoDefaultLib
12191214
references = references })
1215+
|> List.ofSeq
12201216

12211217
let info =
12221218
match sources with

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@types/vscode": "^1.63.1",
4040
"@types/yargs": "17.0.9",
4141
"cassandra-driver": "^4.6.3",
42+
"cdk8s": "^2.2.41",
4243
"monaco-editor": "0.33.0",
4344
"react-player": "2.9.0",
4445
"webpack": "5.70.0",

src/Targets/JsOfOCaml/Writer.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,12 +1756,12 @@ let emitFlattenedDefinitions (ctx: Context) (stmts: Statement list) : text list
17561756
let inline emitTypeName name args =
17571757
Type.appOpt (str (Naming.flattenedTypeName name)) args
17581758

1759-
let rec go prefix (ctx: Context) (v: Statement) =
1759+
let rec go (prefix: unit -> string) (ctx: Context) (v: Statement) =
17601760
match v with
17611761
| Enum e ->
17621762
let fn = ctx |> Context.getFullName [e.name]
17631763
[
1764-
yield tprintf "%s %s = " prefix (Naming.flattenedTypeName fn.name) + GetSelfTyText.enumCases e e.cases
1764+
yield tprintf "%s %s = " (prefix()) (Naming.flattenedTypeName fn.name) + GetSelfTyText.enumCases e e.cases
17651765
for c in e.cases do
17661766
yield tprintf "and %s = " (Naming.flattenedTypeName (fn.name @ [c.name])) + GetSelfTyText.enumCases e [c]
17671767
]
@@ -1782,12 +1782,12 @@ let emitFlattenedDefinitions (ctx: Context) (stmts: Statement list) : text list
17821782
| [] -> Prim prim
17831783
| _ -> App (APrim prim, c.typeParams |> List.map (fun tp -> TypeVar tp.name), UnknownLocation)
17841784
emitType_ ctx target
1785-
[prefix @+ " " @+ emitTypeName fn.name typrm +@ " = " + selfTyText]
1785+
[prefix() @+ " " @+ emitTypeName fn.name typrm +@ " = " + selfTyText]
17861786
| TypeAlias { name = name; typeParams = typeParams; target = target } ->
17871787
let fn = ctx |> Context.getFullName [name]
17881788
let typrm = typeParams |> List.map (fun x -> tprintf "'%s" x.name)
17891789
let selfTyText = emitType_ ctx target
1790-
[prefix @+ " " @+ emitTypeName fn.name typrm +@ " = " + selfTyText]
1790+
[prefix() @+ " " @+ emitTypeName fn.name typrm +@ " = " + selfTyText]
17911791
// TODO: emit extends of type parameters
17921792
| Module m -> m.statements |> List.collect (go prefix (ctx |> Context.ofChildNamespace m.name))
17931793
| Global m -> m.statements |> List.collect (go prefix (ctx |> Context.ofRoot))
@@ -1835,7 +1835,7 @@ let emitFlattenedDefinitions (ctx: Context) (stmts: Statement list) : text list
18351835
for a in aim |> Map.toList |> List.map fst do
18361836
yield genAnonymousInterface (getPrefix()) a
18371837
for stmt in stmts do
1838-
yield! go (getPrefix()) ctx stmt
1838+
yield! go getPrefix ctx stmt
18391839
]
18401840

18411841
let emitStatementsWithStructuredText (ctx: Context) (stmts: Statement list) (st: StructuredText) =

yarn.lock

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,15 @@ cassandra-driver@^4.6.3:
826826
adm-zip "^0.5.3"
827827
long "^2.2.0"
828828

829+
cdk8s@^2.2.41:
830+
version "2.2.41"
831+
resolved "https://registry.yarnpkg.com/cdk8s/-/cdk8s-2.2.41.tgz#7bf007fb095dfc85117bb50073bc7dac0610298b"
832+
integrity sha512-89iFXZ76JNfLh4yVeCfa8Y+0MIIAhP5oSlA+6gpdcWCQLnlRAEMY+NW9LxKfTuLdTwCF26EpltW6nBJyjf08xw==
833+
dependencies:
834+
fast-json-patch "^2.2.1"
835+
follow-redirects "^1.14.9"
836+
yaml "2.0.0-7"
837+
829838
chalk@^2.0.0:
830839
version "2.4.2"
831840
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
@@ -1252,6 +1261,11 @@ express@^4.17.1:
12521261
utils-merge "1.0.1"
12531262
vary "~1.1.2"
12541263

1264+
fast-deep-equal@^2.0.1:
1265+
version "2.0.1"
1266+
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
1267+
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
1268+
12551269
fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
12561270
version "3.1.3"
12571271
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
@@ -1268,6 +1282,13 @@ fast-glob@^3.1.1:
12681282
merge2 "^1.3.0"
12691283
micromatch "^4.0.4"
12701284

1285+
fast-json-patch@^2.2.1:
1286+
version "2.2.1"
1287+
resolved "https://registry.yarnpkg.com/fast-json-patch/-/fast-json-patch-2.2.1.tgz#18150d36c9ab65c7209e7d4eb113f4f8eaabe6d9"
1288+
integrity sha512-4j5uBaTnsYAV5ebkidvxiLUYOwjQ+JSFljeqfTxCrH9bDmlCQaOJFS84oDJ2rAXZq2yskmk3ORfoP9DCwqFNig==
1289+
dependencies:
1290+
fast-deep-equal "^2.0.1"
1291+
12711292
fast-json-stable-stringify@^2.0.0:
12721293
version "2.1.0"
12731294
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
@@ -1325,6 +1346,11 @@ follow-redirects@^1.0.0:
13251346
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc"
13261347
integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==
13271348

1349+
follow-redirects@^1.14.9:
1350+
version "1.14.9"
1351+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
1352+
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==
1353+
13281354
13291355
version "0.2.0"
13301356
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811"
@@ -2819,6 +2845,11 @@ y18n@^5.0.5:
28192845
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
28202846
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==
28212847

2848+
2849+
version "2.0.0-7"
2850+
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.0.0-7.tgz#9799d9d85dfc8f01e4cc425e18e09215364beef1"
2851+
integrity sha512-RbI2Tm3hl9AoHY4wWyWvGvJfFIbHOzuzaxum6ez1A0vve+uXgNor03Wys4t+2sgjJSVSe+B2xerd1/dnvqHlOA==
2852+
28222853
yargs-parser@^21.0.0:
28232854
version "21.0.0"
28242855
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.0.tgz#a485d3966be4317426dd56bdb6a30131b281dc55"

0 commit comments

Comments
 (0)