mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
throw error if nesting platform tags + test
This commit is contained in:
@ -152,6 +152,17 @@ export function test_parse_ShouldParsePlatformSpecificComponents() {
|
||||
}
|
||||
};
|
||||
|
||||
export function test_parse_ThrowErrorWhenNestingPlatforms() {
|
||||
var e: Error;
|
||||
try {
|
||||
builder.parse("<Page><ios><TextField /><android><Label /></android></ios></Page>");
|
||||
} catch (ex) {
|
||||
e = ex;
|
||||
}
|
||||
|
||||
TKUnit.assert(e, "Expected result: Error; Actual result: " + e);
|
||||
};
|
||||
|
||||
export function test_parse_ShouldParseBindings() {
|
||||
var p = <page.Page>builder.parse("<Page><Switch checked='{{ myProp }}' /></Page>");
|
||||
p.bindingContext = { myProp: true };
|
||||
|
@ -49,15 +49,16 @@ function parseInternal(value: string, exports: any): componentBuilder.ComponentM
|
||||
|
||||
if (args.eventType === xml.ParserEventType.StartElement) {
|
||||
if (isPlatform(args.elementName)) {
|
||||
|
||||
if (currentPlatformContext) {
|
||||
throw new Error("Already in '" + currentPlatformContext + "' platform context and cannot switch to '" + args.elementName + "' platform! Platform tags cannot be nested.");
|
||||
}
|
||||
|
||||
currentPlatformContext = args.elementName;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentPlatformContext && !isCurentPlatform(currentPlatformContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.eventType === xml.ParserEventType.EndElement) {
|
||||
if (isPlatform(args.elementName)) {
|
||||
currentPlatformContext = undefined;
|
||||
@ -65,6 +66,10 @@ function parseInternal(value: string, exports: any): componentBuilder.ComponentM
|
||||
}
|
||||
}
|
||||
|
||||
if (currentPlatformContext && !isCurentPlatform(currentPlatformContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (templateBuilder) {
|
||||
if (args.eventType === xml.ParserEventType.StartElement) {
|
||||
templateBuilder.addStartElement(args.prefix, args.namespace, args.elementName, args.attributes);
|
||||
|
Reference in New Issue
Block a user