Skip to content

Commit

Permalink
Allow unescaped paragraph and line separators in string literal (#53869)
Browse files Browse the repository at this point in the history
Co-authored-by: Liviu Gheorghe <[email protected]>
Co-authored-by: Jake Bailey <[email protected]>
  • Loading branch information
3 people authored Sep 15, 2023
1 parent e9af22a commit e654f96
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,8 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
start = pos;
continue;
}
if (isLineBreak(ch) && !jsxAttributeString) {

if ((ch === CharacterCodes.lineFeed || ch === CharacterCodes.carriageReturn) && !jsxAttributeString) {
result += text.substring(start, pos);
tokenFlags |= TokenFlags.Unterminated;
error(Diagnostics.Unterminated_string_literal);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//// [tests/cases/conformance/es2019/allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts] ////

//// [allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts]
// Strings containing unescaped line / paragraph separators
// Using both single quotes, double quotes and template literals

var stringContainingUnescapedLineSeparator1 = "
STRING_CONTENT
";
var stringContainingUnescapedParagraphSeparator1 = "
STRING_CONTENT
";


var stringContainingUnescapedLineSeparator2 = '
STRING_CONTENT
';
var stringContainingUnescapedParagraphSeparator2 = '
STRING_CONTENT
';


var stringContainingUnescapedLineSeparator3 = `
STRING_CONTENT
`;
var stringContainingUnescapedParagraphSeparator3 = `
STRING_CONTENT
`;

// Array of unescaped line / paragraph separators

var arr = [
"

STRING_CONTENT

",
"


STRING_CONTENT


",
"STRING_CONTENT
",
"
STRING_CONTENT",
`\
`,
'
'
];

//// [allowUnescapedParagraphAndLineSeparatorsInStringLiteral.js]
// Strings containing unescaped line / paragraph separators
// Using both single quotes, double quotes and template literals
var stringContainingUnescapedLineSeparator1 = "
STRING_CONTENT
";
var stringContainingUnescapedParagraphSeparator1 = "
STRING_CONTENT
";
var stringContainingUnescapedLineSeparator2 = '
STRING_CONTENT
';
var stringContainingUnescapedParagraphSeparator2 = '
STRING_CONTENT
';
var stringContainingUnescapedLineSeparator3 = "\u2028STRING_CONTENT\u2028";
var stringContainingUnescapedParagraphSeparator3 = "\u2029STRING_CONTENT\u2029";
// Array of unescaped line / paragraph separators
var arr = [
"

STRING_CONTENT

",
"


STRING_CONTENT


",
"STRING_CONTENT
",
"
STRING_CONTENT",
"",
'
'
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//// [tests/cases/conformance/es2019/allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts] ////

=== allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts ===
// Strings containing unescaped line / paragraph separators
// Using both single quotes, double quotes and template literals

var stringContainingUnescapedLineSeparator1 = "
>stringContainingUnescapedLineSeparator1 : Symbol(stringContainingUnescapedLineSeparator1, Decl(allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts, 3, 3))

STRING_CONTENT
";
var stringContainingUnescapedParagraphSeparator1 = "
>stringContainingUnescapedParagraphSeparator1 : Symbol(stringContainingUnescapedParagraphSeparator1, Decl(allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts, 6, 3))

STRING_CONTENT
";


var stringContainingUnescapedLineSeparator2 = '
>stringContainingUnescapedLineSeparator2 : Symbol(stringContainingUnescapedLineSeparator2, Decl(allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts, 11, 3))

STRING_CONTENT
';
var stringContainingUnescapedParagraphSeparator2 = '
>stringContainingUnescapedParagraphSeparator2 : Symbol(stringContainingUnescapedParagraphSeparator2, Decl(allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts, 14, 3))

STRING_CONTENT
';


var stringContainingUnescapedLineSeparator3 = `
>stringContainingUnescapedLineSeparator3 : Symbol(stringContainingUnescapedLineSeparator3, Decl(allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts, 19, 3))

STRING_CONTENT
`;
var stringContainingUnescapedParagraphSeparator3 = `
>stringContainingUnescapedParagraphSeparator3 : Symbol(stringContainingUnescapedParagraphSeparator3, Decl(allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts, 22, 3))

STRING_CONTENT
`;

// Array of unescaped line / paragraph separators

var arr = [
>arr : Symbol(arr, Decl(allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts, 28, 3))

"

STRING_CONTENT

",
"


STRING_CONTENT


",
"STRING_CONTENT
",
"
STRING_CONTENT",
`\
`,
'
'
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//// [tests/cases/conformance/es2019/allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts] ////

=== allowUnescapedParagraphAndLineSeparatorsInStringLiteral.ts ===
// Strings containing unescaped line / paragraph separators
// Using both single quotes, double quotes and template literals

var stringContainingUnescapedLineSeparator1 = "
>stringContainingUnescapedLineSeparator1 : string
>"
STRING_CONTENT
" : "\u2028STRING_CONTENT\u2028"

STRING_CONTENT
";
var stringContainingUnescapedParagraphSeparator1 = "
>stringContainingUnescapedParagraphSeparator1 : string
>"
STRING_CONTENT
" : "\u2029STRING_CONTENT\u2029"

STRING_CONTENT
";


var stringContainingUnescapedLineSeparator2 = '
>stringContainingUnescapedLineSeparator2 : string
>'
STRING_CONTENT
' : "\u2028STRING_CONTENT\u2028"

STRING_CONTENT
';
var stringContainingUnescapedParagraphSeparator2 = '
>stringContainingUnescapedParagraphSeparator2 : string
>'
STRING_CONTENT
' : "\u2029STRING_CONTENT\u2029"

STRING_CONTENT
';


var stringContainingUnescapedLineSeparator3 = `
>stringContainingUnescapedLineSeparator3 : string
>`
STRING_CONTENT
` : "\u2028STRING_CONTENT\u2028"

STRING_CONTENT
`;
var stringContainingUnescapedParagraphSeparator3 = `
>stringContainingUnescapedParagraphSeparator3 : string
>`
STRING_CONTENT
` : "\u2029STRING_CONTENT\u2029"

STRING_CONTENT
`;

// Array of unescaped line / paragraph separators

var arr = [
>arr : string[]
>[ "

STRING_CONTENT

", "


STRING_CONTENT


", "STRING_CONTENT
", "
STRING_CONTENT", `\
`, '
'] : string[]

"
>"

STRING_CONTENT

" : "\u2029\u2028STRING_CONTENT\u2028\u2029"

STRING_CONTENT

",
"
>"


STRING_CONTENT


" : "\u2028\u2029\u2029STRING_CONTENT\u2029\u2029\u2028"


STRING_CONTENT


",
"STRING_CONTENT
>"STRING_CONTENT
" : "STRING_CONTENT\u2029"

",
"
>"
STRING_CONTENT" : "\u2028STRING_CONTENT"

STRING_CONTENT",
`\
>`\
` : ""

`,
'
>'
' : "\u2028"

'
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Strings containing unescaped line / paragraph separators
// Using both single quotes, double quotes and template literals

var stringContainingUnescapedLineSeparator1 = "
STRING_CONTENT
";
var stringContainingUnescapedParagraphSeparator1 = "
STRING_CONTENT
";


var stringContainingUnescapedLineSeparator2 = '
STRING_CONTENT
';
var stringContainingUnescapedParagraphSeparator2 = '
STRING_CONTENT
';


var stringContainingUnescapedLineSeparator3 = `
STRING_CONTENT
`;
var stringContainingUnescapedParagraphSeparator3 = `
STRING_CONTENT
`;

// Array of unescaped line / paragraph separators

var arr = [
"

STRING_CONTENT

",
"


STRING_CONTENT


",
"STRING_CONTENT
",
"
STRING_CONTENT",
`\
`,
'
'
];

0 comments on commit e654f96

Please sign in to comment.