swc does not prioritize jsc.paths by matching prefix length like tsc specifies
yehonatanz opened this issue · comments
Describe the bug
Seems like swc
does not prioritize jsc.paths
matches by length but instead chooses the first (re: arbitrary, since JSON objects are unsorted) that matches.
This is opposed to the behavior specified by tsc
here:
When multiple patterns match a module specifier, the pattern with the longest matching prefix before any * token is used
As far as I understand (zero rust experience, so please be forgiving), this can be rather easily fixed by sorting paths
by index of *
in tsc.rs.
I'm open to implementing it myself if that is indeed classified as bug that needs fixing.
Input code
import { hello } from '@app/helpers/hello';
hello();
Config
{
"module": {
"type": "commonjs",
"strictMode": true,
"noInterop": false
},
"jsc": {
"paths": {
"@app/*": [
"packages/*/src"
],
"@app/helpers/*": [
"packages/helpers/src/*"
]
},
"baseUrl": ".",
"parser": {
"syntax": "typescript"
}
}
}
Playground link (or link to the minimal reproduction)
SWC Info output
No response
Expected behavior
Expected behavior is to match the longer @app/helpers/*
pattern and emit:
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _hello = require("./packages/helpers/src/hello");
(0, _hello.hello)();
Actual behavior
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _hello = require("./packages/helpers/hello/src");
(0, _hello.hello)();
Version
1.4.13
Additional context
No response
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.