FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add source information on the view by PanayotCankov · Pull Request #1761 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (4) .xml  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 5 additions & 0 deletions apps/tests/xml-declaration/examples/test-page.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<GridLayout id="grid">
<Label id="label" text="Text" />
</GridLayout>
</Page>
12 changes: 12 additions & 0 deletions apps/tests/xml-declaration/xml-declaration-tests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import viewModule = require("ui/core/view");
import platform = require("platform");
import gesturesModule = require("ui/gestures");
import segmentedBar = require("ui/segmented-bar");
import { Source } from "utils/debug";

export function test_load_IsDefined() {
TKUnit.assert(types.isFunction(builder.load), "ui/builder should have load method!");
Expand Down Expand Up @@ -974,3 +975,14 @@ export function test_TabViewHasCorrectParentChain() {
model.set("testPassed", false);
helper.navigateToModuleAndRunTest(("." + moduleName + "/mymodulewithxml/TabViewParentChain"), model, testFunc);
}

export function test_hasSourceCodeLocations() {
var basePath = "xml-declaration/";
var page = <Page>builder.load(__dirname + "/examples/test-page.xml");
var grid = page.getViewById("grid");
var gridSource = Source.get(grid);
TKUnit.assertEqual(gridSource.toString(), "file:///app/" + basePath + "examples/test-page.xml:2:3");
var label = page.getViewById("label");
var labelSource = Source.get(label);
TKUnit.assertEqual(labelSource.toString(), "file:///app/" + basePath + "examples/test-page.xml:3:5");
}
32 changes: 27 additions & 5 deletions ui/builder/builder.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ function parseInternal(value: string, context: any, uri?: string): ComponentModu
var ui: xml2ui.ComponentParser;

var errorFormat = (debug && uri) ? xml2ui.SourceErrorFormat(uri) : xml2ui.PositionErrorFormat;
var componentSourceTracker = (debug && uri) ? xml2ui.ComponentSourceTracker(uri) : () => {
// no-op
};

(start = new xml2ui.XmlStringParser(errorFormat))
.pipe(new xml2ui.PlatformFilter())
.pipe(new xml2ui.XmlStateParser(ui = new xml2ui.ComponentParser(context, errorFormat)));
.pipe(new xml2ui.XmlStateParser(ui = new xml2ui.ComponentParser(context, errorFormat, componentSourceTracker)));

start.parse(value);

Expand Down Expand Up @@ -225,6 +228,19 @@ namespace xml2ui {
}
}

interface SourceTracker {
(component: any, p: xml.Position): void;
}

export function ComponentSourceTracker(uri): SourceTracker {
return (component: any, p: xml.Position) => {
if (!Source.get(component)) {
var source = p ? new Source(uri, p.line, p.column) : new Source(uri, -1, -1);
Source.set(component, source);
}
}
}

export class PlatformFilter extends XmlProducerBase implements XmlProducer, XmlConsumer {
private currentPlatformContext: string;

Expand Down Expand Up @@ -293,6 +309,7 @@ namespace xml2ui {
elementName: string;
templateItems: Array<string>;
errorFormat: ErrorFormatter;
sourceTracker: SourceTracker;
}

/**
Expand Down Expand Up @@ -380,13 +397,14 @@ namespace xml2ui {
if (this._templateProperty.name in this._templateProperty.parent.component) {
var context = this._context;
var errorFormat = this._templateProperty.errorFormat;
var sourceTracker = this._templateProperty.sourceTracker;
var template: Template = () => {
var start: xml2ui.XmlArgsReplay;
var ui: xml2ui.ComponentParser;

(start = new xml2ui.XmlArgsReplay(this._recordedXmlStream, errorFormat))
// No platform filter, it has been filtered allready
.pipe(new XmlStateParser(ui = new ComponentParser(context, errorFormat)));
.pipe(new XmlStateParser(ui = new ComponentParser(context, errorFormat, sourceTracker)));

start.replay();

Expand Down Expand Up @@ -418,11 +436,13 @@ namespace xml2ui {
private parents = new Array<ComponentModule>();
private complexProperties = new Array<ComponentParser.ComplexProperty>();

private error;
private error: ErrorFormatter;
private sourceTracker: SourceTracker;

constructor(context: any, errorFormat: ErrorFormatter) {
constructor(context: any, errorFormat: ErrorFormatter, sourceTracker: SourceTracker) {
this.context = context;
this.error = errorFormat;
this.sourceTracker = sourceTracker;
}

public parse(args: xml.ParserEvent): XmlStateConsumer {
Expand Down Expand Up @@ -450,7 +470,8 @@ namespace xml2ui {
name: name,
elementName: args.elementName,
templateItems: [],
errorFormat: this.error
errorFormat: this.error,
sourceTracker: this.sourceTracker
});
}

Expand All @@ -472,6 +493,7 @@ namespace xml2ui {
}

if (componentModule) {
this.sourceTracker(componentModule.component, args.position);
if (parent) {
if (complexProperty) {
// Add component to complex property of parent component.
Expand Down
12 changes: 10 additions & 2 deletions ui/core/view-common.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as visualStateConstants from "ui/styling/visual-state-constants";
import * as bindableModule from "ui/core/bindable";
import * as visualStateModule from "../styling/visual-state";
import * as animModule from "ui/animation";
import { Source } from "utils/debug";

var bindable: typeof bindableModule;
function ensureBindable() {
Expand Down Expand Up @@ -1151,11 +1152,18 @@ export class View extends ProxyObject implements definition.View {
}

public toString(): string {
var str = this.typeName;
if (this.id) {
return this.typeName + `<${this.id}>`;
str += `<${this.id}>`;
} else {
str += `(${this._domId})`;
}
var source = Source.get(this);
if (source) {
str += `@${source};`;
}

return this.typeName + `(${this._domId})`;
return str;
}

public _setNativeViewFrame(nativeView: any, frame: any) {
Expand Down
2 changes: 1 addition & 1 deletion ui/core/view.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class View extends viewCommon.View {
// flag not set, setMeasuredDimension() was not invoked, we raise
// an exception to warn the developer
if ((this._privateFlags & PFLAG_MEASURED_DIMENSION_SET) !== PFLAG_MEASURED_DIMENSION_SET) {
throw new Error("onMeasure() did not set the measured dimension by calling setMeasuredDimension()");
throw new Error("onMeasure() did not set the measured dimension by calling setMeasuredDimension() " + this);
}
}
}
Expand Down

Back | FazBrowse Home | New Git URL