ng-typeview
Advanced tools
Comparing version 0.0.38 to 0.0.39
@@ -77,3 +77,20 @@ "use strict"; | ||
var enumerable = view_ngexpression_parser_1.ngFilterExpressionToTypeScriptEmbedded(ngRepeatData.value.expression, codegenHelpers); | ||
var source = "angular.forEach(" + enumerable + ", " + codegenHelpers.registerVariable(ngRepeatData.value.variable) + " => {" + | ||
// so here we have a hack to be able to support scenarios like | ||
// "(k,v) in data" -- if there are no spaces in the expression, | ||
// we actually parse it as one, variable name being "(k,v)". | ||
// We should fix the parsing but... I just take it as-is then | ||
// split in two variables "k" and "v", then hack around the iteration | ||
// to make it work the way angular does it. | ||
var shouldSplitVar = ngRepeatData.value.variable.startsWith("(") && | ||
ngRepeatData.value.variable.endsWith(")"); | ||
var keysIfSplit = function (x) { return shouldSplitVar ? "Object.keys(" + x + ")" : x; }; | ||
var splitterExpr = ""; | ||
if (shouldSplitVar) { | ||
var vars = ngRepeatData.value.variable.substring(1, ngRepeatData.value.variable.length - 1).split(","); | ||
vars.forEach(function (v, idx) { return codegenHelpers.registerVariable(v); }); | ||
var k = vars[0], v = vars[1]; | ||
splitterExpr = "const " + k + " = curKey; const " + v + " = " + enumerable + "[curKey];"; | ||
} | ||
var repeatVarExpr = shouldSplitVar ? "curKey" : codegenHelpers.registerVariable(ngRepeatData.value.variable); | ||
var source = "angular.forEach(" + keysIfSplit(enumerable) + ", " + repeatVarExpr + " => {" + | ||
("let " + codegenHelpers.registerVariable('$index') + " = 0;") + | ||
@@ -85,2 +102,3 @@ ("let " + codegenHelpers.registerVariable('$first') + " = true;") + | ||
("let " + codegenHelpers.registerVariable('$odd') + " = false;") + | ||
("" + splitterExpr) + | ||
(ngRepeatData.value.trackingExpression ? | ||
@@ -231,2 +249,14 @@ "" + codegenHelpers.declareVariable('any', ngRepeatData.value.trackingExpression) : ""); | ||
handleTag: function (tag, attribs, codegenHelpers) { | ||
var quoteOrNot = function (str) { | ||
if (str === "true" || str === "false") { | ||
return str; | ||
} | ||
if (str.match(/^\d+$/)) { | ||
return str; | ||
} | ||
return '"' + str + '"'; | ||
}; | ||
if (attribs.hasOwnProperty("ng-switch-default")) { | ||
return { source: "default:", closeSource: function () { return "break;"; } }; | ||
} | ||
if (!attribs.hasOwnProperty("ng-switch-when")) { | ||
@@ -241,3 +271,3 @@ return; | ||
else { | ||
return { source: "case " + codegenHelpers.addScopeAccessors(attribs['ng-switch-when']) + ": break;" }; | ||
return { source: "case " + quoteOrNot(attribs['ng-switch-when']) + ":", closeSource: function () { return "break;"; } }; | ||
} | ||
@@ -244,0 +274,0 @@ } |
@@ -114,2 +114,3 @@ "use strict"; | ||
" data: {groups: any[], firstname: string}\n" + | ||
" kvData: {[index:number]: string}\n" + | ||
" triggerAction: boolean\n" + | ||
@@ -116,0 +117,0 @@ " user: string;\n" + |
{ | ||
"name": "ng-typeview", | ||
"version": "0.0.38", | ||
"version": "0.0.39", | ||
"description": "library to enable type-checking of angular views when using typescript", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -70,2 +70,3 @@ import * as assert from 'assert' | ||
" data: {groups: any[], firstname: string}\n" + | ||
" kvData: {[index:number]: string}\n" + | ||
" triggerAction: boolean\n" + | ||
@@ -72,0 +73,0 @@ " user: string;\n" + |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2681
207326
41