mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(semantic): insert binding into correct scope for TSInferType (#9567)
This commit is contained in:
1 parent
be5e5dcc80
commit
bbb4f984f0
13 files changed
+33
-16
No files matched your search
@@ -282,7 +282,9 @@ pub use match_ts_type;
|
||||
/// ## Reference
|
||||
/// * [TypeScript Handbook - Conditional Types](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html)
|
||||
#[ast(visit)]
|
||||
#[scope]
|
||||
#[scope(
|
||||
flags = ScopeFlags::TsConditional,
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
|
||||
pub struct TSConditionalType<'a> {
|
||||
|
||||
@@ -3302,7 +3302,7 @@ pub mod walk {
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_span(&it.span);
|
||||
visitor.visit_ts_type(&it.check_type);
|
||||
visitor.enter_scope(ScopeFlags::empty(), &it.scope_id);
|
||||
visitor.enter_scope(ScopeFlags::TsConditional, &it.scope_id);
|
||||
visitor.visit_ts_type(&it.extends_type);
|
||||
visitor.visit_ts_type(&it.true_type);
|
||||
visitor.leave_scope();
|
||||
|
||||
@@ -3466,7 +3466,7 @@ pub mod walk_mut {
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_span(&mut it.span);
|
||||
visitor.visit_ts_type(&mut it.check_type);
|
||||
visitor.enter_scope(ScopeFlags::empty(), &it.scope_id);
|
||||
visitor.enter_scope(ScopeFlags::TsConditional, &it.scope_id);
|
||||
visitor.visit_ts_type(&mut it.extends_type);
|
||||
visitor.visit_ts_type(&mut it.true_type);
|
||||
visitor.leave_scope();
|
||||
|
||||
@@ -439,9 +439,22 @@ impl<'a> Binder<'a> for TSModuleDeclaration<'a> {
|
||||
|
||||
impl<'a> Binder<'a> for TSTypeParameter<'a> {
|
||||
fn bind(&self, builder: &mut SemanticBuilder) {
|
||||
let symbol_id = builder.declare_symbol(
|
||||
let scope_id = if matches!(
|
||||
builder.nodes.parent_kind(builder.current_node_id),
|
||||
Some(AstKind::TSInferType(_))
|
||||
) {
|
||||
builder
|
||||
.scope
|
||||
.ancestors(builder.current_scope_id)
|
||||
.find(|scope_id| builder.scope.get_flags(*scope_id).is_ts_conditional())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let symbol_id = builder.declare_symbol_on_scope(
|
||||
self.name.span,
|
||||
&self.name.name,
|
||||
scope_id.unwrap_or(builder.current_scope_id),
|
||||
SymbolFlags::TypeParameter,
|
||||
SymbolFlags::TypeParameterExcludes,
|
||||
);
|
||||
|
||||
Vendored
+2
-2
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"children": [
|
||||
{
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(StrictMode)",
|
||||
"flags": "ScopeFlags(StrictMode | TsConditional)",
|
||||
"id": 2,
|
||||
"node": "TSConditionalType",
|
||||
"symbols": [
|
||||
@@ -31,7 +31,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
},
|
||||
{
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(StrictMode)",
|
||||
"flags": "ScopeFlags(StrictMode | TsConditional)",
|
||||
"id": 3,
|
||||
"node": "TSConditionalType",
|
||||
"symbols": [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"children": [
|
||||
{
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(StrictMode)",
|
||||
"flags": "ScopeFlags(StrictMode | TsConditional)",
|
||||
"id": 2,
|
||||
"node": "TSConditionalType",
|
||||
"symbols": [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"children": [
|
||||
{
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(StrictMode)",
|
||||
"flags": "ScopeFlags(StrictMode | TsConditional)",
|
||||
"id": 2,
|
||||
"node": "TSConditionalType",
|
||||
"symbols": [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"children": [
|
||||
{
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(StrictMode)",
|
||||
"flags": "ScopeFlags(StrictMode | TsConditional)",
|
||||
"id": 2,
|
||||
"node": "TSConditionalType",
|
||||
"symbols": [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"children": [
|
||||
{
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(StrictMode)",
|
||||
"flags": "ScopeFlags(StrictMode | TsConditional)",
|
||||
"id": 2,
|
||||
"node": "TSConditionalType",
|
||||
"symbols": [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"children": [
|
||||
{
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(StrictMode)",
|
||||
"flags": "ScopeFlags(StrictMode | TsConditional)",
|
||||
"id": 2,
|
||||
"node": "TSConditionalType",
|
||||
"symbols": [
|
||||
|
||||
Vendored
+1
-1
@@ -16,7 +16,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"children": [
|
||||
{
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(StrictMode)",
|
||||
"flags": "ScopeFlags(StrictMode | TsConditional)",
|
||||
"id": 3,
|
||||
"node": "TSConditionalType",
|
||||
"symbols": [
|
||||
|
||||
@@ -77,6 +77,7 @@ bitflags! {
|
||||
const SetAccessor = 1 << 8;
|
||||
const CatchClause = 1 << 9;
|
||||
const DirectEval = 1 << 10; // <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#direct_and_indirect_eval>
|
||||
const TsConditional = 1 << 11;
|
||||
const Var = Self::Top.bits() | Self::Function.bits() | Self::ClassStaticBlock.bits() | Self::TsModuleBlock.bits();
|
||||
}
|
||||
}
|
||||
@@ -148,6 +149,10 @@ impl ScopeFlags {
|
||||
self.contains(Self::CatchClause)
|
||||
}
|
||||
|
||||
pub fn is_ts_conditional(&self) -> bool {
|
||||
self.contains(Self::TsConditional)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn contains_direct_eval(&self) -> bool {
|
||||
self.contains(Self::DirectEval)
|
||||
|
||||
@@ -13901,7 +13901,7 @@ semantic error: Scope children mismatch:
|
||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(6), ScopeId(7)]
|
||||
rebuilt : ScopeId(0): []
|
||||
Unresolved references mismatch:
|
||||
after transform: ["Pick", "U"]
|
||||
after transform: ["Pick"]
|
||||
rebuilt : []
|
||||
|
||||
tasks/coverage/typescript/tests/cases/compiler/inferFromGenericFunctionReturnTypes2.ts
|
||||
@@ -41049,9 +41049,6 @@ tasks/coverage/typescript/tests/cases/conformance/types/conditional/inferTypes2.
|
||||
semantic error: Scope children mismatch:
|
||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(3), ScopeId(4), ScopeId(6), ScopeId(9), ScopeId(10), ScopeId(12)]
|
||||
rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||
Unresolved references mismatch:
|
||||
after transform: ["P", "foo", "foo2"]
|
||||
rebuilt : ["foo", "foo2"]
|
||||
|
||||
tasks/coverage/typescript/tests/cases/conformance/types/conditional/inferTypesWithExtends1.ts
|
||||
semantic error: Bindings mismatch:
|
||||
|
||||
Reference in new issue
Block a user