mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 03:01:51 +08:00
feat(core): support for external XML UI compilers (#10008)
This commit is contained in:

committed by
GitHub

parent
40b9e3578f
commit
75503ef110
@ -55,9 +55,19 @@ export class Builder {
|
||||
|
||||
return view;
|
||||
} else {
|
||||
const componentModule = loadInternal(moduleName, moduleExports);
|
||||
const componentView = componentModule && componentModule.component;
|
||||
|
||||
let componentView;
|
||||
if (__UI_USE_XML_PARSER__) {
|
||||
const componentModule = loadInternal(moduleName, moduleExports);
|
||||
componentView = componentModule && componentModule.component;
|
||||
} else {
|
||||
const resolvedXmlModuleName = resolveModuleName(moduleName, 'xml');
|
||||
const componentModule = resolvedXmlModuleName ? global.loadModule(resolvedXmlModuleName, true) : null;
|
||||
if (componentModule?.default) {
|
||||
componentView = new componentModule.default();
|
||||
} else {
|
||||
throw new Error('Failed to load component from module: ' + moduleName);
|
||||
}
|
||||
}
|
||||
return componentView;
|
||||
}
|
||||
}
|
||||
@ -226,7 +236,7 @@ function parseInternal(value: string, context: any, xmlModule?: string, moduleNa
|
||||
if (__UI_USE_XML_PARSER__) {
|
||||
let start: xml2ui.XmlStringParser;
|
||||
let ui: xml2ui.ComponentParser;
|
||||
|
||||
|
||||
const errorFormat = debug && xmlModule ? xml2ui.SourceErrorFormat(xmlModule) : xml2ui.PositionErrorFormat;
|
||||
const componentSourceTracker =
|
||||
debug && xmlModule
|
||||
@ -234,15 +244,13 @@ function parseInternal(value: string, context: any, xmlModule?: string, moduleNa
|
||||
: () => {
|
||||
// no-op
|
||||
};
|
||||
|
||||
|
||||
(start = new xml2ui.XmlStringParser(errorFormat)).pipe(new xml2ui.PlatformFilter()).pipe(new xml2ui.XmlStateParser((ui = new xml2ui.ComponentParser(context, errorFormat, componentSourceTracker, moduleName))));
|
||||
|
||||
|
||||
start.parse(value);
|
||||
|
||||
|
||||
return ui.rootComponentModule;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user