Skip to content

Empty @switch block can't compile #53773

Closed

Description

@vlzware

Which @angular/* package(s) are the source of the bug?

compiler-cli

Is this a regression?

Yes

Description

In the code I am working with, we have a section which looked like this:

<ng-container [ngSwitch]="type">
  <!-- commented out code -->
</ng-container>

This used to compile.

If I replace this with the new syntax like this:

@switch (type) {
  <!-- commented out code -->
}

it fails to compile with the error shown below.
The switch block contains commented out code for legacy reasons.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

√ Browser application bundle generation complete.
<e> [webpack-dev-middleware] TypeError: Cannot read properties of undefined (reading 'index')
<e>     at TemplateDefinitionBuilder.visitSwitchBlock (file:///C:/<myproject>/node_modules/@angular/compiler/fesm2022/compiler.mjs:28574:44)
<e>     at SwitchBlock.visit (file:///C:/<myproject>/node_modules/@angular/compiler/fesm2022/compiler.mjs:3970:24)
<e>     at visitAll$1 (file:///C:/<myproject>/node_modules/@angular/compiler/fesm2022/compiler.mjs:4184:34)
<e>     at TemplateDefinitionBuilder.visitElement (file:///C:/<myproject>/node_modules/@angular/compiler/fesm2022/compiler.mjs:28324:9)
<e>     at Element$1.visit (file:///C:/<myproject>/node_modules/@angular/compiler/fesm2022/compiler.mjs:3836:24)
<e>     at visitAll$1 (file:///C:/<myproject>/node_modules/@angular/compiler/fesm2022/compiler.mjs:4184:34)
<e>     at TemplateDefinitionBuilder.buildTemplateFunction (file:///C:/<myproject>/node_modules/@angular/compiler/fesm2022/compiler.mjs:27798:9)
<e>     at compileComponentFromMetadata (file:///C:/<myproject>/node_modules/@angular/compiler/fesm2022/compiler.mjs:30021:60)
<e>     at ComponentDecoratorHandler.compileFull (file:///C:/<myproject>/node_modules/@angular/compiler-cli/bundles/chunk-B5URQIVL.js:7010:17)
<e>     at TraitCompiler.compile (file:///C:/<myproject>/node_modules/@angular/compiler-cli/bundles/chunk-B5URQIVL.js:1688:38)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.0.8
Node: 18.18.2
Package Manager: npm 10.2.5
OS: win32 x64

Angular: 17.0.8
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.8
@angular-devkit/build-angular   17.0.8
@angular-devkit/core            17.0.8
@angular-devkit/schematics      17.0.8
@angular/cdk                    17.0.4
@angular/material               17.0.4
@schematics/angular             17.0.8
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.2

Anything else?

No response

Activity

  1. self-assigned this
    on Jan 3, 2024
  2. added
    area: compiler
    P3
    core: control flow
    on Jan 3, 2024
  3. added this to the Backlog milestone on Jan 3, 2024
  4. added a commit that references this issue on Jan 3, 2024
    3f13bf5
  5. added a commit that references this issue on Jan 3, 2024
    6a41961
  6. added a commit that references this issue on Jan 23, 2024
    9d8f106
  7. added a commit that references this issue on Jan 26, 2024
    687deef
  8. added a commit that references this issue on Jan 26, 2024
    0101b9c
  9. angular-automatic-lock-bot commented on Feb 3, 2024

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  10. locked and limited conversation to collaborators on Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area: compilercore: control flowstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions