Skip to content

Commit

Permalink
fix semiautovivification with slices
Browse files Browse the repository at this point in the history
  • Loading branch information
rhendric committed Feb 10, 2016
1 parent 63c19f5 commit 78ef417
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
16 changes: 13 additions & 3 deletions lib/ast.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/ast.ls
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,6 @@ class exports.Chain extends Node
@head.called = true
else if not @tails.1 and it.key?name is \prototype
@head.sproto = true
else if delete it.vivify
@head = Assign Chain(@head, @tails.splice 0, 9e9), that!, \= \||
else if it instanceof Call and @tails.length is 1
and bi and bi.op in logics = <[ && || xor ]>
call = it
Expand Down Expand Up @@ -759,6 +757,7 @@ class exports.Chain extends Node
.add Call [context, Arr [this; Arr partial.args; Arr partial.partialized]]), post).compile o
@carp 'invalid callee' if tails.0 instanceof Call and not head.is-callable!
@expand-slice o
@expand-vivify!
@expand-bind o
@expand-splat o
@expand-star o
Expand Down Expand Up @@ -837,6 +836,13 @@ class exports.Chain extends Node
i = 0
call <<< method: \.apply, args: [ctx or Literal \null; JS args]

expand-vivify: !->
{tails} = this
i = 0
while i < tails.length when delete tails[i++]vivify
@head = Assign Chain(@head, tails.splice 0, i), that!, \= \||
i = 0

expand-bind: !(o) ->
{tails} = this
i = -1
Expand Down
5 changes: 5 additions & 0 deletions test/chaining.ls
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ eq '0,1' ''+o.a.b
eq '2,3' ''+o.a.c.d
eq 5 o.a.b.e.f.4

a = []
eq 2 a{}[0, 1].length
eq \object typeof a.0
eq \object typeof a.1

# Bang Call
eq '' String!
(-> ok true)!
Expand Down

0 comments on commit 78ef417

Please sign in to comment.