Static block is not being transpiled

445 Views Asked by At

I'm using Angular 14.x and in the tsconfig file:

{
"compileOnSave": false,
"compilerOptions": {
    "baseUrl": "./",
    "outDir": "./xy",
    "sourceMap": true,
    "declaration": false,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2022",
    "module": "es2022",
    "resolveJsonModule": true
}

}

And a browserslist config in the package.json:

"browserslist": [
    "ios_saf >= 15.5",
    "Safari >= 15.6.1",
    "Firefox >= 102",
    "last 2 Edge versions",
    "last 2 Chrome versions"
]

According to this list https://caniuse.com/mdn-javascript_classes_static_initialization_blocks Safari doesn't support static blocks. So it should be transpiled by the Angular TSC, shouldn't it? But it's not getting transpiled.

I thought the TSC looks at the configured target (es2022) and takes in account what is defined in the browserslist and then transpiles the code and where need it transpiles it to something the configured browsers understand?

The code that should be transpiled:

export class XYZ {
  private static y: any;
  static {
    try {
        this.y = this.hello();
    } catch {
        this.y = 'unknown';
    }
  }

 static hello() {
    return 'hello';
}}
0

There are 0 best solutions below