(tpl)
template literals (`...`) and tagged template literals like html... or sql...
(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.
(tpl /select|insert|update|delete/i _ sql)Selects in lines { 1, 2 } but not in { 3 }:
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.
(tpl /\/users\// (id userId))Selects in lines { 1 } but not in { 2, 3 }:
const url = `/users/${userId}`
const url2 = `/users/${otherId}`
const url3 = `/users/42`Clean up CSS-in-JS templates that still use !important.
(tpl /!important/ _ css)Selects in lines { 0 } but not in { 0, 0 }:
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) • (:and) • (:or) • (:not) • (:text) • (:kind) • (:replace) • (:capture)
expr
• (arr) • (bin) • (bool) • (call) • (comp) • (fun) • (id) • (id+) • (jsx) • (mem) • (null) • (num) • (obj) • (of) • (regex) • (regex+) • (str) • (str*) • (str+) • (tpl) • (tpl*) • (:into) • (:and) • (:or) • (:not) • (:text) • (:kind) • (:replace) • (:capture)
tag
• Identifier: shorthand for (id)
• Pattern: shorthand for (id)
• (:kind) • (:ref) • (:text) • (arr) • (attr) • (bool) • (call) • (child) • (comp) • (export) • (fun) • (id) • (id+) • (import) • (jsx) • (mem) • (null) • (num) • (obj) • (of) • (prop) • (regex) • (regex+) • (str) • (str*) • (str+) • (tpl) • (tpl*) • (var) • (:into) • (:and) • (:or) • (:not) • (:replace) • (:capture)