Skip to content

Commit

Permalink
object literal [#7]
Browse files Browse the repository at this point in the history
  • Loading branch information
helixbass committed Jul 23, 2015
1 parent df93ec2 commit 1c2b869
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 124 deletions.
12 changes: 12 additions & 0 deletions cophee_test/compare_output
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ def compare msg, input, expected_output
print '.'
end

compare "object literal",
'''
{{ a: 1 }}
$b = {{
c: 3
d: 4
}}
''',
"""
((object) [ 'a' => 1 ]);
$b = (object) [ 'c' => 3, 'd' => 4 ];
"""
compare "unless element in array",
'''
unless $a in $b()
Expand Down
1 change: 1 addition & 0 deletions documentation/docs/grammar.html
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ <h2 id="grammatical-rules">Grammatical Rules</h2>

<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">Object</span>: [
o <span class="hljs-string">'{ AssignList OptComma }'</span>,<span class="hljs-function"> -&gt;</span> <span class="hljs-keyword">new</span> Obj $<span class="hljs-number">2</span>, $<span class="hljs-number">1.</span>generated
o <span class="hljs-string">'{ { AssignList OptComma } }'</span>,<span class="hljs-function"> -&gt;</span> <span class="hljs-keyword">new</span> Obj $<span class="hljs-number">3</span>, $<span class="hljs-number">2.</span>generated, <span class="hljs-literal">yes</span>
]</pre></div></div>

</li>
Expand Down
5 changes: 3 additions & 2 deletions documentation/docs/nodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,7 @@ <h3 id="obj">Obj</h3>
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Obj = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Obj</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(props, <span class="hljs-property">@generated</span> = <span class="hljs-literal">false</span>)</span> -&gt;</span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(props, <span class="hljs-property">@generated</span> = <span class="hljs-literal">false</span>, <span class="hljs-property">@is_obj</span>=<span class="hljs-literal">false</span>)</span> -&gt;</span>
<span class="hljs-property">@objects</span> = <span class="hljs-property">@properties</span> = props <span class="hljs-keyword">or</span> []

<span class="hljs-attribute">children</span>: [<span class="hljs-string">'properties'</span>]
Expand Down Expand Up @@ -2356,7 +2356,8 @@ <h3 id="obj">Obj</h3>

</div>

<div class="content"><div class='highlight'><pre> answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"[<span class="hljs-subst">#{<span class="hljs-keyword">if</span> props.length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">or</span> dynamicIndex <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> <span class="hljs-string">']'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'\n'</span>}</span>"</span>
<div class="content"><div class='highlight'><pre> answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"(object) "</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@is_obj</span>
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"[<span class="hljs-subst">#{<span class="hljs-keyword">if</span> props.length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">or</span> dynamicIndex <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> <span class="hljs-string">']'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'\n'</span>}</span>"</span>
<span class="hljs-keyword">for</span> prop, i <span class="hljs-keyword">in</span> props
prop.variable.base.value = ensureQuoted prop.variable.base.value <span class="hljs-keyword">unless</span> prop.variable?.properties.length <span class="hljs-keyword">or</span> <span class="hljs-keyword">not</span> prop.variable?.base.value <span class="hljs-keyword">or</span> starts prop.variable.base.value, <span class="hljs-string">'$'</span>
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> prop.<span class="hljs-keyword">this</span> <span class="hljs-keyword">and</span> prop.base.value <span class="hljs-keyword">and</span> (
Expand Down
8 changes: 4 additions & 4 deletions extras/coffee-script.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/coffee-script/grammar.js

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

6 changes: 5 additions & 1 deletion lib/coffee-script/nodes.js

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

Loading

1 comment on commit 1c2b869

@helixbass
Copy link
Owner Author

Choose a reason for hiding this comment

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

ok

Please sign in to comment.