Skip to content

Tagged template string considered an expression, not a function call #822

@yoshuawuyts

Description

@yoshuawuyts

Intro

Template strings are a way to interpolate variables with strings. It's nice, and often more readable than traditional string concatenation

Tagged template strings take this behavior a bit further, and allow functions to be called as if they were strings - but instead the functions receive multiple strings, and a trailing array of positional arguments that the have been used for interpolation. This allows operating on the string and adding all sorts of interesting behavior.

Example

var css = require('sheetify')

// this is a static expression
`
  .js-yellow { color: #f7df1e }
  .bg-js-yellow { background-color: #f7df1e }
`

// this is a function call, which in this case has side effects
css`
  .js-yellow { color: #f7df1e }
  .bg-js-yellow { background-color: #f7df1e }
`

Bug

It appears that standard@9 has introduced a regression where tagged template strings are now considered static expressions - even though they're functions. I think we should probably look into this.

❯ standard
standard: Use JavaScript Standard Style (http://standardjs.com)
  /Users/anon/src/yoshuawuyts/berlinjs/index.js:14:1: Expected an assignm
ent or function call and instead saw an expression.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions