@@ -9,39 +9,8 @@ const Reference = require("eslint-scope/lib/reference");
9
9
const OriginalReferencer = require ( "eslint-scope/lib/referencer" ) ;
10
10
const Scope = require ( "eslint-scope/lib/scope" ) . Scope ;
11
11
const fallback = require ( "eslint-visitor-keys" ) . getKeys ;
12
- const lodash = require ( "lodash" ) ;
13
12
const childVisitorKeys = require ( "./visitor-keys" ) ;
14
13
15
- /**
16
- * Get `.range[0]` of a given object.
17
- * @param {{range: number[]} } x The object to get.
18
- * @returns {number } The gotten value.
19
- */
20
- function byRange0 ( x ) {
21
- return x . range [ 0 ] ;
22
- }
23
-
24
- /**
25
- * Check the TSModuleDeclaration node is `declare global {}` or not.
26
- * @param {TSModuleDeclaration } node The TSModuleDeclaration node to check.
27
- * @param {Token[] } tokens The token list.
28
- * @returns {boolean } `true` if the node is `declare global {}`.
29
- */
30
- function isGlobalAugmentation ( node , tokens ) {
31
- const i = lodash . sortedIndexBy ( tokens , node , byRange0 ) ;
32
- const token1 = tokens [ i ] ;
33
- const token2 = tokens [ i + 1 ] ;
34
-
35
- return Boolean (
36
- token1 &&
37
- token2 &&
38
- ( token1 . type === "Keyword" || token1 . type === "Identifier" ) &&
39
- token1 . value === "declare" &&
40
- ( token2 . type === "Keyword" || token2 . type === "Identifier" ) &&
41
- token2 . value === "global"
42
- ) ;
43
- }
44
-
45
14
/**
46
15
* Define the override function of `Scope#__define` for global augmentation.
47
16
* @param {Function } define The original Scope#__define method.
@@ -570,12 +539,10 @@ class Referencer extends OriginalReferencer {
570
539
* @returns {void }
571
540
*/
572
541
TSModuleDeclaration ( node ) {
573
- const astRoot = this . scopeManager . globalScope . block ;
574
542
const scope = this . currentScope ( ) ;
575
543
const { id, body } = node ;
576
544
577
- // https://github.com/JamesHenry/typescript-estree/issues/27
578
- if ( isGlobalAugmentation ( node , astRoot . tokens ) ) {
545
+ if ( node . global ) {
579
546
this . visitGlobalAugmentation ( node ) ;
580
547
return ;
581
548
}
0 commit comments