Skip to content

Commit 620468a

Browse files
committed
test: add
1 parent 89f2c1b commit 620468a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

crates/oxc_semantic/tests/integration/symbols.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,45 @@ fn test_ts_infer_type() {
237237
// type C is not referenced
238238
tester.has_symbol("C").has_number_of_references(0).test();
239239
}
240+
241+
#[test]
242+
fn test_value_used_as_type() {
243+
// Type annotations (or any type reference) do not resolve to value symbols
244+
SemanticTester::ts(
245+
"
246+
const x = 1;
247+
function foo(a: x) { }
248+
",
249+
)
250+
.has_root_symbol("x")
251+
.intersects_flags(SymbolFlags::Value)
252+
.has_number_of_references(0)
253+
.test();
254+
255+
// T is a value that gets shadowed by a type. When `T` is referenced within
256+
// a value context, the root `const T` should be the symbol recoreded in the
257+
// reference.
258+
let tester = SemanticTester::ts(
259+
"
260+
const T = 1;
261+
function foo<T extends number>(a: T) {
262+
return a + T;
263+
}
264+
",
265+
);
266+
267+
tester.has_root_symbol("T").has_number_of_reads(1).test();
268+
}
269+
270+
#[test]
271+
fn test_type_used_as_value() {
272+
SemanticTester::ts(
273+
"
274+
type T = number;
275+
let x = T;
276+
",
277+
)
278+
.has_some_symbol("T")
279+
.has_number_of_reads(0)
280+
.test();
281+
}

0 commit comments

Comments
 (0)