@@ -9,39 +9,8 @@ const Reference = require("eslint-scope/lib/reference");
99const OriginalReferencer = require ( "eslint-scope/lib/referencer" ) ;
1010const Scope = require ( "eslint-scope/lib/scope" ) . Scope ;
1111const fallback = require ( "eslint-visitor-keys" ) . getKeys ;
12- const lodash = require ( "lodash" ) ;
1312const childVisitorKeys = require ( "./visitor-keys" ) ;
1413
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-
4514/**
4615 * Define the override function of `Scope#__define` for global augmentation.
4716 * @param {Function } define The original Scope#__define method.
@@ -570,12 +539,10 @@ class Referencer extends OriginalReferencer {
570539 * @returns {void }
571540 */
572541 TSModuleDeclaration ( node ) {
573- const astRoot = this . scopeManager . globalScope . block ;
574542 const scope = this . currentScope ( ) ;
575543 const { id, body } = node ;
576544
577- // https://github.com/JamesHenry/typescript-estree/issues/27
578- if ( isGlobalAugmentation ( node , astRoot . tokens ) ) {
545+ if ( node . global ) {
579546 this . visitGlobalAugmentation ( node ) ;
580547 return ;
581548 }
0 commit comments