Skip to content

Commit 7c663cf

Browse files
author
Anton Tolmachev
committed
1 parent cb0a5ea commit 7c663cf

37 files changed

+315
-206
lines changed

src/compiler/emitter.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
28452845
}
28462846
}
28472847

2848+
function emitEmptyBlockComments(node: Node) {
2849+
// special handling for empty blocks
2850+
let pos = node.pos;
2851+
2852+
// skipping leading comments
2853+
const comments = getLeadingCommentRanges(currentText, node.pos);
2854+
2855+
if (comments) {
2856+
pos = comments[comments.length - 1].end;
2857+
}
2858+
2859+
pos = currentText.indexOf("{", pos) + 1;
2860+
// emitting all comments after '{'
2861+
emitTrailingCommentsOfPosition(pos);
2862+
emitLeadingCommentsOfPosition(pos);
2863+
}
2864+
28482865
function emitBlock(node: Block) {
28492866
if (isSingleLineEmptyBlock(node)) {
28502867
emitToken(SyntaxKind.OpenBraceToken, node.pos);
@@ -2855,6 +2872,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
28552872

28562873
emitToken(SyntaxKind.OpenBraceToken, node.pos);
28572874
increaseIndent();
2875+
2876+
if (!!node.statements.length) {
2877+
const firstStatementNode = node.statements[0];
2878+
emitTrailingCommentsOfPosition(firstStatementNode.pos);
2879+
}
2880+
else {
2881+
emitEmptyBlockComments(node);
2882+
}
2883+
28582884
if (node.kind === SyntaxKind.ModuleBlock) {
28592885
Debug.assert(node.parent.kind === SyntaxKind.ModuleDeclaration);
28602886
emitCaptureThisForNodeIfNecessary(node.parent);
@@ -2863,6 +2889,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
28632889
if (node.kind === SyntaxKind.ModuleBlock) {
28642890
emitTempDeclarations(/*newLine*/ true);
28652891
}
2892+
2893+
if (!!node.statements.length) {
2894+
const lastStatementNode = node.statements[node.statements.length - 1];
2895+
emitLeadingCommentsOfPosition(lastStatementNode.end);
2896+
}
2897+
28662898
decreaseIndent();
28672899
writeLine();
28682900
emitToken(SyntaxKind.CloseBraceToken, node.statements.end);

tests/baselines/reference/amdImportAsPrimaryExpression.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ define(["require", "exports"], function (require, exports) {
2626
define(["require", "exports", "./foo_0"], function (require, exports, foo) {
2727
"use strict";
2828
if (foo.E1.A === 0) {
29+
// Should cause runtime import - interesting optimization possibility, as gets inlined to 0.
2930
}
3031
});

tests/baselines/reference/argsInScope.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var C = (function () {
1717
}
1818
C.prototype.P = function (ii, j, k) {
1919
for (var i = 0; i < arguments.length; i++) {
20+
// WScript.Echo("param: " + arguments[i]);
2021
}
2122
};
2223
return C;

tests/baselines/reference/augmentedTypesModules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ var m1b;
111111
var m1b = 1; // error
112112
var m1c = 1; // Should be allowed
113113
var m1d;
114-
(function (m1d) {
114+
(function (m1d) {// error
115115
var I = (function () {
116116
function I() {
117117
}

tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ var M;
7979
}());
8080
})(M || (M = {}));
8181
var M;
82-
(function (M) {
82+
(function (M) {// Shouldnt be _M
8383
var e = (function () {
8484
function e() {
8585
}
@@ -110,7 +110,7 @@ var M;
110110
}());
111111
})(M || (M = {}));
112112
var M;
113-
(function (M) {
113+
(function (M) {// Shouldnt be _M
114114
var e = (function () {
115115
function e() {
116116
}

tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var M;
7171
}());
7272
})(M || (M = {}));
7373
var M;
74-
(function (M) {
74+
(function (M) {// Shouldnt bn _M
7575
var f = (function () {
7676
function f() {
7777
}

tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var M;
7676
})(m3 || (m3 = {}));
7777
})(M || (M = {}));
7878
var M;
79-
(function (M) {
79+
(function (M) {// shouldnt be _M
8080
var m3;
8181
(function (m3) {
8282
var p = M.x;

tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var f = () => this;
88
//// [collisionThisExpressionAndModuleInGlobal.js]
99
var _this = this;
1010
var _this;
11-
(function (_this) {
11+
(function (_this) {//Error
1212
var c = (function () {
1313
function c() {
1414
}

tests/baselines/reference/commonJSImportAsPrimaryExpression.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ exports.C1 = C1;
2727
"use strict";
2828
var foo = require("./foo_0");
2929
if (foo.C1.s1) {
30+
// Should cause runtime import
3031
}

tests/baselines/reference/duplicateAnonymousInners1.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ var Foo;
4949
}
5050
return Helper;
5151
}());
52+
// Inner should not show up in intellisense
53+
// Outer should show up in intellisense
5254
})(Foo || (Foo = {}));

tests/baselines/reference/duplicateLocalVariable1.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ var TestRunner = (function () {
382382
exception = true;
383383
testResult = false;
384384
if (typeof testcase.errorMessageRegEx === "string") {
385-
if (testcase.errorMessageRegEx === "") {
385+
if (testcase.errorMessageRegEx === "") {// Any error is fine
386386
testResult = true;
387387
}
388388
else if (e.message) {
@@ -391,6 +391,7 @@ var TestRunner = (function () {
391391
}
392392
}
393393
if (testResult === false) {
394+
//console.log(e.message);
394395
}
395396
}
396397
if ((testcase.errorMessageRegEx !== undefined) && !exception) {

tests/baselines/reference/duplicateSymbolsExportMatching.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ define(["require", "exports"], function (require, exports) {
7676
var t;
7777
})(inst || (inst = {}));
7878
var inst;
79-
(function (inst) {
79+
(function (inst) {// one error
8080
var t;
8181
})(inst = M.inst || (M.inst = {}));
8282
})(M || (M = {}));
@@ -103,7 +103,7 @@ define(["require", "exports"], function (require, exports) {
103103
return C;
104104
}());
105105
var C;
106-
(function (C) {
106+
(function (C) {// Two visibility errors (one for the clodule symbol, and one for the merged container symbol)
107107
var t;
108108
})(C = M.C || (M.C = {}));
109109
})(M || (M = {}));

tests/baselines/reference/for.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,26 @@ for () { // error
3232
}
3333

3434
//// [for.js]
35-
for (var i = 0; i < 10; i++) {
35+
for (var i = 0; i < 10; i++) {// ok
3636
var x1 = i;
3737
}
38-
for (var j = 0; j < 10; j++) {
38+
for (var j = 0; j < 10; j++) {// ok
3939
var x2 = j;
4040
}
41-
for (var k = 0; k < 10;) {
41+
for (var k = 0; k < 10;) {// ok
4242
k++;
4343
}
44-
for (; i < 10;) {
44+
for (; i < 10;) {// ok
4545
i++;
4646
}
47-
for (; i > 1; i--) {
47+
for (; i > 1; i--) {// ok
4848
}
49-
for (var l = 0;; l++) {
49+
for (var l = 0;; l++) {// ok
5050
if (l > 10) {
5151
break;
5252
}
5353
}
54-
for (;;) {
54+
for (;;) {// ok
5555
}
56-
for (;;) {
56+
for (;;) {// error
5757
}

tests/baselines/reference/forIn.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ for (var l in arr) {
2323

2424
//// [forIn.js]
2525
var arr = null;
26-
for (var i in arr) {
26+
for (var i in arr) {// error
2727
var x1 = arr[i];
2828
var y1 = arr[i];
2929
}
30-
for (var j in arr) {
30+
for (var j in arr) {// ok
3131
var x2 = arr[j];
3232
var y2 = arr[j];
3333
}
3434
var arr2 = [];
35-
for (j in arr2) {
35+
for (j in arr2) {// ok
3636
var x3 = arr2[j];
3737
var y3 = arr2[j];
3838
}

tests/baselines/reference/invalidTryStatements2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function fn2() {
3232
function fn() {
3333
try {
3434
}
35-
catch () {
35+
catch () {// syntax error, missing '(x)'
3636
}
3737
try {
3838
}

tests/baselines/reference/jsFileCompilationLetBeingRenamed.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ function foo(a) {
99
//// [out.js]
1010
function foo(a) {
1111
for (var a_1 = 0; a_1 < 10; a_1++) {
12+
// do something
1213
}
1314
}

tests/baselines/reference/moduleDuplicateIdentifiers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var FooBar;
4949
FooBar.member1 = 2;
5050
})(FooBar = exports.FooBar || (exports.FooBar = {}));
5151
var FooBar;
52-
(function (FooBar) {
52+
(function (FooBar) {// Shouldn't error
5353
FooBar.member2 = 42;
5454
})(FooBar = exports.FooBar || (exports.FooBar = {}));
5555
var Kettle = (function () {

tests/baselines/reference/nameCollisions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var T;
5252
(function (T) {
5353
var x = 2;
5454
var x;
55-
(function (x) {
55+
(function (x) {// error
5656
var Bar = (function () {
5757
function Bar() {
5858
}

tests/baselines/reference/noCatchBlock.js

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

tests/baselines/reference/noCatchBlock.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/noCatchBlock.sourcemap.txt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ sourceFile:noCatchBlock.ts
1212
1 >
1313
2 >^^^^
1414
3 > ^
15+
4 > ^^^^^^->
1516
1 >
1617
>
1718
2 >try
@@ -20,34 +21,51 @@ sourceFile:noCatchBlock.ts
2021
2 >Emitted(1, 5) Source(2, 5) + SourceIndex(0)
2122
3 >Emitted(1, 6) Source(2, 6) + SourceIndex(0)
2223
---
24+
>>> // ...
25+
1->^^^^
26+
2 > ^^^^^^
27+
1->
28+
>
29+
2 > // ...
30+
1->Emitted(2, 5) Source(3, 2) + SourceIndex(0)
31+
2 >Emitted(2, 11) Source(3, 8) + SourceIndex(0)
32+
---
2333
>>>}
2434
1 >
2535
2 >^
2636
3 > ^^^^^^^^^->
2737
1 >
28-
> // ...
2938
>
3039
2 >}
31-
1 >Emitted(2, 1) Source(4, 1) + SourceIndex(0)
32-
2 >Emitted(2, 2) Source(4, 2) + SourceIndex(0)
40+
1 >Emitted(3, 1) Source(4, 1) + SourceIndex(0)
41+
2 >Emitted(3, 2) Source(4, 2) + SourceIndex(0)
3342
---
3443
>>>finally {
3544
1->^^^^^^^^
3645
2 > ^
46+
3 > ^^^^^^^^^^^^^^^^^^^^->
3747
1-> finally
3848
2 > {
39-
1->Emitted(3, 9) Source(4, 11) + SourceIndex(0)
40-
2 >Emitted(3, 10) Source(4, 12) + SourceIndex(0)
49+
1->Emitted(4, 9) Source(4, 11) + SourceIndex(0)
50+
2 >Emitted(4, 10) Source(4, 12) + SourceIndex(0)
51+
---
52+
>>> // N.B. No 'catch' block
53+
1->^^^^
54+
2 > ^^^^^^^^^^^^^^^^^^^^^^^^
55+
1->
56+
>
57+
2 > // N.B. No 'catch' block
58+
1->Emitted(5, 5) Source(5, 2) + SourceIndex(0)
59+
2 >Emitted(5, 29) Source(5, 26) + SourceIndex(0)
4160
---
4261
>>>}
4362
1 >
4463
2 >^
4564
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
4665
1 >
47-
> // N.B. No 'catch' block
4866
>
4967
2 >}
50-
1 >Emitted(4, 1) Source(6, 1) + SourceIndex(0)
51-
2 >Emitted(4, 2) Source(6, 2) + SourceIndex(0)
68+
1 >Emitted(6, 1) Source(6, 1) + SourceIndex(0)
69+
2 >Emitted(6, 2) Source(6, 2) + SourceIndex(0)
5270
---
5371
>>>//# sourceMappingURL=noCatchBlock.js.map

tests/baselines/reference/parserRealSource14.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ var TypeScript;
10111011
ctx.path.push(cur);
10121012
}
10131013
else {
1014+
//logger.log("TODO: Ignoring node because minChar, limChar not better than previous node in stack");
10141015
}
10151016
}
10161017
// The AST walker skips comments, but we might be in one, so check the pre/post comments for this node manually

tests/baselines/reference/parserRealSource7.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ var TypeScript;
13691369
fgSym.declAST = ast;
13701370
}
13711371
}
1372-
else {
1372+
else {// there exists a symbol with this name
13731373
if ((fgSym.kind() == SymbolKind.Type)) {
13741374
fgSym = context.checker.createFunctionSignature(funcDecl, containerSym, containerScope, fgSym, false).declAST.type.symbol;
13751375
}
@@ -1428,7 +1428,7 @@ var TypeScript;
14281428
funcDecl.accessorSymbol = context.checker.createAccessorSymbol(funcDecl, fgSym, containerSym.type, (funcDecl.isMethod() && isStatic), true, containerScope, containerSym);
14291429
}
14301430
funcDecl.type.symbol.declAST = ast;
1431-
if (funcDecl.isConstructor) {
1431+
if (funcDecl.isConstructor) {// REVIEW: Remove when classes completely replace oldclass
14321432
go = true;
14331433
}
14341434
;

tests/baselines/reference/privacyGloImport.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ var m1;
235235
//var m1_im4_private_v4_private = m1_im4_private.f1();
236236
m1.m1_im1_public = m1_M1_public;
237237
m1.m1_im2_public = m1_M2_private;
238+
//export import m1_im3_public = require("m1_M3_public");
239+
//export import m1_im4_public = require("m1_M4_private");
238240
})(m1 || (m1 = {}));
239241
var glo_M1_public;
240242
(function (glo_M1_public) {
@@ -256,5 +258,6 @@ var m2;
256258
var m4;
257259
(function (m4) {
258260
var a = 10;
261+
//import m2 = require("use_glo_M1_public");
259262
})(m4 || (m4 = {}));
260263
})(m2 || (m2 = {}));

0 commit comments

Comments
 (0)