I want the javascript code generated from typescript to have the same white spacing. Long story short, we're migrating from js to ts and maintaining whitespace would allow us to compare generated code against the unmigrated version of the code.
My input ts looks like:
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)
);
The output looks this ugly super long line:
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));
My expected output would be:
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)
);
My tsconfig looks like:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./dist",
},
"include": ["./src/**/*"],
"exclude": [
"node_modules",
"./src/real/*"
]
}
Transpiled TypeScript code could be significantly different depending on the tsconfig.json configuration, so preserving whitespace isn't really an option in the compiler.
One thing you could do is to first run your source through a formatter like Prettier, and also run it again post-compile (prettier --write **/*.ts should do the trick). That should minimize the diffs you see between the source and target code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With