简体   繁体   English

Angular Compiler 是否优化了字符串表达式?

[英]Does the Angular Compiler optimize string expressions?

I have the following code snippet:我有以下代码片段:

"foo".length > 0 ? true : false;

Does the Angular compiler replace it just with true ? Angular 编译器是否仅将其替换为true

tsc does not do; tsc不做; I tried it out.我试过了。

That's the job of the minifier, noy the compiler.这是压缩器的工作,不是编译器。

For example Esbuild (a bundler used by angular) will do that for you:例如 Esbuild(angular 使用的打包器)会为你做这件事:

echo '[1].length > 0 ? true : false' | esbuild --loader=ts --minify
> [1].length>0;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM