Skip to content

fix: dots can now be used in module names #7655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package-lock.json
.c9/
*.launch
.settings/
.atom

# IDE - VSCode
.vscode/*
Expand Down
14 changes: 13 additions & 1 deletion tests/app/ui/builder/builder-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { createViewFromEntry } from "tns-core-modules/ui/builder";
import { sanitizeModuleName } from "tns-core-modules/ui/builder/module-name-sanitizer";

import { assertEqual, assertNull, assertThrows, assertNotNull } from "../../tk-unit";

const COMPONENT_MODULE = "ui/builder/component-module";
Expand Down Expand Up @@ -35,4 +37,14 @@ export function test_create_view_from_entry_with_path_with_slash() {
export function test_create_view_from_entry_with_path_with_tilde() {
const view = getViewComponent("~/" + COMPONENT_MODULE);
assertNotNull(view, `Module starting with "~/" could not be loaded`);
}
}

export function test_sanitize_module_name_with_removable_extension() {
const moduleName = sanitizeModuleName("./xml-declaration/mainPage.xml");
assertEqual(moduleName, "./xml-declaration/mainPage");
}

export function test_sanitize_module_name_with_non_removable_extension() {
const moduleName = sanitizeModuleName("app/views/main.page");
assertEqual(moduleName, "app/views/main.page");
}
9 changes: 4 additions & 5 deletions tns-core-modules/ui/builder/module-name-sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ export function sanitizeModuleName(moduleName: string, removeExtension: boolean
}

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

return moduleName;
}
}