-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support optional properties and optional chaining of those properties (…
…#29) * Update the parser to member access, optional chaining for member access, and optional properties on object types * Add new snapshot files * Update the type checker to handle optional chaining * Update test case to verify behavior of optional chaining when it isn't required
- Loading branch information
1 parent
f535806
commit 9db368f
Showing
12 changed files
with
464 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Escalier.Parser.Tests/snapshots/Tests.ParseObjPropWithOptChain.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
input: obj?.a?.b | ||
output: Success: { Kind = Member ({ Kind = Member ({ Kind = Identifier "obj" | ||
Span = { Start = (Ln: 1, Col: 1) | ||
Stop = (Ln: 1, Col: 4) } | ||
InferredType = None }, "a", true) | ||
Span = { Start = (Ln: 1, Col: 1) | ||
Stop = (Ln: 1, Col: 7) } | ||
InferredType = None }, "b", true) | ||
Span = { Start = (Ln: 1, Col: 1) | ||
Stop = (Ln: 1, Col: 10) } | ||
InferredType = None } |
11 changes: 11 additions & 0 deletions
11
src/Escalier.Parser.Tests/snapshots/Tests.ParseObjProperty.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
input: obj.a.b | ||
output: Success: { Kind = Member ({ Kind = Member ({ Kind = Identifier "obj" | ||
Span = { Start = (Ln: 1, Col: 1) | ||
Stop = (Ln: 1, Col: 4) } | ||
InferredType = None }, "a", false) | ||
Span = { Start = (Ln: 1, Col: 1) | ||
Stop = (Ln: 1, Col: 6) } | ||
InferredType = None }, "b", false) | ||
Span = { Start = (Ln: 1, Col: 1) | ||
Stop = (Ln: 1, Col: 8) } | ||
InferredType = None } |
60 changes: 60 additions & 0 deletions
60
src/Escalier.Parser.Tests/snapshots/Tests.ParseOptionalParams.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
input: | ||
let foo = fn(a?: number, b?: string) => a | ||
|
||
output: Success: [{ Kind = | ||
Decl | ||
{ Kind = | ||
VarDecl | ||
({ Kind = Identifier { Span = { Start = (Ln: 2, Col: 9) | ||
Stop = (Ln: 2, Col: 13) } | ||
Name = "foo" | ||
IsMut = false } | ||
Span = { Start = (Ln: 2, Col: 9) | ||
Stop = (Ln: 2, Col: 13) } | ||
InferredType = None }, | ||
{ Kind = | ||
Function | ||
{ Sig = | ||
{ TypeParams = None | ||
ParamList = | ||
[{ Pattern = | ||
{ Kind = | ||
Identifier { Span = { Start = (Ln: 2, Col: 18) | ||
Stop = (Ln: 2, Col: 19) } | ||
Name = "a" | ||
IsMut = false } | ||
Span = { Start = (Ln: 2, Col: 18) | ||
Stop = (Ln: 2, Col: 19) } | ||
InferredType = None } | ||
TypeAnn = Some { Kind = Keyword Number | ||
Span = { Start = (Ln: 2, Col: 22) | ||
Stop = (Ln: 2, Col: 28) } | ||
InferredType = None } | ||
Optional = true }; | ||
{ Pattern = | ||
{ Kind = | ||
Identifier { Span = { Start = (Ln: 2, Col: 30) | ||
Stop = (Ln: 2, Col: 31) } | ||
Name = "b" | ||
IsMut = false } | ||
Span = { Start = (Ln: 2, Col: 30) | ||
Stop = (Ln: 2, Col: 31) } | ||
InferredType = None } | ||
TypeAnn = Some { Kind = Keyword String | ||
Span = { Start = (Ln: 2, Col: 34) | ||
Stop = (Ln: 2, Col: 40) } | ||
InferredType = None } | ||
Optional = true }] | ||
ReturnType = None | ||
Throws = None } | ||
Body = Expr { Kind = Identifier "a" | ||
Span = { Start = (Ln: 2, Col: 45) | ||
Stop = (Ln: 3, Col: 3) } | ||
InferredType = None } } | ||
Span = { Start = (Ln: 2, Col: 15) | ||
Stop = (Ln: 3, Col: 3) } | ||
InferredType = None }, None) | ||
Span = { Start = (Ln: 2, Col: 5) | ||
Stop = (Ln: 3, Col: 3) } } | ||
Span = { Start = (Ln: 2, Col: 5) | ||
Stop = (Ln: 3, Col: 3) } }] |
47 changes: 47 additions & 0 deletions
47
src/Escalier.Parser.Tests/snapshots/Tests.ParseOptionalProps.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
input: | ||
type Obj = {a?: {b?: {c?: number}}} | ||
|
||
output: Success: [{ Kind = | ||
Decl | ||
{ Kind = | ||
TypeDecl | ||
("Obj", | ||
{ Kind = | ||
Object | ||
[Property | ||
{ Name = "a" | ||
TypeAnn = | ||
{ Kind = | ||
Object | ||
[Property | ||
{ Name = "b" | ||
TypeAnn = | ||
{ Kind = | ||
Object | ||
[Property | ||
{ Name = "c" | ||
TypeAnn = | ||
{ Kind = Keyword Number | ||
Span = | ||
{ Start = (Ln: 2, Col: 31) | ||
Stop = (Ln: 2, Col: 37) } | ||
InferredType = None } | ||
Optional = true | ||
Readonly = false }] | ||
Span = { Start = (Ln: 2, Col: 26) | ||
Stop = (Ln: 2, Col: 38) } | ||
InferredType = None } | ||
Optional = true | ||
Readonly = false }] | ||
Span = { Start = (Ln: 2, Col: 21) | ||
Stop = (Ln: 2, Col: 39) } | ||
InferredType = None } | ||
Optional = true | ||
Readonly = false }] | ||
Span = { Start = (Ln: 2, Col: 16) | ||
Stop = (Ln: 3, Col: 3) } | ||
InferredType = None }, None) | ||
Span = { Start = (Ln: 2, Col: 5) | ||
Stop = (Ln: 3, Col: 3) } } | ||
Span = { Start = (Ln: 2, Col: 5) | ||
Stop = (Ln: 3, Col: 3) } }] |
38 changes: 38 additions & 0 deletions
38
src/Escalier.Parser.Tests/snapshots/Tests.ParseOtherLiterals.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
input: | ||
let a = undefined | ||
let b = null | ||
|
||
output: Success: [{ Kind = | ||
Decl | ||
{ Kind = | ||
VarDecl ({ Kind = Identifier { Span = { Start = (Ln: 2, Col: 7) | ||
Stop = (Ln: 2, Col: 9) } | ||
Name = "a" | ||
IsMut = false } | ||
Span = { Start = (Ln: 2, Col: 7) | ||
Stop = (Ln: 2, Col: 9) } | ||
InferredType = None }, { Kind = Literal Undefined | ||
Span = { Start = (Ln: 2, Col: 11) | ||
Stop = (Ln: 2, Col: 20) } | ||
InferredType = None }, None) | ||
Span = { Start = (Ln: 2, Col: 3) | ||
Stop = (Ln: 3, Col: 3) } } | ||
Span = { Start = (Ln: 2, Col: 3) | ||
Stop = (Ln: 3, Col: 3) } }; | ||
{ Kind = | ||
Decl | ||
{ Kind = | ||
VarDecl ({ Kind = Identifier { Span = { Start = (Ln: 3, Col: 7) | ||
Stop = (Ln: 3, Col: 9) } | ||
Name = "b" | ||
IsMut = false } | ||
Span = { Start = (Ln: 3, Col: 7) | ||
Stop = (Ln: 3, Col: 9) } | ||
InferredType = None }, { Kind = Literal Null | ||
Span = { Start = (Ln: 3, Col: 11) | ||
Stop = (Ln: 3, Col: 15) } | ||
InferredType = None }, None) | ||
Span = { Start = (Ln: 3, Col: 3) | ||
Stop = (Ln: 4, Col: 3) } } | ||
Span = { Start = (Ln: 3, Col: 3) | ||
Stop = (Ln: 4, Col: 3) } }] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.