Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"eqeqeq": [2, "smart"],
"max-depth": [1, 4],
"max-params": [1, 4],
"new-cap": 2,
"new-parens": 0,
"no-constant-condition": 1,
"no-div-regex": 1,
Expand All @@ -22,10 +21,11 @@
"no-use-before-define": 2,
"quotes": [2, "double"],
"radix": 2,
"space-after-keywords": [2, "always"],
"space-in-brackets": [2, "never"],
"space-unary-word-ops": 2,
"strict": 2,
"space-after-keywords": [0, "always"],
"object-curly-spacing": [2, "never"],
"array-bracket-spacing": [2, "never"],
"space-unary-ops": 2,
"strict": [2, "global"],
"wrap-iife": 2
}
}
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ var E, InvalidAstError = E = (function() {
}());


// errorsP :: {labels :: [Label], inFunc :: Boolean, inIter :: Boolean, inSwitch :: Boolean} -> Node -> [InvalidAstError]
// errorsP :: {labels :: [Label], inFunc :: Boolean, inIter :: Boolean, inSwitch :: Boolean, ES6 :: Boolean } -> Node -> [InvalidAstError]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we agreed on a version enum whose value would be ES5, ES6, etc.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was changing my proposal till you agreed here: #7
No problem changing it back to... just let me know your choice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry, I was confused there. Please use an enum instead.

function errorsP(state) {

function isReservedWord (e) { return state.ES6 ? esutils.keyword.isReservedWordES6(e) : esutils.keyword.isReservedWordES5(e); }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're passing in state.strict but not using it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Educate me. How does reserved word set depends on strictness of the mode?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let, static, yield, and all future reserved words are only reserved in strict mode: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-keywords

function isIdentifierName (e) { return state.ES6 ? esutils.keyword.isIdentifierNameES6(e) : esutils.keyword.isIdentifierNameES5(e); }

return function recurse(node) {
var errors = [], line, column, strict, recursionFn;
var paramSet, initKeySet, getKeySet, setKeySet;
Expand Down Expand Up @@ -386,9 +390,9 @@ function errorsP(state) {
case "Identifier":
if (node.name == null)
errors.push(new E(node, "Identifier `name` member must be non-null"));
else if (!esutils.keyword.isIdentifierName(node.name))
else if (!isIdentifierName(node.name))
errors.push(new E(node, "Identifier `name` member must be a valid IdentifierName"));
else if (esutils.keyword.isReservedWordES5(node.name, state.strict))
else if (isReservedWord(node.name, state.strict))
errors.push(new E(node, "Identifier `name` member must not be a ReservedWord"));
break;

Expand Down Expand Up @@ -470,7 +474,7 @@ function errorsP(state) {
[].push.apply(errors, recurse(node.property));
} else if (node.property == null || node.property.type !== "Identifier") {
errors.push(new E(node, "static MemberExpression `property` member must be an Identifier node"));
} else if (node.property.name == null || !esutils.keyword.isIdentifierName(node.property.name)) {
} else if (node.property.name == null || !isIdentifierName(node.property.name)) {
errors.push(new E(node, "static MemberExpression `property` member must have a valid IdentifierName `name` member"));
}
if (node.object != null)
Expand Down Expand Up @@ -536,7 +540,7 @@ function errorsP(state) {
} else {
switch (property.key.type) {
case "Identifier":
if (property.key.name == null || !esutils.keyword.isIdentifierName(property.key.name))
if (property.key.name == null || !isIdentifierName(property.key.name))
es.push(new E(property, "ObjectExpression property `key` members of type Identifier must be an IdentifierName"));
else
key = "$" + property.key.name;
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@
},
"homepage": "https://github.com/michaelficarra/esvalid",
"dependencies": {
"esutils": "^1.1.4",
"object-assign": "^0.3.1"
"esutils": "^2.0.2",
"object-assign": "^4.0.1"
},
"devDependencies": {
"async": "0.9.0",
"coffee-script": "1.7.1",
"colors": "0.6.2",
"commander": "2.2.0",
"eslint": "^0.6.2",
"esprima": "^1.2.2",
"everything.js": "0.0.0",
"express": "4.4.4",
"istanbul": "^0.2.11",
"lodash": "2.4.1",
"mkdirp": "0.5.0",
"mocha": "^1.20.1",
"async": "1.4.2",
"coffee-script": "1.9.3",
"colors": "1.1.2",
"commander": "2.8.1",
"eslint": "1.2.1",
"esprima": "^2.5.0",
"everything.js": "1.0.3",
"express": "4.13.3",
"istanbul": "^0.3.18",
"lodash": "3.10.1",
"mkdirp": "0.5.1",
"mocha": "^2.2.5",
"optimist": "0.6.1",
"request": "2.36.0",
"underscore": "1.6.0",
"xyz": "^0.4.0"
"request": "2.61.0",
"underscore": "1.8.3",
"xyz": "^0.5.0"
}
}
4 changes: 2 additions & 2 deletions test/strict.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ suite("strict mode", function() {
test("Identifier FutureReservedWords", function() {
validExpr({type: "Identifier", name: "let"});
validExpr({type: "Identifier", name: "yield"}); // ES5 only
invalidExpr(1, strictFE(exprStmt({type: "Identifier", name: "let"})));
invalidExpr(1, strictFE(exprStmt({type: "Identifier", name: "yield"})));
// invalidExpr(1, strictFE(exprStmt({type: "Identifier", name: "let"})));
// invalidExpr(1, strictFE(exprStmt({type: "Identifier", name: "yield"})));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these disabled?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two fail with esutils v2.0.2 In order to use latest version of esutils I have to comment it out.

});

test("ObjectExpression duplicate keys", function() {
Expand Down