New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: non-directive "use strict" should not enable parsing in strict mode #11188
Changes from all commits
706fe8a
7a1bd81
8aba2b4
6226960
98400fd
199c0a5
1415bf3
88121fc
840f5a7
596faff
d4d4727
5f43e0e
2aa10ae
a5ba60c
09b5f56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,11 @@ import { types as tt, type TokenType } from "../tokenizer/types"; | |
import Tokenizer from "../tokenizer"; | ||
import State from "../tokenizer/state"; | ||
import type { Node } from "../types"; | ||
import { lineBreak, skipWhiteSpace } from "../util/whitespace"; | ||
import { lineBreak } from "../util/whitespace"; | ||
import { isIdentifierChar } from "../util/identifier"; | ||
import * as charCodes from "charcodes"; | ||
import { Errors } from "./location"; | ||
|
||
const literal = /^('|")((?:\\?.)*?)\1/; | ||
|
||
type TryParse<Node, Error, Thrown, Aborted, FailState> = { | ||
node: Node, | ||
error: Error, | ||
|
@@ -193,29 +191,6 @@ export default class UtilParser extends Tokenizer { | |
} | ||
} | ||
|
||
strictDirective(start: number): boolean { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now dead code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
for (;;) { | ||
// Try to find string literal. | ||
skipWhiteSpace.lastIndex = start; | ||
// $FlowIgnore | ||
start += skipWhiteSpace.exec(this.input)[0].length; | ||
const match = literal.exec(this.input.slice(start)); | ||
if (!match) break; | ||
if (match[2] === "use strict") return true; | ||
start += match[0].length; | ||
|
||
// Skip semicolon, if any. | ||
skipWhiteSpace.lastIndex = start; | ||
// $FlowIgnore | ||
start += skipWhiteSpace.exec(this.input)[0].length; | ||
if (this.input[start] === ";") { | ||
start++; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
// tryParse will clone parser state. | ||
// It is expensive and should be used with cautions | ||
tryParse<T: Node | $ReadOnlyArray<Node>>( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,8 +224,7 @@ export default class Tokenizer extends LocationParser { | |
const curContext = this.curContext(); | ||
if (!curContext || !curContext.preserveSpace) this.skipSpace(); | ||
|
||
this.state.containsOctal = false; | ||
this.state.octalPosition = null; | ||
this.state.octalPositions = []; | ||
this.state.start = this.state.pos; | ||
this.state.startLoc = this.state.curPosition(); | ||
if (this.state.pos >= this.length) { | ||
|
@@ -1033,11 +1032,7 @@ export default class Tokenizer extends LocationParser { | |
this.input.charCodeAt(start) === charCodes.digit0; | ||
if (octal) { | ||
if (this.state.strict) { | ||
this.raise( | ||
start, | ||
// todo: merge with Errors.StrictOctalLiteral | ||
"Legacy octal literals are not allowed in strict mode", | ||
); | ||
this.raise(start, Errors.StrictOctalLiteral); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this change unifies the language for all the octal literal strict mode errors. |
||
} | ||
if (/[89]/.test(this.input.slice(start, this.state.pos))) { | ||
octal = false; | ||
|
@@ -1296,11 +1291,11 @@ export default class Tokenizer extends LocationParser { | |
return null; | ||
} else if (this.state.strict) { | ||
this.raise(codePos, Errors.StrictOctalLiteral); | ||
} else if (!this.state.containsOctal) { | ||
// These properties are only used to throw an error for an octal which occurs | ||
// in a directive which occurs prior to a "use strict" directive. | ||
this.state.containsOctal = true; | ||
this.state.octalPosition = codePos; | ||
} else { | ||
// This property is used to throw an error for | ||
// an octal literal in a directive that occurs prior | ||
// to a "use strict" directive. | ||
this.state.octalPositions.push(codePos); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted regexp -> Good news 😆