Socket
Socket
Sign inDemoInstall

downlevel-dts

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

downlevel-dts - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

.vscode/launch.json

7

baselines/reference/ts3.4/test.d.ts

@@ -53,1 +53,8 @@ /// <reference path="./src/test.d.ts" />

export { default_1 as default };
export declare type Asserts<T> = (val: unknown) => void;
export declare const foo: {
bar: {
baz: <T>(val: unknown) => void;
};
};
export type IR = IteratorResult<number>;

@@ -53,1 +53,8 @@ /// <reference path="./src/test.d.ts" />

export { default_1 as default };
export declare type Asserts<T> = (val: unknown) => void;
export declare const foo: {
bar: {
baz: <T>(val: unknown) => void;
};
};
export type IR = IteratorResult<number>;

@@ -55,1 +55,8 @@ /// <reference path="./src/test.d.ts" />

export { default_1 as default };
export declare type Asserts<T> = (val: unknown) => void;
export declare const foo: {
bar: {
baz: <T>(val: unknown) => void;
};
};
export type IR = IteratorResult<number, string>;

@@ -55,1 +55,8 @@ /// <reference path="./src/test.d.ts" />

export { default_1 as default };
export declare type Asserts<T> = (val: unknown) => asserts val is T;
export declare const foo: {
bar: {
baz: <T>(val: unknown) => asserts val is T;
};
};
export type IR = IteratorResult<number, string>;

@@ -53,1 +53,8 @@ /// <reference path="./src/test.d.ts" />

export * as default from "./src/test";
export declare type Asserts<T> = (val: unknown) => asserts val is T;
export declare const foo: {
bar: {
baz: <T>(val: unknown) => asserts val is T;
};
};
export type IR = IteratorResult<number, string>;

@@ -53,1 +53,8 @@ /// <reference path="./src/test.d.ts" />

export * as default from "./src/test";
export declare type Asserts<T> = (val: unknown) => asserts val is T;
export declare const foo: {
bar: {
baz: <T>(val: unknown) => asserts val is T;
};
};
export type IR = IteratorResult<number, string>;

@@ -53,1 +53,8 @@ /// <reference path="./src/test.d.ts" />

export * as default from "./src/test";
export declare type Asserts<T> = (val: unknown) => asserts val is T;
export declare const foo: {
bar: {
baz: <T>(val: unknown) => asserts val is T;
};
};
export type IR = IteratorResult<number, string>;

81

index.js

@@ -64,19 +64,19 @@ #!/usr/bin/env node

const transform = function(n) {
if (
semver.lt(targetVersion, "3.7.0") &&
ts.isFunctionDeclaration(n) &&
n.type &&
ts.isTypePredicateNode(n.type) &&
n.type.assertsModifier
) {
return ts.createFunctionDeclaration(
n.decorators,
n.modifiers,
n.asteriskToken,
n.name,
n.typeParameters,
n.parameters,
ts.createTypeReferenceNode("void", undefined),
n.body
);
if (semver.lt(targetVersion, "3.7.0")) {
if (ts.isFunctionTypeNode(n) && n.type && ts.isTypePredicateNode(n.type) && n.type.assertsModifier) {
return ts.createFunctionTypeNode(n.typeParameters, n.parameters, ts.createTypeReferenceNode("void", undefined));
}
if (ts.isFunctionDeclaration(n) && n.type && ts.isTypePredicateNode(n.type) && n.type.assertsModifier) {
return ts.createFunctionDeclaration(
n.decorators,
n.modifiers,
n.asteriskToken,
n.name,
n.typeParameters,
n.parameters,
ts.createTypeReferenceNode("void", undefined),
n.body
);
}
}

@@ -122,2 +122,8 @@

}
} else if (semver.lt(targetVersion, "3.6.0") && isTypeReference(n, "IteratorResult")) {
const symbol = checker.getSymbolAtLocation(ts.isTypeReferenceNode(n) ? n.typeName : n.expression);
const typeArguments = n.typeArguments;
if (isStdLibSymbol(symbol) && typeArguments) {
return ts.createTypeReferenceNode(ts.createIdentifier("IteratorResult"), [typeArguments[0]]);
}
} else if (

@@ -172,16 +178,7 @@ semver.lt(targetVersion, "3.8.0") &&

return ts.createImportClause(n.name, n.namedBindings);
} else if (
(ts.isTypeReferenceNode(n) && ts.isIdentifier(n.typeName) && n.typeName.escapedText === "Omit") ||
(ts.isExpressionWithTypeArguments(n) && ts.isIdentifier(n.expression) && n.expression.escapedText === "Omit")
) {
} else if (isTypeReference(n, "Omit")) {
const symbol = checker.getSymbolAtLocation(ts.isTypeReferenceNode(n) ? n.typeName : n.expression);
const typeArguments = n.typeArguments;
if (
semver.lt(targetVersion, "3.5.0") &&
symbol &&
symbol.declarations.length &&
symbol.declarations[0].getSourceFile().fileName.includes("node_modules/typescript/lib/lib") &&
typeArguments
) {
if (semver.lt(targetVersion, "3.5.0") && isStdLibSymbol(symbol) && typeArguments) {
return ts.createTypeReferenceNode(ts.createIdentifier("Pick"), [

@@ -284,1 +281,29 @@ typeArguments[0],

}
/**
* Checks whether a node is a type reference with typeName as a name
* @param {ts.Node} node AST node
* @param {string} typeName name of the type
* @returns true if the node is a type reference with typeName as a name
*/
function isTypeReference(node, typeName) {
return (
(ts.isTypeReferenceNode(node) && ts.isIdentifier(node.typeName) && node.typeName.escapedText === typeName) ||
(ts.isExpressionWithTypeArguments(node) &&
ts.isIdentifier(node.expression) &&
node.expression.escapedText === typeName)
);
}
/**
* Returns whether a symbol is a standard TypeScript library definition
* @param {ts.Symbol | undefined} symbol a symbol in source file
* @returns whether this symbol is for a standard TypeScript library definition
*/
function isStdLibSymbol(symbol) {
return (
symbol &&
symbol.declarations.length &&
symbol.declarations[0].getSourceFile().fileName.includes("node_modules/typescript/lib/lib")
);
}
{
"name": "downlevel-dts",
"version": "0.7.0",
"version": "0.8.0",
"description": "Convert d.ts to be compatible with older typescript compilers",

@@ -12,2 +12,6 @@ "homepage": "https://github.com/sandersn/downlevel-dts",

},
"repository": {
"type": "git",
"url": "https://github.com/sandersn/downlevel-dts.git"
},
"author": "Nathan Shively-Sanders",

@@ -14,0 +18,0 @@ "license": "MIT",

@@ -56,1 +56,11 @@ /// <reference path="./src/test.d.ts" />

export * as default from "./src/test";
export declare type Asserts<T> = (val: unknown) => asserts val is T;
export declare const foo: {
bar: {
baz: <T>(val: unknown) => asserts val is T;
};
};
export type IR = IteratorResult<number, string>;
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc