From 811e42b6d81953b308baa88ff8f0910778375f17 Mon Sep 17 00:00:00 2001 From: Feyzo Date: Wed, 1 Oct 2014 12:51:24 +0300 Subject: [PATCH 1/5] Implemented foreach item syntax check --- lib/compiler/static-analysis/scxml-analyzer.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/compiler/static-analysis/scxml-analyzer.js b/lib/compiler/static-analysis/scxml-analyzer.js index 690121cd..1f8279be 100644 --- a/lib/compiler/static-analysis/scxml-analyzer.js +++ b/lib/compiler/static-analysis/scxml-analyzer.js @@ -80,7 +80,13 @@ var openNodeTypes = { validateJavascriptExpression(node.attributes.cond.value, parser.startTagPosition - 1, parser.position); } - } + }, + "foreach": function (node) { + if(node.attributes.item) { + var constructedExpression = node.attributes.item.value + '=testvalue;'; + validateJavascriptExpression(constructedExpression, parser.startTagPosition - 1, getClosingTagIndex('foreach')); + } + } }; var closedNodeTypes = { @@ -173,6 +179,13 @@ function goThroughSyntaxTree (tree) { }; } +//('foreach') looks for next +function getClosingTagIndex (currentTagName) { + var closingTagString = ""; + + return parser.position + currentScxml.substring(parser.position).indexOf(closingTagString) + closingTagString.length; +} + var treeTypes = { "BlockStatement": function (tree) { tree = tree.body; From 5e08512fc9cdf2df302b369acc12275b7dfe43e0 Mon Sep 17 00:00:00 2001 From: Feyzo Date: Wed, 1 Oct 2014 17:18:48 +0300 Subject: [PATCH 2/5] Removed iteration on objects with error --- lib/compiler/scjson-to-module.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/compiler/scjson-to-module.js b/lib/compiler/scjson-to-module.js index 1f75c242..56d27424 100644 --- a/lib/compiler/scjson-to-module.js +++ b/lib/compiler/scjson-to-module.js @@ -473,12 +473,7 @@ var actionTags = { foreachFnNames.map(function(fnName){return ' ' + generateFnCall(fnName) + ';';}).join('\n') + '\n' + ' }\n' + '} else{\n' + - ' for(' + index + ' in ' + shallowArrayName + '){\n' + - ' if(' + shallowArrayName + '.hasOwnProperty(' + index + ')){\n' + - ' ' + item + ' = ' + shallowArrayName + '[' + index + '];\n' + - foreachFnNames.map(function(fnName){return ' ' + generateFnCall(fnName) + ';';}).join('\n') + '\n' + - ' }\n' + - ' }\n' + + ' this.raise({ name:"error.execution", data : {}});\n' + '}'; return forEachContents; From 45523fff8ebcd8d0972b8fb62715da7595d8ff89 Mon Sep 17 00:00:00 2001 From: Feyzo Date: Wed, 1 Oct 2014 17:19:36 +0300 Subject: [PATCH 3/5] Updated test152 on test framework --- test/scxml-test-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scxml-test-framework b/test/scxml-test-framework index bbf10166..4d579394 160000 --- a/test/scxml-test-framework +++ b/test/scxml-test-framework @@ -1 +1 @@ -Subproject commit bbf101665412b0f80c340df9f109f9c2af4120eb +Subproject commit 4d5793943d45731ae06c0fe8c246c65531bf6828 From 29e891e170499867cc4469aea3fa14e6671d3377 Mon Sep 17 00:00:00 2001 From: Feyzo Date: Wed, 1 Oct 2014 17:19:43 +0300 Subject: [PATCH 4/5] Added test 152 --- test/run-tests-node.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/run-tests-node.sh b/test/run-tests-node.sh index 9f594d65..096e8812 100755 --- a/test/run-tests-node.sh +++ b/test/run-tests-node.sh @@ -36,6 +36,7 @@ node scxml-test-framework/lib/test-client.js -v -r console \ scxml-test-framework/test/targetless-transition/*.scxml \ scxml-test-framework/test/w3c-ecma/test150.txml.scxml \ scxml-test-framework/test/w3c-ecma/test151.txml.scxml \ + scxml-test-framework/test/w3c-ecma/test152.txml.scxml \ scxml-test-framework/test/w3c-ecma/test309.txml.scxml \ scxml-test-framework/test/w3c-ecma/test312.txml.scxml \ scxml-test-framework/test/w3c-ecma/test313.txml.scxml \ From 03ba558bbf7b40323e96095242ecc387697f3c8a Mon Sep 17 00:00:00 2001 From: Feyzo Date: Thu, 2 Oct 2014 21:18:30 +0300 Subject: [PATCH 5/5] Upgraded fing tag method --- lib/compiler/static-analysis/scxml-analyzer.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/compiler/static-analysis/scxml-analyzer.js b/lib/compiler/static-analysis/scxml-analyzer.js index 1f8279be..27b7e213 100644 --- a/lib/compiler/static-analysis/scxml-analyzer.js +++ b/lib/compiler/static-analysis/scxml-analyzer.js @@ -84,7 +84,7 @@ var openNodeTypes = { "foreach": function (node) { if(node.attributes.item) { var constructedExpression = node.attributes.item.value + '=testvalue;'; - validateJavascriptExpression(constructedExpression, parser.startTagPosition - 1, getClosingTagIndex('foreach')); + validateJavascriptExpression(constructedExpression, parser.startTagPosition - 1, getTagIndexFromCurrentPosition('foreach', true)); } } }; @@ -180,10 +180,17 @@ function goThroughSyntaxTree (tree) { } //('foreach') looks for next -function getClosingTagIndex (currentTagName) { - var closingTagString = ""; +function getTagIndexFromCurrentPosition (tagName, isEnd) { - return parser.position + currentScxml.substring(parser.position).indexOf(closingTagString) + closingTagString.length; + if (isEnd) { + var tagString = ""; + + return parser.position + currentScxml.substring(parser.position).indexOf(tagString) + tagString.length; + } else { + var tagString = "<" + tagName + ">"; + + return currentScxml.substring(0, parser.startTagPosition).lastIndexOf(tagString); + } } var treeTypes = {