Merge pull request #921 from NativeScript/nnikolov/PropertyAccessorsThreatedAsExpressions

Fixed index property accessors are treated as expressions.
This commit is contained in:
Nedyalko Nikolov
2015-10-13 08:38:47 +03:00
2 changed files with 21 additions and 2 deletions

View File

@ -1,5 +1,5 @@
// regex that contains all symbols applicable for expression used to AI detect an expression. // regex that contains all symbols applicable for expression used to AI detect an expression.
var expressionSymbolsRegex = /[ \+\-\*%\?:<>=!\|&\(\)\[\]^~]/; var expressionSymbolsRegex = /[\+\-\*\/%\?:<>=!\|&\(\)^~]/;
export module bindingConstants { export module bindingConstants {
export var sourceProperty = "sourceProperty"; export var sourceProperty = "sourceProperty";

View File

@ -195,8 +195,27 @@ export class Binding {
} }
private static getProperties(property: string): Array<string> { private static getProperties(property: string): Array<string> {
var result: Array<string>;
if (property) { if (property) {
return property.split("."); // first replace all '$parents[..]' with a safe string
// second removes all ] since they are not important for property access and not needed
// then split properties either on '.' or '['
var parentsMatches = property.match(bindingBuilder.parentsRegex);
result = property.replace(bindingBuilder.parentsRegex, "parentsMatch")
.replace(/\]/g, "")
.split(/\.|\[/);
var i;
var resultLength = result.length;
var parentsMatchesCounter = 0;
for (i = 0; i < resultLength; i++) {
if (result[i] === "parentsMatch") {
result[i] = parentsMatches[parentsMatchesCounter];
parentsMatchesCounter++;
}
}
return result;
} }
else { else {
return []; return [];