Skip to content

Commit

Permalink
Add Esprima
Browse files Browse the repository at this point in the history
  • Loading branch information
teppeis committed May 1, 2014
1 parent b208dde commit 648511f
Show file tree
Hide file tree
Showing 3 changed files with 438 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ All definitions files include a header with the author and editors, so at some p
* [emissary](https://github.com/atom/emissary) (by [vvakame](https://github.com/vvakame))
* [EpicEditor](http://epiceditor.com/) (by [Boris Yankov](https://github.com/borisyankov))
* [ES6-Promises](https://github.com/jakearchibald/ES6-Promises) (by [François de Campredon](https://github.com/fdecampredon/))
* [Esprima](http://esprima.org/) (by [Teppei Sato](https://github.com/teppeis))
* [expect.js](https://github.com/LearnBoost/expect.js) (by [Teppei Sato](https://github.com/teppeis))
* [expectations](https://github.com/spmason/expectations) (by [vvakame](https://github.com/vvakame))
* [Express](http://expressjs.com/) (by [Boris Yankov](https://github.com/borisyankov))
Expand Down
163 changes: 163 additions & 0 deletions esprima/esprima-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/// <reference path="esprima.d.ts" />

import esprima = require('esprima');
import Syntax = esprima.Syntax;

var token: esprima.Token;
var options: esprima.Options;
var comment: Syntax.Comment;
var program: Syntax.Program;
var statement: Syntax.SomeStatement;
var blockStatement: Syntax.BlockStatement;
var expression: Syntax.SomeExpression;
var property: Syntax.Property;
var identifier: Syntax.Identifier;
var literal: Syntax.Literal;
var switchCase: Syntax.SwitchCase;
var catchClause: Syntax.CatchClause;
var variableDeclaratorOrExpression: Syntax.VariableDeclaratorOrExpression;
var literalOrIdentifier: Syntax.LiteralOrIdentifier;
var blockStatementOrExpression: Syntax.BlockStatementOrExpression;
var identifierOrExpression: Syntax.IdentifierOrExpression;
var any: any;
var string: string;
var boolean: boolean;
var number: number;

// esprima
string = esprima.version;
program = esprima.parse('code');
program = esprima.parse('code', {range: true});
token = esprima.tokenize('code')[0];
token = esprima.tokenize('code', {range: true})[0];

// Token
string = token.type;
string = token.value;

// Program
string = program.type;
statement = program.body[0];
comment = program.comments[0]

// Location
number = program.loc.start.line;
number = program.loc.start.column;
number = program.loc.end.line;
number = program.loc.end.column;
number = program.range[0];

// Comment
string = comment.value;

// Statement
// BlockStatement
string = statement.type;
statement = statement.body[0];
comment = statement.leadingComments[0]
comment = statement.trailingComments[0]

// ExpressionStatement
expression = statement.expression;

// IfStatement
expression = statement.test;
statement = statement.consequent;
statement = statement.alternate;

// LabeledStatement
identifier = statement.label;
statement = statement.body;

// WithStatement
expression = statement.object;

// SwitchStatement
expression = statement.discriminant;
switchCase = statement.cases[0];
boolean = statement.lexical;

// ReturnStatement
expression = statement.argument;

// TryStatement
blockStatement = statement.block;
catchClause = statement.handler;
catchClause = statement.guardedHandlers[0];
blockStatement = statement.finalizer;

// ForStatement
variableDeclaratorOrExpression = statement.init;
expression = statement.update;

// ForInStatement
variableDeclaratorOrExpression = statement.left;
expression = statement.right;
boolean = statement.each;

// Expression
// ArrayExpression
string = expression.type;
expression = expression.elements[0];

// ObjectExpression
property = expression.properties[0];
string = property.type;
literalOrIdentifier = property.key;
expression = property.value;
string = property.kind;

// FunctionExpression
identifier = expression.id;
identifier = expression.params[0];
expression = expression.defaults[0];
identifier = expression.rest;
blockStatementOrExpression = expression.body;
boolean = expression.generator;
boolean = expression.expression;

// SequenceExpression
expression = expression.expressions[0]

// UnaryExpression
string = expression.operator;
boolean = expression.prefix;

// BinaryExpression
expression = expression.left;
expression = expression.right;

// ConditionalExpression
expression = expression.test;
expression = expression.alternate;
expression = expression.consequent;

// ConditionalExpression
expression = expression.callee;
expression = expression.arguments[0];

// MemberExpression
expression = expression.object;
identifierOrExpression = expression.property;
boolean = expression.computed;

// Clauses
// SwitchCase
string = switchCase.type;
expression = switchCase.test;
statement = switchCase.consequent[0];

// CatchClause
string = catchClause.type;
identifier = catchClause.param;
expression = catchClause.guard;
blockStatement = catchClause.body;

// Misc
// Identifier
string = identifier.type;
string = identifier.name;

// Literal
string = literal.type;
any = literal.value;
Loading

0 comments on commit 648511f

Please sign in to comment.