Skip to content

Cleanup emit code for comments. #1777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 99 additions & 73 deletions src/compiler/emitter.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/baselines/reference/arrowFunctionContexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ var __extends = this.__extends || function (d, b) {
__.prototype = b.prototype;
d.prototype = new __();
};
// Arrow function used in with statement
with (window) {
var p = function () { return this; };
}
Expand Down Expand Up @@ -142,6 +143,7 @@ var M;
// Repeat above for module members that are functions? (necessary to redo all of them?)
var M2;
(function (M2) {
// Arrow function used in with statement
with (window) {
var p = function () { return this; };
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/augmentedTypesEnum2.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var e2;
(function (e2) {
e2[e2["One"] = 0] = "One";
})(e2 || (e2 = {}));
;
; // error
var e2 = (function () {
function e2() {
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/augmentedTypesInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ var i3;
(function (i3) {
i3[i3["One"] = 0] = "One";
})(i3 || (i3 = {}));
;
; // error
//import i4 = require(''); // error
6 changes: 3 additions & 3 deletions tests/baselines/reference/augmentedTypesModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,21 @@ var m1d;
var m1d = 1; // error
function m2() {
}
;
; // ok since the module is not instantiated
var m2a;
(function (m2a) {
var y = 2;
})(m2a || (m2a = {}));
function m2a() {
}
;
; // error since the module is instantiated
var m2b;
(function (m2b) {
m2b.y = 2;
})(m2b || (m2b = {}));
function m2b() {
}
;
; // error since the module is instantiated
// should be errors to have function first
function m2c() {
}
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/augmentedTypesModules2.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ module m2g { export class C { foo() { } } }
//// [augmentedTypesModules2.js]
function m2() {
}
;
; // ok since the module is not instantiated
var m2a;
(function (m2a) {
var y = 2;
})(m2a || (m2a = {}));
function m2a() {
}
;
; // error since the module is instantiated
var m2b;
(function (m2b) {
m2b.y = 2;
})(m2b || (m2b = {}));
function m2b() {
}
;
; // error since the module is instantiated
function m2c() {
}
;
Expand All @@ -59,7 +59,7 @@ var m2cc;
})(m2cc || (m2cc = {}));
function m2cc() {
}
;
; // error to have module first
function m2f() {
}
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function foo1<T1, T2>()


//// [commaOperatorOtherValidOperation.js]
//Comma operator in for loop
for (var i = 0, j = 10; i < j; i++, j--) {
}
//Comma operator in fuction arguments and return
Expand Down
6 changes: 5 additions & 1 deletion tests/baselines/reference/commentsOnObjectLiteral1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ var Person = makeClass(
);

//// [commentsOnObjectLiteral1.js]
var Person = makeClass({});
var Person = makeClass(
/**
@scope Person
*/
{});
4 changes: 3 additions & 1 deletion tests/baselines/reference/commentsVarDecl.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ var n = 30;
/** var deckaration with comment on type as well*/
var y = 20;
/// var deckaration with comment on type as well
var yy = 20;
var yy =
/// value comment
20;
/** comment2 */
var z = function (x, y) { return x + y; };
var z2;
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/constDeclarations-scopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ while (false) {
label2: label3: label4: const c = 0;
n = c;
}
// Try/catch/finally
try {
const c = 0;
n = c;
Expand All @@ -201,12 +202,14 @@ finally {
const c = 0;
n = c;
}
// Switch
switch (0) {
case 0:
const c = 0;
n = c;
break;
}
// blocks
{
const c = 0;
n = c;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/constDeclarations-scopes2.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ for (const c = 0; c < 10; n = c ) {
const c = "string";
var n;
var b;
// for scope
for (const c = 0; c < 10; n = c) {
// for block
const c = false;
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/constDeclarations-validContexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ if (true) {
while (false) {
label2: label3: label4: const c9 = 0;
}
// Try/catch/finally
try {
const c10 = 0;
}
Expand All @@ -162,6 +163,7 @@ catch (e) {
finally {
const c12 = 0;
}
// Switch
switch (0) {
case 0:
const c13 = 0;
Expand All @@ -170,6 +172,7 @@ switch (0) {
const c14 = 0;
break;
}
// blocks
{
const c15 = 0;
{
Expand Down
9 changes: 5 additions & 4 deletions tests/baselines/reference/escapedIdentifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,20 @@ constructorTestObject.arg\u0031 = 1;
constructorTestObject.arg2 = 'string';
constructorTestObject.arg\u0033 = true;
constructorTestObject.arg4 = 2;
// Lables
l\u0061bel1: while (false) {
while (false)
continue label1;
continue label1; // it will go to next iteration of outer loop
}
label2: while (false) {
while (false)
continue l\u0061bel2;
continue l\u0061bel2; // it will go to next iteration of outer loop
}
label3: while (false) {
while (false)
continue label3;
continue label3; // it will go to next iteration of outer loop
}
l\u0061bel4: while (false) {
while (false)
continue l\u0061bel4;
continue l\u0061bel4; // it will go to next iteration of outer loop
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ var M;
}
M.F2 = F2;
})(M || (M = {}));
// all of these are errors
for (var a;;) {
}
for (var a = 1;;) {
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/genericChainedCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var s3 = s2.func(num => num.toString())


//// [genericChainedCalls.js]
var r1 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }).func(function (num) { return num.toString(); });
var r1 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }) // error, number doesn't have a length
.func(function (num) { return num.toString(); });
var s1 = v1.func(function (num) { return num.toString(); });
var s2 = s1.func(function (str) { return str.length; }); // should also error
var s3 = s2.func(function (num) { return num.toString(); });
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ function foo(x) {
;
function bar(x, y) {
}
;
; // error at "y"; no error at "x"
function func2(a, b, c) {
}
;
; // error at "a,b,c"
function func3() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
}
;
; // error at "args"
function func4(z, w) {
if (z === void 0) { z = null; }
if (w === void 0) { w = undefined; }
}
;
; // error at "z,w"
// these shouldn't be errors
function noError1(x, y) {
if (x === void 0) { x = 3; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var x1: any; var y1 = new x1;
var x; // error at "x"
function func(k) {
}
;
; //error at "k"
func(x);
// this shouldn't be an error
var bar = 3;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/implicitAnyInCatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class C {


//// [implicitAnyInCatch.js]
// this should not be an error
try {
}
catch (error) {
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/letDeclarations-scopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ for (let l = 0; n = l; l++) {
}
for (let l in {}) {
}
// Try/catch/finally
try {
let l = 0;
n = l;
Expand All @@ -217,12 +218,14 @@ finally {
let l = 0;
n = l;
}
// Switch
switch (0) {
case 0:
let l = 0;
n = l;
break;
}
// blocks
{
let l = 0;
n = l;
Expand Down
4 changes: 4 additions & 0 deletions tests/baselines/reference/letDeclarations-validContexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ if (true) {
while (false) {
label2: label3: label4: let l9 = 0;
}
// Try/catch/finally
try {
let l10 = 0;
}
Expand All @@ -182,6 +183,7 @@ catch (e) {
finally {
let l12 = 0;
}
// Switch
switch (0) {
case 0:
let l13 = 0;
Expand All @@ -190,6 +192,7 @@ switch (0) {
let l14 = 0;
break;
}
// blocks
{
let l15 = 0;
{
Expand Down Expand Up @@ -247,6 +250,7 @@ var o = {
let l29 = 0;
}
};
// labels
label: let l30 = 0;
{
label2: let l31 = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ var r2: I1<number> = v1.func(num => num.toString()) // Correctly returns an I1<s

//// [overEagerReturnTypeSpecialization.js]
//Note: Below simpler repro
var r1 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }); // should error
var r2 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }); // should be ok
var r1 = v1.func(function (num) { return num.toString(); }) // Correctly returns an I1<string>
.func(function (str) { return str.length; }); // should error
var r2 = v1.func(function (num) { return num.toString(); }) // Correctly returns an I1<string>
.func(function (str) { return str.length; }); // should be ok
7 changes: 7 additions & 0 deletions tests/baselines/reference/parserSbp_7.9_A9_T3.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ do {
//// [parserSbp_7.9_A9_T3.js]
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* Check Do-While Statement for automatic semicolon insertion
*
* @path bestPractice/Sbp_7.9_A9_T3.js
* @description Execute do { \n ; \n }while(false) true
*/
//CHECK#1
do {
;
} while (false);
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/promiseChaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var Chain = (function () {
Chain.prototype.then = function (cb) {
var result = cb(this.value);
// should get a fresh type parameter which each then call
var z = this.then(function (x) { return result; }).then(function (x) { return "abc"; }).then(function (x) { return x.length; }); // No error
var z = this.then(function (x) { return result; }) /*S*/.then(function (x) { return "abc"; }) /*string*/.then(function (x) { return x.length; }); // No error
return new Chain(result);
};
return Chain;
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/promiseChaining1.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var Chain2 = (function () {
Chain2.prototype.then = function (cb) {
var result = cb(this.value);
// should get a fresh type parameter which each then call
var z = this.then(function (x) { return result; }).then(function (x) { return "abc"; }).then(function (x) { return x.length; }); // Should error on "abc" because it is not a Function
var z = this.then(function (x) { return result; }) /*S*/.then(function (x) { return "abc"; }) /*Function*/.then(function (x) { return x.length; }); // Should error on "abc" because it is not a Function
return new Chain2(result);
};
return Chain2;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/recursiveInitializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ var f = (x: string) => f(x);
// number unless otherwise specified
var n1 = n1++;
var n2 = n2 + n2;
var n3 = n3 + n3;
var n3 /* any */ = n3 + n3;
// string unless otherwise specified
var s1 = s1 + '';
var s2 = s2 + s2;
var s2 /* any */ = s2 + s2;
var s3 = s3 + s3;
var s4 = '' + s4;
// boolean unless otherwise specified
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/scopingInCatchBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ catch (ex1) {
try {
}
catch (ex1) {
}
} // should not error
try {
}
catch (ex1) {
}
} // should not error
var x = ex1; // should error
Loading