@tishlang/tish 1.9.2 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/tish +0 -0
- package/crates/js_to_tish/src/transform/expr.rs +8 -6
- package/crates/js_to_tish/src/transform/stmt.rs +12 -13
- package/crates/tish/Cargo.toml +1 -1
- package/crates/tish/src/cargo_native_registry.rs +4 -1
- package/crates/tish/src/cli_help.rs +9 -1
- package/crates/tish/src/main.rs +66 -11
- package/crates/tish/tests/integration_test.rs +145 -7
- package/crates/tish_ast/src/ast.rs +3 -9
- package/crates/tish_build_utils/src/lib.rs +74 -23
- package/crates/tish_builtins/src/array.rs +2 -3
- package/crates/tish_builtins/src/construct.rs +15 -28
- package/crates/tish_builtins/src/globals.rs +18 -16
- package/crates/tish_builtins/src/helpers.rs +1 -4
- package/crates/tish_builtins/src/lib.rs +1 -0
- package/crates/tish_builtins/src/math.rs +7 -0
- package/crates/tish_builtins/src/object.rs +10 -10
- package/crates/tish_builtins/src/string.rs +27 -3
- package/crates/tish_builtins/src/symbol.rs +83 -0
- package/crates/tish_compile/src/codegen.rs +324 -158
- package/crates/tish_compile/src/lib.rs +39 -7
- package/crates/tish_compile/src/resolve.rs +191 -6
- package/crates/tish_compile/src/types.rs +6 -6
- package/crates/tish_compile_js/src/codegen.rs +8 -5
- package/crates/tish_core/src/console_style.rs +9 -0
- package/crates/tish_core/src/json.rs +17 -7
- package/crates/tish_core/src/macros.rs +2 -2
- package/crates/tish_core/src/value.rs +213 -4
- package/crates/tish_cranelift/src/link.rs +1 -1
- package/crates/tish_cranelift_runtime/Cargo.toml +4 -0
- package/crates/tish_eval/src/eval.rs +135 -73
- package/crates/tish_eval/src/http.rs +18 -12
- package/crates/tish_eval/src/lib.rs +29 -0
- package/crates/tish_eval/src/regex.rs +1 -1
- package/crates/tish_eval/src/value.rs +89 -4
- package/crates/tish_eval/src/value_convert.rs +30 -8
- package/crates/tish_fmt/src/lib.rs +4 -1
- package/crates/tish_lexer/src/lib.rs +7 -2
- package/crates/tish_llvm/src/lib.rs +2 -2
- package/crates/tish_lsp/src/builtin_goto.rs +111 -10
- package/crates/tish_lsp/src/import_goto.rs +35 -22
- package/crates/tish_lsp/src/main.rs +118 -85
- package/crates/tish_native/src/build.rs +270 -24
- package/crates/tish_native/src/config.rs +48 -0
- package/crates/tish_native/src/lib.rs +139 -12
- package/crates/tish_parser/src/lib.rs +5 -2
- package/crates/tish_parser/src/parser.rs +45 -75
- package/crates/tish_pg/src/error.rs +1 -1
- package/crates/tish_pg/src/lib.rs +61 -73
- package/crates/tish_resolve/src/lib.rs +283 -158
- package/crates/tish_resolve/src/pos.rs +10 -2
- package/crates/tish_runtime/Cargo.toml +3 -0
- package/crates/tish_runtime/src/http.rs +39 -39
- package/crates/tish_runtime/src/http_fetch.rs +12 -12
- package/crates/tish_runtime/src/lib.rs +35 -44
- package/crates/tish_runtime/src/native_promise.rs +0 -11
- package/crates/tish_runtime/src/promise.rs +14 -1
- package/crates/tish_runtime/src/promise_io.rs +1 -4
- package/crates/tish_runtime/src/timers.rs +12 -7
- package/crates/tish_runtime/src/ws.rs +40 -27
- package/crates/tish_runtime/tests/fetch_readable_stream.rs +10 -8
- package/crates/tish_ui/src/jsx.rs +6 -4
- package/crates/tish_ui/src/lib.rs +5 -4
- package/crates/tish_ui/src/runtime/hooks.rs +123 -37
- package/crates/tish_ui/src/runtime/mod.rs +21 -41
- package/crates/tish_vm/Cargo.toml +2 -0
- package/crates/tish_vm/src/vm.rs +258 -153
- package/crates/tish_wasm/src/lib.rs +60 -7
- package/crates/tish_wasm_runtime/Cargo.toml +10 -1
- package/crates/tish_wasm_runtime/src/gpu.rs +413 -0
- package/crates/tish_wasm_runtime/src/lib.rs +7 -1
- package/crates/tishlang_cargo_bindgen/src/classify.rs +1 -3
- package/crates/tishlang_cargo_bindgen/src/discover.rs +10 -5
- package/crates/tishlang_cargo_bindgen/src/infer.rs +18 -8
- package/crates/tishlang_cargo_bindgen/src/lib.rs +25 -26
- package/crates/tishlang_cargo_bindgen/src/main.rs +41 -38
- package/crates/tishlang_cargo_bindgen/src/metadata.rs +4 -1
- package/justfile +3 -3
- package/package.json +1 -1
- package/platform/darwin-arm64/tish +0 -0
- package/platform/darwin-x64/tish +0 -0
- package/platform/linux-arm64/tish +0 -0
- package/platform/linux-x64/tish +0 -0
- package/platform/win32-x64/tish.exe +0 -0
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
|
|
7
7
|
mod pos;
|
|
8
8
|
|
|
9
|
-
pub use pos::{
|
|
9
|
+
pub use pos::{
|
|
10
|
+
lsp_position_for_span_start, span_contains_lsp_position, span_to_lsp_range_exclusive,
|
|
11
|
+
};
|
|
10
12
|
|
|
11
13
|
use std::collections::HashMap;
|
|
12
14
|
use std::sync::Arc;
|
|
13
15
|
|
|
14
16
|
use tishlang_ast::{
|
|
15
|
-
ArrowBody, CallArg, DestructElement, DestructPattern,
|
|
17
|
+
ArrowBody, CallArg, DestructElement, DestructPattern, ExportDeclaration, Expr, FunParam,
|
|
16
18
|
ImportSpecifier, MemberProp, Program, Statement, TypedParam,
|
|
17
19
|
};
|
|
18
20
|
|
|
@@ -24,7 +26,12 @@ pub struct NameUse {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
/// Find the tightest name under the cursor (identifier reference or binding).
|
|
27
|
-
pub fn name_at_cursor(
|
|
29
|
+
pub fn name_at_cursor(
|
|
30
|
+
program: &Program,
|
|
31
|
+
source: &str,
|
|
32
|
+
lsp_line: u32,
|
|
33
|
+
lsp_character: u32,
|
|
34
|
+
) -> Option<NameUse> {
|
|
28
35
|
let mut best: Option<(u64, NameUse)> = None;
|
|
29
36
|
for s in &program.statements {
|
|
30
37
|
collect_stmt(s, source, lsp_line, lsp_character, &mut best);
|
|
@@ -50,10 +57,7 @@ fn consider(
|
|
|
50
57
|
return;
|
|
51
58
|
}
|
|
52
59
|
let sz = span_size(source, span);
|
|
53
|
-
let nu = NameUse {
|
|
54
|
-
name,
|
|
55
|
-
span: *span,
|
|
56
|
-
};
|
|
60
|
+
let nu = NameUse { name, span: *span };
|
|
57
61
|
match best {
|
|
58
62
|
None => *best = Some((sz, nu)),
|
|
59
63
|
Some((osz, _)) if sz < *osz => *best = Some((sz, nu)),
|
|
@@ -211,7 +215,10 @@ fn collect_stmt(
|
|
|
211
215
|
alias,
|
|
212
216
|
alias_span,
|
|
213
217
|
} => {
|
|
214
|
-
let local = alias
|
|
218
|
+
let local = alias
|
|
219
|
+
.as_ref()
|
|
220
|
+
.map(|a| a.clone())
|
|
221
|
+
.unwrap_or_else(|| name.clone());
|
|
215
222
|
let spn = alias_span.as_ref().unwrap_or(name_span);
|
|
216
223
|
consider(source, lsp_line, lsp_char, spn, local, best);
|
|
217
224
|
}
|
|
@@ -225,13 +232,19 @@ fn collect_stmt(
|
|
|
225
232
|
}
|
|
226
233
|
}
|
|
227
234
|
Statement::Export { declaration, .. } => match declaration.as_ref() {
|
|
228
|
-
ExportDeclaration::Named(inner) =>
|
|
235
|
+
ExportDeclaration::Named(inner) => {
|
|
236
|
+
collect_stmt(inner, source, lsp_line, lsp_char, best)
|
|
237
|
+
}
|
|
229
238
|
ExportDeclaration::Default(e) => collect_expr(e, source, lsp_line, lsp_char, best),
|
|
230
239
|
},
|
|
231
|
-
Statement::TypeAlias {
|
|
240
|
+
Statement::TypeAlias {
|
|
241
|
+
name, name_span, ..
|
|
242
|
+
} => {
|
|
232
243
|
consider(source, lsp_line, lsp_char, name_span, name.clone(), best);
|
|
233
244
|
}
|
|
234
|
-
Statement::DeclareVar {
|
|
245
|
+
Statement::DeclareVar {
|
|
246
|
+
name, name_span, ..
|
|
247
|
+
} => {
|
|
235
248
|
consider(source, lsp_line, lsp_char, name_span, name.clone(), best);
|
|
236
249
|
}
|
|
237
250
|
Statement::DeclareFun {
|
|
@@ -335,7 +348,9 @@ fn collect_expr(
|
|
|
335
348
|
best: &mut Option<(u64, NameUse)>,
|
|
336
349
|
) {
|
|
337
350
|
match expr {
|
|
338
|
-
Expr::Ident { name, span } =>
|
|
351
|
+
Expr::Ident { name, span } => {
|
|
352
|
+
consider(source, lsp_line, lsp_char, span, name.clone(), best)
|
|
353
|
+
}
|
|
339
354
|
Expr::Literal { .. } => {}
|
|
340
355
|
Expr::Binary { left, right, .. } => {
|
|
341
356
|
collect_expr(left, source, lsp_line, lsp_char, best);
|
|
@@ -425,17 +440,17 @@ fn collect_expr(
|
|
|
425
440
|
let sp = synthetic_name_span(span.start, name.as_ref());
|
|
426
441
|
consider(source, lsp_line, lsp_char, &sp, name.clone(), best);
|
|
427
442
|
}
|
|
428
|
-
Expr::CompoundAssign {
|
|
429
|
-
|
|
443
|
+
Expr::CompoundAssign {
|
|
444
|
+
name, span, value, ..
|
|
445
|
+
}
|
|
446
|
+
| Expr::LogicalAssign {
|
|
447
|
+
name, span, value, ..
|
|
448
|
+
} => {
|
|
430
449
|
let sp = synthetic_name_span(span.start, name.as_ref());
|
|
431
450
|
consider(source, lsp_line, lsp_char, &sp, name.clone(), best);
|
|
432
451
|
collect_expr(value, source, lsp_line, lsp_char, best);
|
|
433
452
|
}
|
|
434
|
-
Expr::MemberAssign {
|
|
435
|
-
object,
|
|
436
|
-
value,
|
|
437
|
-
..
|
|
438
|
-
} => {
|
|
453
|
+
Expr::MemberAssign { object, value, .. } => {
|
|
439
454
|
collect_expr(object, source, lsp_line, lsp_char, best);
|
|
440
455
|
collect_expr(value, source, lsp_line, lsp_char, best);
|
|
441
456
|
}
|
|
@@ -464,7 +479,9 @@ fn collect_expr(
|
|
|
464
479
|
}
|
|
465
480
|
}
|
|
466
481
|
Expr::Await { operand, .. } => collect_expr(operand, source, lsp_line, lsp_char, best),
|
|
467
|
-
Expr::JsxElement {
|
|
482
|
+
Expr::JsxElement {
|
|
483
|
+
props, children, ..
|
|
484
|
+
} => {
|
|
468
485
|
for p in props {
|
|
469
486
|
match p {
|
|
470
487
|
tishlang_ast::JsxProp::Attr { value, .. } => match value {
|
|
@@ -580,13 +597,19 @@ fn member_chain_collect_expr(
|
|
|
580
597
|
member_chain_collect_expr(left, source, lsp_line, lsp_char, best);
|
|
581
598
|
member_chain_collect_expr(right, source, lsp_line, lsp_char, best);
|
|
582
599
|
}
|
|
583
|
-
Expr::Unary { operand, .. } =>
|
|
600
|
+
Expr::Unary { operand, .. } => {
|
|
601
|
+
member_chain_collect_expr(operand, source, lsp_line, lsp_char, best)
|
|
602
|
+
}
|
|
584
603
|
Expr::Call { callee, args, .. } => {
|
|
585
604
|
member_chain_collect_expr(callee, source, lsp_line, lsp_char, best);
|
|
586
605
|
for a in args {
|
|
587
606
|
match a {
|
|
588
|
-
CallArg::Expr(e) =>
|
|
589
|
-
|
|
607
|
+
CallArg::Expr(e) => {
|
|
608
|
+
member_chain_collect_expr(e, source, lsp_line, lsp_char, best)
|
|
609
|
+
}
|
|
610
|
+
CallArg::Spread(e) => {
|
|
611
|
+
member_chain_collect_expr(e, source, lsp_line, lsp_char, best)
|
|
612
|
+
}
|
|
590
613
|
}
|
|
591
614
|
}
|
|
592
615
|
}
|
|
@@ -594,8 +617,12 @@ fn member_chain_collect_expr(
|
|
|
594
617
|
member_chain_collect_expr(callee, source, lsp_line, lsp_char, best);
|
|
595
618
|
for a in args {
|
|
596
619
|
match a {
|
|
597
|
-
CallArg::Expr(e) =>
|
|
598
|
-
|
|
620
|
+
CallArg::Expr(e) => {
|
|
621
|
+
member_chain_collect_expr(e, source, lsp_line, lsp_char, best)
|
|
622
|
+
}
|
|
623
|
+
CallArg::Spread(e) => {
|
|
624
|
+
member_chain_collect_expr(e, source, lsp_line, lsp_char, best)
|
|
625
|
+
}
|
|
599
626
|
}
|
|
600
627
|
}
|
|
601
628
|
}
|
|
@@ -660,10 +687,14 @@ fn member_chain_collect_expr(
|
|
|
660
687
|
}
|
|
661
688
|
}
|
|
662
689
|
}
|
|
663
|
-
Expr::Assign { value, .. }
|
|
690
|
+
Expr::Assign { value, .. }
|
|
691
|
+
| Expr::CompoundAssign { value, .. }
|
|
692
|
+
| Expr::LogicalAssign { value, .. } => {
|
|
664
693
|
member_chain_collect_expr(value, source, lsp_line, lsp_char, best);
|
|
665
694
|
}
|
|
666
|
-
Expr::TypeOf { operand, .. } =>
|
|
695
|
+
Expr::TypeOf { operand, .. } => {
|
|
696
|
+
member_chain_collect_expr(operand, source, lsp_line, lsp_char, best)
|
|
697
|
+
}
|
|
667
698
|
Expr::PostfixInc { .. }
|
|
668
699
|
| Expr::PostfixDec { .. }
|
|
669
700
|
| Expr::PrefixInc { .. }
|
|
@@ -687,8 +718,12 @@ fn member_chain_collect_expr(
|
|
|
687
718
|
member_chain_collect_fun_param(p, source, lsp_line, lsp_char, best);
|
|
688
719
|
}
|
|
689
720
|
match body {
|
|
690
|
-
ArrowBody::Expr(e) =>
|
|
691
|
-
|
|
721
|
+
ArrowBody::Expr(e) => {
|
|
722
|
+
member_chain_collect_expr(e, source, lsp_line, lsp_char, best)
|
|
723
|
+
}
|
|
724
|
+
ArrowBody::Block(b) => {
|
|
725
|
+
member_chain_collect_stmt(b, source, lsp_line, lsp_char, best)
|
|
726
|
+
}
|
|
692
727
|
}
|
|
693
728
|
}
|
|
694
729
|
Expr::TemplateLiteral { exprs, .. } => {
|
|
@@ -696,8 +731,12 @@ fn member_chain_collect_expr(
|
|
|
696
731
|
member_chain_collect_expr(e, source, lsp_line, lsp_char, best);
|
|
697
732
|
}
|
|
698
733
|
}
|
|
699
|
-
Expr::Await { operand, .. } =>
|
|
700
|
-
|
|
734
|
+
Expr::Await { operand, .. } => {
|
|
735
|
+
member_chain_collect_expr(operand, source, lsp_line, lsp_char, best)
|
|
736
|
+
}
|
|
737
|
+
Expr::JsxElement {
|
|
738
|
+
props, children, ..
|
|
739
|
+
} => {
|
|
701
740
|
for p in props {
|
|
702
741
|
match p {
|
|
703
742
|
tishlang_ast::JsxProp::Attr { value, .. } => {
|
|
@@ -758,9 +797,9 @@ fn member_chain_collect_destruct_pattern(
|
|
|
758
797
|
if let Some(el) = el {
|
|
759
798
|
match el {
|
|
760
799
|
DestructElement::Ident(_, _) => {}
|
|
761
|
-
DestructElement::Pattern(inner) =>
|
|
762
|
-
|
|
763
|
-
|
|
800
|
+
DestructElement::Pattern(inner) => member_chain_collect_destruct_pattern(
|
|
801
|
+
inner, source, lsp_line, lsp_char, best,
|
|
802
|
+
),
|
|
764
803
|
DestructElement::Rest(_, _) => {}
|
|
765
804
|
}
|
|
766
805
|
}
|
|
@@ -770,9 +809,9 @@ fn member_chain_collect_destruct_pattern(
|
|
|
770
809
|
for pr in props {
|
|
771
810
|
match &pr.value {
|
|
772
811
|
DestructElement::Ident(_, _) => {}
|
|
773
|
-
DestructElement::Pattern(inner) =>
|
|
774
|
-
|
|
775
|
-
|
|
812
|
+
DestructElement::Pattern(inner) => member_chain_collect_destruct_pattern(
|
|
813
|
+
inner, source, lsp_line, lsp_char, best,
|
|
814
|
+
),
|
|
776
815
|
DestructElement::Rest(_, _) => {}
|
|
777
816
|
}
|
|
778
817
|
}
|
|
@@ -797,7 +836,9 @@ fn member_chain_collect_stmt(
|
|
|
797
836
|
member_chain_collect_destruct_pattern(pattern, source, lsp_line, lsp_char, best);
|
|
798
837
|
member_chain_collect_expr(init, source, lsp_line, lsp_char, best);
|
|
799
838
|
}
|
|
800
|
-
Statement::ExprStmt { expr, .. } =>
|
|
839
|
+
Statement::ExprStmt { expr, .. } => {
|
|
840
|
+
member_chain_collect_expr(expr, source, lsp_line, lsp_char, best)
|
|
841
|
+
}
|
|
801
842
|
Statement::If {
|
|
802
843
|
cond,
|
|
803
844
|
then_branch,
|
|
@@ -874,7 +915,9 @@ fn member_chain_collect_stmt(
|
|
|
874
915
|
member_chain_collect_stmt(body, source, lsp_line, lsp_char, best);
|
|
875
916
|
member_chain_collect_expr(cond, source, lsp_line, lsp_char, best);
|
|
876
917
|
}
|
|
877
|
-
Statement::Throw { value, .. } =>
|
|
918
|
+
Statement::Throw { value, .. } => {
|
|
919
|
+
member_chain_collect_expr(value, source, lsp_line, lsp_char, best)
|
|
920
|
+
}
|
|
878
921
|
Statement::Try {
|
|
879
922
|
body,
|
|
880
923
|
catch_body,
|
|
@@ -890,8 +933,12 @@ fn member_chain_collect_stmt(
|
|
|
890
933
|
}
|
|
891
934
|
}
|
|
892
935
|
Statement::Export { declaration, .. } => match declaration.as_ref() {
|
|
893
|
-
ExportDeclaration::Named(inner) =>
|
|
894
|
-
|
|
936
|
+
ExportDeclaration::Named(inner) => {
|
|
937
|
+
member_chain_collect_stmt(inner, source, lsp_line, lsp_char, best)
|
|
938
|
+
}
|
|
939
|
+
ExportDeclaration::Default(e) => {
|
|
940
|
+
member_chain_collect_expr(e, source, lsp_line, lsp_char, best)
|
|
941
|
+
}
|
|
895
942
|
},
|
|
896
943
|
Statement::Import { .. }
|
|
897
944
|
| Statement::Break { .. }
|
|
@@ -985,7 +1032,12 @@ fn walk_expr_resolve(
|
|
|
985
1032
|
}
|
|
986
1033
|
walk_expr_resolve(value, scopes, target)
|
|
987
1034
|
}
|
|
988
|
-
Expr::CompoundAssign {
|
|
1035
|
+
Expr::CompoundAssign {
|
|
1036
|
+
name, span, value, ..
|
|
1037
|
+
}
|
|
1038
|
+
| Expr::LogicalAssign {
|
|
1039
|
+
name, span, value, ..
|
|
1040
|
+
} => {
|
|
989
1041
|
let sp = synthetic_name_span(span.start, name.as_ref());
|
|
990
1042
|
if sp == tgt && name.as_ref() == target.name.as_ref() {
|
|
991
1043
|
return scopes.resolve(name.as_ref());
|
|
@@ -1023,20 +1075,18 @@ fn walk_expr_resolve(
|
|
|
1023
1075
|
None
|
|
1024
1076
|
})
|
|
1025
1077
|
}
|
|
1026
|
-
Expr::New { callee, args, .. } => {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
return Some(s);
|
|
1035
|
-
}
|
|
1078
|
+
Expr::New { callee, args, .. } => walk_expr_resolve(callee, scopes, target).or_else(|| {
|
|
1079
|
+
for a in args {
|
|
1080
|
+
let e = match a {
|
|
1081
|
+
CallArg::Expr(e) => e,
|
|
1082
|
+
CallArg::Spread(e) => e,
|
|
1083
|
+
};
|
|
1084
|
+
if let Some(s) = walk_expr_resolve(e, scopes, target) {
|
|
1085
|
+
return Some(s);
|
|
1036
1086
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
}
|
|
1087
|
+
}
|
|
1088
|
+
None
|
|
1089
|
+
}),
|
|
1040
1090
|
Expr::Member { object, .. } => walk_expr_resolve(object, scopes, target),
|
|
1041
1091
|
Expr::Index { object, index, .. } => walk_expr_resolve(object, scopes, target)
|
|
1042
1092
|
.or_else(|| walk_expr_resolve(index, scopes, target)),
|
|
@@ -1105,7 +1155,9 @@ fn walk_expr_resolve(
|
|
|
1105
1155
|
None
|
|
1106
1156
|
}
|
|
1107
1157
|
Expr::Await { operand, .. } => walk_expr_resolve(operand, scopes, target),
|
|
1108
|
-
Expr::JsxElement {
|
|
1158
|
+
Expr::JsxElement {
|
|
1159
|
+
props, children, ..
|
|
1160
|
+
} => {
|
|
1109
1161
|
for p in props {
|
|
1110
1162
|
match p {
|
|
1111
1163
|
tishlang_ast::JsxProp::Attr { value, .. } => {
|
|
@@ -1172,11 +1224,7 @@ fn walk_stmt_resolve(
|
|
|
1172
1224
|
scopes.define(name.as_ref(), *name_span);
|
|
1173
1225
|
None
|
|
1174
1226
|
}
|
|
1175
|
-
Statement::VarDeclDestructure {
|
|
1176
|
-
pattern,
|
|
1177
|
-
init,
|
|
1178
|
-
..
|
|
1179
|
-
} => {
|
|
1227
|
+
Statement::VarDeclDestructure { pattern, init, .. } => {
|
|
1180
1228
|
if let Some(s) = walk_expr_resolve(init, scopes, target) {
|
|
1181
1229
|
return Some(s);
|
|
1182
1230
|
}
|
|
@@ -1189,14 +1237,15 @@ fn walk_stmt_resolve(
|
|
|
1189
1237
|
then_branch,
|
|
1190
1238
|
else_branch,
|
|
1191
1239
|
..
|
|
1192
|
-
} =>
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
}
|
|
1240
|
+
} => walk_expr_resolve(cond, scopes, target)
|
|
1241
|
+
.or_else(|| walk_stmt_implicit(then_branch, scopes, target))
|
|
1242
|
+
.or_else(|| {
|
|
1243
|
+
else_branch
|
|
1244
|
+
.as_ref()
|
|
1245
|
+
.and_then(|b| walk_stmt_implicit(b, scopes, target))
|
|
1246
|
+
}),
|
|
1247
|
+
Statement::While { cond, body, .. } => walk_expr_resolve(cond, scopes, target)
|
|
1248
|
+
.or_else(|| walk_stmt_implicit(body, scopes, target)),
|
|
1200
1249
|
Statement::For {
|
|
1201
1250
|
init,
|
|
1202
1251
|
cond,
|
|
@@ -1246,9 +1295,9 @@ fn walk_stmt_resolve(
|
|
|
1246
1295
|
scopes.pop();
|
|
1247
1296
|
r
|
|
1248
1297
|
}
|
|
1249
|
-
Statement::Return { value, .. } =>
|
|
1250
|
-
|
|
1251
|
-
|
|
1298
|
+
Statement::Return { value, .. } => value
|
|
1299
|
+
.as_ref()
|
|
1300
|
+
.and_then(|e| walk_expr_resolve(e, scopes, target)),
|
|
1252
1301
|
Statement::Block { statements, .. } => {
|
|
1253
1302
|
scopes.push();
|
|
1254
1303
|
let mut out = None;
|
|
@@ -1363,7 +1412,10 @@ fn walk_stmt_resolve(
|
|
|
1363
1412
|
alias,
|
|
1364
1413
|
alias_span,
|
|
1365
1414
|
} => {
|
|
1366
|
-
let local = alias
|
|
1415
|
+
let local = alias
|
|
1416
|
+
.as_ref()
|
|
1417
|
+
.map(|a| a.clone())
|
|
1418
|
+
.unwrap_or_else(|| name.clone());
|
|
1367
1419
|
let spn = alias_span.as_ref().unwrap_or(name_span);
|
|
1368
1420
|
if *spn == tgt_span && local.as_ref() == target.name.as_ref() {
|
|
1369
1421
|
return Some(*spn);
|
|
@@ -1390,14 +1442,18 @@ fn walk_stmt_resolve(
|
|
|
1390
1442
|
ExportDeclaration::Named(inner) => walk_stmt_resolve(inner, scopes, target),
|
|
1391
1443
|
ExportDeclaration::Default(e) => walk_expr_resolve(e, scopes, target),
|
|
1392
1444
|
},
|
|
1393
|
-
Statement::TypeAlias {
|
|
1445
|
+
Statement::TypeAlias {
|
|
1446
|
+
name, name_span, ..
|
|
1447
|
+
} => {
|
|
1394
1448
|
if *name_span == tgt_span && name.as_ref() == target.name.as_ref() {
|
|
1395
1449
|
return Some(*name_span);
|
|
1396
1450
|
}
|
|
1397
1451
|
scopes.define(name.as_ref(), *name_span);
|
|
1398
1452
|
None
|
|
1399
1453
|
}
|
|
1400
|
-
Statement::DeclareVar {
|
|
1454
|
+
Statement::DeclareVar {
|
|
1455
|
+
name, name_span, ..
|
|
1456
|
+
} => {
|
|
1401
1457
|
if *name_span == tgt_span && name.as_ref() == target.name.as_ref() {
|
|
1402
1458
|
return Some(*name_span);
|
|
1403
1459
|
}
|
|
@@ -1479,7 +1535,12 @@ pub fn is_runtime_global_ident(name: &str) -> bool {
|
|
|
1479
1535
|
)
|
|
1480
1536
|
}
|
|
1481
1537
|
|
|
1482
|
-
fn record_unresolved(
|
|
1538
|
+
fn record_unresolved(
|
|
1539
|
+
scopes: &ScopeStack,
|
|
1540
|
+
name: &Arc<str>,
|
|
1541
|
+
span: tishlang_ast::Span,
|
|
1542
|
+
out: &mut Vec<UnresolvedIdentifier>,
|
|
1543
|
+
) {
|
|
1483
1544
|
if is_runtime_global_ident(name.as_ref()) {
|
|
1484
1545
|
return;
|
|
1485
1546
|
}
|
|
@@ -1499,7 +1560,12 @@ fn check_unresolved_expr(expr: &Expr, scopes: &ScopeStack, out: &mut Vec<Unresol
|
|
|
1499
1560
|
record_unresolved(scopes, name, sp, out);
|
|
1500
1561
|
check_unresolved_expr(value, scopes, out);
|
|
1501
1562
|
}
|
|
1502
|
-
Expr::CompoundAssign {
|
|
1563
|
+
Expr::CompoundAssign {
|
|
1564
|
+
name, span, value, ..
|
|
1565
|
+
}
|
|
1566
|
+
| Expr::LogicalAssign {
|
|
1567
|
+
name, span, value, ..
|
|
1568
|
+
} => {
|
|
1503
1569
|
let sp = synthetic_name_span(span.start, name.as_ref());
|
|
1504
1570
|
record_unresolved(scopes, name, sp, out);
|
|
1505
1571
|
check_unresolved_expr(value, scopes, out);
|
|
@@ -1611,7 +1677,9 @@ fn check_unresolved_expr(expr: &Expr, scopes: &ScopeStack, out: &mut Vec<Unresol
|
|
|
1611
1677
|
}
|
|
1612
1678
|
}
|
|
1613
1679
|
Expr::Await { operand, .. } => check_unresolved_expr(operand, scopes, out),
|
|
1614
|
-
Expr::JsxElement {
|
|
1680
|
+
Expr::JsxElement {
|
|
1681
|
+
props, children, ..
|
|
1682
|
+
} => {
|
|
1615
1683
|
for p in props {
|
|
1616
1684
|
match p {
|
|
1617
1685
|
tishlang_ast::JsxProp::Attr { value, .. } => {
|
|
@@ -1639,7 +1707,11 @@ fn check_unresolved_expr(expr: &Expr, scopes: &ScopeStack, out: &mut Vec<Unresol
|
|
|
1639
1707
|
}
|
|
1640
1708
|
}
|
|
1641
1709
|
|
|
1642
|
-
fn check_stmt_implicit_unresolved(
|
|
1710
|
+
fn check_stmt_implicit_unresolved(
|
|
1711
|
+
stmt: &Statement,
|
|
1712
|
+
scopes: &mut ScopeStack,
|
|
1713
|
+
out: &mut Vec<UnresolvedIdentifier>,
|
|
1714
|
+
) {
|
|
1643
1715
|
if matches!(stmt, Statement::Block { .. }) {
|
|
1644
1716
|
check_unresolved_stmt(stmt, scopes, out);
|
|
1645
1717
|
} else {
|
|
@@ -1649,7 +1721,11 @@ fn check_stmt_implicit_unresolved(stmt: &Statement, scopes: &mut ScopeStack, out
|
|
|
1649
1721
|
}
|
|
1650
1722
|
}
|
|
1651
1723
|
|
|
1652
|
-
fn check_unresolved_stmt(
|
|
1724
|
+
fn check_unresolved_stmt(
|
|
1725
|
+
stmt: &Statement,
|
|
1726
|
+
scopes: &mut ScopeStack,
|
|
1727
|
+
out: &mut Vec<UnresolvedIdentifier>,
|
|
1728
|
+
) {
|
|
1653
1729
|
match stmt {
|
|
1654
1730
|
Statement::VarDecl {
|
|
1655
1731
|
name,
|
|
@@ -1799,7 +1875,10 @@ fn check_unresolved_stmt(stmt: &Statement, scopes: &mut ScopeStack, out: &mut Ve
|
|
|
1799
1875
|
alias,
|
|
1800
1876
|
alias_span,
|
|
1801
1877
|
} => {
|
|
1802
|
-
let local = alias
|
|
1878
|
+
let local = alias
|
|
1879
|
+
.as_ref()
|
|
1880
|
+
.map(|a| a.clone())
|
|
1881
|
+
.unwrap_or_else(|| name.clone());
|
|
1803
1882
|
let spn = alias_span.as_ref().unwrap_or(name_span);
|
|
1804
1883
|
scopes.define(local.as_ref(), *spn);
|
|
1805
1884
|
}
|
|
@@ -1816,10 +1895,14 @@ fn check_unresolved_stmt(stmt: &Statement, scopes: &mut ScopeStack, out: &mut Ve
|
|
|
1816
1895
|
ExportDeclaration::Named(inner) => check_unresolved_stmt(inner, scopes, out),
|
|
1817
1896
|
ExportDeclaration::Default(e) => check_unresolved_expr(e, scopes, out),
|
|
1818
1897
|
},
|
|
1819
|
-
Statement::TypeAlias {
|
|
1898
|
+
Statement::TypeAlias {
|
|
1899
|
+
name, name_span, ..
|
|
1900
|
+
} => {
|
|
1820
1901
|
scopes.define(name.as_ref(), *name_span);
|
|
1821
1902
|
}
|
|
1822
|
-
Statement::DeclareVar {
|
|
1903
|
+
Statement::DeclareVar {
|
|
1904
|
+
name, name_span, ..
|
|
1905
|
+
} => {
|
|
1823
1906
|
scopes.define(name.as_ref(), *name_span);
|
|
1824
1907
|
}
|
|
1825
1908
|
Statement::DeclareFun {
|
|
@@ -1942,9 +2025,7 @@ fn enumerate_fun_param(p: &FunParam, exported: bool, out: &mut Vec<BindingSite>)
|
|
|
1942
2025
|
}
|
|
1943
2026
|
}
|
|
1944
2027
|
FunParam::Destructure {
|
|
1945
|
-
pattern,
|
|
1946
|
-
default,
|
|
1947
|
-
..
|
|
2028
|
+
pattern, default, ..
|
|
1948
2029
|
} => {
|
|
1949
2030
|
enumerate_pattern_bindings(pattern, UnusedBindingKind::Parameter, exported, out);
|
|
1950
2031
|
if let Some(e) = default {
|
|
@@ -2063,7 +2144,9 @@ fn enumerate_expr(expr: &Expr, exported: bool, out: &mut Vec<BindingSite>) {
|
|
|
2063
2144
|
}
|
|
2064
2145
|
}
|
|
2065
2146
|
Expr::Await { operand, .. } => enumerate_expr(operand, exported, out),
|
|
2066
|
-
Expr::JsxElement {
|
|
2147
|
+
Expr::JsxElement {
|
|
2148
|
+
props, children, ..
|
|
2149
|
+
} => {
|
|
2067
2150
|
for p in props {
|
|
2068
2151
|
match p {
|
|
2069
2152
|
tishlang_ast::JsxProp::Attr { value, .. } => {
|
|
@@ -2101,7 +2184,10 @@ fn enumerate_stmt(stmt: &Statement, exported: bool, out: &mut Vec<BindingSite>)
|
|
|
2101
2184
|
alias,
|
|
2102
2185
|
alias_span,
|
|
2103
2186
|
} => {
|
|
2104
|
-
let local = alias
|
|
2187
|
+
let local = alias
|
|
2188
|
+
.as_ref()
|
|
2189
|
+
.map(|a| a.clone())
|
|
2190
|
+
.unwrap_or_else(|| name.clone());
|
|
2105
2191
|
let spn = alias_span.as_ref().unwrap_or(name_span);
|
|
2106
2192
|
out.push(BindingSite {
|
|
2107
2193
|
name: local,
|
|
@@ -2289,7 +2375,9 @@ fn enumerate_stmt(stmt: &Statement, exported: bool, out: &mut Vec<BindingSite>)
|
|
|
2289
2375
|
enumerate_stmt(fb, exported, out);
|
|
2290
2376
|
}
|
|
2291
2377
|
}
|
|
2292
|
-
Statement::TypeAlias {
|
|
2378
|
+
Statement::TypeAlias {
|
|
2379
|
+
name, name_span, ..
|
|
2380
|
+
} => {
|
|
2293
2381
|
out.push(BindingSite {
|
|
2294
2382
|
name: name.clone(),
|
|
2295
2383
|
span: *name_span,
|
|
@@ -2297,7 +2385,9 @@ fn enumerate_stmt(stmt: &Statement, exported: bool, out: &mut Vec<BindingSite>)
|
|
|
2297
2385
|
exported,
|
|
2298
2386
|
});
|
|
2299
2387
|
}
|
|
2300
|
-
Statement::DeclareVar {
|
|
2388
|
+
Statement::DeclareVar {
|
|
2389
|
+
name, name_span, ..
|
|
2390
|
+
} => {
|
|
2301
2391
|
out.push(BindingSite {
|
|
2302
2392
|
name: name.clone(),
|
|
2303
2393
|
span: *name_span,
|
|
@@ -2402,29 +2492,19 @@ fn collect_block_locals(
|
|
|
2402
2492
|
for st in statements {
|
|
2403
2493
|
match st {
|
|
2404
2494
|
Statement::VarDecl {
|
|
2405
|
-
name,
|
|
2406
|
-
name_span,
|
|
2407
|
-
..
|
|
2495
|
+
name, name_span, ..
|
|
2408
2496
|
} => out.push((name.clone(), *name_span)),
|
|
2409
2497
|
Statement::FunDecl {
|
|
2410
|
-
name,
|
|
2411
|
-
name_span,
|
|
2412
|
-
..
|
|
2498
|
+
name, name_span, ..
|
|
2413
2499
|
} => out.push((name.clone(), *name_span)),
|
|
2414
2500
|
Statement::TypeAlias {
|
|
2415
|
-
name,
|
|
2416
|
-
name_span,
|
|
2417
|
-
..
|
|
2501
|
+
name, name_span, ..
|
|
2418
2502
|
} => out.push((name.clone(), *name_span)),
|
|
2419
2503
|
Statement::DeclareVar {
|
|
2420
|
-
name,
|
|
2421
|
-
name_span,
|
|
2422
|
-
..
|
|
2504
|
+
name, name_span, ..
|
|
2423
2505
|
} => out.push((name.clone(), *name_span)),
|
|
2424
2506
|
Statement::DeclareFun {
|
|
2425
|
-
name,
|
|
2426
|
-
name_span,
|
|
2427
|
-
..
|
|
2507
|
+
name, name_span, ..
|
|
2428
2508
|
} => out.push((name.clone(), *name_span)),
|
|
2429
2509
|
_ => {}
|
|
2430
2510
|
}
|
|
@@ -2445,7 +2525,12 @@ fn collect_block_locals(
|
|
|
2445
2525
|
..
|
|
2446
2526
|
} => {
|
|
2447
2527
|
if pos::span_contains_lsp_position(source, span, lsp_line, lsp_char)
|
|
2448
|
-
&& pos::span_contains_lsp_position(
|
|
2528
|
+
&& pos::span_contains_lsp_position(
|
|
2529
|
+
source,
|
|
2530
|
+
&body.as_ref().span(),
|
|
2531
|
+
lsp_line,
|
|
2532
|
+
lsp_char,
|
|
2533
|
+
)
|
|
2449
2534
|
{
|
|
2450
2535
|
out.push((name.clone(), *name_span));
|
|
2451
2536
|
}
|
|
@@ -2467,7 +2552,9 @@ fn collect_block_locals(
|
|
|
2467
2552
|
}
|
|
2468
2553
|
collect_block_locals(body, source, lsp_line, lsp_char, out);
|
|
2469
2554
|
}
|
|
2470
|
-
Statement::DoWhile { body, .. } =>
|
|
2555
|
+
Statement::DoWhile { body, .. } => {
|
|
2556
|
+
collect_block_locals(body, source, lsp_line, lsp_char, out)
|
|
2557
|
+
}
|
|
2471
2558
|
Statement::Try {
|
|
2472
2559
|
body,
|
|
2473
2560
|
catch_param,
|
|
@@ -2478,7 +2565,8 @@ fn collect_block_locals(
|
|
|
2478
2565
|
} => {
|
|
2479
2566
|
collect_block_locals(body, source, lsp_line, lsp_char, out);
|
|
2480
2567
|
if let (Some(n), Some(ps), Some(cb)) = (catch_param, catch_param_span, catch_body) {
|
|
2481
|
-
if pos::span_contains_lsp_position(source, &cb.as_ref().span(), lsp_line, lsp_char)
|
|
2568
|
+
if pos::span_contains_lsp_position(source, &cb.as_ref().span(), lsp_line, lsp_char)
|
|
2569
|
+
{
|
|
2482
2570
|
out.push((n.clone(), *ps));
|
|
2483
2571
|
}
|
|
2484
2572
|
collect_block_locals(cb, source, lsp_line, lsp_char, out);
|
|
@@ -2487,7 +2575,11 @@ fn collect_block_locals(
|
|
|
2487
2575
|
collect_block_locals(fb, source, lsp_line, lsp_char, out);
|
|
2488
2576
|
}
|
|
2489
2577
|
}
|
|
2490
|
-
Statement::Switch {
|
|
2578
|
+
Statement::Switch {
|
|
2579
|
+
cases,
|
|
2580
|
+
default_body,
|
|
2581
|
+
..
|
|
2582
|
+
} => {
|
|
2491
2583
|
for (_ce, stmts) in cases {
|
|
2492
2584
|
for st in stmts {
|
|
2493
2585
|
collect_block_locals(st, source, lsp_line, lsp_char, out);
|
|
@@ -2529,7 +2621,9 @@ fn collect_pattern_binding_names(pattern: &DestructPattern, out: &mut Vec<Arc<st
|
|
|
2529
2621
|
if let Some(el) = el {
|
|
2530
2622
|
match el {
|
|
2531
2623
|
DestructElement::Ident(n, _) => out.push(n.clone()),
|
|
2532
|
-
DestructElement::Pattern(inner) =>
|
|
2624
|
+
DestructElement::Pattern(inner) => {
|
|
2625
|
+
collect_pattern_binding_names(inner, out)
|
|
2626
|
+
}
|
|
2533
2627
|
DestructElement::Rest(n, _) => out.push(n.clone()),
|
|
2534
2628
|
}
|
|
2535
2629
|
}
|
|
@@ -2547,10 +2641,7 @@ fn collect_pattern_binding_names(pattern: &DestructPattern, out: &mut Vec<Arc<st
|
|
|
2547
2641
|
}
|
|
2548
2642
|
}
|
|
2549
2643
|
|
|
2550
|
-
fn record_callable_stack(
|
|
2551
|
-
stack: &[Vec<Arc<str>>],
|
|
2552
|
-
best: &mut Option<(usize, Vec<Arc<str>>)>,
|
|
2553
|
-
) {
|
|
2644
|
+
fn record_callable_stack(stack: &[Vec<Arc<str>>], best: &mut Option<(usize, Vec<Arc<str>>)>) {
|
|
2554
2645
|
let depth = stack.len();
|
|
2555
2646
|
let flat: Vec<Arc<str>> = stack
|
|
2556
2647
|
.iter()
|
|
@@ -2588,14 +2679,18 @@ fn walk_expr_completion(
|
|
|
2588
2679
|
walk_expr_completion(e, source, lsp_line, lsp_char, stack, best);
|
|
2589
2680
|
}
|
|
2590
2681
|
}
|
|
2591
|
-
FunParam::Destructure {
|
|
2682
|
+
FunParam::Destructure {
|
|
2683
|
+
default: Some(e), ..
|
|
2684
|
+
} => {
|
|
2592
2685
|
walk_expr_completion(e, source, lsp_line, lsp_char, stack, best);
|
|
2593
2686
|
}
|
|
2594
2687
|
_ => {}
|
|
2595
2688
|
}
|
|
2596
2689
|
}
|
|
2597
2690
|
match body {
|
|
2598
|
-
ArrowBody::Expr(e) =>
|
|
2691
|
+
ArrowBody::Expr(e) => {
|
|
2692
|
+
walk_expr_completion(e, source, lsp_line, lsp_char, stack, best)
|
|
2693
|
+
}
|
|
2599
2694
|
ArrowBody::Block(b) => {
|
|
2600
2695
|
walk_stmt_completion(b, source, lsp_line, lsp_char, stack, best);
|
|
2601
2696
|
}
|
|
@@ -2606,7 +2701,9 @@ fn walk_expr_completion(
|
|
|
2606
2701
|
walk_expr_completion(left, source, lsp_line, lsp_char, stack, best);
|
|
2607
2702
|
walk_expr_completion(right, source, lsp_line, lsp_char, stack, best);
|
|
2608
2703
|
}
|
|
2609
|
-
Expr::Unary { operand, .. } =>
|
|
2704
|
+
Expr::Unary { operand, .. } => {
|
|
2705
|
+
walk_expr_completion(operand, source, lsp_line, lsp_char, stack, best)
|
|
2706
|
+
}
|
|
2610
2707
|
Expr::Call { callee, args, .. } => {
|
|
2611
2708
|
walk_expr_completion(callee, source, lsp_line, lsp_char, stack, best);
|
|
2612
2709
|
for a in args {
|
|
@@ -2627,7 +2724,9 @@ fn walk_expr_completion(
|
|
|
2627
2724
|
walk_expr_completion(e, source, lsp_line, lsp_char, stack, best);
|
|
2628
2725
|
}
|
|
2629
2726
|
}
|
|
2630
|
-
Expr::Member { object, .. } =>
|
|
2727
|
+
Expr::Member { object, .. } => {
|
|
2728
|
+
walk_expr_completion(object, source, lsp_line, lsp_char, stack, best)
|
|
2729
|
+
}
|
|
2631
2730
|
Expr::Index { object, index, .. } => {
|
|
2632
2731
|
walk_expr_completion(object, source, lsp_line, lsp_char, stack, best);
|
|
2633
2732
|
walk_expr_completion(index, source, lsp_line, lsp_char, stack, best);
|
|
@@ -2669,7 +2768,9 @@ fn walk_expr_completion(
|
|
|
2669
2768
|
| Expr::LogicalAssign { value, .. } => {
|
|
2670
2769
|
walk_expr_completion(value, source, lsp_line, lsp_char, stack, best);
|
|
2671
2770
|
}
|
|
2672
|
-
Expr::TypeOf { operand, .. } =>
|
|
2771
|
+
Expr::TypeOf { operand, .. } => {
|
|
2772
|
+
walk_expr_completion(operand, source, lsp_line, lsp_char, stack, best)
|
|
2773
|
+
}
|
|
2673
2774
|
Expr::MemberAssign { object, value, .. } => {
|
|
2674
2775
|
walk_expr_completion(object, source, lsp_line, lsp_char, stack, best);
|
|
2675
2776
|
walk_expr_completion(value, source, lsp_line, lsp_char, stack, best);
|
|
@@ -2689,8 +2790,12 @@ fn walk_expr_completion(
|
|
|
2689
2790
|
walk_expr_completion(e, source, lsp_line, lsp_char, stack, best);
|
|
2690
2791
|
}
|
|
2691
2792
|
}
|
|
2692
|
-
Expr::Await { operand, .. } =>
|
|
2693
|
-
|
|
2793
|
+
Expr::Await { operand, .. } => {
|
|
2794
|
+
walk_expr_completion(operand, source, lsp_line, lsp_char, stack, best)
|
|
2795
|
+
}
|
|
2796
|
+
Expr::JsxElement {
|
|
2797
|
+
props, children, ..
|
|
2798
|
+
} => {
|
|
2694
2799
|
for p in props {
|
|
2695
2800
|
match p {
|
|
2696
2801
|
tishlang_ast::JsxProp::Attr { value, .. } => {
|
|
@@ -2823,7 +2928,9 @@ fn walk_stmt_completion(
|
|
|
2823
2928
|
walk_expr_completion(e, source, lsp_line, lsp_char, stack, best);
|
|
2824
2929
|
}
|
|
2825
2930
|
}
|
|
2826
|
-
FunParam::Destructure {
|
|
2931
|
+
FunParam::Destructure {
|
|
2932
|
+
default: Some(e), ..
|
|
2933
|
+
} => {
|
|
2827
2934
|
walk_expr_completion(e, source, lsp_line, lsp_char, stack, best);
|
|
2828
2935
|
}
|
|
2829
2936
|
_ => {}
|
|
@@ -2943,14 +3050,10 @@ pub fn shallow_module_bindings(program: &Program) -> Vec<(Arc<str>, tishlang_ast
|
|
|
2943
3050
|
for s in &program.statements {
|
|
2944
3051
|
match s {
|
|
2945
3052
|
Statement::VarDecl {
|
|
2946
|
-
name,
|
|
2947
|
-
name_span,
|
|
2948
|
-
..
|
|
3053
|
+
name, name_span, ..
|
|
2949
3054
|
} => out.push((name.clone(), *name_span)),
|
|
2950
3055
|
Statement::FunDecl {
|
|
2951
|
-
name,
|
|
2952
|
-
name_span,
|
|
2953
|
-
..
|
|
3056
|
+
name, name_span, ..
|
|
2954
3057
|
} => out.push((name.clone(), *name_span)),
|
|
2955
3058
|
Statement::Import { specifiers, .. } => {
|
|
2956
3059
|
for sp in specifiers {
|
|
@@ -2961,7 +3064,10 @@ pub fn shallow_module_bindings(program: &Program) -> Vec<(Arc<str>, tishlang_ast
|
|
|
2961
3064
|
alias,
|
|
2962
3065
|
alias_span,
|
|
2963
3066
|
} => {
|
|
2964
|
-
let local = alias
|
|
3067
|
+
let local = alias
|
|
3068
|
+
.as_ref()
|
|
3069
|
+
.map(|a| a.clone())
|
|
3070
|
+
.unwrap_or_else(|| name.clone());
|
|
2965
3071
|
let spn = alias_span.as_ref().unwrap_or(name_span);
|
|
2966
3072
|
out.push((local, *spn));
|
|
2967
3073
|
}
|
|
@@ -2978,14 +3084,10 @@ pub fn shallow_module_bindings(program: &Program) -> Vec<(Arc<str>, tishlang_ast
|
|
|
2978
3084
|
if let ExportDeclaration::Named(inner) = declaration.as_ref() {
|
|
2979
3085
|
match inner.as_ref() {
|
|
2980
3086
|
Statement::VarDecl {
|
|
2981
|
-
name,
|
|
2982
|
-
name_span,
|
|
2983
|
-
..
|
|
3087
|
+
name, name_span, ..
|
|
2984
3088
|
} => out.push((name.clone(), *name_span)),
|
|
2985
3089
|
Statement::FunDecl {
|
|
2986
|
-
name,
|
|
2987
|
-
name_span,
|
|
2988
|
-
..
|
|
3090
|
+
name, name_span, ..
|
|
2989
3091
|
} => out.push((name.clone(), *name_span)),
|
|
2990
3092
|
_ => {}
|
|
2991
3093
|
}
|
|
@@ -3027,7 +3129,9 @@ fn refs_stmt(
|
|
|
3027
3129
|
refs_expr(e, program, source, name, def_span, out);
|
|
3028
3130
|
}
|
|
3029
3131
|
}
|
|
3030
|
-
Statement::VarDeclDestructure { init, .. } =>
|
|
3132
|
+
Statement::VarDeclDestructure { init, .. } => {
|
|
3133
|
+
refs_expr(init, program, source, name, def_span, out)
|
|
3134
|
+
}
|
|
3031
3135
|
Statement::ExprStmt { expr, .. } => refs_expr(expr, program, source, name, def_span, out),
|
|
3032
3136
|
Statement::If {
|
|
3033
3137
|
cond,
|
|
@@ -3063,11 +3167,7 @@ fn refs_stmt(
|
|
|
3063
3167
|
}
|
|
3064
3168
|
refs_stmt(body, program, source, name, def_span, out);
|
|
3065
3169
|
}
|
|
3066
|
-
Statement::ForOf {
|
|
3067
|
-
iterable,
|
|
3068
|
-
body,
|
|
3069
|
-
..
|
|
3070
|
-
} => {
|
|
3170
|
+
Statement::ForOf { iterable, body, .. } => {
|
|
3071
3171
|
refs_expr(iterable, program, source, name, def_span, out);
|
|
3072
3172
|
refs_stmt(body, program, source, name, def_span, out);
|
|
3073
3173
|
}
|
|
@@ -3087,7 +3187,10 @@ fn refs_stmt(
|
|
|
3087
3187
|
if let Some(e) = &tp.default {
|
|
3088
3188
|
refs_expr(e, program, source, name, def_span, out);
|
|
3089
3189
|
}
|
|
3090
|
-
} else if let FunParam::Destructure {
|
|
3190
|
+
} else if let FunParam::Destructure {
|
|
3191
|
+
default: Some(e), ..
|
|
3192
|
+
} = p
|
|
3193
|
+
{
|
|
3091
3194
|
refs_expr(e, program, source, name, def_span, out);
|
|
3092
3195
|
}
|
|
3093
3196
|
}
|
|
@@ -3148,17 +3251,18 @@ fn refs_expr(
|
|
|
3148
3251
|
def_span: tishlang_ast::Span,
|
|
3149
3252
|
out: &mut Vec<tishlang_ast::Span>,
|
|
3150
3253
|
) {
|
|
3151
|
-
let maybe_push =
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3254
|
+
let maybe_push =
|
|
3255
|
+
|span: &tishlang_ast::Span, n: &Arc<str>, out: &mut Vec<tishlang_ast::Span>| {
|
|
3256
|
+
if n.as_ref() != name {
|
|
3257
|
+
return;
|
|
3258
|
+
}
|
|
3259
|
+
let Some((l, c)) = pos::lsp_position_for_span_start(source, span) else {
|
|
3260
|
+
return;
|
|
3261
|
+
};
|
|
3262
|
+
if definition_span(program, source, l, c) == Some(def_span) {
|
|
3263
|
+
out.push(*span);
|
|
3264
|
+
}
|
|
3157
3265
|
};
|
|
3158
|
-
if definition_span(program, source, l, c) == Some(def_span) {
|
|
3159
|
-
out.push(*span);
|
|
3160
|
-
}
|
|
3161
|
-
};
|
|
3162
3266
|
|
|
3163
3267
|
match expr {
|
|
3164
3268
|
Expr::Ident { name: n, span } => maybe_push(span, n, out),
|
|
@@ -3230,7 +3334,11 @@ fn refs_expr(
|
|
|
3230
3334
|
}
|
|
3231
3335
|
}
|
|
3232
3336
|
}
|
|
3233
|
-
Expr::Assign {
|
|
3337
|
+
Expr::Assign {
|
|
3338
|
+
name: n,
|
|
3339
|
+
span,
|
|
3340
|
+
value,
|
|
3341
|
+
} => {
|
|
3234
3342
|
let sp = synthetic_name_span(span.start, n.as_ref());
|
|
3235
3343
|
maybe_push(&sp, n, out);
|
|
3236
3344
|
refs_expr(value, program, source, name, def_span, out);
|
|
@@ -3244,8 +3352,18 @@ fn refs_expr(
|
|
|
3244
3352
|
let sp = synthetic_name_span(span.start, n.as_ref());
|
|
3245
3353
|
maybe_push(&sp, n, out);
|
|
3246
3354
|
}
|
|
3247
|
-
Expr::CompoundAssign {
|
|
3248
|
-
|
|
3355
|
+
Expr::CompoundAssign {
|
|
3356
|
+
name: n,
|
|
3357
|
+
span,
|
|
3358
|
+
value,
|
|
3359
|
+
..
|
|
3360
|
+
}
|
|
3361
|
+
| Expr::LogicalAssign {
|
|
3362
|
+
name: n,
|
|
3363
|
+
span,
|
|
3364
|
+
value,
|
|
3365
|
+
..
|
|
3366
|
+
} => {
|
|
3249
3367
|
let sp = synthetic_name_span(span.start, n.as_ref());
|
|
3250
3368
|
maybe_push(&sp, n, out);
|
|
3251
3369
|
refs_expr(value, program, source, name, def_span, out);
|
|
@@ -3270,7 +3388,10 @@ fn refs_expr(
|
|
|
3270
3388
|
if let Some(e) = &tp.default {
|
|
3271
3389
|
refs_expr(e, program, source, name, def_span, out);
|
|
3272
3390
|
}
|
|
3273
|
-
} else if let FunParam::Destructure {
|
|
3391
|
+
} else if let FunParam::Destructure {
|
|
3392
|
+
default: Some(e), ..
|
|
3393
|
+
} = p
|
|
3394
|
+
{
|
|
3274
3395
|
refs_expr(e, program, source, name, def_span, out);
|
|
3275
3396
|
}
|
|
3276
3397
|
}
|
|
@@ -3285,7 +3406,9 @@ fn refs_expr(
|
|
|
3285
3406
|
}
|
|
3286
3407
|
}
|
|
3287
3408
|
Expr::Await { operand, .. } => refs_expr(operand, program, source, name, def_span, out),
|
|
3288
|
-
Expr::JsxElement {
|
|
3409
|
+
Expr::JsxElement {
|
|
3410
|
+
props, children, ..
|
|
3411
|
+
} => {
|
|
3289
3412
|
for p in props {
|
|
3290
3413
|
match p {
|
|
3291
3414
|
tishlang_ast::JsxProp::Attr { value, .. } => {
|
|
@@ -3293,7 +3416,9 @@ fn refs_expr(
|
|
|
3293
3416
|
refs_expr(e, program, source, name, def_span, out);
|
|
3294
3417
|
}
|
|
3295
3418
|
}
|
|
3296
|
-
tishlang_ast::JsxProp::Spread(e) =>
|
|
3419
|
+
tishlang_ast::JsxProp::Spread(e) => {
|
|
3420
|
+
refs_expr(e, program, source, name, def_span, out)
|
|
3421
|
+
}
|
|
3297
3422
|
}
|
|
3298
3423
|
}
|
|
3299
3424
|
for ch in children {
|