我正在使用 Angular 14.x,在 tsconfig 文件中:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./xy",
"sourceMap": true,
"declaration": false,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2022",
"module": "es2022",
"resolveJsonModule": true
}
}
package.json 中的浏览器列表配置:
"browserslist": [
"ios_saf >= 15.5",
"Safari >= 15.6.1",
"Firefox >= 102",
"last 2 Edge versions",
"last 2 Chrome versions"
]
根据此列表https://caniuse.com/mdn-javascript_classes_static_initialization_blocks Safari 不支持静态块。所以它应该由 Angular TSC 转译,不是吗?但它没有被转译。
我认为 TSC 查看配置的目标 (es2022) 并考虑浏览器列表中定义的内容,然后转译代码以及在哪里需要将其转译为配置的浏览器可以理解的内容?
需要转译的代码:
export class XYZ {
private static y: any;
static {
try {
this.y = this.hello();
} catch {
this.y = 'unknown';
}
}
static hello() {
return 'hello';
}}