Skip to content

Commit f006cb1

Browse files
Accept baseline changes for ASI prevention tests
Co-authored-by: RyanCavanaugh <[email protected]>
1 parent f072810 commit f006cb1

9 files changed

+111
-381
lines changed

internal/printer/printer.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2947,8 +2947,38 @@ func (p *Printer) emitPartiallyEmittedExpression(node *ast.PartiallyEmittedExpre
29472947
}
29482948
}
29492949

2950+
func (p *Printer) commentWillEmitNewLine(comment ast.CommentRange) bool {
2951+
return comment.Kind == ast.KindSingleLineCommentTrivia || comment.HasTrailingNewLine
2952+
}
2953+
29502954
func (p *Printer) willEmitLeadingNewLine(node *ast.Expression) bool {
2951-
return false // !!! check if node will emit a leading comment that contains a trailing newline
2955+
if p.currentSourceFile == nil {
2956+
return false
2957+
}
2958+
2959+
leadingCommentRanges := scanner.GetLeadingCommentRanges(p.emitContext.Factory.AsNodeFactory(), p.currentSourceFile.Text(), node.Pos())
2960+
for comment := range leadingCommentRanges {
2961+
// Check if the comment will emit a newline
2962+
if p.commentWillEmitNewLine(comment) {
2963+
return true
2964+
}
2965+
}
2966+
2967+
// For PartiallyEmittedExpression, recursively check the inner expression
2968+
if node.Kind == ast.KindPartiallyEmittedExpression {
2969+
pee := node.AsPartiallyEmittedExpression()
2970+
if node.Pos() != pee.Expression.Pos() {
2971+
trailingCommentRanges := scanner.GetTrailingCommentRanges(p.emitContext.Factory.AsNodeFactory(), p.currentSourceFile.Text(), pee.Expression.Pos())
2972+
for comment := range trailingCommentRanges {
2973+
if p.commentWillEmitNewLine(comment) {
2974+
return true
2975+
}
2976+
}
2977+
}
2978+
return p.willEmitLeadingNewLine(pee.Expression)
2979+
}
2980+
2981+
return false
29522982
}
29532983

29542984
func (p *Printer) emitExpressionNoASI(node *ast.Expression, precedence ast.OperatorPrecedence) {

testdata/baselines/reference/submodule/conformance/returnStatementNoAsiAfterTransform(target=es5).js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,52 +67,52 @@ function t10() {
6767

6868
//// [returnStatementNoAsiAfterTransform.js]
6969
function t1() {
70-
return
70+
return (
7171
// comment
72-
a;
72+
a);
7373
}
7474
function t2() {
75-
return
75+
return (
7676
// comment
77-
a + 1;
77+
a) + 1;
7878
}
7979
function t3() {
80-
return
80+
return (
8181
// comment
82-
a ? 0 : 1;
82+
a) ? 0 : 1;
8383
}
8484
function t4() {
85-
return
85+
return (
8686
// comment
87-
a.b;
87+
a).b;
8888
}
8989
function t5() {
90-
return
90+
return (
9191
// comment
92-
a[a];
92+
a)[a];
9393
}
9494
function t6() {
95-
return
95+
return (
9696
// comment
97-
a();
97+
a)();
9898
}
9999
function t7() {
100-
return
100+
return (
101101
// comment
102-
a ``;
102+
a) ``;
103103
}
104104
function t8() {
105-
return
105+
return (
106106
// comment
107-
a;
107+
a);
108108
}
109109
function t9() {
110-
return
110+
return (
111111
// comment
112-
a;
112+
a);
113113
}
114114
function t10() {
115-
return
115+
return (
116116
// comment
117-
a;
117+
a);
118118
}

testdata/baselines/reference/submodule/conformance/returnStatementNoAsiAfterTransform(target=es5).js.diff

Lines changed: 0 additions & 75 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/returnStatementNoAsiAfterTransform(target=esnext).js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,52 +67,52 @@ function t10() {
6767

6868
//// [returnStatementNoAsiAfterTransform.js]
6969
function t1() {
70-
return
70+
return (
7171
// comment
72-
a;
72+
a);
7373
}
7474
function t2() {
75-
return
75+
return (
7676
// comment
77-
a + 1;
77+
a) + 1;
7878
}
7979
function t3() {
80-
return
80+
return (
8181
// comment
82-
a ? 0 : 1;
82+
a) ? 0 : 1;
8383
}
8484
function t4() {
85-
return
85+
return (
8686
// comment
87-
a.b;
87+
a).b;
8888
}
8989
function t5() {
90-
return
90+
return (
9191
// comment
92-
a[a];
92+
a)[a];
9393
}
9494
function t6() {
95-
return
95+
return (
9696
// comment
97-
a();
97+
a)();
9898
}
9999
function t7() {
100-
return
100+
return (
101101
// comment
102-
a ``;
102+
a) ``;
103103
}
104104
function t8() {
105-
return
105+
return (
106106
// comment
107-
a;
107+
a);
108108
}
109109
function t9() {
110-
return
110+
return (
111111
// comment
112-
a;
112+
a);
113113
}
114114
function t10() {
115-
return
115+
return (
116116
// comment
117-
a;
117+
a);
118118
}

testdata/baselines/reference/submodule/conformance/returnStatementNoAsiAfterTransform(target=esnext).js.diff

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)