Skip to content

Commit

Permalink
Update flatten helper without recursion (#5454)
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha authored Sep 19, 2023
1 parent 0f02c50 commit 817c39a
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/v2/annotated-source/coffeescript.html
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ <h1>coffeescript.coffee</h1>
<span class="hljs-string">&quot;<span class="hljs-subst">#{err.toString()}</span>\n<span class="hljs-subst">#{frames.join <span class="hljs-string">&#x27;\n&#x27;</span>}</span>\n&quot;</span>
<span class="hljs-function">
<span class="hljs-title">checkShebangLine</span> = <span class="hljs-params">(file, input)</span> -&gt;</span>
firstLine = input.split(<span class="hljs-regexp">/$/m</span>)[<span class="hljs-number">0</span>]
firstLine = input.split(<span class="hljs-regexp">/$/m</span>, <span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]
rest = firstLine?.match(<span class="hljs-regexp">/^#!\s*([^\s]+\s*)(.*)/</span>)
args = rest?[<span class="hljs-number">2</span>]?.split(<span class="hljs-regexp">/\s/</span>).filter (s) -&gt; s <span class="hljs-keyword">isnt</span> <span class="hljs-string">&#x27;&#x27;</span>
<span class="hljs-keyword">if</span> args?.length &gt; <span class="hljs-number">1</span>
Expand Down
8 changes: 1 addition & 7 deletions docs/v2/annotated-source/helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,7 @@ <h1>helpers.coffee</h1>
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.flatten = flatten = <span class="hljs-function"><span class="hljs-params">(array)</span> -&gt;</span>
flattened = []
<span class="hljs-keyword">for</span> element <span class="hljs-keyword">in</span> array
<span class="hljs-keyword">if</span> <span class="hljs-string">&#x27;[object Array]&#x27;</span> <span class="hljs-keyword">is</span> Object::toString.call element
flattened = flattened.concat flatten element
<span class="hljs-keyword">else</span>
flattened.push element
flattened</pre></div></div>
array.flat(<span class="hljs-literal">Infinity</span>)</pre></div></div>

</li>

Expand Down
2 changes: 1 addition & 1 deletion docs/v2/browser-compiler-legacy/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/v2/browser-compiler-modern/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/coffeescript-browser-compiler-legacy/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/coffeescript-browser-compiler-modern/coffeescript.js

Large diffs are not rendered by default.

12 changes: 1 addition & 11 deletions lib/coffeescript/helpers.js

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

8 changes: 1 addition & 7 deletions src/helpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ extend = exports.extend = (object, properties) ->
# Return a flattened version of an array.
# Handy for getting a list of `children` from the nodes.
exports.flatten = flatten = (array) ->
flattened = []
for element in array
if '[object Array]' is Object::toString.call element
flattened = flattened.concat flatten element
else
flattened.push element
flattened
array.flat(Infinity)

# Delete a key from an object, returning the value. Useful when a node is
# looking for a particular method in an options hash.
Expand Down

0 comments on commit 817c39a

Please sign in to comment.