(comp) - JavaScript
computed property access and subscript expressions
clojure
(comp val?)Where:
- val: the expression inside the brackets *
Matching:
- subscript expressions, e.g.
obj[key] - 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]