gpt4 book ai didi

javascript - 如何在从 typescript 生成的javascript中维护空格

转载 作者:行者123 更新时间:2023-12-05 06:24:54 26 4
gpt4 key购买 nike

我希望从 typescript 生成的 javascript 代码具有相同的白色间距。长话短说,我们正在从 js 迁移到 ts,并且保留空白将使我们能够将生成的代码与未迁移的代码版本进行比较。

我的输入 ts 看起来像:

id = this.getOrCreate(
entity.uuid,
dao.wrap(utils.trimProxyPrefix(entity.name)),
dao.wrap(entity.type),
dao.wrap(entity.targetName),
dao.wrap(entity.targetType),
dao.wrap(entity.targetIp),
dao.wrap(host),
dao.wrap(version),
dao.wrap(status)
);

输出看起来很丑陋超长的一行:

id = this.getOrCreate(entity.uuid, dao.wrap(utils.trimProxyPrefix(entity.name)), dao.wrap(entity.type), dao.wrap(entity.targetName), dao.wrap(entity.targetType), dao.wrap(entity.targetIp), dao.wrap(host), dao.wrap(version), dao.wrap(status));  

我的预期输出是:

id = this.getOrCreate(
entity.uuid,
dao.wrap(utils.trimProxyPrefix(entity.name)),
dao.wrap(entity.type),
dao.wrap(entity.targetName),
dao.wrap(entity.targetType),
dao.wrap(entity.targetIp),
dao.wrap(host),
dao.wrap(version),
dao.wrap(status)
);

我的 tsconfig 看起来像:

{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./dist",
},
"include": ["./src/**/*"],
"exclude": [
"node_modules",
"./src/real/*"
]
}

最佳答案

根据 tsconfig.json 配置的不同,转译的 TypeScript 代码可能会有很大不同,因此在编译器中保留空格并不是一个真正的选项。

您可以做的一件事是首先通过像 Prettier 这样的格式化程序运行您的源代码。 ,并在编译后再次运行它(prettier --write **/*.ts 应该可以解决问题)。这应该最大限度地减少您在源代码和目标代码之间看到的差异。

关于javascript - 如何在从 typescript 生成的javascript中维护空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57466429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com