fix: fix syntax error in compiling functions

fix syntax error in DesktopEngine.compileFunction
This commit is contained in:
Frank.R.Wu 2021-11-10 22:07:19 +08:00
parent 24123435be
commit 5ed245459c
3 changed files with 10 additions and 9 deletions

View File

@ -62,11 +62,7 @@ public class ContractNode {
cn.initText(cts); cn.initText(cts);
} }
for (FunctionNode fun : functions) { for (FunctionNode fun : functions) {
if (fun.isExport) { fun.initTextWithCleaning(cts, fun.isExport, fun.isView());
fun.initTextWithoutExport(cts);
} else {
fun.initText(cts);
}
if (fun.isExport || fun.functionName.equals("onCreate")) { if (fun.isExport || fun.functionName.equals("onCreate")) {
fun.initTextWithRequester(); fun.initTextWithRequester();
} }

View File

@ -34,10 +34,16 @@ public class Script {
public void initText(CommonTokenStream cts) { public void initText(CommonTokenStream cts) {
plainText = cts.getText(interval); plainText = cts.getText(interval);
} }
public void initTextWithoutExport(CommonTokenStream cts) { public void initTextWithCleaning(CommonTokenStream cts, boolean isExported, boolean isView) {
plainText = cts.getText(interval).replaceFirst("export", ""); String plainText = cts.getText(interval);
if (isExported) {
plainText = plainText.replaceFirst("exported", "");
}
if (isView) {
plainText = plainText.replaceFirst("\\)\\s?view\\s?\\{", "){");
}
this.plainText = plainText;
} }
} }

View File

@ -57,7 +57,6 @@ public class FunctionReader extends YJSParserBaseVisitor<FunctionNode> {
node.setInterval( node.setInterval(
new Interval(ctx.Function().getSourceInterval().a, ctx.getSourceInterval().b)); new Interval(ctx.Function().getSourceInterval().a, ctx.getSourceInterval().b));
List<AnnotationContext> annotations = new ArrayList<>(); List<AnnotationContext> annotations = new ArrayList<>();
if (null != ctx.annotations()) { if (null != ctx.annotations()) {
annotations = ctx.annotations().annotation(); annotations = ctx.annotations().annotation();