git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix for #2244 (#2246)
0824b1fLiam Goodacre
src/Language/PureScript/CodeGen/JS.hs+8−5
@@ -280,15 +280,18 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
280 extendObj obj sts = do
280 extendObj obj sts = do
281 newObj <- freshName
281 newObj <- freshName
282 key <- freshName
282 key <- freshName
283+ evaluatedObj <- freshName
283 let
284 let
284 jsKey = JSVar Nothing key
285 jsKey = JSVar Nothing key
285 jsNewObj = JSVar Nothing newObj
286 jsNewObj = JSVar Nothing newObj
287+ jsEvaluatedObj = JSVar Nothing evaluatedObj
286− block = JSBlock Nothing (objAssign:copy:extend ++ [JSReturn Nothing jsNewObj])
288+ block = JSBlock Nothing (evaluate:objAssign:copy:extend ++ [JSReturn Nothing jsNewObj])
289+ evaluate = JSVariableIntroduction Nothing evaluatedObj (Just obj)
287 objAssign = JSVariableIntroduction Nothing newObj (Just $ JSObjectLiteral Nothing [])
290 objAssign = JSVariableIntroduction Nothing newObj (Just $ JSObjectLiteral Nothing [])
288− copy = JSForIn Nothing key obj $ JSBlock Nothing [JSIfElse Nothing cond assign Nothing]
291+ copy = JSForIn Nothing key jsEvaluatedObj $ JSBlock Nothing [JSIfElse Nothing cond assign Nothing]
289− cond = JSApp Nothing (JSAccessor Nothing "hasOwnProperty" obj) [jsKey]
292+ cond = JSApp Nothing (JSAccessor Nothing "hasOwnProperty" jsEvaluatedObj) [jsKey]
290− assign = JSBlock Nothing [JSAssignment Nothing (JSIndexer Nothing jsKey jsNewObj) (JSIndexer Nothing jsKey obj)]
293+ assign = JSBlock Nothing [JSAssignment Nothing (JSIndexer Nothing jsKey jsNewObj) (JSIndexer Nothing jsKey jsEvaluatedObj)]
291− stToAssign (s, js) = JSAssignment Nothing (JSAccessor Nothing s jsNewObj) js
294+ stToAssign (s, js) = JSAssignment Nothing (accessorString s jsNewObj) js
292 extend = map stToAssign sts
295 extend = map stToAssign sts
293 return $ JSApp Nothing (JSFunction Nothing Nothing [] block) []
296 return $ JSApp Nothing (JSFunction Nothing Nothing [] block) []
294
297
src/Language/PureScript/CodeGen/JS/Common.hs+1−1
@@ -35,7 +35,7 @@ identToJs (GenIdent _ _) = internalError "GenIdent in identToJs"
35-- Test if a string is a valid JS identifier without escaping.
35-- Test if a string is a valid JS identifier without escaping.
36--
36--
37identNeedsEscaping :: String -> Bool
37identNeedsEscaping :: String -> Bool
38−identNeedsEscaping s = s /= identToJs (Ident s)
38+identNeedsEscaping s = s /= identToJs (Ident s) || null s
39
39
40-- |
40-- |
41-- Attempts to find a human-readable name for a symbol, if none has been specified returns the
41-- Attempts to find a human-readable name for a symbol, if none has been specified returns the