fix: disallow \8, \9 in strict mode string (#11852)

This commit is contained in:
Huáng Jùnliàng
2020-07-21 09:44:56 -04:00
committed by GitHub
parent 3680f019d7
commit 2bf38fb914
18 changed files with 129 additions and 15 deletions

View File

@@ -139,6 +139,7 @@ export const ErrorMessages = Object.freeze({
StrictEvalArgumentsBinding: "Binding '%0' in strict mode",
StrictFunction:
"In strict mode code, functions can only be declared at top level or inside a block",
StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'",
StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode",
StrictWith: "'with' in strict mode",
SuperNotAllowed:

View File

@@ -1357,6 +1357,8 @@ export default class Tokenizer extends ParserErrors {
case charCodes.digit9:
if (inTemplate) {
return null;
} else if (this.state.strict) {
this.raise(this.state.pos - 1, Errors.StrictNumericEscape);
}
// fall through
default:
@@ -1385,7 +1387,7 @@ export default class Tokenizer extends ParserErrors {
if (inTemplate) {
return null;
} else if (this.state.strict) {
this.raise(codePos, Errors.StrictOctalLiteral);
this.raise(codePos, Errors.StrictNumericEscape);
} else {
// This property is used to throw an error for
// an octal literal in a directive that occurs prior