Skip to content

Commit

Permalink
fix(es/dep-graph): Analyze import type children (#7883)
Browse files Browse the repository at this point in the history
**Description:**

It was not analyzing children of a dynamic imports.
  • Loading branch information
dsherret authored Aug 29, 2023
1 parent 44de87f commit 057bd5f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions crates/swc_ecma_dep_graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ impl<'a> Visit for DependencyCollector<'a> {
specifier_span: node.arg.span,
import_attributes: Default::default(),
});
node.visit_children_with(self);
}

fn visit_module_items(&mut self, items: &[ast::ModuleItem]) {
Expand Down Expand Up @@ -810,4 +811,47 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
]
);
}

#[test]
fn ts_import_object_lit_property() {
let source = r#"
export declare const SomeValue: typeof Core & import("./a.d.ts").Constructor<{
paginate: import("./b.d.ts").PaginateInterface;
} & import("./c.d.ts").RestEndpointMethods>;
"#;
let (module, comments) = helper("test.ts", source).unwrap();
let dependencies = analyze_dependencies(&module, &comments);
assert_eq!(
dependencies,
vec![
DependencyDescriptor {
kind: DependencyKind::ImportType,
is_dynamic: false,
leading_comments: Vec::new(),
span: Span::new(BytePos(48), BytePos(176), Default::default()),
specifier: JsWord::from("./a.d.ts"),
specifier_span: Span::new(BytePos(55), BytePos(65), Default::default()),
import_attributes: ImportAttributes::None,
},
DependencyDescriptor {
kind: DependencyKind::ImportType,
is_dynamic: false,
leading_comments: Vec::new(),
span: Span::new(BytePos(95), BytePos(131), Default::default()),
specifier: JsWord::from("./b.d.ts"),
specifier_span: Span::new(BytePos(102), BytePos(112), Default::default()),
import_attributes: ImportAttributes::None,
},
DependencyDescriptor {
kind: DependencyKind::ImportType,
is_dynamic: false,
leading_comments: Vec::new(),
span: Span::new(BytePos(137), BytePos(175), Default::default()),
specifier: JsWord::from("./c.d.ts"),
specifier_span: Span::new(BytePos(144), BytePos(154), Default::default()),
import_attributes: ImportAttributes::None,
}
]
);
}
}

