-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from matthewmcgarvey/mm/destructuring-1
- Loading branch information
Showing
10 changed files
with
130 additions
and
106 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Mint | ||
class Compiler | ||
def _compile(node : Ast::EnumDestructuring, variable : String) : Tuple(String, Array(String)) | ||
variables = | ||
case lookups[node].as(Ast::EnumOption).parameters[0]? | ||
when Ast::EnumRecordDefinition | ||
node.parameters.compact_map do |param| | ||
case param | ||
when Ast::TypeVariable | ||
"const #{js.variable_of(param)} = #{variable}._0.#{param.value}" | ||
end | ||
end | ||
else | ||
node.parameters.map_with_index do |param, index1| | ||
"const #{js.variable_of(param)} = #{variable}._#{index1}" | ||
end | ||
end | ||
|
||
name = | ||
js.class_of(lookups[node]) | ||
|
||
{ | ||
"#{variable} instanceof #{name}", | ||
variables, | ||
} | ||
end | ||
end | ||
end |
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,15 @@ | ||
module Mint | ||
class Compiler | ||
def _compile(node : Ast::TupleDestructuring, variable : String) : Tuple(String, Array(String)) | ||
variables = | ||
node | ||
.parameters | ||
.join(',') { |param| js.variable_of(param) } | ||
|
||
{ | ||
"Array.isArray(#{variable})", | ||
["const [#{variables}] = #{variable}"], | ||
} | ||
end | ||
end | ||
end |
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
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