mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 13:27:15 +08:00
Merge pull request #19270 from peter-scott/master
ESPrima - Update to version 4.0
This commit is contained in:
@@ -1,28 +1,44 @@
|
||||
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;
|
||||
program = esprima.parse('code');
|
||||
program = esprima.parse('code', {range: true});
|
||||
program = esprima.parse('import * as code from "code"', {sourceType: 'module'})
|
||||
|
||||
// Parse Module & Parse Script
|
||||
program = esprima.parseScript('answer = 42');
|
||||
program = esprima.parseModule('import { sqrt } from "math.js"');
|
||||
|
||||
// Parsing Options
|
||||
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 });
|
||||
program = esprima.parseScript('answer = 42', { range: true });
|
||||
program = esprima.parseScript('const answer = 42', { tokens: true });
|
||||
program = esprima.parseScript('answer = 42 // TODO: why', { comment: true });
|
||||
program = esprima.parseScript('answer = 42 // TODO: why', { comment: true, range: true });
|
||||
|
||||
// Tokenizing
|
||||
token = esprima.tokenize('code')[0];
|
||||
token = esprima.tokenize('code', {range: true})[0];
|
||||
|
||||
// Syntax Delegate
|
||||
esprima.parseScript('answer = 42', {}, (node) => {
|
||||
if (node.type === esprima.Syntax.VariableDeclaration) {
|
||||
}
|
||||
});
|
||||
|
||||
// Token
|
||||
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;
|
||||
}
|
||||
|
||||
190
types/esprima/index.d.ts
vendored
190
types/esprima/index.d.ts
vendored
@@ -1,104 +1,102 @@
|
||||
// Type definitions for Esprima v2.1.0
|
||||
// Type definitions for Esprima 4.0
|
||||
// Project: http://esprima.org
|
||||
// Definitions by: teppeis <https://github.com/teppeis>, RReverser <https://github.com/RReverser>
|
||||
// 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 parse(code: string, options?: Options, delegate?: (node: ESTree.Node, meta: any) => void): ESTree.Program;
|
||||
function tokenize(code: string, options?: Options): Array<Token>;
|
||||
|
||||
interface Token {
|
||||
type: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
loc?: boolean;
|
||||
range?: boolean;
|
||||
raw?: boolean;
|
||||
tokens?: boolean;
|
||||
comment?: boolean;
|
||||
attachComment?: boolean;
|
||||
tolerant?: boolean;
|
||||
source?: boolean;
|
||||
sourceType?: 'script' | 'module';
|
||||
}
|
||||
|
||||
const Syntax: {
|
||||
AssignmentExpression: 'AssignmentExpression',
|
||||
AssignmentPattern: 'AssignmentPattern',
|
||||
ArrayExpression: 'ArrayExpression',
|
||||
ArrayPattern: 'ArrayPattern',
|
||||
ArrowFunctionExpression: 'ArrowFunctionExpression',
|
||||
BlockStatement: 'BlockStatement',
|
||||
BinaryExpression: 'BinaryExpression',
|
||||
BreakStatement: 'BreakStatement',
|
||||
CallExpression: 'CallExpression',
|
||||
CatchClause: 'CatchClause',
|
||||
ClassBody: 'ClassBody',
|
||||
ClassDeclaration: 'ClassDeclaration',
|
||||
ClassExpression: 'ClassExpression',
|
||||
ConditionalExpression: 'ConditionalExpression',
|
||||
ContinueStatement: 'ContinueStatement',
|
||||
DoWhileStatement: 'DoWhileStatement',
|
||||
DebuggerStatement: 'DebuggerStatement',
|
||||
EmptyStatement: 'EmptyStatement',
|
||||
ExportAllDeclaration: 'ExportAllDeclaration',
|
||||
ExportDefaultDeclaration: 'ExportDefaultDeclaration',
|
||||
ExportNamedDeclaration: 'ExportNamedDeclaration',
|
||||
ExportSpecifier: 'ExportSpecifier',
|
||||
ExpressionStatement: 'ExpressionStatement',
|
||||
ForStatement: 'ForStatement',
|
||||
ForOfStatement: 'ForOfStatement',
|
||||
ForInStatement: 'ForInStatement',
|
||||
FunctionDeclaration: 'FunctionDeclaration',
|
||||
FunctionExpression: 'FunctionExpression',
|
||||
Identifier: 'Identifier',
|
||||
IfStatement: 'IfStatement',
|
||||
ImportDeclaration: 'ImportDeclaration',
|
||||
ImportDefaultSpecifier: 'ImportDefaultSpecifier',
|
||||
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
|
||||
ImportSpecifier: 'ImportSpecifier',
|
||||
Literal: 'Literal',
|
||||
LabeledStatement: 'LabeledStatement',
|
||||
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'
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
|
||||
3
types/esprima/tslint.json
Normal file
3
types/esprima/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
28
types/esprima/v2/esprima-tests.ts
Normal file
28
types/esprima/v2/esprima-tests.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import esprima = require('esprima');
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
var token: esprima.Token;
|
||||
var comment: ESTree.Comment;
|
||||
var program: ESTree.Program;
|
||||
var string: string;
|
||||
|
||||
// esprima
|
||||
string = esprima.version;
|
||||
program = esprima.parse('code');
|
||||
program = esprima.parse('code', {range: true});
|
||||
program = esprima.parse('import * as code from "code"', {sourceType: 'module'})
|
||||
token = esprima.tokenize('code')[0];
|
||||
token = esprima.tokenize('code', {range: true})[0];
|
||||
|
||||
// Token
|
||||
string = token.type;
|
||||
string = token.value;
|
||||
|
||||
// Comment
|
||||
string = comment.value;
|
||||
|
||||
// Type narrowing
|
||||
var node: ESTree.Node;
|
||||
if(node.type === esprima.Syntax.IfStatement){
|
||||
node.consequent = node;
|
||||
}
|
||||
104
types/esprima/v2/index.d.ts
vendored
Normal file
104
types/esprima/v2/index.d.ts
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
// Type definitions for Esprima v2.1.0
|
||||
// Project: http://esprima.org
|
||||
// Definitions by: teppeis <https://github.com/teppeis>, RReverser <https://github.com/RReverser>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="estree" />
|
||||
|
||||
export = esprima;
|
||||
export as namespace esprima;
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
declare namespace esprima {
|
||||
|
||||
const version: string;
|
||||
|
||||
function parse(code: string, options?: Options, delegate?: (node: ESTree.Node, meta: any) => void): ESTree.Program;
|
||||
function tokenize(code: string, options?: Options): Array<Token>;
|
||||
|
||||
interface Token {
|
||||
type: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
loc?: boolean;
|
||||
range?: boolean;
|
||||
raw?: boolean;
|
||||
tokens?: boolean;
|
||||
comment?: boolean;
|
||||
attachComment?: boolean;
|
||||
tolerant?: boolean;
|
||||
source?: boolean;
|
||||
sourceType?: 'script' | 'module';
|
||||
}
|
||||
|
||||
const Syntax: {
|
||||
AssignmentExpression: 'AssignmentExpression',
|
||||
AssignmentPattern: 'AssignmentPattern',
|
||||
ArrayExpression: 'ArrayExpression',
|
||||
ArrayPattern: 'ArrayPattern',
|
||||
ArrowFunctionExpression: 'ArrowFunctionExpression',
|
||||
BlockStatement: 'BlockStatement',
|
||||
BinaryExpression: 'BinaryExpression',
|
||||
BreakStatement: 'BreakStatement',
|
||||
CallExpression: 'CallExpression',
|
||||
CatchClause: 'CatchClause',
|
||||
ClassBody: 'ClassBody',
|
||||
ClassDeclaration: 'ClassDeclaration',
|
||||
ClassExpression: 'ClassExpression',
|
||||
ConditionalExpression: 'ConditionalExpression',
|
||||
ContinueStatement: 'ContinueStatement',
|
||||
DoWhileStatement: 'DoWhileStatement',
|
||||
DebuggerStatement: 'DebuggerStatement',
|
||||
EmptyStatement: 'EmptyStatement',
|
||||
ExportAllDeclaration: 'ExportAllDeclaration',
|
||||
ExportDefaultDeclaration: 'ExportDefaultDeclaration',
|
||||
ExportNamedDeclaration: 'ExportNamedDeclaration',
|
||||
ExportSpecifier: 'ExportSpecifier',
|
||||
ExpressionStatement: 'ExpressionStatement',
|
||||
ForStatement: 'ForStatement',
|
||||
ForOfStatement: 'ForOfStatement',
|
||||
ForInStatement: 'ForInStatement',
|
||||
FunctionDeclaration: 'FunctionDeclaration',
|
||||
FunctionExpression: 'FunctionExpression',
|
||||
Identifier: 'Identifier',
|
||||
IfStatement: 'IfStatement',
|
||||
ImportDeclaration: 'ImportDeclaration',
|
||||
ImportDefaultSpecifier: 'ImportDefaultSpecifier',
|
||||
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
|
||||
ImportSpecifier: 'ImportSpecifier',
|
||||
Literal: 'Literal',
|
||||
LabeledStatement: 'LabeledStatement',
|
||||
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'
|
||||
};
|
||||
|
||||
}
|
||||
27
types/esprima/v2/tsconfig.json
Normal file
27
types/esprima/v2/tsconfig.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"esprima": [
|
||||
"esprima/v2"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"esprima-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import evaluate = require('static-eval');
|
||||
import esprima = require('esprima');
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
var parse = esprima.parse;
|
||||
var parse = esprima.parseScript;
|
||||
|
||||
|
||||
var src = '[1,2,3+4*10+n,foo(3+5),obj[""+"x"].y]';
|
||||
|
||||
Reference in New Issue
Block a user