Skip to content

Commit

Permalink
Properly handle line breaks when looking for directives (#1283)
Browse files Browse the repository at this point in the history
FIX: Properly recognize \"use strict\" when preceded by a string with an escaped newline.
  • Loading branch information
lgalfaso committed Mar 16, 2024
1 parent bd0aa5c commit 9a5ecbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion acorn/src/parseutil.js
Expand Up @@ -6,7 +6,7 @@ const pp = Parser.prototype

// ## Parser utilities

const literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/
const literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/s
pp.strictDirective = function(start) {
if (this.options.ecmaVersion < 5) return false
for (;;) {
Expand Down
6 changes: 6 additions & 0 deletions test/tests-directive.js
Expand Up @@ -2,6 +2,7 @@
if (typeof exports !== "undefined") {
var driver = require("./driver.js");
var test = driver.test;
var testFail = driver.testFail;
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -1384,3 +1385,8 @@ test("(a = () => { \"use strict\"; foo }) => { \"use strict\" }", {
}
]
}, { ecmaVersion: 6 })

testFail(
"function invalid() { \"\\7\\\n\"; \"use strict\"; }",
"Octal literal in strict mode (1:22)",
{ ecmaVersion: 6 })

0 comments on commit 9a5ecbc

Please sign in to comment.