Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TS 4.8+ #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 18 additions & 15 deletions packages/ts-transform-paths/src/importPathVisitor.ts
Expand Up @@ -64,28 +64,30 @@ export function importPathVisitor(
if (!newImport || newImport === importValue) return

if (nodeToFix && fixNode) fixNode(nodeToFix, newImport)
const newSpec = ts.createLiteral(newImport)
const newSpec = ts.factory.createStringLiteral(newImport)

let newNode: ts.Node | undefined

if (ts.isImportTypeNode(node)) {
newNode = ts.updateImportTypeNode(
newNode = ts.factory.updateImportTypeNode(
node,
ts.createLiteralTypeNode(newSpec),
ts.factory.createLiteralTypeNode(newSpec),
node.qualifier,
node.typeArguments,
node.isTypeOf
)
newNode.flags = node.flags
}

const mods = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined

if (ts.isImportDeclaration(node)) {
const importNode = ts.updateImportDeclaration(
const importNode = ts.factory.updateImportDeclaration(
node,
node.decorators,
node.modifiers,
mods,
node.importClause,
newSpec
newSpec,
node.assertClause
)

importNode.moduleSpecifier.parent = node.moduleSpecifier.parent
Expand Down Expand Up @@ -117,14 +119,16 @@ export function importPathVisitor(
}

if (ts.isExportDeclaration(node)) {
const exportNode = ts.updateExportDeclaration(

const exportNode = ts.factory.updateExportDeclaration(
node,
node.decorators,
node.modifiers,
mods,
node.isTypeOnly,
node.exportClause,
newSpec,
node.isTypeOnly
node.assertClause
)

if (exportNode.flags !== node.flags) {
/**
* Additional hacks for exports. Without it ts throw exception, if flags changed in export node.
Expand All @@ -144,15 +148,14 @@ export function importPathVisitor(
}

if (ts.isCallExpression(node))
newNode = ts.updateCall(node, node.expression, node.typeArguments, [
newNode = ts.factory.updateCallExpression(node, node.expression, node.typeArguments, [
newSpec,
])

if (ts.isModuleDeclaration(node)) {
newNode = ts.updateModuleDeclaration(
newNode = ts.factory.updateModuleDeclaration(
node,
node.decorators,
node.modifiers,
mods,
newSpec,
node.body
)
Expand Down