Skip to content

Commit 5447b04

Browse files
committed
Refactoring ui/builder and template builder to preserve source information for templates
1 parent 8bee3ed commit 5447b04

File tree

6 files changed

+451
-326
lines changed

6 files changed

+451
-326
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
2+
xmlns:tc="xml-declaration/template-builder-tests/template-view">
3+
<tc:TemplateView id="template-view">
4+
<tc:TemplateView.template>
5+
<StackLayout>
6+
<!--
7+
At first I was going to put "MenuItem",
8+
as per https://github.com/NativeScript/NativeScript/issues/501,
9+
but then again we may re-introduce "MenuItem" in future and blow this test up.
10+
So here is something unique that has better chance not to appear.
11+
This comment also offsets error's row and column numbers so if you edit,
12+
please do so beyond the unicorn.
13+
-->
14+
<Unicorn backgroundColor="pink" />
15+
<Label text="Modal Page" />
16+
</StackLayout>
17+
</tc:TemplateView.template>
18+
</tc:TemplateView>
19+
</Page>

apps/tests/xml-declaration/xml-declaration-tests.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ export function test_parse_template_property() {
837837
TKUnit.assertEqual(button.text, "Click!", "Expected child Button to have text 'Click!'");
838838
}
839839

840-
export function test_ParserError() {
840+
export function test_NonExistingElementError() {
841841
var basePath = "xml-declaration/";
842842
var expectedErrorStart =
843843
"Building UI from XML. @file:///app/" + basePath + "errors/non-existing-element.xml:11:5\n" +
@@ -856,3 +856,28 @@ export function test_ParserError() {
856856
}
857857
TKUnit.assertEqual(message.substr(0, expectedErrorStart.length), expectedErrorStart, "Expected load to throw, and the message to start with specific string");
858858
}
859+
860+
export function test_NonExistingElementInTemplateError() {
861+
var basePath = "xml-declaration/";
862+
var expectedErrorStart =
863+
"Building UI from XML. @file:///app/" + basePath + "errors/non-existing-element-in-template.xml:14:17\n" +
864+
" ↳Module 'ui/unicorn' not found for element 'Unicorn'.\n";
865+
if (global.android) {
866+
expectedErrorStart += " ↳Module \"ui/unicorn\" not found";
867+
} else {
868+
expectedErrorStart += " ↳Failed to find module 'ui/unicorn'";
869+
}
870+
871+
var message;
872+
var page = builder.load(__dirname + "/errors/non-existing-element-in-template.xml");
873+
TKUnit.assert(view, "Expected the xml to generate a page");
874+
var templateView = <TemplateView>page.getViewById("template-view");
875+
TKUnit.assert(templateView, "Expected the page to have a TemplateView with 'temaplte-view' id.");
876+
877+
try {
878+
templateView.parseTemplate();
879+
} catch(e) {
880+
message = e.message;
881+
}
882+
TKUnit.assertEqual(message.substr(0, expectedErrorStart.length), expectedErrorStart, "Expected load to throw, and the message to start with specific string");
883+
}

tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,6 @@
478478
"ui/builder/component-builder.ts",
479479
"ui/builder/special-properties.d.ts",
480480
"ui/builder/special-properties.ts",
481-
"ui/builder/template-builder.d.ts",
482-
"ui/builder/template-builder.ts",
483481
"ui/button/button-common.ts",
484482
"ui/button/button.android.ts",
485483
"ui/button/button.d.ts",

0 commit comments

Comments
 (0)