(tpl) - JavaScript
template literals (`...`) and tagged template literals like html... or sql...
clojure
(tpl quasis? expr? tag?)Where:
- quasis: the literal string fragments (the
helloand!in`hello ${name}!`) * - expr: the interpolation expressions (the
userIdin`${userId}`) * - tag: the tag function (the
htmlinhtml`...`) *
Matching:
- template literals, e.g.
`hello ${name}` - tagged template literals, e.g.
html`<div>${content}</div>`
Behavior
- Empty templates like
are matched.
Examples
Audit SQL tagged templates before moving to parameterized queries.
clojure
(tpl /select|insert|update|delete/i _ sql)Selects in lines { 1, 2 } but not in { 3 }:
typescript
const q1 = sql`SELECT * FROM users WHERE id = ${userId}`
const q2 = sql`UPDATE users SET active = 1`
const q3 = `SELECT * FROM users`Find URLs built with userId interpolation to migrate to a URL builder.
clojure
(tpl /\/users\// (id userId))Selects in lines { 1 } but not in { 2, 3 }:
typescript
const url = `/users/${userId}`
const url2 = `/users/${otherId}`
const url3 = `/users/42`Clean up CSS-in-JS templates that still use !important.
clojure
(tpl /!important/ _ css)Selects in lines { 0 } but not in { 0, 0 }:
typescript
const button = css`
color: red !important;
`
const card = css`
color: blue;
`
const other = styled.div`
color: red !important;
`Arguments
quasis
- Identifier: shorthand for (str)
- String: shorthand for (str)
- Pattern: shorthand for (str)
- (str)
- (:into)
- (:nearest)
- (:and)
- (:or)
- (:not)
- (:text)
- (:kind)
- (:replace)
- (:replace-in)
- (:capture)