JS backend: fixed bug with the sourcemap generation when binary operation used as statement.

This commit is contained in:
Zalim Bashorov
2013-10-07 20:09:56 +04:00
parent d3b4e4eb1f
commit 0aa1d0265b
2 changed files with 21 additions and 7 deletions
@@ -19,13 +19,16 @@ package org.jetbrains.js.compiler;
import com.google.dart.compiler.backend.js.JsToStringGenerationVisitor;
import com.google.dart.compiler.backend.js.ast.*;
import com.google.dart.compiler.util.TextOutput;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class JsSourceGenerationVisitor extends JsToStringGenerationVisitor implements TextOutput.OutListener {
@Nullable
private final SourceMapBuilder sourceMapBuilder;
private Object pendingSourceInfo;
private final List<Object> pendingSources = new SmartList<Object>();
public JsSourceGenerationVisitor(TextOutput out, @Nullable SourceMapBuilder sourceMapBuilder) {
super(out);
@@ -52,11 +55,13 @@ public class JsSourceGenerationVisitor extends JsToStringGenerationVisitor imple
@Override
public void indentedAfterNewLine() {
if (pendingSourceInfo != null) {
assert sourceMapBuilder != null;
sourceMapBuilder.processSourceInfo(pendingSourceInfo);
pendingSourceInfo = null;
if (pendingSources.isEmpty()) return;
assert sourceMapBuilder != null;
for (Object source : pendingSources) {
sourceMapBuilder.processSourceInfo(source);
}
pendingSources.clear();
}
@Override
@@ -71,9 +76,8 @@ public class JsSourceGenerationVisitor extends JsToStringGenerationVisitor imple
if (sourceMapBuilder != null) {
Object sourceInfo = node.getSource();
if (sourceInfo != null) {
assert pendingSourceInfo == null;
if (p.isJustNewlined()) {
pendingSourceInfo = sourceInfo;
pendingSources.add(sourceInfo);
}
else {
sourceMapBuilder.processSourceInfo(sourceInfo);
@@ -0,0 +1,10 @@
package foo
fun box(): String {
1 * 2 / 3
var ok = ""
ok += "O" + "K"
return ok
}