Skip to content

Commit

Permalink
fix(es/module): Preserve import specifier if resolving fails (#7955)
Browse files Browse the repository at this point in the history
**Related issue:**

 - vercel/next.js#55216

This PR fixes a regression caught by the PR above.
  • Loading branch information
kdy1 authored Sep 15, 2023
1 parent 88b009c commit be5b02a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions crates/swc_ecma_transforms_module/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,8 @@ where
target_path.display().to_string().into()
}
}
}

impl<R> ImportResolver for NodeImportResolver<R>
where
R: Resolve,
{
fn resolve_import(&self, base: &FileName, module_specifier: &str) -> Result<JsWord, Error> {
fn try_resolve_import(&self, base: &FileName, module_specifier: &str) -> Result<JsWord, Error> {
let _tracing = if cfg!(debug_assertions) {
Some(
tracing::span!(
Expand Down Expand Up @@ -316,6 +311,19 @@ where
}
}

impl<R> ImportResolver for NodeImportResolver<R>
where
R: Resolve,
{
fn resolve_import(&self, base: &FileName, module_specifier: &str) -> Result<JsWord, Error> {
self.try_resolve_import(base, module_specifier)
.or_else(|err| {
warn!("Failed to resolve import: {}", err);
Ok(module_specifier.into())
})
}
}

macro_rules! impl_ref {
($P:ident, $T:ty) => {
impl<$P> ImportResolver for $T
Expand Down

1 comment on commit be5b02a

@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: be5b02a Previous: ca22359 Ratio
es/full/bugs-1 283633 ns/iter (± 9139) 290032 ns/iter (± 11193) 0.98
es/full/minify/libraries/antd 1331246836 ns/iter (± 12227104) 1330458804 ns/iter (± 12089512) 1.00
es/full/minify/libraries/d3 277810953 ns/iter (± 7374611) 276548786 ns/iter (± 2772988) 1.00
es/full/minify/libraries/echarts 1077040577 ns/iter (± 28674696) 1068056088 ns/iter (± 15404409) 1.01
es/full/minify/libraries/jquery 84534916 ns/iter (± 237290) 84529255 ns/iter (± 402048) 1.00
es/full/minify/libraries/lodash 97654222 ns/iter (± 356163) 97158121 ns/iter (± 564513) 1.01
es/full/minify/libraries/moment 50043838 ns/iter (± 182751) 50212200 ns/iter (± 502370) 1.00
es/full/minify/libraries/react 17956920 ns/iter (± 37733) 17963316 ns/iter (± 85409) 1.00
es/full/minify/libraries/terser 220027862 ns/iter (± 1044971) 216861168 ns/iter (± 1211169) 1.01
es/full/minify/libraries/three 387416925 ns/iter (± 2002363) 388161165 ns/iter (± 3927529) 1.00
es/full/minify/libraries/typescript 2671326786 ns/iter (± 13088365) 2668348138 ns/iter (± 12607876) 1.00
es/full/minify/libraries/victory 570160546 ns/iter (± 4687994) 570062939 ns/iter (± 5854242) 1.00
es/full/minify/libraries/vue 119321217 ns/iter (± 513251) 120747797 ns/iter (± 492605) 0.99
es/full/codegen/es3 34590 ns/iter (± 103) 34842 ns/iter (± 140) 0.99
es/full/codegen/es5 34484 ns/iter (± 542) 34590 ns/iter (± 94) 1.00
es/full/codegen/es2015 34577 ns/iter (± 71) 34639 ns/iter (± 64) 1.00
es/full/codegen/es2016 34620 ns/iter (± 72) 34620 ns/iter (± 93) 1
es/full/codegen/es2017 34672 ns/iter (± 92) 34792 ns/iter (± 129) 1.00
es/full/codegen/es2018 34645 ns/iter (± 73) 34642 ns/iter (± 106) 1.00
es/full/codegen/es2019 34618 ns/iter (± 91) 34681 ns/iter (± 96) 1.00
es/full/codegen/es2020 34582 ns/iter (± 155) 34806 ns/iter (± 70) 0.99
es/full/all/es3 168411868 ns/iter (± 892349) 167556425 ns/iter (± 782011) 1.01
es/full/all/es5 160439674 ns/iter (± 628238) 160217012 ns/iter (± 811531) 1.00
es/full/all/es2015 119895565 ns/iter (± 725272) 119946059 ns/iter (± 835351) 1.00
es/full/all/es2016 118481852 ns/iter (± 834638) 118625561 ns/iter (± 764276) 1.00
es/full/all/es2017 117358676 ns/iter (± 600219) 117617751 ns/iter (± 619783) 1.00
es/full/all/es2018 115270274 ns/iter (± 825018) 117251566 ns/iter (± 727814) 0.98
es/full/all/es2019 116015573 ns/iter (± 614362) 115692654 ns/iter (± 566507) 1.00
es/full/all/es2020 111595829 ns/iter (± 539298) 112360404 ns/iter (± 575741) 0.99
es/full/parser 487466 ns/iter (± 5288) 487546 ns/iter (± 4938) 1.00
es/full/base/fixer 18473 ns/iter (± 104) 17614 ns/iter (± 90) 1.05
es/full/base/resolver_and_hygiene 79986 ns/iter (± 123) 79037 ns/iter (± 135) 1.01
serialization of serde 298 ns/iter (± 0) 292 ns/iter (± 0) 1.02
css/minify/libraries/bootstrap 28419831 ns/iter (± 42498) 29204775 ns/iter (± 45430) 0.97
css/visitor/compare/clone 1673744 ns/iter (± 5757) 1752103 ns/iter (± 7782) 0.96
css/visitor/compare/visit_mut_span 1791608 ns/iter (± 7590) 1870378 ns/iter (± 7130) 0.96
css/visitor/compare/visit_mut_span_panic 1874853 ns/iter (± 7073) 1888248 ns/iter (± 4095) 0.99
css/visitor/compare/fold_span 2577126 ns/iter (± 8570) 2649091 ns/iter (± 5054) 0.97
css/visitor/compare/fold_span_panic 2761435 ns/iter (± 11331) 2868126 ns/iter (± 11424) 0.96
css/lexer/bootstrap_5_1_3 4415536 ns/iter (± 5023) 4452331 ns/iter (± 21551) 0.99
css/lexer/foundation_6_7_4 3785915 ns/iter (± 2315) 3740278 ns/iter (± 3537) 1.01
css/lexer/tailwind_3_1_1 710990 ns/iter (± 691) 711070 ns/iter (± 1071) 1.00
css/parser/bootstrap_5_1_3 19545269 ns/iter (± 59421) 19372411 ns/iter (± 34965) 1.01
css/parser/foundation_6_7_4 15618911 ns/iter (± 43037) 15235547 ns/iter (± 28154) 1.03
css/parser/tailwind_3_1_1 2972186 ns/iter (± 2340) 2960647 ns/iter (± 5266) 1.00
es/codegen/colors 727045 ns/iter (± 396594) 728223 ns/iter (± 396030) 1.00
es/codegen/large 3136711 ns/iter (± 1665470) 3146029 ns/iter (± 1684161) 1.00
es/codegen/with-parser/colors 45348 ns/iter (± 647) 46143 ns/iter (± 217) 0.98
es/codegen/with-parser/large 489030 ns/iter (± 1109) 493263 ns/iter (± 1663) 0.99
es/minify/libraries/antd 1167927078 ns/iter (± 12012341) 1160455933 ns/iter (± 13231104) 1.01
es/minify/libraries/d3 239321326 ns/iter (± 887290) 241706075 ns/iter (± 1066318) 0.99
es/minify/libraries/echarts 912599713 ns/iter (± 7608211) 920675823 ns/iter (± 8089227) 0.99
es/minify/libraries/jquery 73339713 ns/iter (± 155401) 73664070 ns/iter (± 356010) 1.00
es/minify/libraries/lodash 87153083 ns/iter (± 619687) 87604299 ns/iter (± 179975) 0.99
es/minify/libraries/moment 43831016 ns/iter (± 193018) 44109914 ns/iter (± 279989) 0.99
es/minify/libraries/react 16019942 ns/iter (± 38971) 16041411 ns/iter (± 93810) 1.00
es/minify/libraries/terser 185540304 ns/iter (± 865352) 187048872 ns/iter (± 533420) 0.99
es/minify/libraries/three 320921429 ns/iter (± 1930365) 323375143 ns/iter (± 1856504) 0.99
es/minify/libraries/typescript 2280736973 ns/iter (± 17604711) 2285450496 ns/iter (± 20794038) 1.00
es/minify/libraries/victory 478084090 ns/iter (± 4539240) 484493149 ns/iter (± 3992713) 0.99
es/minify/libraries/vue 105705574 ns/iter (± 312801) 106779897 ns/iter (± 835958) 0.99
es/visitor/compare/clone 1931151 ns/iter (± 3337) 1962781 ns/iter (± 2407) 0.98
es/visitor/compare/visit_mut_span 2273356 ns/iter (± 3240) 2299492 ns/iter (± 4490) 0.99
es/visitor/compare/visit_mut_span_panic 2328179 ns/iter (± 10176) 2344727 ns/iter (± 3828) 0.99
es/visitor/compare/fold_span 3349903 ns/iter (± 10205) 3397864 ns/iter (± 5471) 0.99
es/visitor/compare/fold_span_panic 3522801 ns/iter (± 8330) 3534566 ns/iter (± 6712) 1.00
es/lexer/colors 13214 ns/iter (± 41) 12930 ns/iter (± 18) 1.02
es/lexer/angular 6075190 ns/iter (± 17878) 6077634 ns/iter (± 6765) 1.00
es/lexer/backbone 776315 ns/iter (± 1171) 784536 ns/iter (± 753) 0.99
es/lexer/jquery 4469822 ns/iter (± 13175) 4454284 ns/iter (± 6720) 1.00
es/lexer/jquery mobile 6819948 ns/iter (± 44427) 6798808 ns/iter (± 9718) 1.00
es/lexer/mootools 3540902 ns/iter (± 6414) 3547548 ns/iter (± 7823) 1.00
es/lexer/underscore 653667 ns/iter (± 1266) 660150 ns/iter (± 839) 0.99
es/lexer/three 21155983 ns/iter (± 21741) 21261631 ns/iter (± 22955) 1.00
es/lexer/yui 3785030 ns/iter (± 3770) 3769572 ns/iter (± 26741) 1.00
es/parser/colors 27557 ns/iter (± 53) 27244 ns/iter (± 71) 1.01
es/parser/angular 13713144 ns/iter (± 63831) 13640392 ns/iter (± 62596) 1.01
es/parser/backbone 2008145 ns/iter (± 11774) 1994225 ns/iter (± 7272) 1.01
es/parser/jquery 10967908 ns/iter (± 51597) 10904764 ns/iter (± 35583) 1.01
es/parser/jquery mobile 16735856 ns/iter (± 260807) 16739440 ns/iter (± 23304) 1.00
es/parser/mootools 8413955 ns/iter (± 18453) 8362593 ns/iter (± 20622) 1.01
es/parser/underscore 1731667 ns/iter (± 10198) 1717257 ns/iter (± 8272) 1.01
es/parser/three 47469165 ns/iter (± 493122) 47126258 ns/iter (± 325891) 1.01
es/parser/yui 8337048 ns/iter (± 29939) 8282537 ns/iter (± 33282) 1.01
es/preset-env/usage/builtin_type 135180 ns/iter (± 32422) 133994 ns/iter (± 31067) 1.01
es/preset-env/usage/property 16438 ns/iter (± 62) 16726 ns/iter (± 60) 0.98
es/resolver/typescript 94450018 ns/iter (± 1385853) 92124712 ns/iter (± 1482686) 1.03
es/fixer/typescript 66911775 ns/iter (± 665578) 64239505 ns/iter (± 1361445) 1.04
es/hygiene/typescript 135269608 ns/iter (± 714559) 133424568 ns/iter (± 1937757) 1.01
es/resolver_with_hygiene/typescript 250243043 ns/iter (± 2717648) 245309314 ns/iter (± 710221) 1.02
es/visitor/base-perf/module_clone 59086 ns/iter (± 206) 58808 ns/iter (± 250) 1.00
es/visitor/base-perf/fold_empty 62610 ns/iter (± 281) 62855 ns/iter (± 283) 1.00
es/visitor/base-perf/fold_noop_impl_all 63014 ns/iter (± 172) 63221 ns/iter (± 327) 1.00
es/visitor/base-perf/fold_noop_impl_vec 62885 ns/iter (± 219) 63300 ns/iter (± 268) 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 40 ns/iter (± 0) 40 ns/iter (± 0) 1
es/visitor/base-perf/boxing_boxed 109 ns/iter (± 0) 109 ns/iter (± 0) 1
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 2438 ns/iter (± 9) 2519 ns/iter (± 16) 0.97
es/base/parallel/resolver/typescript 4240050311 ns/iter (± 235031723) 4027068247 ns/iter (± 339954133) 1.05
es/base/parallel/hygiene/typescript 1477465434 ns/iter (± 16423000) 1514867329 ns/iter (± 45799103) 0.98
misc/visitors/time-complexity/time 5 150 ns/iter (± 0) 150 ns/iter (± 0) 1
misc/visitors/time-complexity/time 10 452 ns/iter (± 0) 450 ns/iter (± 25) 1.00
misc/visitors/time-complexity/time 15 796 ns/iter (± 0) 797 ns/iter (± 10) 1.00
misc/visitors/time-complexity/time 20 1283 ns/iter (± 2) 1308 ns/iter (± 1) 0.98
misc/visitors/time-complexity/time 40 4356 ns/iter (± 7) 4392 ns/iter (± 26) 0.99
misc/visitors/time-complexity/time 60 10601 ns/iter (± 18) 9060 ns/iter (± 9) 1.17
es/full-target/es2016 232949 ns/iter (± 930) 230808 ns/iter (± 1709) 1.01
es/full-target/es2017 221136 ns/iter (± 577) 218764 ns/iter (± 506) 1.01
es/full-target/es2018 208744 ns/iter (± 534) 207306 ns/iter (± 352) 1.01
es2020_nullish_coalescing 70082 ns/iter (± 444) 70006 ns/iter (± 448) 1.00
es2020_optional_chaining 77606 ns/iter (± 186) 78227 ns/iter (± 324) 0.99
es2022_class_properties 113636 ns/iter (± 259) 116919 ns/iter (± 1146) 0.97
es2018_object_rest_spread 73996 ns/iter (± 298) 74896 ns/iter (± 207) 0.99
es2019_optional_catch_binding 62507 ns/iter (± 208) 63318 ns/iter (± 195) 0.99
es2017_async_to_generator 62630 ns/iter (± 233) 62854 ns/iter (± 265) 1.00
es2016_exponentiation 66755 ns/iter (± 232) 67836 ns/iter (± 229) 0.98
es2015_arrow 70576 ns/iter (± 170) 70497 ns/iter (± 217) 1.00
es2015_block_scoped_fn 67232 ns/iter (± 251) 71259 ns/iter (± 369) 0.94
es2015_block_scoping 122858 ns/iter (± 453) 121751 ns/iter (± 448) 1.01

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

Please sign in to comment.