-
Notifications
You must be signed in to change notification settings - Fork 28
Issue 285 - foreach syntax #292
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: 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 = { | ||
|
|
@@ -173,6 +179,20 @@ function goThroughSyntaxTree (tree) { | |
| }; | ||
| } | ||
|
|
||
| //('foreach') looks for next </foreach> | ||
| function getTagIndexFromCurrentPosition (tagName, isEnd) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of this function? |
||
|
|
||
| if (isEnd) { | ||
| var tagString = "</" + tagName + ">"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
| +0 −1 | test/w3c-ecma/test152.txml.scxml | |
| +4 −1 | test/w3c-ecma/test321.txml.scxml | |
| +1 −1 | test/w3c-ecma/test323.txml.scxml |
There was a problem hiding this comment.
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.