git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix for #2244 (#2246)

* Fix for #2244 * Fix record extension code gen: * Now uses accessorString for assigning keys * Now only evaluates the object once instead of `1 + (2 * num of existing keys)`

commit0824b1f9c09ff908a19977fa4f5208e5b7b6805e authorLiam Goodacre <goodacre.liam@gmail.com> dateTue 26 Jul 2016, 03:48 (10 years ago) parentf0d5256
2 files changed+9−6
src/Language/PureScript/CodeGen/JS.hs+8−5 src/Language/PureScript/CodeGen/JS/Common.hs+1−1
src/Language/PureScript/CodeGen/JS.hs+8−5
@@ -280,15 +280,18 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
280280 extendObj obj sts = do
281281 newObj <- freshName
282282 key <- freshName
283+ evaluatedObj <- freshName
283284 let
284285 jsKey = JSVar Nothing key
285286 jsNewObj = JSVar Nothing newObj
286− block = JSBlock Nothing (objAssign:copy:extend ++ [JSReturn Nothing jsNewObj])
287+ jsEvaluatedObj = JSVar Nothing evaluatedObj
288+ block = JSBlock Nothing (evaluate:objAssign:copy:extend ++ [JSReturn Nothing jsNewObj])
289+ evaluate = JSVariableIntroduction Nothing evaluatedObj (Just obj)
287290 objAssign = JSVariableIntroduction Nothing newObj (Just $ JSObjectLiteral Nothing [])
288− copy = JSForIn Nothing key obj $ JSBlock Nothing [JSIfElse Nothing cond assign Nothing]
289− cond = JSApp Nothing (JSAccessor Nothing "hasOwnProperty" obj) [jsKey]
290− assign = JSBlock Nothing [JSAssignment Nothing (JSIndexer Nothing jsKey jsNewObj) (JSIndexer Nothing jsKey obj)]
291− stToAssign (s, js) = JSAssignment Nothing (JSAccessor Nothing s jsNewObj) js
291+ copy = JSForIn Nothing key jsEvaluatedObj $ JSBlock Nothing [JSIfElse Nothing cond assign Nothing]
292+ cond = JSApp Nothing (JSAccessor Nothing "hasOwnProperty" jsEvaluatedObj) [jsKey]
293+ assign = JSBlock Nothing [JSAssignment Nothing (JSIndexer Nothing jsKey jsNewObj) (JSIndexer Nothing jsKey jsEvaluatedObj)]
294+ stToAssign (s, js) = JSAssignment Nothing (accessorString s jsNewObj) js
292295 extend = map stToAssign sts
293296 return $ JSApp Nothing (JSFunction Nothing Nothing [] block) []
294297
src/Language/PureScript/CodeGen/JS/Common.hs+1−1
@@ -35,7 +35,7 @@ identToJs (GenIdent _ _) = internalError "GenIdent in identToJs"
3535-- Test if a string is a valid JS identifier without escaping.
3636--
3737identNeedsEscaping :: String -> Bool
38−identNeedsEscaping s = s /= identToJs (Ident s)
38+identNeedsEscaping s = s /= identToJs (Ident s) || null s
3939
4040-- |
4141-- Attempts to find a human-readable name for a symbol, if none has been specified returns the