mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:37:34 +00:00
LibJS: Allow all line terminators to be used for line continuations
This commit is contained in:
parent
1319ad476d
commit
66e315959d
3 changed files with 21 additions and 4 deletions
|
@ -32,7 +32,7 @@ test("use strict with double quotes after statement does not yield strict mode c
|
||||||
|
|
||||||
test("use strict interrupted by a line continuation does not yield strict mode code", () => {
|
test("use strict interrupted by a line continuation does not yield strict mode code", () => {
|
||||||
"use \
|
"use \
|
||||||
strict";
|
strict";
|
||||||
expect(isStrictMode()).toBeFalse();
|
expect(isStrictMode()).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -18,13 +18,13 @@ test("CARRIAGE RETURN is a line terminator", () => {
|
||||||
|
|
||||||
test("LINE SEPARATOR is a line terminator", () => {
|
test("LINE SEPARATOR is a line terminator", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
Function(`
@`);
|
Function("
@");
|
||||||
}).toThrowWithMessage(SyntaxError, "line: 3, column: 1");
|
}).toThrowWithMessage(SyntaxError, "line: 3, column: 1");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("PARAGRAPH SEPARATOR is a line terminator", () => {
|
test("PARAGRAPH SEPARATOR is a line terminator", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
Function(`
@`);
|
Function("
@");
|
||||||
}).toThrowWithMessage(SyntaxError, "line: 3, column: 1");
|
}).toThrowWithMessage(SyntaxError, "line: 3, column: 1");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -48,6 +48,13 @@ test("LS/PS are allowed in string literal", () => {
|
||||||
|
|
||||||
test("line terminators can be mixed (but please don't)", () => {
|
test("line terminators can be mixed (but please don't)", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
Function(`\r\
\r\n
\n\r@`);
|
Function("\r
\r\n
\n\r@");
|
||||||
}).toThrowWithMessage(SyntaxError, "line: 7, column: 1");
|
}).toThrowWithMessage(SyntaxError, "line: 7, column: 1");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("all line terminators are valid for line continuations", () => {
|
||||||
|
expect(Function('return "a\\\nb"')()).toBe("ab");
|
||||||
|
expect(Function('return "a\\\rb"')()).toBe("ab");
|
||||||
|
expect(Function('return "a\\
b"')()).toBe("ab");
|
||||||
|
expect(Function('return "a\\
b"')()).toBe("ab");
|
||||||
|
});
|
||||||
|
|
|
@ -157,6 +157,8 @@ String Token::string_value(StringValueStatus& status) const
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
break;
|
break;
|
||||||
|
case '\r':
|
||||||
|
break;
|
||||||
case 'x': {
|
case 'x': {
|
||||||
if (i + 2 >= m_value.length() - offset)
|
if (i + 2 >= m_value.length() - offset)
|
||||||
return encoding_failure(StringValueStatus::MalformedHexEscape);
|
return encoding_failure(StringValueStatus::MalformedHexEscape);
|
||||||
|
@ -207,6 +209,14 @@ String Token::string_value(StringValueStatus& status) const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
if (i + 2 < m_value.length() - offset) {
|
||||||
|
auto three_chars_view = m_value.substring_view(i, 3);
|
||||||
|
if (three_chars_view == LINE_SEPARATOR || three_chars_view == PARAGRAPH_SEPARATOR) {
|
||||||
|
// line continuation with LS or PS
|
||||||
|
i += 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (is_template && (m_value[i] == '$' || m_value[i] == '`')) {
|
if (is_template && (m_value[i] == '$' || m_value[i] == '`')) {
|
||||||
builder.append(m_value[i]);
|
builder.append(m_value[i]);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue