Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@typescript-eslint/typescript-estree

Package Overview
Dependencies
Maintainers
1
Versions
3931
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typescript-eslint/typescript-estree - npm Package Compare versions

Comparing version 1.1.1-alpha.11 to 1.1.1

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
### Bug Fixes
- **parser:** add visiting of type parameters in JSXOpeningElement ([#150](https://github.com/typescript-eslint/typescript-eslint/issues/150)) ([5e16003](https://github.com/typescript-eslint/typescript-eslint/commit/5e16003))
- **ts-estree:** expand optional property to include question token ([#138](https://github.com/typescript-eslint/typescript-eslint/issues/138)) ([9068b62](https://github.com/typescript-eslint/typescript-eslint/commit/9068b62))
### Performance Improvements
- **ts-estree:** don't create Program in parse() ([#148](https://github.com/typescript-eslint/typescript-eslint/issues/148)) ([aacf5b0](https://github.com/typescript-eslint/typescript-eslint/commit/aacf5b0))
# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)

@@ -8,0 +19,0 @@

11

dist/parser.d.ts

@@ -11,4 +11,6 @@ import ts from 'typescript';

} : {});
interface ParseAndGenerateServicesResult<T extends ParserOptions> {
ast: AST<T>;
export declare const version: string;
export declare function parse<T extends ParserOptions = ParserOptions>(code: string, options?: T): AST<T>;
export declare function parseAndGenerateServices(code: string, options: ParserOptions): {
ast: Program;
services: {

@@ -19,7 +21,4 @@ program: ts.Program | undefined;

};
}
export declare const version: string;
export declare function parse<T extends ParserOptions = ParserOptions>(code: string, options?: T): AST<T>;
export declare function parseAndGenerateServices<T extends ParserOptions = ParserOptions>(code: string, options: T): ParseAndGenerateServicesResult<T>;
};
export { AST_NODE_TYPES } from './ast-node-types';
export { ParserOptions };

@@ -27,7 +27,4 @@ "use strict";

/**
* Compute the filename based on the parser options.
* Compute the filename based on the parser options
*
* Even if jsx option is set in typescript compiler, filename still has to
* contain .tsx file extension.
*
* @param options Parser options

@@ -88,2 +85,4 @@ */

function createNewProgram(code) {
// Even if jsx option is set in typescript compiler, filename still has to
// contain .tsx file extension
const FILENAME = getFileName(extra);

@@ -142,70 +141,72 @@ const compilerHost = {

}
function applyParserOptionsToExtra(options) {
/**
* Track range information in the AST
*/
extra.range = typeof options.range === 'boolean' && options.range;
extra.loc = typeof options.loc === 'boolean' && options.loc;
/**
* Track tokens in the AST
*/
if (typeof options.tokens === 'boolean' && options.tokens) {
extra.tokens = [];
/**
* Parses the given source code to produce a valid AST
* @param {string} code TypeScript code
* @param {boolean} shouldGenerateServices Flag determining whether to generate ast maps and program or not
* @param {ParserOptions} options configuration object for the parser
* @returns {Object} the AST
*/
function generateAST(code, options = {}, shouldGenerateServices = false) {
if (typeof code !== 'string' && !(code instanceof String)) {
code = String(code);
}
/**
* Track comments in the AST
*/
if (typeof options.comment === 'boolean' && options.comment) {
extra.comment = true;
extra.comments = [];
resetExtra();
if (typeof options !== 'undefined') {
extra.range = typeof options.range === 'boolean' && options.range;
extra.loc = typeof options.loc === 'boolean' && options.loc;
if (typeof options.tokens === 'boolean' && options.tokens) {
extra.tokens = [];
}
if (typeof options.comment === 'boolean' && options.comment) {
extra.comment = true;
extra.comments = [];
}
if (typeof options.jsx === 'boolean' && options.jsx) {
extra.jsx = true;
}
/**
* Allow the user to cause the parser to error if it encounters an unknown AST Node Type
* (used in testing).
*/
if (typeof options.errorOnUnknownASTType === 'boolean' &&
options.errorOnUnknownASTType) {
extra.errorOnUnknownASTType = true;
}
/**
* Retrieve semantic and syntactic diagnostics from the underlying TypeScript Program
* and turn them into parse errors
*/
if (shouldGenerateServices &&
typeof options.errorOnTypeScriptSyntacticAndSemanticIssues ===
'boolean' &&
options.errorOnTypeScriptSyntacticAndSemanticIssues) {
extra.errorOnTypeScriptSyntacticAndSemanticIssues = true;
}
if (typeof options.useJSXTextNode === 'boolean' && options.useJSXTextNode) {
extra.useJSXTextNode = true;
}
/**
* Allow the user to override the function used for logging
*/
if (typeof options.loggerFn === 'function') {
extra.log = options.loggerFn;
}
else if (options.loggerFn === false) {
extra.log = Function.prototype;
}
if (typeof options.project === 'string') {
extra.projects = [options.project];
}
else if (Array.isArray(options.project) &&
options.project.every(projectPath => typeof projectPath === 'string')) {
extra.projects = options.project;
}
if (typeof options.tsconfigRootDir === 'string') {
extra.tsconfigRootDir = options.tsconfigRootDir;
}
if (Array.isArray(options.extraFileExtensions) &&
options.extraFileExtensions.every(ext => typeof ext === 'string')) {
extra.extraFileExtensions = options.extraFileExtensions;
}
}
/**
* Enable JSX - note the applicable file extension is still required
*/
if (typeof options.jsx === 'boolean' && options.jsx) {
extra.jsx = true;
}
/**
* The JSX AST changed the node type for string literals
* inside a JSX Element from `Literal` to `JSXText`.
*
* When value is `true`, these nodes will be parsed as type `JSXText`.
* When value is `false`, these nodes will be parsed as type `Literal`.
*/
if (typeof options.useJSXTextNode === 'boolean' && options.useJSXTextNode) {
extra.useJSXTextNode = true;
}
/**
* Allow the user to cause the parser to error if it encounters an unknown AST Node Type
* (used in testing)
*/
if (typeof options.errorOnUnknownASTType === 'boolean' &&
options.errorOnUnknownASTType) {
extra.errorOnUnknownASTType = true;
}
/**
* Allow the user to override the function used for logging
*/
if (typeof options.loggerFn === 'function') {
extra.log = options.loggerFn;
}
else if (options.loggerFn === false) {
extra.log = Function.prototype;
}
if (typeof options.project === 'string') {
extra.projects = [options.project];
}
else if (Array.isArray(options.project) &&
options.project.every(projectPath => typeof projectPath === 'string')) {
extra.projects = options.project;
}
if (typeof options.tsconfigRootDir === 'string') {
extra.tsconfigRootDir = options.tsconfigRootDir;
}
if (Array.isArray(options.extraFileExtensions) &&
options.extraFileExtensions.every(ext => typeof ext === 'string')) {
extra.extraFileExtensions = options.extraFileExtensions;
}
}
function warnAboutTSVersion() {
if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) {

@@ -225,85 +226,8 @@ const border = '=============';

}
}
//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------
exports.version = packageJSON.version;
function parse(code, options) {
/**
* Reset the parse configuration
*/
resetExtra();
/**
* Ensure users do not attempt to use parse() when they need parseAndGenerateServices()
*/
if (options && options.errorOnTypeScriptSyntacticAndSemanticIssues) {
throw new Error(`"errorOnTypeScriptSyntacticAndSemanticIssues" is only supported for parseAndGenerateServices()`);
}
/**
* Ensure the source code is a string, and store a reference to it
*/
if (typeof code !== 'string' && !(code instanceof String)) {
code = String(code);
}
const shouldProvideParserServices = shouldGenerateServices && extra.projects && extra.projects.length > 0;
const { ast, program } = getProgramAndAST(code, options, shouldProvideParserServices);
extra.code = code;
/**
* Apply the given parser options
* Convert the AST
*/
if (typeof options !== 'undefined') {
applyParserOptionsToExtra(options);
}
/**
* Warn if the user is using an unsupported version of TypeScript
*/
warnAboutTSVersion();
/**
* Create a ts.SourceFile directly, no ts.Program is needed for a simple
* parse
*/
const ast = typescript_1.default.createSourceFile(getFileName(extra), code, typescript_1.default.ScriptTarget.Latest,
/* setParentNodes */ true);
/**
* Convert the TypeScript AST to an ESTree-compatible one
*/
const { estree } = ast_converter_1.default(ast, extra, false);
return estree;
}
exports.parse = parse;
function parseAndGenerateServices(code, options) {
/**
* Reset the parse configuration
*/
resetExtra();
/**
* Ensure the source code is a string, and store a reference to it
*/
if (typeof code !== 'string' && !(code instanceof String)) {
code = String(code);
}
extra.code = code;
/**
* Apply the given parser options
*/
if (typeof options !== 'undefined') {
applyParserOptionsToExtra(options);
if (typeof options.errorOnTypeScriptSyntacticAndSemanticIssues ===
'boolean' &&
options.errorOnTypeScriptSyntacticAndSemanticIssues) {
extra.errorOnTypeScriptSyntacticAndSemanticIssues = true;
}
}
/**
* Warn if the user is using an unsupported version of TypeScript
*/
warnAboutTSVersion();
/**
* Generate a full ts.Program in order to be able to provide parser
* services, such as type-checking
*/
const shouldProvideParserServices = extra.projects && extra.projects.length > 0;
const { ast, program } = getProgramAndAST(code, options, shouldProvideParserServices);
/**
* Convert the TypeScript AST to an ESTree-compatible one, and optionally preserve
* mappings between converted and original AST nodes
*/
const { estree, astMaps } = ast_converter_1.default(ast, extra, shouldProvideParserServices);

@@ -320,15 +244,29 @@ /**

}
/**
* Return the converted AST and additional parser services
*/
return {
ast: estree,
estree,
program: shouldProvideParserServices ? program : undefined,
astMaps: shouldProvideParserServices
? astMaps
: { esTreeNodeToTSNodeMap: undefined, tsNodeToESTreeNodeMap: undefined }
};
}
//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------
exports.version = packageJSON.version;
function parse(code, options) {
if (options && options.errorOnTypeScriptSyntacticAndSemanticIssues) {
throw new Error(`"errorOnTypeScriptSyntacticAndSemanticIssues" is only supported for parseAndGenerateServices()`);
}
return generateAST(code, options).estree;
}
exports.parse = parse;
function parseAndGenerateServices(code, options) {
const result = generateAST(code, options, /*shouldGenerateServices*/ true);
return {
ast: result.estree,
services: {
program: shouldProvideParserServices ? program : undefined,
esTreeNodeToTSNodeMap: shouldProvideParserServices && astMaps
? astMaps.esTreeNodeToTSNodeMap
: undefined,
tsNodeToESTreeNodeMap: shouldProvideParserServices && astMaps
? astMaps.tsNodeToESTreeNodeMap
: undefined
program: result.program,
esTreeNodeToTSNodeMap: result.astMaps.esTreeNodeToTSNodeMap,
tsNodeToESTreeNodeMap: result.astMaps.tsNodeToESTreeNodeMap
}

@@ -335,0 +273,0 @@ };

{
"name": "@typescript-eslint/typescript-estree",
"version": "1.1.1-alpha.11+aacf5b0",
"version": "1.1.1",
"description": "A parser that converts TypeScript source code into an ESTree compatible form",

@@ -45,6 +45,6 @@ "main": "dist/parser.js",

"devDependencies": {
"@typescript-eslint/shared-fixtures": "1.1.1-alpha.11+aacf5b0",
"@typescript-eslint/shared-fixtures": "1.1.1",
"typescript": "~3.2.1"
},
"gitHead": "aacf5b05c7f0d802bbc28222d7c95141fa0ff86c"
"gitHead": "5b0b3d9edbcb3ab588a34c431037d9deece30824"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc