diff --git a/crates/oxc_linter/src/rules/eslint/no_global_assign.rs b/crates/oxc_linter/src/rules/eslint/no_global_assign.rs index 0a766e2afac2d..8e036f68db8ee 100644 --- a/crates/oxc_linter/src/rules/eslint/no_global_assign.rs +++ b/crates/oxc_linter/src/rules/eslint/no_global_assign.rs @@ -65,7 +65,7 @@ impl Rule for NoGlobalAssign { fn run_once(&self, ctx: &LintContext) { let symbol_table = ctx.symbols(); for reference_id_list in ctx.scopes().root_unresolved_references().values() { - for &reference_id in reference_id_list { + for &(reference_id, _) in reference_id_list { let reference = symbol_table.get_reference(reference_id); if reference.is_write() { let name = reference.name(); diff --git a/crates/oxc_linter/src/rules/eslint/no_undef.rs b/crates/oxc_linter/src/rules/eslint/no_undef.rs index 3bf4e78e2f893..1fd9a4cc3b12a 100644 --- a/crates/oxc_linter/src/rules/eslint/no_undef.rs +++ b/crates/oxc_linter/src/rules/eslint/no_undef.rs @@ -50,7 +50,7 @@ impl Rule for NoUndef { let symbol_table = ctx.symbols(); for reference_id_list in ctx.scopes().root_unresolved_references().values() { - for &reference_id in reference_id_list { + for &(reference_id, _) in reference_id_list { let reference = symbol_table.get_reference(reference_id); let name = reference.name(); diff --git a/crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs b/crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs index af0941d7dbb1d..44b16061fd191 100644 --- a/crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs +++ b/crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs @@ -90,18 +90,22 @@ impl Rule for NoConfusingSetTimeout { let mut jest_reference_id_list: Vec<(ReferenceId, Span)> = vec![]; let mut seen_jest_set_timeout = false; - for reference_ids in scopes.root_unresolved_references().values() { - collect_jest_reference_id(reference_ids, &mut jest_reference_id_list, ctx); + for reference_ids_and_meanings in scopes.root_unresolved_references().values() { + let reference_ids: Vec<_> = + reference_ids_and_meanings.iter().map(|(reference_id, _)| *reference_id).collect(); + collect_jest_reference_id(&reference_ids, &mut jest_reference_id_list, ctx); } for reference_ids in &symbol_table.resolved_references { collect_jest_reference_id(reference_ids, &mut jest_reference_id_list, ctx); } - for reference_id_list in scopes.root_unresolved_references().values() { + for reference_ids_and_meanings in scopes.root_unresolved_references().values() { + let reference_ids: Vec<_> = + reference_ids_and_meanings.iter().map(|(reference_id, _)| *reference_id).collect(); handle_jest_set_time_out( ctx, - reference_id_list, + &reference_ids, &jest_reference_id_list, &mut seen_jest_set_timeout, &id_to_jest_node_map, diff --git a/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs b/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs index 3ed3ff259c053..e0f73bf31d068 100644 --- a/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs +++ b/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs @@ -53,7 +53,7 @@ impl Rule for NoJasmineGlobals { .filter(|(key, _)| NON_JASMINE_PROPERTY_NAMES.contains(&key.as_str())); for (name, reference_ids) in jasmine_references { - for &reference_id in reference_ids { + for &(reference_id, _) in reference_ids { let reference = symbol_table.get_reference(reference_id); if let Some((error, help)) = get_non_jasmine_property_messages(name) { ctx.diagnostic(no_jasmine_globals_diagnostic(error, help, reference.span())); diff --git a/crates/oxc_linter/src/rules/jest/no_mocks_import.rs b/crates/oxc_linter/src/rules/jest/no_mocks_import.rs index ecdbc2a2bba02..a27e4fb725020 100644 --- a/crates/oxc_linter/src/rules/jest/no_mocks_import.rs +++ b/crates/oxc_linter/src/rules/jest/no_mocks_import.rs @@ -48,7 +48,7 @@ impl Rule for NoMocksImport { return; }; - for reference_id in require_reference_ids { + for (reference_id, _) in require_reference_ids { let reference = ctx.symbols().get_reference(*reference_id); let Some(parent) = ctx.nodes().parent_node(reference.node_id()) else { return; diff --git a/crates/oxc_linter/src/utils/jest.rs b/crates/oxc_linter/src/utils/jest.rs index aebcf7cc471f8..a4b48f17a6d29 100644 --- a/crates/oxc_linter/src/utils/jest.rs +++ b/crates/oxc_linter/src/utils/jest.rs @@ -241,8 +241,8 @@ fn collect_ids_referenced_to_global(ctx: &LintContext) -> Vec { .root_unresolved_references() .iter() .filter(|(name, _)| JEST_METHOD_NAMES.contains(name.as_str())) - .flat_map(|(_, reference_ids)| reference_ids.clone()) - .collect::>() + .flat_map(|(_, reference_ids)| reference_ids.iter().map(|(id, _)| *id)) + .collect() } /// join name of the expression. e.g. diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index df4e25c98ae2e..a17b6e67c695b 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -37,6 +37,14 @@ macro_rules! control_flow { }; } +// Imported symbols could be a type or value - we don't know without a checker. +// NOTE: `import type { Foo }` does not get recorded in SymbolFlags as a `Type`; +// adding support for that would make this work even better. +const MEANING_VALUELIKE: SymbolFlags = + SymbolFlags::Value.union(SymbolFlags::ImportBinding).union(SymbolFlags::Ambient); +const MEANING_TYPELIKE: SymbolFlags = SymbolFlags::Type.union(SymbolFlags::ImportBinding); +const MEANING_ANY: SymbolFlags = SymbolFlags::all(); + pub struct SemanticBuilder<'a> { pub source_text: &'a str, @@ -59,6 +67,8 @@ pub struct SemanticBuilder<'a> { // and when we reach a value declaration we set it // to value like pub namespace_stack: Vec, + /// symbol meaning criteria stack. For resolving symbol references. + meaning_stack: Vec, current_reference_flag: ReferenceFlag, // builders @@ -104,6 +114,7 @@ impl<'a> SemanticBuilder<'a> { current_scope_id, function_stack: vec![], namespace_stack: vec![], + meaning_stack: vec![MEANING_VALUELIKE], nodes: AstNodes::default(), scope, symbols: SymbolTable::default(), @@ -160,6 +171,9 @@ impl<'a> SemanticBuilder<'a> { program.scope_id.set(Some(scope_id)); } else { self.visit_program(program); + if self.check_syntax_error { + checker::check_last(&self); + } // Checking syntax error on module record requires scope information from the previous AST pass if self.check_syntax_error { @@ -234,6 +248,14 @@ impl<'a> SemanticBuilder<'a> { } } + pub fn current_meaning(&self) -> SymbolFlags { + let meaning = self.meaning_stack.last().copied(); + #[cfg(debug_assertions)] + return meaning.unwrap(); + #[cfg(not(debug_assertions))] + return meaning.unwrap_or(SymbolFlags::all()); + } + pub fn current_scope_flags(&self) -> ScopeFlags { self.scope.get_flags(self.current_scope_id) } @@ -307,6 +329,7 @@ impl<'a> SemanticBuilder<'a> { &mut self, reference: Reference, add_unresolved_reference: bool, + meaning: SymbolFlags, ) -> ReferenceId { let reference_name = reference.name().clone(); let reference_id = self.symbols.create_reference(reference); @@ -315,9 +338,10 @@ impl<'a> SemanticBuilder<'a> { self.current_scope_id, reference_name, reference_id, + meaning, ); } else { - self.resolve_reference_ids(reference_name.clone(), vec![reference_id]); + self.resolve_reference_ids(reference_name.clone(), vec![(reference_id, meaning)]); } reference_id } @@ -351,15 +375,29 @@ impl<'a> SemanticBuilder<'a> { } } - fn resolve_reference_ids(&mut self, name: CompactStr, reference_ids: Vec) { + fn resolve_reference_ids( + &mut self, + name: CompactStr, + reference_ids: Vec<(ReferenceId, SymbolFlags)>, + ) { let parent_scope_id = self.scope.get_parent_id(self.current_scope_id).unwrap_or(self.current_scope_id); if let Some(symbol_id) = self.scope.get_binding(self.current_scope_id, &name) { - for reference_id in &reference_ids { - self.symbols.references[*reference_id].set_symbol_id(symbol_id); + let symbol_flags = self.symbols.get_flag(symbol_id); + let mut unresolved: Vec<(ReferenceId, SymbolFlags)> = + Vec::with_capacity(reference_ids.len()); + for (reference_id, meaning) in reference_ids { + let reference = &mut self.symbols.references[reference_id]; + // if dbg!(symbol_flags).intersects(dbg!(meaning)) { + if symbol_flags.intersects(meaning) { + reference.set_symbol_id(symbol_id); + self.symbols.resolved_references[symbol_id].push(reference_id); + } else { + unresolved.push((reference_id, meaning)); + } } - self.symbols.resolved_references[symbol_id].extend(reference_ids); + self.scope.extend_unresolved_reference(parent_scope_id, name, unresolved); } else { self.scope.extend_unresolved_reference(parent_scope_id, name, reference_ids); } @@ -1628,6 +1666,16 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> { self.leave_node(kind); self.leave_scope(); } + + fn visit_ts_type_assertion(&mut self, expr: &TSTypeAssertion<'a>) { + let kind = AstKind::TSTypeAssertion(self.alloc(expr)); + self.enter_node(kind); + self.meaning_stack.push(MEANING_VALUELIKE); + self.visit_expression(&expr.expression); + self.meaning_stack.pop(); + self.visit_ts_type(&expr.type_annotation); + self.leave_node(kind); + } } impl<'a> SemanticBuilder<'a> { @@ -1648,11 +1696,14 @@ impl<'a> SemanticBuilder<'a> { }); /* cfg */ + // println!("enter - {}", kind.debug_name()); match kind { AstKind::ExportDefaultDeclaration(_) => { + self.meaning_stack.push(MEANING_ANY); self.current_symbol_flags |= SymbolFlags::Export; } AstKind::ExportNamedDeclaration(decl) => { + self.meaning_stack.push(MEANING_ANY); self.current_symbol_flags |= SymbolFlags::Export; if decl.export_kind.is_type() { self.current_reference_flag = ReferenceFlag::Type; @@ -1724,6 +1775,9 @@ impl<'a> SemanticBuilder<'a> { self.current_node_flags |= NodeFlags::Parameter; param.bind(self); } + AstKind::TSImportEqualsDeclaration(_) => { + self.meaning_stack.push(SymbolFlags::NameSpaceModule.union(SymbolFlags::Enum)); + } AstKind::TSModuleDeclaration(module_declaration) => { module_declaration.bind(self); let symbol_id = self @@ -1733,11 +1787,17 @@ impl<'a> SemanticBuilder<'a> { self.namespace_stack.push(*symbol_id.unwrap()); } AstKind::TSTypeAliasDeclaration(type_alias_declaration) => { + self.meaning_stack.push(MEANING_TYPELIKE); type_alias_declaration.bind(self); } AstKind::TSInterfaceDeclaration(interface_declaration) => { + self.meaning_stack.push(MEANING_TYPELIKE); interface_declaration.bind(self); } + AstKind::TSInterfaceHeritage(_) => { + // https://github.com/oxc-project/oxc/issues/3963 + self.meaning_stack.push(MEANING_TYPELIKE.union(SymbolFlags::NameSpaceModule)); + } AstKind::TSEnumDeclaration(enum_declaration) => { enum_declaration.bind(self); // TODO: const enum? @@ -1747,14 +1807,45 @@ impl<'a> SemanticBuilder<'a> { enum_member.bind(self); } AstKind::TSTypeParameter(type_parameter) => { + self.meaning_stack.push(MEANING_TYPELIKE); type_parameter.bind(self); } + AstKind::TSTypeReference(_) => { + self.meaning_stack.push(MEANING_TYPELIKE); + } + AstKind::TSTypeParameterInstantiation(_) => { + self.meaning_stack.push(MEANING_TYPELIKE); + } AstKind::ExportSpecifier(s) if s.export_kind.is_type() => { self.current_reference_flag = ReferenceFlag::Type; } AstKind::TSTypeName(_) => { + // note: do _not_ push a Type meaning onto the stack here. self.current_reference_flag = ReferenceFlag::Type; } + AstKind::TSTypeQuery(_) => { + // checks types of a value symbol (e.g. `typeof x`), so we're + // looking for a value even though its used as a type + self.meaning_stack.push(MEANING_VALUELIKE); + } + AstKind::TSTypeAnnotation(_) => { + self.meaning_stack.push(MEANING_TYPELIKE); + } + AstKind::TSPropertySignature(sig) => { + debug_assert!(self.current_meaning().is_type()); + // Constants and symbols can be used as types in property index + // signatures. We can't handle symbols b/c we don't a checker + // and can't perform type inference. + if sig.computed { + self.meaning_stack.push(MEANING_TYPELIKE.union(SymbolFlags::ConstVariable)); + } else { + self.meaning_stack.push(MEANING_TYPELIKE); + } + } + AstKind::TSQualifiedName(_) => { + // allow `const x: A.B`, where A is a module + self.meaning_stack.push(self.current_meaning().union(SymbolFlags::NameSpaceModule)); + } AstKind::IdentifierReference(ident) => { self.reference_identifier(ident); } @@ -1798,6 +1889,7 @@ impl<'a> SemanticBuilder<'a> { #[allow(clippy::single_match)] fn leave_kind(&mut self, kind: AstKind<'a>) { + // println!("leave - {}", kind.debug_name()); match kind { AstKind::Program(program) => { self.add_export_flag_to_export_identifiers(program); @@ -1807,9 +1899,11 @@ impl<'a> SemanticBuilder<'a> { self.class_table_builder.pop_class(); } AstKind::ExportDefaultDeclaration(_) => { + self.meaning_stack.pop(); self.current_symbol_flags -= SymbolFlags::Export; } AstKind::ExportNamedDeclaration(decl) => { + self.meaning_stack.pop(); self.current_symbol_flags -= SymbolFlags::Export; if decl.export_kind.is_type() { self.current_reference_flag -= ReferenceFlag::Type; @@ -1841,6 +1935,19 @@ impl<'a> SemanticBuilder<'a> { AstKind::TSTypeName(_) => { self.current_reference_flag -= ReferenceFlag::Type; } + AstKind::TSImportEqualsDeclaration(_) + | AstKind::TSTypeAliasDeclaration(_) + | AstKind::TSInterfaceDeclaration(_) + | AstKind::TSInterfaceHeritage(_) + | AstKind::TSQualifiedName(_) + | AstKind::TSPropertySignature(_) + | AstKind::TSTypeParameterInstantiation(_) + | AstKind::TSTypeReference(_) + | AstKind::TSTypeAnnotation(_) + | AstKind::TSTypeQuery(_) + | AstKind::TSTypeParameter(_) => { + self.meaning_stack.pop(); + } AstKind::UpdateExpression(_) => { if self.is_not_expression_statement_parent() { self.current_reference_flag -= ReferenceFlag::Read; @@ -1877,12 +1984,15 @@ impl<'a> SemanticBuilder<'a> { fn reference_identifier(&mut self, ident: &IdentifierReference) { let flag = self.resolve_reference_usages(); let name = ident.name.to_compact_str(); + // println!("declaring reference on {name} with meaning {:?}", self.current_meaning()); let reference = Reference::new(ident.span, name, self.current_node_id, flag); // `function foo({bar: identifier_reference}) {}` // ^^^^^^^^^^^^^^^^^^^^ Parameter initializer must be resolved immediately // to avoid binding to variables inside the scope let add_unresolved_reference = !self.current_node_flags.has_parameter(); - let reference_id = self.declare_reference(reference, add_unresolved_reference); + let reference_id = + self.declare_reference(reference, add_unresolved_reference, self.current_meaning()); + // self.declare_reference(reference, add_unresolved_reference, dbg!(self.current_meaning())); ident.reference_id.set(Some(reference_id)); } @@ -1911,7 +2021,7 @@ impl<'a> SemanticBuilder<'a> { self.current_node_id, ReferenceFlag::read(), ); - self.declare_reference(reference, true); + self.declare_reference(reference, true, SymbolFlags::Value); } fn is_not_expression_statement_parent(&self) -> bool { diff --git a/crates/oxc_semantic/src/checker/mod.rs b/crates/oxc_semantic/src/checker/mod.rs index eb36d98ddcdb9..93885d48c94ea 100644 --- a/crates/oxc_semantic/src/checker/mod.rs +++ b/crates/oxc_semantic/src/checker/mod.rs @@ -11,6 +11,9 @@ use typescript as ts; use crate::{builder::SemanticBuilder, AstNode}; +pub fn check_last(ctx: &SemanticBuilder<'_>) { + ts::check_symbol_resolution_failures(ctx); +} pub fn check<'a>(node: &AstNode<'a>, ctx: &SemanticBuilder<'a>) { let kind = node.kind(); diff --git a/crates/oxc_semantic/src/checker/typescript.rs b/crates/oxc_semantic/src/checker/typescript.rs index 263b043aa6864..0e2dc09322fa4 100644 --- a/crates/oxc_semantic/src/checker/typescript.rs +++ b/crates/oxc_semantic/src/checker/typescript.rs @@ -7,6 +7,51 @@ use rustc_hash::FxHashMap; use crate::{builder::SemanticBuilder, diagnostics::redeclaration}; +/// ts(2749) +fn value_used_as_type(span: Span, name: &str) -> OxcDiagnostic { + OxcDiagnostic::error(format!("'{name}' refers to a value, but is being used as a type here.")) + .with_label(span) + .with_help(format!("Did you mean 'typeof {name}'?")) +} + +/// ts(2693) +fn type_used_as_value(span: Span, name: &str) -> OxcDiagnostic { + OxcDiagnostic::error(format!("'{name}' refers to a type, but is being used as a value here.")) + .with_label(span) +} + +pub fn check_symbol_resolution_failures(ctx: &SemanticBuilder<'_>) { + for (scope_id, name, reference_ids) in ctx.scope.iter_unresolved_references() { + if let Some(symbol_id) = ctx.scope.find_binding(scope_id, name) { + let symbol_flags = ctx.symbols.get_flag(symbol_id); + for (reference_id, meaning) in reference_ids { + let reference = ctx.symbols.get_reference(*reference_id); + // note: is_value() does not imply !is_type() + // if meaning.is_value() && !symbol_flags.intersects(*meaning) { + if meaning.is_value() && symbol_flags.is_type() { + // checker.ts, checkAndReportErrorForUsingTypeAsValue + ctx.error(type_used_as_value(reference.span(), name)); + // } else if meaning.is_type() && !symbol_flags.intersects(*meaning) { + } else if meaning.is_type() && symbol_flags.is_value() { + // checker.ts, checkAndReportErrorForUsingValueAsType + ctx.error(value_used_as_type(reference.span(), name)); + } + // match (symbol_flags.is_type(), meaning.is_type()) { + // (true, false) => { + // // checker.ts, checkAndReportErrorForUsingValueAsType + // ctx.error(value_used_as_type(reference.span(), name)); + // } + // (false, true) => { + // // checker.ts, checkAndReportErrorForUsingTypeAsValue + // ctx.error(type_used_as_value(reference.span(), name)); + // } + // _ => {} + // } + } + } + } +} + fn empty_type_parameter_list(span0: Span) -> OxcDiagnostic { OxcDiagnostic::error("Type parameter list cannot be empty.").with_label(span0) } diff --git a/crates/oxc_semantic/src/scope.rs b/crates/oxc_semantic/src/scope.rs index 2698f90bef93d..1cc23388994f2 100644 --- a/crates/oxc_semantic/src/scope.rs +++ b/crates/oxc_semantic/src/scope.rs @@ -4,6 +4,7 @@ use indexmap::IndexMap; use oxc_index::IndexVec; use oxc_span::CompactStr; pub use oxc_syntax::scope::{ScopeFlags, ScopeId}; +use oxc_syntax::symbol::SymbolFlags; use rustc_hash::{FxHashMap, FxHasher}; use crate::{reference::ReferenceId, symbol::SymbolId, AstNodeId}; @@ -11,7 +12,7 @@ use crate::{reference::ReferenceId, symbol::SymbolId, AstNodeId}; type FxIndexMap = IndexMap>; type Bindings = FxIndexMap; -type UnresolvedReferences = FxHashMap>; +type UnresolvedReferences = FxHashMap>; /// Scope Tree /// @@ -141,8 +142,13 @@ impl ScopeTree { self.get_binding(self.root_scope_id(), name) } - pub fn add_root_unresolved_reference(&mut self, name: CompactStr, reference_id: ReferenceId) { - self.add_unresolved_reference(self.root_scope_id(), name, reference_id); + pub fn add_root_unresolved_reference( + &mut self, + name: CompactStr, + reference_id: ReferenceId, + meaning: SymbolFlags, + ) { + self.add_unresolved_reference(self.root_scope_id(), name, reference_id, meaning); } pub fn has_binding(&self, scope_id: ScopeId, name: &str) -> bool { @@ -210,15 +216,16 @@ impl ScopeTree { scope_id: ScopeId, name: CompactStr, reference_id: ReferenceId, + meaning: SymbolFlags, ) { - self.unresolved_references[scope_id].entry(name).or_default().push(reference_id); + self.unresolved_references[scope_id].entry(name).or_default().push((reference_id, meaning)); } pub(crate) fn extend_unresolved_reference( &mut self, scope_id: ScopeId, name: CompactStr, - reference_ids: Vec, + reference_ids: Vec<(ReferenceId, SymbolFlags)>, ) { self.unresolved_references[scope_id].entry(name).or_default().extend(reference_ids); } @@ -229,4 +236,17 @@ impl ScopeTree { ) -> &mut UnresolvedReferences { &mut self.unresolved_references[scope_id] } + + /// [`Iterator`] over `(scope the reference is in, the unresolved symbol name, reference ids)` + pub(crate) fn iter_unresolved_references( + &self, + ) -> impl Iterator + '_ { + self.unresolved_references.iter_enumerated().flat_map( + |(scope_id, unresolved_references)| { + unresolved_references + .iter() + .map(move |(name, reference_ids)| (scope_id, name, reference_ids.as_slice())) + }, + ) + } } diff --git a/crates/oxc_semantic/tests/integration/modules.rs b/crates/oxc_semantic/tests/integration/modules.rs index 1fed48fcff2b4..8b24229e52dc2 100644 --- a/crates/oxc_semantic/tests/integration/modules.rs +++ b/crates/oxc_semantic/tests/integration/modules.rs @@ -151,6 +151,29 @@ fn test_exported_enum() { test.has_some_symbol("B").is_not_exported().contains_flags(SymbolFlags::EnumMember).test(); } +#[test] +fn test_exported_variable() { + SemanticTester::ts( + " +const x = 1; +export { x } + ", + ) + .has_root_symbol("x") + .is_exported() + .test(); + + SemanticTester::ts( + " +const x = 1; +export { x as default } + ", + ) + .has_root_symbol("x") + .is_exported() + .test(); +} + // FIXME #[test] #[ignore] @@ -188,6 +211,18 @@ fn test_exports_in_namespace() { assert!(!semantic.module_record().exported_bindings.contains_key("bar")); } +#[test] +fn test_reexport() { + let test = SemanticTester::ts( + " + import { x } from './foo'; + export { x as y } + ", + ); + test.has_root_symbol("y").is_exported().test(); + test.has_root_symbol("x").is_not_exported().test(); +} + #[test] fn test_export_in_invalid_scope() { let test = SemanticTester::js( diff --git a/crates/oxc_semantic/tests/integration/symbols.rs b/crates/oxc_semantic/tests/integration/symbols.rs index 8b43297749a19..dadbb6f586136 100644 --- a/crates/oxc_semantic/tests/integration/symbols.rs +++ b/crates/oxc_semantic/tests/integration/symbols.rs @@ -98,6 +98,46 @@ fn test_types_simple() { .test(); } +#[test] +fn test_value_used_as_type() { + // Type annotations (or any type reference) do not resolve to value symbols + SemanticTester::ts( + " + const x = 1; + function foo(a: x) { } + ", + ) + .has_root_symbol("x") + .intersects_flags(SymbolFlags::Value) + .has_number_of_references(0) + .test(); + + // T is a value that gets shadowed by a type. When `T` is referenced within + // a value context, the root `const T` should be the symbol recoreded in the + // reference. + let tester = SemanticTester::ts( + " +const T = 1; +function foo(a: T) { + return a + T; +} +", + ); + + tester.has_root_symbol("T").has_number_of_reads(1).test(); + // TODO: type annotations not currently recorded as a type/read reference + // This `T` is the type parameter + // tester.has_symbol_at_offset(28).has_number_of_reads(1).test(); +} + +#[test] +fn test_type_used_as_value() { + SemanticTester::ts(" + type T = number; + let x = T; + ").expect_errors(true).has_some_symbol("T").has_number_of_reads(0).test(); +} + #[test] fn test_export_flag() { let tester = SemanticTester::js( @@ -114,3 +154,11 @@ 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 foo() { + SemanticTester::ts(" + type T = number; + type U = T; + ").has_root_symbol("T").test(); +} diff --git a/crates/oxc_semantic/tests/integration/util/mod.rs b/crates/oxc_semantic/tests/integration/util/mod.rs index 3cdd9f154a059..af48c873fd02a 100644 --- a/crates/oxc_semantic/tests/integration/util/mod.rs +++ b/crates/oxc_semantic/tests/integration/util/mod.rs @@ -189,6 +189,10 @@ impl<'a> SemanticTester<'a> { SymbolTester::new_at_root(self, self.build(), name) } + pub fn has_symbol_at_offset(&self, offset: u32) -> SymbolTester { + SymbolTester::new_at_offset(self, self.build(), offset) + } + /// 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..33f339cdbf072 100644 --- a/crates/oxc_semantic/tests/integration/util/symbol_tester.rs +++ b/crates/oxc_semantic/tests/integration/util/symbol_tester.rs @@ -66,6 +66,25 @@ impl<'a> SymbolTester<'a> { } } + pub fn new_at_offset(parent: &'a SemanticTester, semantic: Semantic<'a>, offset: u32) -> Self { + let msg = format!("Could not find symbol at offset {offset}"); + let symbol_id = semantic + .symbols() + .spans + .iter_enumerated() + .find(|(_, span)| span.contains_inclusive(offset)) + .map(|(symbol_id, _)| symbol_id) + .expect(&msg); + + let symbol_name = semantic.symbols().get_name(symbol_id).to_string(); + SymbolTester { + parent, + semantic: Rc::new(semantic), + target_symbol_name: symbol_name, + test_result: Ok(symbol_id), + } + } + /// Get inner resources without consuming `self` pub fn inner(&self) -> (Rc>, SymbolId) { (Rc::clone(&self.semantic), *self.test_result.as_ref().unwrap()) diff --git a/crates/oxc_span/src/span.rs b/crates/oxc_span/src/span.rs index f1e41c6ec3249..716a330ac1640 100644 --- a/crates/oxc_span/src/span.rs +++ b/crates/oxc_span/src/span.rs @@ -117,6 +117,25 @@ impl Span { self.start == self.end } + /// Checks if this [`Span`] contains an offset. + /// + /// The end index is considered included. + /// + /// # Example + /// ``` + /// use oxc_span::Span; + /// + /// let span = Span::new(1, 5); + /// assert!(span.contains_inclusive(1)); + /// assert!(span.contains_inclusive(5)); + /// + /// assert!(!span.contains_inclusive(0)); + /// assert!(!span.contains_inclusive(6)); + /// ``` + pub const fn contains_inclusive(&self, offset: u32) -> bool { + self.start <= offset && offset <= self.end + } + /// Returns `true` if `self` is not a real span. /// i.e. `SPAN` which is used for generated nodes which are not in source code. /// diff --git a/crates/oxc_syntax/src/reference.rs b/crates/oxc_syntax/src/reference.rs index 9738e3666d808..ebff5f5d6a7fd 100644 --- a/crates/oxc_syntax/src/reference.rs +++ b/crates/oxc_syntax/src/reference.rs @@ -27,8 +27,12 @@ bitflags! { const None = 0; const Read = 1 << 0; const Write = 1 << 1; - // Used in type definitions. + /// Used in type definitions. const Type = 1 << 2; + /// Used as a value. + const Value = 1 << 3; + /// Could be a [value](`ReferenceFlag::Value`) or a [type](`ReferenceFlag::Type`). + const Agnostic = Self::Type.bits() | Self::Value.bits(); const ReadWrite = Self::Read.bits() | Self::Write.bits(); } } @@ -73,6 +77,16 @@ impl ReferenceFlag { /// The identifier is used in a type definition. pub const fn is_type(&self) -> bool { - self.contains(Self::Type) + self.contains(Self::Type) && !self.contains(Self::Value) + } + + /// The identifier is used in a value-like context. + pub const fn is_value(&self) -> bool { + self.contains(Self::Value) && !self.contains(Self::Type) + } + + /// The identifier is used either as a value or a type. + pub const fn is_agnostic(&self) -> bool { + self.contains(Self::Agnostic) } } diff --git a/crates/oxc_syntax/src/symbol.rs b/crates/oxc_syntax/src/symbol.rs index 528aee31eb50a..1dad44c75acb0 100644 --- a/crates/oxc_syntax/src/symbol.rs +++ b/crates/oxc_syntax/src/symbol.rs @@ -77,8 +77,13 @@ impl SymbolFlags { self.intersects(Self::Variable) } + pub fn is_value(&self) -> bool { + self.intersects(Self::Value) + } + + /// Note: Some values can be types (e.g. classes, enums) pub fn is_type(&self) -> bool { - !self.intersects(Self::Value) + self.intersects(Self::Type) } pub fn is_const_variable(&self) -> bool { diff --git a/crates/oxc_traverse/src/context/scoping.rs b/crates/oxc_traverse/src/context/scoping.rs index fa3b93569f601..8a821bdb8f671 100644 --- a/crates/oxc_traverse/src/context/scoping.rs +++ b/crates/oxc_traverse/src/context/scoping.rs @@ -292,10 +292,11 @@ impl TraverseScoping { &mut self, name: CompactStr, flag: ReferenceFlag, + // TODO: meaning ) -> ReferenceId { let reference = Reference::new(SPAN, name.clone(), AstNodeId::dummy(), flag); let reference_id = self.symbols.create_reference(reference); - self.scopes.add_root_unresolved_reference(name, reference_id); + self.scopes.add_root_unresolved_reference(name, reference_id, SymbolFlags::all()); reference_id } @@ -356,9 +357,58 @@ impl TraverseScoping { name: CompactStr, flag: ReferenceFlag, ) -> ReferenceId { - let symbol_id = self.scopes.find_binding(self.current_scope_id, name.as_str()); + let meaning = if flag.intersects(ReferenceFlag::Type) { + SymbolFlags::Type + } else { + SymbolFlags::Value + }; + // let symbol_id = self.scopes.find_binding(self.current_scope_id, + // name.as_str()); + let symbol_id = self.resolve_binding(name.as_str(), Some(meaning)); self.create_reference(name, symbol_id, flag) } + + /// Attempt to resolve a symbol bound to a `name` by walking up the scope + /// tree, starting at the current scope id. + /// + /// See [`TraverseScoping::resolve_binding_from_scope`] for more details. + pub fn resolve_binding(&self, name: &str, meaning: Option) -> Option { + self.resolve_binding_from_scope(self.current_scope_id, name, meaning) + } + + /// Attempt to resolve a symbol bound to a `name` by walking up the scope + /// tree, starting at the desired `scope_id`. + /// + /// Meaning refers to the kind of symbol desired. It will almost always be + /// [`SymbolFlags::Value`] or [`SymbolFlags::Type`]. This prevents us from + /// binding variable declarations to type references, e.g. in + /// ```ts + /// const x = 1; + /// function foo(a: x) {} + /// ``` + /// + /// If you do not care about what kind of symbol is found, you can pass + /// [`None`]; this is equivalent to [`SymbolFlags::all()`]. + /// + /// This method returns [`None`] when no symbol is found with the desired + /// `name`, or if a symbol is found but it does not have the correct meaning. + pub fn resolve_binding_from_scope( + &self, + scope_id: ScopeId, + name: &str, + meaning: Option, + ) -> Option { + let meaning = meaning.unwrap_or(SymbolFlags::all()); + for scope_id in self.scopes.ancestors(scope_id) { + if let Some(symbol_id) = self.scopes.get_binding(scope_id, name) { + let symbol_flags = self.symbols.get_flag(symbol_id); + if symbol_flags.intersects(meaning) { + return Some(symbol_id); + } + } + } + None + } } // Methods used internally within crate diff --git a/tasks/coverage/parser_babel.snap b/tasks/coverage/parser_babel.snap index a5643ebeec0f1..15fdaba830b43 100644 --- a/tasks/coverage/parser_babel.snap +++ b/tasks/coverage/parser_babel.snap @@ -2,7 +2,7 @@ commit: 12619ffe parser_babel Summary: AST Parsed : 2091/2101 (99.52%) -Positive Passed: 2083/2101 (99.14%) +Positive Passed: 2082/2101 (99.10%) Negative Passed: 1364/1501 (90.87%) Expect Syntax Error: "annex-b/disabled/1.1-html-comments-close/input.js" Expect Syntax Error: "annex-b/disabled/3.1-sloppy-labeled-functions/input.js" @@ -399,6 +399,16 @@ Expect to Parse: "typescript/types/const-type-parameters-babel-7/input.ts" · ───── 15 │ class E {} ╰──── +Expect to Parse: "typescript/types/import-type-dynamic/input.ts" + + × 'Y' refers to a value, but is being used as a type here. + ╭─[typescript/types/import-type-dynamic/input.ts:2:22] + 1 │ let x: typeof import('./x'); + 2 │ let Y: import('./y').Y; + · ─ + 3 │ let z: import("/z").foo.bar; + ╰──── + help: Did you mean 'typeof Y'? × Identifier `f` has already been declared ╭─[annex-b/disabled/3.4-var-redeclaration-catch-binding/input.js:2:17] diff --git a/tasks/coverage/parser_typescript.snap b/tasks/coverage/parser_typescript.snap index d613b7363324a..d5d5fe2aa8d5a 100644 --- a/tasks/coverage/parser_typescript.snap +++ b/tasks/coverage/parser_typescript.snap @@ -2,8 +2,8 @@ commit: d8086f14 parser_typescript Summary: AST Parsed : 5280/5283 (99.94%) -Positive Passed: 5273/5283 (99.81%) -Negative Passed: 1068/4875 (21.91%) +Positive Passed: 5268/5283 (99.72%) +Negative Passed: 1099/4875 (22.54%) Expect Syntax Error: "compiler/ClassDeclaration10.ts" Expect Syntax Error: "compiler/ClassDeclaration11.ts" Expect Syntax Error: "compiler/ClassDeclaration13.ts" @@ -171,9 +171,7 @@ Expect Syntax Error: "compiler/autolift4.ts" Expect Syntax Error: "compiler/avoidListingPropertiesForTypesWithOnlyCallOrConstructSignatures.ts" Expect Syntax Error: "compiler/awaitCallExpressionInSyncFunction.ts" Expect Syntax Error: "compiler/awaitInClassInAsyncFunction.ts" -Expect Syntax Error: "compiler/awaitedType.ts" Expect Syntax Error: "compiler/awaitedTypeNoLib.ts" -Expect Syntax Error: "compiler/awaitedTypeStrictNull.ts" Expect Syntax Error: "compiler/badExternalModuleReference.ts" Expect Syntax Error: "compiler/baseCheck.ts" Expect Syntax Error: "compiler/baseClassImprovedMismatchErrors.ts" @@ -275,8 +273,6 @@ Expect Syntax Error: "compiler/classExpressionWithDecorator1.ts" Expect Syntax Error: "compiler/classExtendingQualifiedName.ts" Expect Syntax Error: "compiler/classExtendsClauseClassMergedWithModuleNotReferingConstructor.ts" Expect Syntax Error: "compiler/classExtendsClauseClassNotReferringConstructor.ts" -Expect Syntax Error: "compiler/classExtendsInterface.ts" -Expect Syntax Error: "compiler/classExtendsInterfaceInExpression.ts" Expect Syntax Error: "compiler/classExtendsInterfaceInModule.ts" Expect Syntax Error: "compiler/classExtendsInterfaceThatExtendsClassWithPrivates1.ts" Expect Syntax Error: "compiler/classExtendsInterface_not.ts" @@ -385,7 +381,6 @@ Expect Syntax Error: "compiler/constructorInvocationWithTooFewTypeArgs.ts" Expect Syntax Error: "compiler/constructorOverloads3.ts" Expect Syntax Error: "compiler/constructorOverloads4.ts" Expect Syntax Error: "compiler/constructorOverloads6.ts" -Expect Syntax Error: "compiler/constructorOverloads7.ts" Expect Syntax Error: "compiler/constructorParametersInVariableDeclarations.ts" Expect Syntax Error: "compiler/constructorParametersThatShadowExternalNamesInVariableDeclarations.ts" Expect Syntax Error: "compiler/constructorReturnsInvalidType.ts" @@ -485,7 +480,6 @@ Expect Syntax Error: "compiler/deepKeysIndexing.ts" Expect Syntax Error: "compiler/deeplyNestedAssignabilityErrorsCombined.ts" Expect Syntax Error: "compiler/deeplyNestedAssignabilityIssue.ts" Expect Syntax Error: "compiler/deeplyNestedCheck.ts" -Expect Syntax Error: "compiler/deeplyNestedMappedTypes.ts" Expect Syntax Error: "compiler/defaultArgsInFunctionExpressions.ts" Expect Syntax Error: "compiler/defaultArgsInOverloads.ts" Expect Syntax Error: "compiler/defaultBestCommonTypesHaveDecls.ts" @@ -706,7 +700,6 @@ Expect Syntax Error: "compiler/forInStatement2.ts" Expect Syntax Error: "compiler/forInStatement4.ts" Expect Syntax Error: "compiler/forInStatement7.ts" Expect Syntax Error: "compiler/forInStrictNullChecksNoError.ts" -Expect Syntax Error: "compiler/forwardDeclaredCommonTypes01.ts" Expect Syntax Error: "compiler/forwardRefInClassProperties.ts" Expect Syntax Error: "compiler/forwardRefInEnum.ts" Expect Syntax Error: "compiler/functionAndInterfaceWithSeparateErrors.ts" @@ -782,7 +775,6 @@ Expect Syntax Error: "compiler/genericConditionalConstrainedToUnknownNotAssignab Expect Syntax Error: "compiler/genericConstraint1.ts" Expect Syntax Error: "compiler/genericConstraint2.ts" Expect Syntax Error: "compiler/genericConstraintSatisfaction1.ts" -Expect Syntax Error: "compiler/genericConstructInvocationWithNoTypeArg.ts" Expect Syntax Error: "compiler/genericConstructorFunction1.ts" Expect Syntax Error: "compiler/genericDefaults.ts" Expect Syntax Error: "compiler/genericDefaultsErrors.ts" @@ -988,7 +980,6 @@ Expect Syntax Error: "compiler/interfaceImplementation8.ts" Expect Syntax Error: "compiler/interfaceInheritance.ts" Expect Syntax Error: "compiler/interfaceMayNotBeExtendedWitACall.ts" Expect Syntax Error: "compiler/interfaceMemberValidation.ts" -Expect Syntax Error: "compiler/interfaceNameAsIdentifier.ts" Expect Syntax Error: "compiler/interfacePropertiesWithSameName2.ts" Expect Syntax Error: "compiler/interfacePropertiesWithSameName3.ts" Expect Syntax Error: "compiler/interfaceWithImplements1.ts" @@ -1017,7 +1008,6 @@ Expect Syntax Error: "compiler/invalidStaticField.ts" Expect Syntax Error: "compiler/invalidSymbolInTypeParameter1.ts" Expect Syntax Error: "compiler/invalidTripleSlashReference.ts" Expect Syntax Error: "compiler/invalidUseOfTypeAsNamespace.ts" -Expect Syntax Error: "compiler/invariantGenericErrorElaboration.ts" Expect Syntax Error: "compiler/invocationExpressionInFunctionParameter.ts" Expect Syntax Error: "compiler/invokingNonGenericMethodWithTypeArguments1.ts" Expect Syntax Error: "compiler/invokingNonGenericMethodWithTypeArguments2.ts" @@ -1173,10 +1163,6 @@ Expect Syntax Error: "compiler/modularizeLibrary_ErrorFromUsingWellknownSymbolWi Expect Syntax Error: "compiler/moduleAndInterfaceSharingName2.ts" Expect Syntax Error: "compiler/moduleAndInterfaceWithSameName.ts" Expect Syntax Error: "compiler/moduleAsBaseType.ts" -Expect Syntax Error: "compiler/moduleAssignmentCompat1.ts" -Expect Syntax Error: "compiler/moduleAssignmentCompat2.ts" -Expect Syntax Error: "compiler/moduleAssignmentCompat3.ts" -Expect Syntax Error: "compiler/moduleAssignmentCompat4.ts" Expect Syntax Error: "compiler/moduleAugmentationGlobal6.ts" Expect Syntax Error: "compiler/moduleAugmentationGlobal6_1.ts" Expect Syntax Error: "compiler/moduleAugmentationGlobal7.ts" @@ -1184,7 +1170,6 @@ Expect Syntax Error: "compiler/moduleAugmentationGlobal7_1.ts" Expect Syntax Error: "compiler/moduleAugmentationGlobal8.ts" Expect Syntax Error: "compiler/moduleAugmentationGlobal8_1.ts" Expect Syntax Error: "compiler/moduleClassArrayCodeGenTest.ts" -Expect Syntax Error: "compiler/moduleCrashBug1.ts" Expect Syntax Error: "compiler/moduleExports1.ts" Expect Syntax Error: "compiler/moduleImport.ts" Expect Syntax Error: "compiler/moduleNewExportBug.ts" @@ -1197,7 +1182,6 @@ Expect Syntax Error: "compiler/moduleVisibilityTest2.ts" Expect Syntax Error: "compiler/moduleVisibilityTest3.ts" Expect Syntax Error: "compiler/moduleVisibilityTest4.ts" Expect Syntax Error: "compiler/moduleWithNoValuesAsType.ts" -Expect Syntax Error: "compiler/moduleWithValuesAsType.ts" Expect Syntax Error: "compiler/module_augmentExistingAmbientVariable.ts" Expect Syntax Error: "compiler/module_augmentExistingVariable.ts" Expect Syntax Error: "compiler/multiLineContextDiagnosticWithPretty.ts" @@ -1205,7 +1189,6 @@ Expect Syntax Error: "compiler/multiLineErrors.ts" Expect Syntax Error: "compiler/multipleBaseInterfaesWithIncompatibleProperties.ts" Expect Syntax Error: "compiler/multipleClassPropertyModifiers.ts" Expect Syntax Error: "compiler/multipleClassPropertyModifiersErrors.ts" -Expect Syntax Error: "compiler/multipleExportAssignments.ts" Expect Syntax Error: "compiler/multipleExportAssignmentsInAmbientDeclaration.ts" Expect Syntax Error: "compiler/multipleExports.ts" Expect Syntax Error: "compiler/multipleInheritance.ts" @@ -1401,7 +1384,6 @@ Expect Syntax Error: "compiler/parseUnaryExpressionNoTypeAssertionInJsx3.ts" Expect Syntax Error: "compiler/partialDiscriminatedUnionMemberHasGoodError.ts" Expect Syntax Error: "compiler/potentiallyUncalledDecorators.ts" Expect Syntax Error: "compiler/prettyFileWithErrorsAndTabs.ts" -Expect Syntax Error: "compiler/primaryExpressionMods.ts" Expect Syntax Error: "compiler/primitiveConstraints1.ts" Expect Syntax Error: "compiler/primitiveConstraints2.ts" Expect Syntax Error: "compiler/primitiveMembers.ts" @@ -1445,7 +1427,6 @@ Expect Syntax Error: "compiler/propertyParameterWithQuestionMark.ts" Expect Syntax Error: "compiler/propertySignatures.ts" Expect Syntax Error: "compiler/protectedMembers.ts" Expect Syntax Error: "compiler/protectedMembersThisParameter.ts" -Expect Syntax Error: "compiler/protoAssignment.ts" Expect Syntax Error: "compiler/prototypes.ts" Expect Syntax Error: "compiler/publicGetterProtectedSetterFromThisParameter.ts" Expect Syntax Error: "compiler/publicMemberImplementedAsPrivateInDerivedClass.ts" @@ -1506,7 +1487,6 @@ Expect Syntax Error: "compiler/regularExpressionUnicodePropertyValueExpressionSu Expect Syntax Error: "compiler/relationComplexityError.ts" Expect Syntax Error: "compiler/relationalOperatorComparable.ts" Expect Syntax Error: "compiler/renamingDestructuredPropertyInFunctionType.ts" -Expect Syntax Error: "compiler/renamingDestructuredPropertyInFunctionType3.ts" Expect Syntax Error: "compiler/requiredInitializedParameter1.ts" Expect Syntax Error: "compiler/requiredInitializedParameter2.ts" Expect Syntax Error: "compiler/requiredMappedTypeModifierTrumpsVariance.ts" @@ -1635,7 +1615,6 @@ Expect Syntax Error: "compiler/systemModule2.ts" Expect Syntax Error: "compiler/systemModule9.ts" Expect Syntax Error: "compiler/targetTypeBaseCalls.ts" Expect Syntax Error: "compiler/targetTypeCastTest.ts" -Expect Syntax Error: "compiler/targetTypeTest1.ts" Expect Syntax Error: "compiler/targetTypeTest3.ts" Expect Syntax Error: "compiler/targetTypeVoidFunc.ts" Expect Syntax Error: "compiler/templateLiteralIntersection2.ts" @@ -1733,7 +1712,6 @@ Expect Syntax Error: "compiler/typePredicateInLoop.ts" Expect Syntax Error: "compiler/typePredicateInherit.ts" Expect Syntax Error: "compiler/typePredicatesInUnion3.ts" Expect Syntax Error: "compiler/typeUsedAsTypeLiteralIndex.ts" -Expect Syntax Error: "compiler/typeUsedAsValueError.ts" Expect Syntax Error: "compiler/typeValueConflict1.ts" Expect Syntax Error: "compiler/typeValueConflict2.ts" Expect Syntax Error: "compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts" @@ -1743,9 +1721,7 @@ Expect Syntax Error: "compiler/typedArrays-es5.ts" Expect Syntax Error: "compiler/typedArraysCrossAssignability01.ts" Expect Syntax Error: "compiler/typeofClass.ts" Expect Syntax Error: "compiler/typeofInObjectLiteralType.ts" -Expect Syntax Error: "compiler/typeofInternalModules.ts" Expect Syntax Error: "compiler/typeofProperty.ts" -Expect Syntax Error: "compiler/typeofSimple.ts" Expect Syntax Error: "compiler/typeofUnknownSymbol.ts" Expect Syntax Error: "compiler/umdDependencyComment2.ts" Expect Syntax Error: "compiler/umdDependencyCommentName1.ts" @@ -1987,7 +1963,6 @@ Expect Syntax Error: "conformance/classes/classDeclarations/classAbstractKeyword Expect Syntax Error: "conformance/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethod1.ts" Expect Syntax Error: "conformance/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethods2.ts" Expect Syntax Error: "conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts" -Expect Syntax Error: "conformance/classes/classDeclarations/classExtendingClassLikeType.ts" Expect Syntax Error: "conformance/classes/classDeclarations/classExtendingNonConstructor.ts" Expect Syntax Error: "conformance/classes/classDeclarations/classHeritageSpecification/classExtendsItself.ts" Expect Syntax Error: "conformance/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly.ts" @@ -2745,7 +2720,6 @@ Expect Syntax Error: "conformance/expressions/unaryOperators/typeofOperator/type Expect Syntax Error: "conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithStringType.ts" Expect Syntax Error: "conformance/expressions/unaryOperators/voidOperator/voidOperatorWithAnyOtherType.ts" Expect Syntax Error: "conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts" -Expect Syntax Error: "conformance/expressions/valuesAndReferences/assignments.ts" Expect Syntax Error: "conformance/externalModules/es6/es6modulekindWithES5Target10.ts" Expect Syntax Error: "conformance/externalModules/es6/es6modulekindWithES5Target9.ts" Expect Syntax Error: "conformance/externalModules/esnext/esnextmodulekindWithES5Target10.ts" @@ -2809,7 +2783,6 @@ Expect Syntax Error: "conformance/interfaces/declarationMerging/twoInterfacesDif Expect Syntax Error: "conformance/interfaces/declarationMerging/twoInterfacesDifferentRootModule2.ts" Expect Syntax Error: "conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts" Expect Syntax Error: "conformance/interfaces/interfaceDeclarations/interfaceExtendingOptionalChain.ts" -Expect Syntax Error: "conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts" Expect Syntax Error: "conformance/interfaces/interfaceDeclarations/interfaceThatHidesBaseProperty2.ts" Expect Syntax Error: "conformance/interfaces/interfaceDeclarations/interfaceThatIndirectlyInheritsFromItself.ts" Expect Syntax Error: "conformance/interfaces/interfaceDeclarations/interfaceThatInheritsFromItself.ts" @@ -2842,7 +2815,6 @@ Expect Syntax Error: "conformance/internalModules/exportDeclarations/ModuleWithE Expect Syntax Error: "conformance/internalModules/exportDeclarations/ModuleWithExportedAndNonExportedImportAlias.ts" Expect Syntax Error: "conformance/internalModules/exportDeclarations/ModuleWithExportedAndNonExportedVariables.ts" Expect Syntax Error: "conformance/internalModules/importDeclarations/circularImportAlias.ts" -Expect Syntax Error: "conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts" Expect Syntax Error: "conformance/internalModules/importDeclarations/shadowedInternalModule.ts" Expect Syntax Error: "conformance/internalModules/moduleDeclarations/InvalidNonInstantiatedModule.ts" Expect Syntax Error: "conformance/internalModules/moduleDeclarations/invalidNestedModules.ts" @@ -3560,7 +3532,6 @@ Expect Syntax Error: "conformance/types/primitives/boolean/invalidBooleanAssignm Expect Syntax Error: "conformance/types/primitives/enum/invalidEnumAssignments.ts" Expect Syntax Error: "conformance/types/primitives/enum/validEnumAssignments.ts" Expect Syntax Error: "conformance/types/primitives/null/directReferenceToNull.ts" -Expect Syntax Error: "conformance/types/primitives/null/validNullAssignments.ts" Expect Syntax Error: "conformance/types/primitives/number/assignFromNumberInterface.ts" Expect Syntax Error: "conformance/types/primitives/number/assignFromNumberInterface2.ts" Expect Syntax Error: "conformance/types/primitives/number/invalidNumberAssignments.ts" @@ -3569,7 +3540,6 @@ Expect Syntax Error: "conformance/types/primitives/string/assignFromStringInterf Expect Syntax Error: "conformance/types/primitives/string/invalidStringAssignments.ts" Expect Syntax Error: "conformance/types/primitives/string/stringPropertyAccessWithError.ts" Expect Syntax Error: "conformance/types/primitives/undefined/directReferenceToUndefined.ts" -Expect Syntax Error: "conformance/types/primitives/undefined/invalidUndefinedAssignments.ts" Expect Syntax Error: "conformance/types/primitives/void/invalidAssignmentsToVoid.ts" Expect Syntax Error: "conformance/types/primitives/void/invalidVoidAssignments.ts" Expect Syntax Error: "conformance/types/primitives/void/invalidVoidValues.ts" @@ -3592,7 +3562,6 @@ Expect Syntax Error: "conformance/types/specifyingTypes/typeQueries/typeofThis.t Expect Syntax Error: "conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts" Expect Syntax Error: "conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts" Expect Syntax Error: "conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts" -Expect Syntax Error: "conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts" Expect Syntax Error: "conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts" Expect Syntax Error: "conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts" Expect Syntax Error: "conformance/types/spread/objectSpreadIndexSignature.ts" @@ -3827,6 +3796,50 @@ Expect to Parse: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts" · ──── 24 │ const enum H {} ╰──── +Expect to Parse: "compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts" + + × 'arguments' refers to a type, but is being used as a value here. + ╭─[compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts:5:16] + 4 │ function f() { + 5 │ arguments; + · ───────── + 6 │ } + ╰──── +Expect to Parse: "compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts" + + × 'arguments' refers to a type, but is being used as a value here. + ╭─[compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts:5:16] + 4 │ var x = function f() { + 5 │ arguments; + · ───────── + 6 │ } + ╰──── +Expect to Parse: "compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts" + + × 'f' refers to a type, but is being used as a value here. + ╭─[compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts:5:8] + 4 │ var x = function f() { + 5 │ f; + · ─ + 6 │ } + ╰──── +Expect to Parse: "compiler/staticAnonymousTypeNotReferencingTypeParameter.ts" + + × 'Array' refers to a type, but is being used as a value here. + ╭─[compiler/staticAnonymousTypeNotReferencingTypeParameter.ts:43:85] + 42 │ // keep both methods. + 43 │ static createFixedSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } + · ───── + 44 │ static createGrowableSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } + ╰──── + + × 'Array' refers to a type, but is being used as a value here. + ╭─[compiler/staticAnonymousTypeNotReferencingTypeParameter.ts:44:88] + 43 │ static createFixedSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } + 44 │ static createGrowableSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } + · ───── + 45 │ static clone(dit: typeof ListWrapper, array: T[]): T[] { return array.slice(0); } + ╰──── Expect to Parse: "compiler/withStatementInternalComments.ts" × 'with' statements are not allowed @@ -3944,6 +3957,94 @@ Expect to Parse: "conformance/externalModules/topLevelAwait.3.ts" 4 │ declare class C extends await {} · ───── ╰──── +Expect to Parse: "conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts" + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:20:18] + 19 │ + 20 │ class C1 extends Constructor() { x: string } + · ─────────── + 21 │ class C2 extends Constructor() { x: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:21:18] + 20 │ class C1 extends Constructor() { x: string } + 21 │ class C2 extends Constructor() { x: string } + · ─────────── + 22 │ class C3 extends Constructor() { x: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:22:18] + 21 │ class C2 extends Constructor() { x: string } + 22 │ class C3 extends Constructor() { x: string } + · ─────────── + 23 │ class C4 extends Constructor() { x: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:23:18] + 22 │ class C3 extends Constructor() { x: string } + 23 │ class C4 extends Constructor() { x: string } + · ─────────── + 24 │ class C5 extends Constructor() { x: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:24:18] + 23 │ class C4 extends Constructor() { x: string } + 24 │ class C5 extends Constructor() { x: string } + · ─────────── + 25 │ class C6 extends Constructor() { x: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:25:18] + 24 │ class C5 extends Constructor() { x: string } + 25 │ class C6 extends Constructor() { x: string } + · ─────────── + 26 │ class C7 extends Constructor() { x: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:26:18] + 25 │ class C6 extends Constructor() { x: string } + 26 │ class C7 extends Constructor() { x: string } + · ─────────── + 27 │ + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:50:19] + 49 │ + 50 │ class C20 extends Constructor>() { x: string } + · ─────────── + 51 │ class C21 extends Constructor>() { x: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:51:19] + 50 │ class C20 extends Constructor>() { x: string } + 51 │ class C21 extends Constructor>() { x: string } + · ─────────── + 52 │ class C22 extends Constructor>() { x: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:52:19] + 51 │ class C21 extends Constructor>() { x: string } + 52 │ class C22 extends Constructor>() { x: string } + · ─────────── + 53 │ class C23 extends Constructor>() { x: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts:53:19] + 52 │ class C22 extends Constructor>() { x: string } + 53 │ class C23 extends Constructor>() { x: string } + · ─────────── + ╰──── Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" × Identifier `orbitol` has already been declared @@ -4620,6 +4721,54 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 23 │ } ╰──── + × 'MaybePromise' refers to a type, but is being used as a value here. + ╭─[compiler/awaitedType.ts:42:9] + 41 │ ] = await Promise.all([ + 42 │ MaybePromise(1), + · ──────────── + 43 │ MaybePromise('2'), + ╰──── + + × 'MaybePromise' refers to a type, but is being used as a value here. + ╭─[compiler/awaitedType.ts:43:9] + 42 │ MaybePromise(1), + 43 │ MaybePromise('2'), + · ──────────── + 44 │ MaybePromise(true), + ╰──── + + × 'MaybePromise' refers to a type, but is being used as a value here. + ╭─[compiler/awaitedType.ts:44:9] + 43 │ MaybePromise('2'), + 44 │ MaybePromise(true), + · ──────────── + 45 │ ]) + ╰──── + + × 'MaybePromise' refers to a type, but is being used as a value here. + ╭─[compiler/awaitedTypeStrictNull.ts:42:9] + 41 │ ] = await Promise.all([ + 42 │ MaybePromise(1), + · ──────────── + 43 │ MaybePromise('2'), + ╰──── + + × 'MaybePromise' refers to a type, but is being used as a value here. + ╭─[compiler/awaitedTypeStrictNull.ts:43:9] + 42 │ MaybePromise(1), + 43 │ MaybePromise('2'), + · ──────────── + 44 │ MaybePromise(true), + ╰──── + + × 'MaybePromise' refers to a type, but is being used as a value here. + ╭─[compiler/awaitedTypeStrictNull.ts:44:9] + 43 │ MaybePromise('2'), + 44 │ MaybePromise(true), + · ──────────── + 45 │ ]) + ╰──── + × Unexpected token ╭─[compiler/badArrayIndex.ts:1:22] 1 │ var results = number[]; @@ -4755,6 +4904,29 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" ╰──── help: Try insert a semicolon here + × 'Comparable2' refers to a type, but is being used as a value here. + ╭─[compiler/classExtendsInterface.ts:6:21] + 5 │ interface Comparable2 {} + 6 │ class A2 extends Comparable2 {} + · ─────────── + 7 │ class B2 implements Comparable2 {} + ╰──── + + × 'Comparable' refers to a type, but is being used as a value here. + ╭─[compiler/classExtendsInterface.ts:2:17] + 1 │ interface Comparable {} + 2 │ class A extends Comparable {} + · ────────── + 3 │ class B implements Comparable {} + ╰──── + + × 'A' refers to a type, but is being used as a value here. + ╭─[compiler/classExtendsInterfaceInExpression.ts:7:25] + 6 │ + 7 │ class C extends factory(A) {} + · ─ + ╰──── + × Expected `{` but found `EOF` ╭─[compiler/classHeritageWithTrailingSeparator.ts:3:2] 2 │ class D extends C, { @@ -5654,6 +5826,24 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 8 │ ╰──── + × 'Point' refers to a value, but is being used as a type here. + ╭─[compiler/constructorOverloads7.ts:7:35] + 6 │ + 7 │ add(dx: number, dy: number): Point; + · ───── + 8 │ origin: Point; + ╰──── + help: Did you mean 'typeof Point'? + + × 'Point' refers to a value, but is being used as a type here. + ╭─[compiler/constructorOverloads7.ts:8:14] + 7 │ add(dx: number, dy: number): Point; + 8 │ origin: Point; + · ───── + 9 │ + ╰──── + help: Did you mean 'typeof Point'? + × Multiple constructor implementations are not allowed. ╭─[compiler/constructorOverloads8.ts:2:5] 1 │ class C { @@ -5788,6 +5978,24 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 5 │ ╰──── + × 'Readonly' refers to a value, but is being used as a type here. + ╭─[compiler/deeplyNestedMappedTypes.ts:113:5] + 112 │ export type PropertiesReducer> = Evaluate<( + 113 │ Readonly>>> & + · ──────── + 114 │ Readonly>> & + ╰──── + help: Did you mean 'typeof Readonly'? + + × 'Readonly' refers to a value, but is being used as a type here. + ╭─[compiler/deeplyNestedMappedTypes.ts:114:5] + 113 │ Readonly>>> & + 114 │ Readonly>> & + · ──────── + 115 │ Partial>> & + ╰──── + help: Did you mean 'typeof Readonly'? + × Unexpected token ╭─[compiler/defaultKeywordWithoutExport1.ts:4:1] 3 │ @decorator @@ -6675,6 +6883,62 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 30 │ } ╰──── + × 'WeakSet' refers to a type, but is being used as a value here. + ╭─[compiler/forwardDeclaredCommonTypes01.ts:14:9] + 13 │ new Set; + 14 │ new WeakSet; + · ─────── + 15 │ }); + ╰──── + + × 'Promise' refers to a type, but is being used as a value here. + ╭─[compiler/forwardDeclaredCommonTypes01.ts:9:9] + 8 │ (function() { + 9 │ new Promise; + · ─────── + 10 │ new Symbol; Symbol(); + ╰──── + + × 'Set' refers to a type, but is being used as a value here. + ╭─[compiler/forwardDeclaredCommonTypes01.ts:13:9] + 12 │ new WeakMap; + 13 │ new Set; + · ─── + 14 │ new WeakSet; + ╰──── + + × 'Map' refers to a type, but is being used as a value here. + ╭─[compiler/forwardDeclaredCommonTypes01.ts:11:9] + 10 │ new Symbol; Symbol(); + 11 │ new Map; + · ─── + 12 │ new WeakMap; + ╰──── + + × 'Symbol' refers to a type, but is being used as a value here. + ╭─[compiler/forwardDeclaredCommonTypes01.ts:10:9] + 9 │ new Promise; + 10 │ new Symbol; Symbol(); + · ────── + 11 │ new Map; + ╰──── + + × 'Symbol' refers to a type, but is being used as a value here. + ╭─[compiler/forwardDeclaredCommonTypes01.ts:10:17] + 9 │ new Promise; + 10 │ new Symbol; Symbol(); + · ────── + 11 │ new Map; + ╰──── + + × 'WeakMap' refers to a type, but is being used as a value here. + ╭─[compiler/forwardDeclaredCommonTypes01.ts:12:9] + 11 │ new Map; + 12 │ new WeakMap; + · ─────── + 13 │ new Set; + ╰──── + × Identifier `foo3` has already been declared ╭─[compiler/funClodule.ts:15:10] 14 │ @@ -6760,6 +7024,13 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 4 │ f. ╰──── + × 'Foo' refers to a type, but is being used as a value here. + ╭─[compiler/genericConstructInvocationWithNoTypeArg.ts:4:27] + 3 │ } + 4 │ var f2: Foo = new Foo(3); + · ─── + ╰──── + × A 'get' accessor must not have any formal parameters. ╭─[compiler/gettersAndSettersErrors.ts:6:19] 5 │ public Foo = 0; // error - duplicate identifier Foo - confirmed @@ -6972,6 +7243,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" · ╰── `{` expected ╰──── + × 'C' refers to a type, but is being used as a value here. + ╭─[compiler/interfaceNameAsIdentifier.ts:4:1] + 3 │ } + 4 │ C(); + · ─ + 5 │ + ╰──── + × Expected a semicolon or an implicit semicolon after a statement, but found none ╭─[compiler/interfaceNaming1.ts:1:10] 1 │ interface { } @@ -7049,6 +7328,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" · ▲ ╰──── + × 'Obj' refers to a type, but is being used as a value here. + ╭─[compiler/invariantGenericErrorElaboration.ts:4:13] + 3 │ const wat: Runtype = Num; + 4 │ const Foo = Obj({ foo: Num }) + · ─── + 5 │ + ╰──── + × Identifier `a` has already been declared ╭─[compiler/jsFileCompilationBindDuplicateIdentifier.ts:1:5] 1 │ var a = 10; @@ -7718,6 +8005,87 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 3 │ } ╰──── + × 'A' refers to a value, but is being used as a type here. + ╭─[compiler/moduleAssignmentCompat1.ts:9:8] + 8 │ + 9 │ var a: A; + · ─ + 10 │ var b: B; + ╰──── + help: Did you mean 'typeof A'? + + × 'B' refers to a value, but is being used as a type here. + ╭─[compiler/moduleAssignmentCompat1.ts:10:8] + 9 │ var a: A; + 10 │ var b: B; + · ─ + 11 │ + ╰──── + help: Did you mean 'typeof B'? + + × 'A' refers to a value, but is being used as a type here. + ╭─[compiler/moduleAssignmentCompat2.ts:9:8] + 8 │ + 9 │ var a: A; + · ─ + 10 │ var b: B; + ╰──── + help: Did you mean 'typeof A'? + + × 'B' refers to a value, but is being used as a type here. + ╭─[compiler/moduleAssignmentCompat2.ts:10:8] + 9 │ var a: A; + 10 │ var b: B; + · ─ + 11 │ + ╰──── + help: Did you mean 'typeof B'? + + × 'A' refers to a value, but is being used as a type here. + ╭─[compiler/moduleAssignmentCompat3.ts:8:8] + 7 │ + 8 │ var a: A; + · ─ + 9 │ var b: B; + ╰──── + help: Did you mean 'typeof A'? + + × 'B' refers to a value, but is being used as a type here. + ╭─[compiler/moduleAssignmentCompat3.ts:9:8] + 8 │ var a: A; + 9 │ var b: B; + · ─ + 10 │ + ╰──── + help: Did you mean 'typeof B'? + + × 'A' refers to a value, but is being used as a type here. + ╭─[compiler/moduleAssignmentCompat4.ts:12:8] + 11 │ + 12 │ var a: A; + · ─ + 13 │ var b: B; + ╰──── + help: Did you mean 'typeof A'? + + × 'B' refers to a value, but is being used as a type here. + ╭─[compiler/moduleAssignmentCompat4.ts:13:8] + 12 │ var a: A; + 13 │ var b: B; + · ─ + 14 │ + ╰──── + help: Did you mean 'typeof B'? + + × '_modes' refers to a value, but is being used as a type here. + ╭─[compiler/moduleCrashBug1.ts:18:9] + 17 │ + 18 │ var m : _modes; + · ────── + 19 │ + ╰──── + help: Did you mean 'typeof _modes'? + × Identifier `Kettle` has already been declared ╭─[compiler/moduleDuplicateIdentifiers.ts:20:14] 19 │ @@ -7886,6 +8254,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" ╰──── help: Try insert a semicolon here + × 'A' refers to a value, but is being used as a type here. + ╭─[compiler/moduleWithValuesAsType.ts:5:8] + 4 │ + 5 │ var a: A; // no error + · ─ + ╰──── + help: Did you mean 'typeof A'? + × TS1108: A 'return' statement can only be used within a function body ╭─[compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts:1:1] 1 │ return this.edit(role) @@ -7893,6 +8269,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 2 │ .then((role: Role) => ╰──── + × 'connectExport' refers to a type, but is being used as a value here. + ╭─[compiler/multipleExportAssignments.ts:14:10] + 13 │ export = server; + 14 │ export = connectExport; + · ───────────── + 15 │ + ╰──── + × Identifier `z` has already been declared ╭─[compiler/nameCollisions.ts:10:5] 9 │ @@ -8675,6 +9059,23 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 1 │ if (true) { ╰──── + × 'm' refers to a value, but is being used as a type here. + ╭─[compiler/primaryExpressionMods.ts:11:8] + 10 │ var x2 = m.a; // Same as M.a + 11 │ var q: m.P; // Error + · ─ + ╰──── + help: Did you mean 'typeof m'? + + × 'M' refers to a value, but is being used as a type here. + ╭─[compiler/primaryExpressionMods.ts:7:8] + 6 │ var p: M.P; // Used as ModuleName + 7 │ var m: M = M; // Used as TypeName and PrimaryExpression (error on TypeName) + · ─ + 8 │ var m2: typeof M = M; // Used as PrimaryExpression in TypeQuery + ╰──── + help: Did you mean 'typeof M'? + × 'export' modifier cannot be used here. ╭─[compiler/privacyImportParseErrors.ts:326:9] 325 │ @@ -8700,6 +9101,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" ╰──── help: Try insert a semicolon here + × 'Number' refers to a type, but is being used as a value here. + ╭─[compiler/protoAssignment.ts:7:1] + 6 │ + 7 │ Number.prototype.compareTo = function (other: number) { + · ────── + 8 │ + ╰──── + × Identifier `bar` has already been declared ╭─[compiler/reassignStaticProp.ts:3:12] 2 │ @@ -8863,6 +9272,24 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" ╰──── help: Try insert a semicolon here + × 'sym' refers to a value, but is being used as a type here. + ╭─[compiler/renamingDestructuredPropertyInFunctionType3.ts:3:16] + 2 │ type O = Record + 3 │ type F14 = ({ [sym]: string }: O) => void; // Error + · ─── + 4 │ type G14 = new ({ [sym]: string }: O) => void; // Error + ╰──── + help: Did you mean 'typeof sym'? + + × 'sym' refers to a value, but is being used as a type here. + ╭─[compiler/renamingDestructuredPropertyInFunctionType3.ts:4:20] + 3 │ type F14 = ({ [sym]: string }: O) => void; // Error + 4 │ type G14 = new ({ [sym]: string }: O) => void; // Error + · ─── + 5 │ + ╰──── + help: Did you mean 'typeof sym'? + × Expected `from` but found `while` ╭─[compiler/reservedWords2.ts:1:8] 1 │ import while = require("dfdf"); @@ -10020,6 +10447,24 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 5 │ f `123qdawdrqw${ 1 }${ ╰──── + × 'Point' refers to a value, but is being used as a type here. + ╭─[compiler/targetTypeTest1.ts:6:43] + 5 │ public y: number; + 6 │ public add(dx: number, dy: number): Point; + · ───── + 7 │ static origin: Point; + ╰──── + help: Did you mean 'typeof Point'? + + × 'Point' refers to a value, but is being used as a type here. + ╭─[compiler/targetTypeTest1.ts:7:22] + 6 │ public add(dx: number, dy: number): Point; + 7 │ static origin: Point; + · ───── + 8 │ + ╰──── + help: Did you mean 'typeof Point'? + × Bad escape sequence in untagged template literal ╭─[compiler/templateLiteralEscapeSequence.ts:3:2] 2 │ @@ -10300,6 +10745,63 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" ╰──── help: Try insert a semicolon here + × 'someType' refers to a type, but is being used as a value here. + ╭─[compiler/typeUsedAsValueError.ts:21:11] + 20 │ let five = new TypeAliasForSomeClassNotFound(); + 21 │ let six = someType; + · ──────── + 22 │ acceptsSomeType(someType); + ╰──── + + × 'someType' refers to a type, but is being used as a value here. + ╭─[compiler/typeUsedAsValueError.ts:22:17] + 21 │ let six = someType; + 22 │ acceptsSomeType(someType); + · ──────── + 23 │ acceptsSomeType(someTypeNotFound); + ╰──── + + × 'Interface' refers to a type, but is being used as a value here. + ╭─[compiler/typeUsedAsValueError.ts:16:11] + 15 │ + 16 │ let one = Interface; + · ───────── + 17 │ let two = InterfaceNotFound; + ╰──── + + × 'TypeAliasForSomeClass' refers to a type, but is being used as a value here. + ╭─[compiler/typeUsedAsValueError.ts:18:13] + 17 │ let two = InterfaceNotFound; + 18 │ let three = TypeAliasForSomeClass; + · ───────────────────── + 19 │ let four = new TypeAliasForSomeClass(); + ╰──── + + × 'TypeAliasForSomeClass' refers to a type, but is being used as a value here. + ╭─[compiler/typeUsedAsValueError.ts:19:16] + 18 │ let three = TypeAliasForSomeClass; + 19 │ let four = new TypeAliasForSomeClass(); + · ───────────────────── + 20 │ let five = new TypeAliasForSomeClassNotFound(); + ╰──── + + × 'Outer' refers to a value, but is being used as a type here. + ╭─[compiler/typeofInternalModules.ts:17:9] + 16 │ + 17 │ var x4: Outer = Outer; + · ───── + 18 │ var x5: typeof importInst; + ╰──── + help: Did you mean 'typeof Outer'? + + × 'J' refers to a type, but is being used as a value here. + ╭─[compiler/typeofSimple.ts:8:21] + 7 │ + 8 │ var numberJ: typeof J; //Error, cannot reference type in typeof + · ─ + 9 │ var numberI: I; + ╰──── + × Cannot assign to 'eval' in strict mode ╭─[compiler/unaryOperatorsInStrictMode.ts:3:3] 2 │ @@ -10974,6 +11476,22 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 18 │ ╰──── + × 'DIC' refers to a type, but is being used as a value here. + ╭─[conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts:38:5] + 37 │ new DCI; + 38 │ new DIC; + · ─── + 39 │ new DCC1; + ╰──── + + × 'DCI' refers to a type, but is being used as a value here. + ╭─[conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts:37:5] + 36 │ new CC2; + 37 │ new DCI; + · ─── + 38 │ new DIC; + ╰──── + × Expected `(` but found `Identifier` ╭─[conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts:16:20] 15 │ abstract async foo_f(); @@ -11024,6 +11542,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" ╰──── help: Try insert a semicolon here + × 'Base' refers to a type, but is being used as a value here. + ╭─[conformance/classes/classDeclarations/classExtendingClassLikeType.ts:7:18] + 6 │ // Error, no Base constructor function + 7 │ class D0 extends Base { + · ──── + 8 │ } + ╰──── + × Expected `{` but found `?.` ╭─[conformance/classes/classDeclarations/classHeritageSpecification/classExtendingOptionalChain.ts:9:22] 8 │ // error @@ -15888,6 +16414,13 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" ╰──── help: Try insert a semicolon here + × 'I' refers to a type, but is being used as a value here. + ╭─[conformance/expressions/valuesAndReferences/assignments.ts:31:1] + 30 │ interface I { } + 31 │ I = null; // Error + · ─ + ╰──── + × Unexpected token ╭─[conformance/externalModules/exportNonInitializedVariablesAMD.ts:1:4] 1 │ var; @@ -16159,6 +16692,46 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 11 │ I // This should be the identifier 'I' ╰──── + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts:16:18] + 15 │ + 16 │ class C1 extends Constructor() { a: string } + · ─────────── + 17 │ class C2 extends Constructor() { b: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts:17:18] + 16 │ class C1 extends Constructor() { a: string } + 17 │ class C2 extends Constructor() { b: string } + · ─────────── + 18 │ class C3 extends Constructor() { length: string } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts:18:18] + 17 │ class C2 extends Constructor() { b: string } + 18 │ class C3 extends Constructor() { length: string } + · ─────────── + 19 │ class C4 extends Constructor() { 0: number } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts:19:18] + 18 │ class C3 extends Constructor() { length: string } + 19 │ class C4 extends Constructor() { 0: number } + · ─────────── + 20 │ class C5 extends Constructor() { c: number } + ╰──── + + × 'Constructor' refers to a type, but is being used as a value here. + ╭─[conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts:20:18] + 19 │ class C4 extends Constructor() { 0: number } + 20 │ class C5 extends Constructor() { c: number } + · ─────────── + 21 │ + ╰──── + × Expected a semicolon or an implicit semicolon after a statement, but found none ╭─[conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts:5:10] 4 │ interface boolean { } @@ -16182,6 +16755,30 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 3 │ let; ╰──── + × 'C' refers to a type, but is being used as a value here. + ╭─[conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts:11:12] + 10 │ + 11 │ import c = C; + · ─ + 12 │ + ╰──── + + × 'I' refers to a type, but is being used as a value here. + ╭─[conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts:23:12] + 22 │ + 23 │ import i = I; + · ─ + ╰──── + + × 'V' refers to a value, but is being used as a type here. + ╭─[conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts:5:12] + 4 │ + 5 │ import v = V; + · ─ + 6 │ + ╰──── + help: Did you mean 'typeof V'? + × 'public' modifier cannot be used here. ╭─[conformance/internalModules/moduleBody/invalidModuleWithStatementsOfEveryKind.ts:4:5] 3 │ module Y { @@ -16410,6 +17007,15 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 4 │ } ╰──── + × 'm' refers to a value, but is being used as a type here. + ╭─[conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts:12:8] + 11 │ var m = M2; + 12 │ var p: m.Point; // Error + · ─ + 13 │ + ╰──── + help: Did you mean 'typeof m'? + × Identifier `err` has already been declared ╭─[conformance/jsdoc/jsdocCatchClauseWithTypeAnnotation.ts:33:9] 32 │ try { } @@ -20693,6 +21299,22 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 21 │ } ╰──── + × 'I' refers to a type, but is being used as a value here. + ╭─[conformance/types/primitives/null/validNullAssignments.ts:20:1] + 19 │ g = null; // ok + 20 │ I = null; // error + · ─ + 21 │ + ╰──── + + × 'I' refers to a type, but is being used as a value here. + ╭─[conformance/types/primitives/undefined/invalidUndefinedAssignments.ts:14:1] + 13 │ g = x; + 14 │ I = x; + · ─ + 15 │ + ╰──── + × A rest element must be last in a destructuring pattern ╭─[conformance/types/rest/objectRestNegative.ts:2:7] 1 │ let o = { a: 1, b: 'no' }; @@ -20760,6 +21382,14 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" 2 │ var x2: typeof (): void; ╰──── + × 'I' refers to a type, but is being used as a value here. + ╭─[conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts:20:17] + 19 │ + 20 │ class D extends I { + · ─ + 21 │ } + ╰──── + × Unexpected token ╭─[conformance/types/spread/objectSpreadNegativeParse.ts:1:18] 1 │ let o7 = { ...o? }; diff --git a/tasks/transform_conformance/babel.snap.md b/tasks/transform_conformance/babel.snap.md index 580cd26e07b2e..353b3e36aa404 100644 --- a/tasks/transform_conformance/babel.snap.md +++ b/tasks/transform_conformance/babel.snap.md @@ -1,9 +1,8 @@ commit: 12619ffe -Passed: 475/927 +Passed: 472/927 # All Passed: -* babel-preset-react * babel-plugin-transform-react-display-name * babel-plugin-transform-react-jsx-self * babel-plugin-transform-react-jsx-source @@ -467,8 +466,13 @@ Passed: 475/927 * optimize-const-enums/merged-exported/input.ts * regression/15768/input.ts -# babel-plugin-transform-react-jsx (141/142) +# babel-preset-react (8/9) +* regression/11294/input.mjs + +# babel-plugin-transform-react-jsx (139/142) * react-automatic/does-not-add-source-self-automatic/input.mjs +* react-automatic/handle-fragments-with-key/input.js +* sourcemaps/JSXText/input.js # babel-plugin-transform-react-jsx-development (9/10) * cross-platform/within-ts-module-block/input.ts