Skip to content

(tpl*)

template literals matched by a pseudo-evaluated value that includes interpolations

clojure
(tpl* val tag?)

Where:

  1. val: the text pattern to find when template parts are joined *
  2. tag: the tag function (the gql in gql`...`) *

Matching:

  1. template literals, e.g. `hello ${name}`
  2. tagged template literals, e.g. gql`query { ... }`

Behavior

  • Pseudo-evaluates templates by concatenating literal fragments and interpolation identifiers/literals in order.
  • Expressions that are not identifiers or literals contribute no text to the evaluated value.

Examples

Locate GraphQL queries that request PII fields.

clojure
(tpl* /email|ssn/i gql)

Selects in lines { 1 } but not in { 2, 3 }:

typescript
const q1 = gql`query User { id email }`
const q2 = gql`query User { id name }`
const q3 = sql`SELECT email FROM users`

Find URLs built via template strings before migrating to a URL builder.

clojure
(tpl* /https?:/)

Selects in lines { 1, 2 } but not in { 3 }:

typescript
const url1 = `https://api.example.com/users/${id}`
const url2 = `http://localhost:${port}/health`
const url3 = `/users/${id}`

Remove !important from styled-components templates.

clojure
(tpl* /!important/ (mem div styled))

Selects in lines { 0 } but not in { 0, 0 }:

typescript
const Button = styled.div`
  color: red !important;
`
const Badge = styled.span`
  color: blue !important;
`
const Link = styled.div`
  color: red;
`

Arguments

val

• Identifier • String • Pattern

Does NOT support: CompositionFree-form SelectionRefinementReplacement

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)

Copyright © 2022-present Semantic Works, Inc.