Use a different RegEx

This commit is contained in:
Ryan Cavanaugh
2017-10-31 18:38:00 -07:00
parent 5395d0ddb8
commit 5dc02ef5cc
2 changed files with 29 additions and 1 deletions

View File

@@ -2417,7 +2417,13 @@ namespace ts {
* Takes a string like "jquery-min.4.2.3" and returns "jquery"
*/
export function removeMinAndVersionNumbers(fileName: string) {
return fileName.replace(/((?:\.|-)min(?=\.|$))|((?:-|\.)\d+)/g, "");
const match = /((\w|(-(?!min)))+)(\.|-)?.*/.exec(fileName);
if (match) {
return match[1];
}
else {
return fileName;
}
}
export interface ObjectAllocator {

View File

@@ -1496,6 +1496,28 @@ namespace ts.projectSystem {
}
});
it("removes version numbers correctly", () => {
const testData: [string, string][] = [
["jquery-max", "jquery-max"],
["jquery.min", "jquery"],
["jquery-min.4.2.3", "jquery"],
["jquery.4.2-test.js", "jquery"],
["jquery.min.4.2.1", "jquery"],
["jquery.7.min.js", "jquery"],
["jquery.7.min-beta", "jquery"],
["minimum", "minimum"],
["min", "min"],
["min.3.2", "min"],
["jquery", "jquery"]
];
const suffixes = [".js", ".jsx", ""];
for (const t of testData) {
for (const suf of suffixes) {
assert.equal(removeMinAndVersionNumbers(t[0] + suf), t[1]);
}
}
});
it("ignores files excluded by a legacy safe type list", () => {
const file1 = {
path: "/a/b/bliss.js",