Replace the forbidReserved option with an allowReserved option

For consistency with similar options
This commit is contained in:
Marijn Haverbeke 2015-03-12 22:00:45 +01:00
parent ba750b253b
commit 4735ef53ef
3 changed files with 9 additions and 9 deletions

View File

@ -63,8 +63,8 @@ object referring to that same position.
- **onTrailingComma**: Like `onInsertedSemicolon`, but for trailing
commas.
- **forbidReserved**: If `true`, using a reserved word will generate
an error. Defaults to `false`. When given the value `"everywhere"`,
- **allowReserved**: If `false`, using a reserved word will generate
an error. Defaults to `true`. When given the value `"never"`,
reserved words and keywords can also not be used as property names
(as in Internet Explorer's old parser).

View File

@ -60,11 +60,11 @@
// `onTrailingComma` is similar to `onInsertedSemicolon`, but for
// trailing commas.
onTrailingComma: null,
// By default, reserved words are not enforced. Enable
// `forbidReserved` to enforce them. When this option has the
// value "everywhere", reserved words and keywords can also not be
// By default, reserved words are not enforced. Disable
// `allowReserved` to enforce them. When this option has the
// value "never", reserved words and keywords can also not be
// used as property names.
forbidReserved: false,
allowReserved: true,
// When enabled, a return at the top level is not considered an
// error.
allowReturnOutsideFunction: false,
@ -2700,10 +2700,10 @@
pp.parseIdent = function(liberal) {
var node = this.startNode();
if (liberal && this.options.forbidReserved == "everywhere") liberal = false;
if (liberal && this.options.allowReserved == "never") liberal = false;
if (this.type === tt.name) {
if (!liberal &&
(this.options.forbidReserved &&
(!this.options.allowReserved &&
(this.options.ecmaVersion === 3 ? isReservedWord3 : isReservedWord5)(this.value) ||
this.strict && isStrictReservedWord(this.value)) &&
this.input.slice(this.start, this.end).indexOf("\\") == -1)

View File

@ -13871,7 +13871,7 @@ testFail("function hello() {'use strict'; ({ i: 10, s(eval) { } }); }", "Definin
testFail("function a() { \"use strict\"; ({ b(t, t) { } }); }", "Argument name clash in strict mode (1:37)", {ecmaVersion: 6});
testFail("var super", "The keyword 'super' is reserved (1:4)", {ecmaVersion: 6, forbidReserved: true});
testFail("var super", "The keyword 'super' is reserved (1:4)", {ecmaVersion: 6, allowReserved: false});
testFail("var default", "Unexpected token (1:4)", {ecmaVersion: 6});