Skip to content

Commit 05aa096

Browse files
teherikd
authored andcommitted
Tests + fixes for missing string escapes.
Signed-off-by: Erik de Castro Lopo <[email protected]> Closes: #49
1 parent 3294055 commit 05aa096

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Tests/LiteralParser.hs

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ testLiteralParser = describe "Parse literals:" $ do
4747
testLiteral "'\\u1234'" `shouldBe` "Right (JSAstLiteral (JSStringLiteral '\\u1234'))"
4848
testLiteral "'\\uabcd'" `shouldBe` "Right (JSAstLiteral (JSStringLiteral '\\uabcd'))"
4949
testLiteral "\"\\r\\n\"" `shouldBe` "Right (JSAstLiteral (JSStringLiteral \"\\r\\n\"))"
50+
testLiteral "\"\\b\"" `shouldBe` "Right (JSAstLiteral (JSStringLiteral \"\\b\"))"
51+
testLiteral "\"\\f\"" `shouldBe` "Right (JSAstLiteral (JSStringLiteral \"\\f\"))"
52+
testLiteral "\"\\t\"" `shouldBe` "Right (JSAstLiteral (JSStringLiteral \"\\t\"))"
53+
testLiteral "\"\\v\"" `shouldBe` "Right (JSAstLiteral (JSStringLiteral \"\\v\"))"
54+
testLiteral "\"\\0\"" `shouldBe` "Right (JSAstLiteral (JSStringLiteral \"\\0\"))"
5055
testLiteral "\"hello\\nworld\"" `shouldBe` "Right (JSAstLiteral (JSStringLiteral \"hello\\nworld\"))"
5156
testLiteral "'hello\\nworld'" `shouldBe` "Right (JSAstLiteral (JSStringLiteral 'hello\\nworld'))"
5257

src/Language/JavaScript/Parser/Lexer.x

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ $not_eol_char = ~$eol_char -- anything but an end of line character
6464
6565
$string_chars = [^ \n \r ' \" \\]
6666
67-
@sq_escapes = \\ ( \\ | ' | r | n | x )
68-
@dq_escapes = \\ ( \\ | \" | r | n | x )
67+
-- See e.g. http://es5.github.io/x7.html#x7.8.4 (Table 4)
68+
@sq_escapes = \\ ( \\ | ' | b | f | n | r | t | v | 0 | x )
69+
@dq_escapes = \\ ( \\ | \" | b | f | n | r | t | v | 0 | x )
6970
7071
@unicode_escape = \\ u $hex_digit{4}
7172

0 commit comments

Comments
 (0)