-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAstGeneratorJavascriptBlock.cpp
More file actions
34 lines (25 loc) · 952 Bytes
/
AstGeneratorJavascriptBlock.cpp
File metadata and controls
34 lines (25 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <private/qqmljsast_p.h>
#include "AstGeneratorBase.h"
#include "AstGeneratorJavascriptBlock.h"
#include "Location.h"
#include "parser.h"
using namespace QQmlJS::AST;
json AstGeneratorJavascriptBlock::operator()(Statement *node) {
accept(node);
QString value = QString::fromStdString(toString(loc));
bool isBlock = node->kind == node->Kind_Block;
bool isObject = !isBlock && value.startsWith('{') && value.endsWith('}');
bool hasSemicolon = !isBlock && value.endsWith(';');
Location newLoc = hasSemicolon ? loc - 1 : loc;
ast["kind"] = isBlock ? "JavascriptBlock" : "JavascriptValue";
ast["loc"] = getLoc(newLoc);
ast["object"] = isObject;
ast["value"] = toString(newLoc);
return ast;
}
void AstGeneratorJavascriptBlock::accept(Node *node) {
Node::accept(node, this);
}
void AstGeneratorJavascriptBlock::postVisit(Node *node) {
loc = mergeLocs(loc, node->firstSourceLocation(), node->lastSourceLocation());
}