mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 11:17:04 +08:00
fix: dots can now be used in module names (#7655)
Only known extensions are stripped from the end of module names
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,6 +21,7 @@ package-lock.json
|
|||||||
.c9/
|
.c9/
|
||||||
*.launch
|
*.launch
|
||||||
.settings/
|
.settings/
|
||||||
|
.atom
|
||||||
|
|
||||||
# IDE - VSCode
|
# IDE - VSCode
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { createViewFromEntry } from "tns-core-modules/ui/builder";
|
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";
|
import { assertEqual, assertNull, assertThrows, assertNotNull } from "../../tk-unit";
|
||||||
|
|
||||||
const COMPONENT_MODULE = "ui/builder/component-module";
|
const COMPONENT_MODULE = "ui/builder/component-module";
|
||||||
@ -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() {
|
export function test_create_view_from_entry_with_path_with_tilde() {
|
||||||
const view = getViewComponent("~/" + COMPONENT_MODULE);
|
const view = getViewComponent("~/" + COMPONENT_MODULE);
|
||||||
assertNotNull(view, `Module starting with "~/" could not be loaded`);
|
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");
|
||||||
|
}
|
||||||
|
@ -10,11 +10,10 @@ export function sanitizeModuleName(moduleName: string, removeExtension: boolean
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (removeExtension) {
|
if (removeExtension) {
|
||||||
const lastDot = moduleName.lastIndexOf(".");
|
const extToRemove = ["js", "ts", "xml", "html", "css", "scss"];
|
||||||
if (lastDot > 0) {
|
const extensionRegEx = new RegExp(`(.*)\\.(?:${extToRemove.join("|")})`, "i");
|
||||||
moduleName = moduleName.substr(0, lastDot);
|
moduleName = moduleName.replace(extensionRegEx, "$1");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return moduleName;
|
return moduleName;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user