JS backend: fixed bug with the sourcemap generation when binary operation used as statement.
This commit is contained in:
@@ -19,13 +19,16 @@ package org.jetbrains.js.compiler;
|
|||||||
import com.google.dart.compiler.backend.js.JsToStringGenerationVisitor;
|
import com.google.dart.compiler.backend.js.JsToStringGenerationVisitor;
|
||||||
import com.google.dart.compiler.backend.js.ast.*;
|
import com.google.dart.compiler.backend.js.ast.*;
|
||||||
import com.google.dart.compiler.util.TextOutput;
|
import com.google.dart.compiler.util.TextOutput;
|
||||||
|
import com.intellij.util.SmartList;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class JsSourceGenerationVisitor extends JsToStringGenerationVisitor implements TextOutput.OutListener {
|
public class JsSourceGenerationVisitor extends JsToStringGenerationVisitor implements TextOutput.OutListener {
|
||||||
@Nullable
|
@Nullable
|
||||||
private final SourceMapBuilder sourceMapBuilder;
|
private final SourceMapBuilder sourceMapBuilder;
|
||||||
|
|
||||||
private Object pendingSourceInfo;
|
private final List<Object> pendingSources = new SmartList<Object>();
|
||||||
|
|
||||||
public JsSourceGenerationVisitor(TextOutput out, @Nullable SourceMapBuilder sourceMapBuilder) {
|
public JsSourceGenerationVisitor(TextOutput out, @Nullable SourceMapBuilder sourceMapBuilder) {
|
||||||
super(out);
|
super(out);
|
||||||
@@ -52,11 +55,13 @@ public class JsSourceGenerationVisitor extends JsToStringGenerationVisitor imple
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void indentedAfterNewLine() {
|
public void indentedAfterNewLine() {
|
||||||
if (pendingSourceInfo != null) {
|
if (pendingSources.isEmpty()) return;
|
||||||
assert sourceMapBuilder != null;
|
|
||||||
sourceMapBuilder.processSourceInfo(pendingSourceInfo);
|
assert sourceMapBuilder != null;
|
||||||
pendingSourceInfo = null;
|
for (Object source : pendingSources) {
|
||||||
|
sourceMapBuilder.processSourceInfo(source);
|
||||||
}
|
}
|
||||||
|
pendingSources.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,9 +76,8 @@ public class JsSourceGenerationVisitor extends JsToStringGenerationVisitor imple
|
|||||||
if (sourceMapBuilder != null) {
|
if (sourceMapBuilder != null) {
|
||||||
Object sourceInfo = node.getSource();
|
Object sourceInfo = node.getSource();
|
||||||
if (sourceInfo != null) {
|
if (sourceInfo != null) {
|
||||||
assert pendingSourceInfo == null;
|
|
||||||
if (p.isJustNewlined()) {
|
if (p.isJustNewlined()) {
|
||||||
pendingSourceInfo = sourceInfo;
|
pendingSources.add(sourceInfo);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sourceMapBuilder.processSourceInfo(sourceInfo);
|
sourceMapBuilder.processSourceInfo(sourceInfo);
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
1 * 2 / 3
|
||||||
|
|
||||||
|
var ok = ""
|
||||||
|
ok += "O" + "K"
|
||||||
|
|
||||||
|
return ok
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user