update Espree; handle new node types (#555)

This commit is contained in:
Jeff Williams 2015-03-16 09:29:54 -07:00
parent 0b41c89f83
commit 141499d3af
12 changed files with 1162 additions and 280 deletions

View File

@ -63,12 +63,14 @@ var parserOptions = exports.parserOptions = {
arrowFunctions: true,
binaryLiterals: true,
blockBindings: true,
classes: true,
defaultParams: true,
destructuring: true,
forOf: true,
generators: true,
globalReturn: true,
jsx: false,
modules: true,
objectLiteralComputedProperties: true,
objectLiteralDuplicateProperties: true,
objectLiteralShorthandMethods: true,

View File

@ -6,6 +6,7 @@ exports.Syntax = {
ArrayPattern: 'ArrayPattern',
ArrowFunctionExpression: 'ArrowFunctionExpression',
AssignmentExpression: 'AssignmentExpression',
AssignmentPattern: 'AssignmentPattern',
BinaryExpression: 'BinaryExpression',
BlockStatement: 'BlockStatement',
BreakStatement: 'BreakStatement',
@ -21,8 +22,9 @@ exports.Syntax = {
DebuggerStatement: 'DebuggerStatement',
DoWhileStatement: 'DoWhileStatement',
EmptyStatement: 'EmptyStatement',
ExportBatchSpecifier: 'ExportBatchSpecifier',
ExportDeclaration: 'ExportDeclaration',
ExportAllDeclaration: 'ExportAllDeclaration',
ExportDefaultDeclaration: 'ExportDefaultDeclaration',
ExportNamedDeclaration: 'ExportNamedDeclaration',
ExportSpecifier: 'ExportSpecifier',
ExpressionStatement: 'ExpressionStatement',
ForInStatement: 'ForInStatement',
@ -33,6 +35,8 @@ exports.Syntax = {
Identifier: 'Identifier',
IfStatement: 'IfStatement',
ImportDeclaration: 'ImportDeclaration',
ImportDefaultSpecifier: 'ImportDefaultSpecifier',
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
ImportSpecifier: 'ImportSpecifier',
LabeledStatement: 'LabeledStatement',
LetStatement: 'LetStatement', // TODO: update Rhino to use VariableDeclaration

View File

@ -515,10 +515,13 @@ Visitor.prototype.makeSymbolFoundEvent = function(node, parser, filename) {
case Syntax.ClassBody:
case Syntax.ClassDeclaration:
case Syntax.ClassExpression:
case Syntax.ExportBatchSpecifier:
case Syntax.ExportDeclaration:
case Syntax.ExportAllDeclaration:
case Syntax.ExportDefaultDeclaration:
case Syntax.ExportNamedDeclaration:
case Syntax.ExportSpecifier:
case Syntax.ImportDeclaration:
case Syntax.ImportDefaultSpecifier:
case Syntax.ImportNamespaceSpecifier:
case Syntax.ImportSpecifier:
case Syntax.MethodDefinition:
case Syntax.ModuleDeclaration:

View File

@ -93,6 +93,8 @@ walkers[Syntax.AssignmentExpression] = function(node, parent, state, cb) {
cb(node.right, node, state);
};
walkers[Syntax.AssignmentPattern] = walkers[Syntax.AssignmentExpression];
walkers[Syntax.BinaryExpression] = function(node, parent, state, cb) {
cb(node.left, node, state);
cb(node.right, node, state);
@ -171,22 +173,28 @@ walkers[Syntax.DoWhileStatement] = function(node, parent, state, cb) {
walkers[Syntax.EmptyStatement] = leafNode;
walkers[Syntax.ExportBatchSpecifier] = leafNode;
walkers[Syntax.ExportAllDeclaration] = function(node, parent, state, cb) {
if (node.source) {
cb(node.source, node, state);
}
};
walkers[Syntax.ExportDeclaration] = function(node, parent, state, cb) {
walkers[Syntax.ExportDefaultDeclaration] = function(node, parent, state, cb) {
if (node.declaration) {
cb(node.declaration, node, state);
}
};
walkers[Syntax.ExportNamedDeclaration] = function(node, parent, state, cb) {
var i;
var l;
if (node.declaration) {
for (i = 0, l = node.declaration.length; i < l; i++) {
cb(node.declaration[i], node, state);
}
cb(node.declaration, node, state);
}
if (node.specifiers) {
for (i = 0, l = node.specifiers.length; i < l; i++) {
cb(node.specifiers[i], node, state);
}
for (i = 0, l = node.specifiers.length; i < l; i++) {
cb(node.specifiers[i], node, state);
}
if (node.source) {
@ -195,12 +203,12 @@ walkers[Syntax.ExportDeclaration] = function(node, parent, state, cb) {
};
walkers[Syntax.ExportSpecifier] = function(node, parent, state, cb) {
if (node.id) {
cb(node.id, node, state);
if (node.exported) {
cb(node.exported, node, state);
}
if (node.name) {
cb(node.name, node, state);
if (node.local) {
cb(node.local, node, state);
}
};
@ -261,6 +269,14 @@ walkers[Syntax.ImportDeclaration] = function(node, parent, state, cb) {
}
};
walkers[Syntax.ImportDefaultSpecifier] = function(node, parent, state, cb) {
if (node.local) {
cb(node.local, node, state);
}
};
walkers[Syntax.ImportNamespaceSpecifier] = walkers[Syntax.ImportDefaultSpecifier];
walkers[Syntax.ImportSpecifier] = walkers[Syntax.ExportSpecifier];
walkers[Syntax.LabeledStatement] = function(node, parent, state, cb) {

1045
node_modules/espree/espree.js generated vendored

File diff suppressed because it is too large Load Diff

View File

@ -161,6 +161,47 @@ module.exports = {
};
},
/**
* Creates an ASTNode representation of a class body.
* @param {ASTNode} body The node representing the body of the class.
* @returns {ASTNode} An ASTNode representing the class body.
*/
createClassBody: function (body) {
return {
type: astNodeTypes.ClassBody,
body: body
};
},
createClassExpression: function (id, superClass, body) {
return {
type: astNodeTypes.ClassExpression,
id: id,
superClass: superClass,
body: body
};
},
createClassDeclaration: function (id, superClass, body) {
return {
type: astNodeTypes.ClassDeclaration,
id: id,
superClass: superClass,
body: body
};
},
createMethodDefinition: function (propertyType, kind, key, value, computed) {
return {
type: astNodeTypes.MethodDefinition,
key: key,
value: value,
kind: kind,
"static": propertyType === "static",
computed: computed
};
},
/**
* Create an ASTNode representation of a conditional expression
* @param {ASTNode} test The conditional to evaluate
@ -317,7 +358,7 @@ module.exports = {
return {
type: astNodeTypes.FunctionDeclaration,
id: id,
params: params,
params: params || [],
defaults: defaults || [],
body: body,
rest: rest || null,
@ -341,7 +382,7 @@ module.exports = {
return {
type: astNodeTypes.FunctionExpression,
id: id,
params: params,
params: params || [],
defaults: defaults || [],
body: body,
rest: rest || null,
@ -531,12 +572,14 @@ module.exports = {
/**
* Create an ASTNode representation of an entire program
* @param {ASTNode} body The program body
* @param {string} sourceType Either "module" or "script".
* @returns {ASTNode} An ASTNode representing an entire program
*/
createProgram: function (body) {
createProgram: function (body, sourceType) {
return {
type: astNodeTypes.Program,
body: body
body: body,
sourceType: sourceType
};
},
@ -639,17 +682,17 @@ module.exports = {
/**
* Create an ASTNode representation of a try statement
* @param {ASTNode} block The try block
* @param {ASTNode} guardedHandlers Any guarded catch handlers
* @param {ASTNode} handlers Any catch handlers
* @param {ASTNode} handler A catch handler
* @param {?ASTNode} finalizer The final code block to run after the try/catch has run
* @returns {ASTNode} An ASTNode representing a try statement
*/
createTryStatement: function (block, guardedHandlers, handlers, finalizer) {
createTryStatement: function (block, handler, finalizer) {
return {
type: astNodeTypes.TryStatement,
block: block,
guardedHandlers: guardedHandlers,
handlers: handlers,
guardedHandlers: [],
handlers: handler ? [ handler ] : [],
handler: handler,
finalizer: finalizer
};
},
@ -801,6 +844,67 @@ module.exports = {
type: astNodeTypes.JSXClosingElement,
name: name
};
},
createExportSpecifier: function (local, exported) {
return {
type: astNodeTypes.ExportSpecifier,
exported: exported || local,
local: local
};
},
createImportDefaultSpecifier: function (local) {
return {
type: astNodeTypes.ImportDefaultSpecifier,
local: local
};
},
createImportNamespaceSpecifier: function (local) {
return {
type: astNodeTypes.ImportNamespaceSpecifier,
local: local
};
},
createExportNamedDeclaration: function (declaration, specifiers, source) {
return {
type: astNodeTypes.ExportNamedDeclaration,
declaration: declaration,
specifiers: specifiers,
source: source
};
},
createExportDefaultDeclaration: function (declaration) {
return {
type: astNodeTypes.ExportDefaultDeclaration,
declaration: declaration
};
},
createExportAllDeclaration: function (source) {
return {
type: astNodeTypes.ExportAllDeclaration,
source: source
};
},
createImportSpecifier: function (local, imported) {
return {
type: astNodeTypes.ImportSpecifier,
local: local || imported,
imported: imported
};
},
createImportDeclaration: function (specifiers, source) {
return {
type: astNodeTypes.ImportDeclaration,
specifiers: specifiers,
source: source
};
}
};

View File

@ -39,6 +39,7 @@
module.exports = {
AssignmentExpression: "AssignmentExpression",
AssignmentPattern: "AssignmentPattern",
ArrayExpression: "ArrayExpression",
ArrayPattern: "ArrayPattern",
ArrowFunctionExpression: "ArrowFunctionExpression",
@ -47,6 +48,9 @@ module.exports = {
BreakStatement: "BreakStatement",
CallExpression: "CallExpression",
CatchClause: "CatchClause",
ClassBody: "ClassBody",
ClassDeclaration: "ClassDeclaration",
ClassExpression: "ClassExpression",
ConditionalExpression: "ConditionalExpression",
ContinueStatement: "ContinueStatement",
DoWhileStatement: "DoWhileStatement",
@ -64,6 +68,7 @@ module.exports = {
LabeledStatement: "LabeledStatement",
LogicalExpression: "LogicalExpression",
MemberExpression: "MemberExpression",
MethodDefinition: "MethodDefinition",
NewExpression: "NewExpression",
ObjectExpression: "ObjectExpression",
ObjectPattern: "ObjectPattern",
@ -97,5 +102,13 @@ module.exports = {
JSXOpeningElement: "JSXOpeningElement",
JSXAttribute: "JSXAttribute",
JSXSpreadAttribute: "JSXSpreadAttribute",
JSXText: "JSXText"
JSXText: "JSXText",
ExportDefaultDeclaration: "ExportDefaultDeclaration",
ExportNamedDeclaration: "ExportNamedDeclaration",
ExportAllDeclaration: "ExportAllDeclaration",
ExportSpecifier: "ExportSpecifier",
ImportDeclaration: "ImportDeclaration",
ImportSpecifier: "ImportSpecifier",
ImportDefaultSpecifier: "ImportDefaultSpecifier",
ImportNamespaceSpecifier: "ImportNamespaceSpecifier"
};

171
node_modules/espree/lib/comment-attachment.js generated vendored Normal file
View File

@ -0,0 +1,171 @@
/**
* @fileoverview Attaches comments to the AST.
* @author Nicholas C. Zakas
* @copyright 2015 Nicholas C. Zakas. All rights reserved.
* @copyright 2011-2013 Ariya Hidayat <ariya.hidayat@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var astNodeTypes = require("./ast-node-types");
//------------------------------------------------------------------------------
// Private
//------------------------------------------------------------------------------
var extra = {
trailingComments: [],
leadingComments: [],
bottomRightStack: []
};
//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------
module.exports = {
reset: function() {
extra.trailingComments = [];
extra.leadingComments = [];
extra.bottomRightStack = [];
},
addComment: function(comment) {
extra.trailingComments.push(comment);
extra.leadingComments.push(comment);
},
processComment: function(node) {
var lastChild,
trailingComments,
i;
if (node.type === astNodeTypes.Program) {
if (node.body.length > 0) {
return;
}
}
if (extra.trailingComments.length > 0) {
/*
* If the first comment in trailingComments comes after the
* current node, then we're good - all comments in the array will
* come after the node and so it's safe to add then as official
* trailingComments.
*/
if (extra.trailingComments[0].range[0] >= node.range[1]) {
trailingComments = extra.trailingComments;
extra.trailingComments = [];
} else {
/*
* Otherwise, if the first comment doesn't come after the
* current node, that means we have a mix of leading and trailing
* comments in the array and that leadingComments contains the
* same items as trailingComments. Reset trailingComments to
* zero items and we'll handle this by evaluating leadingComments
* later.
*/
extra.trailingComments.length = 0;
}
} else {
if (extra.bottomRightStack.length > 0 &&
extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments &&
extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments[0].range[0] >= node.range[1]) {
trailingComments = extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments;
delete extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments;
}
}
// Eating the stack.
while (extra.bottomRightStack.length > 0 && extra.bottomRightStack[extra.bottomRightStack.length - 1].range[0] >= node.range[0]) {
lastChild = extra.bottomRightStack.pop();
}
if (lastChild) {
if (lastChild.leadingComments && lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= node.range[0]) {
node.leadingComments = lastChild.leadingComments;
delete lastChild.leadingComments;
}
} else if (extra.leadingComments.length > 0) {
if (extra.leadingComments[extra.leadingComments.length - 1].range[1] <= node.range[0]) {
node.leadingComments = extra.leadingComments;
extra.leadingComments = [];
} else {
// https://github.com/eslint/espree/issues/2
/*
* In special cases, such as return (without a value) and
* debugger, all comments will end up as leadingComments and
* will otherwise be eliminated. This extra step runs when the
* bottomRightStack is empty and there are comments left
* in leadingComments.
*
* This loop figures out the stopping point between the actual
* leading and trailing comments by finding the location of the
* first comment that comes after the given node.
*/
for (i = 0; i < extra.leadingComments.length; i++) {
if (extra.leadingComments[i].range[1] > node.range[0]) {
break;
}
}
/*
* Split the array based on the location of the first comment
* that comes after the node. Keep in mind that this could
* result in an empty array, and if so, the array must be
* deleted.
*/
node.leadingComments = extra.leadingComments.slice(0, i);
if (node.leadingComments.length === 0) {
delete node.leadingComments;
}
/*
* Similarly, trailing comments are attached later. The variable
* must be reset to null if there are no trailing comments.
*/
trailingComments = extra.leadingComments.slice(i);
if (trailingComments.length === 0) {
trailingComments = null;
}
}
}
if (trailingComments) {
node.trailingComments = trailingComments;
}
extra.bottomRightStack.push(node);
}
};

View File

@ -97,6 +97,12 @@ module.exports = {
// enable super in functions
superInFunctions: false,
// enable parsing of classes
classes: false,
// enable parsing of modules
modules: false,
// React JSX parsing
jsx: false,

10
node_modules/espree/lib/messages.js generated vendored
View File

@ -78,6 +78,9 @@ module.exports = {
StrictDelete: "Delete of an unqualified identifier in strict mode.",
StrictDuplicateProperty: "Duplicate data property in object literal not allowed in strict mode",
DuplicatePrototypeProperty: "Duplicate '__proto__' property in object literal are not allowed",
ConstructorSpecialMethod: "Class constructor may not be an accessor",
DuplicateConstructor: "A class may only have one constructor",
StaticPrototype: "Classes may not have static property named prototype",
AccessorDataProperty: "Object literal may not have data and accessor property with the same name",
AccessorGetSet: "Object literal may not have multiple get/set accessors with the same name",
StrictLHSAssignment: "Assignment to eval or arguments is not allowed in strict mode",
@ -86,5 +89,10 @@ module.exports = {
StrictReservedWord: "Use of future reserved word in strict mode",
InvalidJSXAttributeValue: "JSX value should be either an expression or a quoted JSX text",
ExpectedJSXClosingTag: "Expected corresponding JSX closing tag for %0",
AdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag"
AdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag",
MissingFromClause: "Missing from clause",
NoAsAfterImportNamespace: "Missing as after import *",
InvalidModuleSpecifier: "Invalid module specifier",
IllegalImportDeclaration: "Illegal import declaration",
IllegalExportDeclaration: "Illegal export declaration"
};

12
node_modules/espree/package.json generated vendored

File diff suppressed because one or more lines are too long

View File

@ -17,7 +17,7 @@
"bluebird": "~2.9.14",
"catharsis": "~0.8.6",
"escape-string-regexp": "~1.0.2",
"espree": "~1.9.1",
"espree": "~1.12.0",
"js2xmlparser": "~0.1.7",
"marked": "~0.3.2",
"requizzle": "~0.2.0",