@@ -30,6 +30,25 @@ test('$ can use escaped newlines and character escaped tab indentations', testSc
3030\tbar` , 'foo\tbar' ) ;
3131test ( '$ can use escaped newlines and character escaped newlines' , testScriptStdout , ( ) => $ `echo.js foo\
3232\n\nbar` , 'foo\n\nbar' ) ;
33+ // An escaped newline is ignored, so it must not separate tokens, nor hide the whitespaces following it.
34+ // This must behave the same whether the tokens around it are expressions or not.
35+ test ( '$ can use escaped newlines between tokens' , testScriptStdout , ( ) => $ `echo.js foo\
36+ bar` , 'foobar' ) ;
37+ test ( '$ can use escaped newlines between expressions' , testScriptStdout , ( ) => $ `echo.js ${ 'foo' } \
38+ ${ 'bar' } `, 'foobar' ) ;
39+ test ( '$ can use multiple escaped newlines between expressions' , testScriptStdout , ( ) => $ `echo.js ${ 'foo' } \
40+ \
41+ ${ 'bar' } `, 'foobar' ) ;
42+ test ( '$ can use escaped newlines and space indentations between expressions' , testScriptStdout , ( ) => $ `echo.js ${ 'foo' } \
43+ ${ 'bar' } ` , 'foo\nbar' ) ;
44+ test ( '$ can use escaped newlines and tab indentations between expressions' , testScriptStdout , ( ) => $ `echo.js ${ 'foo' } \
45+ ${ 'bar' } ` , 'foo\nbar' ) ;
46+ test ( '$ can use escaped newlines and space indentations after an expression' , testScriptStdout , ( ) => $ `echo.js ${ 'foo' } \
47+ bar` , 'foo\nbar' ) ;
48+ test ( '$ can use escaped newlines and tab indentations after an expression' , testScriptStdout , ( ) => $ `echo.js ${ 'foo' } \
49+ bar` , 'foo\nbar' ) ;
50+ test ( '$ can use escaped newlines before an expression' , testScriptStdout , ( ) => $ `echo.js foo\
51+ ${ 'bar' } `, 'foobar' ) ;
3352test ( '$ can use Windows newlines and tab indentations' , testScriptStdout , ( ) => escapedCall ( 'echo.js foo\r\n\tbar' ) , 'foo\nbar' ) ;
3453test ( '$ can use Windows newlines and space indentations' , testScriptStdout , ( ) => escapedCall ( 'echo.js foo\r\n bar' ) , 'foo\nbar' ) ;
3554test ( '$ does not ignore comments in expressions' , testScriptStdout , ( ) => $ `echo.js foo
@@ -238,6 +257,19 @@ test('$ splits tokens - \\u{0000063}', testScriptStdout, () => $`echo.js a\u{000
238257test ( '$ splits expressions - \\u{0000063}' , testScriptStdout , ( ) => $ `echo.js ${ 'a' } \u{0000063}${ 'b' } ` , 'acb' ) ;
239258test ( '$ concatenates tokens - \\u{0000063}' , testScriptStdout , ( ) => $ `echo.js \u{0000063}a\u{0000063} b` , 'cac\nb' ) ;
240259test ( '$ concatenates expressions - \\u{0000063}' , testScriptStdout , ( ) => $ `echo.js \u{0000063}${ 'a' } \u{0000063} b` , 'cac\nb' ) ;
260+
261+ // Code points above the BMP are a surrogate pair, i.e. two characters, in the template string but not in its raw version.
262+ // Miscounting them shifts every following character, which splits tokens at the wrong place and breaks the surrogate pair.
263+ test ( '$ handles tokens - \\u{1F600}' , testScriptStdout , ( ) => $ `echo.js \u{1F600}` , '\u{1F600}' ) ;
264+ test ( '$ splits tokens - \\u{1F600}' , testScriptStdout , ( ) => $ `echo.js a\u{1F600}b` , 'a\u{1F600}b' ) ;
265+ test ( '$ splits expressions - \\u{1F600}' , testScriptStdout , ( ) => $ `echo.js ${ 'a' } \u{1F600}${ 'b' } ` , 'a\u{1F600}b' ) ;
266+ test ( '$ concatenates tokens - \\u{1F600}' , testScriptStdout , ( ) => $ `echo.js \u{1F600}a\u{1F600} b` , '\u{1F600}a\u{1F600}\nb' ) ;
267+ test ( '$ concatenates expressions - \\u{1F600}' , testScriptStdout , ( ) => $ `echo.js \u{1F600}${ 'a' } \u{1F600} b` , '\u{1F600}a\u{1F600}\nb' ) ;
268+ test ( '$ handles multiple tokens - \\u{1F600}' , testScriptStdout , ( ) => $ `echo.js \u{1F600}\u{1F600} b c` , '\u{1F600}\u{1F600}\nb\nc' ) ;
269+ test ( '$ handles the highest code point - \\u{10FFFF}' , testScriptStdout , ( ) => $ `echo.js \u{10FFFF} b` , '\u{10FFFF}\nb' ) ;
270+ // The BMP boundary is the exact point where the character count changes
271+ test ( '$ handles the last BMP code point - \\u{FFFF}' , testScriptStdout , ( ) => $ `echo.js \u{FFFF} b` , '\u{FFFF}\nb' ) ;
272+ test ( '$ handles the first astral code point - \\u{10000}' , testScriptStdout , ( ) => $ `echo.js \u{10000} b` , '\u{10000}\nb' ) ;
241273test ( '$ handles tokens - \\u{0063}}' , testScriptStdout , ( ) => $ `echo.js \u{0063}}` , 'c}' ) ;
242274test ( '$ splits tokens - \\u{0063}}' , testScriptStdout , ( ) => $ `echo.js a\u{0063}}b` , 'ac}b' ) ;
243275test ( '$ splits expressions - \\u{0063}}' , testScriptStdout , ( ) => $ `echo.js ${ 'a' } \u{0063}}${ 'b' } ` , 'ac}b' ) ;
0 commit comments