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

When add or modify imports, the format is not kept #41

Open
iFwu opened this issue Apr 10, 2023 · 1 comment
Open

When add or modify imports, the format is not kept #41

iFwu opened this issue Apr 10, 2023 · 1 comment

Comments

@iFwu
Copy link

iFwu commented Apr 10, 2023

Environment

Node: v18.15.0
magicast: v0.2.3

Reproduction

import { parseModule } from 'magicast'

const mod = parseModule(`import { defineConfig } from "foo"
export default defineConfig({})`)

mod.imports.defineConfig.from = 'bar'
console.log(mod.generate().code)

It outputs:

import { defineConfig } from "bar";
export default defineConfig({})

The semicolon should not be appended to the import declaration.

Describe the bug

When modify or add imports, the format is not kept.

Additional context

No response

Logs

No response

@iFwu iFwu changed the title Import When add or modify imports, the format is not kept Apr 10, 2023
@zoeyzhao19
Copy link
Contributor

It happened to be an recast's inline behavior since

Whenever Recast cannot reprint a modified node using the original source code, it falls back to using a generic pretty printer. So the worst that can happen is that your changes trigger some harmless reformatting of your code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants