scrhartley opened a new pull request, #106:
URL: https://github.com/apache/freemarker/pull/106

   The current `switch` directive is not recommended due to its fall-through 
behavior being regarded as error-prone. To solve this problem, we introduce a 
new `on` directive as an alternative to `case`, which doesn't support 
fall-through. This new directive allows specifying multiple comma-separated 
conditions in order to address the primary motivator for using fall-through 
with `case`.
   
   ## Example
   
   Using `case`:
   ```freemarker
   <#switch animal.size>
     <#case "tiny">
     <#case "small">
        This will be processed if it is small
        <#break>
     <#case "medium">
        This will be processed if it is medium
        <#break>
     <#default>
        This will be processed if it is neither
   </#switch>
   ```
   Using `on`:
   ```freemarker
   <#switch animal.size>
     <#on "tiny", "small">
        This will be processed if it is small
     <#on "medium">
        This will be processed if it is medium
     <#default>
        This will be processed if it is neither
   </#switch>
   ```
   
   ## Details
   
   * Mixing `case` and `on` directives is disallowed and will fail.
   * If a `switch` contains an `on`, then using `break` or `continue` is not 
supported (applying to both `on` and `default`). In this situation, `break` and 
`continue` will follow the behavior of the containing scope, e.g. of a 
containing `list`. This does mean that if someone accidentally uses `break` 
with `on`, they could potentially become confused.
   
   ### Additional Notes
   
   * When `on` is not used, the legacy behavior for `case`/`default` is that 
`continue` will be treated as `break`. If we wish to change this, then that 
work can be done separately.
   * If using `default`, the parser also allows it to appear before or between 
`case` directives, but when using `on` then `default` is only allowed after.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to