Skip to content

Commit 5c2cafa

Browse files
authored
Fix leading source file comment emit bugs (#1945)
1 parent 8bf36dd commit 5c2cafa

File tree

857 files changed

+2059
-4404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

857 files changed

+2059
-4404
lines changed

internal/printer/printer.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4384,18 +4384,24 @@ func (p *Printer) emitSourceFile(node *ast.SourceFile) {
43844384

43854385
p.writeLine()
43864386

4387-
state := p.emitDetachedCommentsBeforeStatementList(node.AsNode(), node.Statements.Loc)
43884387
p.pushNameGenerationScope(node.AsNode())
43894388
p.generateAllNames(node.Statements)
43904389

43914390
index := 0
4391+
var state *commentState
43924392
if node.ScriptKind != core.ScriptKindJSON {
43934393
p.emitShebangIfNeeded(node)
43944394
index = p.emitPrologueDirectives(node.Statements)
4395+
if !p.writer.IsAtStartOfLine() {
4396+
p.writeLine()
4397+
}
4398+
state = p.emitDetachedCommentsBeforeStatementList(node.AsNode(), node.Statements.Loc)
43954399
p.emitHelpers(node.AsNode())
43964400
if node.IsDeclarationFile {
43974401
p.emitTripleSlashDirectives(node)
43984402
}
4403+
} else {
4404+
state = p.emitDetachedCommentsBeforeStatementList(node.AsNode(), node.Statements.Loc)
43994405
}
44004406

44014407
// !!! Emit triple-slash directives
@@ -5083,7 +5089,7 @@ func (p *Printer) emitDetachedCommentsBeforeStatementList(node *ast.Node, detach
50835089
containerPos := p.containerPos
50845090
containerEnd := p.containerEnd
50855091
declarationListContainerEnd := p.declarationListContainerEnd
5086-
skipLeadingComments := emitFlags&EFNoLeadingComments == 0 && !ast.PositionIsSynthesized(detachedRange.Pos())
5092+
skipLeadingComments := ast.PositionIsSynthesized(detachedRange.Pos()) || emitFlags&EFNoLeadingComments != 0
50875093

50885094
if !skipLeadingComments {
50895095
p.emitDetachedCommentsAndUpdateCommentsInfo(detachedRange)

testdata/baselines/reference/compiler/declarationEmitNoCrashOnCrossFileNode.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testdata/baselines/reference/compiler/emitEndOfFileJSDocComments2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function test(param) {
2323

2424
//// [emitEndOfFileJSDocComments2.js]
2525
"use strict";
26-
Object.defineProperty(exports, "__esModule", { value: true });
2726
/** @typedef {number} A */
27+
Object.defineProperty(exports, "__esModule", { value: true });
2828
/**
2929
* JSDoc comment for function
3030
* @param {string} param - A string parameter

testdata/baselines/reference/submodule/compiler/APISample_Watch.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ watchMain();
8585

8686
//// [APISample_Watch.js]
8787
"use strict";
88+
/*
89+
* Note: This test is a public API sample. The sample sources can be found
90+
* at: https://github.com/Microsoft/TypeScript-wiki/blob/master/Using-the-Compiler-API.md#writing-an-incremental-program-watcher
91+
* Please log a "breaking change" issue for any API breaking change affecting this issue
92+
*/
8893
Object.defineProperty(exports, "__esModule", { value: true });
8994
const ts = require("typescript");
9095
const formatHost = {

testdata/baselines/reference/submodule/compiler/APISample_Watch.js.diff

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
--- old.APISample_Watch.js
22
+++ new.APISample_Watch.js
3-
@@= skipped -84, +84 lines =@@
4-
5-
//// [APISample_Watch.js]
6-
"use strict";
7-
-/*
8-
- * Note: This test is a public API sample. The sample sources can be found
9-
- * at: https://github.com/Microsoft/TypeScript-wiki/blob/master/Using-the-Compiler-API.md#writing-an-incremental-program-watcher
10-
- * Please log a "breaking change" issue for any API breaking change affecting this issue
11-
- */
3+
@@= skipped -90, +90 lines =@@
4+
* Please log a "breaking change" issue for any API breaking change affecting this issue
5+
*/
126
Object.defineProperty(exports, "__esModule", { value: true });
137
-var ts = require("typescript");
148
+const ts = require("typescript");

testdata/baselines/reference/submodule/compiler/APISample_WatchWithDefaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ watchMain();
5858

5959
//// [APISample_WatchWithDefaults.js]
6060
"use strict";
61+
/*
62+
* Note: This test is a public API sample. This uses default sys interface without having to pass anything
63+
* Please log a "breaking change" issue for any API breaking change affecting this issue
64+
*/
6165
Object.defineProperty(exports, "__esModule", { value: true });
6266
const ts = require("typescript");
6367
function watchMain() {

testdata/baselines/reference/submodule/compiler/APISample_WatchWithDefaults.js.diff

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
--- old.APISample_WatchWithDefaults.js
22
+++ new.APISample_WatchWithDefaults.js
3-
@@= skipped -57, +57 lines =@@
4-
5-
//// [APISample_WatchWithDefaults.js]
6-
"use strict";
7-
-/*
8-
- * Note: This test is a public API sample. This uses default sys interface without having to pass anything
9-
- * Please log a "breaking change" issue for any API breaking change affecting this issue
10-
- */
3+
@@= skipped -62, +62 lines =@@
4+
* Please log a "breaking change" issue for any API breaking change affecting this issue
5+
*/
116
Object.defineProperty(exports, "__esModule", { value: true });
127
-var ts = require("typescript");
138
+const ts = require("typescript");

testdata/baselines/reference/submodule/compiler/APISample_WatchWithOwnWatchHost.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ watchMain();
6565

6666
//// [APISample_WatchWithOwnWatchHost.js]
6767
"use strict";
68+
/*
69+
* Note: This test is a public API sample. This sample verifies creating abstract builder to watch list of root files
70+
* Please log a "breaking change" issue for any API breaking change affecting this issue
71+
*/
6872
Object.defineProperty(exports, "__esModule", { value: true });
6973
const ts = require("typescript");
7074
function watchMain() {

testdata/baselines/reference/submodule/compiler/APISample_WatchWithOwnWatchHost.js.diff

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
--- old.APISample_WatchWithOwnWatchHost.js
22
+++ new.APISample_WatchWithOwnWatchHost.js
3-
@@= skipped -64, +64 lines =@@
4-
5-
//// [APISample_WatchWithOwnWatchHost.js]
6-
"use strict";
7-
-/*
8-
- * Note: This test is a public API sample. This sample verifies creating abstract builder to watch list of root files
9-
- * Please log a "breaking change" issue for any API breaking change affecting this issue
10-
- */
3+
@@= skipped -69, +69 lines =@@
4+
* Please log a "breaking change" issue for any API breaking change affecting this issue
5+
*/
116
Object.defineProperty(exports, "__esModule", { value: true });
127
-var ts = require("typescript");
138
+const ts = require("typescript");

testdata/baselines/reference/submodule/compiler/APISample_compile.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ compile(process.argv.slice(2), {
4848

4949
//// [APISample_compile.js]
5050
"use strict";
51+
/*
52+
* Note: This test is a public API sample. The sample sources can be found
53+
* at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-minimal-compiler
54+
* Please log a "breaking change" issue for any API breaking change affecting this issue
55+
*/
5156
Object.defineProperty(exports, "__esModule", { value: true });
5257
exports.compile = compile;
5358
const ts = require("typescript");

0 commit comments

Comments
 (0)