Skip to content

(comp)

computed property access and subscript expressions

clojure
(comp val?)

Where:

  1. val: the expression inside the brackets *

Matching:

  1. subscript expressions, e.g. obj[key]
  2. computed property names in objects, e.g. { [key]: value }

Behavior

  • Matches computed/dynamic property access using square brackets.
  • Works in both member access (obj[expr]) and object literal property names ({ [expr]: value }).

Examples

Find dynamic property access using environment variables before refactoring.

clojure
(mem (comp (mem _ (id process))))

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

typescript
const apiUrl = config[process.env.NODE_ENV]
const setting = options[process.env.FEATURE_FLAG]
const value = data[userInput]

Locate computed property names in objects for ES5 compatibility check.

clojure
(obj (prop (comp)))

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

typescript
const obj1 = { [key]: value }
const obj2 = { name: value }
const obj3 = { [Symbol.iterator]: function*() {} }

Find array access with string literals to convert to dot notation.

clojure
(mem (comp (str)))

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

typescript
const name = user['name']
const age = user['age']
const value = data[dynamicKey]

Arguments

val

• Identifier: shorthand for (id)
• String: shorthand for (str)
(arr) (bin) (bool) (call) (comp) (fun) (id) (id+) (jsx) (mem) (null) (num) (obj) (of) (regex) (regex+) (str) (str*) (str+) (tpl) (tpl*) (:ref) (:into) (:and) (:or) (:not) (:text) (:kind) (:replace) (:capture)

Copyright © 2022-present Semantic Works, Inc.