diff options
author | Marcin Gasperowicz <xnooga@gmail.com> | 2020-10-25 14:46:51 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-25 15:16:47 +0100 |
commit | e5ddcadd3cca81b7ad52339bb0fa7e95c93340aa (patch) | |
tree | d682680eeacbc129785a5a309d9e66a906751ee8 /Libraries/LibJS/Tests | |
parent | e6505a95f19387560e9ab83aa1ebdd2c2a7c0c42 (diff) | |
download | serenity-e5ddcadd3cca81b7ad52339bb0fa7e95c93340aa.zip |
LibJS: Parse line continuations in string literals properly
Newlines after line continuation were inserted into the string
literals. This patch makes the parser ignore the newlines after \ and
also makes it so that "use strict" containing a line continuation is
not a valid "use strict".
Diffstat (limited to 'Libraries/LibJS/Tests')
-rw-r--r-- | Libraries/LibJS/Tests/functions/function-strict-mode.js | 6 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/template-literals.js | 7 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/test-common-tests.js | 3 |
3 files changed, 16 insertions, 0 deletions
diff --git a/Libraries/LibJS/Tests/functions/function-strict-mode.js b/Libraries/LibJS/Tests/functions/function-strict-mode.js index 85f022603d..08145bf089 100644 --- a/Libraries/LibJS/Tests/functions/function-strict-mode.js +++ b/Libraries/LibJS/Tests/functions/function-strict-mode.js @@ -30,6 +30,12 @@ test("use strict with double quotes after statement does not yield strict mode c expect(isStrictMode()).toBeFalse(); }); +test("use strict interrupted by a line continuation does not yield strict mode code", () => { + "use \ + strict"; + expect(isStrictMode()).toBeFalse(); +}); + test("strict mode propagates down the scope chain", () => { "use strict"; expect(isStrictMode()).toBeTrue(); diff --git a/Libraries/LibJS/Tests/template-literals.js b/Libraries/LibJS/Tests/template-literals.js index 17cb548641..07d81509a8 100644 --- a/Libraries/LibJS/Tests/template-literals.js +++ b/Libraries/LibJS/Tests/template-literals.js @@ -53,6 +53,13 @@ test("newline literals (not characters)", () => { ).toBe("foo\n bar"); }); +test("line continuation in literals (not characters)", () => { + expect( + `foo\ + bar` + ).toBe("foo bar"); +}); + test("reference error from expressions", () => { expect(() => `${b}`).toThrowWithMessage(ReferenceError, "'b' is not defined"); }); diff --git a/Libraries/LibJS/Tests/test-common-tests.js b/Libraries/LibJS/Tests/test-common-tests.js index 31951fffde..a2071f15a0 100644 --- a/Libraries/LibJS/Tests/test-common-tests.js +++ b/Libraries/LibJS/Tests/test-common-tests.js @@ -53,6 +53,9 @@ test("toHaveLength", () => { expect([1]).toHaveLength(1); expect({ length: 1 }).toHaveLength(1); + expect("a\ +b").toHaveLength(2); + expect(() => { expect(1).toHaveLength(); }).toThrow(ExpectationError); |