Skip to content

Commit

Permalink
fix(es/module): Make jsc.paths fully resolve TypeScript files (#7901)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #7861
 - Closes #7898
  • Loading branch information
kdy1 authored Aug 31, 2023
1 parent 4823060 commit c714dd2
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
const _a = require("../packages/a/src");
const _a = require("../packages/a/src/index.js");
console.log(`${(0, _a.displayA)()}`);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
(async function() {
const { displayA } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("../packages/a/src")));
const { displayA } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("../packages/a/src/index.js")));
console.log(displayA());
})();
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import test from "./utils";
import test from "./utils/index.js";
test();
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
require("./core/module/moduleFile");
require("./core/utils");
require("./core/utils/index.js");
require("./core/utilFile");
require("./utils");
require("./utils/index.js");
console.log("SUCCESS");
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import{config}from"../config";const main=()=>config();main();
import{config}from"../config/index.js";const main=()=>config();main();
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _ = /*#__PURE__*/ _interop_require_default._(require("."));
const _ = /*#__PURE__*/ _interop_require_default._(require("./index.js"));
function bar() {
console.log(_.default);
}
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7829/1/output/1.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { fn } from "./libs/pkg/src";
import { fn } from "./libs/pkg/src/index.js";
console.log(fn);
6 changes: 1 addition & 5 deletions crates/swc_ecma_transforms_module/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,7 @@ fn to_specifier(mut target_path: PathBuf, orig_filename: Option<&str>) -> JsWord
target_path.set_extension("js");
}
} else if is_resolved_as_ts && is_resolved_as_index {
if orig_filename == "index" {
target_path.set_extension("");
} else {
target_path.pop();
}
target_path.set_extension("js");
}
} else {
target_path.set_extension("");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { displayB } from "../packages/b/src";
import { displayB } from "../packages/b/src/index.js";
async function display() {
const displayA = await import("../packages/a/src").then((c)=>c.displayA);
const displayA = await import("../packages/a/src/index.js").then((c)=>c.displayA);
console.log(displayA());
console.log(displayB());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import o from ".";
import o from "./index.js";
export default function bar() {
console.log(o);
}
4 changes: 2 additions & 2 deletions node-swc/__tests__/transform/issue_4730_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ it("should work", async () => {
value: true
});
const _interop_require_wildcard = require(\\"@swc/helpers/_/_interop_require_wildcard\\");
const _b = require(\\"../packages/b/src\\");
const _b = require(\\"../packages/b/src/index.js\\");
async function display() {
const displayA = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require(\\"../packages/a/src\\"))).then((c)=>c.displayA);
const displayA = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require(\\"../packages/a/src/index.js\\"))).then((c)=>c.displayA);
console.log(displayA());
console.log((0, _b.displayB)());
}
Expand Down

1 comment on commit c714dd2

