Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fix(scope-manager): don't create references for intrinsic JSX elements (
- Loading branch information
Showing
with
208 additions
and 10 deletions.
- +21 −0 packages/eslint-plugin/tests/eslint-rules/no-undef.test.ts
- +14 −1 packages/scope-manager/src/referencer/Referencer.ts
- +0 −8 packages/scope-manager/tests/fixtures/jsx/children.tsx.shot
- +2 −0 packages/scope-manager/tests/fixtures/jsx/component-intrinsic-name.tsx
- +58 −0 packages/scope-manager/tests/fixtures/jsx/component-intrinsic-name.tsx.shot
- 0 packages/scope-manager/tests/fixtures/jsx/{component-namespaced.tsx → component-namespaced1.tsx}
- +1 −1 ...scope-manager/tests/fixtures/jsx/{component-namespaced.tsx.shot → component-namespaced1.tsx.shot}
- +6 −0 packages/scope-manager/tests/fixtures/jsx/component-namespaced2.tsx
- +106 −0 packages/scope-manager/tests/fixtures/jsx/component-namespaced2.tsx.shot
@@ -0,0 +1,2 @@ | ||
function div() {} // should not be referenced | ||
<div />; |
@@ -0,0 +1,58 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`jsx component-intrinsic-name 1`] = ` | ||
ScopeManager { | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2 { | ||
defs: Array [ | ||
FunctionNameDefinition$1 { | ||
name: Identifier<"div">, | ||
node: FunctionDeclaration$1, | ||
}, | ||
], | ||
name: "div", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: false, | ||
}, | ||
Variable$3 { | ||
defs: Array [], | ||
name: "arguments", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: true, | ||
}, | ||
], | ||
scopes: Array [ | ||
GlobalScope$1 { | ||
block: Program$2, | ||
isStrict: false, | ||
references: Array [], | ||
set: Map { | ||
"const" => ImplicitGlobalConstTypeVariable, | ||
"div" => Variable$2, | ||
}, | ||
type: "global", | ||
upper: null, | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2, | ||
], | ||
}, | ||
FunctionScope$2 { | ||
block: FunctionDeclaration$1, | ||
isStrict: false, | ||
references: Array [], | ||
set: Map { | ||
"arguments" => Variable$3, | ||
}, | ||
type: "function", | ||
upper: GlobalScope$1, | ||
variables: Array [ | ||
Variable$3, | ||
], | ||
}, | ||
], | ||
} | ||
`; |
File renamed without changes.
@@ -0,0 +1,6 @@ | ||
const x = { | ||
Foo() {}, | ||
}; | ||
const Foo = 1; // should be unreferenced | ||
|
||
<x.Foo />; // lower cased namespaces should still create a reference |
@@ -0,0 +1,106 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`jsx component-namespaced2 1`] = ` | ||
ScopeManager { | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2 { | ||
defs: Array [ | ||
VariableDefinition$1 { | ||
name: Identifier<"x">, | ||
node: VariableDeclarator$1, | ||
}, | ||
], | ||
name: "x", | ||
references: Array [ | ||
Reference$1 { | ||
identifier: Identifier<"x">, | ||
init: true, | ||
isRead: false, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: true, | ||
resolved: Variable$2, | ||
writeExpr: ObjectExpression$2, | ||
}, | ||
Reference$3 { | ||
identifier: JSXIdentifier$3, | ||
isRead: true, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: false, | ||
resolved: Variable$2, | ||
}, | ||
], | ||
isValueVariable: true, | ||
isTypeVariable: false, | ||
}, | ||
Variable$3 { | ||
defs: Array [], | ||
name: "arguments", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: true, | ||
}, | ||
Variable$4 { | ||
defs: Array [ | ||
VariableDefinition$2 { | ||
name: Identifier<"Foo">, | ||
node: VariableDeclarator$4, | ||
}, | ||
], | ||
name: "Foo", | ||
references: Array [ | ||
Reference$2 { | ||
identifier: Identifier<"Foo">, | ||
init: true, | ||
isRead: false, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: true, | ||
resolved: Variable$4, | ||
writeExpr: Literal$5, | ||
}, | ||
], | ||
isValueVariable: true, | ||
isTypeVariable: false, | ||
}, | ||
], | ||
scopes: Array [ | ||
GlobalScope$1 { | ||
block: Program$6, | ||
isStrict: false, | ||
references: Array [ | ||
Reference$1, | ||
Reference$2, | ||
Reference$3, | ||
], | ||
set: Map { | ||
"const" => ImplicitGlobalConstTypeVariable, | ||
"x" => Variable$2, | ||
"Foo" => Variable$4, | ||
}, | ||
type: "global", | ||
upper: null, | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2, | ||
Variable$4, | ||
], | ||
}, | ||
FunctionScope$2 { | ||
block: FunctionExpression$7, | ||
isStrict: false, | ||
references: Array [], | ||
set: Map { | ||
"arguments" => Variable$3, | ||
}, | ||
type: "function", | ||
upper: GlobalScope$1, | ||
variables: Array [ | ||
Variable$3, | ||
], | ||
}, | ||
], | ||
} | ||
`; |