diff --git a/crates/oxc_ast/src/ast/ts.rs b/crates/oxc_ast/src/ast/ts.rs index ae26e5d3ad281..b7aaf26eadad1 100644 --- a/crates/oxc_ast/src/ast/ts.rs +++ b/crates/oxc_ast/src/ast/ts.rs @@ -230,7 +230,8 @@ pub use match_ts_type; /// /// #[visited_node] -#[derive(Debug, Hash)] +#[scope] +#[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] pub struct TSConditionalType<'a> { @@ -240,6 +241,7 @@ pub struct TSConditionalType<'a> { pub extends_type: TSType<'a>, pub true_type: TSType<'a>, pub false_type: TSType<'a>, + pub scope_id: Cell>, } /// string | string[] | (() => string) | { s: string } @@ -579,8 +581,7 @@ pub struct TSTypeParameterInstantiation<'a> { } #[visited_node] -#[scope] -#[derive(Debug)] +#[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] pub struct TSTypeParameter<'a> { @@ -592,7 +593,6 @@ pub struct TSTypeParameter<'a> { pub r#in: bool, pub out: bool, pub r#const: bool, - pub scope_id: Cell>, } #[visited_node] @@ -606,16 +606,19 @@ pub struct TSTypeParameterDeclaration<'a> { } #[visited_node] -#[derive(Debug, Hash)] +#[scope] +#[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] pub struct TSTypeAliasDeclaration<'a> { #[cfg_attr(feature = "serialize", serde(flatten))] pub span: Span, pub id: BindingIdentifier<'a>, + #[scope(enter_before)] pub type_parameters: Option>>, pub type_annotation: TSType<'a>, pub declare: bool, + pub scope_id: Cell>, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -642,17 +645,20 @@ pub struct TSClassImplements<'a> { /// /// interface `BindingIdentifier` `TypeParameters_opt` `InterfaceExtendsClause_opt` `ObjectType` #[visited_node] -#[derive(Debug, Hash)] +#[scope] +#[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] pub struct TSInterfaceDeclaration<'a> { #[cfg_attr(feature = "serialize", serde(flatten))] pub span: Span, pub id: BindingIdentifier<'a>, + #[scope(enter_before)] pub extends: Option>>, pub type_parameters: Option>>, pub body: Box<'a, TSInterfaceBody<'a>>, pub declare: bool, + pub scope_id: Cell>, } #[visited_node] @@ -726,7 +732,8 @@ pub enum TSMethodSignatureKind { } #[visited_node] -#[derive(Debug, Hash)] +#[scope] +#[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] pub struct TSMethodSignature<'a> { @@ -740,10 +747,12 @@ pub struct TSMethodSignature<'a> { pub params: Box<'a, FormalParameters<'a>>, pub return_type: Option>>, pub type_parameters: Option>>, + pub scope_id: Cell>, } #[visited_node] -#[derive(Debug, Hash)] +#[scope] +#[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] pub struct TSConstructSignatureDeclaration<'a> { @@ -752,6 +761,7 @@ pub struct TSConstructSignatureDeclaration<'a> { pub params: Box<'a, FormalParameters<'a>>, pub return_type: Option>>, pub type_parameters: Option>>, + pub scope_id: Cell>, } #[visited_node] @@ -994,7 +1004,8 @@ pub struct TSConstructorType<'a> { } #[visited_node] -#[derive(Debug, Hash)] +#[scope] +#[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] pub struct TSMappedType<'a> { @@ -1005,6 +1016,7 @@ pub struct TSMappedType<'a> { pub type_annotation: Option>, pub optional: TSMappedTypeModifierOperator, pub readonly: TSMappedTypeModifierOperator, + pub scope_id: Cell>, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/crates/oxc_ast/src/ast_impl/ts.rs b/crates/oxc_ast/src/ast_impl/ts.rs index 975e2e9a9c28d..65384029c3b93 100644 --- a/crates/oxc_ast/src/ast_impl/ts.rs +++ b/crates/oxc_ast/src/ast_impl/ts.rs @@ -103,31 +103,6 @@ impl<'a> TSTypeName<'a> { } } -impl<'a> TSTypeParameter<'a> { - pub fn new( - span: Span, - name: BindingIdentifier<'a>, - constraint: Option>, - default: Option>, - r#in: bool, - out: bool, - r#const: bool, - ) -> Self { - Self { span, name, constraint, default, r#in, out, r#const, scope_id: Cell::default() } - } -} - -impl<'a> Hash for TSTypeParameter<'a> { - fn hash(&self, state: &mut H) { - self.name.hash(state); - self.constraint.hash(state); - self.default.hash(state); - self.r#in.hash(state); - self.out.hash(state); - self.r#const.hash(state); - } -} - impl<'a> TSType<'a> { /// Remove nested parentheses from this type. pub fn without_parenthesized(&self) -> &Self { @@ -233,3 +208,68 @@ impl ImportOrExportKind { matches!(self, Self::Type) } } + +impl<'a> Hash for TSMappedType<'a> { + fn hash(&self, state: &mut H) { + self.span.hash(state); + self.type_parameter.hash(state); + self.name_type.hash(state); + self.type_annotation.hash(state); + self.optional.hash(state); + self.readonly.hash(state); + } +} + +impl<'a> Hash for TSConditionalType<'a> { + fn hash(&self, state: &mut H) { + self.span.hash(state); + self.check_type.hash(state); + self.extends_type.hash(state); + self.true_type.hash(state); + self.false_type.hash(state); + } +} + +impl<'a> Hash for TSInterfaceDeclaration<'a> { + fn hash(&self, state: &mut H) { + self.span.hash(state); + self.id.hash(state); + self.type_parameters.hash(state); + self.extends.hash(state); + self.body.hash(state); + self.declare.hash(state); + } +} + +impl<'a> Hash for TSTypeAliasDeclaration<'a> { + fn hash(&self, state: &mut H) { + self.span.hash(state); + self.id.hash(state); + self.type_parameters.hash(state); + self.type_annotation.hash(state); + self.declare.hash(state); + } +} + +impl<'a> Hash for TSMethodSignature<'a> { + fn hash(&self, state: &mut H) { + self.span.hash(state); + self.key.hash(state); + self.computed.hash(state); + self.optional.hash(state); + self.kind.hash(state); + self.this_param.hash(state); + self.params.hash(state); + self.return_type.hash(state); + self.type_parameters.hash(state); + } +} + +impl<'a> Hash for TSConstructSignatureDeclaration<'a> { + fn hash(&self, state: &mut H) { + self.span.hash(state); + self.params.hash(state); + self.return_type.hash(state); + self.type_parameters.hash(state); + } +} diff --git a/crates/oxc_ast/src/ast_kind_impl.rs b/crates/oxc_ast/src/ast_kind_impl.rs index 8b7d53a8f0aa5..bcf1b56ba3dec 100644 --- a/crates/oxc_ast/src/ast_kind_impl.rs +++ b/crates/oxc_ast/src/ast_kind_impl.rs @@ -345,6 +345,9 @@ impl<'a> AstKind<'a> { Self::TSNamedTupleMember(_) => "TSNamedTupleMember".into(), Self::TSPropertySignature(_) => "TSPropertySignature".into(), + Self::TSConditionalType(_) => "TSConditionalType".into(), + Self::TSMappedType(_) => "TSMappedType".into(), + Self::TSConstructSignatureDeclaration(_) => "TSConstructSignatureDeclaration".into(), } } } diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index 4f1d7fa9ce379..70d02d1eeacca 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -6062,7 +6062,14 @@ impl<'a> AstBuilder<'a> { true_type: TSType<'a>, false_type: TSType<'a>, ) -> TSConditionalType<'a> { - TSConditionalType { span, check_type, extends_type, true_type, false_type } + TSConditionalType { + span, + check_type, + extends_type, + true_type, + false_type, + scope_id: Default::default(), + } } #[inline] @@ -6542,16 +6549,7 @@ impl<'a> AstBuilder<'a> { out: bool, r#const: bool, ) -> TSTypeParameter<'a> { - TSTypeParameter { - span, - name, - constraint, - default, - r#in, - out, - r#const, - scope_id: Default::default(), - } + TSTypeParameter { span, name, constraint, default, r#in, out, r#const } } #[inline] @@ -6605,6 +6603,7 @@ impl<'a> AstBuilder<'a> { type_parameters: type_parameters.into_in(self.allocator), type_annotation, declare, + scope_id: Default::default(), } } @@ -6675,6 +6674,7 @@ impl<'a> AstBuilder<'a> { type_parameters: type_parameters.into_in(self.allocator), body: body.into_in(self.allocator), declare, + scope_id: Default::default(), } } @@ -7013,6 +7013,7 @@ impl<'a> AstBuilder<'a> { params: params.into_in(self.allocator), return_type: return_type.into_in(self.allocator), type_parameters: type_parameters.into_in(self.allocator), + scope_id: Default::default(), } } @@ -7066,6 +7067,7 @@ impl<'a> AstBuilder<'a> { params: params.into_in(self.allocator), return_type: return_type.into_in(self.allocator), type_parameters: type_parameters.into_in(self.allocator), + scope_id: Default::default(), } } @@ -7678,6 +7680,7 @@ impl<'a> AstBuilder<'a> { type_annotation, optional, readonly, + scope_id: Default::default(), } } diff --git a/crates/oxc_ast/src/generated/ast_kind.rs b/crates/oxc_ast/src/generated/ast_kind.rs index 91ca373eb477e..91eed09b2b849 100644 --- a/crates/oxc_ast/src/generated/ast_kind.rs +++ b/crates/oxc_ast/src/generated/ast_kind.rs @@ -107,6 +107,7 @@ pub enum AstType { TSEnumMember, TSTypeAnnotation, TSLiteralType, + TSConditionalType, TSUnionType, TSIntersectionType, TSParenthesizedType, @@ -137,6 +138,7 @@ pub enum AstType { TSInterfaceDeclaration, TSPropertySignature, TSMethodSignature, + TSConstructSignatureDeclaration, TSInterfaceHeritage, TSModuleDeclaration, TSModuleBlock, @@ -144,6 +146,7 @@ pub enum AstType { TSInferType, TSTypeQuery, TSImportType, + TSMappedType, TSTemplateLiteralType, TSAsExpression, TSSatisfiesExpression, @@ -273,6 +276,7 @@ pub enum AstKind<'a> { TSEnumMember(&'a TSEnumMember<'a>), TSTypeAnnotation(&'a TSTypeAnnotation<'a>), TSLiteralType(&'a TSLiteralType<'a>), + TSConditionalType(&'a TSConditionalType<'a>), TSUnionType(&'a TSUnionType<'a>), TSIntersectionType(&'a TSIntersectionType<'a>), TSParenthesizedType(&'a TSParenthesizedType<'a>), @@ -303,6 +307,7 @@ pub enum AstKind<'a> { TSInterfaceDeclaration(&'a TSInterfaceDeclaration<'a>), TSPropertySignature(&'a TSPropertySignature<'a>), TSMethodSignature(&'a TSMethodSignature<'a>), + TSConstructSignatureDeclaration(&'a TSConstructSignatureDeclaration<'a>), TSInterfaceHeritage(&'a TSInterfaceHeritage<'a>), TSModuleDeclaration(&'a TSModuleDeclaration<'a>), TSModuleBlock(&'a TSModuleBlock<'a>), @@ -310,6 +315,7 @@ pub enum AstKind<'a> { TSInferType(&'a TSInferType<'a>), TSTypeQuery(&'a TSTypeQuery<'a>), TSImportType(&'a TSImportType<'a>), + TSMappedType(&'a TSMappedType<'a>), TSTemplateLiteralType(&'a TSTemplateLiteralType<'a>), TSAsExpression(&'a TSAsExpression<'a>), TSSatisfiesExpression(&'a TSSatisfiesExpression<'a>), @@ -440,6 +446,7 @@ impl<'a> GetSpan for AstKind<'a> { Self::TSEnumMember(it) => it.span(), Self::TSTypeAnnotation(it) => it.span(), Self::TSLiteralType(it) => it.span(), + Self::TSConditionalType(it) => it.span(), Self::TSUnionType(it) => it.span(), Self::TSIntersectionType(it) => it.span(), Self::TSParenthesizedType(it) => it.span(), @@ -470,6 +477,7 @@ impl<'a> GetSpan for AstKind<'a> { Self::TSInterfaceDeclaration(it) => it.span(), Self::TSPropertySignature(it) => it.span(), Self::TSMethodSignature(it) => it.span(), + Self::TSConstructSignatureDeclaration(it) => it.span(), Self::TSInterfaceHeritage(it) => it.span(), Self::TSModuleDeclaration(it) => it.span(), Self::TSModuleBlock(it) => it.span(), @@ -477,6 +485,7 @@ impl<'a> GetSpan for AstKind<'a> { Self::TSInferType(it) => it.span(), Self::TSTypeQuery(it) => it.span(), Self::TSImportType(it) => it.span(), + Self::TSMappedType(it) => it.span(), Self::TSTemplateLiteralType(it) => it.span(), Self::TSAsExpression(it) => it.span(), Self::TSSatisfiesExpression(it) => it.span(), diff --git a/crates/oxc_ast/src/generated/visit.rs b/crates/oxc_ast/src/generated/visit.rs index 9afffe69c3e5f..5abd35de2e343 100644 --- a/crates/oxc_ast/src/generated/visit.rs +++ b/crates/oxc_ast/src/generated/visit.rs @@ -2030,11 +2030,15 @@ pub mod walk { #[inline] pub fn walk_ts_conditional_type<'a, V: Visit<'a>>(visitor: &mut V, it: &TSConditionalType<'a>) { - // NOTE: AstKind doesn't exists! + let kind = AstKind::TSConditionalType(visitor.alloc(it)); + visitor.enter_node(kind); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); visitor.visit_ts_type(&it.check_type); visitor.visit_ts_type(&it.extends_type); visitor.visit_ts_type(&it.true_type); visitor.visit_ts_type(&it.false_type); + visitor.leave_scope(); + visitor.leave_node(kind); } #[inline] @@ -2072,7 +2076,6 @@ pub mod walk { pub fn walk_ts_type_parameter<'a, V: Visit<'a>>(visitor: &mut V, it: &TSTypeParameter<'a>) { let kind = AstKind::TSTypeParameter(visitor.alloc(it)); visitor.enter_node(kind); - visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); visitor.visit_binding_identifier(&it.name); if let Some(constraint) = &it.constraint { visitor.visit_ts_type(constraint); @@ -2080,7 +2083,6 @@ pub mod walk { if let Some(default) = &it.default { visitor.visit_ts_type(default); } - visitor.leave_scope(); visitor.leave_node(kind); } @@ -2262,7 +2264,9 @@ pub mod walk { #[inline] pub fn walk_ts_mapped_type<'a, V: Visit<'a>>(visitor: &mut V, it: &TSMappedType<'a>) { - // NOTE: AstKind doesn't exists! + let kind = AstKind::TSMappedType(visitor.alloc(it)); + visitor.enter_node(kind); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); visitor.visit_ts_type_parameter(&it.type_parameter); if let Some(name_type) = &it.name_type { visitor.visit_ts_type(name_type); @@ -2270,6 +2274,8 @@ pub mod walk { if let Some(type_annotation) = &it.type_annotation { visitor.visit_ts_type(type_annotation); } + visitor.leave_scope(); + visitor.leave_node(kind); } #[inline] @@ -2433,7 +2439,9 @@ pub mod walk { visitor: &mut V, it: &TSConstructSignatureDeclaration<'a>, ) { - // NOTE: AstKind doesn't exists! + let kind = AstKind::TSConstructSignatureDeclaration(visitor.alloc(it)); + visitor.enter_node(kind); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); visitor.visit_formal_parameters(&it.params); if let Some(return_type) = &it.return_type { visitor.visit_ts_type_annotation(return_type); @@ -2441,12 +2449,15 @@ pub mod walk { if let Some(type_parameters) = &it.type_parameters { visitor.visit_ts_type_parameter_declaration(type_parameters); } + visitor.leave_scope(); + visitor.leave_node(kind); } #[inline] pub fn walk_ts_method_signature<'a, V: Visit<'a>>(visitor: &mut V, it: &TSMethodSignature<'a>) { let kind = AstKind::TSMethodSignature(visitor.alloc(it)); visitor.enter_node(kind); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); visitor.visit_property_key(&it.key); if let Some(this_param) = &it.this_param { visitor.visit_ts_this_parameter(this_param); @@ -2458,6 +2469,7 @@ pub mod walk { if let Some(type_parameters) = &it.type_parameters { visitor.visit_ts_type_parameter_declaration(type_parameters); } + visitor.leave_scope(); visitor.leave_node(kind); } @@ -3757,10 +3769,12 @@ pub mod walk { let kind = AstKind::TSTypeAliasDeclaration(visitor.alloc(it)); visitor.enter_node(kind); visitor.visit_binding_identifier(&it.id); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); if let Some(type_parameters) = &it.type_parameters { visitor.visit_ts_type_parameter_declaration(type_parameters); } visitor.visit_ts_type(&it.type_annotation); + visitor.leave_scope(); visitor.leave_node(kind); } @@ -3772,6 +3786,7 @@ pub mod walk { let kind = AstKind::TSInterfaceDeclaration(visitor.alloc(it)); visitor.enter_node(kind); visitor.visit_binding_identifier(&it.id); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); if let Some(extends) = &it.extends { visitor.visit_ts_interface_heritages(extends); } @@ -3779,6 +3794,7 @@ pub mod walk { visitor.visit_ts_type_parameter_declaration(type_parameters); } visitor.visit_ts_interface_body(&it.body); + visitor.leave_scope(); visitor.leave_node(kind); } diff --git a/crates/oxc_ast/src/generated/visit_mut.rs b/crates/oxc_ast/src/generated/visit_mut.rs index ab0f923b7826a..8fa4d4d67d6d7 100644 --- a/crates/oxc_ast/src/generated/visit_mut.rs +++ b/crates/oxc_ast/src/generated/visit_mut.rs @@ -2088,11 +2088,15 @@ pub mod walk_mut { visitor: &mut V, it: &mut TSConditionalType<'a>, ) { - // NOTE: AstType doesn't exists! + let kind = AstType::TSConditionalType; + visitor.enter_node(kind); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); visitor.visit_ts_type(&mut it.check_type); visitor.visit_ts_type(&mut it.extends_type); visitor.visit_ts_type(&mut it.true_type); visitor.visit_ts_type(&mut it.false_type); + visitor.leave_scope(); + visitor.leave_node(kind); } #[inline] @@ -2136,7 +2140,6 @@ pub mod walk_mut { ) { let kind = AstType::TSTypeParameter; visitor.enter_node(kind); - visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); visitor.visit_binding_identifier(&mut it.name); if let Some(constraint) = &mut it.constraint { visitor.visit_ts_type(constraint); @@ -2144,7 +2147,6 @@ pub mod walk_mut { if let Some(default) = &mut it.default { visitor.visit_ts_type(default); } - visitor.leave_scope(); visitor.leave_node(kind); } @@ -2341,7 +2343,9 @@ pub mod walk_mut { #[inline] pub fn walk_ts_mapped_type<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut TSMappedType<'a>) { - // NOTE: AstType doesn't exists! + let kind = AstType::TSMappedType; + visitor.enter_node(kind); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); visitor.visit_ts_type_parameter(&mut it.type_parameter); if let Some(name_type) = &mut it.name_type { visitor.visit_ts_type(name_type); @@ -2349,6 +2353,8 @@ pub mod walk_mut { if let Some(type_annotation) = &mut it.type_annotation { visitor.visit_ts_type(type_annotation); } + visitor.leave_scope(); + visitor.leave_node(kind); } #[inline] @@ -2524,7 +2530,9 @@ pub mod walk_mut { visitor: &mut V, it: &mut TSConstructSignatureDeclaration<'a>, ) { - // NOTE: AstType doesn't exists! + let kind = AstType::TSConstructSignatureDeclaration; + visitor.enter_node(kind); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); visitor.visit_formal_parameters(&mut it.params); if let Some(return_type) = &mut it.return_type { visitor.visit_ts_type_annotation(return_type); @@ -2532,6 +2540,8 @@ pub mod walk_mut { if let Some(type_parameters) = &mut it.type_parameters { visitor.visit_ts_type_parameter_declaration(type_parameters); } + visitor.leave_scope(); + visitor.leave_node(kind); } #[inline] @@ -2541,6 +2551,7 @@ pub mod walk_mut { ) { let kind = AstType::TSMethodSignature; visitor.enter_node(kind); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); visitor.visit_property_key(&mut it.key); if let Some(this_param) = &mut it.this_param { visitor.visit_ts_this_parameter(this_param); @@ -2552,6 +2563,7 @@ pub mod walk_mut { if let Some(type_parameters) = &mut it.type_parameters { visitor.visit_ts_type_parameter_declaration(type_parameters); } + visitor.leave_scope(); visitor.leave_node(kind); } @@ -3969,10 +3981,12 @@ pub mod walk_mut { let kind = AstType::TSTypeAliasDeclaration; visitor.enter_node(kind); visitor.visit_binding_identifier(&mut it.id); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); if let Some(type_parameters) = &mut it.type_parameters { visitor.visit_ts_type_parameter_declaration(type_parameters); } visitor.visit_ts_type(&mut it.type_annotation); + visitor.leave_scope(); visitor.leave_node(kind); } @@ -3984,6 +3998,7 @@ pub mod walk_mut { let kind = AstType::TSInterfaceDeclaration; visitor.enter_node(kind); visitor.visit_binding_identifier(&mut it.id); + visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); if let Some(extends) = &mut it.extends { visitor.visit_ts_interface_heritages(extends); } @@ -3991,6 +4006,7 @@ pub mod walk_mut { visitor.visit_ts_type_parameter_declaration(type_parameters); } visitor.visit_ts_interface_body(&mut it.body); + visitor.leave_scope(); visitor.leave_node(kind); } diff --git a/crates/oxc_semantic/tests/integration/symbols.rs b/crates/oxc_semantic/tests/integration/symbols.rs index 8b43297749a19..3d0517ca03305 100644 --- a/crates/oxc_semantic/tests/integration/symbols.rs +++ b/crates/oxc_semantic/tests/integration/symbols.rs @@ -114,3 +114,126 @@ fn test_export_flag() { tester.has_root_symbol("b").contains_flags(SymbolFlags::Export).test(); tester.has_root_symbol("c").contains_flags(SymbolFlags::Export).test(); } + +#[test] +fn test_multiple_ts_type_alias_declaration() { + let tester = SemanticTester::ts( + " + type A = AB + type B = AB + ", + ); + + tester + .has_symbol("AB") + .contains_flags(SymbolFlags::TypeParameter) + .has_number_of_references(1) + .test(); +} + +#[test] +fn test_function_with_type_parameter() { + let tester = SemanticTester::ts( + " + function mdl() { + function mdl2() { + function mdl3() { + return '' as M; + } + } + } + function kfc() { + function kfc2() { + function kfc3() { + return '' as K; + } + } + } + ", + ); + + tester.has_symbol("M").has_number_of_references(1).test(); + tester.has_symbol("K").has_number_of_references(0).test(); +} + +#[test] +fn test_class_with_type_parameter() { + let tester = SemanticTester::ts( + " + class Cls { + a: T; + method(b: T | K) {} + func() { + type D = T; + return null as D + } + } + type B = any; + class ClassB { + b: B; + } + ", + ); + + tester.has_symbol("T").has_number_of_references(3).test(); + tester.has_symbol("K").has_number_of_references(1).test(); + tester.has_symbol("D").has_number_of_references(1).test(); + + // type B is not referenced + tester.has_symbol("B").has_number_of_references(0).test(); +} + +#[test] +fn test_ts_mapped_type() { + let tester = SemanticTester::ts( + " + type M = { [K in keyof T]: T[K] }; + type Y = any; + type X = { [Y in keyof T]: T[Y] }; + ", + ); + + tester.has_symbol("T").has_number_of_references(2).test(); + tester.has_symbol("K").has_number_of_references(1).test(); + + // type Y is not referenced + tester.has_symbol("Y").has_number_of_references(0).test(); +} + +#[test] +fn test_ts_interface_declaration_with_type_parameter() { + let tester = SemanticTester::ts( + " + type A = any; + interface ITA { + a: A; + } + interface ITB { + b: B; + } + ", + ); + + tester.has_symbol("B").has_number_of_references(1).test(); + + // type A is not referenced + tester.has_symbol("A").has_number_of_references(0).test(); +} + +#[test] +fn test_ts_infer_type() { + let tester = SemanticTester::ts( + " + type T = T extends infer U ? U : never; + + type C = any; + type K = K extends infer C ? K : never; + ", + ); + + tester.has_symbol("T").has_number_of_references(1).test(); + tester.has_symbol("U").has_number_of_references(1).test(); + + // type C is not referenced + tester.has_symbol("C").has_number_of_references(0).test(); +} diff --git a/crates/oxc_semantic/tests/integration/util/mod.rs b/crates/oxc_semantic/tests/integration/util/mod.rs index 3cdd9f154a059..75efcd1d007af 100644 --- a/crates/oxc_semantic/tests/integration/util/mod.rs +++ b/crates/oxc_semantic/tests/integration/util/mod.rs @@ -189,6 +189,14 @@ impl<'a> SemanticTester<'a> { SymbolTester::new_at_root(self, self.build(), name) } + /// Find first symbol by name in the source code. + /// + /// ## Fails + /// 1. No symbol with the given name exists, + pub fn has_symbol(&self, name: &str) -> SymbolTester { + SymbolTester::new_first_binding(self, self.build(), name) + } + /// Tests that a class with the given name exists /// /// ## Fails diff --git a/crates/oxc_semantic/tests/integration/util/symbol_tester.rs b/crates/oxc_semantic/tests/integration/util/symbol_tester.rs index ccc1929e9f78b..3640b5a6f4bc5 100644 --- a/crates/oxc_semantic/tests/integration/util/symbol_tester.rs +++ b/crates/oxc_semantic/tests/integration/util/symbol_tester.rs @@ -1,7 +1,8 @@ use std::rc::Rc; use oxc_diagnostics::{Error, OxcDiagnostic}; -use oxc_semantic::{Reference, ScopeFlags, Semantic, SymbolFlags, SymbolId}; +use oxc_semantic::{Reference, ScopeFlags, ScopeId, Semantic, SymbolFlags, SymbolId}; +use oxc_span::CompactStr; use super::{Expect, SemanticTester}; @@ -71,6 +72,27 @@ impl<'a> SymbolTester<'a> { (Rc::clone(&self.semantic), *self.test_result.as_ref().unwrap()) } + pub(super) fn new_first_binding( + parent: &'a SemanticTester, + semantic: Semantic<'a>, + target: &str, + ) -> Self { + let symbols_with_target_name: Option<(ScopeId, SymbolId, &CompactStr)> = + semantic.scopes().iter_bindings().find(|(_, _, name)| name.as_str() == target); + + let data = match symbols_with_target_name { + Some((_, symbol_id, _)) => Ok(symbol_id), + None => Err(OxcDiagnostic::error(format!("Could not find declaration for {target}"))), + }; + + SymbolTester { + parent, + semantic: Rc::new(semantic), + target_symbol_name: target.to_string(), + test_result: data, + } + } + /// Checks if the resolved symbol contains all flags in `flags`, using [`SymbolFlags::contains()`] #[must_use] pub fn contains_flags(mut self, flags: SymbolFlags) -> Self { diff --git a/crates/oxc_traverse/src/ancestor.rs b/crates/oxc_traverse/src/ancestor.rs index 8ba65a30260c6..2496879aaba6d 100644 --- a/crates/oxc_traverse/src/ancestor.rs +++ b/crates/oxc_traverse/src/ancestor.rs @@ -8839,6 +8839,8 @@ pub(crate) const OFFSET_TS_CONDITIONAL_TYPE_TRUE_TYPE: usize = offset_of!(TSConditionalType, true_type); pub(crate) const OFFSET_TS_CONDITIONAL_TYPE_FALSE_TYPE: usize = offset_of!(TSConditionalType, false_type); +pub(crate) const OFFSET_TS_CONDITIONAL_TYPE_SCOPE_ID: usize = + offset_of!(TSConditionalType, scope_id); #[repr(transparent)] #[derive(Debug)] @@ -8872,6 +8874,14 @@ impl<'a> TSConditionalTypeWithoutCheckType<'a> { as *const TSType<'a>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_CONDITIONAL_TYPE_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -8906,6 +8916,14 @@ impl<'a> TSConditionalTypeWithoutExtendsType<'a> { as *const TSType<'a>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_CONDITIONAL_TYPE_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -8941,6 +8959,14 @@ impl<'a> TSConditionalTypeWithoutTrueType<'a> { as *const TSType<'a>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_CONDITIONAL_TYPE_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -8975,6 +9001,14 @@ impl<'a> TSConditionalTypeWithoutFalseType<'a> { &*((self.0 as *const u8).add(OFFSET_TS_CONDITIONAL_TYPE_TRUE_TYPE) as *const TSType<'a>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_CONDITIONAL_TYPE_SCOPE_ID) + as *const Cell>) + } + } } pub(crate) const OFFSET_TS_UNION_TYPE_SPAN: usize = offset_of!(TSUnionType, span); @@ -9318,7 +9352,6 @@ pub(crate) const OFFSET_TS_TYPE_PARAMETER_DEFAULT: usize = offset_of!(TSTypePara pub(crate) const OFFSET_TS_TYPE_PARAMETER_IN: usize = offset_of!(TSTypeParameter, r#in); pub(crate) const OFFSET_TS_TYPE_PARAMETER_OUT: usize = offset_of!(TSTypeParameter, out); pub(crate) const OFFSET_TS_TYPE_PARAMETER_CONST: usize = offset_of!(TSTypeParameter, r#const); -pub(crate) const OFFSET_TS_TYPE_PARAMETER_SCOPE_ID: usize = offset_of!(TSTypeParameter, scope_id); #[repr(transparent)] #[derive(Debug)] @@ -9360,14 +9393,6 @@ impl<'a> TSTypeParameterWithoutName<'a> { pub fn r#const(&self) -> &bool { unsafe { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_CONST) as *const bool) } } - - #[inline] - pub fn scope_id(&self) -> &Cell> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_SCOPE_ID) - as *const Cell>) - } - } } #[repr(transparent)] @@ -9410,14 +9435,6 @@ impl<'a> TSTypeParameterWithoutConstraint<'a> { pub fn r#const(&self) -> &bool { unsafe { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_CONST) as *const bool) } } - - #[inline] - pub fn scope_id(&self) -> &Cell> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_SCOPE_ID) - as *const Cell>) - } - } } #[repr(transparent)] @@ -9460,14 +9477,6 @@ impl<'a> TSTypeParameterWithoutDefault<'a> { pub fn r#const(&self) -> &bool { unsafe { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_CONST) as *const bool) } } - - #[inline] - pub fn scope_id(&self) -> &Cell> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_SCOPE_ID) - as *const Cell>) - } - } } pub(crate) const OFFSET_TS_TYPE_PARAMETER_DECLARATION_SPAN: usize = @@ -9500,6 +9509,8 @@ pub(crate) const OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_ANNOTATION: usize = offset_of!(TSTypeAliasDeclaration, type_annotation); pub(crate) const OFFSET_TS_TYPE_ALIAS_DECLARATION_DECLARE: usize = offset_of!(TSTypeAliasDeclaration, declare); +pub(crate) const OFFSET_TS_TYPE_ALIAS_DECLARATION_SCOPE_ID: usize = + offset_of!(TSTypeAliasDeclaration, scope_id); #[repr(transparent)] #[derive(Debug)] @@ -9535,6 +9546,14 @@ impl<'a> TSTypeAliasDeclarationWithoutId<'a> { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_DECLARE) as *const bool) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -9573,6 +9592,14 @@ impl<'a> TSTypeAliasDeclarationWithoutTypeParameters<'a> { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_DECLARE) as *const bool) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -9611,6 +9638,14 @@ impl<'a> TSTypeAliasDeclarationWithoutTypeAnnotation<'a> { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_DECLARE) as *const bool) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_SCOPE_ID) + as *const Cell>) + } + } } pub(crate) const OFFSET_TS_CLASS_IMPLEMENTS_SPAN: usize = offset_of!(TSClassImplements, span); @@ -9668,6 +9703,8 @@ pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_BODY: usize = offset_of!(TSInterfaceDeclaration, body); pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_DECLARE: usize = offset_of!(TSInterfaceDeclaration, declare); +pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_SCOPE_ID: usize = + offset_of!(TSInterfaceDeclaration, scope_id); #[repr(transparent)] #[derive(Debug)] @@ -9711,6 +9748,14 @@ impl<'a> TSInterfaceDeclarationWithoutId<'a> { &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_DECLARE) as *const bool) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -9755,6 +9800,14 @@ impl<'a> TSInterfaceDeclarationWithoutExtends<'a> { &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_DECLARE) as *const bool) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -9801,6 +9854,14 @@ impl<'a> TSInterfaceDeclarationWithoutTypeParameters<'a> { &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_DECLARE) as *const bool) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -9845,6 +9906,14 @@ impl<'a> TSInterfaceDeclarationWithoutBody<'a> { &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_DECLARE) as *const bool) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_SCOPE_ID) + as *const Cell>) + } + } } pub(crate) const OFFSET_TS_INTERFACE_BODY_SPAN: usize = offset_of!(TSInterfaceBody, span); @@ -10188,6 +10257,8 @@ pub(crate) const OFFSET_TS_METHOD_SIGNATURE_RETURN_TYPE: usize = offset_of!(TSMethodSignature, return_type); pub(crate) const OFFSET_TS_METHOD_SIGNATURE_TYPE_PARAMETERS: usize = offset_of!(TSMethodSignature, type_parameters); +pub(crate) const OFFSET_TS_METHOD_SIGNATURE_SCOPE_ID: usize = + offset_of!(TSMethodSignature, scope_id); #[repr(transparent)] #[derive(Debug)] @@ -10248,6 +10319,14 @@ impl<'a> TSMethodSignatureWithoutKey<'a> { as *const Option>>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_METHOD_SIGNATURE_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -10308,6 +10387,14 @@ impl<'a> TSMethodSignatureWithoutThisParam<'a> { as *const Option>>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_METHOD_SIGNATURE_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -10368,6 +10455,14 @@ impl<'a> TSMethodSignatureWithoutParams<'a> { as *const Option>>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_METHOD_SIGNATURE_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -10428,6 +10523,14 @@ impl<'a> TSMethodSignatureWithoutReturnType<'a> { as *const Option>>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_METHOD_SIGNATURE_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -10488,6 +10591,14 @@ impl<'a> TSMethodSignatureWithoutTypeParameters<'a> { as *const Option>>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_METHOD_SIGNATURE_SCOPE_ID) + as *const Cell>) + } + } } pub(crate) const OFFSET_TS_CONSTRUCT_SIGNATURE_DECLARATION_SPAN: usize = @@ -10498,6 +10609,8 @@ pub(crate) const OFFSET_TS_CONSTRUCT_SIGNATURE_DECLARATION_RETURN_TYPE: usize = offset_of!(TSConstructSignatureDeclaration, return_type); pub(crate) const OFFSET_TS_CONSTRUCT_SIGNATURE_DECLARATION_TYPE_PARAMETERS: usize = offset_of!(TSConstructSignatureDeclaration, type_parameters); +pub(crate) const OFFSET_TS_CONSTRUCT_SIGNATURE_DECLARATION_SCOPE_ID: usize = + offset_of!(TSConstructSignatureDeclaration, scope_id); #[repr(transparent)] #[derive(Debug)] @@ -10529,6 +10642,14 @@ impl<'a> TSConstructSignatureDeclarationWithoutParams<'a> { as *const Option>>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_CONSTRUCT_SIGNATURE_DECLARATION_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -10561,6 +10682,14 @@ impl<'a> TSConstructSignatureDeclarationWithoutReturnType<'a> { as *const Option>>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_CONSTRUCT_SIGNATURE_DECLARATION_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -10593,6 +10722,14 @@ impl<'a> TSConstructSignatureDeclarationWithoutTypeParameters<'a> { as *const Option>>) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_CONSTRUCT_SIGNATURE_DECLARATION_SCOPE_ID) + as *const Cell>) + } + } } pub(crate) const OFFSET_TS_INDEX_SIGNATURE_NAME_SPAN: usize = @@ -11410,6 +11547,7 @@ pub(crate) const OFFSET_TS_MAPPED_TYPE_TYPE_ANNOTATION: usize = offset_of!(TSMappedType, type_annotation); pub(crate) const OFFSET_TS_MAPPED_TYPE_OPTIONAL: usize = offset_of!(TSMappedType, optional); pub(crate) const OFFSET_TS_MAPPED_TYPE_READONLY: usize = offset_of!(TSMappedType, readonly); +pub(crate) const OFFSET_TS_MAPPED_TYPE_SCOPE_ID: usize = offset_of!(TSMappedType, scope_id); #[repr(transparent)] #[derive(Debug)] @@ -11452,6 +11590,14 @@ impl<'a> TSMappedTypeWithoutTypeParameter<'a> { as *const TSMappedTypeModifierOperator) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_MAPPED_TYPE_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -11495,6 +11641,14 @@ impl<'a> TSMappedTypeWithoutNameType<'a> { as *const TSMappedTypeModifierOperator) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_MAPPED_TYPE_SCOPE_ID) + as *const Cell>) + } + } } #[repr(transparent)] @@ -11538,6 +11692,14 @@ impl<'a> TSMappedTypeWithoutTypeAnnotation<'a> { as *const TSMappedTypeModifierOperator) } } + + #[inline] + pub fn scope_id(&self) -> &Cell> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_TS_MAPPED_TYPE_SCOPE_ID) + as *const Cell>) + } + } } pub(crate) const OFFSET_TS_TEMPLATE_LITERAL_TYPE_SPAN: usize = diff --git a/crates/oxc_traverse/src/context/scoping.rs b/crates/oxc_traverse/src/context/scoping.rs index 4345abd18bb2b..30482793a4d11 100644 --- a/crates/oxc_traverse/src/context/scoping.rs +++ b/crates/oxc_traverse/src/context/scoping.rs @@ -577,7 +577,15 @@ impl<'a> Visit<'a> for ChildScopeCollector { self.scope_ids.push(decl.scope_id.get().unwrap()); } - fn visit_ts_type_parameter(&mut self, ty: &TSTypeParameter<'a>) { - self.scope_ids.push(ty.scope_id.get().unwrap()); + fn visit_ts_interface_declaration(&mut self, it: &TSInterfaceDeclaration<'a>) { + self.scope_ids.push(it.scope_id.get().unwrap()); + } + + fn visit_ts_mapped_type(&mut self, it: &TSMappedType<'a>) { + self.scope_ids.push(it.scope_id.get().unwrap()); + } + + fn visit_ts_conditional_type(&mut self, it: &TSConditionalType<'a>) { + self.scope_ids.push(it.scope_id.get().unwrap()); } } diff --git a/crates/oxc_traverse/src/walk.rs b/crates/oxc_traverse/src/walk.rs index 89280fa248900..b3373c2035472 100644 --- a/crates/oxc_traverse/src/walk.rs +++ b/crates/oxc_traverse/src/walk.rs @@ -3925,6 +3925,14 @@ pub(crate) unsafe fn walk_ts_conditional_type<'a, Tr: Traverse<'a>>( node: *mut TSConditionalType<'a>, ctx: &mut TraverseCtx<'a>, ) { + let mut previous_scope_id = None; + if let Some(scope_id) = (*((node as *mut u8).add(ancestor::OFFSET_TS_CONDITIONAL_TYPE_SCOPE_ID) + as *mut Cell>)) + .get() + { + previous_scope_id = Some(ctx.current_scope_id()); + ctx.set_current_scope_id(scope_id); + } traverser.enter_ts_conditional_type(&mut *node, ctx); ctx.push_stack(Ancestor::TSConditionalTypeCheckType( ancestor::TSConditionalTypeWithoutCheckType(node), @@ -3954,6 +3962,9 @@ pub(crate) unsafe fn walk_ts_conditional_type<'a, Tr: Traverse<'a>>( ); ctx.pop_stack(); traverser.exit_ts_conditional_type(&mut *node, ctx); + if let Some(previous_scope_id) = previous_scope_id { + ctx.set_current_scope_id(previous_scope_id); + } } pub(crate) unsafe fn walk_ts_union_type<'a, Tr: Traverse<'a>>( @@ -4417,14 +4428,6 @@ pub(crate) unsafe fn walk_ts_type_parameter<'a, Tr: Traverse<'a>>( node: *mut TSTypeParameter<'a>, ctx: &mut TraverseCtx<'a>, ) { - let mut previous_scope_id = None; - if let Some(scope_id) = (*((node as *mut u8).add(ancestor::OFFSET_TS_TYPE_PARAMETER_SCOPE_ID) - as *mut Cell>)) - .get() - { - previous_scope_id = Some(ctx.current_scope_id()); - ctx.set_current_scope_id(scope_id); - } traverser.enter_ts_type_parameter(&mut *node, ctx); ctx.push_stack(Ancestor::TSTypeParameterName(ancestor::TSTypeParameterWithoutName(node))); walk_binding_identifier( @@ -4446,9 +4449,6 @@ pub(crate) unsafe fn walk_ts_type_parameter<'a, Tr: Traverse<'a>>( } ctx.pop_stack(); traverser.exit_ts_type_parameter(&mut *node, ctx); - if let Some(previous_scope_id) = previous_scope_id { - ctx.set_current_scope_id(previous_scope_id); - } } pub(crate) unsafe fn walk_ts_type_parameter_declaration<'a, Tr: Traverse<'a>>( @@ -4485,6 +4485,15 @@ pub(crate) unsafe fn walk_ts_type_alias_declaration<'a, Tr: Traverse<'a>>( as *mut BindingIdentifier, ctx, ); + let mut previous_scope_id = None; + if let Some(scope_id) = (*((node as *mut u8) + .add(ancestor::OFFSET_TS_TYPE_ALIAS_DECLARATION_SCOPE_ID) + as *mut Cell>)) + .get() + { + previous_scope_id = Some(ctx.current_scope_id()); + ctx.set_current_scope_id(scope_id); + } if let Some(field) = &mut *((node as *mut u8) .add(ancestor::OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_PARAMETERS) as *mut Option>) @@ -4500,6 +4509,9 @@ pub(crate) unsafe fn walk_ts_type_alias_declaration<'a, Tr: Traverse<'a>>( ctx, ); ctx.pop_stack(); + if let Some(previous_scope_id) = previous_scope_id { + ctx.set_current_scope_id(previous_scope_id); + } traverser.exit_ts_type_alias_declaration(&mut *node, ctx); } @@ -4543,6 +4555,15 @@ pub(crate) unsafe fn walk_ts_interface_declaration<'a, Tr: Traverse<'a>>( as *mut BindingIdentifier, ctx, ); + let mut previous_scope_id = None; + if let Some(scope_id) = (*((node as *mut u8) + .add(ancestor::OFFSET_TS_INTERFACE_DECLARATION_SCOPE_ID) + as *mut Cell>)) + .get() + { + previous_scope_id = Some(ctx.current_scope_id()); + ctx.set_current_scope_id(scope_id); + } if let Some(field) = &mut *((node as *mut u8) .add(ancestor::OFFSET_TS_INTERFACE_DECLARATION_EXTENDS) as *mut Option>) @@ -4567,6 +4588,9 @@ pub(crate) unsafe fn walk_ts_interface_declaration<'a, Tr: Traverse<'a>>( ctx, ); ctx.pop_stack(); + if let Some(previous_scope_id) = previous_scope_id { + ctx.set_current_scope_id(previous_scope_id); + } traverser.exit_ts_interface_declaration(&mut *node, ctx); } @@ -4707,6 +4731,14 @@ pub(crate) unsafe fn walk_ts_method_signature<'a, Tr: Traverse<'a>>( node: *mut TSMethodSignature<'a>, ctx: &mut TraverseCtx<'a>, ) { + let mut previous_scope_id = None; + if let Some(scope_id) = (*((node as *mut u8).add(ancestor::OFFSET_TS_METHOD_SIGNATURE_SCOPE_ID) + as *mut Cell>)) + .get() + { + previous_scope_id = Some(ctx.current_scope_id()); + ctx.set_current_scope_id(scope_id); + } traverser.enter_ts_method_signature(&mut *node, ctx); ctx.push_stack(Ancestor::TSMethodSignatureKey(ancestor::TSMethodSignatureWithoutKey(node))); walk_property_key( @@ -4744,6 +4776,9 @@ pub(crate) unsafe fn walk_ts_method_signature<'a, Tr: Traverse<'a>>( } ctx.pop_stack(); traverser.exit_ts_method_signature(&mut *node, ctx); + if let Some(previous_scope_id) = previous_scope_id { + ctx.set_current_scope_id(previous_scope_id); + } } pub(crate) unsafe fn walk_ts_construct_signature_declaration<'a, Tr: Traverse<'a>>( @@ -4751,6 +4786,15 @@ pub(crate) unsafe fn walk_ts_construct_signature_declaration<'a, Tr: Traverse<'a node: *mut TSConstructSignatureDeclaration<'a>, ctx: &mut TraverseCtx<'a>, ) { + let mut previous_scope_id = None; + if let Some(scope_id) = (*((node as *mut u8) + .add(ancestor::OFFSET_TS_CONSTRUCT_SIGNATURE_DECLARATION_SCOPE_ID) + as *mut Cell>)) + .get() + { + previous_scope_id = Some(ctx.current_scope_id()); + ctx.set_current_scope_id(scope_id); + } traverser.enter_ts_construct_signature_declaration(&mut *node, ctx); ctx.push_stack(Ancestor::TSConstructSignatureDeclarationParams( ancestor::TSConstructSignatureDeclarationWithoutParams(node), @@ -4777,6 +4821,9 @@ pub(crate) unsafe fn walk_ts_construct_signature_declaration<'a, Tr: Traverse<'a } ctx.pop_stack(); traverser.exit_ts_construct_signature_declaration(&mut *node, ctx); + if let Some(previous_scope_id) = previous_scope_id { + ctx.set_current_scope_id(previous_scope_id); + } } pub(crate) unsafe fn walk_ts_index_signature_name<'a, Tr: Traverse<'a>>( @@ -5205,6 +5252,14 @@ pub(crate) unsafe fn walk_ts_mapped_type<'a, Tr: Traverse<'a>>( node: *mut TSMappedType<'a>, ctx: &mut TraverseCtx<'a>, ) { + let mut previous_scope_id = None; + if let Some(scope_id) = (*((node as *mut u8).add(ancestor::OFFSET_TS_MAPPED_TYPE_SCOPE_ID) + as *mut Cell>)) + .get() + { + previous_scope_id = Some(ctx.current_scope_id()); + ctx.set_current_scope_id(scope_id); + } traverser.enter_ts_mapped_type(&mut *node, ctx); ctx.push_stack(Ancestor::TSMappedTypeTypeParameter( ancestor::TSMappedTypeWithoutTypeParameter(node), @@ -5230,6 +5285,9 @@ pub(crate) unsafe fn walk_ts_mapped_type<'a, Tr: Traverse<'a>>( } ctx.pop_stack(); traverser.exit_ts_mapped_type(&mut *node, ctx); + if let Some(previous_scope_id) = previous_scope_id { + ctx.set_current_scope_id(previous_scope_id); + } } pub(crate) unsafe fn walk_ts_template_literal_type<'a, Tr: Traverse<'a>>( diff --git a/tasks/ast_codegen/src/generators/ast_kind.rs b/tasks/ast_codegen/src/generators/ast_kind.rs index 3c080272dc591..a836b5cd1cde3 100644 --- a/tasks/ast_codegen/src/generators/ast_kind.rs +++ b/tasks/ast_codegen/src/generators/ast_kind.rs @@ -8,7 +8,7 @@ use super::generated_header; pub struct AstKindGenerator; -pub const BLACK_LIST: [&str; 69] = [ +pub const BLACK_LIST: [&str; 66] = [ "Expression", "ObjectPropertyKind", "TemplateElement", @@ -41,7 +41,6 @@ pub const BLACK_LIST: [&str; 69] = [ "TSEnumMemberName", "TSLiteral", "TSType", - "TSConditionalType", "TSTypeOperator", "TSArrayType", "TSTupleType", @@ -52,7 +51,6 @@ pub const BLACK_LIST: [&str; 69] = [ "TSSignature", "TSIndexSignature", "TSCallSignatureDeclaration", - "TSConstructSignatureDeclaration", "TSIndexSignatureName", "TSTypePredicate", "TSTypePredicateName", @@ -64,7 +62,6 @@ pub const BLACK_LIST: [&str; 69] = [ "TSImportAttributeName", "TSFunctionType", "TSConstructorType", - "TSMappedType", "TSModuleReference", "TSExportAssignment", "TSNamespaceExportDeclaration", diff --git a/tasks/coverage/parser_typescript.snap b/tasks/coverage/parser_typescript.snap index b062690c231a8..5680538155014 100644 --- a/tasks/coverage/parser_typescript.snap +++ b/tasks/coverage/parser_typescript.snap @@ -2,8 +2,8 @@ commit: d8086f14 parser_typescript Summary: AST Parsed : 6444/6456 (99.81%) -Positive Passed: 6408/6456 (99.26%) -Negative Passed: 1165/5653 (20.61%) +Positive Passed: 6421/6456 (99.46%) +Negative Passed: 1160/5653 (20.52%) Expect Syntax Error: "compiler/ClassDeclaration10.ts" Expect Syntax Error: "compiler/ClassDeclaration11.ts" Expect Syntax Error: "compiler/ClassDeclaration13.ts" @@ -1107,6 +1107,7 @@ Expect Syntax Error: "compiler/inferenceExactOptionalProperties2.ts" Expect Syntax Error: "compiler/inferenceFromIncompleteSource.ts" Expect Syntax Error: "compiler/inferenceShouldFailOnEvolvingArrays.ts" Expect Syntax Error: "compiler/inferentialTypingWithObjectLiteralProperties.ts" +Expect Syntax Error: "compiler/infiniteConstraints.ts" Expect Syntax Error: "compiler/infinitelyExpandingTypes1.ts" Expect Syntax Error: "compiler/inheritFromGenericTypeParameter.ts" Expect Syntax Error: "compiler/inheritSameNamePrivatePropertiesFromDifferentOrigins.ts" @@ -1260,6 +1261,7 @@ Expect Syntax Error: "compiler/jsdocClassMissingTypeArguments.ts" Expect Syntax Error: "compiler/jsdocFunctionTypeFalsePositive.ts" Expect Syntax Error: "compiler/jsdocIllegalTags.ts" Expect Syntax Error: "compiler/jsdocImportTypeNodeNamespace.ts" +Expect Syntax Error: "compiler/jsdocInTypeScript.ts" Expect Syntax Error: "compiler/jsdocParamTagInvalid.ts" Expect Syntax Error: "compiler/jsdocParameterParsingInfiniteLoop.ts" Expect Syntax Error: "compiler/jsdocPropertyTagInvalid.ts" @@ -1529,6 +1531,7 @@ Expect Syntax Error: "compiler/noSymbolForMergeCrash.ts" Expect Syntax Error: "compiler/noTypeArgumentOnReturnType1.ts" Expect Syntax Error: "compiler/noUncheckedIndexedAccessCompoundAssignments.ts" Expect Syntax Error: "compiler/noUnusedLocals_destructuringAssignment.ts" +Expect Syntax Error: "compiler/noUnusedLocals_selfReference.ts" Expect Syntax Error: "compiler/noUnusedLocals_selfReference_skipsBlockLocations.ts" Expect Syntax Error: "compiler/noUnusedLocals_typeParameterMergedWithParameter.ts" Expect Syntax Error: "compiler/noUnusedLocals_writeOnly.ts" @@ -2223,6 +2226,7 @@ Expect Syntax Error: "compiler/unusedTypeParameters3.ts" Expect Syntax Error: "compiler/unusedTypeParameters4.ts" Expect Syntax Error: "compiler/unusedTypeParameters5.ts" Expect Syntax Error: "compiler/unusedTypeParameters8.ts" +Expect Syntax Error: "compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts" Expect Syntax Error: "compiler/unusedTypeParametersWithUnderscore.ts" Expect Syntax Error: "compiler/unusedTypeParameters_infer.ts" Expect Syntax Error: "compiler/unusedTypeParameters_templateTag.ts" @@ -4168,6 +4172,7 @@ Expect Syntax Error: "conformance/types/literal/templateLiteralTypes3.ts" Expect Syntax Error: "conformance/types/literal/templateLiteralTypes4.ts" Expect Syntax Error: "conformance/types/literal/templateLiteralTypes5.ts" Expect Syntax Error: "conformance/types/literal/templateLiteralTypes7.ts" +Expect Syntax Error: "conformance/types/literal/templateLiteralTypesPatterns.ts" Expect Syntax Error: "conformance/types/literal/templateLiteralTypesPatternsPrefixSuffixAssignability.ts" Expect Syntax Error: "conformance/types/mapped/mappedTypeAsClauseRelationships.ts" Expect Syntax Error: "conformance/types/mapped/mappedTypeAsClauses.ts" @@ -4502,22 +4507,6 @@ Expect to Parse: "compiler/arrayFromAsync.ts" · ╰── `(` expected 23 │ arr.push(v); ╰──── -Expect to Parse: "compiler/awaitedTypeJQuery.ts" - - × Identifier `T` has already been declared - ╭─[compiler/awaitedTypeJQuery.ts:3:20] - 2 │ - 3 │ interface Thenable extends PromiseLike { } - · ┬ - · ╰── `T` has already been declared here - 4 │ - ╰──── - ╭─[compiler/awaitedTypeJQuery.ts:125:6] - 124 │ - 125 │ type T = Awaited>; // string - · ┬ - · ╰── It can not be redeclared here - ╰──── Expect to Parse: "compiler/bom-utf16be.ts" × Invalid Character `￾` @@ -4525,97 +4514,6 @@ Expect to Parse: "compiler/bom-utf16be.ts" 1 │ ￾瘀愀爀 砀㴀㄀ 㬀ഀ਀ · ─ ╰──── -Expect to Parse: "compiler/deferredConditionalTypes.ts" - - × Identifier `A` has already been declared - ╭─[compiler/deferredConditionalTypes.ts:1:6] - 1 │ type A = { x: T } extends { x: 0 } ? 1 : 0; - · ┬ - · ╰── `A` has already been declared here - 2 │ - ╰──── - ╭─[compiler/deferredConditionalTypes.ts:15:9] - 14 │ - 15 │ type Or = [A, B] extends [false, false] ? false : true; - · ┬ - · ╰── It can not be redeclared here - 16 │ type And = [A, B] extends [true, true] ? true : false; - ╰──── - - × Identifier `A` has already been declared - ╭─[compiler/deferredConditionalTypes.ts:1:6] - 1 │ type A = { x: T } extends { x: 0 } ? 1 : 0; - · ┬ - · ╰── `A` has already been declared here - 2 │ - ╰──── - ╭─[compiler/deferredConditionalTypes.ts:16:10] - 15 │ type Or = [A, B] extends [false, false] ? false : true; - 16 │ type And = [A, B] extends [true, true] ? true : false; - · ┬ - · ╰── It can not be redeclared here - 17 │ type Not = T extends true ? false : true; - ╰──── - - × Identifier `A` has already been declared - ╭─[compiler/deferredConditionalTypes.ts:1:6] - 1 │ type A = { x: T } extends { x: 0 } ? 1 : 0; - · ┬ - · ╰── `A` has already been declared here - 2 │ - ╰──── - ╭─[compiler/deferredConditionalTypes.ts:18:14] - 17 │ type Not = T extends true ? false : true; - 18 │ type Extends = A extends B ? true : false; - · ┬ - · ╰── It can not be redeclared here - 19 │ - ╰──── - - × Identifier `A` has already been declared - ╭─[compiler/deferredConditionalTypes.ts:1:6] - 1 │ type A = { x: T } extends { x: 0 } ? 1 : 0; - · ┬ - · ╰── `A` has already been declared here - 2 │ - ╰──── - ╭─[compiler/deferredConditionalTypes.ts:31:13] - 30 │ - 31 │ type Equals = [A, B] extends [B, A] ? true : false; - · ┬ - · ╰── It can not be redeclared here - 32 │ - ╰──── - - × Identifier `A` has already been declared - ╭─[compiler/deferredConditionalTypes.ts:1:6] - 1 │ type A = { x: T } extends { x: 0 } ? 1 : 0; - · ┬ - · ╰── `A` has already been declared here - 2 │ - ╰──── - ╭─[compiler/deferredConditionalTypes.ts:46:13] - 45 │ - 46 │ type AndBit = [A, B] extends [1, 1] ? 1 : 0; - · ┬ - · ╰── It can not be redeclared here - 47 │ - ╰──── - - × Identifier `A` has already been declared - ╭─[compiler/deferredConditionalTypes.ts:1:6] - 1 │ type A = { x: T } extends { x: 0 } ? 1 : 0; - · ┬ - · ╰── `A` has already been declared here - 2 │ - ╰──── - ╭─[compiler/deferredConditionalTypes.ts:48:14] - 47 │ - 48 │ type TestBit = AndBit< - · ┬ - · ╰── It can not be redeclared here - 49 │ A extends 1 ? 0 : 1, - ╰──── Expect to Parse: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts" × 'with' statements are not allowed @@ -4625,89 +4523,6 @@ Expect to Parse: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts" · ──── 24 │ const enum H {} ╰──── -Expect to Parse: "compiler/eventEmitterPatternWithRecordOfFunction.ts" - - × Identifier `A` has already been declared - ╭─[compiler/eventEmitterPatternWithRecordOfFunction.ts:1:11] - 1 │ interface A { - · ┬ - · ╰── `A` has already been declared here - 2 │ emit(event: string, ...args: any[]): boolean; - ╰──── - ╭─[compiler/eventEmitterPatternWithRecordOfFunction.ts:5:42] - 4 │ - 5 │ type Args = F extends (...args: infer A) => void ? A : never; - · ┬ - · ╰── It can not be redeclared here - 6 │ - ╰──── -Expect to Parse: "compiler/inferenceErasedSignatures.ts" - - × Identifier `T1` has already been declared - ╭─[compiler/inferenceErasedSignatures.ts:29:20] - 28 │ - 29 │ interface BaseType { - · ─┬ - · ╰── `T1` has already been declared here - 30 │ set(key: K, value: this[K]): this[K]; - 31 │ useT1(c: T1): void; - 32 │ useT2(r?: T2): void; - 33 │ unrelatedButSomehowRelevant(r?: any): void; - 34 │ } - 35 │ - 36 │ interface InheritedType extends BaseType { - 37 │ // This declaration shouldn't do anything... - 38 │ useT1(_: number): void - 39 │ } - 40 │ - 41 │ // Structural expansion of InheritedType - 42 │ interface StructuralVersion { - 43 │ set(key: K, value: this[K]): this[K]; - 44 │ useT1(c: number): void; - 45 │ useT2(r?: boolean): void; - 46 │ unrelatedButSomehowRelevant(r?: any): void; - 47 │ } - 48 │ - 49 │ type GetT1 = T extends BaseType ? U : never; - 50 │ - 51 │ type T1 = GetT1; // number - · ─┬ - · ╰── It can not be redeclared here - 52 │ type T2 = GetT1; // number - ╰──── - - × Identifier `T2` has already been declared - ╭─[compiler/inferenceErasedSignatures.ts:29:24] - 28 │ - 29 │ interface BaseType { - · ─┬ - · ╰── `T2` has already been declared here - 30 │ set(key: K, value: this[K]): this[K]; - 31 │ useT1(c: T1): void; - 32 │ useT2(r?: T2): void; - 33 │ unrelatedButSomehowRelevant(r?: any): void; - 34 │ } - 35 │ - 36 │ interface InheritedType extends BaseType { - 37 │ // This declaration shouldn't do anything... - 38 │ useT1(_: number): void - 39 │ } - 40 │ - 41 │ // Structural expansion of InheritedType - 42 │ interface StructuralVersion { - 43 │ set(key: K, value: this[K]): this[K]; - 44 │ useT1(c: number): void; - 45 │ useT2(r?: boolean): void; - 46 │ unrelatedButSomehowRelevant(r?: any): void; - 47 │ } - 48 │ - 49 │ type GetT1 = T extends BaseType ? U : never; - 50 │ - 51 │ type T1 = GetT1; // number - 52 │ type T2 = GetT1; // number - · ─┬ - · ╰── It can not be redeclared here - ╰──── Expect to Parse: "compiler/jsFileClassSelfReferencedProperty.ts" × Cannot use export statement outside a module @@ -4775,67 +4590,6 @@ Expect to Parse: "compiler/moduleResolution_packageJson_yesAtPackageRoot_fakeSco · ▲ ╰──── help: Try insert a semicolon here -Expect to Parse: "compiler/nondistributiveConditionalTypeInfer.ts" - - × Identifier `R` has already been declared - ╭─[compiler/nondistributiveConditionalTypeInfer.ts:1:43] - 1 │ type _R = [T] extends [{ _R: (_: infer R) => void }] ? R : never; - · ┬ - · ╰── `R` has already been declared here - 2 │ type _E = [T] extends [{ _E: () => infer E }] ? E : never; - ╰──── - ╭─[compiler/nondistributiveConditionalTypeInfer.ts:11:6] - 10 │ - 11 │ type R = _R>; - · ┬ - · ╰── It can not be redeclared here - 12 │ type E = _E>; - ╰──── - - × Identifier `E` has already been declared - ╭─[compiler/nondistributiveConditionalTypeInfer.ts:2:45] - 1 │ type _R = [T] extends [{ _R: (_: infer R) => void }] ? R : never; - 2 │ type _E = [T] extends [{ _E: () => infer E }] ? E : never; - · ┬ - · ╰── `E` has already been declared here - 3 │ type _A = [T] extends [{ _A: () => infer A }] ? A : never; - ╰──── - ╭─[compiler/nondistributiveConditionalTypeInfer.ts:12:6] - 11 │ type R = _R>; - 12 │ type E = _E>; - · ┬ - · ╰── It can not be redeclared here - 13 │ type A = _A>; - ╰──── - - × Identifier `A` has already been declared - ╭─[compiler/nondistributiveConditionalTypeInfer.ts:3:45] - 2 │ type _E = [T] extends [{ _E: () => infer E }] ? E : never; - 3 │ type _A = [T] extends [{ _A: () => infer A }] ? A : never; - · ┬ - · ╰── `A` has already been declared here - 4 │ - ╰──── - ╭─[compiler/nondistributiveConditionalTypeInfer.ts:13:6] - 12 │ type E = _E>; - 13 │ type A = _A>; - · ┬ - · ╰── It can not be redeclared here - ╰──── -Expect to Parse: "compiler/relatedViaDiscriminatedTypeNoError2.ts" - - × Identifier `T` has already been declared - ╭─[compiler/relatedViaDiscriminatedTypeNoError2.ts:3:14] - 2 │ type AOrBObj = { name: "A" | "B" }; - 3 │ type Generic = T; - · ┬ - · ╰── `T` has already been declared here - 4 │ - 5 │ type T = Generic; - · ┬ - · ╰── It can not be redeclared here - 6 │ - ╰──── Expect to Parse: "compiler/sourceMapValidationDecorators.ts" × Unexpected token @@ -4853,30 +4607,6 @@ Expect to Parse: "compiler/thisInObjectJs.ts" · ────── 2 │ let obj = { ╰──── -Expect to Parse: "compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts" - - × Identifier `T` has already been declared - ╭─[compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts:3:6] - 2 │ - 3 │ type T = { }; - · ┬ ┬ - · │ ╰── It can not be redeclared here - · ╰── `T` has already been declared here - 4 │ - ╰──── - - × Identifier `T` has already been declared - ╭─[compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts:3:6] - 2 │ - 3 │ type T = { }; - · ┬ - · ╰── `T` has already been declared here - 4 │ - 5 │ interface I { }; - · ┬ - · ╰── It can not be redeclared here - 6 │ - ╰──── Expect to Parse: "compiler/usedImportNotElidedInJs.ts" × Cannot use import statement outside a module @@ -5052,23 +4782,6 @@ Expect to Parse: "conformance/esDecorators/esDecorators-decoratorExpression.1.ts 14 │ ╰──── help: Try insert a semicolon here -Expect to Parse: "conformance/interfaces/declarationMerging/twoMergedInterfacesWithDifferingOverloads.ts" - - × Identifier `A` has already been declared - ╭─[conformance/interfaces/declarationMerging/twoMergedInterfacesWithDifferingOverloads.ts:3:11] - 2 │ - 3 │ interface A { - · ┬ - · ╰── `A` has already been declared here - 4 │ foo(x: number): number; - ╰──── - ╭─[conformance/interfaces/declarationMerging/twoMergedInterfacesWithDifferingOverloads.ts:42:9] - 41 │ b: U; - 42 │ foo(x: A, y: A): U; - · ┬ - · ╰── It can not be redeclared here - 43 │ } - ╰──── Expect to Parse: "conformance/jsdoc/constructorTagOnClassConstructor.ts" × Cannot use export statement outside a module @@ -5179,188 +4892,6 @@ Expect to Parse: "conformance/salsa/typeFromPropertyAssignmentWithExport.ts" · ────── 4 │ ╰──── -Expect to Parse: "conformance/types/intersection/intersectionMemberOfUnionNarrowsCorrectly.ts" - - × Identifier `U` has already been declared - ╭─[conformance/types/intersection/intersectionMemberOfUnionNarrowsCorrectly.ts:1:13] - 1 │ export type U = { kind?: 'A', a: string } | { kind?: 'B' } & { b: string }; - · ┬ - · ╰── `U` has already been declared here - 2 │ type Ex = T extends U ? T : never; - · ┬ - · ╰── It can not be redeclared here - 3 │ declare let x: Ex - ╰──── -Expect to Parse: "conformance/types/mapped/mappedTypeModifiers.ts" - - × Identifier `T` has already been declared - ╭─[conformance/types/mapped/mappedTypeModifiers.ts:1:6] - 1 │ type T = { a: number, b: string }; - · ┬ - · ╰── `T` has already been declared here - 2 │ type TP = { a?: number, b?: string }; - ╰──── - ╭─[conformance/types/mapped/mappedTypeModifiers.ts:38:15] - 37 │ - 38 │ type Boxified = { [P in keyof T]: { x: T[P] } }; - · ┬ - · ╰── It can not be redeclared here - 39 │ - ╰──── -Expect to Parse: "conformance/types/mapped/mappedTypesGenericTuples.ts" - - × Identifier `K` has already been declared - ╭─[conformance/types/mapped/mappedTypesGenericTuples.ts:3:6] - 2 │ - 3 │ type K = { [P in keyof T]: P }; - · ┬ - · ╰── `K` has already been declared here - 4 │ type M = { [P in keyof T]: T[P] }; - ╰──── - ╭─[conformance/types/mapped/mappedTypesGenericTuples.ts:27:37] - 26 │ - 27 │ type Keys = { [K in keyof O]: K }; - · ┬ - · ╰── It can not be redeclared here - 28 │ - ╰──── -Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts" - - × Identifier `A` has already been declared - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:3:7] - 2 │ - 3 │ class A { - · ┬ - · ╰── `A` has already been declared here - 4 │ foo(x: T): T { return null; } - ╰──── - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:15:22] - 14 │ - 15 │ interface I { - · ┬ - · ╰── It can not be redeclared here - 16 │ foo(x: X): X; - ╰──── - - × Identifier `A` has already been declared - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:3:7] - 2 │ - 3 │ class A { - · ┬ - · ╰── `A` has already been declared here - 4 │ foo(x: T): T { return null; } - ╰──── - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:20:15] - 19 │ interface I2 { - 20 │ foo(x: Y): Y; - · ┬ - · ╰── It can not be redeclared here - 21 │ } - ╰──── - - × Identifier `B` has already been declared - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:7:7] - 6 │ - 7 │ class B { - · ┬ - · ╰── `B` has already been declared here - 8 │ foo(x: U): U { return null; } - ╰──── - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:20:18] - 19 │ interface I2 { - 20 │ foo(x: Y): Y; - · ┬ - · ╰── It can not be redeclared here - 21 │ } - ╰──── - - × Identifier `A` has already been declared - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:3:7] - 2 │ - 3 │ class A { - · ┬ - · ╰── `A` has already been declared here - 4 │ foo(x: T): T { return null; } - ╰──── - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:23:17] - 22 │ - 23 │ var a: { foo(x: Z): Z } - · ┬ - · ╰── It can not be redeclared here - 24 │ var b = { foo(x: A) { return x; } }; - ╰──── - - × Identifier `B` has already been declared - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:7:7] - 6 │ - 7 │ class B { - · ┬ - · ╰── `B` has already been declared here - 8 │ foo(x: U): U { return null; } - ╰──── - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:23:20] - 22 │ - 23 │ var a: { foo(x: Z): Z } - · ┬ - · ╰── It can not be redeclared here - 24 │ var b = { foo(x: A) { return x; } }; - ╰──── - - × Identifier `C` has already been declared - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.ts:11:7] - 10 │ - 11 │ class C { - · ┬ - · ╰── `C` has already been declared here - 12 │ foo(x: V): V { return null; } - 13 │ } - 14 │ - 15 │ interface I { - 16 │ foo(x: X): X; - 17 │ } - 18 │ - 19 │ interface I2 { - 20 │ foo(x: Y): Y; - 21 │ } - 22 │ - 23 │ var a: { foo(x: Z): Z } - · ┬ - · ╰── It can not be redeclared here - 24 │ var b = { foo(x: A) { return x; } }; - ╰──── -Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.ts" - - × Identifier `B` has already been declared - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.ts:3:7] - 2 │ - 3 │ class B { - · ┬ - · ╰── `B` has already been declared here - 4 │ constructor(x: U) { return null; } - ╰──── - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.ts:16:19] - 15 │ interface I2 { - 16 │ new (x: Y): C; - · ┬ - · ╰── It can not be redeclared here - 17 │ } - ╰──── - - × Identifier `B` has already been declared - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.ts:3:7] - 2 │ - 3 │ class B { - · ┬ - · ╰── `B` has already been declared here - 4 │ constructor(x: U) { return null; } - ╰──── - ╭─[conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.ts:19:21] - 18 │ - 19 │ var a: { new (x: Z): C; } - · ┬ - · ╰── It can not be redeclared here - 20 │ var b = { new(x: A) { return x; } }; - ╰──── × A parameter property is only allowed in a constructor implementation. ╭─[compiler/ArrowFunctionExpression1.ts:1:10] @@ -8534,22 +8065,6 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje 3 │ } ╰──── - × Identifier `T2` has already been declared - ╭─[compiler/infiniteConstraints.ts:4:6] - 3 │ type T1], { val: string }>["val"] }> = B; - 4 │ type T2]["val"] }> = B; - · ─┬ - · ╰── `T2` has already been declared here - 5 │ - ╰──── - ╭─[compiler/infiniteConstraints.ts:42:61] - 41 │ T extends unknown ? - 42 │ ((arg: Elm, ...rest: T) => void) extends ((...args: infer T2) => void) ? T2 : - · ─┬ - · ╰── It can not be redeclared here - 43 │ never : - ╰──── - × Expected a semicolon or an implicit semicolon after a statement, but found none ╭─[compiler/innerModExport1.ts:5:11] 4 │ var non_export_var: number; @@ -8912,22 +8427,6 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje · ────── ╰──── - × Identifier `T` has already been declared - ╭─[compiler/jsdocInTypeScript.ts:5:7] - 4 │ - 5 │ class T { - · ┬ - · ╰── `T` has already been declared here - 6 │ prop: number; - ╰──── - ╭─[compiler/jsdocInTypeScript.ts:34:13] - 33 │ /** @template T */ - 34 │ interface I {} - · ┬ - · ╰── It can not be redeclared here - 35 │ - ╰──── - × Cannot use export statement outside a module ╭─[compiler/jsdocTypedefNoCrash2.ts:1:1] 1 │ export type foo = 5; @@ -9956,23 +9455,6 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje 8 │ ╰──── - × Identifier `T` has already been declared - ╭─[compiler/noUnusedLocals_selfReference.ts:14:6] - 13 │ interface I { x: I }; - 14 │ type T = { x: T }; - · ┬ - · ╰── `T` has already been declared here - 15 │ namespace N { N; } - 16 │ - 17 │ // Avoid a false positive. - 18 │ // Previously `T` was considered unused due to merging with the property, - 19 │ // back when all non-blocks were checked for recursion. - 20 │ export interface A { T: T } - · ┬ - · ╰── It can not be redeclared here - 21 │ - ╰──── - × Identifier `m1` has already been declared ╭─[compiler/nonMergedDeclarationsAndOverloads.ts:2:5] 1 │ class A { @@ -12484,29 +11966,6 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje 84 │ z(x); ╰──── - × Identifier `T` has already been declared - ╭─[compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts:3:6] - 2 │ - 3 │ type T = { }; - · ┬ ┬ - · │ ╰── It can not be redeclared here - · ╰── `T` has already been declared here - 4 │ - ╰──── - - × Identifier `T` has already been declared - ╭─[compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts:3:6] - 2 │ - 3 │ type T = { }; - · ┬ - · ╰── `T` has already been declared here - 4 │ - 5 │ interface I { }; - · ┬ - · ╰── It can not be redeclared here - 6 │ - ╰──── - × Expected a semicolon or an implicit semicolon after a statement, but found none ╭─[compiler/validRegexp.ts:1:23] 1 │ var x = / [a - z /]$ / i; @@ -22392,69 +21851,6 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje 2 │ const a = import ╰──── - × Identifier `A` has already been declared - ╭─[conformance/types/literal/templateLiteralTypesPatterns.ts:158:6] - 157 │ // validates concatenation of patterns - 158 │ type A = `${number}`; - · ┬ - · ╰── `A` has already been declared here - 159 │ type B = `${A} ${A}`; - 160 │ const exampleBad: B = "anything"; // fails - 161 │ const exampleGood: B = "1 2"; // ok - 162 │ - 163 │ // Repro from #41161 - 164 │ - 165 │ var aa: '0'; - 166 │ var aa: '0' & `${number}`; - 167 │ - 168 │ // Remove string literals from unions with matching template literals - 169 │ - 170 │ let t1: `foo${string}` | 'foo1' | '1foo'; // `foo${string}` | '1foo' - 171 │ let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; // `foo${string}` | '1foo' | 'xfoo' - 172 │ let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; // `foo${string}` | xfoo' | `${number}foo` - 173 │ - 174 │ var bb: `${number}`; - 175 │ var bb: `${number}` | '0'; - 176 │ - 177 │ // Normalize `${string}` to just string - 178 │ - 179 │ type T2S = `${A}${B}`; - · ┬ - · ╰── It can not be redeclared here - 180 │ - ╰──── - - × Identifier `B` has already been declared - ╭─[conformance/types/literal/templateLiteralTypesPatterns.ts:159:6] - 158 │ type A = `${number}`; - 159 │ type B = `${A} ${A}`; - · ┬ - · ╰── `B` has already been declared here - 160 │ const exampleBad: B = "anything"; // fails - 161 │ const exampleGood: B = "1 2"; // ok - 162 │ - 163 │ // Repro from #41161 - 164 │ - 165 │ var aa: '0'; - 166 │ var aa: '0' & `${number}`; - 167 │ - 168 │ // Remove string literals from unions with matching template literals - 169 │ - 170 │ let t1: `foo${string}` | 'foo1' | '1foo'; // `foo${string}` | '1foo' - 171 │ let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; // `foo${string}` | '1foo' | 'xfoo' - 172 │ let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; // `foo${string}` | xfoo' | `${number}foo` - 173 │ - 174 │ var bb: `${number}`; - 175 │ var bb: `${number}` | '0'; - 176 │ - 177 │ // Normalize `${string}` to just string - 178 │ - 179 │ type T2S = `${A}${B}`; - · ┬ - · ╰── It can not be redeclared here - 180 │ - ╰──── - × Identifier `T` has already been declared ╭─[conformance/types/localTypes/localTypes4.ts:18:16] 17 │ // Type parameters and top-level local types are in same declaration space