Swap quotes (#355)

- During the first iteration, we printed the unescaped values which let to printing invalid JavaScript characters and bad things like invisible characters.
- During the second iteration, we escaped everything, which generated valid JavaScript but you lost your emojis and chinese/cyrillic characters

In this iteration, which I hope will be the last one, we maintain the string exactly as encoded and only swap quotes. The swap quotes implementation is a bit convoluted but I think it works.
This commit is contained in:
Christopher Chedeau authored and GitHub committed 2017-01-20 14:47:52 -08:00
1 parent d20a580655
commit 080b7f8ec4
4 files changed
+56 -23

No files matched your search

@@ -57,11 +57,11 @@ exports[`test strings.js 1`] = `
\"\'\";
\'\"\';
\'\"\';
\'\\\"\';
\'\\\\\"\';
\"\'\";
\"\'\";
\"\\\'\";
\"\\\\\'\";
\"\'\\\"\";
@@ -71,7 +71,7 @@ exports[`test strings.js 1`] = `
\"\\\\\";
\"\\0\";
\"\\uD83D\\uDC36\";
\"🐶\";
"
`;
@@ -104,11 +104,11 @@ exports[`test strings.js 2`] = `
\"\'\";
\'\"\';
\'\"\';
\'\\\"\';
\'\\\\\"\';
\"\'\";
\"\'\";
\"\\\'\";
\"\\\\\'\";
\'\\\'\"\';
@@ -118,6 +118,6 @@ exports[`test strings.js 2`] = `
\'\\\\\';
\'\\0\';
\'\\uD83D\\uDC36\';
\'🐶\';
"
`;
@@ -30,17 +30,17 @@ exports[`test strings.js 1`] = `
\"abc\",
\"\'\",
\'\"\',
\'\"\',
\'\\\"\',
\'\\\\\"\',
\"\'\",
\"\'\",
\"\\\'\",
\"\\\\\'\",
\"\'\\\"\",
\"\'\\\"\",
\"\\\\\",
\"\\\\\",
\"\\0\",
\"\\uD83D\\uDC36\",
\"🐶\",
\'\\uD801\\uDC28\'
];
"
@@ -73,8 +73,6 @@ function utf16Length(str, pos) {
exports[`test keys.js 1`] = `
"({\'この事はつもり素晴らしいことさ\': \'35jL9V\'})
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
({
\"\\u3053\\u306E\\u4E8B\\u306F\\u3064\\u3082\\u308A\\u7D20\\u6674\\u3089\\u3057\\u3044\\u3053\\u3068\\u3055\": \"35jL9V\"
});
({ \"この事はつもり素晴らしいことさ\": \"35jL9V\" });
"
`;