mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
add some specs for name extract
This commit is contained in:
parent
e94494721a
commit
02a20ea695
@ -228,5 +228,6 @@ end
|
||||
return {
|
||||
has_destructure = has_destructure,
|
||||
split_assign = split_assign,
|
||||
build_assign = build_assign
|
||||
build_assign = build_assign,
|
||||
extract_assign_names = extract_assign_names
|
||||
}
|
||||
|
@ -123,4 +123,4 @@ split_assign = (scope, assign) ->
|
||||
|
||||
build.group g
|
||||
|
||||
{ :has_destructure, :split_assign, :build_assign }
|
||||
{ :has_destructure, :split_assign, :build_assign, :extract_assign_names }
|
||||
|
@ -1,6 +1,55 @@
|
||||
|
||||
import with_dev from require "spec.helpers"
|
||||
|
||||
describe "moonscript.transform.destructure", ->
|
||||
local extract_assign_names
|
||||
|
||||
with_dev ->
|
||||
{ :extract_assign_names } = require "moonscript.transform.destructure"
|
||||
|
||||
it "extracts names from table destructure", ->
|
||||
des = {
|
||||
"table"
|
||||
{
|
||||
{{"key_literal", "hi"}, {"ref", "hi"}}
|
||||
{{"key_literal", "world"}, {"ref", "world"}}
|
||||
}
|
||||
}
|
||||
|
||||
assert.same {
|
||||
{
|
||||
{"ref", "hi"} -- target
|
||||
{
|
||||
{"dot", "hi"}
|
||||
} -- chain suffix
|
||||
}
|
||||
|
||||
{
|
||||
{"ref", "world"}
|
||||
{
|
||||
{"dot", "world"}
|
||||
}
|
||||
}
|
||||
|
||||
}, extract_assign_names des
|
||||
|
||||
it "extracts names from array destructure", ->
|
||||
des = {
|
||||
"table"
|
||||
{
|
||||
{{"ref", "hi"}}
|
||||
}
|
||||
}
|
||||
|
||||
assert.same {
|
||||
{
|
||||
{"ref", "hi"}
|
||||
{
|
||||
{"index", {"number", 1}}
|
||||
}
|
||||
}
|
||||
}, extract_assign_names des
|
||||
|
||||
describe "moonscript.transform.statements", ->
|
||||
local last_stm, transform_last_stm, Run
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user