downlevel-dts
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -24,1 +24,7 @@ /// <reference path="./src/test.d.ts" /> | ||
export type F = Pick<E, Exclude<keyof E, 'a'>>; | ||
export class G { | ||
private "G.#private"; | ||
} | ||
export class H extends G { | ||
private "H.#private"; | ||
} |
60
index.js
@@ -22,5 +22,3 @@ #!/usr/bin/env node | ||
const program = ts.createProgram( | ||
sh | ||
.find(path.join(src)) | ||
.filter(f => f.endsWith(".d.ts") && !/node_modules/.test(f)), | ||
sh.find(path.join(src)).filter(f => f.endsWith(".d.ts") && !/node_modules/.test(f)), | ||
{} | ||
@@ -33,9 +31,5 @@ ); | ||
}); | ||
for (const t of ts.transform(files, [doTransform.bind(null, checker)]) | ||
.transformed) { | ||
for (const t of ts.transform(files, [doTransform.bind(null, checker)]).transformed) { | ||
const f = /** @type {import("typescript").SourceFile} */ (t); | ||
const targetPath = path.join( | ||
target, | ||
path.resolve(f.fileName).slice(path.resolve(src).length) | ||
); | ||
const targetPath = path.join(target, path.resolve(f.fileName).slice(path.resolve(src).length)); | ||
sh.mkdir("-p", path.dirname(targetPath)); | ||
@@ -52,3 +46,2 @@ fs.writeFileSync(targetPath, dedupeTripleSlash(printer.printFile(f))); | ||
} | ||
/** | ||
@@ -95,2 +88,14 @@ * @param {import("typescript").TypeChecker} checker | ||
} | ||
} else if (ts.isPropertyDeclaration(n) && ts.isPrivateIdentifier(n.name) && n.name.escapedText === "#private") { | ||
// #private => private "#private" | ||
const modifiers = ts.createModifiersFromModifierFlags(ts.ModifierFlags.Private); | ||
const parentName = n.parent.name ? n.parent.name.escapedText : "(anonymous)"; | ||
return ts.createProperty( | ||
n.decorators, | ||
modifiers, | ||
ts.createStringLiteral(parentName + ".#private"), | ||
/*?! token*/ undefined, | ||
/*type*/ undefined, | ||
/*initialiser*/ undefined | ||
); | ||
} else if ( | ||
@@ -111,6 +116,3 @@ ts.isExportDeclaration(n) && | ||
n.modifiers, | ||
ts.createImportClause( | ||
/*name*/ undefined, | ||
ts.createNamespaceImport(tempName) | ||
), | ||
ts.createImportClause(/*name*/ undefined, ts.createNamespaceImport(tempName)), | ||
n.moduleSpecifier | ||
@@ -121,5 +123,3 @@ ), | ||
undefined, | ||
ts.createNamedExports([ | ||
ts.createExportSpecifier(tempName, n.exportClause.name) | ||
]), | ||
ts.createNamedExports([ts.createExportSpecifier(tempName, n.exportClause.name)]), | ||
n.moduleSpecifier | ||
@@ -129,15 +129,6 @@ ) | ||
} else if (ts.isExportDeclaration(n) && n.isTypeOnly) { | ||
return ts.createExportDeclaration( | ||
n.decorators, | ||
n.modifiers, | ||
n.exportClause, | ||
n.moduleSpecifier | ||
); | ||
return ts.createExportDeclaration(n.decorators, n.modifiers, n.exportClause, n.moduleSpecifier); | ||
} else if (ts.isImportClause(n) && n.isTypeOnly) { | ||
return ts.createImportClause(n.name, n.namedBindings); | ||
} else if ( | ||
ts.isTypeReferenceNode(n) && | ||
ts.isIdentifier(n.typeName) && | ||
n.typeName.escapedText === "Omit" | ||
) { | ||
} else if (ts.isTypeReferenceNode(n) && ts.isIdentifier(n.typeName) && n.typeName.escapedText === "Omit") { | ||
const symbol = checker.getSymbolAtLocation(n.typeName); | ||
@@ -149,5 +140,3 @@ const typeArguments = n.typeArguments; | ||
symbol.declarations.length && | ||
symbol.declarations[0] | ||
.getSourceFile() | ||
.fileName.includes("node_modules/typescript/lib/lib") && | ||
symbol.declarations[0].getSourceFile().fileName.includes("node_modules/typescript/lib/lib") && | ||
typeArguments | ||
@@ -179,10 +168,5 @@ ) { | ||
function getMatchingAccessor(n, getset) { | ||
if (!ts.isClassDeclaration(n.parent)) | ||
throw new Error( | ||
"Bad AST -- accessor parent should be a class declaration." | ||
); | ||
if (!ts.isClassDeclaration(n.parent)) throw new Error("Bad AST -- accessor parent should be a class declaration."); | ||
const isOther = getset === "get" ? ts.isSetAccessor : ts.isGetAccessor; | ||
return n.parent.members.some( | ||
m => isOther(m) && m.name.getText() === n.name.getText() | ||
); | ||
return n.parent.members.some(m => isOther(m) && m.name.getText() === n.name.getText()); | ||
} | ||
@@ -189,0 +173,0 @@ |
@@ -22,9 +22,9 @@ const { main } = require("./index"); | ||
main("test", "test/ts3.4"); | ||
expect(fs.readFileSync("baselines/ts3.4/test.d.ts", "utf8")).toEqual( | ||
fs.readFileSync("test/ts3.4/test.d.ts", "utf8") | ||
expect(fs.readFileSync("test/ts3.4/test.d.ts", "utf8")).toEqual( | ||
fs.readFileSync("baselines/ts3.4/test.d.ts", "utf8") | ||
); | ||
expect(fs.readFileSync("baselines/ts3.4/src/test.d.ts", "utf8")).toEqual( | ||
fs.readFileSync("test/ts3.4/src/test.d.ts", "utf8") | ||
expect(fs.readFileSync("test/ts3.4/src/test.d.ts", "utf8")).toEqual( | ||
fs.readFileSync("baselines/ts3.4/src/test.d.ts", "utf8") | ||
); | ||
} | ||
}); |
module.exports = { | ||
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.jsx?$", | ||
"moduleFileExtensions": [ | ||
"js", | ||
"jsx", | ||
"json", | ||
"node" | ||
], | ||
} | ||
testRegex: "(/__tests__/.*|\\.(test|spec))\\.jsx?$", | ||
moduleFileExtensions: ["js", "jsx", "json", "node"] | ||
}; |
{ | ||
"name": "downlevel-dts", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Convert d.ts to be compatible with older typescript compilers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -28,1 +28,8 @@ /// <reference types="node" /> | ||
export type F = Omit<E, 'a'>; | ||
export class G { | ||
#private | ||
} | ||
export class H extends G { | ||
#private | ||
} |
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
12342
16
333