Skip to content

target: es2020 doesn't work with ?. null conditional operator #18204

@vivainio

Description

@vivainio

🐞 bug report

Affected Package

@angular/cli

Is this a regression?

No

Description

?. operator doesn't work if you set target: "ES2020" in tsconfig.base.json

🔬 Minimal Reproduction

Check out https://github.com/vivainio/repro-angular-es2020-fail

run "ng build" and observe the compiler error.

If you change it back to "target": "es2016", ng build succeeds.

🔥 Exception or Error


ERROR in ./src/app/app.component.ts 38:20
Module parse failed: Unexpected token (38:20)
File was processed with these loaders:
 * ./node_modules/@ngtools/webpack/src/index.js
You may need an additional loader to handle the result of these loaders.
|         this.title = 'test2020';
|         const a = undefined;
>         const b = a?.name;
|     }
| }

🌍 Your Environment

Angular Version:



Angular CLI: 10.0.1
Node: 12.18.1
OS: win32 x64

Angular: 10.0.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.1
@angular-devkit/build-angular     0.1000.1
@angular-devkit/build-optimizer   0.1000.1
@angular-devkit/build-webpack     0.1000.1
@angular-devkit/core              10.0.1
@angular-devkit/schematics        10.0.1
@angular/cli                      10.0.1
@ngtools/webpack                  10.0.1
@schematics/angular               10.0.1
@schematics/update                0.1000.1
rxjs                              6.5.5
typescript                        3.9.6
webpack                           4.43.0

Anything else relevant?

I'm aware that native async/await is not supported by Zone.js, but for the purposes of this discussions I don't care about this gap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions