Skip to content
This repository was archived by the owner on Sep 25, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lib/compiler/scjson-to-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be dedented two spaces.

'}';

return forEachContents;
Expand Down
22 changes: 21 additions & 1 deletion lib/compiler/static-analysis/scxml-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, getTagIndexFromCurrentPosition('foreach', true));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should check that the top-level node is an ExpressionStatement. Like this:

http://esprima.org/demo/parse.html?code=%2F%2F%20Life%2C%20Universe%2C%20and%20Everything%0A6%20*%207%3B%0A

Expression “6 * 7” yields:

{
    "type": "Program",
    "body": [
        {
            "type": "ExpressionStatement",
            "expression": {
                "type": "BinaryExpression",
                "operator": "*",
                "left": {
                    "type": "Literal",
                    "value": 6,
                    "raw": "6"
                },
                "right": {
                    "type": "Literal",
                    "value": 7,
                    "raw": "7"
                }
            }
        }
    ]
}

Then you do not need to create a constructed expression.

You will still need to wrap esprima.parse it in a try/catch to catch syntax errors.

}
}
};

var closedNodeTypes = {
Expand Down Expand Up @@ -173,6 +179,20 @@ function goThroughSyntaxTree (tree) {
};
}

//('foreach') looks for next </foreach>
function getTagIndexFromCurrentPosition (tagName, isEnd) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this function?


if (isEnd) {
var tagString = "</" + tagName + ">";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to break on weird whitespace? E.g. the legally valid xml close tag ""


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 = {
"BlockStatement": function (tree) {
tree = tree.body;
Expand Down
1 change: 1 addition & 0 deletions test/run-tests-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion test/scxml-test-framework