mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
refactor(builder): handle modules with "/" or "~/" (#7418)
This commit is contained in:

committed by
Manol Donev

parent
4437cd622b
commit
8851835cb1
@ -1,5 +1,5 @@
|
||||
import { createViewFromEntry } from "tns-core-modules/ui/builder";
|
||||
import { assertEqual, assertNull, assertThrows } from "../../tk-unit";
|
||||
import { assertEqual, assertNull, assertThrows, assertNotNull } from "../../tk-unit";
|
||||
|
||||
const COMPONENT_MODULE = "ui/builder/component-module";
|
||||
const MISSING_MODULE = "ui/builder/missing-module";
|
||||
@ -22,7 +22,17 @@ export function test_view_is_NOT_module_root_component() {
|
||||
assertNull(undefinedModule, `View<${nestedView}> should NOT be a root component of a module.`);
|
||||
}
|
||||
|
||||
export function test_load_component_from_missing_module_throws() {
|
||||
export function test_create_view_from_entry_from_missing_module_throws() {
|
||||
assertThrows(() => getViewComponent(MISSING_MODULE),
|
||||
"Loading component from a missing module SHOULD throw an error.");
|
||||
}
|
||||
|
||||
export function test_create_view_from_entry_with_path_with_slash() {
|
||||
const view = getViewComponent("/" + COMPONENT_MODULE);
|
||||
assertNotNull(view, `Module starting with "/" could not be loaded`);
|
||||
}
|
||||
|
||||
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`);
|
||||
}
|
@ -57,20 +57,21 @@ export const createViewFromEntry = profile("createViewFromEntry", (entry: ViewEn
|
||||
|
||||
return view;
|
||||
} else if (entry.moduleName) {
|
||||
const resolvedCodeModuleName = resolveModuleName(entry.moduleName, ""); //`${moduleName}.xml`;
|
||||
const moduleName = sanitizeModuleName(entry.moduleName);
|
||||
const resolvedCodeModuleName = resolveModuleName(moduleName, ""); //`${moduleName}.xml`;
|
||||
let moduleExports = resolvedCodeModuleName ? global.loadModule(resolvedCodeModuleName) : null;
|
||||
|
||||
if (moduleExports && moduleExports.createPage) {
|
||||
// Exports has a createPage() method
|
||||
const view = moduleExports.createPage();
|
||||
const resolvedCssModuleName = resolveModuleName(entry.moduleName, "css"); //entry.moduleName + ".css";
|
||||
const resolvedCssModuleName = resolveModuleName(moduleName, "css"); //entry.moduleName + ".css";
|
||||
if (resolvedCssModuleName) {
|
||||
view.addCssFile(resolvedCssModuleName);
|
||||
}
|
||||
|
||||
return view;
|
||||
} else {
|
||||
const componentModule = loadInternal(entry.moduleName, moduleExports);
|
||||
const componentModule = loadInternal(moduleName, moduleExports);
|
||||
const componentView = componentModule && componentModule.component;
|
||||
|
||||
return componentView;
|
||||
|
Reference in New Issue
Block a user