Skip to content

Commit df1f3e5

Browse files
committed
exporting a function should work
1 parent 83cb79e commit df1f3e5

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/ToJs.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ instance ConvertToJs Salty where
166166
toJs (Operation left Spaceship right) = print2 "% <=> %" (toJs left) (toJs right)
167167

168168
toJs (Function name args body visibility scope)
169-
| scope == ClassScope = print3 "\n%(%) {\n%\n}\n" funcName funcArgs (funcBody body)
169+
| scope == ClassScope = print3 "%(%) {\n%\n}\n" funcName funcArgs (funcBody body)
170170
| otherwise = print3 "const % = (%) => {\n%\n}\n" funcName funcArgs (funcBody body)
171171
where funcName = funcVisibility ++ (simpleVarName name)
172172
-- the parser strips out the leading '_' but we need to put it back for JS
@@ -347,6 +347,8 @@ instance ConvertToJs Salty where
347347
toJs (Keyword (KwPreceding "const" (Operation (Constant (Variable var _)) op right))) = "const " ++ (toJs (Operation (PurePhp (simpleVarName var)) op right))
348348
toJs (Keyword (KwPreceding "const" (Constant (Variable var _)))) = "const " ++ (simpleVarName var)
349349
toJs (Keyword (KwPreceding "const" (Variable var _))) = "const " ++ (simpleVarName var)
350+
351+
toJs (Keyword (KwPreceding "export" (Keyword (KwPreceding "default" f@(Function n a b v s))))) = "export default function " ++ (toJs (Function n a b v ClassScope))
350352
toJs (Keyword (KwPreceding str salty)) = str ++ " " ++ (toJs salty)
351353
toJs (Keyword (KwSimple str)) = str
352354
toJs (Range (SaltyNumber l) (SaltyNumber r)) = show $ [left..right]

test/JsSpec.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -707,5 +707,6 @@ jsTests = [
707707
"h1 (myVar.foo)" `matches` "<h1>{myVar.foo}</h1>",
708708
"h1 (@myVar.bar)" `matches` "<h1>{this.myVar.bar}</h1>",
709709
"h1 (@@myVar.baz)" `matches` "<h1>{this.state.myVar.baz}</h1>",
710-
"h1 ('hello, ' ++ name ++ '!')" `matches` "<h1>{\"hello, \" + name + \"!\"}</h1>"
710+
"h1 ('hello, ' ++ name ++ '!')" `matches` "<h1>{\"hello, \" + name + \"!\"}</h1>",
711+
"export default foo := 1" `matches` "export default function foo() {\n return 1;\n}"
711712
]

todos

+2
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ in a where clause, all those vars need to be defined w a const or a let.
3838

3939
would be cool to add some basic checks as warnings. Like constructors of react components need to have a super(props) call.
4040
getChildContext needs to be matched with a childContextTypes. Functions that use a context need to define contextTypes. etc.
41+
42+
listings.prices.0 should resolve to listing.prices[0]

0 commit comments

Comments
 (0)