Skip to content

Commit b6ff4d3

Browse files
surduSvetoslavTsenov
authored andcommitted
fix: dots can now be used in module names (#7655)
Only known extensions are stripped from the end of module names
1 parent b0d1c91 commit b6ff4d3

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package-lock.json
2121
.c9/
2222
*.launch
2323
.settings/
24+
.atom
2425

2526
# IDE - VSCode
2627
.vscode/*

tests/app/ui/builder/builder-tests.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { createViewFromEntry } from "tns-core-modules/ui/builder";
2+
import { sanitizeModuleName } from "tns-core-modules/ui/builder/module-name-sanitizer";
3+
24
import { assertEqual, assertNull, assertThrows, assertNotNull } from "../../tk-unit";
35

46
const COMPONENT_MODULE = "ui/builder/component-module";
@@ -35,4 +37,14 @@ export function test_create_view_from_entry_with_path_with_slash() {
3537
export function test_create_view_from_entry_with_path_with_tilde() {
3638
const view = getViewComponent("~/" + COMPONENT_MODULE);
3739
assertNotNull(view, `Module starting with "~/" could not be loaded`);
38-
}
40+
}
41+
42+
export function test_sanitize_module_name_with_removable_extension() {
43+
const moduleName = sanitizeModuleName("./xml-declaration/mainPage.xml");
44+
assertEqual(moduleName, "./xml-declaration/mainPage");
45+
}
46+
47+
export function test_sanitize_module_name_with_non_removable_extension() {
48+
const moduleName = sanitizeModuleName("app/views/main.page");
49+
assertEqual(moduleName, "app/views/main.page");
50+
}

tns-core-modules/ui/builder/module-name-sanitizer.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ export function sanitizeModuleName(moduleName: string, removeExtension: boolean
1010
}
1111

1212
if (removeExtension) {
13-
const lastDot = moduleName.lastIndexOf(".");
14-
if (lastDot > 0) {
15-
moduleName = moduleName.substr(0, lastDot);
16-
}
13+
const extToRemove = ["js", "ts", "xml", "html", "css", "scss"];
14+
const extensionRegEx = new RegExp(`(.*)\\.(?:${extToRemove.join("|")})`, "i");
15+
moduleName = moduleName.replace(extensionRegEx, "$1");
1716
}
1817

1918
return moduleName;
20-
}
19+
}

0 commit comments

Comments
 (0)