@@ -19,6 +19,7 @@ import Prelude.Compat
1919import Control.Monad
2020import Control.Monad.Error.Class
2121
22+import Data.Char (chr, digitToInt)
2223import Data.Generics (everything, everywhere, mkQ, mkT)
2324import Data.Graph
2425import Data.List (nub, stripPrefix)
@@ -186,11 +187,34 @@ withDeps (Module modulePath es) = Module modulePath (map expandDeps es)
186187
187188-- String literals include the quote chars
188189fromStringLiteral :: JSExpression -> Maybe String
189−fromStringLiteral (JSStringLiteral _ str) = Just $ trimStringQuotes str
190+fromStringLiteral (JSStringLiteral _ str) = Just $ strValue str
190191fromStringLiteral _ = Nothing
191192
192−trimStringQuotes :: String -> String
193−trimStringQuotes str = reverse $ drop 1 $ reverse $ drop 1 $ str
193+strValue :: String -> String
194+strValue str = go $ drop 1 str
195+ where
196+ go ('\\' : 'b' : xs) = '\b' : go xs
197+ go ('\\' : 'f' : xs) = '\f' : go xs
198+ go ('\\' : 'n' : xs) = '\n' : go xs
199+ go ('\\' : 'r' : xs) = '\r' : go xs
200+ go ('\\' : 't' : xs) = '\t' : go xs
201+ go ('\\' : 'v' : xs) = '\v' : go xs
202+ go ('\\' : '0' : xs) = '\0' : go xs
203+ go ('\\' : 'x' : a : b : xs) = chr (a' + b') : go xs
204+ where
205+ a' = 16 * digitToInt a
206+ b' = digitToInt b
207+ go ('\\' : 'u' : a : b : c : d : xs) = chr (a' + b' + c' + d') : go xs
208+ where
209+ a' = 16 * 16 * 16 * digitToInt a
210+ b' = 16 * 16 * digitToInt b
211+ c' = 16 * digitToInt c
212+ d' = digitToInt d
213+ go ('\\' : x : xs) = x : go xs
214+ go "\"" = ""
215+ go "'" = ""
216+ go (x : xs) = x : go xs
217+ go "" = ""
194218
195219commaList :: JSCommaList a -> [a]
196220commaList JSLNil = []
@@ -332,7 +356,7 @@ matchExportsAssignment stmt
332356 = Nothing
333357
334358extractLabel :: JSPropertyName -> Maybe String
335−extractLabel (JSPropertyString _ nm) = Just (trimStringQuotes nm)
359+extractLabel (JSPropertyString _ nm) = Just $ strValue nm
336360extractLabel (JSPropertyIdent _ nm) = Just nm
337361extractLabel _ = Nothing
338362