Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast_visit/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast_visit/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 14 additions & 1 deletion crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_syntax/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions tasks/coverage/snapshots/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Loading