Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle dropped fields in methods #31

Merged
merged 6 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 54 additions & 5 deletions driver/normalizer/normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func (op opArrToChain) Construct(st *State, n nodes.Node) (nodes.Node, error) {

func funcDefMap(typ string, returns bool, other Obj) Mapping {
src := Obj{
"Body": Var("body"),
"Identifier": Var("name"),
"ParameterList": Obj{
uast.KeyType: String("ParameterList"),
Expand All @@ -190,8 +189,7 @@ func funcDefMap(typ string, returns bool, other Obj) Mapping {
),

// FIXME(dennwc): driver drops them currently
"ExpressionBody": Any(),
"Modifiers": Any(),
"Modifiers": Any(),
}
for k, v := range other {
src[k] = v
Expand All @@ -208,7 +206,38 @@ func funcDefMap(typ string, returns bool, other Obj) Mapping {
)
}
return MapSemantic(typ, uast.FunctionGroup{}, MapObj(
src,
// Either Body or ExpressionBody will be set.
CasesObj("isArrow",
src,
Objs{
// case 1: arrow expression
{
"Body": Is(nil),
"ExpressionBody": Obj{
uast.KeyType: String("ArrowExpressionClause"),
// will use this positions for Block in Body
uast.KeyPos: Var("arrow_pos"),
"ArrowToken": Obj{
uast.KeyType: String("EqualsGreaterThanToken"),
// will use this position for Return in Body
uast.KeyPos: Var("arrow_pos_tok"),
"IsMissing": Bool(false),
"Text": Any(),
"Value": Any(),
"ValueText": Any(),
},
"IsMissing": Bool(false),
"IsStructuredTrivia": Bool(false),
"Expression": Var("arrow"),
},
},
// case 2: full body
{
"ExpressionBody": Is(nil),
"Body": Var("body"),
},
},
),

Obj{
"Nodes": Arr(
Expand All @@ -220,8 +249,28 @@ func funcDefMap(typ string, returns bool, other Obj) Mapping {
UASTType(uast.Alias{}, Obj{
"Name": Var("name"),
"Node": UASTType(uast.Function{}, Obj{
"Body": Var("body"),
"Type": UASTType(uast.FunctionType{}, dstType),
// If the function was defined with an arrow expression, we will
// generate a uast:Block with a since csharp:Return node containing
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I can understand this sentence generate a uast:Block with a ...? since csharp:Return node containing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed the typo in the latest commit.

// the expression.
"Body": Cases("isArrow",
// case 1: arrow expression
UASTType(uast.Block{}, Obj{
uast.KeyPos: Var("arrow_pos"),
"Statements": Arr(
Obj{
uast.KeyType: String("ReturnStatement"),
uast.KeyPos: Var("arrow_pos_tok"),
"Expression": Var("arrow"),
},
),
}),
// case 2: full body
// TODO(dennwc): this will definitely fail the reverse transform
// make a more specific node check when we need it
// see https://github.com/bblfsh/sdk/issues/355
Var("body"),
),
}),
}),
),
Expand Down
Loading