Skip to content

Commit

Permalink
skip private properties in TypeScript classes, handle getters/setters…
Browse files Browse the repository at this point in the history
… in TypeScript classes
  • Loading branch information
kevinbarabash committed Sep 22, 2024
1 parent 3e212e7 commit 22e9bff
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 94 deletions.
65 changes: 58 additions & 7 deletions src/Escalier.Compiler/Prelude.fs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ module Prelude =
for KeyValue(key, value) in value.Namespaces do
ns <- ns.AddNamespace key value
| None -> failwith $"Couldn't find namespace: '{name}'"
| NamedExport { Src = src; Specifiers = specifiers } ->
| NamedExport { Src = Some src
Specifiers = specifiers } ->
let mutable resolvedPath = resolvePath projectRoot env.Filename src

if resolvedPath.EndsWith(".js") then
Expand Down Expand Up @@ -530,13 +531,63 @@ module Prelude =
printfn $"resolvedPath = {resolvedPath}"
failwith "TODO: getLibExports - NamedExport"

for specifier in specifiers do
match specifier with
| Named { Name = name; Alias = alias } ->
// TODO: look for specifer in exportNs and add it to ns
printfn $"name = {name}, alias = {alias}"
for Named { Name = name; Alias = alias } in specifiers do
let mutable found = false

failwith "TODO: getExports - NamedExports"
let exportName =
match alias with
| Some a -> a
| None -> name

match exportNs.Values.TryFind name with
| Some binding ->
ns <- ns.AddBinding exportName binding
found <- true
| None -> ()

match exportNs.Schemes.TryFind name with
| Some scheme ->
ns <- ns.AddScheme exportName scheme
found <- true
| None -> ()

match exportNs.Namespaces.TryFind name with
| Some value ->
ns <- ns.AddNamespace exportName value
found <- true
| None -> ()

if found then
failwith $"Couldn't find export '{name}' in {resolvedPath}"
| NamedExport { Src = None; Specifiers = specifiers } ->
for Named { Name = name; Alias = alias } in specifiers do
let mutable found = false

let exportName =
match alias with
| Some a -> a
| None -> name

match env.TryFindValue name with
| Some binding ->
ns <- ns.AddBinding exportName binding
found <- true
| None -> ()

match env.TryFindScheme name with
| Some scheme ->
ns <- ns.AddScheme exportName scheme
found <- true
| None -> ()

match env.Namespace.Namespaces.TryFind name with
| Some value ->
ns <- ns.AddNamespace exportName value
found <- true
| None -> ()

if found then
failwith $"Couldn't find '{name}' to export"
| ExportDefault expr ->
match expr.Kind with
| ExprKind.Identifier { Name = name } ->
Expand Down
9 changes: 8 additions & 1 deletion src/Escalier.Data/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ module Syntax =
type EnumVariant =
{ Name: string
TypeAnn: option<TypeAnn> // Must only be an object or tuple type
Init: option<Expr> // Can only be a numer literal or string literal
Span: Span }

type EnumDecl =
Expand Down Expand Up @@ -619,6 +620,11 @@ module Syntax =
Op: string // TODO: Use an enum for this
Right: TypeAnn }

type ImportType =
{ Src: string
Qualifier: option<Common.QualifiedIdent>
TypeArgs: option<list<TypeAnn>> }

type TypeAnnKind =
| Literal of Common.Literal
| Keyword of KeywordTypeAnn
Expand All @@ -641,6 +647,7 @@ module Syntax =
| Binary of BinaryType
| TemplateLiteral of Common.TemplateLiteral<TypeAnn>
| Intrinsic
| ImportType of ImportType

[<CustomEquality; NoComparison>]
type TypeAnn =
Expand Down Expand Up @@ -669,7 +676,7 @@ module Syntax =
type ExportSpecifier = Named of Named

type NamedExport =
{ Src: string
{ Src: option<string>
Specifiers: list<ExportSpecifier> }

type ExportAll = { Src: string }
Expand Down
1 change: 1 addition & 0 deletions src/Escalier.Data/Visitor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ module rec ExprVisitor =
walk max
| TypeAnnKind.TemplateLiteral { Exprs = expr } -> List.iter walk expr
| TypeAnnKind.Intrinsic -> ()
| TypeAnnKind.ImportType _ -> ()

let walkTypeAnnObjElem
(visitor: SyntaxVisitor<'S>)
Expand Down
4 changes: 3 additions & 1 deletion src/Escalier.Interop/MergeLib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ module MergeLib =
if List.contains resolvedPath visitedPaths then
return ()
else
printfn $"resolvedPath = {resolvedPath}"

visitedPaths <- resolvedPath :: visitedPaths

let contents = File.ReadAllText(resolvedPath)
Expand All @@ -159,7 +161,7 @@ module MergeLib =
for item in ast.Items do
match item with
| Import { Path = path } -> do! traverse resolvedPath path
| Export(Export.NamedExport { Src = src }) ->
| Export(Export.NamedExport { Src = Some src }) ->
do! traverse resolvedPath src
| Export(Export.ExportAll { Src = src }) ->
do! traverse resolvedPath src
Expand Down
Loading

0 comments on commit 22e9bff

Please sign in to comment.