mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
esprima 4.0 with linting
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import esprima = require('esprima');
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
var token: esprima.Token;
|
||||
var comment: ESTree.Comment;
|
||||
var program: ESTree.Program;
|
||||
var string: string;
|
||||
let token: esprima.Token;
|
||||
let program: ESTree.Program;
|
||||
let string: string;
|
||||
|
||||
// esprima
|
||||
string = esprima.version;
|
||||
@@ -14,7 +13,8 @@ program = esprima.parseScript('answer = 42');
|
||||
program = esprima.parseModule('import { sqrt } from "math.js"');
|
||||
|
||||
// Parsing Options
|
||||
program = esprima.parseScript('var el= <title>${product}</title>', { jsx: true });
|
||||
const title = 'Hello World!';
|
||||
program = esprima.parseScript(`var el= <title>${title}</title>`, { jsx: true });
|
||||
program = esprima.parseScript('if (x) function y() {}');
|
||||
program = esprima.parseScript('"use strict"; with (x) {}', { tolerant: true });
|
||||
program = esprima.parseScript('answer = 42', { range: true });
|
||||
@@ -28,9 +28,8 @@ token = esprima.tokenize('code')[0];
|
||||
token = esprima.tokenize('code', {range: true})[0];
|
||||
|
||||
// Syntax Delegate
|
||||
esprima.parseScript('answer = 42', {}, function (node) {
|
||||
esprima.parseScript('answer = 42', {}, (node) => {
|
||||
if (node.type === esprima.Syntax.VariableDeclaration) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -38,11 +37,8 @@ esprima.parseScript('answer = 42', {}, function (node) {
|
||||
string = token.type;
|
||||
string = token.value;
|
||||
|
||||
// Comment
|
||||
string = comment.value;
|
||||
|
||||
// Type narrowing
|
||||
var node: ESTree.Node;
|
||||
if(node.type === esprima.Syntax.IfStatement){
|
||||
const node: ESTree.Node = program.body[0];
|
||||
if (node.type === esprima.Syntax.IfStatement) {
|
||||
node.consequent = node;
|
||||
}
|
||||
|
||||
194
types/esprima/index.d.ts
vendored
194
types/esprima/index.d.ts
vendored
@@ -1,110 +1,102 @@
|
||||
// Type definitions for Esprima v4.0.0
|
||||
// Type definitions for Esprima 4.0
|
||||
// Project: http://esprima.org
|
||||
// Definitions by: teppeis <https://github.com/teppeis>, RReverser <https://github.com/RReverser>, peter-scott <https://github.com/peter-scott>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="estree" />
|
||||
|
||||
export = esprima;
|
||||
export as namespace esprima;
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
declare namespace esprima {
|
||||
export const version: string;
|
||||
|
||||
const version: string;
|
||||
|
||||
function parseScript(input: string, config?: ParseOptions, delegate?: (node: ESTree.Node, meta: any) => void): ESTree.Program;
|
||||
function parseModule(input: string, config?: ParseOptions, delegate?: (node: ESTree.Node, meta: any) => void): ESTree.Program;
|
||||
function tokenize(input: string, config?: TokenizeOptions): Array<Token>;
|
||||
|
||||
interface Token {
|
||||
type: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface ParseOptions {
|
||||
jsx?: boolean,
|
||||
range?: boolean;
|
||||
loc?: boolean;
|
||||
tolerant?: boolean;
|
||||
tokens?: boolean;
|
||||
comment?: boolean;
|
||||
}
|
||||
|
||||
interface TokenizeOptions {
|
||||
range?: boolean;
|
||||
loc?: boolean;
|
||||
comment?: boolean;
|
||||
}
|
||||
|
||||
const Syntax: {
|
||||
ArrayExpression: 'ArrayExpression',
|
||||
ArrayPattern: 'ArrayPattern',
|
||||
ArrowFunctionExpression: 'ArrowFunctionExpression',
|
||||
AssignmentExpression: 'AssignmentExpression',
|
||||
AssignmentPattern: 'AssignmentPattern',
|
||||
AwaitExpression: 'AwaitExpression',
|
||||
BinaryExpression: 'BinaryExpression',
|
||||
BlockStatement: 'BlockStatement',
|
||||
BreakStatement: 'BreakStatement',
|
||||
CallExpression: 'CallExpression',
|
||||
CatchClause: 'CatchClause',
|
||||
ClassBody: 'ClassBody',
|
||||
ClassDeclaration: 'ClassDeclaration',
|
||||
ClassExpression: 'ClassExpression',
|
||||
ConditionalExpression: 'ConditionalExpression',
|
||||
ContinueStatement: 'ContinueStatement',
|
||||
DebuggerStatement: 'DebuggerStatement',
|
||||
DoWhileStatement: 'DoWhileStatement',
|
||||
EmptyStatement: 'EmptyStatement',
|
||||
ExportAllDeclaration: 'ExportAllDeclaration',
|
||||
ExportDefaultDeclaration: 'ExportDefaultDeclaration',
|
||||
ExportNamedDeclaration: 'ExportNamedDeclaration',
|
||||
ExportSpecifier: 'ExportSpecifier',
|
||||
ExpressionStatement: 'ExpressionStatement',
|
||||
ForInStatement: 'ForInStatement',
|
||||
ForOfStatement: 'ForOfStatement',
|
||||
ForStatement: 'ForStatement',
|
||||
FunctionDeclaration: 'FunctionDeclaration',
|
||||
FunctionExpression: 'FunctionExpression',
|
||||
Identifier: 'Identifier',
|
||||
IfStatement: 'IfStatement',
|
||||
Import: 'Import',
|
||||
ImportDeclaration: 'ImportDeclaration',
|
||||
ImportDefaultSpecifier: 'ImportDefaultSpecifier',
|
||||
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
|
||||
ImportSpecifier: 'ImportSpecifier',
|
||||
LabeledStatement: 'LabeledStatement',
|
||||
Literal: 'Literal',
|
||||
LogicalExpression: 'LogicalExpression',
|
||||
MemberExpression: 'MemberExpression',
|
||||
MetaProperty: 'MetaProperty',
|
||||
MethodDefinition: 'MethodDefinition',
|
||||
NewExpression: 'NewExpression',
|
||||
ObjectExpression: 'ObjectExpression',
|
||||
ObjectPattern: 'ObjectPattern',
|
||||
Program: 'Program',
|
||||
Property: 'Property',
|
||||
RestElement: 'RestElement',
|
||||
ReturnStatement: 'ReturnStatement',
|
||||
SequenceExpression: 'SequenceExpression',
|
||||
SpreadElement: 'SpreadElement',
|
||||
Super: 'Super',
|
||||
SwitchCase: 'SwitchCase',
|
||||
SwitchStatement: 'SwitchStatement',
|
||||
TaggedTemplateExpression: 'TaggedTemplateExpression',
|
||||
TemplateElement: 'TemplateElement',
|
||||
TemplateLiteral: 'TemplateLiteral',
|
||||
ThisExpression: 'ThisExpression',
|
||||
ThrowStatement: 'ThrowStatement',
|
||||
TryStatement: 'TryStatement',
|
||||
UnaryExpression: 'UnaryExpression',
|
||||
UpdateExpression: 'UpdateExpression',
|
||||
VariableDeclaration: 'VariableDeclaration',
|
||||
VariableDeclarator: 'VariableDeclarator',
|
||||
WhileStatement: 'WhileStatement',
|
||||
WithStatement: 'WithStatement',
|
||||
YieldExpression: 'YieldExpression'
|
||||
};
|
||||
export function parseScript(input: string, config?: ParseOptions, delegate?: (node: ESTree.Node, meta: any) => void): ESTree.Program;
|
||||
export function parseModule(input: string, config?: ParseOptions, delegate?: (node: ESTree.Node, meta: any) => void): ESTree.Program;
|
||||
export function tokenize(input: string, config?: TokenizeOptions): Token[];
|
||||
|
||||
export interface Token {
|
||||
type: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface ParseOptions {
|
||||
jsx?: boolean;
|
||||
range?: boolean;
|
||||
loc?: boolean;
|
||||
tolerant?: boolean;
|
||||
tokens?: boolean;
|
||||
comment?: boolean;
|
||||
}
|
||||
|
||||
export interface TokenizeOptions {
|
||||
range?: boolean;
|
||||
loc?: boolean;
|
||||
comment?: boolean;
|
||||
}
|
||||
|
||||
export const Syntax: {
|
||||
ArrayExpression: 'ArrayExpression',
|
||||
ArrayPattern: 'ArrayPattern',
|
||||
ArrowFunctionExpression: 'ArrowFunctionExpression',
|
||||
AssignmentExpression: 'AssignmentExpression',
|
||||
AssignmentPattern: 'AssignmentPattern',
|
||||
AwaitExpression: 'AwaitExpression',
|
||||
BinaryExpression: 'BinaryExpression',
|
||||
BlockStatement: 'BlockStatement',
|
||||
BreakStatement: 'BreakStatement',
|
||||
CallExpression: 'CallExpression',
|
||||
CatchClause: 'CatchClause',
|
||||
ClassBody: 'ClassBody',
|
||||
ClassDeclaration: 'ClassDeclaration',
|
||||
ClassExpression: 'ClassExpression',
|
||||
ConditionalExpression: 'ConditionalExpression',
|
||||
ContinueStatement: 'ContinueStatement',
|
||||
DebuggerStatement: 'DebuggerStatement',
|
||||
DoWhileStatement: 'DoWhileStatement',
|
||||
EmptyStatement: 'EmptyStatement',
|
||||
ExportAllDeclaration: 'ExportAllDeclaration',
|
||||
ExportDefaultDeclaration: 'ExportDefaultDeclaration',
|
||||
ExportNamedDeclaration: 'ExportNamedDeclaration',
|
||||
ExportSpecifier: 'ExportSpecifier',
|
||||
ExpressionStatement: 'ExpressionStatement',
|
||||
ForInStatement: 'ForInStatement',
|
||||
ForOfStatement: 'ForOfStatement',
|
||||
ForStatement: 'ForStatement',
|
||||
FunctionDeclaration: 'FunctionDeclaration',
|
||||
FunctionExpression: 'FunctionExpression',
|
||||
Identifier: 'Identifier',
|
||||
IfStatement: 'IfStatement',
|
||||
Import: 'Import',
|
||||
ImportDeclaration: 'ImportDeclaration',
|
||||
ImportDefaultSpecifier: 'ImportDefaultSpecifier',
|
||||
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
|
||||
ImportSpecifier: 'ImportSpecifier',
|
||||
LabeledStatement: 'LabeledStatement',
|
||||
Literal: 'Literal',
|
||||
LogicalExpression: 'LogicalExpression',
|
||||
MemberExpression: 'MemberExpression',
|
||||
MetaProperty: 'MetaProperty',
|
||||
MethodDefinition: 'MethodDefinition',
|
||||
NewExpression: 'NewExpression',
|
||||
ObjectExpression: 'ObjectExpression',
|
||||
ObjectPattern: 'ObjectPattern',
|
||||
Program: 'Program',
|
||||
Property: 'Property',
|
||||
RestElement: 'RestElement',
|
||||
ReturnStatement: 'ReturnStatement',
|
||||
SequenceExpression: 'SequenceExpression',
|
||||
SpreadElement: 'SpreadElement',
|
||||
Super: 'Super',
|
||||
SwitchCase: 'SwitchCase',
|
||||
SwitchStatement: 'SwitchStatement',
|
||||
TaggedTemplateExpression: 'TaggedTemplateExpression',
|
||||
TemplateElement: 'TemplateElement',
|
||||
TemplateLiteral: 'TemplateLiteral',
|
||||
ThisExpression: 'ThisExpression',
|
||||
ThrowStatement: 'ThrowStatement',
|
||||
TryStatement: 'TryStatement',
|
||||
UnaryExpression: 'UnaryExpression',
|
||||
UpdateExpression: 'UpdateExpression',
|
||||
VariableDeclaration: 'VariableDeclaration',
|
||||
VariableDeclarator: 'VariableDeclarator',
|
||||
WhileStatement: 'WhileStatement',
|
||||
WithStatement: 'WithStatement',
|
||||
YieldExpression: 'YieldExpression'
|
||||
};
|
||||
|
||||
3
types/esprima/tslint.json
Normal file
3
types/esprima/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user