main
parent
e758aeb17a
commit
971705ebf3
@ -1,14 +0,0 @@
|
||||
declare type BeginLoading = () => void;
|
||||
declare type EndLoading = () => void;
|
||||
declare type HttpFailed = (ok: boolean, status: number, statusText: string) => void;
|
||||
declare type HttpErr = (errCode: number, errMsg: string) => void;
|
||||
export declare class GlobalUnit {
|
||||
static JWT_STR: string;
|
||||
static APP_NAME: string;
|
||||
static BASE_URL: string;
|
||||
static BeginLoading?: BeginLoading;
|
||||
static EndLoading?: EndLoading;
|
||||
static HttpFailed?: HttpFailed;
|
||||
static HttpErr?: HttpErr;
|
||||
}
|
||||
export {};
|
@ -1,386 +0,0 @@
|
||||
import { GlobalUnit } from './globalunit';
|
||||
import { isWeAPP } from './utils';
|
||||
export { GlobalUnit, isWeAPP };
|
||||
export declare class GetRbacCheckrolecodeResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class GetRbacDelroleResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class GetRbacDelrouteResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class GetRbacDeluserResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class GetRbacGetcodeResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
data?: RbacGetCodeDataObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetCodeDataObject {
|
||||
code: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class GetRbacGetrolebyuseridResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
data?: RbacGetRoleDataObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetRoleDataObject {
|
||||
role?: RbacGetRoleObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetRoleObject {
|
||||
id: string;
|
||||
role_code: string;
|
||||
role_name: string;
|
||||
description: string;
|
||||
created_at: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class GetRbacGetroutelistResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
data?: RbacGetRouteListDataObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetRouteListDataObject {
|
||||
routes?: RbacGetRouteListRouteList[];
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetRouteListRouteList {
|
||||
id: string;
|
||||
parent_id: string;
|
||||
menu_type: number;
|
||||
name: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
sort: number;
|
||||
component: string;
|
||||
redirect: string;
|
||||
perms: string;
|
||||
perms_type: number;
|
||||
btn_status: number;
|
||||
path: string;
|
||||
hideInBread: number;
|
||||
hideInMenu: number;
|
||||
notCache: number;
|
||||
isMmin: number;
|
||||
children?: RbacGetRouteListChildrenList[];
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetRouteListChildrenList {
|
||||
id: string;
|
||||
parent_id: string;
|
||||
menu_type: number;
|
||||
name: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
sort: number;
|
||||
component: string;
|
||||
redirect: string;
|
||||
perms: string;
|
||||
perms_type: number;
|
||||
path: string;
|
||||
btn_status: number;
|
||||
hideInBread: number;
|
||||
hideInMenu: number;
|
||||
notCache: number;
|
||||
isMmin: number;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class GetRbacGetroutesbyroleidResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
data?: RbacGetRoleRoutesDataObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetRoleRoutesDataObject {
|
||||
routes?: RbacGetRoleRoutesRouteList[];
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetRoleRoutesRouteList {
|
||||
id: string;
|
||||
parent_id: string;
|
||||
title: string;
|
||||
checked: number;
|
||||
children?: RbacGetRoleRoutesChildrenList[];
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetRoleRoutesChildrenList {
|
||||
id: string;
|
||||
parent_id: string;
|
||||
title: string;
|
||||
checked: number;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class GetRbacGetuserpermissionResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
data?: RbacPermissionDataObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacPermissionDataObject {
|
||||
routes?: RbacPermissionRouteList[];
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacPermissionRouteList {
|
||||
id: string;
|
||||
parent_id: string;
|
||||
menu_type: number;
|
||||
name: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
sort: number;
|
||||
component: string;
|
||||
redirect: string;
|
||||
perms: string;
|
||||
perms_type: number;
|
||||
btn_status: number;
|
||||
path: string;
|
||||
is_choose: string;
|
||||
meta?: RbacPermissionRouteMetaObj;
|
||||
children?: RbacPermissionRouteChildrenList[];
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacPermissionRouteMetaObj {
|
||||
title: string;
|
||||
icon: string;
|
||||
hideInBread?: Bool;
|
||||
hideInMenu?: Bool;
|
||||
notCache?: Bool;
|
||||
isMmin?: Bool;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class Bool {
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacPermissionRouteChildrenList {
|
||||
id: string;
|
||||
parent_id: string;
|
||||
menu_type: number;
|
||||
name: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
sort: number;
|
||||
component: string;
|
||||
redirect: string;
|
||||
perms: string;
|
||||
perms_type: number;
|
||||
path: string;
|
||||
is_choose: string;
|
||||
btn_status: number;
|
||||
meta?: RbacPermissionRouteChildrenMetaObj;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacPermissionRouteChildrenMetaObj {
|
||||
title: string;
|
||||
icon: string;
|
||||
hideInBread?: Bool;
|
||||
hideInMenu?: Bool;
|
||||
notCache?: Bool;
|
||||
isMmin?: Bool;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class GetRbacGetusersbyroleidResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
data?: RbacUserListDataObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacUserListDataObject {
|
||||
count: number;
|
||||
users?: RbacUserListDataUserList[];
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacUserListDataUserList {
|
||||
id: string;
|
||||
username: string;
|
||||
avatar: string;
|
||||
realname: string;
|
||||
disable: string;
|
||||
root: number;
|
||||
created_at: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacCreateroleResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacCreaterouteResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacDelrolebindResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacGetrolesResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
data?: RbacGetRoleListDataObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetRoleListDataObject {
|
||||
count: number;
|
||||
roles?: RbacGetRoleList[];
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacGetRoleList {
|
||||
id: string;
|
||||
role_code: string;
|
||||
role_name: string;
|
||||
description: string;
|
||||
created_at: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacGetuserlistResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
data?: RbacUserListDataObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacLoginResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
data?: RbacLoginDataObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacLoginDataObject {
|
||||
user?: RbacLoginUserObject;
|
||||
jwt: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacLoginUserObject {
|
||||
id: string;
|
||||
username: string;
|
||||
avatar: string;
|
||||
realname: string;
|
||||
disable: string;
|
||||
created_at: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacRegisterResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
data?: RbacCreateUserDataObject;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class RbacCreateUserDataObject {
|
||||
id: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacRolebindrouteResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacRolebinduserResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacUpdateroleResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacUpdaterouteResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacUpdateuserResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class PostRbacUserbindroleResponse {
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
constructor(jsonObj: Object);
|
||||
toMap(): any;
|
||||
}
|
||||
export declare class Rbac {
|
||||
static GetRbacCheckrolecode(role_code: string, callback?: (response: GetRbacCheckrolecodeResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static GetRbacDelrole(role_id: string, callback?: (response: GetRbacDelroleResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static GetRbacDelroute(route_id: string, callback?: (response: GetRbacDelrouteResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static GetRbacDeluser(user_id: string, callback?: (response: GetRbacDeluserResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static GetRbacGetcode(_t: string, callback?: (response: GetRbacGetcodeResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static GetRbacGetrolebyuserid(user_id: string, callback?: (response: GetRbacGetrolebyuseridResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static GetRbacGetroutelist(callback?: (response: GetRbacGetroutelistResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static GetRbacGetroutesbyroleid(role_id: string, callback?: (response: GetRbacGetroutesbyroleidResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static GetRbacGetuserpermission(callback?: (response: GetRbacGetuserpermissionResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static GetRbacGetusersbyroleid(role_id: string, callback?: (response: GetRbacGetusersbyroleidResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacCreaterole(description: string | undefined, role_code: string, role_name: string, callback?: (response: PostRbacCreateroleResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacCreateroute(btn_status: number, component: string, hideInBread: number, hideInMenu: number, icon: string, isMmin: number, ment_type: number, name: string, notCache: number, parent_id: string, path: string, perms: string, perms_type: number, redirect: string, sort: number, title: string, callback?: (response: PostRbacCreaterouteResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacDelrolebind(role_id: string, user_id: string, callback?: (response: PostRbacDelrolebindResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacGetroles(limit?: number, page?: number, role_code?: string, role_name?: string, callback?: (response: PostRbacGetrolesResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacGetuserlist(limit?: number, page?: number, realname?: string, username?: string, callback?: (response: PostRbacGetuserlistResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacLogin(_t: string, code: string, password: string, username: string, callback?: (response: PostRbacLoginResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacRegister(avatar: string, password: string, realname: string, root: number, username: string, callback?: (response: PostRbacRegisterResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacRolebindroute(role_id: string, routes: string[], callback?: (response: PostRbacRolebindrouteResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacRolebinduser(role_id: string, users: string[], callback?: (response: PostRbacRolebinduserResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacUpdaterole(description: string | undefined, role_id: string, role_name: string, callback?: (response: PostRbacUpdateroleResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacUpdateroute(btn_status: number, component: string, hideInBread: number, hideInMenu: number, icon: string, isMmin: number, ment_type: number, name: string, notCache: number, parent_id: string, path: string, perms: string, perms_type: number, redirect: string, route_id: string, sort: number, title: string, callback?: (response: PostRbacUpdaterouteResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacUpdateuser(avatar: string, realname: string, root: number, user_id: string, callback?: (response: PostRbacUpdateuserResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
static PostRbacUserbindrole(role_id: string, user_id: string, callback?: (response: PostRbacUserbindroleResponse) => void, loading?: boolean, isshow?: boolean): void;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,23 +0,0 @@
|
||||
export interface RequestOptions {
|
||||
ignoreCache?: boolean;
|
||||
headers?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
timeout?: number;
|
||||
}
|
||||
export declare const DEFAULT_REQUEST_OPTIONS: {
|
||||
ignoreCache: boolean;
|
||||
headers: {
|
||||
Accept: string;
|
||||
};
|
||||
timeout: number;
|
||||
};
|
||||
export interface RequestResult {
|
||||
ok: boolean;
|
||||
status: number;
|
||||
statusText: string;
|
||||
data: string;
|
||||
json: <T>() => T;
|
||||
headers: string;
|
||||
}
|
||||
export declare function request(method: 'get' | 'post', url: string, queryParams?: any, body?: any, options?: RequestOptions): Promise<RequestResult>;
|
@ -1,73 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DEFAULT_REQUEST_OPTIONS = {
|
||||
ignoreCache: false,
|
||||
headers: {
|
||||
Accept: 'application/json, text/javascript, text/plain',
|
||||
},
|
||||
timeout: 5000,
|
||||
};
|
||||
function queryParams(params = {}) {
|
||||
return Object.keys(params)
|
||||
.map((k) => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
|
||||
.join('&');
|
||||
}
|
||||
function withQuery(url, params = {}) {
|
||||
const queryString = queryParams(params);
|
||||
return queryString
|
||||
? url + (url.indexOf('?') === -1 ? '?' : '&') + queryString
|
||||
: url;
|
||||
}
|
||||
function parseXHRResult(xhr) {
|
||||
return {
|
||||
ok: xhr.status >= 200 && xhr.status < 300,
|
||||
status: xhr.status,
|
||||
statusText: xhr.statusText,
|
||||
headers: xhr.getAllResponseHeaders(),
|
||||
data: xhr.responseText,
|
||||
json: () => JSON.parse(xhr.responseText),
|
||||
};
|
||||
}
|
||||
function errorResponse(xhr, message = null) {
|
||||
return {
|
||||
ok: false,
|
||||
status: xhr.status,
|
||||
statusText: xhr.statusText,
|
||||
headers: xhr.getAllResponseHeaders(),
|
||||
data: message || xhr.statusText,
|
||||
json: () => JSON.parse(message || xhr.statusText),
|
||||
};
|
||||
}
|
||||
function request(method, url, queryParams = {}, body = null, options = exports.DEFAULT_REQUEST_OPTIONS) {
|
||||
const ignoreCache = options.ignoreCache || exports.DEFAULT_REQUEST_OPTIONS.ignoreCache;
|
||||
const headers = options.headers || exports.DEFAULT_REQUEST_OPTIONS.headers;
|
||||
const timeout = options.timeout || exports.DEFAULT_REQUEST_OPTIONS.timeout;
|
||||
return new Promise((resolve, reject) => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open(method, withQuery(url, queryParams));
|
||||
if (headers) {
|
||||
Object.keys(headers).forEach((key) => xhr.setRequestHeader(key, headers[key]));
|
||||
}
|
||||
if (ignoreCache) {
|
||||
xhr.setRequestHeader('Cache-Control', 'no-cache');
|
||||
}
|
||||
xhr.timeout = timeout;
|
||||
xhr.onload = () => {
|
||||
resolve(parseXHRResult(xhr));
|
||||
};
|
||||
xhr.onerror = () => {
|
||||
resolve(errorResponse(xhr, 'Failed to make request.'));
|
||||
};
|
||||
xhr.ontimeout = () => {
|
||||
resolve(errorResponse(xhr, 'Request took longer than expected.'));
|
||||
};
|
||||
if (method === 'post' && body) {
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(body));
|
||||
}
|
||||
else {
|
||||
xhr.send();
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.request = request;
|
@ -1,2 +0,0 @@
|
||||
export declare function endsWith(str: string, suffix: string): boolean;
|
||||
export declare const isWeAPP: () => boolean;
|
@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
function endsWith(str, suffix) {
|
||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||
}
|
||||
exports.endsWith = endsWith;
|
||||
exports.isWeAPP = () => typeof wx !== 'undefined';
|
@ -0,0 +1 @@
|
||||
../mocha/bin/_mocha
|
@ -0,0 +1 @@
|
||||
../color-support/bin.js
|
@ -0,0 +1 @@
|
||||
../esprima/bin/esparse.js
|
@ -0,0 +1 @@
|
||||
../esprima/bin/esvalidate.js
|
@ -0,0 +1 @@
|
||||
../he/bin/he
|
@ -0,0 +1 @@
|
||||
../js-yaml/bin/js-yaml.js
|
@ -0,0 +1 @@
|
||||
../json5/lib/cli.js
|
@ -0,0 +1 @@
|
||||
../mkdirp/bin/cmd.js
|
@ -0,0 +1 @@
|
||||
../mocha/bin/mocha
|
@ -0,0 +1 @@
|
||||
../resolve/bin/resolve
|
@ -0,0 +1 @@
|
||||
../semver/bin/semver.js
|
@ -0,0 +1 @@
|
||||
../ts-mocha/bin/ts-mocha
|
@ -0,0 +1 @@
|
||||
../ts-node/dist/bin.js
|
@ -0,0 +1 @@
|
||||
../tsc/bin/tsc
|
@ -0,0 +1 @@
|
||||
../tslint/bin/tslint
|
@ -0,0 +1 @@
|
||||
../typescript/bin/tsserver
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
@ -0,0 +1 @@
|
||||
Copyright 2018 Klaus Meinhardt <klaus.meinhardt1@gmail.com> (https://github.com/ajafff)
|
@ -0,0 +1,75 @@
|
||||
# Bifröst
|
||||
|
||||
Compatiblity layer for TSLint rules and formatters.
|
||||
|
||||
[](https://www.npmjs.com/package/@fimbul/bifrost)
|
||||
[](https://www.npmjs.com/package/@fimbul/bifrost)
|
||||
[](https://renovateapp.com/)
|
||||
[](https://circleci.com/gh/fimbullinter/wotan/tree/master)
|
||||
[](https://ci.appveyor.com/project/ajafff/wotan/branch/master)
|
||||
[](https://codecov.io/gh/fimbullinter/wotan)
|
||||
[](https://gitter.im/fimbullinter/wotan)
|
||||
|
||||
Make sure to also read the [full documentation of all available modules](https://github.com/fimbullinter/wotan#readme).
|
||||
|
||||
## Purpose
|
||||
|
||||
Allows TSLint rule authors to provide the same rules for Wotan without any refactoring.
|
||||
Although `@fimbul/heimdall` already allows users to use your rules and formatters in Wotan, they still need to remember to use `-m @fimbul/heimdall` when running Wotan.
|
||||
You can help these users by providing your rules in a format that Wotan understands without any plugin.
|
||||
|
||||
It also provides the exact opposite functionality: using rules originally written for Fimbullinter (wotan) as TSLint rule.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install --save @fimbul/bifrost
|
||||
# or
|
||||
yarn add @fimbul/bifrost
|
||||
```
|
||||
|
||||
## Using TSLint Rules and Formatters in Wotan
|
||||
|
||||
### Rules
|
||||
|
||||
Given a TSLint rule `my-foo` in a file `myFooRule.ts`, you simply create a file `my-foo.ts` with the following content:
|
||||
|
||||
```ts
|
||||
import {wrapTslintRule} from '@fimbul/bifrost';
|
||||
import {Rule} from './myFooRule.ts';
|
||||
|
||||
const Wrapped = wrapTslintRule(Rule, 'my-foo');
|
||||
export {Wrapped as Rule};
|
||||
```
|
||||
|
||||
If you want to use a different directory for your TSLint rules and their Wotan wrapper, you just need to adjust the paths in the above example.
|
||||
|
||||
### Formatters
|
||||
|
||||
Given a TSLint formatter `my-foo` in a file `myFooFormatter.ts`, you simply create a file `my-foo.ts` with the following content:
|
||||
|
||||
```ts
|
||||
import {wrapTslintFormatter} from '@fimbul/bifrost';
|
||||
import {Formatter} from './myFooFormatter.ts';
|
||||
|
||||
const Wrapped = wrapTslintFormatter(Formatter);
|
||||
export {Wrapped as Formatter};
|
||||
```
|
||||
|
||||
Note that findings with severity `suggestion` are reported as `warning` through TSLint formatters.
|
||||
|
||||
## Using Fimbullinter Rules in TSLint
|
||||
|
||||
Given a Fimbullinter rule `my-foo` in a file `my-foo.ts`, you simply create a file `myFooRule.ts` with the following content:
|
||||
|
||||
```ts
|
||||
import {wrapRuleForTslint} from '@fimbul/bifrost';
|
||||
import {Rule} from './my-foo.ts';
|
||||
|
||||
const Wrapped = wrapRuleForTslint(Rule);
|
||||
export {Wrapped as Rule};
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0 © [Klaus Meinhardt](https://github.com/ajafff)
|
@ -0,0 +1,811 @@
|
||||
# 3.21.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `getWellKnownSymbolPropertyOfType` to reliably get symbol named properties due to changes in typescript@4.3
|
||||
* `getPropertyNameOfWellKnownSymbol` is now deprecated
|
||||
|
||||
# 3.20.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* `findImports` and `findImportLikeNodes` take an additional parameter `ignoreFileName`. The default value for this paramter is `true` to remain backwards compatible. When set to `false`, it matches the behavior of TypeScript, i.e. only looks for `require` in JavaScript files.
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `getJsDoc` for `EndOfFileToken` now returns `JSDoc` comments whose contents are usable with the type checker
|
||||
|
||||
# 3.19.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `getSymbolOfClassLikeDeclaration` no longer crashes on anonymous mixin classes
|
||||
|
||||
# 3.19.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* `getSymbolOfClassLikeDeclaration` to retrieve the symbol of class declarations and expressions regardless whether they have a name or not
|
||||
* `getBaseOfClassLikeDeclaration` to conventiently get the expression after `extends`
|
||||
* `getBaseClassMemberOfClassElement` to look up the declaration of a class member in the base class
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `getConstructorTypeOfClassLikeDeclaration` now really returns the constructor type (the static side of the class), previously it returned the instance type
|
||||
* `hasExhaustiveCaseClauses` allows additional case clauses with `null`, `undefined` and `never`
|
||||
|
||||
# 3.18.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* Source maps for easier debugging
|
||||
* JSDoc is preserved in declaration files
|
||||
* Comments are presered in transpiled code
|
||||
* Everything you need to handle the control flow changes of TypeScript@3.7
|
||||
* `callExpressionAffectsControlFlow` to determine whether a CallExpression affects control flow by returning `never` or `asserts`
|
||||
* `hasExhaustiveCaseClauses` to determine whether a SwitchStatement's CaseClauses handle every possible value
|
||||
* `endsControlFlow` and `getControlFlowEnd` take an optional `checker` parameter to recognize exhaustive SwitchStatements and control flow effects of CallExpressions
|
||||
* `formatPseudoBigInt` converts TypeScript's representation of a BigInt to its literal representation as you would write it in your source code
|
||||
* `getAstNodeAtPosition` similar to `getTokenAtPosition`, but only operates on AST Nodes
|
||||
* `removeOptionalChainingUndefinedMarkerType` and `isOptionalChainingUndefinedMarkerType` to handle types originating in an optional chain
|
||||
* `findImports` and `findImportLikeNodes`: prepare for import assertions
|
||||
* `getTsCheckDirective` as new name for `getCheckJsDirective`
|
||||
* `getCheckJsDirective` is now deprecated
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `getUsageDomain`: handles NamespaceExport and NamedTupleMember
|
||||
* `getPropertyName`: handles parentheses and negative numeric literals, excludes RegExp literals and private identifiers
|
||||
* `getSingleLateBoundPropertyNameOfPropertyName` and `getLateBoundPropertyNamesOfPropertyName`: handles private identifiers
|
||||
* `hasAccessModifier`: handles JSDoc access modifier
|
||||
* `hasSideEffects`: correctly determines side effects of (static) property initializers
|
||||
* `isExpressionValueUsed`: handle nullish coalescing and conditional assignment operators
|
||||
* `canHaveJsDoc`: aligned with upstream changes in TypeScript
|
||||
* `isCompilerOptionEnabled`:
|
||||
* `noUncheckedIndexedAccess` requires `strictNullChecks`
|
||||
* `checkJs` implies `allowJs`
|
||||
* `emitDeclarationOnly` requires `declaration`
|
||||
* `isInConstContext`: handle template string interpolations
|
||||
* excluded unnecessary files from npm package
|
||||
|
||||
# 3.17.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isValidJsxIdentifier`, `isValidPropertyAccess`, `isValidPropertyName`: fix unicode character width handling
|
||||
|
||||
# 3.17.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* `isValidJsxIdentifier` added an optional parameter to specify the target ECMAScript version
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isValidJsxIdentifier` now handles astral plane characters
|
||||
|
||||
# 3.16.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `getIteratorYieldResultFromIteratorResult` to extract the `yield`ed type from `IteratorResult<TYield, TReturn, TNext>`
|
||||
|
||||
# 3.15.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* `isValidIdentifier`, `isValidPropertyName`, `isValidPropertyAccess`, `isValidNumericLiteral` added an optional parameter to specify the target ECMAScript version
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isValidPropertyName`, `isValidPropertyAccess` now handle astral plane characters
|
||||
|
||||
# 3.14.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `findImports`: fixed crash on nested namespaces
|
||||
|
||||
# 3.14.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `getInstanceTypeOfClassLikeDeclaration` and `getConstructorTypeOfClassLikeDeclaration`
|
||||
* added `AccessKind.Delete` to `getAccessKind`: `getAccessKind(node) & AccessKind.Modification` can now be used to restore the old behavior of `isReassignmentTarget(node)`
|
||||
|
||||
# 3.13.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* `getAccessKind` determines whether an expression is read from, written to or both
|
||||
* optimized `getPropertyOfType` for unambiguous property names to partially work around https://github.com/microsoft/TypeScript/issues/31565
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isReassignmentTarget` no longer returns `true` for `DeleteExpression` as it doesn't **assign** a value to the operand
|
||||
|
||||
# 3.12.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* `getLateBoundPropertyNamesOfPropertyName` returns all statically analyzable names of a property, method, ...
|
||||
* `getSingleLateBoundPropertyNameOfPropertyName` returns the literal name of a property, method, ... if statically analyzable
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* fixed circular import
|
||||
|
||||
# 3.11.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* typeguards: `isNumericOrStringLikeLiteral`, `isTupleTypeReference`
|
||||
* `intersectionTypeParts` as counterpart to `unionTypeParts`
|
||||
* `someTypePart` to execute a callback for each union or intersection constituent until the callback returns true
|
||||
* `getPropertyOfType` looks up a property by its escaped name
|
||||
* `isPropertyReadonlyInType` determines whether a property in a given type cannot be written to
|
||||
* `symbolHasReadonlyDeclaration` determines if a Symbol has any readonly or constant declaration
|
||||
* `isNumericPropertyName` determines whether a property name would match an index signature
|
||||
* `isBindableObjectDefinePropertyCall` returns true for statically analyzable forms of `Object.defineProperty(o, 'p', {value, writable})`
|
||||
* `isReadonlyAssignmentDeclaration` determines whether an `Object.defineProperty` call is known to result in a readonly property
|
||||
* `getLateBoundPropertyNames` returns all known property names of an expression
|
||||
* `getPropertyNameFromType` extracts the property name of literal types
|
||||
* `isWellKnownSymbolLiterally` to recognize expressions in the form of `Symbol.<name>`
|
||||
* `getPropertyNameOfWellKnownSymbol` returns the escaped name for a well known symbol literal
|
||||
* `unwrapParentheses` returns the first child expression that is not a `ParenthesizedExpression`
|
||||
|
||||
# 3.10.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* `isCompilerOptionEnabled`: `incremental` is implicitly enabled by `composite`
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `collectVariableUsage`/`getUsageDomain`: no longer treat `as const` as type usage
|
||||
|
||||
# 3.9.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* reverted invalid deprecation of `canHaveJsdoc`
|
||||
* fixed condition in `parseJsdocOfNode`
|
||||
|
||||
# 3.9.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added typeguards: `isNullLiteral` and `isBooleanLiteral`
|
||||
|
||||
# 3.8.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* exposes typeguards for typescript@3.2 by default
|
||||
* added utilities: `isConstAssertion` and `isInConstContext`
|
||||
|
||||
# 3.7.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `isBlockScopedDeclarationStatement`
|
||||
* added `isInSingleStatementContext`
|
||||
|
||||
# 3.6.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `getCheckJsDirective` utility to parse `// @ts-check` and `// @ts-nocheck` pragmas
|
||||
|
||||
# 3.5.2
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* Published declaration files no longer contain `const enum`. They are now declared as regular enums instead.
|
||||
|
||||
# 3.5.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isThenableType` allows `Node` instead of `Expression` as parameter
|
||||
* `isBlockScopeBoundary` and `isScopeBoundary` consider `WithStatement` as scope boundary
|
||||
|
||||
# 3.5.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* correctly handle BigInt literals
|
||||
* added typeguard `isBigIntLiteral`
|
||||
* `isLiteralType` recognises BigInt
|
||||
* `getPropertyName` adds special handling for BigInt
|
||||
|
||||
# 3.4.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added utility `commentText` to get the actual text content of a comment excluding the characters needed to start and end the comment
|
||||
|
||||
# 3.3.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `findImports`: fixed handling of ImportEqualsDeclaration
|
||||
|
||||
# 3.3.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* `isCompilerOptionEnabled`: recognizes `strictBindCallApply`
|
||||
* `getTokenAtPosition`: optionally includes JSDoc during lookup
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isCompilerOptionEnabled`: correctly implements logic for `allowSyntheticDefaultImports`
|
||||
* `findImportLikeNodes`: correctly finds imports in namespaces
|
||||
* `findImportLikeNodes` / `findImports`: finds import types in JSDoc of JS files
|
||||
|
||||
# 3.2.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added utility `findImportLikeNodes` that works similar to `findImports` but returns the import statement or expression instead of the module specifier and doesn't filter non-string module specifiers
|
||||
|
||||
# 3.1.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added utilities: `isKeywordKind` and `isValidJsxIdentifier`
|
||||
* exposes typeguards for typescript@3.0 by default
|
||||
|
||||
# 3.0.0
|
||||
|
||||
:warning: **Breaking Changes:**
|
||||
|
||||
* Dropped support for `typescript@<2.8.0`
|
||||
* Dropped support for Node.js 4
|
||||
* Removed deprecated APIs:
|
||||
* `getIdentifierText`, `isJsxFramgment`, `ImportOptions`
|
||||
* deprected overloads of `isModifierFlagSet`, `findImports` and `getControlFlowEnd`
|
||||
* control flow related symbols can no longer be imported from `'tsutils/util/util'`, import directly from `'tsutils/util/control-flow'` or `'tsutils/util'`
|
||||
* `isFunctionScopeBoundary` and `isBlockScopeBoundary` now return a enum member of `ScopeBoundary` instead of a boolean
|
||||
* `isFunctionScopeBoundary` no longer returns a truthy value for `InterfaceDeclaration`, `TypeAliasDeclaration`
|
||||
|
||||
**Features:**
|
||||
|
||||
* added utility `isTypeScopeBoundary` returning `ScopeBoundary.Type` or `ScopeBoundary.ConditionalType`
|
||||
* added enum `ScopeBoundarySelector` whose members can be used to determine if a declaration belongs to a given `ScopeBoundary` by using bitwise AND
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `collectVariableUsage` now correctly handles `infer T` nested inside function signatures or mapped types
|
||||
* `isCompilerOptionEnabled` correctly handles `skipDefaultLibCHeck` and `suppressImplicitAnyIndexErrors`
|
||||
|
||||
# 2.29.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added utility `isCompilerOptionEnabled`
|
||||
|
||||
# 2.28.0
|
||||
|
||||
Typeguards are now split into multiple submodules for each version of TypeScript (starting with 2.8.0).
|
||||
That means you can now import directly from `"tsutils/typeguard/2.8"` to get compatible declaraton files for TypeScript@2.8.
|
||||
For more information please read the relevant section in [README.md](README.md).
|
||||
|
||||
**Features:**
|
||||
|
||||
* added typeguards: `isTupleType`, `isOptionalTypeNode`, `isRestTypeNode`, `isSyntheticExpression` (currently available from `"tsutils/typeguard/3.0"`)
|
||||
* added utility `isStrictCompilerOptionEnabled`
|
||||
|
||||
# 2.27.2
|
||||
|
||||
Avoid crash caused by removed function in `typescript@3.0.0`.
|
||||
|
||||
# 2.27.1
|
||||
|
||||
Added support for TypeScript@3.0.0 nightly builds.
|
||||
|
||||
# 2.27.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `getIIFE` utility
|
||||
|
||||
# 2.26.2
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `forEachComment` and `forEachTokenWithTrivia` no longer duplicate comments around missing nodes
|
||||
|
||||
# 2.26.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* fixed crash in `hasSideEffects` with tagged template literal without substitution: ``tag`template` ``
|
||||
|
||||
# 2.26.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added typeguard `isLiteralTypeNode`
|
||||
* added support for type imports (`type T = import('foo')`) to `findImports` via `ImportKind.ImportType`
|
||||
|
||||
# 2.25.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `collectVariableUsage`: fixed name lookup in function signatures to match runtime behavior. Note that this is not completely fixed in TypeScript, yet. See: [Microsoft/TypeScript#22825](https://github.com/Microsoft/TypeScript/issues/22825) and [Microsoft/TypeScript#22769](https://github.com/Microsoft/TypeScript/issues/22769)
|
||||
|
||||
# 2.25.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added utilities: `isStatementInAmbientContext` and `isAmbientModuleBlock`
|
||||
|
||||
# 2.24.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added typeguards for typescript@2.8: `isConditionalTypeNode`, `isInferTypeNode`, `isConditionalType`, `isInstantiableType`, `isSubstitutionType`
|
||||
|
||||
# 2.23.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added typeguard `isForInOrOfStatement`
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* correctly handle comments in generic JSX elements: `<MyComponent<string>/*comment*/></MyComponent>`
|
||||
* fixed a bug with false positive trailing comments at the end of JSX self closing element: `<div><br/>/*no comment*/</div>`
|
||||
|
||||
# 2.22.2
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `collectVariableUsage`: handle ConditionalTypes and `infer T`, which will be introduced in TypeScript@2.8.0 and are already available in nightly builds
|
||||
* `isLiteralType` no longer returns true for `ts.TypeFlags.BooleanLiteral` as this is not a `ts.LiteralType`
|
||||
|
||||
# 2.22.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `endsControlFlow`:
|
||||
* handle loops that might not even run a single iteration
|
||||
* handle constant boolean conditions in loops and if
|
||||
|
||||
# 2.22.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `isFalsyType` utility
|
||||
|
||||
# 2.21.2
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* fixed compile error with `typescript@2.8.0-dev`
|
||||
|
||||
# 2.21.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isReassignmentTarget`: handle type assertions and non-null assertion
|
||||
|
||||
# 2.21.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `forEachDeclaredVariable` uses a more precise type for the callback parameter to make it useable again with typescript@2.7.1
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `isUniqueESSymbolType` typeguard
|
||||
|
||||
# 2.20.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `isThenableType` utility
|
||||
* added `unionTypeParts` utility
|
||||
|
||||
# 2.19.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `forEachComment`, `getCommentAtPosition` and `isPositionInComment`: skip shebang (`#! something`) to not miss following comments at the start of the file
|
||||
|
||||
# 2.19.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `WrappedAst` interface that models the type of a wrapped SourceFile more accurate
|
||||
* added `getWrappedNodeAtPosition` utiltiy that takes a `NodeWrap` and returns the most deeply nested NodeWrap that contains the given position
|
||||
|
||||
# 2.18.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* `getControlFlowEnd` accepts BlockLike as argument
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `getControlFlowEnd` and `endsControlFlow`: correctly handle nested LabeledStatements
|
||||
* `endsControlFlow` removed erroneous special case when an IterationStatement is passed as argument whose parent is a LabeledStatement.
|
||||
* if you want labels of an IterationStatement (or SwitchStatement) to be handled, you need to pass the LabeledStatement as argument.
|
||||
* :warning: this fix may change the returned value if you relied on the buggy behavior
|
||||
|
||||
**Deprecations:**
|
||||
|
||||
* deprecated overload of `getControlFlowEnd` that contains the `label` parameter. This parameter is no longer used and should no longer be passed to the function.
|
||||
|
||||
# 2.17.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `getControlFlowEnd` and `endsControlFlow` (#22)
|
||||
* ThrowStatements inside `try` are filtered out if there is a `catch` clause
|
||||
* TryStatements with `catch` only end control flow if `try` AND `catch` definitely end control flow
|
||||
|
||||
# 2.17.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `kind` property to `NodeWrap`
|
||||
* added `getControlFlowEnd` to public API
|
||||
|
||||
# 2.16.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `isDecorator` and `isCallLikeExpression` typeguards
|
||||
|
||||
# 2.15.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `convertAst` utility to produce a flattened and wrapped version of the AST
|
||||
|
||||
# 2.14.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added `isDeleteExpression`
|
||||
* added `getLineBreakStyle`
|
||||
|
||||
# 2.13.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* fixed name of `isJsxFragment`
|
||||
|
||||
# 2.13.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added support for `JsxFragment` introduced in typescript@2.6.2
|
||||
* added corresponding typeguard functions
|
||||
|
||||
# 2.12.2
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `endsControlFlow`
|
||||
* added missing logic for labeled statement, iteration statements and try-catch
|
||||
* added missing logic for `break` and `continue` with labels
|
||||
* take all jump statements into account, not only the last statement
|
||||
* `isValidIdentifier` and `isValidNumericLiteral` handle irregular whitespace
|
||||
* `findImports` searches in ambient modules inside regular `.ts` files (not only `.d.ts`)
|
||||
* `canHaveJsDoc` is now a typeguard
|
||||
|
||||
# 2.12.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `forEachTokenWithTrivia`
|
||||
* handles irregular whitespace and no longer visits some tokens twice
|
||||
* correctly calculates the range of JsxText
|
||||
|
||||
# 2.12.0
|
||||
|
||||
**API-Changes:**
|
||||
|
||||
* deprecated `ImportOptions` if favor of the new `ImportKind` enum
|
||||
|
||||
# 2.11.2
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `parseJsDocOfNode`: set correct `pos`, `end` and `parent` properties. Also affects `getJsDoc` of `EndOfFileToken`
|
||||
|
||||
# 2.11.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `collectVariableUsage`: correctly consider catch binding as block scoped declaration inside catch block
|
||||
|
||||
# 2.11.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `getJsDoc` now correctly returns JsDoc for `EndOfFileToken`
|
||||
|
||||
**Features:**
|
||||
|
||||
* added utility `parseJsDocOfNode`
|
||||
|
||||
# 2.10.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added utility `findImports` to find all kinds of imports in a source file
|
||||
|
||||
# 2.9.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* added typeguard `isMappedTypeNode`
|
||||
* added utilities `canHaveJsDoc` and `getJsDoc`
|
||||
|
||||
# 2.8.2
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `collectVariableUsage`: handle global augmentation like other module augmentations
|
||||
|
||||
# 2.8.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* Support `typescript@2.5.1` with optional catch binding
|
||||
* `collectVariableUsage` fixed a bug where method decorator had method's parameters in scope
|
||||
|
||||
# 2.8.0
|
||||
|
||||
* Compatibility with the latest typescript nightly
|
||||
* Added `getIdentifierText` to unescape identifiers across typescript versions
|
||||
|
||||
# 2.7.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isReassignmentTarget` don't return `true` for right side of assignment
|
||||
|
||||
# 2.7.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* Added `isReassignmentTarget` utility
|
||||
|
||||
# 2.6.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `getDeclarationDomain` now returns `undefined` for Parameter in IndexSignature
|
||||
* `collectVariableUsage` ignores Parameter in IndexSignature
|
||||
|
||||
# 2.6.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `collectVariableUsage`:
|
||||
* don't merge imports with global declarations
|
||||
* treat everything in a declaration file as exported if there is no explicit `export {};`
|
||||
* `isExpressionValueUsed`: handle destructuring in `for...of`
|
||||
|
||||
**Features:**
|
||||
|
||||
* Added `getModifier` utility
|
||||
* Added `DeclarationDomain.Import` to distinguish imports from other declarations
|
||||
|
||||
# 2.5.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `collectVariableUsage` ignore jump labels as in `break label;`
|
||||
|
||||
# 2.5.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isFunctionWithBody` handles constructor overload correctly.
|
||||
|
||||
**Features:**
|
||||
|
||||
* Implemented `isExpressionValueUsed` to check whether the result of an expression is actually used.
|
||||
* Implemented `getDeclarationDomain` to determine if a given declaration introduces a new symbol in the value or type domain.
|
||||
|
||||
**`collectVariableUses` is now usable**
|
||||
|
||||
* no longer ignores signatures and its parameters
|
||||
* don't merge declarations and uses across domains
|
||||
* no longer marks exceptions in catch clause or parameter properties as exported
|
||||
* fixed exports of namespaces
|
||||
* fixed scoping of ClassExpression name
|
||||
* correcly handle ambient namespaces and module augmentations
|
||||
* fixed how `: typeof foo` is handled for parameters and function return type
|
||||
* **still WIP**: `export {Foo as Bar}` inside ambient namespaces and modules
|
||||
|
||||
# 2.4.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `getLineRanges`: `contentLength` now contains the correct line length when there are multiple consecutive line break characters
|
||||
* `getTokenAtPosition`: don't match tokens that end at the specified position (because that's already outside of their range)
|
||||
* deprecated the misnamed `isModfierFlagSet`, use the new `isModifierFlagSet` instead
|
||||
|
||||
**Features:**
|
||||
|
||||
* Added typeguard: `isJsDoc`
|
||||
* Added experimental scope and usage analysis (`getUsageDomain` and `collectVariableUsage`)
|
||||
|
||||
# 2.3.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `forEachComment` no longer omits some comments when callback returns a truthy value
|
||||
* `isPositionInComment` fixed false positive inside JSXText
|
||||
|
||||
**Features:**
|
||||
|
||||
* Added utility: `getCommentAtPosition`
|
||||
|
||||
# 2.2.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* Fixed bit value of `SideEffectOptions.JsxElement` to be a power of 2
|
||||
|
||||
**Features:**
|
||||
|
||||
* Added utilities: `getTokenAtPosition` and `isPositionInComment`
|
||||
|
||||
# 2.1.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* Added typeguard `isExpression`
|
||||
* Added utilities: `hasSideEffects`, `getDeclarationOfBindingElement`
|
||||
|
||||
# 2.0.0
|
||||
|
||||
**Breaking Changes:**
|
||||
|
||||
* Dropped compatibility with `typescript@<2.1.0`
|
||||
* Removed misnamed `isNumericliteral`, use `isNumericLiteral` instead (notice the uppercase L)
|
||||
* Removed `isEnumLiteralType` which will cause compile errors with typescript@2.4.0
|
||||
* Refactored directory structure: all imports that referenced subdirectories (e.g. `require('tsutils/src/typeguard')` will be broken
|
||||
|
||||
**Features:**
|
||||
|
||||
* New directory structure allows imports of typeguards or utils independently, e.g. (`require('tsutils/typeguard')`)
|
||||
|
||||
# 1.9.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isObjectFlagSet` now uses the correct `objectFlags` property
|
||||
|
||||
# 1.9.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `getNextToken` no longer omits `EndOfFileToken` when there is no trivia before EOF. That means the only inputs where `getNextToken` returns `undefined` are `SourceFile` and `EndOfFileToken`
|
||||
|
||||
**Features**:
|
||||
|
||||
* Added typeguards for types
|
||||
* Added utilities for flag checking: `isNodeFlagSet`, `isTypeFlagSet`, `isSymbolFlagSet`,`isObjectFlagSet`, `isModifierFlagSet`
|
||||
|
||||
# 1.8.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* Support peer dependency of typescript nightlies of 2.4.0
|
||||
* Added typeguards: `isJsxAttributes`, `isIntersectionTypeNode`, `isTypeOperatorNode`, `isTypePredicateNode`, `isTypeQueryNode`, `isUnionTypeNode`
|
||||
|
||||
# 1.7.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `isFunctionScopeBoundary` now handles Interfaces, TypeAliases, FunctionSignatures, etc
|
||||
|
||||
**Features:**
|
||||
|
||||
* Added utilities: `isThisParameter`, `isSameLine` and `isFunctionWithBody`
|
||||
|
||||
# 1.6.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* Add `isValidPropertyAccess`, `isValidNumericLiteral` and `isValidPropertyName`
|
||||
|
||||
# 1.5.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* Add `isValidIdentifier`
|
||||
|
||||
# 1.4.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* Add `contentLength` property to the result of `getLineRanges`
|
||||
|
||||
# 1.3.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `canHaveLeadingTrivia`:
|
||||
* Fix property access on undefined parent reference
|
||||
* Fixes: [palantir/tslint#2330](https://github.com/palantir/tslint/issues/2330)
|
||||
* `hasOwnThisReference`: now includes accessors on object literals
|
||||
|
||||
**Features:**
|
||||
|
||||
* Typeguards:
|
||||
* isTypeParameterDeclaration
|
||||
* isEnitityName
|
||||
|
||||
# 1.2.2
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* `hasOwnThisReference`:
|
||||
* exclude overload signatures of function declarations
|
||||
* add method declarations on object literals
|
||||
|
||||
# 1.2.1
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* Fix name of `isNumericLiteral`
|
||||
|
||||
# 1.2.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* Typeguards:
|
||||
* isEnumMember
|
||||
* isExpressionWithTypeArguments
|
||||
* isImportSpecifier
|
||||
* Utilities:
|
||||
* isJsDocKind, isTypeNodeKind
|
||||
* Allow typescript@next in peerDependencies
|
||||
|
||||
# 1.1.0
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
* Fix isBlockScopeBoundary: Remove WithStatement, IfStatment, DoStatement and WhileStatement because they are no scope boundary whitout a block.
|
||||
|
||||
**Features:**
|
||||
|
||||
* Added more typeguards:
|
||||
* isAssertionExpression
|
||||
* isEmptyStatement
|
||||
* isJsxAttributeLike
|
||||
* isJsxOpeningLikeElement
|
||||
* isNonNullExpression
|
||||
* isSyntaxList
|
||||
* Utilities:
|
||||
* getNextToken, getPreviousToken
|
||||
* hasOwnThisReference
|
||||
* getLineRanges
|
||||
|
||||
# 1.0.0
|
||||
|
||||
**Features:**
|
||||
|
||||
* Initial implementation of typeguards
|
||||
* Utilities:
|
||||
* getChildOfKind
|
||||
* isNodeKind, isAssignmentKind
|
||||
* hasModifier, isParameterProperty, hasAccessModifier
|
||||
* getPreviousStatement, getNextStatement
|
||||
* getPropertyName
|
||||
* forEachDestructuringIdentifier, forEachDeclaredVariable
|
||||
* getVariableDeclarationKind, isBlockScopedVariableDeclarationList, isBlockScopedVariableDeclaration
|
||||
* isScopeBoundary, isFunctionScopeBoundary, isBlockScopeBoundary
|
||||
* forEachToken, forEachTokenWithTrivia, forEachComment
|
||||
* endsControlFlow
|
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Klaus Meinhardt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -0,0 +1,61 @@
|
||||
# Utility functions for working with typescript's AST
|
||||
|
||||
[](https://greenkeeper.io/)
|
||||
|
||||
## Usage
|
||||
|
||||
This package consists of two major parts: utilities and typeguard functions.
|
||||
By importing the project you will get both of them.
|
||||
```js
|
||||
import * as utils from "tsutils";
|
||||
utils.isIdentifier(node); // typeguard
|
||||
utils.getLineRanges(sourceFile); // utilities
|
||||
```
|
||||
|
||||
If you don't need everything offered by this package, you can select what should be imported. The parts that are not imported are never read from disk and may save some startup time and reduce memory consumtion.
|
||||
|
||||
If you only need typeguards you can explicitly import them:
|
||||
```js
|
||||
import { isIdentifier } from "tsutils/typeguard";
|
||||
// You can even distiguish between typeguards for nodes and types
|
||||
import { isUnionTypeNode } from "tsutils/typeguard/node";
|
||||
import { isUnionType } from "tsutils/typeguard/type";
|
||||
```
|
||||
|
||||
If you only need the utilities you can also explicitly import them:
|
||||
```js
|
||||
import { forEachComment, forEachToken } from "tsutils/util";
|
||||
```
|
||||
|
||||
### Typescript version dependency
|
||||
|
||||
This package is backwards compatible with typescript 2.8.0 at runtime although compiling might need a newer version of typescript installed.
|
||||
|
||||
Using `typescript@next` might work, but it's not officially supported. If you encounter any bugs, please open an issue.
|
||||
|
||||
For compatibility with older versions of TypeScript typeguard functions are separated by TypeScript version. If you are stuck on `typescript@2.8`, you should import directly from the submodule for that version:
|
||||
|
||||
```js
|
||||
// all typeguards compatible with typescript@2.8
|
||||
import { isIdentifier } from "tsutils/typeguard/2.8";
|
||||
// you can even use nested submodules
|
||||
import { isIdentifier } from "tsutils/typeguard/2.8/node";
|
||||
|
||||
// all typeguards compatible with typescript@2.9 (includes those of 2.8)
|
||||
import { isIdentifier } from "tsutils/typeguard/2.9";
|
||||
|
||||
// always points to the latest stable version (2.9 as of writing this)
|
||||
import { isIdentifier } from "tsutils/typeguard";
|
||||
import { isIdentifier } from "tsutils";
|
||||
|
||||
// always points to the typeguards for the next TypeScript version (3.0 as of writing this)
|
||||
import { isIdentifier } from "tsutils/typeguard/next";
|
||||
```
|
||||
|
||||
Note that if you are also using utility functions, you should prefer the relevant submodule:
|
||||
|
||||
```js
|
||||
// importing directly from 'tsutils' would pull in the latest typeguards
|
||||
import { forEachToken } from 'tsutils/util';
|
||||
import { isIdentifier } from 'tsutils/typeguard/2.8';
|
||||
```
|
@ -0,0 +1,2 @@
|
||||
export * from './typeguard';
|
||||
export * from './util';
|
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./typeguard"), exports);
|
||||
tslib_1.__exportStar(require("./util"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,iDAAuB"}
|
@ -0,0 +1,63 @@
|
||||
{
|
||||
"name": "tsutils",
|
||||
"version": "3.21.0",
|
||||
"description": "utilities for working with typescript's AST",
|
||||
"scripts": {
|
||||
"precompile": "rimraf \"{,util,typeguard,test{,/rules}/*.{js,d.ts,js.map}\"",
|
||||
"compile": "ttsc -p .",
|
||||
"lint:tslint": "wotan -m @fimbul/valtyr",
|
||||
"lint:wotan": "wotan",
|
||||
"lint": "run-p lint:*",
|
||||
"test": "mocha test/*Tests.js && tslint --test 'test/rules/**/tslint.json'",
|
||||
"verify": "run-s compile lint coverage",
|
||||
"prepublishOnly": "run-s verify",
|
||||
"coverage": "nyc run-s test",
|
||||
"report-coverage": "cat ./coverage/lcov.info | coveralls",
|
||||
"github-release": "node ./scripts/github-release.js",
|
||||
"postpublish": "git push origin master --tags && run-s github-release"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ajafff/tsutils"
|
||||
},
|
||||
"keywords": [
|
||||
"typescript",
|
||||
"ts",
|
||||
"ast",
|
||||
"typeguard",
|
||||
"utils",
|
||||
"helper",
|
||||
"node"
|
||||
],
|
||||
"author": "Klaus Meinhardt",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@fimbul/mithotyn": "^0.21.0",
|
||||
"@fimbul/valtyr": "^0.22.0",
|
||||
"@fimbul/wotan": "^0.22.0",
|
||||
"@types/chai": "^4.0.10",
|
||||
"@types/mocha": "^5.0.0",
|
||||
"@types/node": "^11.13.0",
|
||||
"chai": "^4.1.2",
|
||||
"coveralls": "^3.0.0",
|
||||
"github-release-from-changelog": "^1.3.0",
|
||||
"mocha": "^6.0.2",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"nyc": "^13.3.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-transform-const-enum": "^0.0.1",
|
||||
"tslint": "^5.8.0",
|
||||
"tslint-consistent-codestyle": "^1.11.0",
|
||||
"ttypescript": "^1.5.5",
|
||||
"typescript": "4.2.0-dev.20201230"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": "^1.8.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
export * from './node';
|
||||
export * from './type';
|
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./node"), exports);
|
||||
tslib_1.__exportStar(require("./type"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,iDAAuB"}
|
@ -0,0 +1,155 @@
|
||||
import * as ts from 'typescript';
|
||||
export declare function isAccessorDeclaration(node: ts.Node): node is ts.AccessorDeclaration;
|
||||
export declare function isArrayBindingPattern(node: ts.Node): node is ts.ArrayBindingPattern;
|
||||
export declare function isArrayLiteralExpression(node: ts.Node): node is ts.ArrayLiteralExpression;
|
||||
export declare function isArrayTypeNode(node: ts.Node): node is ts.ArrayTypeNode;
|
||||
export declare function isArrowFunction(node: ts.Node): node is ts.ArrowFunction;
|
||||
export declare function isAsExpression(node: ts.Node): node is ts.AsExpression;
|
||||
export declare function isAssertionExpression(node: ts.Node): node is ts.AssertionExpression;
|
||||
export declare function isAwaitExpression(node: ts.Node): node is ts.AwaitExpression;
|
||||
export declare function isBinaryExpression(node: ts.Node): node is ts.BinaryExpression;
|
||||
export declare function isBindingElement(node: ts.Node): node is ts.BindingElement;
|
||||
export declare function isBindingPattern(node: ts.Node): node is ts.BindingPattern;
|
||||
export declare function isBlock(node: ts.Node): node is ts.Block;
|
||||
export declare function isBlockLike(node: ts.Node): node is ts.BlockLike;
|
||||
export declare function isBooleanLiteral(node: ts.Node): node is ts.BooleanLiteral;
|
||||
export declare function isBreakOrContinueStatement(node: ts.Node): node is ts.BreakOrContinueStatement;
|
||||
export declare function isBreakStatement(node: ts.Node): node is ts.BreakStatement;
|
||||
export declare function isCallExpression(node: ts.Node): node is ts.CallExpression;
|
||||
export declare function isCallLikeExpression(node: ts.Node): node is ts.CallLikeExpression;
|
||||
export declare function isCallSignatureDeclaration(node: ts.Node): node is ts.CallSignatureDeclaration;
|
||||
export declare function isCaseBlock(node: ts.Node): node is ts.CaseBlock;
|
||||
export declare function isCaseClause(node: ts.Node): node is ts.CaseClause;
|
||||
export declare function isCaseOrDefaultClause(node: ts.Node): node is ts.CaseOrDefaultClause;
|
||||
export declare function isCatchClause(node: ts.Node): node is ts.CatchClause;
|
||||
export declare function isClassDeclaration(node: ts.Node): node is ts.ClassDeclaration;
|
||||
export declare function isClassExpression(node: ts.Node): node is ts.ClassExpression;
|
||||
export declare function isClassLikeDeclaration(node: ts.Node): node is ts.ClassLikeDeclaration;
|
||||
export declare function isCommaListExpression(node: ts.Node): node is ts.CommaListExpression;
|
||||
export declare function isConditionalExpression(node: ts.Node): node is ts.ConditionalExpression;
|
||||
export declare function isConditionalTypeNode(node: ts.Node): node is ts.ConditionalTypeNode;
|
||||
export declare function isConstructorDeclaration(node: ts.Node): node is ts.ConstructorDeclaration;
|
||||
export declare function isConstructorTypeNode(node: ts.Node): node is ts.ConstructorTypeNode;
|
||||
export declare function isConstructSignatureDeclaration(node: ts.Node): node is ts.ConstructSignatureDeclaration;
|
||||
export declare function isContinueStatement(node: ts.Node): node is ts.ContinueStatement;
|
||||
export declare function isComputedPropertyName(node: ts.Node): node is ts.ComputedPropertyName;
|
||||
export declare function isDebuggerStatement(node: ts.Node): node is ts.DebuggerStatement;
|
||||
export declare function isDecorator(node: ts.Node): node is ts.Decorator;
|
||||
export declare function isDefaultClause(node: ts.Node): node is ts.DefaultClause;
|
||||
export declare function isDeleteExpression(node: ts.Node): node is ts.DeleteExpression;
|
||||
export declare function isDoStatement(node: ts.Node): node is ts.DoStatement;
|
||||
export declare function isElementAccessExpression(node: ts.Node): node is ts.ElementAccessExpression;
|
||||
export declare function isEmptyStatement(node: ts.Node): node is ts.EmptyStatement;
|
||||
export declare function isEntityName(node: ts.Node): node is ts.EntityName;
|
||||
export declare function isEntityNameExpression(node: ts.Node): node is ts.EntityNameExpression;
|
||||
export declare function isEnumDeclaration(node: ts.Node): node is ts.EnumDeclaration;
|
||||
export declare function isEnumMember(node: ts.Node): node is ts.EnumMember;
|
||||
export declare function isExportAssignment(node: ts.Node): node is ts.ExportAssignment;
|
||||
export declare function isExportDeclaration(node: ts.Node): node is ts.ExportDeclaration;
|
||||
export declare function isExportSpecifier(node: ts.Node): node is ts.ExportSpecifier;
|
||||
export declare function isExpression(node: ts.Node): node is ts.Expression;
|
||||
export declare function isExpressionStatement(node: ts.Node): node is ts.ExpressionStatement;
|
||||
export declare function isExpressionWithTypeArguments(node: ts.Node): node is ts.ExpressionWithTypeArguments;
|
||||
export declare function isExternalModuleReference(node: ts.Node): node is ts.ExternalModuleReference;
|
||||
export declare function isForInStatement(node: ts.Node): node is ts.ForInStatement;
|
||||
export declare function isForInOrOfStatement(node: ts.Node): node is ts.ForInOrOfStatement;
|
||||
export declare function isForOfStatement(node: ts.Node): node is ts.ForOfStatement;
|
||||
export declare function isForStatement(node: ts.Node): node is ts.ForStatement;
|
||||
export declare function isFunctionDeclaration(node: ts.Node): node is ts.FunctionDeclaration;
|
||||
export declare function isFunctionExpression(node: ts.Node): node is ts.FunctionExpression;
|
||||
export declare function isFunctionTypeNode(node: ts.Node): node is ts.FunctionTypeNode;
|
||||
export declare function isGetAccessorDeclaration(node: ts.Node): node is ts.GetAccessorDeclaration;
|
||||
export declare function isIdentifier(node: ts.Node): node is ts.Identifier;
|
||||
export declare function isIfStatement(node: ts.Node): node is ts.IfStatement;
|
||||
export declare function isImportClause(node: ts.Node): node is ts.ImportClause;
|
||||
export declare function isImportDeclaration(node: ts.Node): node is ts.ImportDeclaration;
|
||||
export declare function isImportEqualsDeclaration(node: ts.Node): node is ts.ImportEqualsDeclaration;
|
||||
export declare function isImportSpecifier(node: ts.Node): node is ts.ImportSpecifier;
|
||||
export declare function isIndexedAccessTypeNode(node: ts.Node): node is ts.IndexedAccessTypeNode;
|
||||
export declare function isIndexSignatureDeclaration(node: ts.Node): node is ts.IndexSignatureDeclaration;
|
||||
export declare function isInferTypeNode(node: ts.Node): node is ts.InferTypeNode;
|
||||
export declare function isInterfaceDeclaration(node: ts.Node): node is ts.InterfaceDeclaration;
|
||||
export declare function isIntersectionTypeNode(node: ts.Node): node is ts.IntersectionTypeNode;
|
||||
export declare function isIterationStatement(node: ts.Node): node is ts.IterationStatement;
|
||||
export declare function isJsDoc(node: ts.Node): node is ts.JSDoc;
|
||||
export declare function isJsxAttribute(node: ts.Node): node is ts.JsxAttribute;
|
||||
export declare function isJsxAttributeLike(node: ts.Node): node is ts.JsxAttributeLike;
|
||||
export declare function isJsxAttributes(node: ts.Node): node is ts.JsxAttributes;
|
||||
export declare function isJsxClosingElement(node: ts.Node): node is ts.JsxClosingElement;
|
||||
export declare function isJsxClosingFragment(node: ts.Node): node is ts.JsxClosingFragment;
|
||||
export declare function isJsxElement(node: ts.Node): node is ts.JsxElement;
|
||||
export declare function isJsxExpression(node: ts.Node): node is ts.JsxExpression;
|
||||
export declare function isJsxFragment(node: ts.Node): node is ts.JsxFragment;
|
||||
export declare function isJsxOpeningElement(node: ts.Node): node is ts.JsxOpeningElement;
|
||||
export declare function isJsxOpeningFragment(node: ts.Node): node is ts.JsxOpeningFragment;
|
||||
export declare function isJsxOpeningLikeElement(node: ts.Node): node is ts.JsxOpeningLikeElement;
|
||||
export declare function isJsxSelfClosingElement(node: ts.Node): node is ts.JsxSelfClosingElement;
|
||||
export declare function isJsxSpreadAttribute(node: ts.Node): node is ts.JsxSpreadAttribute;
|
||||
export declare function isJsxText(node: ts.Node): node is ts.JsxText;
|
||||
export declare function isLabeledStatement(node: ts.Node): node is ts.LabeledStatement;
|
||||
export declare function isLiteralExpression(node: ts.Node): node is ts.LiteralExpression;
|
||||
export declare function isLiteralTypeNode(node: ts.Node): node is ts.LiteralTypeNode;
|
||||
export declare function isMappedTypeNode(node: ts.Node): node is ts.MappedTypeNode;
|
||||
export declare function isMetaProperty(node: ts.Node): node is ts.MetaProperty;
|
||||
export declare function isMethodDeclaration(node: ts.Node): node is ts.MethodDeclaration;
|
||||
export declare function isMethodSignature(node: ts.Node): node is ts.MethodSignature;
|
||||
export declare function isModuleBlock(node: ts.Node): node is ts.ModuleBlock;
|
||||
export declare function isModuleDeclaration(node: ts.Node): node is ts.ModuleDeclaration;
|
||||
export declare function isNamedExports(node: ts.Node): node is ts.NamedExports;
|
||||
export declare function isNamedImports(node: ts.Node): node is ts.NamedImports;
|
||||
export declare function isNamespaceDeclaration(node: ts.Node): node is ts.NamespaceDeclaration;
|
||||
export declare function isNamespaceImport(node: ts.Node): node is ts.NamespaceImport;
|
||||
export declare function isNamespaceExportDeclaration(node: ts.Node): node is ts.NamespaceExportDeclaration;
|
||||
export declare function isNewExpression(node: ts.Node): node is ts.NewExpression;
|
||||
export declare function isNonNullExpression(node: ts.Node): node is ts.NonNullExpression;
|
||||
export declare function isNoSubstitutionTemplateLiteral(node: ts.Node): node is ts.NoSubstitutionTemplateLiteral;
|
||||
export declare function isNullLiteral(node: ts.Node): node is ts.NullLiteral;
|
||||
export declare function isNumericLiteral(node: ts.Node): node is ts.NumericLiteral;
|
||||
export declare function isNumericOrStringLikeLiteral(node: ts.Node): node is ts.NumericLiteral | ts.StringLiteral | ts.NoSubstitutionTemplateLiteral;
|
||||
export declare function isObjectBindingPattern(node: ts.Node): node is ts.ObjectBindingPattern;
|
||||
export declare function isObjectLiteralExpression(node: ts.Node): node is ts.ObjectLiteralExpression;
|
||||
export declare function isOmittedExpression(node: ts.Node): node is ts.OmittedExpression;
|
||||
export declare function isParameterDeclaration(node: ts.Node): node is ts.ParameterDeclaration;
|
||||
export declare function isParenthesizedExpression(node: ts.Node): node is ts.ParenthesizedExpression;
|
||||
export declare function isParenthesizedTypeNode(node: ts.Node): node is ts.ParenthesizedTypeNode;
|
||||
export declare function isPostfixUnaryExpression(node: ts.Node): node is ts.PostfixUnaryExpression;
|
||||
export declare function isPrefixUnaryExpression(node: ts.Node): node is ts.PrefixUnaryExpression;
|
||||
export declare function isPropertyAccessExpression(node: ts.Node): node is ts.PropertyAccessExpression;
|
||||
export declare function isPropertyAssignment(node: ts.Node): node is ts.PropertyAssignment;
|
||||
export declare function isPropertyDeclaration(node: ts.Node): node is ts.PropertyDeclaration;
|
||||
export declare function isPropertySignature(node: ts.Node): node is ts.PropertySignature;
|
||||
export declare function isQualifiedName(node: ts.Node): node is ts.QualifiedName;
|
||||
export declare function isRegularExpressionLiteral(node: ts.Node): node is ts.RegularExpressionLiteral;
|
||||
export declare function isReturnStatement(node: ts.Node): node is ts.ReturnStatement;
|
||||
export declare function isSetAccessorDeclaration(node: ts.Node): node is ts.SetAccessorDeclaration;
|
||||
export declare function isShorthandPropertyAssignment(node: ts.Node): node is ts.ShorthandPropertyAssignment;
|
||||
export declare function isSignatureDeclaration(node: ts.Node): node is ts.SignatureDeclaration;
|
||||
export declare function isSourceFile(node: ts.Node): node is ts.SourceFile;
|
||||
export declare function isSpreadAssignment(node: ts.Node): node is ts.SpreadAssignment;
|
||||
export declare function isSpreadElement(node: ts.Node): node is ts.SpreadElement;
|
||||
export declare function isStringLiteral(node: ts.Node): node is ts.StringLiteral;
|
||||
export declare function isSwitchStatement(node: ts.Node): node is ts.SwitchStatement;
|
||||
export declare function isSyntaxList(node: ts.Node): node is ts.SyntaxList;
|
||||
export declare function isTaggedTemplateExpression(node: ts.Node): node is ts.TaggedTemplateExpression;
|
||||
export declare function isTemplateExpression(node: ts.Node): node is ts.TemplateExpression;
|
||||
export declare function isTemplateLiteral(node: ts.Node): node is ts.TemplateLiteral;
|
||||
export declare function isTextualLiteral(node: ts.Node): node is ts.StringLiteral | ts.NoSubstitutionTemplateLiteral;
|
||||
export declare function isThrowStatement(node: ts.Node): node is ts.ThrowStatement;
|
||||
export declare function isTryStatement(node: ts.Node): node is ts.TryStatement;
|
||||
export declare function isTupleTypeNode(node: ts.Node): node is ts.TupleTypeNode;
|
||||
export declare function isTypeAliasDeclaration(node: ts.Node): node is ts.TypeAliasDeclaration;
|
||||
export declare function isTypeAssertion(node: ts.Node): node is ts.TypeAssertion;
|
||||
export declare function isTypeLiteralNode(node: ts.Node): node is ts.TypeLiteralNode;
|
||||
export declare function isTypeOfExpression(node: ts.Node): node is ts.TypeOfExpression;
|
||||
export declare function isTypeOperatorNode(node: ts.Node): node is ts.TypeOperatorNode;
|
||||
export declare function isTypeParameterDeclaration(node: ts.Node): node is ts.TypeParameterDeclaration;
|
||||
export declare function isTypePredicateNode(node: ts.Node): node is ts.TypePredicateNode;
|
||||
export declare function isTypeReferenceNode(node: ts.Node): node is ts.TypeReferenceNode;
|
||||
export declare function isTypeQueryNode(node: ts.Node): node is ts.TypeQueryNode;
|
||||
export declare function isUnionTypeNode(node: ts.Node): node is ts.UnionTypeNode;
|
||||
export declare function isVariableDeclaration(node: ts.Node): node is ts.VariableDeclaration;
|
||||
export declare function isVariableStatement(node: ts.Node): node is ts.VariableStatement;
|
||||
export declare function isVariableDeclarationList(node: ts.Node): node is ts.VariableDeclarationList;
|
||||
export declare function isVoidExpression(node: ts.Node): node is ts.VoidExpression;
|
||||
export declare function isWhileStatement(node: ts.Node): node is ts.WhileStatement;
|
||||
export declare function isWithStatement(node: ts.Node): node is ts.WithStatement;
|
@ -0,0 +1,714 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isExpressionStatement = exports.isExpression = exports.isExportSpecifier = exports.isExportDeclaration = exports.isExportAssignment = exports.isEnumMember = exports.isEnumDeclaration = exports.isEntityNameExpression = exports.isEntityName = exports.isEmptyStatement = exports.isElementAccessExpression = exports.isDoStatement = exports.isDeleteExpression = exports.isDefaultClause = exports.isDecorator = exports.isDebuggerStatement = exports.isComputedPropertyName = exports.isContinueStatement = exports.isConstructSignatureDeclaration = exports.isConstructorTypeNode = exports.isConstructorDeclaration = exports.isConditionalTypeNode = exports.isConditionalExpression = exports.isCommaListExpression = exports.isClassLikeDeclaration = exports.isClassExpression = exports.isClassDeclaration = exports.isCatchClause = exports.isCaseOrDefaultClause = exports.isCaseClause = exports.isCaseBlock = exports.isCallSignatureDeclaration = exports.isCallLikeExpression = exports.isCallExpression = exports.isBreakStatement = exports.isBreakOrContinueStatement = exports.isBooleanLiteral = exports.isBlockLike = exports.isBlock = exports.isBindingPattern = exports.isBindingElement = exports.isBinaryExpression = exports.isAwaitExpression = exports.isAssertionExpression = exports.isAsExpression = exports.isArrowFunction = exports.isArrayTypeNode = exports.isArrayLiteralExpression = exports.isArrayBindingPattern = exports.isAccessorDeclaration = void 0;
|
||||
exports.isNamespaceImport = exports.isNamespaceDeclaration = exports.isNamedImports = exports.isNamedExports = exports.isModuleDeclaration = exports.isModuleBlock = exports.isMethodSignature = exports.isMethodDeclaration = exports.isMetaProperty = exports.isMappedTypeNode = exports.isLiteralTypeNode = exports.isLiteralExpression = exports.isLabeledStatement = exports.isJsxText = exports.isJsxSpreadAttribute = exports.isJsxSelfClosingElement = exports.isJsxOpeningLikeElement = exports.isJsxOpeningFragment = exports.isJsxOpeningElement = exports.isJsxFragment = exports.isJsxExpression = exports.isJsxElement = exports.isJsxClosingFragment = exports.isJsxClosingElement = exports.isJsxAttributes = exports.isJsxAttributeLike = exports.isJsxAttribute = exports.isJsDoc = exports.isIterationStatement = exports.isIntersectionTypeNode = exports.isInterfaceDeclaration = exports.isInferTypeNode = exports.isIndexSignatureDeclaration = exports.isIndexedAccessTypeNode = exports.isImportSpecifier = exports.isImportEqualsDeclaration = exports.isImportDeclaration = exports.isImportClause = exports.isIfStatement = exports.isIdentifier = exports.isGetAccessorDeclaration = exports.isFunctionTypeNode = exports.isFunctionExpression = exports.isFunctionDeclaration = exports.isForStatement = exports.isForOfStatement = exports.isForInOrOfStatement = exports.isForInStatement = exports.isExternalModuleReference = exports.isExpressionWithTypeArguments = void 0;
|
||||
exports.isVariableStatement = exports.isVariableDeclaration = exports.isUnionTypeNode = exports.isTypeQueryNode = exports.isTypeReferenceNode = exports.isTypePredicateNode = exports.isTypeParameterDeclaration = exports.isTypeOperatorNode = exports.isTypeOfExpression = exports.isTypeLiteralNode = exports.isTypeAssertion = exports.isTypeAliasDeclaration = exports.isTupleTypeNode = exports.isTryStatement = exports.isThrowStatement = exports.isTextualLiteral = exports.isTemplateLiteral = exports.isTemplateExpression = exports.isTaggedTemplateExpression = exports.isSyntaxList = exports.isSwitchStatement = exports.isStringLiteral = exports.isSpreadElement = exports.isSpreadAssignment = exports.isSourceFile = exports.isSignatureDeclaration = exports.isShorthandPropertyAssignment = exports.isSetAccessorDeclaration = exports.isReturnStatement = exports.isRegularExpressionLiteral = exports.isQualifiedName = exports.isPropertySignature = exports.isPropertyDeclaration = exports.isPropertyAssignment = exports.isPropertyAccessExpression = exports.isPrefixUnaryExpression = exports.isPostfixUnaryExpression = exports.isParenthesizedTypeNode = exports.isParenthesizedExpression = exports.isParameterDeclaration = exports.isOmittedExpression = exports.isObjectLiteralExpression = exports.isObjectBindingPattern = exports.isNumericOrStringLikeLiteral = exports.isNumericLiteral = exports.isNullLiteral = exports.isNoSubstitutionTemplateLiteral = exports.isNonNullExpression = exports.isNewExpression = exports.isNamespaceExportDeclaration = void 0;
|
||||
exports.isWithStatement = exports.isWhileStatement = exports.isVoidExpression = exports.isVariableDeclarationList = void 0;
|
||||
const ts = require("typescript");
|
||||
function isAccessorDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.GetAccessor ||
|
||||
node.kind === ts.SyntaxKind.SetAccessor;
|
||||
}
|
||||
exports.isAccessorDeclaration = isAccessorDeclaration;
|
||||
function isArrayBindingPattern(node) {
|
||||
return node.kind === ts.SyntaxKind.ArrayBindingPattern;
|
||||
}
|
||||
exports.isArrayBindingPattern = isArrayBindingPattern;
|
||||
function isArrayLiteralExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.ArrayLiteralExpression;
|
||||
}
|
||||
exports.isArrayLiteralExpression = isArrayLiteralExpression;
|
||||
function isArrayTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.ArrayType;
|
||||
}
|
||||
exports.isArrayTypeNode = isArrayTypeNode;
|
||||
function isArrowFunction(node) {
|
||||
return node.kind === ts.SyntaxKind.ArrowFunction;
|
||||
}
|
||||
exports.isArrowFunction = isArrowFunction;
|
||||
function isAsExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.AsExpression;
|
||||
}
|
||||
exports.isAsExpression = isAsExpression;
|
||||
function isAssertionExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.AsExpression ||
|
||||
node.kind === ts.SyntaxKind.TypeAssertionExpression;
|
||||
}
|
||||
exports.isAssertionExpression = isAssertionExpression;
|
||||
function isAwaitExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.AwaitExpression;
|
||||
}
|
||||
exports.isAwaitExpression = isAwaitExpression;
|
||||
function isBinaryExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.BinaryExpression;
|
||||
}
|
||||
exports.isBinaryExpression = isBinaryExpression;
|
||||
function isBindingElement(node) {
|
||||
return node.kind === ts.SyntaxKind.BindingElement;
|
||||
}
|
||||
exports.isBindingElement = isBindingElement;
|
||||
function isBindingPattern(node) {
|
||||
return node.kind === ts.SyntaxKind.ArrayBindingPattern ||
|
||||
node.kind === ts.SyntaxKind.ObjectBindingPattern;
|
||||
}
|
||||
exports.isBindingPattern = isBindingPattern;
|
||||
function isBlock(node) {
|
||||
return node.kind === ts.SyntaxKind.Block;
|
||||
}
|
||||
exports.isBlock = isBlock;
|
||||
function isBlockLike(node) {
|
||||
return node.statements !== undefined;
|
||||
}
|
||||
exports.isBlockLike = isBlockLike;
|
||||
function isBooleanLiteral(node) {
|
||||
return node.kind === ts.SyntaxKind.TrueKeyword || node.kind === ts.SyntaxKind.FalseKeyword;
|
||||
}
|
||||
exports.isBooleanLiteral = isBooleanLiteral;
|
||||
function isBreakOrContinueStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.BreakStatement ||
|
||||
node.kind === ts.SyntaxKind.ContinueStatement;
|
||||
}
|
||||
exports.isBreakOrContinueStatement = isBreakOrContinueStatement;
|
||||
function isBreakStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.BreakStatement;
|
||||
}
|
||||
exports.isBreakStatement = isBreakStatement;
|
||||
function isCallExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.CallExpression;
|
||||
}
|
||||
exports.isCallExpression = isCallExpression;
|
||||
function isCallLikeExpression(node) {
|
||||
switch (node.kind) {
|
||||
case ts.SyntaxKind.CallExpression:
|
||||
case ts.SyntaxKind.Decorator:
|
||||
case ts.SyntaxKind.JsxOpeningElement:
|
||||
case ts.SyntaxKind.JsxSelfClosingElement:
|
||||
case ts.SyntaxKind.NewExpression:
|
||||
case ts.SyntaxKind.TaggedTemplateExpression:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.isCallLikeExpression = isCallLikeExpression;
|
||||
function isCallSignatureDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.CallSignature;
|
||||
}
|
||||
exports.isCallSignatureDeclaration = isCallSignatureDeclaration;
|
||||
function isCaseBlock(node) {
|
||||
return node.kind === ts.SyntaxKind.CaseBlock;
|
||||
}
|
||||
exports.isCaseBlock = isCaseBlock;
|
||||
function isCaseClause(node) {
|
||||
return node.kind === ts.SyntaxKind.CaseClause;
|
||||
}
|
||||
exports.isCaseClause = isCaseClause;
|
||||
function isCaseOrDefaultClause(node) {
|
||||
return node.kind === ts.SyntaxKind.CaseClause ||
|
||||
node.kind === ts.SyntaxKind.DefaultClause;
|
||||
}
|
||||
exports.isCaseOrDefaultClause = isCaseOrDefaultClause;
|
||||
function isCatchClause(node) {
|
||||
return node.kind === ts.SyntaxKind.CatchClause;
|
||||
}
|
||||
exports.isCatchClause = isCatchClause;
|
||||
function isClassDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.ClassDeclaration;
|
||||
}
|
||||
exports.isClassDeclaration = isClassDeclaration;
|
||||
function isClassExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.ClassExpression;
|
||||
}
|
||||
exports.isClassExpression = isClassExpression;
|
||||
function isClassLikeDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.ClassDeclaration ||
|
||||
node.kind === ts.SyntaxKind.ClassExpression;
|
||||
}
|
||||
exports.isClassLikeDeclaration = isClassLikeDeclaration;
|
||||
function isCommaListExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.CommaListExpression;
|
||||
}
|
||||
exports.isCommaListExpression = isCommaListExpression;
|
||||
function isConditionalExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.ConditionalExpression;
|
||||
}
|
||||
exports.isConditionalExpression = isConditionalExpression;
|
||||
function isConditionalTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.ConditionalType;
|
||||
}
|
||||
exports.isConditionalTypeNode = isConditionalTypeNode;
|
||||
function isConstructorDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.Constructor;
|
||||
}
|
||||
exports.isConstructorDeclaration = isConstructorDeclaration;
|
||||
function isConstructorTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.ConstructorType;
|
||||
}
|
||||
exports.isConstructorTypeNode = isConstructorTypeNode;
|
||||
function isConstructSignatureDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.ConstructSignature;
|
||||
}
|
||||
exports.isConstructSignatureDeclaration = isConstructSignatureDeclaration;
|
||||
function isContinueStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.ContinueStatement;
|
||||
}
|
||||
exports.isContinueStatement = isContinueStatement;
|
||||
function isComputedPropertyName(node) {
|
||||
return node.kind === ts.SyntaxKind.ComputedPropertyName;
|
||||
}
|
||||
exports.isComputedPropertyName = isComputedPropertyName;
|
||||
function isDebuggerStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.DebuggerStatement;
|
||||
}
|
||||
exports.isDebuggerStatement = isDebuggerStatement;
|
||||
function isDecorator(node) {
|
||||
return node.kind === ts.SyntaxKind.Decorator;
|
||||
}
|
||||
exports.isDecorator = isDecorator;
|
||||
function isDefaultClause(node) {
|
||||
return node.kind === ts.SyntaxKind.DefaultClause;
|
||||
}
|
||||
exports.isDefaultClause = isDefaultClause;
|
||||
function isDeleteExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.DeleteExpression;
|
||||
}
|
||||
exports.isDeleteExpression = isDeleteExpression;
|
||||
function isDoStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.DoStatement;
|
||||
}
|
||||
exports.isDoStatement = isDoStatement;
|
||||
function isElementAccessExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.ElementAccessExpression;
|
||||
}
|
||||
exports.isElementAccessExpression = isElementAccessExpression;
|
||||
function isEmptyStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.EmptyStatement;
|
||||
}
|
||||
exports.isEmptyStatement = isEmptyStatement;
|
||||
function isEntityName(node) {
|
||||
return node.kind === ts.SyntaxKind.Identifier || isQualifiedName(node);
|
||||
}
|
||||
exports.isEntityName = isEntityName;
|
||||
function isEntityNameExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.Identifier ||
|
||||
isPropertyAccessExpression(node) && isEntityNameExpression(node.expression);
|
||||
}
|
||||
exports.isEntityNameExpression = isEntityNameExpression;
|
||||
function isEnumDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.EnumDeclaration;
|
||||
}
|
||||
exports.isEnumDeclaration = isEnumDeclaration;
|
||||
function isEnumMember(node) {
|
||||
return node.kind === ts.SyntaxKind.EnumMember;
|
||||
}
|
||||
exports.isEnumMember = isEnumMember;
|
||||
function isExportAssignment(node) {
|
||||
return node.kind === ts.SyntaxKind.ExportAssignment;
|
||||
}
|
||||
exports.isExportAssignment = isExportAssignment;
|
||||
function isExportDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.ExportDeclaration;
|
||||
}
|
||||
exports.isExportDeclaration = isExportDeclaration;
|
||||
function isExportSpecifier(node) {
|
||||
return node.kind === ts.SyntaxKind.ExportSpecifier;
|
||||
}
|
||||
exports.isExportSpecifier = isExportSpecifier;
|
||||
function isExpression(node) {
|
||||
switch (node.kind) {
|
||||
case ts.SyntaxKind.ArrayLiteralExpression:
|
||||
case ts.SyntaxKind.ArrowFunction:
|
||||
case ts.SyntaxKind.AsExpression:
|
||||
case ts.SyntaxKind.AwaitExpression:
|
||||
case ts.SyntaxKind.BinaryExpression:
|
||||
case ts.SyntaxKind.CallExpression:
|
||||
case ts.SyntaxKind.ClassExpression:
|
||||
case ts.SyntaxKind.CommaListExpression:
|
||||
case ts.SyntaxKind.ConditionalExpression:
|
||||
case ts.SyntaxKind.DeleteExpression:
|
||||
case ts.SyntaxKind.ElementAccessExpression:
|
||||
case ts.SyntaxKind.FalseKeyword:
|
||||
case ts.SyntaxKind.FunctionExpression:
|
||||
case ts.SyntaxKind.Identifier:
|
||||
case ts.SyntaxKind.JsxElement:
|
||||
case ts.SyntaxKind.JsxFragment:
|
||||
case ts.SyntaxKind.JsxExpression:
|
||||
case ts.SyntaxKind.JsxOpeningElement:
|
||||
case ts.SyntaxKind.JsxOpeningFragment:
|
||||
case ts.SyntaxKind.JsxSelfClosingElement:
|
||||
case ts.SyntaxKind.MetaProperty:
|
||||
case ts.SyntaxKind.NewExpression:
|
||||
case ts.SyntaxKind.NonNullExpression:
|
||||
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case ts.SyntaxKind.NullKeyword:
|
||||
case ts.SyntaxKind.NumericLiteral:
|
||||
case ts.SyntaxKind.ObjectLiteralExpression:
|
||||
case ts.SyntaxKind.OmittedExpression:
|
||||
case ts.SyntaxKind.ParenthesizedExpression:
|
||||
case ts.SyntaxKind.PostfixUnaryExpression:
|
||||
case ts.SyntaxKind.PrefixUnaryExpression:
|
||||
case ts.SyntaxKind.PropertyAccessExpression:
|
||||
case ts.SyntaxKind.RegularExpressionLiteral:
|
||||
case ts.SyntaxKind.SpreadElement:
|
||||
case ts.SyntaxKind.StringLiteral:
|
||||
case ts.SyntaxKind.SuperKeyword:
|
||||
case ts.SyntaxKind.TaggedTemplateExpression:
|
||||
case ts.SyntaxKind.TemplateExpression:
|
||||
case ts.SyntaxKind.ThisKeyword:
|
||||
case ts.SyntaxKind.TrueKeyword:
|
||||
case ts.SyntaxKind.TypeAssertionExpression:
|
||||
case ts.SyntaxKind.TypeOfExpression:
|
||||
case ts.SyntaxKind.VoidExpression:
|
||||
case ts.SyntaxKind.YieldExpression:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.isExpression = isExpression;
|
||||
function isExpressionStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.ExpressionStatement;
|
||||
}
|
||||
exports.isExpressionStatement = isExpressionStatement;
|
||||
function isExpressionWithTypeArguments(node) {
|
||||
return node.kind === ts.SyntaxKind.ExpressionWithTypeArguments;
|
||||
}
|
||||
exports.isExpressionWithTypeArguments = isExpressionWithTypeArguments;
|
||||
function isExternalModuleReference(node) {
|
||||
return node.kind === ts.SyntaxKind.ExternalModuleReference;
|
||||
}
|
||||
exports.isExternalModuleReference = isExternalModuleReference;
|
||||
function isForInStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.ForInStatement;
|
||||
}
|
||||
exports.isForInStatement = isForInStatement;
|
||||
function isForInOrOfStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.ForOfStatement || node.kind === ts.SyntaxKind.ForInStatement;
|
||||
}
|
||||
exports.isForInOrOfStatement = isForInOrOfStatement;
|
||||
function isForOfStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.ForOfStatement;
|
||||
}
|
||||
exports.isForOfStatement = isForOfStatement;
|
||||
function isForStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.ForStatement;
|
||||
}
|
||||
exports.isForStatement = isForStatement;
|
||||
function isFunctionDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.FunctionDeclaration;
|
||||
}
|
||||
exports.isFunctionDeclaration = isFunctionDeclaration;
|
||||
function isFunctionExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.FunctionExpression;
|
||||
}
|
||||
exports.isFunctionExpression = isFunctionExpression;
|
||||
function isFunctionTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.FunctionType;
|
||||
}
|
||||
exports.isFunctionTypeNode = isFunctionTypeNode;
|
||||
function isGetAccessorDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.GetAccessor;
|
||||
}
|
||||
exports.isGetAccessorDeclaration = isGetAccessorDeclaration;
|
||||
function isIdentifier(node) {
|
||||
return node.kind === ts.SyntaxKind.Identifier;
|
||||
}
|
||||
exports.isIdentifier = isIdentifier;
|
||||
function isIfStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.IfStatement;
|
||||
}
|
||||
exports.isIfStatement = isIfStatement;
|
||||
function isImportClause(node) {
|
||||
return node.kind === ts.SyntaxKind.ImportClause;
|
||||
}
|
||||
exports.isImportClause = isImportClause;
|
||||
function isImportDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.ImportDeclaration;
|
||||
}
|
||||
exports.isImportDeclaration = isImportDeclaration;
|
||||
function isImportEqualsDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.ImportEqualsDeclaration;
|
||||
}
|
||||
exports.isImportEqualsDeclaration = isImportEqualsDeclaration;
|
||||
function isImportSpecifier(node) {
|
||||
return node.kind === ts.SyntaxKind.ImportSpecifier;
|
||||
}
|
||||
exports.isImportSpecifier = isImportSpecifier;
|
||||
function isIndexedAccessTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.IndexedAccessType;
|
||||
}
|
||||
exports.isIndexedAccessTypeNode = isIndexedAccessTypeNode;
|
||||
function isIndexSignatureDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.IndexSignature;
|
||||
}
|
||||
exports.isIndexSignatureDeclaration = isIndexSignatureDeclaration;
|
||||
function isInferTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.InferType;
|
||||
}
|
||||
exports.isInferTypeNode = isInferTypeNode;
|
||||
function isInterfaceDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.InterfaceDeclaration;
|
||||
}
|
||||
exports.isInterfaceDeclaration = isInterfaceDeclaration;
|
||||
function isIntersectionTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.IntersectionType;
|
||||
}
|
||||
exports.isIntersectionTypeNode = isIntersectionTypeNode;
|
||||
function isIterationStatement(node) {
|
||||
switch (node.kind) {
|
||||
case ts.SyntaxKind.ForStatement:
|
||||
case ts.SyntaxKind.ForOfStatement:
|
||||
case ts.SyntaxKind.ForInStatement:
|
||||
case ts.SyntaxKind.WhileStatement:
|
||||
case ts.SyntaxKind.DoStatement:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.isIterationStatement = isIterationStatement;
|
||||
function isJsDoc(node) {
|
||||
return node.kind === ts.SyntaxKind.JSDocComment;
|
||||
}
|
||||
exports.isJsDoc = isJsDoc;
|
||||
function isJsxAttribute(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxAttribute;
|
||||
}
|
||||
exports.isJsxAttribute = isJsxAttribute;
|
||||
function isJsxAttributeLike(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxAttribute ||
|
||||
node.kind === ts.SyntaxKind.JsxSpreadAttribute;
|
||||
}
|
||||
exports.isJsxAttributeLike = isJsxAttributeLike;
|
||||
function isJsxAttributes(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxAttributes;
|
||||
}
|
||||
exports.isJsxAttributes = isJsxAttributes;
|
||||
function isJsxClosingElement(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxClosingElement;
|
||||
}
|
||||
exports.isJsxClosingElement = isJsxClosingElement;
|
||||
function isJsxClosingFragment(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxClosingFragment;
|
||||
}
|
||||
exports.isJsxClosingFragment = isJsxClosingFragment;
|
||||
function isJsxElement(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxElement;
|
||||
}
|
||||
exports.isJsxElement = isJsxElement;
|
||||
function isJsxExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxExpression;
|
||||
}
|
||||
exports.isJsxExpression = isJsxExpression;
|
||||
function isJsxFragment(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxFragment;
|
||||
}
|
||||
exports.isJsxFragment = isJsxFragment;
|
||||
function isJsxOpeningElement(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxOpeningElement;
|
||||
}
|
||||
exports.isJsxOpeningElement = isJsxOpeningElement;
|
||||
function isJsxOpeningFragment(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxOpeningFragment;
|
||||
}
|
||||
exports.isJsxOpeningFragment = isJsxOpeningFragment;
|
||||
function isJsxOpeningLikeElement(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxOpeningElement ||
|
||||
node.kind === ts.SyntaxKind.JsxSelfClosingElement;
|
||||
}
|
||||
exports.isJsxOpeningLikeElement = isJsxOpeningLikeElement;
|
||||
function isJsxSelfClosingElement(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxSelfClosingElement;
|
||||
}
|
||||
exports.isJsxSelfClosingElement = isJsxSelfClosingElement;
|
||||
function isJsxSpreadAttribute(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxSpreadAttribute;
|
||||
}
|
||||
exports.isJsxSpreadAttribute = isJsxSpreadAttribute;
|
||||
function isJsxText(node) {
|
||||
return node.kind === ts.SyntaxKind.JsxText;
|
||||
}
|
||||
exports.isJsxText = isJsxText;
|
||||
function isLabeledStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.LabeledStatement;
|
||||
}
|
||||
exports.isLabeledStatement = isLabeledStatement;
|
||||
function isLiteralExpression(node) {
|
||||
return node.kind >= ts.SyntaxKind.FirstLiteralToken &&
|
||||
node.kind <= ts.SyntaxKind.LastLiteralToken;
|
||||
}
|
||||
exports.isLiteralExpression = isLiteralExpression;
|
||||
function isLiteralTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.LiteralType;
|
||||
}
|
||||
exports.isLiteralTypeNode = isLiteralTypeNode;
|
||||
function isMappedTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.MappedType;
|
||||
}
|
||||
exports.isMappedTypeNode = isMappedTypeNode;
|
||||
function isMetaProperty(node) {
|
||||
return node.kind === ts.SyntaxKind.MetaProperty;
|
||||
}
|
||||
exports.isMetaProperty = isMetaProperty;
|
||||
function isMethodDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.MethodDeclaration;
|
||||
}
|
||||
exports.isMethodDeclaration = isMethodDeclaration;
|
||||
function isMethodSignature(node) {
|
||||
return node.kind === ts.SyntaxKind.MethodSignature;
|
||||
}
|
||||
exports.isMethodSignature = isMethodSignature;
|
||||
function isModuleBlock(node) {
|
||||
return node.kind === ts.SyntaxKind.ModuleBlock;
|
||||
}
|
||||
exports.isModuleBlock = isModuleBlock;
|
||||
function isModuleDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.ModuleDeclaration;
|
||||
}
|
||||
exports.isModuleDeclaration = isModuleDeclaration;
|
||||
function isNamedExports(node) {
|
||||
return node.kind === ts.SyntaxKind.NamedExports;
|
||||
}
|
||||
exports.isNamedExports = isNamedExports;
|
||||
function isNamedImports(node) {
|
||||
return node.kind === ts.SyntaxKind.NamedImports;
|
||||
}
|
||||
exports.isNamedImports = isNamedImports;
|
||||
function isNamespaceDeclaration(node) {
|
||||
return isModuleDeclaration(node) &&
|
||||
node.name.kind === ts.SyntaxKind.Identifier &&
|
||||
node.body !== undefined &&
|
||||
(node.body.kind === ts.SyntaxKind.ModuleBlock ||
|
||||
isNamespaceDeclaration(node.body));
|
||||
}
|
||||
exports.isNamespaceDeclaration = isNamespaceDeclaration;
|
||||
function isNamespaceImport(node) {
|
||||
return node.kind === ts.SyntaxKind.NamespaceImport;
|
||||
}
|
||||
exports.isNamespaceImport = isNamespaceImport;
|
||||
function isNamespaceExportDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.NamespaceExportDeclaration;
|
||||
}
|
||||
exports.isNamespaceExportDeclaration = isNamespaceExportDeclaration;
|
||||
function isNewExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.NewExpression;
|
||||
}
|
||||
exports.isNewExpression = isNewExpression;
|
||||
function isNonNullExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.NonNullExpression;
|
||||
}
|
||||
exports.isNonNullExpression = isNonNullExpression;
|
||||
function isNoSubstitutionTemplateLiteral(node) {
|
||||
return node.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral;
|
||||
}
|
||||
exports.isNoSubstitutionTemplateLiteral = isNoSubstitutionTemplateLiteral;
|
||||
function isNullLiteral(node) {
|
||||
return node.kind === ts.SyntaxKind.NullKeyword;
|
||||
}
|
||||
exports.isNullLiteral = isNullLiteral;
|
||||
function isNumericLiteral(node) {
|
||||
return node.kind === ts.SyntaxKind.NumericLiteral;
|
||||
}
|
||||
exports.isNumericLiteral = isNumericLiteral;
|
||||
function isNumericOrStringLikeLiteral(node) {
|
||||
switch (node.kind) {
|
||||
case ts.SyntaxKind.StringLiteral:
|
||||
case ts.SyntaxKind.NumericLiteral:
|
||||
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.isNumericOrStringLikeLiteral = isNumericOrStringLikeLiteral;
|
||||
function isObjectBindingPattern(node) {
|
||||
return node.kind === ts.SyntaxKind.ObjectBindingPattern;
|
||||
}
|
||||
exports.isObjectBindingPattern = isObjectBindingPattern;
|
||||
function isObjectLiteralExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.ObjectLiteralExpression;
|
||||
}
|
||||
exports.isObjectLiteralExpression = isObjectLiteralExpression;
|
||||
function isOmittedExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.OmittedExpression;
|
||||
}
|
||||
exports.isOmittedExpression = isOmittedExpression;
|
||||
function isParameterDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.Parameter;
|
||||
}
|
||||
exports.isParameterDeclaration = isParameterDeclaration;
|
||||
function isParenthesizedExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.ParenthesizedExpression;
|
||||
}
|
||||
exports.isParenthesizedExpression = isParenthesizedExpression;
|
||||
function isParenthesizedTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.ParenthesizedType;
|
||||
}
|
||||
exports.isParenthesizedTypeNode = isParenthesizedTypeNode;
|
||||
function isPostfixUnaryExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.PostfixUnaryExpression;
|
||||
}
|
||||
exports.isPostfixUnaryExpression = isPostfixUnaryExpression;
|
||||
function isPrefixUnaryExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.PrefixUnaryExpression;
|
||||
}
|
||||
exports.isPrefixUnaryExpression = isPrefixUnaryExpression;
|
||||
function isPropertyAccessExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.PropertyAccessExpression;
|
||||
}
|
||||
exports.isPropertyAccessExpression = isPropertyAccessExpression;
|
||||
function isPropertyAssignment(node) {
|
||||
return node.kind === ts.SyntaxKind.PropertyAssignment;
|
||||
}
|
||||
exports.isPropertyAssignment = isPropertyAssignment;
|
||||
function isPropertyDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.PropertyDeclaration;
|
||||
}
|
||||
exports.isPropertyDeclaration = isPropertyDeclaration;
|
||||
function isPropertySignature(node) {
|
||||
return node.kind === ts.SyntaxKind.PropertySignature;
|
||||
}
|
||||
exports.isPropertySignature = isPropertySignature;
|
||||
function isQualifiedName(node) {
|
||||
return node.kind === ts.SyntaxKind.QualifiedName;
|
||||
}
|
||||
exports.isQualifiedName = isQualifiedName;
|
||||
function isRegularExpressionLiteral(node) {
|
||||
return node.kind === ts.SyntaxKind.RegularExpressionLiteral;
|
||||
}
|
||||
exports.isRegularExpressionLiteral = isRegularExpressionLiteral;
|
||||
function isReturnStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.ReturnStatement;
|
||||
}
|
||||
exports.isReturnStatement = isReturnStatement;
|
||||
function isSetAccessorDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.SetAccessor;
|
||||
}
|
||||
exports.isSetAccessorDeclaration = isSetAccessorDeclaration;
|
||||
function isShorthandPropertyAssignment(node) {
|
||||
return node.kind === ts.SyntaxKind.ShorthandPropertyAssignment;
|
||||
}
|
||||
exports.isShorthandPropertyAssignment = isShorthandPropertyAssignment;
|
||||
function isSignatureDeclaration(node) {
|
||||
return node.parameters !== undefined;
|
||||
}
|
||||
exports.isSignatureDeclaration = isSignatureDeclaration;
|
||||
function isSourceFile(node) {
|
||||
return node.kind === ts.SyntaxKind.SourceFile;
|
||||
}
|
||||
exports.isSourceFile = isSourceFile;
|
||||
function isSpreadAssignment(node) {
|
||||
return node.kind === ts.SyntaxKind.SpreadAssignment;
|
||||
}
|
||||
exports.isSpreadAssignment = isSpreadAssignment;
|
||||
function isSpreadElement(node) {
|
||||
return node.kind === ts.SyntaxKind.SpreadElement;
|
||||
}
|
||||
exports.isSpreadElement = isSpreadElement;
|
||||
function isStringLiteral(node) {
|
||||
return node.kind === ts.SyntaxKind.StringLiteral;
|
||||
}
|
||||
exports.isStringLiteral = isStringLiteral;
|
||||
function isSwitchStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.SwitchStatement;
|
||||
}
|
||||
exports.isSwitchStatement = isSwitchStatement;
|
||||
function isSyntaxList(node) {
|
||||
return node.kind === ts.SyntaxKind.SyntaxList;
|
||||
}
|
||||
exports.isSyntaxList = isSyntaxList;
|
||||
function isTaggedTemplateExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.TaggedTemplateExpression;
|
||||
}
|
||||
exports.isTaggedTemplateExpression = isTaggedTemplateExpression;
|
||||
function isTemplateExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.TemplateExpression;
|
||||
}
|
||||
exports.isTemplateExpression = isTemplateExpression;
|
||||
function isTemplateLiteral(node) {
|
||||
return node.kind === ts.SyntaxKind.TemplateExpression ||
|
||||
node.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral;
|
||||
}
|
||||
exports.isTemplateLiteral = isTemplateLiteral;
|
||||
function isTextualLiteral(node) {
|
||||
return node.kind === ts.SyntaxKind.StringLiteral ||
|
||||
node.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral;
|
||||
}
|
||||
exports.isTextualLiteral = isTextualLiteral;
|
||||
function isThrowStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.ThrowStatement;
|
||||
}
|
||||
exports.isThrowStatement = isThrowStatement;
|
||||
function isTryStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.TryStatement;
|
||||
}
|
||||
exports.isTryStatement = isTryStatement;
|
||||
function isTupleTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.TupleType;
|
||||
}
|
||||
exports.isTupleTypeNode = isTupleTypeNode;
|
||||
function isTypeAliasDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.TypeAliasDeclaration;
|
||||
}
|
||||
exports.isTypeAliasDeclaration = isTypeAliasDeclaration;
|
||||
function isTypeAssertion(node) {
|
||||
return node.kind === ts.SyntaxKind.TypeAssertionExpression;
|
||||
}
|
||||
exports.isTypeAssertion = isTypeAssertion;
|
||||
function isTypeLiteralNode(node) {
|
||||
return node.kind === ts.SyntaxKind.TypeLiteral;
|
||||
}
|
||||
exports.isTypeLiteralNode = isTypeLiteralNode;
|
||||
function isTypeOfExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.TypeOfExpression;
|
||||
}
|
||||
exports.isTypeOfExpression = isTypeOfExpression;
|
||||
function isTypeOperatorNode(node) {
|
||||
return node.kind === ts.SyntaxKind.TypeOperator;
|
||||
}
|
||||
exports.isTypeOperatorNode = isTypeOperatorNode;
|
||||
function isTypeParameterDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.TypeParameter;
|
||||
}
|
||||
exports.isTypeParameterDeclaration = isTypeParameterDeclaration;
|
||||
function isTypePredicateNode(node) {
|
||||
return node.kind === ts.SyntaxKind.TypePredicate;
|
||||
}
|
||||
exports.isTypePredicateNode = isTypePredicateNode;
|
||||
function isTypeReferenceNode(node) {
|
||||
return node.kind === ts.SyntaxKind.TypeReference;
|
||||
}
|
||||
exports.isTypeReferenceNode = isTypeReferenceNode;
|
||||
function isTypeQueryNode(node) {
|
||||
return node.kind === ts.SyntaxKind.TypeQuery;
|
||||
}
|
||||
exports.isTypeQueryNode = isTypeQueryNode;
|
||||
function isUnionTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.UnionType;
|
||||
}
|
||||
exports.isUnionTypeNode = isUnionTypeNode;
|
||||
function isVariableDeclaration(node) {
|
||||
return node.kind === ts.SyntaxKind.VariableDeclaration;
|
||||
}
|
||||
exports.isVariableDeclaration = isVariableDeclaration;
|
||||
function isVariableStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.VariableStatement;
|
||||
}
|
||||
exports.isVariableStatement = isVariableStatement;
|
||||
function isVariableDeclarationList(node) {
|
||||
return node.kind === ts.SyntaxKind.VariableDeclarationList;
|
||||
}
|
||||
exports.isVariableDeclarationList = isVariableDeclarationList;
|
||||
function isVoidExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.VoidExpression;
|
||||
}
|
||||
exports.isVoidExpression = isVoidExpression;
|
||||
function isWhileStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.WhileStatement;
|
||||
}
|
||||
exports.isWhileStatement = isWhileStatement;
|
||||
function isWithStatement(node) {
|
||||
return node.kind === ts.SyntaxKind.WithStatement;
|
||||
}
|
||||
exports.isWithStatement = isWithStatement;
|
||||
//# sourceMappingURL=node.js.map
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,18 @@
|
||||
import * as ts from 'typescript';
|
||||
export declare function isConditionalType(type: ts.Type): type is ts.ConditionalType;
|
||||
export declare function isEnumType(type: ts.Type): type is ts.EnumType;
|
||||
export declare function isGenericType(type: ts.Type): type is ts.GenericType;
|
||||
export declare function isIndexedAccessType(type: ts.Type): type is ts.IndexedAccessType;
|
||||
export declare function isIndexedAccessype(type: ts.Type): type is ts.IndexType;
|
||||
export declare function isInstantiableType(type: ts.Type): type is ts.InstantiableType;
|
||||
export declare function isInterfaceType(type: ts.Type): type is ts.InterfaceType;
|
||||
export declare function isIntersectionType(type: ts.Type): type is ts.IntersectionType;
|
||||
export declare function isLiteralType(type: ts.Type): type is ts.LiteralType;
|
||||
export declare function isObjectType(type: ts.Type): type is ts.ObjectType;
|
||||
export declare function isSubstitutionType(type: ts.Type): type is ts.SubstitutionType;
|
||||
export declare function isTypeParameter(type: ts.Type): type is ts.TypeParameter;
|
||||
export declare function isTypeReference(type: ts.Type): type is ts.TypeReference;
|
||||
export declare function isTypeVariable(type: ts.Type): type is ts.TypeParameter | ts.IndexedAccessType;
|
||||
export declare function isUnionOrIntersectionType(type: ts.Type): type is ts.UnionOrIntersectionType;
|
||||
export declare function isUnionType(type: ts.Type): type is ts.UnionType;
|
||||
export declare function isUniqueESSymbolType(type: ts.Type): type is ts.UniqueESSymbolType;
|
@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isUniqueESSymbolType = exports.isUnionType = exports.isUnionOrIntersectionType = exports.isTypeVariable = exports.isTypeReference = exports.isTypeParameter = exports.isSubstitutionType = exports.isObjectType = exports.isLiteralType = exports.isIntersectionType = exports.isInterfaceType = exports.isInstantiableType = exports.isIndexedAccessype = exports.isIndexedAccessType = exports.isGenericType = exports.isEnumType = exports.isConditionalType = void 0;
|
||||
const ts = require("typescript");
|
||||
function isConditionalType(type) {
|
||||
return (type.flags & ts.TypeFlags.Conditional) !== 0;
|
||||
}
|
||||
exports.isConditionalType = isConditionalType;
|
||||
function isEnumType(type) {
|
||||
return (type.flags & ts.TypeFlags.Enum) !== 0;
|
||||
}
|
||||
exports.isEnumType = isEnumType;
|
||||
function isGenericType(type) {
|
||||
return (type.flags & ts.TypeFlags.Object) !== 0 &&
|
||||
(type.objectFlags & ts.ObjectFlags.ClassOrInterface) !== 0 &&
|
||||
(type.objectFlags & ts.ObjectFlags.Reference) !== 0;
|
||||
}
|
||||
exports.isGenericType = isGenericType;
|
||||
function isIndexedAccessType(type) {
|
||||
return (type.flags & ts.TypeFlags.IndexedAccess) !== 0;
|
||||
}
|
||||
exports.isIndexedAccessType = isIndexedAccessType;
|
||||
function isIndexedAccessype(type) {
|
||||
return (type.flags & ts.TypeFlags.Index) !== 0;
|
||||
}
|
||||
exports.isIndexedAccessype = isIndexedAccessype;
|
||||
function isInstantiableType(type) {
|
||||
return (type.flags & ts.TypeFlags.Instantiable) !== 0;
|
||||
}
|
||||
exports.isInstantiableType = isInstantiableType;
|
||||
function isInterfaceType(type) {
|
||||
return (type.flags & ts.TypeFlags.Object) !== 0 &&
|
||||
(type.objectFlags & ts.ObjectFlags.ClassOrInterface) !== 0;
|
||||
}
|
||||
exports.isInterfaceType = isInterfaceType;
|
||||
function isIntersectionType(type) {
|
||||
return (type.flags & ts.TypeFlags.Intersection) !== 0;
|
||||
}
|
||||
exports.isIntersectionType = isIntersectionType;
|
||||
function isLiteralType(type) {
|
||||
return (type.flags & (ts.TypeFlags.StringOrNumberLiteral | ts.TypeFlags.BigIntLiteral)) !== 0;
|
||||
}
|
||||
exports.isLiteralType = isLiteralType;
|
||||
function isObjectType(type) {
|
||||
return (type.flags & ts.TypeFlags.Object) !== 0;
|
||||
}
|
||||
exports.isObjectType = isObjectType;
|
||||
function isSubstitutionType(type) {
|
||||
return (type.flags & ts.TypeFlags.Substitution) !== 0;
|
||||
}
|
||||
exports.isSubstitutionType = isSubstitutionType;
|
||||
function isTypeParameter(type) {
|
||||
return (type.flags & ts.TypeFlags.TypeParameter) !== 0;
|
||||
}
|
||||
exports.isTypeParameter = isTypeParameter;
|
||||
function isTypeReference(type) {
|
||||
return (type.flags & ts.TypeFlags.Object) !== 0 &&
|
||||
(type.objectFlags & ts.ObjectFlags.Reference) !== 0;
|
||||
}
|
||||
exports.isTypeReference = isTypeReference;
|
||||
function isTypeVariable(type) {
|
||||
return (type.flags & ts.TypeFlags.TypeVariable) !== 0;
|
||||
}
|
||||
exports.isTypeVariable = isTypeVariable;
|
||||
function isUnionOrIntersectionType(type) {
|
||||
return (type.flags & ts.TypeFlags.UnionOrIntersection) !== 0;
|
||||
}
|
||||
exports.isUnionOrIntersectionType = isUnionOrIntersectionType;
|
||||
function isUnionType(type) {
|
||||
return (type.flags & ts.TypeFlags.Union) !== 0;
|
||||
}
|
||||
exports.isUnionType = isUnionType;
|
||||
function isUniqueESSymbolType(type) {
|
||||
return (type.flags & ts.TypeFlags.UniqueESSymbol) !== 0;
|
||||
}
|
||||
exports.isUniqueESSymbolType = isUniqueESSymbolType;
|
||||
//# sourceMappingURL=type.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"type.js","sourceRoot":"","sources":["type.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,SAAgB,iBAAiB,CAAC,IAAa;IAC3C,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAFD,8CAEC;AAED,SAAgB,UAAU,CAAC,IAAa;IACpC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAFD,gCAEC;AAED,SAAgB,aAAa,CAAC,IAAa;IACvC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;QAC3C,CAAiB,IAAK,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,CAAC;QAC3E,CAAiB,IAAK,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAJD,sCAIC;AAED,SAAgB,mBAAmB,CAAC,IAAa;IAC7C,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC;AAFD,kDAEC;AAED,SAAgB,kBAAkB,CAAC,IAAa;IAC5C,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC;AAFD,gDAEC;AAED,SAAgB,kBAAkB,CAAC,IAAa;IAC5C,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAFD,gDAEC;AAED,SAAgB,eAAe,CAAC,IAAa;IACzC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;QAC3C,CAAiB,IAAK,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACpF,CAAC;AAHD,0CAGC;AAED,SAAgB,kBAAkB,CAAC,IAAa;IAC5C,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAFD,gDAEC;AAED,SAAgB,aAAa,CAAC,IAAa;IACvC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,qBAAqB,GAAG,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,CAAC;AAClG,CAAC;AAFD,sCAEC;AAED,SAAgB,YAAY,CAAC,IAAa;IACtC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC;AAFD,oCAEC;AAED,SAAgB,kBAAkB,CAAC,IAAa;IAC5C,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAFD,gDAEC;AAED,SAAgB,eAAe,CAAC,IAAa;IACzC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC;AAFD,0CAEC;AAED,SAAgB,eAAe,CAAC,IAAa;IACzC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;QAC3C,CAAiB,IAAK,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAHD,0CAGC;AAED,SAAgB,cAAc,CAAC,IAAa;IACxC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAFD,wCAEC;AAED,SAAgB,yBAAyB,CAAC,IAAa;IACnD,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AAFD,8DAEC;AAED,SAAgB,WAAW,CAAC,IAAa;IACrC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC;AAFD,kCAEC;AAED,SAAgB,oBAAoB,CAAC,IAAa;IAC9C,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC;AAFD,oDAEC"}
|
@ -0,0 +1,2 @@
|
||||
export * from './node';
|
||||
export * from './type';
|
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./node"), exports);
|
||||
tslib_1.__exportStar(require("./type"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,iDAAuB"}
|
@ -0,0 +1,3 @@
|
||||
export * from '../2.8/node';
|
||||
import * as ts from 'typescript';
|
||||
export declare function isImportTypeNode(node: ts.Node): node is ts.ImportTypeNode;
|
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isImportTypeNode = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("../2.8/node"), exports);
|
||||
const ts = require("typescript");
|
||||
function isImportTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.ImportType;
|
||||
}
|
||||
exports.isImportTypeNode = isImportTypeNode;
|
||||
//# sourceMappingURL=node.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"node.js","sourceRoot":"","sources":["node.ts"],"names":[],"mappings":";;;;AAAA,sDAA4B;AAE5B,iCAAiC;AAEjC,SAAgB,gBAAgB,CAAC,IAAa;IAC1C,OAAO,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;AAClD,CAAC;AAFD,4CAEC"}
|
@ -0,0 +1 @@
|
||||
export * from '../2.8/type';
|
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("../2.8/type"), exports);
|
||||
//# sourceMappingURL=type.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"type.js","sourceRoot":"","sources":["type.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
|
@ -0,0 +1,2 @@
|
||||
export * from './node';
|
||||
export * from './type';
|
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./node"), exports);
|
||||
tslib_1.__exportStar(require("./type"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,iDAAuB"}
|
@ -0,0 +1,5 @@
|
||||
export * from '../2.9/node';
|
||||
import * as ts from 'typescript';
|
||||
export declare function isOptionalTypeNode(node: ts.Node): node is ts.OptionalTypeNode;
|
||||
export declare function isRestTypeNode(node: ts.Node): node is ts.RestTypeNode;
|
||||
export declare function isSyntheticExpression(node: ts.Node): node is ts.SyntheticExpression;
|
@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isSyntheticExpression = exports.isRestTypeNode = exports.isOptionalTypeNode = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("../2.9/node"), exports);
|
||||
const ts = require("typescript");
|
||||
function isOptionalTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.OptionalType;
|
||||
}
|
||||
exports.isOptionalTypeNode = isOptionalTypeNode;
|
||||
function isRestTypeNode(node) {
|
||||
return node.kind === ts.SyntaxKind.RestType;
|
||||
}
|
||||
exports.isRestTypeNode = isRestTypeNode;
|
||||
function isSyntheticExpression(node) {
|
||||
return node.kind === ts.SyntaxKind.SyntheticExpression;
|
||||
}
|
||||
exports.isSyntheticExpression = isSyntheticExpression;
|
||||
//# sourceMappingURL=node.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"node.js","sourceRoot":"","sources":["node.ts"],"names":[],"mappings":";;;;AAAA,sDAA4B;AAE5B,iCAAiC;AAEjC,SAAgB,kBAAkB,CAAC,IAAa;IAC5C,OAAO,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC;AACpD,CAAC;AAFD,gDAEC;AAED,SAAgB,cAAc,CAAC,IAAa;IACxC,OAAO,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;AAChD,CAAC;AAFD,wCAEC;AAED,SAAgB,qBAAqB,CAAC,IAAa;IAC/C,OAAO,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC;AAC3D,CAAC;AAFD,sDAEC"}
|
@ -0,0 +1,6 @@
|
||||
export * from '../2.9/type';
|
||||
import * as ts from 'typescript';
|
||||
export declare function isTupleType(type: ts.Type): type is ts.TupleType;
|
||||
export declare function isTupleTypeReference(type: ts.Type): type is ts.TypeReference & {
|
||||
target: ts.TupleType;
|
||||
};
|
@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isTupleTypeReference = exports.isTupleType = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("../2.9/type"), exports);
|
||||
const ts = require("typescript");
|
||||
const type_1 = require("../2.9/type");
|
||||
function isTupleType(type) {
|
||||
return (type.flags & ts.TypeFlags.Object && type.objectFlags & ts.ObjectFlags.Tuple) !== 0;
|
||||
}
|
||||
exports.isTupleType = isTupleType;
|
||||
function isTupleTypeReference(type) {
|
||||
return type_1.isTypeReference(type) && isTupleType(type.target);
|
||||
}
|
||||
exports.isTupleTypeReference = isTupleTypeReference;
|
||||
//# sourceMappingURL=type.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"type.js","sourceRoot":"","sources":["type.ts"],"names":[],"mappings":";;;;AAAA,sDAA4B;AAE5B,iCAAiC;AACjC,sCAA8C;AAE9C,SAAgB,WAAW,CAAC,IAAa;IACrC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,IAAoB,IAAK,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAChH,CAAC;AAFD,kCAEC;AAED,SAAgB,oBAAoB,CAAC,IAAa;IAC9C,OAAO,sBAAe,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC7D,CAAC;AAFD,oDAEC"}
|
@ -0,0 +1,2 @@
|
||||
export * from './node';
|
||||
export * from './type';
|
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./node"), exports);
|
||||
tslib_1.__exportStar(require("./type"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,iDAAuB"}
|
@ -0,0 +1,3 @@
|
||||
export * from '../3.0/node';
|
||||
import * as ts from 'typescript';
|
||||
export declare function isBigIntLiteral(node: ts.Node): node is ts.BigIntLiteral;
|
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isBigIntLiteral = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("../3.0/node"), exports);
|
||||
const ts = require("typescript");
|
||||
function isBigIntLiteral(node) {
|
||||
return node.kind === ts.SyntaxKind.BigIntLiteral;
|
||||
}
|
||||
exports.isBigIntLiteral = isBigIntLiteral;
|
||||
//# sourceMappingURL=node.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"node.js","sourceRoot":"","sources":["node.ts"],"names":[],"mappings":";;;;AAAA,sDAA4B;AAE5B,iCAAiC;AAEjC,SAAgB,eAAe,CAAC,IAAa;IACzC,OAAO,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;AACrD,CAAC;AAFD,0CAEC"}
|
@ -0,0 +1 @@
|
||||
export * from '../3.0/type';
|
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("../3.0/type"), exports);
|
||||
//# sourceMappingURL=type.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"type.js","sourceRoot":"","sources":["type.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
|
@ -0,0 +1,2 @@
|
||||
export * from './node';
|
||||
export * from './type';
|
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./node"), exports);
|
||||
tslib_1.__exportStar(require("./type"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,iDAAuB"}
|
@ -0,0 +1,2 @@
|
||||
export * from './node';
|
||||
export * from './type';
|
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./node"), exports);
|
||||
tslib_1.__exportStar(require("./type"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,iDAAuB"}
|
@ -0,0 +1 @@
|
||||
export * from '../3.2/node';
|
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("../3.2/node"), exports);
|
||||
//# sourceMappingURL=node.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"node.js","sourceRoot":"","sources":["node.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
|
@ -0,0 +1 @@
|
||||
export * from '../3.2/type';
|
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("../3.2/type"), exports);
|
||||
//# sourceMappingURL=type.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"type.js","sourceRoot":"","sources":["type.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
|
@ -0,0 +1 @@
|
||||
export * from './3.2/node';
|
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./3.2/node"), exports);
|
||||
//# sourceMappingURL=node.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"node.js","sourceRoot":"","sources":["node.ts"],"names":[],"mappings":";;;AAAA,qDAA2B"}
|
@ -0,0 +1 @@
|
||||
export * from './3.2/type';
|
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./3.2/type"), exports);
|
||||
//# sourceMappingURL=type.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"type.js","sourceRoot":"","sources":["type.ts"],"names":[],"mappings":";;;AAAA,qDAA2B"}
|
@ -0,0 +1,24 @@
|
||||
import * as ts from 'typescript';
|
||||
export declare function endsControlFlow(statement: ts.Statement | ts.BlockLike, checker?: ts.TypeChecker): boolean;
|
||||
export declare type ControlFlowStatement = ts.BreakStatement | ts.ContinueStatement | ts.ReturnStatement | ts.ThrowStatement | ts.ExpressionStatement & {
|
||||
expression: ts.CallExpression;
|
||||
};
|
||||
export interface ControlFlowEnd {
|
||||
/**
|
||||
* Statements that may end control flow at this statement.
|
||||
* Does not contain control flow statements that jump only inside the statement, for example a `continue` inside a nested for loop.
|
||||
*/
|
||||
readonly statements: ReadonlyArray<ControlFlowStatement>;
|
||||
/** `true` if control flow definitely ends. */
|
||||
readonly end: boolean;
|
||||
}
|
||||
export declare function getControlFlowEnd(statement: ts.Statement | ts.BlockLike, checker?: ts.TypeChecker): ControlFlowEnd;
|
||||
export declare enum SignatureEffect {
|
||||
Never = 1,
|
||||
Asserts = 2
|
||||
}
|
||||
/**
|
||||
* Dermines whether a top level CallExpression has a control flow effect according to TypeScript's rules.
|
||||
* This handles functions returning `never` and `asserts`.
|
||||
*/
|
||||
export declare function callExpressionAffectsControlFlow(node: ts.CallExpression, checker: ts.TypeChecker): SignatureEffect | undefined;
|
@ -0,0 +1,296 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.callExpressionAffectsControlFlow = exports.SignatureEffect = exports.getControlFlowEnd = exports.endsControlFlow = void 0;
|
||||
const ts = require("typescript");
|
||||
const node_1 = require("../typeguard/node");
|
||||
const util_1 = require("./util");
|
||||
function endsControlFlow(statement, checker) {
|
||||
return getControlFlowEnd(statement, checker).end;
|
||||
}
|
||||
exports.endsControlFlow = endsControlFlow;
|
||||
const defaultControlFlowEnd = { statements: [], end: false };
|
||||
function getControlFlowEnd(statement, checker) {
|
||||
return node_1.isBlockLike(statement) ? handleBlock(statement, checker) : getControlFlowEndWorker(statement, checker);
|
||||
}
|
||||
exports.getControlFlowEnd = getControlFlowEnd;
|
||||
function getControlFlowEndWorker(statement, checker) {
|
||||
switch (statement.kind) {
|
||||
case ts.SyntaxKind.ReturnStatement:
|
||||
case ts.SyntaxKind.ThrowStatement:
|
||||
case ts.SyntaxKind.ContinueStatement:
|
||||
case ts.SyntaxKind.BreakStatement:
|
||||
return { statements: [statement], end: true };
|
||||
case ts.SyntaxKind.Block:
|
||||
return handleBlock(statement, checker);
|
||||
case ts.SyntaxKind.ForStatement:
|
||||
case ts.SyntaxKind.WhileStatement:
|
||||
return handleForAndWhileStatement(statement, checker);
|
||||
case ts.SyntaxKind.ForOfStatement:
|
||||
case ts.SyntaxKind.ForInStatement:
|
||||
return handleForInOrOfStatement(statement, checker);
|
||||
case ts.SyntaxKind.DoStatement:
|
||||
return matchBreakOrContinue(getControlFlowEndWorker(statement.statement, checker), node_1.isBreakOrContinueStatement);
|
||||
case ts.SyntaxKind.IfStatement:
|
||||
return handleIfStatement(statement, checker);
|
||||
case ts.SyntaxKind.SwitchStatement:
|
||||
return matchBreakOrContinue(handleSwitchStatement(statement, checker), node_1.isBreakStatement);
|
||||
case ts.SyntaxKind.TryStatement:
|
||||
return handleTryStatement(statement, checker);
|
||||
case ts.SyntaxKind.LabeledStatement:
|
||||
return matchLabel(getControlFlowEndWorker(statement.statement, checker), statement.label);
|
||||
case ts.SyntaxKind.WithStatement:
|
||||
return getControlFlowEndWorker(statement.statement, checker);
|
||||
case ts.SyntaxKind.ExpressionStatement:
|
||||
if (checker === undefined)
|
||||
return defaultControlFlowEnd;
|
||||
return handleExpressionStatement(statement, checker);
|
||||
default:
|
||||
return defaultControlFlowEnd;
|
||||
}
|
||||
}
|
||||
function handleBlock(statement, checker) {
|
||||
const result = { statements: [], end: false };
|
||||
for (const s of statement.statements) {
|
||||
const current = getControlFlowEndWorker(s, checker);
|
||||
result.statements.push(...current.statements);
|
||||
if (current.end) {
|
||||
result.end = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function handleForInOrOfStatement(statement, checker) {
|
||||
const end = matchBreakOrContinue(getControlFlowEndWorker(statement.statement, checker), node_1.isBreakOrContinueStatement);
|
||||
end.end = false; // loop body is guaranteed to be executed
|
||||
return end;
|
||||
}
|
||||
function handleForAndWhileStatement(statement, checker) {
|
||||
const constantCondition = statement.kind === ts.SyntaxKind.WhileStatement
|
||||
? getConstantCondition(statement.expression)
|
||||
: statement.condition === undefined || getConstantCondition(statement.condition);
|
||||
if (constantCondition === false)
|
||||
return defaultControlFlowEnd; // loop body is never executed
|
||||
const end = matchBreakOrContinue(getControlFlowEndWorker(statement.statement, checker), node_1.isBreakOrContinueStatement);
|
||||
if (constantCondition === undefined)
|
||||
end.end = false; // can't be sure that loop body is executed at all
|
||||
return end;
|
||||
}
|
||||
/** Simply detects `true` and `false` in conditions. That matches TypeScript's behavior. */
|
||||
function getConstantCondition(node) {
|
||||
switch (node.kind) {
|
||||
case ts.SyntaxKind.TrueKeyword:
|
||||
return true;
|
||||
case ts.SyntaxKind.FalseKeyword:
|
||||
return false;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
function handleIfStatement(node, checker) {
|
||||
switch (getConstantCondition(node.expression)) {
|
||||
case true:
|
||||
// else branch is never executed
|
||||
return getControlFlowEndWorker(node.thenStatement, checker);
|
||||
case false:
|
||||
// then branch is never executed
|
||||
return node.elseStatement === undefined
|
||||
? defaultControlFlowEnd
|
||||
: getControlFlowEndWorker(node.elseStatement, checker);
|
||||
}
|
||||
const then = getControlFlowEndWorker(node.thenStatement, checker);
|
||||
if (node.elseStatement === undefined)
|
||||
return {
|
||||
statements: then.statements,
|
||||
end: false,
|
||||
};
|
||||
const elze = getControlFlowEndWorker(node.elseStatement, checker);
|
||||
return {
|
||||
statements: [...then.statements, ...elze.statements],
|
||||
end: then.end && elze.end,
|
||||
};
|
||||
}
|
||||
function handleSwitchStatement(node, checker) {
|
||||
let hasDefault = false;
|
||||
const result = {
|
||||
statements: [],
|
||||
end: false,
|
||||
};
|
||||
for (const clause of node.caseBlock.clauses) {
|
||||
if (clause.kind === ts.SyntaxKind.DefaultClause)
|
||||
hasDefault = true;
|
||||
const current = handleBlock(clause, checker);
|
||||
result.end = current.end;
|
||||
result.statements.push(...current.statements);
|
||||
}
|
||||
result.end && (result.end = hasDefault || checker !== undefined && util_1.hasExhaustiveCaseClauses(node, checker));
|
||||
return result;
|
||||
}
|
||||
function handleTryStatement(node, checker) {
|
||||
let finallyResult;
|
||||
if (node.finallyBlock !== undefined) {
|
||||
finallyResult = handleBlock(node.finallyBlock, checker);
|
||||
// if 'finally' always ends control flow, we are not interested in any jump statements from 'try' or 'catch'
|
||||
if (finallyResult.end)
|
||||
return finallyResult;
|
||||
}
|
||||
const tryResult = handleBlock(node.tryBlock, checker);
|
||||
if (node.catchClause === undefined)
|
||||
return { statements: finallyResult.statements.concat(tryResult.statements), end: tryResult.end };
|
||||
const catchResult = handleBlock(node.catchClause.block, checker);
|
||||
return {
|
||||
statements: tryResult.statements
|
||||
// remove all throw statements and throwing function calls from the list of control flow statements inside tryBlock
|
||||
.filter((s) => s.kind !== ts.SyntaxKind.ThrowStatement && s.kind !== ts.SyntaxKind.ExpressionStatement)
|
||||
.concat(catchResult.statements, finallyResult === undefined ? [] : finallyResult.statements),
|
||||
end: tryResult.end && catchResult.end, // only ends control flow if try AND catch definitely end control flow
|
||||
};
|
||||
}
|
||||
/** Dotted name as TypeScript requires it for assertion signatures to affect control flow. */
|
||||
function isDottedNameWithExplicitTypeAnnotation(node, checker) {
|
||||
while (true) {
|
||||
switch (node.kind) {
|
||||
case ts.SyntaxKind.Identifier: {
|
||||
const symbol = checker.getExportSymbolOfSymbol(checker.getSymbolAtLocation(node));
|
||||
return isExplicitlyTypedSymbol(util_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias) ? checker.getAliasedSymbol(symbol) : symbol, checker);
|
||||
}
|
||||
case ts.SyntaxKind.ThisKeyword:
|
||||
return isExplicitlyTypedThis(node);
|
||||
case ts.SyntaxKind.SuperKeyword:
|
||||
return true;
|
||||
case ts.SyntaxKind.PropertyAccessExpression:
|
||||
if (!isExplicitlyTypedSymbol(checker.getSymbolAtLocation(node), checker))
|
||||
return false;
|
||||
// falls through
|
||||
case ts.SyntaxKind.ParenthesizedExpression:
|
||||
node = node.expression;
|
||||
continue;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
function isExplicitlyTypedSymbol(symbol, checker) {
|
||||
if (symbol === undefined)
|
||||
return false;
|
||||
if (util_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Function | ts.SymbolFlags.Method | ts.SymbolFlags.Class | ts.SymbolFlags.ValueModule))
|
||||
return true;
|
||||
if (!util_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Variable | ts.SymbolFlags.Property))
|
||||
return false;
|
||||
if (symbol.valueDeclaration === undefined)
|
||||
return false;
|
||||
if (declarationHasExplicitTypeAnnotation(symbol.valueDeclaration))
|
||||
return true;
|
||||
return node_1.isVariableDeclaration(symbol.valueDeclaration) &&
|
||||
symbol.valueDeclaration.parent.parent.kind === ts.SyntaxKind.ForOfStatement &&
|
||||
isDottedNameWithExplicitTypeAnnotation(symbol.valueDeclaration.parent.parent.expression, checker);
|
||||
}
|
||||
function declarationHasExplicitTypeAnnotation(node) {
|
||||
if (ts.isJSDocPropertyLikeTag(node))
|
||||
return node.typeExpression !== undefined;
|
||||
return (node_1.isVariableDeclaration(node) ||
|
||||
node_1.isParameterDeclaration(node) ||
|
||||
node_1.isPropertyDeclaration(node) ||
|
||||
node_1.isPropertySignature(node)) && (util_1.isNodeFlagSet(node, ts.NodeFlags.JavaScriptFile)
|
||||
? ts.getJSDocType(node)
|
||||
: node.type) !== undefined;
|
||||
}
|
||||
function isExplicitlyTypedThis(node) {
|
||||
var _a;
|
||||
do {
|
||||
node = node.parent;
|
||||
if (node_1.isDecorator(node)) {
|
||||
// `this` in decorators always resolves outside of the containing class
|
||||
if (node.parent.kind === ts.SyntaxKind.Parameter && node_1.isClassLikeDeclaration(node.parent.parent.parent)) {
|
||||
node = node.parent.parent.parent.parent;
|
||||
}
|
||||
else if (node_1.isClassLikeDeclaration(node.parent.parent)) {
|
||||
node = node.parent.parent.parent;
|
||||
}
|
||||
else if (node_1.isClassLikeDeclaration(node.parent)) {
|
||||
node = node.parent.parent;
|
||||
}
|
||||
}
|
||||
} while (util_1.isFunctionScopeBoundary(node) !== 1 /* Function */ || node.kind === ts.SyntaxKind.ArrowFunction);
|
||||
return util_1.isFunctionWithBody(node) &&
|
||||
(util_1.isNodeFlagSet(node, ts.NodeFlags.JavaScriptFile)
|
||||
? ((_a = ts.getJSDocThisTag(node)) === null || _a === void 0 ? void 0 : _a.typeExpression) !== undefined
|
||||
: node.parameters.length !== 0 && util_1.isThisParameter(node.parameters[0]) && node.parameters[0].type !== undefined) ||
|
||||
node_1.isClassLikeDeclaration(node.parent);
|
||||
}
|
||||
var SignatureEffect;
|
||||
(function (SignatureEffect) {
|
||||
SignatureEffect[SignatureEffect["Never"] = 1] = "Never";
|
||||
SignatureEffect[SignatureEffect["Asserts"] = 2] = "Asserts";
|
||||
})(SignatureEffect = exports.SignatureEffect || (exports.SignatureEffect = {}));
|
||||
/**
|
||||
* Dermines whether a top level CallExpression has a control flow effect according to TypeScript's rules.
|
||||
* This handles functions returning `never` and `asserts`.
|
||||
*/
|
||||
function callExpressionAffectsControlFlow(node, checker) {
|
||||
var _a, _b, _c;
|
||||
if (!node_1.isExpressionStatement(node.parent) ||
|
||||
ts.isOptionalChain(node) ||
|
||||
!isDottedNameWithExplicitTypeAnnotation(node.expression, checker))
|
||||
return;
|
||||
const signature = checker.getResolvedSignature(node);
|
||||
if ((signature === null || signature === void 0 ? void 0 : signature.declaration) === undefined)
|
||||
return;
|
||||
const typeNode = ts.isJSDocSignature(signature.declaration)
|
||||
? (_b = (_a = signature.declaration.type) === null || _a === void 0 ? void 0 : _a.typeExpression) === null || _b === void 0 ? void 0 : _b.type
|
||||
: (_c = signature.declaration.type) !== null && _c !== void 0 ? _c : (util_1.isNodeFlagSet(signature.declaration, ts.NodeFlags.JavaScriptFile)
|
||||
? ts.getJSDocReturnType(signature.declaration)
|
||||
: undefined);
|
||||
if (typeNode === undefined)
|
||||
return;
|
||||
if (node_1.isTypePredicateNode(typeNode) && typeNode.assertsModifier !== undefined)
|
||||
return 2 /* Asserts */;
|
||||
return util_1.isTypeFlagSet(checker.getTypeFromTypeNode(typeNode), ts.TypeFlags.Never) ? 1 /* Never */ : undefined;
|
||||
}
|
||||
exports.callExpressionAffectsControlFlow = callExpressionAffectsControlFlow;
|
||||
function handleExpressionStatement(node, checker) {
|
||||
if (!node_1.isCallExpression(node.expression))
|
||||
return defaultControlFlowEnd;
|
||||
switch (callExpressionAffectsControlFlow(node.expression, checker)) {
|
||||
case 2 /* Asserts */:
|
||||
return { statements: [node], end: false };
|
||||
case 1 /* Never */:
|
||||
return { statements: [node], end: true };
|
||||
case undefined:
|
||||
return defaultControlFlowEnd;
|
||||
}
|
||||
}
|
||||
function matchBreakOrContinue(current, pred) {
|
||||
const result = {
|
||||
statements: [],
|
||||
end: current.end,
|
||||
};
|
||||
for (const statement of current.statements) {
|
||||
if (pred(statement) && statement.label === undefined) {
|
||||
result.end = false;
|
||||
continue;
|
||||
}
|
||||
result.statements.push(statement);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function matchLabel(current, label) {
|
||||
const result = {
|
||||
statements: [],
|
||||
end: current.end,
|
||||
};
|
||||
const labelText = label.text;
|
||||
for (const statement of current.statements) {
|
||||
switch (statement.kind) {
|
||||
case ts.SyntaxKind.BreakStatement:
|
||||
case ts.SyntaxKind.ContinueStatement:
|
||||
if (statement.label !== undefined && statement.label.text === labelText) {
|
||||
result.end = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
result.statements.push(statement);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//# sourceMappingURL=control-flow.js.map
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,33 @@
|
||||
import * as ts from 'typescript';
|
||||
/** Wraps an AST node. Can be used as a tree using `children` or a linked list using `next` and `skip`. */
|
||||
export interface NodeWrap {
|
||||
/** The real AST node. */
|
||||
node: ts.Node;
|
||||
/** The SyntaxKind of `node`. */
|
||||
kind: ts.SyntaxKind;
|
||||
/** All immediate children of `node` that would be visited by `ts.forEachChild(node, cb)`. */
|
||||
children: NodeWrap[];
|
||||
/** Link to the next NodeWrap, depth-first. */
|
||||
next?: NodeWrap;
|
||||
/** Link to the next NodeWrap skipping all children of the current node. */
|
||||
skip?: NodeWrap;
|
||||
/** Link to the parent NodeWrap */
|
||||
parent?: NodeWrap;
|
||||
}
|
||||
export interface WrappedAst extends NodeWrap {
|
||||
node: ts.SourceFile;
|
||||
next: NodeWrap;
|
||||
skip: undefined;
|
||||
parent: undefined;
|
||||
}
|
||||
export interface ConvertedAst {
|
||||
/** nodes wrapped in a data structure with useful links */
|
||||
wrapped: WrappedAst;
|
||||
/** depth-first array of all nodes excluding SourceFile */
|
||||
flat: ReadonlyArray<ts.Node>;
|
||||
}
|
||||
/**
|
||||
* Takes a `ts.SourceFile` and creates data structures that are easier (or more performant) to traverse.
|
||||
* Note that there is only a performance gain if you can reuse these structures. It's not recommended for one-time AST walks.
|
||||
*/
|
||||
export declare function convertAst(sourceFile: ts.SourceFile): ConvertedAst;
|
@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.convertAst = void 0;
|
||||
const ts = require("typescript");
|
||||
const util_1 = require("./util");
|
||||
/**
|
||||
* Takes a `ts.SourceFile` and creates data structures that are easier (or more performant) to traverse.
|
||||
* Note that there is only a performance gain if you can reuse these structures. It's not recommended for one-time AST walks.
|
||||
*/
|
||||
function convertAst(sourceFile) {
|
||||
const wrapped = {
|
||||
node: sourceFile,
|
||||
parent: undefined,
|
||||
kind: ts.SyntaxKind.SourceFile,
|
||||
children: [],
|
||||
next: undefined,
|
||||
skip: undefined,
|
||||
};
|
||||
const flat = [];
|
||||
let current = wrapped;
|
||||
function collectChildren(node) {
|
||||
current.children.push({
|
||||
node,
|
||||
parent: current,
|
||||
kind: node.kind,
|
||||
children: [],
|
||||
next: undefined,
|
||||
skip: undefined,
|
||||
});
|
||||
}
|
||||
const stack = [];
|
||||
while (true) {
|
||||
if (current.children.length === 0) {
|
||||
ts.forEachChild(current.node, collectChildren);
|
||||
if (current.children.length === 0) {
|
||||
current = current.parent; // nothing to do here, go back to parent
|
||||
}
|
||||
else {
|
||||
// recurse into first child
|
||||
const firstChild = current.children[0];
|
||||
current.next = firstChild;
|
||||
flat.push(firstChild.node);
|
||||
if (util_1.isNodeKind(firstChild.kind))
|
||||
current = firstChild;
|
||||
stack.push(1); // set index in stack so we know where to continue processing children
|
||||
}
|
||||
}
|
||||
else {
|
||||
const index = stack[stack.length - 1];
|
||||
if (index < current.children.length) { // handles 2nd child to the last
|
||||
const currentChild = current.children[index];
|
||||
flat.push(currentChild.node);
|
||||
let previous = current.children[index - 1];
|
||||
while (previous.children.length !== 0) {
|
||||
previous.skip = currentChild;
|
||||
previous = previous.children[previous.children.length - 1];
|
||||
}
|
||||
previous.skip = previous.next = currentChild;
|
||||
++stack[stack.length - 1];
|
||||
if (util_1.isNodeKind(currentChild.kind))
|
||||
current = currentChild; // recurse into child
|
||||
}
|
||||
else {
|
||||
// done on this node
|
||||
if (stack.length === 1)
|
||||
break;
|
||||
// remove index from stack and go back to parent
|
||||
stack.pop();
|
||||
current = current.parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
wrapped,
|
||||
flat,
|
||||
};
|
||||
}
|
||||
exports.convertAst = convertAst;
|
||||
//# sourceMappingURL=convert-ast.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"convert-ast.js","sourceRoot":"","sources":["convert-ast.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,iCAAoC;AAgCpC;;;GAGG;AACH,SAAgB,UAAU,CAAC,UAAyB;IAChD,MAAM,OAAO,GAAe;QACxB,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,SAAS;QACjB,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,UAAU;QAC9B,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAO,SAAS;QACpB,IAAI,EAAE,SAAS;KAClB,CAAC;IACF,MAAM,IAAI,GAAc,EAAE,CAAC;IAC3B,IAAI,OAAO,GAAa,OAAO,CAAC;IAEhC,SAAS,eAAe,CAAC,IAAa;QAClC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;YAClB,IAAI;YACJ,MAAM,EAAE,OAAO;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,EAAE;YACZ,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;SAClB,CAAC,CAAC;IACP,CAAC;IACD,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,OAAO,IAAI,EAAE;QACT,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YAC/B,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;YAC/C,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC/B,OAAO,GAAG,OAAO,CAAC,MAAO,CAAC,CAAC,wCAAwC;aACtE;iBAAM;gBACH,2BAA2B;gBAC3B,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBACvC,OAAO,CAAC,IAAI,GAAG,UAAU,CAAC;gBAC1B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;gBAC3B,IAAI,iBAAU,CAAC,UAAU,CAAC,IAAI,CAAC;oBAC3B,OAAO,GAAG,UAAU,CAAC;gBACzB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,sEAAsE;aACxF;SACJ;aAAM;YACH,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACtC,IAAI,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,gCAAgC;gBACnE,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAC7C,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;gBAC7B,IAAI,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;gBAC3C,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;oBACnC,QAAQ,CAAC,IAAI,GAAG,YAAY,CAAC;oBAC7B,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;iBAC9D;gBACD,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,GAAG,YAAY,CAAC;gBAC7C,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;gBAC1B,IAAI,iBAAU,CAAC,YAAY,CAAC,IAAI,CAAC;oBAC7B,OAAO,GAAG,YAAY,CAAC,CAAC,qBAAqB;aACpD;iBAAM;gBACH,oBAAoB;gBACpB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;oBAClB,MAAM;gBACV,gDAAgD;gBAChD,KAAK,CAAC,GAAG,EAAE,CAAC;gBACZ,OAAO,GAAG,OAAO,CAAC,MAAO,CAAC;aAC7B;SACJ;KACJ;IAED,OAAO;QACH,OAAO;QACP,IAAI;KACP,CAAC;AACN,CAAC;AAlED,gCAkEC"}
|
@ -0,0 +1,5 @@
|
||||
export * from './util';
|
||||
export * from './usage';
|
||||
export * from './control-flow';
|
||||
export * from './type';
|
||||
export * from './convert-ast';
|
@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./util"), exports);
|
||||
tslib_1.__exportStar(require("./usage"), exports);
|
||||
tslib_1.__exportStar(require("./control-flow"), exports);
|
||||
tslib_1.__exportStar(require("./type"), exports);
|
||||
tslib_1.__exportStar(require("./convert-ast"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,kDAAwB;AACxB,yDAA+B;AAC/B,iDAAuB;AACvB,wDAA8B"}
|
@ -0,0 +1,35 @@
|
||||
import * as ts from 'typescript';
|
||||
import { PropertyName } from './util';
|
||||
export declare function isEmptyObjectType(type: ts.Type): type is ts.ObjectType;
|
||||
export declare function removeOptionalityFromType(checker: ts.TypeChecker, type: ts.Type): ts.Type;
|
||||
export declare function removeOptionalChainingUndefinedMarkerType(checker: ts.TypeChecker, type: ts.Type): ts.Type;
|
||||
export declare function isOptionalChainingUndefinedMarkerType(checker: ts.TypeChecker, t: ts.Type): boolean;
|
||||
export declare function isTypeAssignableToNumber(checker: ts.TypeChecker, type: ts.Type): boolean;
|
||||
export declare function isTypeAssignableToString(checker: ts.TypeChecker, type: ts.Type): boolean;
|
||||
export declare function getCallSignaturesOfType(type: ts.Type): ReadonlyArray<ts.Signature>;
|
||||
/** Returns all types of a union type or an array containing `type` itself if it's no union type. */
|
||||
export declare function unionTypeParts(type: ts.Type): ts.Type[];
|
||||
/** Returns all types of a intersection type or an array containing `type` itself if it's no intersection type. */
|
||||
export declare function intersectionTypeParts(type: ts.Type): ts.Type[];
|
||||
export declare function someTypePart(type: ts.Type, predicate: (t: ts.Type) => t is ts.UnionOrIntersectionType, cb: (t: ts.Type) => boolean): boolean;
|
||||
/** Determines if a type thenable and can be used with `await`. */
|
||||
export declare function isThenableType(checker: ts.TypeChecker, node: ts.Node, type: ts.Type): boolean;
|
||||
/** Determines if a type thenable and can be used with `await`. */
|
||||
export declare function isThenableType(checker: ts.TypeChecker, node: ts.Expression, type?: ts.Type): boolean;
|
||||
/** Determine if a type is definitely falsy. This function doesn't unwrap union types. */
|
||||
export declare function isFalsyType(type: ts.Type): boolean;
|
||||
/** Determines whether the given type is a boolean literal type and matches the given boolean literal (true or false). */
|
||||
export declare function isBooleanLiteralType(type: ts.Type, literal: boolean): boolean;
|
||||
export declare function getPropertyOfType(type: ts.Type, name: ts.__String): ts.Symbol | undefined;
|
||||
export declare function getWellKnownSymbolPropertyOfType(type: ts.Type, wellKnownSymbolName: string, checker: ts.TypeChecker): ts.Symbol | undefined;
|
||||
/** Determines if writing to a certain property of a given type is allowed. */
|
||||
export declare function isPropertyReadonlyInType(type: ts.Type, name: ts.__String, checker: ts.TypeChecker): boolean;
|
||||
export declare function symbolHasReadonlyDeclaration(symbol: ts.Symbol, checker: ts.TypeChecker): boolean;
|
||||
/** Returns the the literal name or unique symbol name from a given type. Doesn't unwrap union types. */
|
||||
export declare function getPropertyNameFromType(type: ts.Type): PropertyName | undefined;
|
||||
export declare function getSymbolOfClassLikeDeclaration(node: ts.ClassLikeDeclaration, checker: ts.TypeChecker): ts.Symbol;
|
||||
export declare function getConstructorTypeOfClassLikeDeclaration(node: ts.ClassLikeDeclaration, checker: ts.TypeChecker): ts.Type;
|
||||
export declare function getInstanceTypeOfClassLikeDeclaration(node: ts.ClassLikeDeclaration, checker: ts.TypeChecker): ts.Type;
|
||||
export declare function getIteratorYieldResultFromIteratorResult(type: ts.Type, node: ts.Node, checker: ts.TypeChecker): ts.Type;
|
||||
/** Lookup the declaration of a class member in the super class. */
|
||||
export declare function getBaseClassMemberOfClassElement(node: ts.PropertyDeclaration | ts.MethodDeclaration | ts.AccessorDeclaration, checker: ts.TypeChecker): ts.Symbol | undefined;
|
@ -0,0 +1,331 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getBaseClassMemberOfClassElement = exports.getIteratorYieldResultFromIteratorResult = exports.getInstanceTypeOfClassLikeDeclaration = exports.getConstructorTypeOfClassLikeDeclaration = exports.getSymbolOfClassLikeDeclaration = exports.getPropertyNameFromType = exports.symbolHasReadonlyDeclaration = exports.isPropertyReadonlyInType = exports.getWellKnownSymbolPropertyOfType = exports.getPropertyOfType = exports.isBooleanLiteralType = exports.isFalsyType = exports.isThenableType = exports.someTypePart = exports.intersectionTypeParts = exports.unionTypeParts = exports.getCallSignaturesOfType = exports.isTypeAssignableToString = exports.isTypeAssignableToNumber = exports.isOptionalChainingUndefinedMarkerType = exports.removeOptionalChainingUndefinedMarkerType = exports.removeOptionalityFromType = exports.isEmptyObjectType = void 0;
|
||||
const ts = require("typescript");
|
||||
const type_1 = require("../typeguard/type");
|
||||
const util_1 = require("./util");
|
||||
const node_1 = require("../typeguard/node");
|
||||
function isEmptyObjectType(type) {
|
||||
if (type_1.isObjectType(type) &&
|
||||
type.objectFlags & ts.ObjectFlags.Anonymous &&
|
||||
type.getProperties().length === 0 &&
|
||||
type.getCallSignatures().length === 0 &&
|
||||
type.getConstructSignatures().length === 0 &&
|
||||
type.getStringIndexType() === undefined &&
|
||||
type.getNumberIndexType() === undefined) {
|
||||
const baseTypes = type.getBaseTypes();
|
||||
return baseTypes === undefined || baseTypes.every(isEmptyObjectType);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.isEmptyObjectType = isEmptyObjectType;
|
||||
function removeOptionalityFromType(checker, type) {
|
||||
if (!containsTypeWithFlag(type, ts.TypeFlags.Undefined))
|
||||
return type;
|
||||
const allowsNull = containsTypeWithFlag(type, ts.TypeFlags.Null);
|
||||
type = checker.getNonNullableType(type);
|
||||
return allowsNull ? checker.getNullableType(type, ts.TypeFlags.Null) : type;
|
||||
}
|
||||
exports.removeOptionalityFromType = removeOptionalityFromType;
|
||||
function containsTypeWithFlag(type, flag) {
|
||||
for (const t of unionTypeParts(type))
|
||||
if (util_1.isTypeFlagSet(t, flag))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
function removeOptionalChainingUndefinedMarkerType(checker, type) {
|
||||
if (!type_1.isUnionType(type))
|
||||
return isOptionalChainingUndefinedMarkerType(checker, type) ? type.getNonNullableType() : type;
|
||||
let flags = 0;
|
||||
let containsUndefinedMarker = false;
|
||||
for (const t of type.types) {
|
||||
if (isOptionalChainingUndefinedMarkerType(checker, t)) {
|
||||
containsUndefinedMarker = true;
|
||||
}
|
||||
else {
|
||||
flags |= t.flags;
|
||||
}
|
||||
}
|
||||
return containsUndefinedMarker
|
||||
? checker.getNullableType(type.getNonNullableType(), flags)
|
||||
: type;
|
||||
}
|
||||
exports.removeOptionalChainingUndefinedMarkerType = removeOptionalChainingUndefinedMarkerType;
|
||||
function isOptionalChainingUndefinedMarkerType(checker, t) {
|
||||
return util_1.isTypeFlagSet(t, ts.TypeFlags.Undefined) && checker.getNullableType(t.getNonNullableType(), ts.TypeFlags.Undefined) !== t;
|
||||
}
|
||||
exports.isOptionalChainingUndefinedMarkerType = isOptionalChainingUndefinedMarkerType;
|
||||
function isTypeAssignableToNumber(checker, type) {
|
||||
return isTypeAssignableTo(checker, type, ts.TypeFlags.NumberLike);
|
||||
}
|
||||
exports.isTypeAssignableToNumber = isTypeAssignableToNumber;
|
||||
function isTypeAssignableToString(checker, type) {
|
||||
return isTypeAssignableTo(checker, type, ts.TypeFlags.StringLike);
|
||||
}
|
||||
exports.isTypeAssignableToString = isTypeAssignableToString;
|
||||
function isTypeAssignableTo(checker, type, flags) {
|
||||
flags |= ts.TypeFlags.Any;
|
||||
let typeParametersSeen;
|
||||
return (function check(t) {
|
||||
if (type_1.isTypeParameter(t) && t.symbol !== undefined && t.symbol.declarations !== undefined) {
|
||||
if (typeParametersSeen === undefined) {
|
||||
typeParametersSeen = new Set([t]);
|
||||
}
|
||||
else if (!typeParametersSeen.has(t)) {
|
||||
typeParametersSeen.add(t);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
const declaration = t.symbol.declarations[0];
|
||||
if (declaration.constraint === undefined)
|
||||
return true; // TODO really?
|
||||
return check(checker.getTypeFromTypeNode(declaration.constraint));
|
||||
}
|
||||
if (type_1.isUnionType(t))
|
||||
return t.types.every(check);
|
||||
if (type_1.isIntersectionType(t))
|
||||
return t.types.some(check);
|
||||
return util_1.isTypeFlagSet(t, flags);
|
||||
})(type);
|
||||
}
|
||||
function getCallSignaturesOfType(type) {
|
||||
if (type_1.isUnionType(type)) {
|
||||
const signatures = [];
|
||||
for (const t of type.types)
|
||||
signatures.push(...getCallSignaturesOfType(t));
|
||||
return signatures;
|
||||
}
|
||||
if (type_1.isIntersectionType(type)) {
|
||||
let signatures;
|
||||
for (const t of type.types) {
|
||||
const sig = getCallSignaturesOfType(t);
|
||||
if (sig.length !== 0) {
|
||||
if (signatures !== undefined)
|
||||
return []; // if more than one type of the intersection has call signatures, none of them is useful for inference
|
||||
signatures = sig;
|
||||
}
|
||||
}
|
||||
return signatures === undefined ? [] : signatures;
|
||||
}
|
||||
return type.getCallSignatures();
|
||||
}
|
||||
exports.getCallSignaturesOfType = getCallSignaturesOfType;
|
||||
/** Returns all types of a union type or an array containing `type` itself if it's no union type. */
|
||||
function unionTypeParts(type) {
|
||||
return type_1.isUnionType(type) ? type.types : [type];
|
||||
}
|
||||
exports.unionTypeParts = unionTypeParts;
|
||||
/** Returns all types of a intersection type or an array containing `type` itself if it's no intersection type. */
|
||||
function intersectionTypeParts(type) {
|
||||
return type_1.isIntersectionType(type) ? type.types : [type];
|
||||
}
|
||||
exports.intersectionTypeParts = intersectionTypeParts;
|
||||
function someTypePart(type, predicate, cb) {
|
||||
return predicate(type) ? type.types.some(cb) : cb(type);
|
||||
}
|
||||
exports.someTypePart = someTypePart;
|
||||
function isThenableType(checker, node, type = checker.getTypeAtLocation(node)) {
|
||||
for (const ty of unionTypeParts(checker.getApparentType(type))) {
|
||||
const then = ty.getProperty('then');
|
||||
if (then === undefined)
|
||||
continue;
|
||||
const thenType = checker.getTypeOfSymbolAtLocation(then, node);
|
||||
for (const t of unionTypeParts(thenType))
|
||||
for (const signature of t.getCallSignatures())
|
||||
if (signature.parameters.length !== 0 && isCallback(checker, signature.parameters[0], node))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.isThenableType = isThenableType;
|
||||
function isCallback(checker, param, node) {
|
||||
let type = checker.getApparentType(checker.getTypeOfSymbolAtLocation(param, node));
|
||||
if (param.valueDeclaration.dotDotDotToken) {
|
||||
// unwrap array type of rest parameter
|
||||
type = type.getNumberIndexType();
|
||||
if (type === undefined)
|
||||
return false;
|
||||
}
|
||||
for (const t of unionTypeParts(type))
|
||||
if (t.getCallSignatures().length !== 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
/** Determine if a type is definitely falsy. This function doesn't unwrap union types. */
|
||||
function isFalsyType(type) {
|
||||
if (type.flags & (ts.TypeFlags.Undefined | ts.TypeFlags.Null | ts.TypeFlags.Void))
|
||||
return true;
|
||||
if (type_1.isLiteralType(type))
|
||||
return !type.value;
|
||||
return isBooleanLiteralType(type, false);
|
||||
}
|
||||
exports.isFalsyType = isFalsyType;
|
||||
/** Determines whether the given type is a boolean literal type and matches the given boolean literal (true or false). */
|
||||
function isBooleanLiteralType(type, literal) {
|
||||
return util_1.isTypeFlagSet(type, ts.TypeFlags.BooleanLiteral) &&
|
||||
type.intrinsicName === (literal ? 'true' : 'false');
|
||||
}
|
||||
exports.isBooleanLiteralType = isBooleanLiteralType;
|
||||
function getPropertyOfType(type, name) {
|
||||
if (!name.startsWith('__'))
|
||||
return type.getProperty(name);
|
||||
return type.getProperties().find((s) => s.escapedName === name);
|
||||
}
|
||||
exports.getPropertyOfType = getPropertyOfType;
|
||||
function getWellKnownSymbolPropertyOfType(type, wellKnownSymbolName, checker) {
|
||||
const prefix = '__@' + wellKnownSymbolName;
|
||||
for (const prop of type.getProperties()) {
|
||||
if (!prop.name.startsWith(prefix))
|
||||
continue;
|
||||
const globalSymbol = checker.getApparentType(checker.getTypeAtLocation(prop.valueDeclaration.name.expression)).symbol;
|
||||
if (prop.escapedName === getPropertyNameOfWellKnownSymbol(checker, globalSymbol, wellKnownSymbolName))
|
||||
return prop;
|
||||
}
|
||||
return;
|
||||
}
|
||||
exports.getWellKnownSymbolPropertyOfType = getWellKnownSymbolPropertyOfType;
|
||||
function getPropertyNameOfWellKnownSymbol(checker, symbolConstructor, symbolName) {
|
||||
const knownSymbol = symbolConstructor &&
|
||||
checker.getTypeOfSymbolAtLocation(symbolConstructor, symbolConstructor.valueDeclaration).getProperty(symbolName);
|
||||
const knownSymbolType = knownSymbol && checker.getTypeOfSymbolAtLocation(knownSymbol, knownSymbol.valueDeclaration);
|
||||
if (knownSymbolType && type_1.isUniqueESSymbolType(knownSymbolType))
|
||||
return knownSymbolType.escapedName;
|
||||
return ('__@' + symbolName);
|
||||
}
|
||||
/** Determines if writing to a certain property of a given type is allowed. */
|
||||
function isPropertyReadonlyInType(type, name, checker) {
|
||||
let seenProperty = false;
|
||||
let seenReadonlySignature = false;
|
||||
for (const t of unionTypeParts(type)) {
|
||||
if (getPropertyOfType(t, name) === undefined) {
|
||||
// property is not present in this part of the union -> check for readonly index signature
|
||||
const index = (util_1.isNumericPropertyName(name) ? checker.getIndexInfoOfType(t, ts.IndexKind.Number) : undefined) ||
|
||||
checker.getIndexInfoOfType(t, ts.IndexKind.String);
|
||||
if (index !== undefined && index.isReadonly) {
|
||||
if (seenProperty)
|
||||
return true;
|
||||
seenReadonlySignature = true;
|
||||
}
|
||||
}
|
||||
else if (seenReadonlySignature || isReadonlyPropertyIntersection(t, name, checker)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
seenProperty = true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.isPropertyReadonlyInType = isPropertyReadonlyInType;
|
||||
function isReadonlyPropertyIntersection(type, name, checker) {
|
||||
return someTypePart(type, type_1.isIntersectionType, (t) => {
|
||||
const prop = getPropertyOfType(t, name);
|
||||
if (prop === undefined)
|
||||
return false;
|
||||
if (prop.flags & ts.SymbolFlags.Transient) {
|
||||
if (/^(?:[1-9]\d*|0)$/.test(name) && type_1.isTupleTypeReference(t))
|
||||
return t.target.readonly;
|
||||
switch (isReadonlyPropertyFromMappedType(t, name, checker)) {
|
||||
case true:
|
||||
return true;
|
||||
case false:
|
||||
return false;
|
||||
default:
|
||||
// `undefined` falls through
|
||||
}
|
||||
}
|
||||
return (
|
||||
// members of namespace import
|
||||
util_1.isSymbolFlagSet(prop, ts.SymbolFlags.ValueModule) ||
|
||||
// we unwrapped every mapped type, now we can check the actual declarations
|
||||
symbolHasReadonlyDeclaration(prop, checker));
|
||||
});
|
||||
}
|
||||
function isReadonlyPropertyFromMappedType(type, name, checker) {
|
||||
if (!type_1.isObjectType(type) || !util_1.isObjectFlagSet(type, ts.ObjectFlags.Mapped))
|
||||
return;
|
||||
const declaration = type.symbol.declarations[0];
|
||||
// well-known symbols are not affected by mapped types
|
||||
if (declaration.readonlyToken !== undefined && !/^__@[^@]+$/.test(name))
|
||||
return declaration.readonlyToken.kind !== ts.SyntaxKind.MinusToken;
|
||||
return isPropertyReadonlyInType(type.modifiersType, name, checker);
|
||||
}
|
||||
function symbolHasReadonlyDeclaration(symbol, checker) {
|
||||
return (symbol.flags & ts.SymbolFlags.Accessor) === ts.SymbolFlags.GetAccessor ||
|
||||
symbol.declarations !== undefined &&
|
||||
symbol.declarations.some((node) => util_1.isModifierFlagSet(node, ts.ModifierFlags.Readonly) ||
|
||||
node_1.isVariableDeclaration(node) && util_1.isNodeFlagSet(node.parent, ts.NodeFlags.Const) ||
|
||||
node_1.isCallExpression(node) && util_1.isReadonlyAssignmentDeclaration(node, checker) ||
|
||||
node_1.isEnumMember(node) ||
|
||||
(node_1.isPropertyAssignment(node) || node_1.isShorthandPropertyAssignment(node)) && util_1.isInConstContext(node.parent));
|
||||
}
|
||||
exports.symbolHasReadonlyDeclaration = symbolHasReadonlyDeclaration;
|
||||
/** Returns the the literal name or unique symbol name from a given type. Doesn't unwrap union types. */
|
||||
function getPropertyNameFromType(type) {
|
||||
// string or number literal. bigint is intentionally excluded
|
||||
if (type.flags & (ts.TypeFlags.StringLiteral | ts.TypeFlags.NumberLiteral)) {
|
||||
const value = String(type.value);
|
||||
return { displayName: value, symbolName: ts.escapeLeadingUnderscores(value) };
|
||||
}
|
||||
if (type_1.isUniqueESSymbolType(type))
|
||||
return {
|
||||
displayName: `[${type.symbol
|
||||
? `${isKnownSymbol(type.symbol) ? 'Symbol.' : ''}${type.symbol.name}`
|
||||
: type.escapedName.replace(/^__@|@\d+$/g, '')}]`,
|
||||
symbolName: type.escapedName,
|
||||
};
|
||||
}
|
||||
exports.getPropertyNameFromType = getPropertyNameFromType;
|
||||
function isKnownSymbol(symbol) {
|
||||
return util_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Property) &&
|
||||
symbol.valueDeclaration !== undefined &&
|
||||
node_1.isInterfaceDeclaration(symbol.valueDeclaration.parent) &&
|
||||
symbol.valueDeclaration.parent.name.text === 'SymbolConstructor' &&
|
||||
isGlobalDeclaration(symbol.valueDeclaration.parent);
|
||||
}
|
||||
function isGlobalDeclaration(node) {
|
||||
return util_1.isNodeFlagSet(node.parent, ts.NodeFlags.GlobalAugmentation) || node_1.isSourceFile(node.parent) && !ts.isExternalModule(node.parent);
|
||||
}
|
||||
function getSymbolOfClassLikeDeclaration(node, checker) {
|
||||
var _a;
|
||||
return checker.getSymbolAtLocation((_a = node.name) !== null && _a !== void 0 ? _a : util_1.getChildOfKind(node, ts.SyntaxKind.ClassKeyword));
|
||||
}
|
||||
exports.getSymbolOfClassLikeDeclaration = getSymbolOfClassLikeDeclaration;
|
||||
function getConstructorTypeOfClassLikeDeclaration(node, checker) {
|
||||
return node.kind === ts.SyntaxKind.ClassExpression
|
||||
? checker.getTypeAtLocation(node)
|
||||
: checker.getTypeOfSymbolAtLocation(getSymbolOfClassLikeDeclaration(node, checker), node);
|
||||
}
|
||||
exports.getConstructorTypeOfClassLikeDeclaration = getConstructorTypeOfClassLikeDeclaration;
|
||||
function getInstanceTypeOfClassLikeDeclaration(node, checker) {
|
||||
return node.kind === ts.SyntaxKind.ClassDeclaration
|
||||
? checker.getTypeAtLocation(node)
|
||||
: checker.getDeclaredTypeOfSymbol(getSymbolOfClassLikeDeclaration(node, checker));
|
||||
}
|
||||
exports.getInstanceTypeOfClassLikeDeclaration = getInstanceTypeOfClassLikeDeclaration;
|
||||
function getIteratorYieldResultFromIteratorResult(type, node, checker) {
|
||||
return type_1.isUnionType(type) && type.types.find((t) => {
|
||||
const done = t.getProperty('done');
|
||||
return done !== undefined &&
|
||||
isBooleanLiteralType(removeOptionalityFromType(checker, checker.getTypeOfSymbolAtLocation(done, node)), false);
|
||||
}) || type;
|
||||
}
|
||||
exports.getIteratorYieldResultFromIteratorResult = getIteratorYieldResultFromIteratorResult;
|
||||
/** Lookup the declaration of a class member in the super class. */
|
||||
function getBaseClassMemberOfClassElement(node, checker) {
|
||||
if (!node_1.isClassLikeDeclaration(node.parent))
|
||||
return;
|
||||
const base = util_1.getBaseOfClassLikeExpression(node.parent);
|
||||
if (base === undefined)
|
||||
return;
|
||||
const name = util_1.getSingleLateBoundPropertyNameOfPropertyName(node.name, checker);
|
||||
if (name === undefined)
|
||||
return;
|
||||
const baseType = checker.getTypeAtLocation(util_1.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword)
|
||||
? base.expression
|
||||
: base);
|
||||
return getPropertyOfType(baseType, name.symbolName);
|
||||
}
|
||||
exports.getBaseClassMemberOfClassElement = getBaseClassMemberOfClassElement;
|
||||
//# sourceMappingURL=type.js.map
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue