Skip to content

Add support for angular @switch exhaustive type check case "@default never;" #18966

@GenFlogi

Description

@GenFlogi

Prettier v3.8.1
Playground link

--parser angular

Input:

<!DOCTYPE html>
<HTML CLASS="no-js mY-ClAsS">
  <HEAD>
    <META CHARSET="utf-8">
    <TITLE>My tITlE</TITLE>
    <META NAME="description" content="My CoNtEnT">
  </HEAD>
  <body>
    @switch(state) {
      @case('finished') {
        <div>Finished</div>
      }
      @case('open') {
        <div>Open</div>
      }
      @case('errored') {
        <div>Error - Example</div>
      }
      @default never; <!-- https://angular.dev/api/core/@switch#exhaustive-type-checking -->
    }
    <P>Hello world!<BR> This is HTML5 Boilerplate.</P>
    <SCRIPT>
      window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
      ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
    </SCRIPT>
    <SCRIPT src="https://www.google-analytics.com/analytics.js" ASYNC DEFER></SCRIPT>
  </body>
</HTML>

Output:

SyntaxError: Incomplete block "default never". If you meant to write the @ character, you should use the "&#64;" HTML entity instead. (19:7)
  17 |         <div>Error - Example</div>
  18 |       }
> 19 |       @default never; <!-- https://angular.dev/api/core/@switch#exhaustive-type-checking -->
     |       ^^^^^^^^^^^^^^
  20 |     }
  21 |     <P>Hello world!<BR> This is HTML5 Boilerplate.</P>
  22 |     <SCRIPT>

Expected output:

<!DOCTYPE html>
<HTML CLASS="no-js mY-ClAsS">
  <HEAD>
    <META CHARSET="utf-8" />
    <TITLE>My tITlE</TITLE>
    <META NAME="description" content="My CoNtEnT" />
  </HEAD>
  <body>
    @switch (state) {
      @case ("finished") {
        <div>Finished</div>
      }
      @case ("open") {
        <div>Open</div>
      }
      @case ("errored") {
        <div>Error - Example</div>
      }
      @default never;
      <!-- https://angular.dev/api/core/@switch#exhaustive-type-checking -->
    }
    <P>Hello world!<BR /> This is HTML5 Boilerplate.</P>
    <SCRIPT>
      window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new
      Date; ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
    </SCRIPT>
    <SCRIPT
      src="https://www.google-analytics.com/analytics.js"
      ASYNC
      DEFER
    ></SCRIPT>
  </body>
</HTML>

Why?
https://angular.dev/api/core/@switch#exhaustive-type-checking

Metadata

Metadata

Assignees

Labels

lang:angularIssues affecting Angular template (not general JS/TS issues used for Angular)

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions