(of) - JavaScript
constructor calls using new
clojure
(of callee args?)Where:
- callee: constructor being instantiated (the
Fooinnew Foo()) * - args: constructor arguments (use
(arg ...)to match by position or value) *
Matching:
- constructor calls, e.g.
new Foo() - constructor calls without arguments, e.g.
new Foo - member constructors, e.g.
new Api.Client()
Behavior
- Only matches
newexpressions, not plain calls likeFoo().
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()