Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Fix behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Oct 25, 2016
1 parent 1fa06f6 commit b6892dc
Show file tree
Hide file tree
Showing 63 changed files with 1,010 additions and 512 deletions.
42 changes: 31 additions & 11 deletions src/parser/expression.js
Expand Up @@ -804,7 +804,21 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,
}

if (this.eat(tt.colon)) {
prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos);
if (isPattern) {
prop.value = this.parseMaybeDefault(this.state.start, this.state.startLoc);
if (prop.value.type === "Identifier") {
let name = prop.value.name;
if (this.isReservedWord(name)) {
this.raise(prop.value.start, "Binding reserved word " + name);
}

if (this.state.strict && (reservedWords.strictBind(name) || reservedWords.strict(name))) {
this.raise(prop.value.start, "Binding " + name + " in strict mode");
}
}
} else {
prop.value = this.parseMaybeAssign(false, refShorthandDefaultPos);
}
return this.finishNode(prop, "ObjectProperty");
}

Expand All @@ -827,13 +841,19 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,

if (!prop.computed && prop.key.type === "Identifier") {
if (isPattern) {
let illegalBinding = this.isKeyword(prop.key.name);
if (!illegalBinding && this.state.strict) {
illegalBinding = reservedWords.strictBind(prop.key.name) || reservedWords.strict(prop.key.name);
let name = prop.key.name;
if (this.isKeyword(name)) {
this.raise(prop.key.start, "Binding keyword " + name);
}

if (this.isReservedWord(name)) {
this.raise(prop.key.start, "Binding reserved word " + name);
}
if (illegalBinding) {
this.raise(prop.key.start, "Binding " + prop.key.name);

if (this.state.strict && (reservedWords.strictBind(name) || reservedWords.strict(name))) {
this.raise(prop.key.start, "Binding " + name + " in strict mode");
}

prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone());
} else if (this.match(tt.eq) && refShorthandDefaultPos) {
if (!refShorthandDefaultPos.start) {
Expand All @@ -843,6 +863,7 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,
} else {
prop.value = prop.key.__clone();
}

prop.shorthand = true;
return this.finishNode(prop, "ObjectProperty");
}
Expand Down Expand Up @@ -999,13 +1020,12 @@ pp.parseIdentifier = function (liberal) {

if (this.match(tt.name)) {
if (!liberal) {
if (this.state.strict && reservedWords.strict(this.state.value)) {
this.raise(this.state.start, "The keyword '" + this.state.value + "' is reserved");
if (this.isReservedWord(this.state.value)) {
this.raise(this.state.start, this.state.value + " is a reserved word");
}

if (this.inModule && reservedWords[6](this.state.value)) {
this.raise(this.state.start, "The keyword '" + this.state.value +
"' is reserved when source type is module");
if (this.state.strict && reservedWords.strict(this.state.value)) {
this.raise(this.state.start, "The keyword '" + this.state.value + "' is reserved");
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/parser/index.js
Expand Up @@ -11,7 +11,6 @@ export default class Parser extends Tokenizer {

this.options = options;
this.inModule = this.options.sourceType === "module";
this.isReservedWord = reservedWords[6];
this.input = input;
this.plugins = this.loadPlugins(this.options.plugins);
this.filename = options.sourceFilename;
Expand All @@ -22,6 +21,14 @@ export default class Parser extends Tokenizer {
}
}

isReservedWord(word: string): boolean {
if (word === "await") {
return this.inModule;
} else {
return reservedWords[6](word);
}
}

hasPlugin(name: string): boolean {
return !!(this.plugins["*"] || this.plugins[name]);
}
Expand Down
9 changes: 5 additions & 4 deletions src/parser/lval.js
Expand Up @@ -205,12 +205,13 @@ pp.checkLVal = function (expr, isBinding, checkClashes, contextDescription) {
switch (expr.type) {
case "Identifier":
let errBegin = isBinding ? "Binding " : "Assigning to ";
if (this.state.strict && (reservedWords.strictBind(expr.name) || reservedWords.strict(expr.name))) {
this.raise(expr.start, errBegin + expr.name + " in strict mode");

if (this.isReservedWord(expr.name)) {
this.raise(expr.start, errBegin + "reserved word " + expr.name);
}

if (this.inModule && reservedWords[6](expr.name)) {
this.raise(expr.start, errBegin + expr.name + " is invalid when source type is module");
if (this.state.strict && (reservedWords.strictBind(expr.name) || reservedWords.strict(expr.name))) {
this.raise(expr.start, errBegin + expr.name + " in strict mode");
}

if (checkClashes) {
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/core/uncategorised/544/actual.js
@@ -0,0 +1,2 @@
"use strict";
const { public } = foo();
3 changes: 3 additions & 0 deletions test/fixtures/core/uncategorised/544/options.json
@@ -0,0 +1,3 @@
{
"throws": "Binding public in strict mode (2:8)"
}
1 change: 1 addition & 0 deletions test/fixtures/core/uncategorised/545/actual.js
@@ -0,0 +1 @@
const { public } = foo();
4 changes: 4 additions & 0 deletions test/fixtures/core/uncategorised/545/options.json
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "Binding public in strict mode (1:8)"
}
1 change: 1 addition & 0 deletions test/fixtures/core/uncategorised/546/actual.js
@@ -0,0 +1 @@
const { public } = foo();
@@ -1,89 +1,89 @@
{
"type": "File",
"start": 0,
"end": 23,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
"column": 25
}
},
"program": {
"type": "Program",
"start": 0,
"end": 23,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
"column": 25
}
},
"sourceType": "script",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 23,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
"column": 25
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 6,
"end": 22,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 22
"column": 24
}
},
"id": {
"type": "ObjectPattern",
"start": 6,
"end": 14,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 14
"column": 16
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 8,
"end": 12,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 12
"column": 14
}
},
"method": false,
Expand All @@ -92,36 +92,36 @@
"key": {
"type": "Identifier",
"start": 8,
"end": 12,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 12
"column": 14
},
"identifierName": "enum"
"identifierName": "public"
},
"name": "enum"
"name": "public"
},
"value": {
"type": "Identifier",
"start": 8,
"end": 12,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 12
"column": 14
},
"identifierName": "enum"
"identifierName": "public"
},
"name": "enum"
"name": "public"
},
"extra": {
"shorthand": true
Expand All @@ -131,30 +131,30 @@
},
"init": {
"type": "CallExpression",
"start": 17,
"end": 22,
"start": 19,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 17
"column": 19
},
"end": {
"line": 1,
"column": 22
"column": 24
}
},
"callee": {
"type": "Identifier",
"start": 17,
"end": 20,
"start": 19,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 17
"column": 19
},
"end": {
"line": 1,
"column": 20
"column": 22
},
"identifierName": "foo"
},
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/core/uncategorised/546/options.json
@@ -0,0 +1,3 @@
{
"sourceType": "script"
}
@@ -1,3 +1,3 @@
{
"throws": "Binding this (1:6)"
"throws": "Binding keyword this (1:6)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/357/options.json
@@ -1,4 +1,4 @@
{
"sourceType": "module",
"throws": "The keyword 'await' is reserved when source type is module (1:0)"
"throws": "await is a reserved word (1:0)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/359/options.json
@@ -1,4 +1,4 @@
{
"sourceType": "module",
"throws": "Binding await is invalid when source type is module (1:6)"
"throws": "Binding reserved word await (1:6)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/361/options.json
@@ -1,4 +1,4 @@
{
"sourceType": "module",
"throws": "Binding await is invalid when source type is module (1:8)"
"throws": "Binding reserved word await (1:8)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/363/options.json
@@ -1,4 +1,4 @@
{
"sourceType": "module",
"throws": "Binding await is invalid when source type is module (1:15)"
"throws": "Binding reserved word await (1:15)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/365/options.json
@@ -1,4 +1,4 @@
{
"sourceType": "module",
"throws": "The keyword 'await' is reserved when source type is module (1:9)"
"throws": "await is a reserved word (1:9)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/367/options.json
@@ -1,4 +1,4 @@
{
"sourceType": "module",
"throws": "The keyword 'await' is reserved when source type is module (1:6)"
"throws": "await is a reserved word (1:6)"
}

0 comments on commit b6892dc

Please sign in to comment.