Skip to content

Commit

Permalink
fix(scope-manager): don't create a variable for global augmentation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjuan committed Oct 6, 2020
1 parent c71f423 commit 6bc9325
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/eslint-plugin/tests/rules/no-use-before-define.test.ts
Expand Up @@ -347,6 +347,17 @@ const React = require('react');
`
type T = (value: unknown) => value is Id;
`,
`
global.foo = true;
declare global {
namespace NodeJS {
interface Global {
foo?: boolean;
}
}
}
`,
],
invalid: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/scope-manager/src/referencer/Referencer.ts
Expand Up @@ -765,7 +765,7 @@ class Referencer extends Visitor {
}

protected TSModuleDeclaration(node: TSESTree.TSModuleDeclaration): void {
if (node.id.type === AST_NODE_TYPES.Identifier) {
if (node.id.type === AST_NODE_TYPES.Identifier && !node.global) {
this.currentScope().defineIdentifier(
node.id,
new TSModuleNameDefinition(node.id, node),
Expand Down
@@ -0,0 +1,3 @@
//// @sourceType = module

declare global {}
@@ -0,0 +1,42 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ts-module global-augmentation 1`] = `
ScopeManager {
variables: Array [
ImplicitGlobalConstTypeVariable,
],
scopes: Array [
GlobalScope$1 {
block: Program$1,
isStrict: false,
references: Array [],
set: Map {
"const" => ImplicitGlobalConstTypeVariable,
},
type: "global",
upper: null,
variables: Array [
ImplicitGlobalConstTypeVariable,
],
},
ModuleScope$2 {
block: Program$1,
isStrict: true,
references: Array [],
set: Map {},
type: "module",
upper: GlobalScope$1,
variables: Array [],
},
TSModuleScope$3 {
block: TSModuleDeclaration$2,
isStrict: true,
references: Array [],
set: Map {},
type: "tsModule",
upper: ModuleScope$2,
variables: Array [],
},
],
}
`;

0 comments on commit 6bc9325

Please sign in to comment.