@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: c714dd2 Previous: 2db10e9 Ratio
es/full/bugs-1 280569 ns/iter (± 2456) 283912 ns/iter (± 8826) 0.99
es/full/minify/libraries/antd 1287545691 ns/iter (± 12038060) 1387151075 ns/iter (± 43279686) 0.93
es/full/minify/libraries/d3 271112637 ns/iter (± 4971427) 279476166 ns/iter (± 6418360) 0.97
es/full/minify/libraries/echarts 1026138777 ns/iter (± 4407801) 1059269407 ns/iter (± 13395724) 0.97
es/full/minify/libraries/jquery 83323898 ns/iter (± 87492) 83674326 ns/iter (± 2098319) 1.00
es/full/minify/libraries/lodash 96771578 ns/iter (± 333612) 97509221 ns/iter (± 1270908) 0.99
es/full/minify/libraries/moment 49516224 ns/iter (± 178763) 50379231 ns/iter (± 615295) 0.98
es/full/minify/libraries/react 17878526 ns/iter (± 45739) 18279801 ns/iter (± 251520) 0.98
es/full/minify/libraries/terser 215673514 ns/iter (± 916209) 218638828 ns/iter (± 1072105) 0.99
es/full/minify/libraries/three 380330150 ns/iter (± 843736) 388579637 ns/iter (± 2654853) 0.98
es/full/minify/libraries/typescript 2594888248 ns/iter (± 13358142) 2606384876 ns/iter (± 17265830) 1.00
es/full/minify/libraries/victory 556224352 ns/iter (± 3011580) 566023858 ns/iter (± 8551319) 0.98
es/full/minify/libraries/vue 117981534 ns/iter (± 580107) 119065553 ns/iter (± 1123031) 0.99
es/full/codegen/es3 33254 ns/iter (± 57) 34779 ns/iter (± 100) 0.96
es/full/codegen/es5 33246 ns/iter (± 132) 34799 ns/iter (± 78) 0.96
es/full/codegen/es2015 33310 ns/iter (± 136) 34666 ns/iter (± 130) 0.96
es/full/codegen/es2016 33319 ns/iter (± 136) 34805 ns/iter (± 184) 0.96
es/full/codegen/es2017 33244 ns/iter (± 122) 34799 ns/iter (± 103) 0.96
es/full/codegen/es2018 33541 ns/iter (± 88) 34742 ns/iter (± 103) 0.97
es/full/codegen/es2019 33412 ns/iter (± 133) 34750 ns/iter (± 96) 0.96
es/full/codegen/es2020 33495 ns/iter (± 165) 34702 ns/iter (± 112) 0.97
es/full/all/es3 169414785 ns/iter (± 1097111) 170418074 ns/iter (± 1030376) 0.99
es/full/all/es5 161252794 ns/iter (± 742131) 163186057 ns/iter (± 982212) 0.99
es/full/all/es2015 120578525 ns/iter (± 694718) 122704269 ns/iter (± 1243922) 0.98
es/full/all/es2016 119333251 ns/iter (± 947487) 121178079 ns/iter (± 717310) 0.98
es/full/all/es2017 118899121 ns/iter (± 470567) 121910633 ns/iter (± 1347717) 0.98
es/full/all/es2018 116405869 ns/iter (± 865652) 118839202 ns/iter (± 658475) 0.98
es/full/all/es2019 116222778 ns/iter (± 452146) 118458140 ns/iter (± 736142) 0.98
es/full/all/es2020 111838267 ns/iter (± 559620) 114094292 ns/iter (± 680680) 0.98
es/full/parser 492766 ns/iter (± 4333) 492172 ns/iter (± 6074) 1.00
es/full/base/fixer 19466 ns/iter (± 286) 18024 ns/iter (± 73) 1.08
es/full/base/resolver_and_hygiene 81350 ns/iter (± 181) 81678 ns/iter (± 99) 1.00
serialization of serde 293 ns/iter (± 0) 289 ns/iter (± 4) 1.01
css/minify/libraries/bootstrap 28950870 ns/iter (± 29351) 28619273 ns/iter (± 110070) 1.01
css/visitor/compare/clone 1613626 ns/iter (± 3225) 1630892 ns/iter (± 4099) 0.99
css/visitor/compare/visit_mut_span 1756795 ns/iter (± 6745) 1767706 ns/iter (± 27703) 0.99
css/visitor/compare/visit_mut_span_panic 1819507 ns/iter (± 2758) 1829829 ns/iter (± 3897) 0.99
css/visitor/compare/fold_span 2545710 ns/iter (± 5672) 2569404 ns/iter (± 7589) 0.99
css/visitor/compare/fold_span_panic 2732503 ns/iter (± 7928) 2771202 ns/iter (± 14626) 0.99
css/lexer/bootstrap_5_1_3 4482035 ns/iter (± 3678) 4482737 ns/iter (± 27432) 1.00
css/lexer/foundation_6_7_4 3772597 ns/iter (± 1368) 3767219 ns/iter (± 1710) 1.00
css/lexer/tailwind_3_1_1 718741 ns/iter (± 430) 721296 ns/iter (± 529) 1.00
css/parser/bootstrap_5_1_3 18943710 ns/iter (± 30904) 18916010 ns/iter (± 93385) 1.00
css/parser/foundation_6_7_4 15208248 ns/iter (± 9294) 15167360 ns/iter (± 11829) 1.00
css/parser/tailwind_3_1_1 2956485 ns/iter (± 2735) 2947867 ns/iter (± 2889) 1.00
es/codegen/colors 731820 ns/iter (± 399994) 739718 ns/iter (± 405795) 0.99
es/codegen/large 3142439 ns/iter (± 1668549) 2894434 ns/iter (± 1541644) 1.09
es/codegen/with-parser/colors 44959 ns/iter (± 47) 45739 ns/iter (± 369) 0.98
es/codegen/with-parser/large 481881 ns/iter (± 1089) 488750 ns/iter (± 1050) 0.99
es/minify/libraries/antd 1120610405 ns/iter (± 10654513) 1189921217 ns/iter (± 24777760) 0.94
es/minify/libraries/d3 236623868 ns/iter (± 521258) 241690002 ns/iter (± 3973949) 0.98
es/minify/libraries/echarts 882193973 ns/iter (± 5152319) 929250298 ns/iter (± 14305652) 0.95
es/minify/libraries/jquery 72880340 ns/iter (± 102576) 74091008 ns/iter (± 679624) 0.98
es/minify/libraries/lodash 86365458 ns/iter (± 243704) 89933913 ns/iter (± 1593782) 0.96
es/minify/libraries/moment 43272507 ns/iter (± 67877) 44842757 ns/iter (± 535413) 0.96
es/minify/libraries/react 15950955 ns/iter (± 50827) 16461104 ns/iter (± 172027) 0.97
es/minify/libraries/terser 184432306 ns/iter (± 631156) 207764340 ns/iter (± 14025357) 0.89
es/minify/libraries/three 317328068 ns/iter (± 947800) 344675299 ns/iter (± 12511346) 0.92
es/minify/libraries/typescript 2213918585 ns/iter (± 3386407) 2415635259 ns/iter (± 97052558) 0.92
es/minify/libraries/victory 469431860 ns/iter (± 1256551) 548764827 ns/iter (± 53824652) 0.86
es/minify/libraries/vue 104683259 ns/iter (± 171048) 109181872 ns/iter (± 1198241) 0.96
es/visitor/compare/clone 1917501 ns/iter (± 5103) 1926332 ns/iter (± 5664) 1.00
es/visitor/compare/visit_mut_span 2262946 ns/iter (± 6830) 2279813 ns/iter (± 4642) 0.99
es/visitor/compare/visit_mut_span_panic 2290958 ns/iter (± 3836) 2323074 ns/iter (± 92057) 0.99
es/visitor/compare/fold_span 3313132 ns/iter (± 6678) 3347345 ns/iter (± 15696) 0.99
es/visitor/compare/fold_span_panic 3454101 ns/iter (± 6055) 3490840 ns/iter (± 12145) 0.99
es/lexer/colors 13132 ns/iter (± 86) 13439 ns/iter (± 30) 0.98
es/lexer/angular 6001923 ns/iter (± 5677) 6170633 ns/iter (± 9665) 0.97
es/lexer/backbone 784906 ns/iter (± 4172) 796475 ns/iter (± 1151) 0.99
es/lexer/jquery 4424869 ns/iter (± 3079) 4513122 ns/iter (± 1723) 0.98
es/lexer/jquery mobile 6794077 ns/iter (± 4369) 6846380 ns/iter (± 7820) 0.99
es/lexer/mootools 3504743 ns/iter (± 2770) 3580023 ns/iter (± 2186) 0.98
es/lexer/underscore 651265 ns/iter (± 592) 661820 ns/iter (± 1104) 0.98
es/lexer/three 21216119 ns/iter (± 22749) 21419139 ns/iter (± 16815) 0.99
es/lexer/yui 3812553 ns/iter (± 2386) 3832845 ns/iter (± 3988) 0.99
es/parser/colors 26629 ns/iter (± 34) 27533 ns/iter (± 60) 0.97
es/parser/angular 13270413 ns/iter (± 35429) 13553185 ns/iter (± 301283) 0.98
es/parser/backbone 1953768 ns/iter (± 7895) 1996511 ns/iter (± 18119) 0.98
es/parser/jquery 10694569 ns/iter (± 40931) 11439368 ns/iter (± 89947) 0.93
es/parser/jquery mobile 16388215 ns/iter (± 50339) 17734566 ns/iter (± 150576) 0.92
es/parser/mootools 8229827 ns/iter (± 19408) 8537799 ns/iter (± 32544) 0.96
es/parser/underscore 1685595 ns/iter (± 9168) 1734744 ns/iter (± 3154) 0.97
es/parser/three 46087519 ns/iter (± 108772) 47147502 ns/iter (± 436722) 0.98
es/parser/yui 8164867 ns/iter (± 24226) 8304175 ns/iter (± 39894) 0.98
es/preset-env/usage/builtin_type 135554 ns/iter (± 32503) 137479 ns/iter (± 32450) 0.99
es/preset-env/usage/property 16177 ns/iter (± 62) 17071 ns/iter (± 66) 0.95
es/resolver/typescript 89528477 ns/iter (± 1111851) 91607751 ns/iter (± 1264331) 0.98
es/fixer/typescript 62380048 ns/iter (± 677492) 64341965 ns/iter (± 2006832) 0.97
es/hygiene/typescript 127745338 ns/iter (± 386996) 130197208 ns/iter (± 1593672) 0.98
es/resolver_with_hygiene/typescript 239374852 ns/iter (± 954964) 246113213 ns/iter (± 1312831) 0.97
es/visitor/base-perf/module_clone 59783 ns/iter (± 310) 62033 ns/iter (± 467) 0.96
es/visitor/base-perf/fold_empty 63828 ns/iter (± 254) 65024 ns/iter (± 253) 0.98
es/visitor/base-perf/fold_noop_impl_all 64511 ns/iter (± 235) 65952 ns/iter (± 3399) 0.98
es/visitor/base-perf/fold_noop_impl_vec 64764 ns/iter (± 322) 65677 ns/iter (± 256) 0.99
es/visitor/base-perf/boxing_boxed_clone 57 ns/iter (± 0) 57 ns/iter (± 0) 1
es/visitor/base-perf/boxing_unboxed_clone 40 ns/iter (± 0) 40 ns/iter (± 0) 1
es/visitor/base-perf/boxing_boxed 106 ns/iter (± 0) 127 ns/iter (± 0) 0.83
es/visitor/base-perf/boxing_unboxed 75 ns/iter (± 0) 85 ns/iter (± 0) 0.88
es/visitor/base-perf/visit_empty 0 ns/iter (± 0) 0 ns/iter (± 0) NaN
es/visitor/base-perf/visit_contains_this 2485 ns/iter (± 14) 2531 ns/iter (± 6) 0.98
es/base/parallel/resolver/typescript 3527875316 ns/iter (± 267294222) 3652691825 ns/iter (± 262795340) 0.97
es/base/parallel/hygiene/typescript 1427183703 ns/iter (± 15496422) 1437212626 ns/iter (± 15467285) 0.99
misc/visitors/time-complexity/time 5 118 ns/iter (± 0) 119 ns/iter (± 0) 0.99
misc/visitors/time-complexity/time 10 388 ns/iter (± 7) 378 ns/iter (± 6) 1.03
misc/visitors/time-complexity/time 15 659 ns/iter (± 5) 676 ns/iter (± 10) 0.97
misc/visitors/time-complexity/time 20 1041 ns/iter (± 47) 1058 ns/iter (± 2) 0.98
misc/visitors/time-complexity/time 40 4127 ns/iter (± 4) 3554 ns/iter (± 10) 1.16
misc/visitors/time-complexity/time 60 7254 ns/iter (± 36) 7476 ns/iter (± 131) 0.97
es/full-target/es2016 227857 ns/iter (± 360) 231147 ns/iter (± 357) 0.99
es/full-target/es2017 218501 ns/iter (± 1061) 220176 ns/iter (± 436) 0.99
es/full-target/es2018 206220 ns/iter (± 577) 210729 ns/iter (± 658) 0.98
es2020_nullish_coalescing 69060 ns/iter (± 529) 70729 ns/iter (± 236) 0.98
es2020_optional_chaining 79645 ns/iter (± 195) 81236 ns/iter (± 842) 0.98
es2022_class_properties 113298 ns/iter (± 450) 116134 ns/iter (± 473) 0.98
es2018_object_rest_spread 73387 ns/iter (± 166) 74777 ns/iter (± 250) 0.98
es2019_optional_catch_binding 63070 ns/iter (± 223) 65301 ns/iter (± 166) 0.97
es2017_async_to_generator 62419 ns/iter (± 177) 65446 ns/iter (± 247) 0.95
es2016_exponentiation 64824 ns/iter (± 178) 66343 ns/iter (± 266) 0.98
es2015_arrow 70342 ns/iter (± 196) 72354 ns/iter (± 234) 0.97
es2015_block_scoped_fn 66884 ns/iter (± 235) 69092 ns/iter (± 192) 0.97
es2015_block_scoping 122795 ns/iter (± 763) 122246 ns/iter (± 527) 1.00

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

Please sign in to comment.