Commits

Rune Halvorsen committed f381da1

Unified all parens in cs, to use classic style

Comments (0)

Files changed (1)

-window.linenoise = (input, env) -> _build (_tokenize input), null, env
+window.linenoise = (input, env) -> _build(_tokenize(input), null, env)
 
 _build = (tokens, parent, env={}) ->
     root = not parent
     while token = tokens.shift()
         switch token[0]
             when "+" then 1
-            when ">" then _build tokens, parent.lastChild, env
+            when ">" then _build(tokens, parent.lastChild, env)
             when "<" then return parent if not root
-            when '"' then parent.appendChild _makeTextNode token, env
-            else parent.appendChild _makeNode token, env
+            when '"' then parent.appendChild(_makeTextNode(token, env))
+            else parent.appendChild(_makeNode(token, env))
     parent
 
 _strip = (str) -> str.replace /^\s+|\s+$/g, ""
 
 _interpolate = (subject, env) ->
-    subject.replace /{(.+?)}/g, (str, m1) -> _getProperty(m1, env) ? str
+    subject.replace(/{(.+?)}/g, (str, m1) -> _getProperty(m1, env) ? str)
 
 _getProperty = (propdesc, env) ->
     propchain = propdesc.split(/\.|\[(.*?)\]/).filter((e) -> e)
-    propchain.reduce ((cont, name) -> cont[name]), env
+    propchain.reduce(((cont, name) -> cont[name]), env)
 
 _makeTextNode = (description, env) ->
-    document.createTextNode _interpolate (description.slice 1, -1), env
+    document.createTextNode(_interpolate(description.slice(1, -1), env))
 
 _makeNode = (description, env) ->
-    parts = (description.split /(".+?"|#|\.|\[.+?\])/).map(_strip).filter((e) -> e)
-    ele = document.createElement parts.shift(), env
+    parts = description.split(/(".+?"|#|\.|\[.+?\])/).map(_strip).filter((e) -> e)
+    ele = document.createElement(parts.shift(), env)
     while part = parts.shift()
         switch part[0]
-            when "#" then ele.id = _interpolate parts.shift(), env
-            when "." then ele.className += " " + (_interpolate parts.shift(), env)
+            when "#" then ele.id = _interpolate(parts.shift(), env)
+            when "." then ele.className += " " + _interpolate(parts.shift(), env)
             when "["
                 for name, value of _parseAttributes(part, env)
-                    ele.setAttribute(name, (_interpolate value, env))
+                    ele.setAttribute(name, _interpolate(value, env))
     ele
 
 _parseAttributes = (attrtoken, env) ->
     attrtoken = _strip(attrtoken.slice 1, -1)
     attrs = {}
 
-    for [name, value] in (attrtoken.split /\s*,\s*/).map((e) -> e.split(/\s*=\s*/))
+    for [name, value] in attrtoken.split(/\s*,\s*/).map((e) -> e.split(/\s*=\s*/))
         attrs[name] = _interpolate value, env
-
     attrs
 
 _tokenize = (noisestring) ->
     tokens = []
-    pretokens = noisestring.split /(?=[\.\+\>< ^])(".+?")(?![\.\+\>< $])/
+    pretokens = noisestring.split(/(?=[\.\+\>< ^])(".+?")(?![\.\+\>< $])/)
 
-    while (token = pretokens.shift())?
+    while (token = pretokens.shift())
         if token[0] is '"' then tokens.push token
-        else tokens = tokens.concat token.split /([\+><])/
+        else tokens = tokens.concat(token.split(/([\+><])/))
 
-    tokens.map(_strip).filter (e) -> e isnt ""
+    tokens.map(_strip).filter((e) -> e isnt "")