Skip to content

FEATURE: Simplify template literals #33

@grebaldi

Description

@grebaldi

As of right now, template literals are modeled after ECMAScript, e.g.:

export component Foo {
  bar: string

  return `
  Hello ${bar}
  `
}

Imho this causes two problems:

  1. The ${ sequence is a considerable complication for the parser (or better: The tokenizer)
  2. Template literals of this kind cause lots of unwanted space, that cannot be trimed away by the engine itself

I therefore suggest to change the template literal syntax to this:

export component Foo {
  bar: string

  return """
    Hello {bar}
    """
}

Rules are:

  1. Leading and trailing spaces are trimmed
  2. Indentation as per the closing delimiter is removed from every line (similar to PHP Heredoc syntax: https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc)

This will still allow for possible future tagged template literals, like:

export component Foo {
  bar: string

  return markdown"""
    # A markdown document
    
    ## Some headline: {bar}
    Lorem ipsum...
    """
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions