@@ -19,6 +19,7 @@ import Prelude.Compat
19import Control.Monad
19import Control.Monad
20import Control.Monad.Error.Class
20import Control.Monad.Error.Class
22+import Data.Char (chr, digitToInt)
22import Data.Generics (everything, everywhere, mkQ, mkT)
23import Data.Generics (everything, everywhere, mkQ, mkT)
23import Data.Graph
24import Data.Graph
24import Data.List (nub, stripPrefix)
25import Data.List (nub, stripPrefix)
@@ -186,11 +187,34 @@ withDeps (Module modulePath es) = Module modulePath (map expandDeps es)
187-- String literals include the quote chars
188-- String literals include the quote chars
188fromStringLiteral :: JSExpression -> Maybe String
189fromStringLiteral :: JSExpression -> Maybe String
189−fromStringLiteral (JSStringLiteral _ str) = Just $ trimStringQuotes str
190+fromStringLiteral (JSStringLiteral _ str) = Just $ strValue str
190fromStringLiteral _ = Nothing
191fromStringLiteral _ = Nothing
192−trimStringQuotes :: String -> String
193+strValue :: String -> String
193−trimStringQuotes str = reverse $ drop 1 $ reverse $ drop 1 $ str
194+strValue str = go $ drop 1 str
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
205+ a' = 16 * digitToInt a
207+ go ('\\' : 'u' : a : b : c : d : xs) = chr (a' + b' + c' + d') : go xs
209+ a' = 16 * 16 * 16 * digitToInt a
210+ b' = 16 * 16 * digitToInt b
211+ c' = 16 * digitToInt c
213+ go ('\\' : x : xs) = x : go xs
216+ go (x : xs) = x : go xs
195commaList :: JSCommaList a -> [a]
219commaList :: JSCommaList a -> [a]
196commaList JSLNil = []
220commaList JSLNil = []
@@ -332,7 +356,7 @@ matchExportsAssignment stmt
332 = Nothing
356 = Nothing
334extractLabel :: JSPropertyName -> Maybe String
358extractLabel :: JSPropertyName -> Maybe String
335−extractLabel (JSPropertyString _ nm) = Just (trimStringQuotes nm)
359+extractLabel (JSPropertyString _ nm) = Just $ strValue nm
336extractLabel (JSPropertyIdent _ nm) = Just nm
360extractLabel (JSPropertyIdent _ nm) = Just nm
337extractLabel _ = Nothing
361extractLabel _ = Nothing