Skip to content

(prop) - JavaScript ​

properties in objects and destructuring patterns

clojure
(prop key? val?)

Where:

  1. key: property key (the a in a: 1 or { a }) *
  2. val: property value *

Matching:

  1. key-value pairs, e.g. a: 1
  2. shorthand properties, e.g. a
  3. spread and rest, e.g. ...rest
  4. computed properties, e.g. [key]: value
  5. default values in destructuring, e.g. a = 1

Behavior ​

  • Matches properties in object literals, object patterns, and TypeScript object types.
  • Handles both regular properties and destructuring patterns in function parameters.
  • For spread elements like { ...rest }, use the val argument to match the identifier being spread. Matching the spread operator itself (...) is not currently supported.

Examples ​

Find objects using deprecated configuration keys before renaming them.

clojure
(obj (prop apiKey))

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

typescript
const config = { apiKey: 'secret' }
const settings = { token: 'secret' }
const partial = { apiKey: 'key', token: 'val' }

Locate environment-specific config objects that hardcode production URLs.

clojure
(obj (prop url (str /prod|production/)))

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

typescript
const config = { url: 'https://api.production.com' }
const dev = { url: 'https://api.dev.com' }
const staging = { url: 'https://api.staging.com' }

Find React components using inline style objects to migrate to CSS modules.

clojure
(obj (prop style (obj)))

Selects in lines { 1, 3 }:

typescript
<div style={{ color: 'red' }} />
<div className="red" />
<Component style={{ margin: 0 }} />

Identify destructuring patterns with defaults that may hide undefined values.

clojure
(fun _ (arg _ (obj (prop _ (num)))))

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

typescript
function load({ timeout = 3000 }) {}
function fetch({ retries = 5 }) {}
function init({ port }) {}

Arguments ​

key ​

  1. Identifier: shorthand for (id)
  2. String: shorthand for (str)
  3. Number: shorthand for (num)
  4. (id)
  5. (str)
  6. (num)
  7. (comp)
  8. (:into)
  9. (:nearest)
  10. (:and)
  11. (:or)
  12. (:not)
  13. (:text)
  14. (:kind)
  15. (:replace)
  16. (:replace-in)
  17. (:capture)

val ​

Copyright © 2022-present Semantic Works, Inc.