From ff0b022a1fcba803e159e0d6a39e67472f54a293 Mon Sep 17 00:00:00 2001 From: Shawn Walton Date: Fri, 23 Sep 2022 13:48:21 -0700 Subject: [PATCH] Upgrade TS to 4.5.x, fix some of the broken tests --- package.json | 2 +- src/nodes/export-declaration.ts | 6 +----- src/printers/node.ts | 12 ++++++++++-- yarn.lock | 8 ++++---- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index fed36985..6e692dad 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lodash": "^4.17.20", "prettier": "^2.5.1", "shelljs": "^0.8.4", - "typescript": "~4.4.4", + "typescript": "~4.5.0", "typescript-compiler": "^1.4.1-2" }, "devDependencies": { diff --git a/src/nodes/export-declaration.ts b/src/nodes/export-declaration.ts index 7bce8fa4..90ee4913 100644 --- a/src/nodes/export-declaration.ts +++ b/src/nodes/export-declaration.ts @@ -37,13 +37,9 @@ export default class ExportDeclaration extends Node { } else { typeExports = []; valueExports = []; - let nextIsType = false; for (const node of rawElements) { - if (nextIsType) { + if (node.isTypeOnly) { typeExports.push(node); - nextIsType = false; - } else if (node.name.originalKeywordKind === 150) { - nextIsType = true; } else { valueExports.push(node); } diff --git a/src/printers/node.ts b/src/printers/node.ts index de0b884d..430c7bd4 100644 --- a/src/printers/node.ts +++ b/src/printers/node.ts @@ -218,6 +218,9 @@ export function getFullyQualifiedName( decl.kind === ts.SyntaxKind.TypeParameter || leftMostSymbol?.parent?.escapedName === "__global"; } + // TODO: something here is fucky. we want to take the branch when merging namespaces + // so that we get ns$a.b instead of ns$a$b, but we want to not take it when printing + // globalThis.whatever; taking it will print globalThis.whatever instead of whatever if (!symbol || typeChecker.isUnknownSymbol(symbol) || isExternalSymbol) { return printEntityName(type); } @@ -655,7 +658,12 @@ export const printType = withEnv( ${isTypeImport ? "" : "typeof "} ${getTypeofFullyQualifiedName(targetSymbol, type.typeName)}>`; } - return printers.declarations.typeReference(type, !targetSymbol); + // double-bang fixes most tests, but also breaks some utility types, + // esp the ones that aren't provided args when they're expected + // need to determine exactly what the difference between these two is + // and why they took different branches in 4.4 + return printers.declarations.typeReference(type, targetSymbol); + // return printers.declarations.typeReference(type, !targetSymbol); }; // if importing an enum, we have to change how the type is used across the file @@ -671,7 +679,7 @@ export const printType = withEnv( return getAdjustedType(symbol); } } - return printers.declarations.typeReference(type, !symbol); + return printers.declarations.typeReference(type, symbol); } case ts.SyntaxKind.VariableDeclaration: diff --git a/yarn.lock b/yarn.lock index dde61c01..5568c3a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4783,10 +4783,10 @@ typescript-compiler@^1.4.1-2: resolved "https://registry.yarnpkg.com/typescript-compiler/-/typescript-compiler-1.4.1-2.tgz#ba4f7db22d91534a1929d90009dce161eb72fd3f" integrity sha1-uk99si2RU0oZKdkACdzhYety/T8= -typescript@~4.4.4: - version "4.4.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" - integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== +typescript@~4.5.0: + version "4.5.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3" + integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA== unbox-primitive@^1.0.1: version "1.0.1"