downlevel-dts
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -20,1 +20,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -20,1 +20,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
@@ -22,1 +22,7 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<T> = () => T; | ||
export type Setter<T> = (value: T) => void; | ||
export interface State<T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
110
index.js
@@ -66,7 +66,11 @@ #!/usr/bin/env node | ||
if (ts.isFunctionTypeNode(n) && n.type && ts.isTypePredicateNode(n.type) && n.type.assertsModifier) { | ||
return ts.createFunctionTypeNode(n.typeParameters, n.parameters, ts.createTypeReferenceNode("void", undefined)); | ||
return ts.factory.createFunctionTypeNode( | ||
n.typeParameters, | ||
n.parameters, | ||
ts.factory.createTypeReferenceNode("void", undefined) | ||
); | ||
} | ||
if (ts.isFunctionDeclaration(n) && n.type && ts.isTypePredicateNode(n.type) && n.type.assertsModifier) { | ||
return ts.createFunctionDeclaration( | ||
return ts.factory.createFunctionDeclaration( | ||
n.decorators, | ||
@@ -78,3 +82,3 @@ n.modifiers, | ||
n.parameters, | ||
ts.createTypeReferenceNode("void", undefined), | ||
ts.factory.createTypeReferenceNode("void", undefined), | ||
n.body | ||
@@ -92,6 +96,6 @@ ); | ||
} | ||
const modifiers = ts.createModifiersFromModifierFlags(flags); | ||
const modifiers = ts.factory.createModifiersFromModifierFlags(flags); | ||
return copyComment( | ||
other ? [n, other] : [n], | ||
ts.createProperty( | ||
ts.factory.createPropertyDeclaration( | ||
n.decorators, | ||
@@ -113,3 +117,3 @@ modifiers, | ||
[n], | ||
ts.createProperty( | ||
ts.factory.createPropertyDeclaration( | ||
n.decorators, | ||
@@ -128,3 +132,3 @@ n.modifiers, | ||
if (isStdLibSymbol(symbol) && typeArguments) { | ||
return ts.createTypeReferenceNode(ts.createIdentifier("IteratorResult"), [typeArguments[0]]); | ||
return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("IteratorResult"), [typeArguments[0]]); | ||
} | ||
@@ -138,8 +142,8 @@ } else if ( | ||
// #private => private "#private" | ||
const modifiers = ts.createModifiersFromModifierFlags(ts.ModifierFlags.Private); | ||
const modifiers = ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Private); | ||
const parentName = n.parent.name ? n.parent.name.escapedText : "(anonymous)"; | ||
return ts.createProperty( | ||
return ts.factory.createPropertyDeclaration( | ||
n.decorators, | ||
modifiers, | ||
ts.createStringLiteral(parentName + ".#private"), | ||
ts.factory.createStringLiteral(parentName + ".#private"), | ||
/*?! token*/ undefined, | ||
@@ -160,8 +164,8 @@ /*type*/ undefined, | ||
// export { ns_1 as ns } | ||
const tempName = ts.createUniqueName(n.exportClause.name.getText()); | ||
const tempName = ts.factory.createUniqueName(n.exportClause.name.getText()); | ||
return [ | ||
ts.createImportDeclaration( | ||
ts.factory.createImportDeclaration( | ||
n.decorators, | ||
n.modifiers, | ||
ts.createImportClause(/*name*/ undefined, ts.createNamespaceImport(tempName)), | ||
ts.factory.createImportClause(false, /*name*/ undefined, ts.factory.createNamespaceImport(tempName)), | ||
n.moduleSpecifier | ||
@@ -171,6 +175,7 @@ ), | ||
[n], | ||
ts.createExportDeclaration( | ||
ts.factory.createExportDeclaration( | ||
undefined, | ||
undefined, | ||
ts.createNamedExports([ts.createExportSpecifier(false, tempName, n.exportClause.name)]) | ||
false, | ||
ts.factory.createNamedExports([ts.factory.createExportSpecifier(false, tempName, n.exportClause.name)]) | ||
) | ||
@@ -180,5 +185,5 @@ ) | ||
} else if (semver.lt(targetVersion, "3.8.0") && ts.isExportDeclaration(n) && n.isTypeOnly) { | ||
return ts.createExportDeclaration(n.decorators, n.modifiers, n.exportClause, n.moduleSpecifier); | ||
return ts.factory.createExportDeclaration(n.decorators, n.modifiers, false, n.exportClause, n.moduleSpecifier); | ||
} else if (semver.lt(targetVersion, "3.8.0") && ts.isImportClause(n) && n.isTypeOnly) { | ||
return ts.createImportClause(n.name, n.namedBindings); | ||
return ts.factory.createImportClause(false, n.name, n.namedBindings); | ||
} else if ( | ||
@@ -202,8 +207,11 @@ semver.lt(targetVersion, "4.5.0") && | ||
[n], | ||
ts.createImportDeclaration( | ||
ts.factory.createImportDeclaration( | ||
n.decorators, | ||
n.modifiers, | ||
ts.createImportClause( | ||
ts.factory.createImportClause( | ||
false, | ||
n.importClause.name, | ||
ts.createNamedImports(elements.map(e => ts.createImportSpecifier(false, e.propertyName, e.name))) | ||
ts.factory.createNamedImports( | ||
elements.map(e => ts.factory.createImportSpecifier(false, e.propertyName, e.name)) | ||
) | ||
), | ||
@@ -230,9 +238,11 @@ n.moduleSpecifier | ||
[n], | ||
ts.createImportDeclaration( | ||
ts.factory.createImportDeclaration( | ||
n.decorators, | ||
n.modifiers, | ||
ts.createImportClause( | ||
ts.factory.createImportClause( | ||
true, | ||
n.importClause.name, | ||
ts.createNamedImports(typeElements.map(e => ts.createImportSpecifier(false, e.propertyName, e.name))), | ||
true | ||
ts.createNamedImports( | ||
typeElements.map(e => ts.factory.createImportSpecifier(false, e.propertyName, e.name)) | ||
) | ||
), | ||
@@ -255,8 +265,11 @@ n.moduleSpecifier | ||
typeOnlyImportDeclaration, | ||
ts.createImportDeclaration( | ||
ts.factory.createImportDeclaration( | ||
n.decorators, | ||
n.modifiers, | ||
ts.createImportClause( | ||
ts.factory.createImportClause( | ||
false, | ||
n.importClause.name, | ||
ts.createNamedImports(valueElements.map(e => ts.createImportSpecifier(false, e.propertyName, e.name))) | ||
ts.factory.createNamedImports( | ||
valueElements.map(e => ts.factory.createImportSpecifier(false, e.propertyName, e.name)) | ||
) | ||
), | ||
@@ -286,6 +299,9 @@ n.moduleSpecifier | ||
[n], | ||
ts.createExportDeclaration( | ||
ts.factory.createExportDeclaration( | ||
n.decorators, | ||
n.modifiers, | ||
ts.createNamedExports(elements.map(e => ts.createExportSpecifier(false, e.propertyName, e.name))), | ||
false, | ||
ts.factory.createNamedExports( | ||
elements.map(e => ts.factory.createExportSpecifier(false, e.propertyName, e.name)) | ||
), | ||
n.moduleSpecifier | ||
@@ -313,8 +329,10 @@ ) | ||
[n], | ||
ts.createExportDeclaration( | ||
ts.factory.createExportDeclaration( | ||
n.decorators, | ||
n.modifiers, | ||
ts.createNamedExports(typeElements.map(e => ts.createExportSpecifier(false, e.propertyName, e.name))), | ||
n.moduleSpecifier, | ||
true | ||
true, | ||
ts.factory.createNamedExports( | ||
typeElements.map(e => ts.factory.createExportSpecifier(false, e.propertyName, e.name)) | ||
), | ||
n.moduleSpecifier | ||
) | ||
@@ -340,6 +358,9 @@ ); | ||
typeOnlyExportDeclaration, | ||
ts.createExportDeclaration( | ||
ts.factory.createExportDeclaration( | ||
n.decorators, | ||
n.modifiers, | ||
ts.createNamedExports(valueElements.map(e => ts.createExportSpecifier(false, e.propertyName, e.name))), | ||
false, | ||
ts.factory.createNamedExports( | ||
valueElements.map(e => ts.factory.createExportSpecifier(false, e.propertyName, e.name)) | ||
), | ||
n.moduleSpecifier | ||
@@ -354,6 +375,6 @@ ) | ||
if (semver.lt(targetVersion, "3.5.0") && isStdLibSymbol(symbol) && typeArguments) { | ||
return ts.createTypeReferenceNode(ts.createIdentifier("Pick"), [ | ||
return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Pick"), [ | ||
typeArguments[0], | ||
ts.createTypeReferenceNode(ts.createIdentifier("Exclude"), [ | ||
ts.createTypeOperatorNode(typeArguments[0]), | ||
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Exclude"), [ | ||
ts.factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, typeArguments[0]), | ||
typeArguments[1] | ||
@@ -366,3 +387,3 @@ ]) | ||
return ts.addSyntheticLeadingComment( | ||
member.dotDotDotToken ? ts.createRestTypeNode(member.type) : member.type, | ||
member.dotDotDotToken ? ts.factory.createRestTypeNode(member.type) : member.type, | ||
ts.SyntaxKind.MultiLineCommentTrivia, | ||
@@ -372,2 +393,11 @@ ts.unescapeLeadingUnderscores(member.name.escapedText), | ||
); | ||
} else if (semver.lt(targetVersion, "4.7.0") && ts.isTypeParameterDeclaration(n)) { | ||
return ts.factory.createTypeParameterDeclaration( | ||
n.modifiers?.filter( | ||
modifier => modifier.kind !== ts.SyntaxKind.InKeyword && modifier.kind !== ts.SyntaxKind.OutKeyword | ||
), | ||
n.name, | ||
n.constraint, | ||
n.default | ||
); | ||
} | ||
@@ -380,3 +410,3 @@ return ts.visitEachChild(n, transform, k); | ||
function defaultAny(t) { | ||
return t || ts.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword); | ||
return t || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword); | ||
} | ||
@@ -383,0 +413,0 @@ |
@@ -7,3 +7,3 @@ const { main } = require("./index"); | ||
describe("main", () => { | ||
const tsVersions = ["3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6"]; | ||
const tsVersions = ["3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6", "4.7"]; | ||
@@ -10,0 +10,0 @@ if (fs.existsSync(`baselines/local`)) { |
{ | ||
"name": "downlevel-dts", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "Convert d.ts to be compatible with older typescript compilers", | ||
@@ -21,10 +21,10 @@ "homepage": "https://github.com/sandersn/downlevel-dts", | ||
"shelljs": "^0.8.3", | ||
"typescript": "^4.5.5" | ||
"typescript": "next" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^13.1.6", | ||
"@types/semver": "^7.3.4", | ||
"@types/shelljs": "^0.8.6", | ||
"@types/semver": "^7.3.4", | ||
"husky": "^4.0.0", | ||
"jest": "^24.9.0", | ||
"jest": "^28.0.0", | ||
"prettier": "^1.19.1", | ||
@@ -31,0 +31,0 @@ "pretty-quick": "^2.0.1" |
@@ -316,3 +316,3 @@ downlevel-dts rewrites .d.ts files created by any version of TypeScript so | ||
"typesVersions": { | ||
"<3.9": { "*": ["ts3.4/*"] } | ||
"<4.0": { "*": ["ts3.4/*"] } | ||
} | ||
@@ -319,0 +319,0 @@ ``` |
@@ -25,2 +25,9 @@ export class C { | ||
export type F = Omit<E, 'a'>; | ||
export type F = Omit<E, 'a'>; | ||
export type Getter<out T> = () => T; | ||
export type Setter<in T> = (value: T) => void; | ||
export interface State<in out T> { | ||
get: () => T; | ||
set: (value: T) => void; | ||
} |
Sorry, the diff of this file is not supported yet
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
67277
45
2041
+ Addedtypescript@5.7.0-dev.20240912(transitive)
- Removedtypescript@4.9.5(transitive)
Updatedtypescript@next