From 7c5d1011cba8c7342ea729f5f00a2ad57f04d461 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Wed, 17 Jun 2015 16:07:42 +0300 Subject: [PATCH] throw error if nesting platform tags + test --- apps/tests/xml-declaration/xml-declaration-tests.ts | 11 +++++++++++ ui/builder/builder.ts | 13 +++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/apps/tests/xml-declaration/xml-declaration-tests.ts b/apps/tests/xml-declaration/xml-declaration-tests.ts index a932e97b5..54385ba32 100644 --- a/apps/tests/xml-declaration/xml-declaration-tests.ts +++ b/apps/tests/xml-declaration/xml-declaration-tests.ts @@ -152,6 +152,17 @@ export function test_parse_ShouldParsePlatformSpecificComponents() { } }; +export function test_parse_ThrowErrorWhenNestingPlatforms() { + var e: Error; + try { + builder.parse(""); + } catch (ex) { + e = ex; + } + + TKUnit.assert(e, "Expected result: Error; Actual result: " + e); +}; + export function test_parse_ShouldParseBindings() { var p = builder.parse(""); p.bindingContext = { myProp: true }; diff --git a/ui/builder/builder.ts b/ui/builder/builder.ts index 76c1887a3..c0de226fd 100644 --- a/ui/builder/builder.ts +++ b/ui/builder/builder.ts @@ -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);