magicast icon indicating copy to clipboard operation
magicast copied to clipboard

When add or modify imports, the format is not kept

Open iFwu opened this issue 2 years ago • 1 comments

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 avatar Apr 10 '23 07:04 iFwu

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

zoeyzhao19 avatar May 16 '23 06:05 zoeyzhao19