downlevel-dts
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -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>; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
37022
30
1005
2
0