[JS AST] Add single line comment node

This commit is contained in:
Zalim Bashorov
2019-11-20 19:17:04 +03:00
parent 5fe79f71ad
commit 83e85b3ec8
4 changed files with 40 additions and 0 deletions
@@ -1046,6 +1046,14 @@ public class JsToStringGenerationVisitor extends JsVisitor {
popSourceInfo();
}
@Override
public void visitSingleLineComment(@NotNull JsSingleLineComment comment) {
p.print("//");
p.print(comment.getText());
needSemi = false;
newline();
}
@Override
public void visitDocComment(@NotNull JsDocComment comment) {
boolean asSingleLine = comment.getTags().size() == 1;
@@ -0,0 +1,22 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.js.backend.ast
class JsSingleLineComment(val text: String) : SourceInfoAwareJsNode(), JsStatement {
override fun accept(visitor: JsVisitor) {
visitor.visitSingleLineComment(this)
}
override fun acceptChildren(visitor: JsVisitor) {
}
override fun traverse(visitor: JsVisitorWithContext, ctx: JsContext<*>) {
visitor.visit(this, ctx)
visitor.endVisit(this, ctx)
}
override fun deepCopy() = this
}
@@ -159,6 +159,9 @@ abstract class JsVisitor {
open fun visitDocComment(comment: JsDocComment): Unit =
visitElement(comment)
open fun visitSingleLineComment(comment: JsSingleLineComment): Unit =
visitElement(comment)
protected open fun visitElement(node: JsNode) {
}
}
@@ -207,6 +207,9 @@ public abstract class JsVisitorWithContext {
public void endVisit(@NotNull JsVars x, @NotNull JsContext ctx) {
}
public void endVisit(@NotNull JsSingleLineComment x, @NotNull JsContext ctx) {
}
public void endVisit(@NotNull JsWhile x, @NotNull JsContext ctx) {
endVisit((JsLoop) x, ctx);
}
@@ -383,6 +386,10 @@ public abstract class JsVisitorWithContext {
return visit((JsLoop) x, ctx);
}
public boolean visit(@NotNull JsSingleLineComment x, @NotNull JsContext ctx) {
return true;
}
protected abstract <T extends JsNode> T doAccept(T node);
protected abstract JsExpression doAcceptLvalue(JsExpression expr);