|
5 | 5 | "use strict"
|
6 | 6 |
|
7 | 7 | let typeMatchesSpecifier =
|
8 |
| - /** @type {import('ts-declaration-location').default | undefined} */ |
| 8 | + /** @type {import('ts-declaration-location').default | undefined | null} */ |
9 | 9 | (undefined)
|
10 | 10 |
|
11 |
| -try { |
12 |
| - typeMatchesSpecifier = |
13 |
| - /** @type {import('ts-declaration-location').default} */ ( |
14 |
| - /** @type {unknown} */ (require("ts-declaration-location")) |
15 |
| - ) |
16 |
| - |
17 |
| - // eslint-disable-next-line no-empty -- Deliberately left empty. |
18 |
| -} catch {} |
19 | 11 | const getTypeOfNode = require("../util/get-type-of-node")
|
20 | 12 | const getParserServices = require("../util/get-parser-services")
|
21 | 13 | const getFullTypeName = require("../util/get-full-type-name")
|
@@ -124,6 +116,31 @@ module.exports = {
|
124 | 116 | const selector = options.allowAtRootLevel
|
125 | 117 | ? selectors.map(selector => `:function ${selector}`)
|
126 | 118 | : selectors
|
| 119 | + |
| 120 | + const hasAdvancedIgnores = ignores.some( |
| 121 | + ignore => typeof ignore !== "string" |
| 122 | + ) |
| 123 | + |
| 124 | + // Only require `ts-declaration-location` if needed and not already required. |
| 125 | + if (hasAdvancedIgnores) { |
| 126 | + if (typeMatchesSpecifier === undefined) { |
| 127 | + try { |
| 128 | + typeMatchesSpecifier = |
| 129 | + /** @type {import('ts-declaration-location').default} */ ( |
| 130 | + /** @type {unknown} */ ( |
| 131 | + require("ts-declaration-location") |
| 132 | + ) |
| 133 | + ) |
| 134 | + } catch { |
| 135 | + typeMatchesSpecifier === null |
| 136 | + } |
| 137 | + } else { |
| 138 | + throw new Error( |
| 139 | + 'ts-declaration-location not available. Rule "n/no-sync" is configured to use "ignores" option with a non-string value. This requires ts-declaration-location to be available.' |
| 140 | + ) |
| 141 | + } |
| 142 | + } |
| 143 | + |
127 | 144 | return {
|
128 | 145 | /**
|
129 | 146 | * @param {import('estree').Identifier & {parent: import('estree').Node}} node
|
@@ -160,12 +177,6 @@ module.exports = {
|
160 | 177 | )
|
161 | 178 | }
|
162 | 179 |
|
163 |
| - if (typeMatchesSpecifier === undefined) { |
164 |
| - throw new Error( |
165 |
| - 'ts-declaration-location not available. Rule "n/no-sync" is configured to use "ignores" option with a non-string value. This requires ts-declaration-location to be available.' |
166 |
| - ) |
167 |
| - } |
168 |
| - |
169 | 180 | type =
|
170 | 181 | type === undefined
|
171 | 182 | ? getTypeOfNode(node, parserServices)
|
|
0 commit comments