From 199ef32ca6522ee5a9e1b66af7c3bc0391fee530 Mon Sep 17 00:00:00 2001 From: Peter Scott Date: Wed, 30 Aug 2017 07:33:47 +0100 Subject: [PATCH] moved current esprima type definitions to version subfolder --- types/esprima/tsconfig.json | 2 +- types/esprima/v2/esprima-tests.ts | 28 ++++++++ types/esprima/v2/index.d.ts | 104 ++++++++++++++++++++++++++++++ types/esprima/v2/tsconfig.json | 27 ++++++++ 4 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 types/esprima/v2/esprima-tests.ts create mode 100644 types/esprima/v2/index.d.ts create mode 100644 types/esprima/v2/tsconfig.json diff --git a/types/esprima/tsconfig.json b/types/esprima/tsconfig.json index b94d0875ed..e70c3e04a4 100644 --- a/types/esprima/tsconfig.json +++ b/types/esprima/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" diff --git a/types/esprima/v2/esprima-tests.ts b/types/esprima/v2/esprima-tests.ts new file mode 100644 index 0000000000..376a9a7562 --- /dev/null +++ b/types/esprima/v2/esprima-tests.ts @@ -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; +} \ No newline at end of file diff --git a/types/esprima/v2/index.d.ts b/types/esprima/v2/index.d.ts new file mode 100644 index 0000000000..d602f72d30 --- /dev/null +++ b/types/esprima/v2/index.d.ts @@ -0,0 +1,104 @@ +// Type definitions for Esprima v2.1.0 +// Project: http://esprima.org +// Definitions by: teppeis , RReverser +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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; + + 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' + }; + +} \ No newline at end of file diff --git a/types/esprima/v2/tsconfig.json b/types/esprima/v2/tsconfig.json new file mode 100644 index 0000000000..7de8cc1403 --- /dev/null +++ b/types/esprima/v2/tsconfig.json @@ -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" + ] +} \ No newline at end of file