Skip to content

(of)

constructor calls using new

clojure
(of callee args?)

Where:

  1. callee: constructor being instantiated (the Foo in new Foo()) *
  2. args: constructor arguments (use (arg ...) to match by position or value) *

Matching:

  1. constructor calls, e.g. new Foo()
  2. constructor calls without arguments, e.g. new Foo
  3. member constructors, e.g. new Api.Client()

Behavior

  • Only matches new expressions, not plain calls like Foo().

Examples

Find error constructions with legacy messages to standardize.

clojure
(of Error (arg 1 (str /deprecated/i)))

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

typescript
throw new Error("Deprecated API")
throw new Error(err)
throw Error("Deprecated API")

Locate URL constructions that still hardcode http.

clojure
(of URL (arg 1 (str /http:\/\//)))

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

typescript
const url1 = new URL("http://example.com")
const url2 = new URL("https://example.com")
const url3 = new URL("/path", base)

Audit usages of a specific client constructor before renaming.

clojure
(of (mem Client Api))

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

typescript
const client1 = new Api.Client()
const client2 = new Api.Server()
const client3 = new Client()

Arguments

callee

• 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)

args

(arg)
(:into) (:and) (:or) (:not) (:text) (:kind) (:replace) (:capture)

Copyright © 2022-present Semantic Works, Inc.