mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Added import attribute to page module. (#3009)
This commit is contained in:
committed by
Vladimir Enchev
parent
f63f61ce77
commit
fbe5f2cab1
@@ -168,6 +168,13 @@ export function test_parse_ShouldResolveExportsFromCodeFile() {
|
||||
TKUnit.assert((<any>page).customCodeLoaded, "Parse should resolve exports from custom code file.");
|
||||
}
|
||||
|
||||
export function test_parse_ShouldResolveExportsFromImport() {
|
||||
var page = builder.parse("<Page import='~/xml-declaration/custom-code-file' loaded='loaded'></Page>");
|
||||
page._emit("loaded");
|
||||
|
||||
TKUnit.assert((<any>page).customCodeLoaded, "Parse should resolve exports from import.");
|
||||
}
|
||||
|
||||
export function test_parse_ShouldResolveExportsFromCodeFileForPageContent() {
|
||||
var page = builder.parse("<Page codeFile='~/xml-declaration/custom-code-file' loaded='loaded'><Button loaded='loaded' /></Page>");
|
||||
(<any>page).content._emit("loaded");
|
||||
|
||||
@@ -28,6 +28,8 @@ var MODULES = {
|
||||
var CODEFILE = "codeFile";
|
||||
var CSSFILE = "cssFile";
|
||||
|
||||
var IMPORT = "import";
|
||||
|
||||
var platform: typeof platformModule;
|
||||
function ensurePlatform() {
|
||||
if (!platform) {
|
||||
@@ -82,6 +84,17 @@ export function getComponentModule(elementName: string, namespace: string, attri
|
||||
}
|
||||
|
||||
if (attributes) {
|
||||
if (attributes[IMPORT]) {
|
||||
var importPath = attributes[IMPORT].trim();
|
||||
|
||||
if (importPath.indexOf("~/") === 0) {
|
||||
importPath = path.join(knownFolders.currentApp().path, importPath.replace("~/", ""));
|
||||
}
|
||||
|
||||
exports = global.loadModule(importPath);
|
||||
(<any>instance).exports = exports;
|
||||
}
|
||||
|
||||
if (attributes[CODEFILE]) {
|
||||
if (instance instanceof Page) {
|
||||
var codeFilePath = attributes[CODEFILE].trim();
|
||||
|
||||
Reference in New Issue
Block a user