Skip to content

Commit 9a5ecbc

Browse files
authored
Properly handle line breaks when looking for directives (#1283)
FIX: Properly recognize \"use strict\" when preceded by a string with an escaped newline.
1 parent bd0aa5c commit 9a5ecbc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

acorn/src/parseutil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const pp = Parser.prototype
66

77
// ## Parser utilities
88

9-
const literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/
9+
const literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/s
1010
pp.strictDirective = function(start) {
1111
if (this.options.ecmaVersion < 5) return false
1212
for (;;) {

test/tests-directive.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
if (typeof exports !== "undefined") {
33
var driver = require("./driver.js");
44
var test = driver.test;
5+
var testFail = driver.testFail;
56
}
67

78
//------------------------------------------------------------------------
@@ -1384,3 +1385,8 @@ test("(a = () => { \"use strict\"; foo }) => { \"use strict\" }", {
13841385
}
13851386
]
13861387
}, { ecmaVersion: 6 })
1388+
1389+
testFail(
1390+
"function invalid() { \"\\7\\\n\"; \"use strict\"; }",
1391+
"Octal literal in strict mode (1:22)",
1392+
{ ecmaVersion: 6 })

0 commit comments

Comments
 (0)