dsherret / dsherret/ts-morph

Using `set` on a node results in the node not being updated synchronously

Open
#1,402 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

When using `set` on an import declaration it results in the node not being updated synchronously. Using the specific `setDefaultImport` and `insertNamedImport` it does result in the node being updated synchronously as expected. I haven't been able to replicate this in a test environment unfortunately.

Here is example logs that are output. The add returns before it's complete, another request is then sent off the get the type data but because of the imports not being there anymore for a period of time it returns `any`.

```
import { Cake } from "./src/components/components";export function HelloWorld() {
return (
<>

);
}

could not find symbol mate
import "./src/components/components";export function HelloWorld() {
return (
<>

);
}

could not find symbol mate
import "./src/components/components";export function HelloWorld() {
return (
<>

);
}

could not find symbol mate
import { } from "./src/components/components";export function HelloWorld() {
return (
<>

);
}

could not find symbol mate
import { } from "./src/components/components";export function HelloWorld() {
return (
<>

);
}

import { Cake, Straw } from "./src/components/components";export function HelloWorld() {
return (
<>

);
}
```

Version: 17.0.1

**To Reproduce**

I need to figure out how best to replicate this, apologies.

**Expected behavior**

The `set` is synchronous so at the end of the function call its guaranteed to be updated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.