Skip to content

(import)

ESM import statements, or imported identifiers when nested inside another selector

clojure
(import source? specifier?)

Where:

  1. source: module source string (the "mod" in import x from "mod") *
  2. specifier: imported specifier to match *

Matching:

  1. default imports, e.g. import x from "mod"
  2. named imports, e.g. import { a } from "mod"
  3. namespace imports, e.g. import * as ns from "mod"
  4. side-effect imports, e.g. import "./side-effect"

Behavior

  • As a top-level selector, (import ...) matches import statements; when nested, it resolves to the imported binding(s) for use in other selectors (e.g., (call (import "jquery" ajax))).
  • Specifier matching uses the exported name (not the local alias).

Examples

Find files that import lodash/fp before migrating to lodash-es.

clojure
(import /lodash\/fp/)

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

typescript
import map from "lodash/fp/map"
import { map } from "lodash"
import "./setup"

Locate uses of jQuery's ajax, regardless of local alias.

clojure
(call (import "jquery" ajax))

Selects in lines { 4, 5 } but not in { 6 }:

typescript
import { ajax } from "jquery"
import { ajax as myAjax } from "jquery"
import { getJSON } from "jquery"
ajax()
myAjax()
getJSON()

List the specifiers imported from a module for auditing.

clojure
(import "react-router" (:into))

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

typescript
import { Link, Route } from "react-router"
import { useParams } from "react-router"
import { Navigate } from "other"

Arguments

source

• Identifier: shorthand for (str)
• String: shorthand for (str)
• Pattern: shorthand for (str)
(str)
(:into) (:and) (:or) (:not) (:text) (:kind) (:replace) (:capture)

specifier

• Identifier: shorthand for (id)
• String: shorthand for (str)
• Pattern: shorthand for (id)
"*"
"default"
(id)
(:into) (:and) (:or) (:not) (:text) (:kind) (:replace) (:capture)

Copyright © 2022-present Semantic Works, Inc.