1 comment on commit 057bd5f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 057bd5f Previous: a97d8b4 Ratio
es/full/bugs-1 287815 ns/iter (± 7460) 286409 ns/iter (± 3445) 1.00
es/full/minify/libraries/antd 1405333116 ns/iter (± 17684766) 1330485391 ns/iter (± 21464066) 1.06
es/full/minify/libraries/d3 287995335 ns/iter (± 2350086) 272019100 ns/iter (± 6472416) 1.06
es/full/minify/libraries/echarts 1132260295 ns/iter (± 13448868) 1062288245 ns/iter (± 6083769) 1.07
es/full/minify/libraries/jquery 86091765 ns/iter (± 501548) 83744966 ns/iter (± 324813) 1.03
es/full/minify/libraries/lodash 99012935 ns/iter (± 795542) 96785184 ns/iter (± 774628) 1.02
es/full/minify/libraries/moment 51397756 ns/iter (± 462699) 49413024 ns/iter (± 125337) 1.04
es/full/minify/libraries/react 18405070 ns/iter (± 151662) 17917890 ns/iter (± 34617) 1.03
es/full/minify/libraries/terser 228301801 ns/iter (± 3840616) 216457785 ns/iter (± 1201227) 1.05
es/full/minify/libraries/three 417697433 ns/iter (± 5348116) 387795180 ns/iter (± 1682775) 1.08
es/full/minify/libraries/typescript 2792774919 ns/iter (± 24108622) 2641396390 ns/iter (± 10568191) 1.06
es/full/minify/libraries/victory 628533291 ns/iter (± 14397102) 575760842 ns/iter (± 8933145) 1.09
es/full/minify/libraries/vue 123021088 ns/iter (± 1471701) 119030550 ns/iter (± 311565) 1.03
es/full/codegen/es3 33165 ns/iter (± 141) 34334 ns/iter (± 85) 0.97
es/full/codegen/es5 33131 ns/iter (± 124) 34202 ns/iter (± 62) 0.97
es/full/codegen/es2015 33184 ns/iter (± 129) 34219 ns/iter (± 65) 0.97
es/full/codegen/es2016 33334 ns/iter (± 97) 34142 ns/iter (± 96) 0.98
es/full/codegen/es2017 33286 ns/iter (± 61) 34224 ns/iter (± 63) 0.97
es/full/codegen/es2018 33090 ns/iter (± 44) 34189 ns/iter (± 50) 0.97
es/full/codegen/es2019 33305 ns/iter (± 93) 34180 ns/iter (± 110) 0.97
es/full/codegen/es2020 33153 ns/iter (± 88) 34241 ns/iter (± 87) 0.97
es/full/all/es3 169723357 ns/iter (± 1292767) 168381528 ns/iter (± 804909) 1.01
es/full/all/es5 161874558 ns/iter (± 1810073) 160248005 ns/iter (± 722127) 1.01
es/full/all/es2015 120811810 ns/iter (± 1226729) 120210543 ns/iter (± 434546) 1.01
es/full/all/es2016 120303332 ns/iter (± 776693) 118736584 ns/iter (± 1624975) 1.01
es/full/all/es2017 119584636 ns/iter (± 629054) 117707886 ns/iter (± 487077) 1.02
es/full/all/es2018 117450005 ns/iter (± 1285293) 116386505 ns/iter (± 569417) 1.01
es/full/all/es2019 116955547 ns/iter (± 992982) 115311252 ns/iter (± 498242) 1.01
es/full/all/es2020 112137960 ns/iter (± 733892) 111186240 ns/iter (± 613412) 1.01
es/full/parser 492966 ns/iter (± 2035) 490348 ns/iter (± 4521) 1.01
es/full/base/fixer 18827 ns/iter (± 121) 18390 ns/iter (± 125) 1.02
es/full/base/resolver_and_hygiene 79267 ns/iter (± 122) 80428 ns/iter (± 149) 0.99
serialization of serde 298 ns/iter (± 0) 292 ns/iter (± 0) 1.02
css/minify/libraries/bootstrap 28740005 ns/iter (± 147258) 28229042 ns/iter (± 68664) 1.02
css/visitor/compare/clone 1625372 ns/iter (± 4799) 1631664 ns/iter (± 2504) 1.00
css/visitor/compare/visit_mut_span 1767248 ns/iter (± 5116) 1757936 ns/iter (± 3744) 1.01
css/visitor/compare/visit_mut_span_panic 1840393 ns/iter (± 5437) 1843832 ns/iter (± 5678) 1.00
css/visitor/compare/fold_span 2567335 ns/iter (± 8660) 2566659 ns/iter (± 3624) 1.00
css/visitor/compare/fold_span_panic 2759888 ns/iter (± 7587) 2747954 ns/iter (± 7243) 1.00
css/lexer/bootstrap_5_1_3 4739614 ns/iter (± 5411) 4504425 ns/iter (± 2007) 1.05
css/lexer/foundation_6_7_4 4003072 ns/iter (± 2757) 3794367 ns/iter (± 5628) 1.06
css/lexer/tailwind_3_1_1 758103 ns/iter (± 364) 717270 ns/iter (± 515) 1.06
css/parser/bootstrap_5_1_3 20122062 ns/iter (± 65793) 19744747 ns/iter (± 42525) 1.02
css/parser/foundation_6_7_4 16307797 ns/iter (± 66607) 16036984 ns/iter (± 23059) 1.02
css/parser/tailwind_3_1_1 3095110 ns/iter (± 6547) 3014346 ns/iter (± 5894) 1.03
es/codegen/colors 739064 ns/iter (± 404414) 739966 ns/iter (± 403245) 1.00
es/codegen/large 2908646 ns/iter (± 1544284) 3148913 ns/iter (± 1667138) 0.92
es/codegen/with-parser/colors 46026 ns/iter (± 268) 48711 ns/iter (± 245) 0.94
es/codegen/with-parser/large 486760 ns/iter (± 1005) 529485 ns/iter (± 1448) 0.92
es/minify/libraries/antd 1232615667 ns/iter (± 18043789) 1170851208 ns/iter (± 13944527) 1.05
es/minify/libraries/d3 251051130 ns/iter (± 3289775) 241031551 ns/iter (± 987084) 1.04
es/minify/libraries/echarts 981963423 ns/iter (± 10311379) 925371030 ns/iter (± 5399711) 1.06
es/minify/libraries/jquery 74353751 ns/iter (± 410082) 73100826 ns/iter (± 174817) 1.02
es/minify/libraries/lodash 87953562 ns/iter (± 482501) 86920181 ns/iter (± 125654) 1.01
es/minify/libraries/moment 43894674 ns/iter (± 371826) 43237993 ns/iter (± 98002) 1.02
es/minify/libraries/react 16136784 ns/iter (± 63938) 15971887 ns/iter (± 93654) 1.01
es/minify/libraries/terser 191599196 ns/iter (± 1257174) 187007341 ns/iter (± 1274724) 1.02
es/minify/libraries/three 347421795 ns/iter (± 4275590) 328516900 ns/iter (± 2517829) 1.06
es/minify/libraries/typescript 2371200388 ns/iter (± 13370068) 2283809352 ns/iter (± 9393332) 1.04
es/minify/libraries/victory 553106533 ns/iter (± 10445384) 484082060 ns/iter (± 2660517) 1.14
es/minify/libraries/vue 107824115 ns/iter (± 495724) 106210732 ns/iter (± 397068) 1.02
es/visitor/compare/clone 1972811 ns/iter (± 5874) 1952295 ns/iter (± 6664) 1.01
es/visitor/compare/visit_mut_span 2269732 ns/iter (± 4139) 2261864 ns/iter (± 7262) 1.00
es/visitor/compare/visit_mut_span_panic 2335052 ns/iter (± 5610) 2328032 ns/iter (± 3666) 1.00
es/visitor/compare/fold_span 3381241 ns/iter (± 9053) 3371760 ns/iter (± 7706) 1.00
es/visitor/compare/fold_span_panic 3493071 ns/iter (± 26708) 3469964 ns/iter (± 9476) 1.01
es/lexer/colors 13191 ns/iter (± 7) 13212 ns/iter (± 76) 1.00
es/lexer/angular 6190702 ns/iter (± 10914) 6100979 ns/iter (± 9967) 1.01
es/lexer/backbone 798967 ns/iter (± 490) 788740 ns/iter (± 2072) 1.01
es/lexer/jquery 4552658 ns/iter (± 5039) 4522205 ns/iter (± 18204) 1.01
es/lexer/jquery mobile 6926308 ns/iter (± 15745) 6872109 ns/iter (± 20464) 1.01
es/lexer/mootools 3643830 ns/iter (± 2179) 3569396 ns/iter (± 7807) 1.02
es/lexer/underscore 671500 ns/iter (± 737) 662732 ns/iter (± 1555) 1.01
es/lexer/three 21648251 ns/iter (± 37165) 21469231 ns/iter (± 53436) 1.01
es/lexer/yui 3855283 ns/iter (± 1639) 3812374 ns/iter (± 3545) 1.01
es/parser/colors 26971 ns/iter (± 335) 27135 ns/iter (± 50) 0.99
es/parser/angular 13530814 ns/iter (± 116957) 13375081 ns/iter (± 36660) 1.01
es/parser/backbone 1999112 ns/iter (± 8170) 1980700 ns/iter (± 8676) 1.01
es/parser/jquery 10988565 ns/iter (± 118622) 10834107 ns/iter (± 44718) 1.01
es/parser/jquery mobile 16836081 ns/iter (± 137904) 16534149 ns/iter (± 67988) 1.02
es/parser/mootools 8405121 ns/iter (± 115296) 8303088 ns/iter (± 13339) 1.01
es/parser/underscore 1723843 ns/iter (± 9267) 1717226 ns/iter (± 10416) 1.00
es/parser/three 48989760 ns/iter (± 185514) 46898623 ns/iter (± 524826) 1.04
es/parser/yui 8337543 ns/iter (± 35080) 8228776 ns/iter (± 20528) 1.01
es/preset-env/usage/builtin_type 135988 ns/iter (± 32019) 134879 ns/iter (± 31847) 1.01
es/preset-env/usage/property 17612 ns/iter (± 45) 16916 ns/iter (± 52) 1.04
es/resolver/typescript 92669509 ns/iter (± 1044287) 89575821 ns/iter (± 953813) 1.03
es/fixer/typescript 67931120 ns/iter (± 580792) 64509014 ns/iter (± 442637) 1.05
es/hygiene/typescript 136437261 ns/iter (± 1578472) 133960660 ns/iter (± 738244) 1.02
es/resolver_with_hygiene/typescript 258642255 ns/iter (± 2793839) 247144589 ns/iter (± 1096383) 1.05
es/visitor/base-perf/module_clone 59283 ns/iter (± 159) 59083 ns/iter (± 189) 1.00
es/visitor/base-perf/fold_empty 62734 ns/iter (± 214) 63249 ns/iter (± 588) 0.99
es/visitor/base-perf/fold_noop_impl_all 62892 ns/iter (± 246) 63347 ns/iter (± 173) 0.99
es/visitor/base-perf/fold_noop_impl_vec 63489 ns/iter (± 285) 63914 ns/iter (± 335) 0.99
es/visitor/base-perf/boxing_boxed_clone 58 ns/iter (± 0) 56 ns/iter (± 0) 1.04
es/visitor/base-perf/boxing_unboxed_clone 39 ns/iter (± 0) 40 ns/iter (± 0) 0.97
es/visitor/base-perf/boxing_boxed 111 ns/iter (± 0) 109 ns/iter (± 0) 1.02
es/visitor/base-perf/boxing_unboxed 77 ns/iter (± 0) 78 ns/iter (± 0) 0.99
es/visitor/base-perf/visit_empty 0 ns/iter (± 0) 0 ns/iter (± 0) NaN
es/visitor/base-perf/visit_contains_this 2623 ns/iter (± 12) 2634 ns/iter (± 23) 1.00
es/base/parallel/resolver/typescript 3756472490 ns/iter (± 253991238) 3892021719 ns/iter (± 307255367) 0.97
es/base/parallel/hygiene/typescript 1501538904 ns/iter (± 20778417) 1459994374 ns/iter (± 14526009) 1.03
misc/visitors/time-complexity/time 5 135 ns/iter (± 1) 133 ns/iter (± 1) 1.02
misc/visitors/time-complexity/time 10 396 ns/iter (± 14) 393 ns/iter (± 3) 1.01
misc/visitors/time-complexity/time 15 720 ns/iter (± 1) 685 ns/iter (± 2) 1.05
misc/visitors/time-complexity/time 20 1065 ns/iter (± 9) 1050 ns/iter (± 5) 1.01
misc/visitors/time-complexity/time 40 4108 ns/iter (± 5) 4112 ns/iter (± 4) 1.00
misc/visitors/time-complexity/time 60 8765 ns/iter (± 15) 7295 ns/iter (± 11) 1.20
es/full-target/es2016 227316 ns/iter (± 437) 228347 ns/iter (± 1089) 1.00
es/full-target/es2017 218741 ns/iter (± 630) 218728 ns/iter (± 682) 1.00
es/full-target/es2018 207324 ns/iter (± 1049) 205709 ns/iter (± 1024) 1.01
es2020_nullish_coalescing 70532 ns/iter (± 440) 71732 ns/iter (± 347) 0.98
es2020_optional_chaining 82639 ns/iter (± 261) 82681 ns/iter (± 242) 1.00
es2022_class_properties 114889 ns/iter (± 606) 114097 ns/iter (± 286) 1.01
es2018_object_rest_spread 75185 ns/iter (± 195) 75812 ns/iter (± 153) 0.99
es2019_optional_catch_binding 64767 ns/iter (± 149) 65184 ns/iter (± 173) 0.99
es2017_async_to_generator 65105 ns/iter (± 306) 65921 ns/iter (± 256) 0.99
es2016_exponentiation 66166 ns/iter (± 157) 66607 ns/iter (± 230) 0.99
es2015_arrow 71836 ns/iter (± 221) 72663 ns/iter (± 233) 0.99
es2015_block_scoped_fn 68618 ns/iter (± 232) 69275 ns/iter (± 322) 0.99
es2015_block_scoping 119942 ns/iter (± 496) 121031 ns/iter (± 658) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.