Skip to content

(import) - JavaScript

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

  1. Identifier: shorthand for (str)
  2. String: shorthand for (str)
  3. Pattern: shorthand for (str)
  4. (str)
  5. (:into)
  6. (:nearest)
  7. (:and)
  8. (:or)
  9. (:not)
  10. (:text)
  11. (:kind)
  12. (:replace)
  13. (:replace-in)
  14. (:capture)

specifier

  1. Identifier: shorthand for (id)
  2. String: shorthand for (str)
  3. Pattern: shorthand for (id)
  4. "*"
  5. "default"
  6. (id)
  7. (:into)
  8. (:nearest)
  9. (:and)
  10. (:or)
  11. (:not)
  12. (:text)
  13. (:kind)
  14. (:replace)
  15. (:replace-in)
  16. (:capture)

Copyright © 2022-present Semantic Works, Inc.