Only preseve pinned comment at the top of file

This commit is contained in:
Yui T
2015-08-20 15:01:59 -07:00
parent 4b7e2b3139
commit 3f66968776
17 changed files with 361 additions and 2 deletions

View File

@@ -6923,11 +6923,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function filterComments(ranges: CommentRange[], isTopOfFileComments: boolean, isEmittedNode=true): CommentRange[] {
// TODO (yuisu): comment
if (compilerOptions.removeComments) {
ranges = filter(ranges, isPinnedComments);
ranges = isTopOfFileComments ? filter(ranges, isPinnedComments) : [];
}
else {
// TODO (yuisu): comment
if (!isEmittedNode) {
ranges = isTopOfFileComments ? filter(ranges, isTripleSlashOrPinnedComments) : filter(ranges, isPinnedComments);
}

View File

@@ -0,0 +1,14 @@
//// [doNotEmitPinnedCommentNotOnTopOfFile.ts]
var x = 10;
/*!
multi line
comment
*/
var x = 10;
//// [doNotEmitPinnedCommentNotOnTopOfFile.js]
var x = 10;
var x = 10;

View File

@@ -0,0 +1,13 @@
=== tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts ===
var x = 10;
>x : Symbol(x, Decl(doNotEmitPinnedCommentNotOnTopOfFile.ts, 0, 3), Decl(doNotEmitPinnedCommentNotOnTopOfFile.ts, 8, 3))
/*!
multi line
comment
*/
var x = 10;
>x : Symbol(x, Decl(doNotEmitPinnedCommentNotOnTopOfFile.ts, 0, 3), Decl(doNotEmitPinnedCommentNotOnTopOfFile.ts, 8, 3))

View File

@@ -0,0 +1,15 @@
=== tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts ===
var x = 10;
>x : number
>10 : number
/*!
multi line
comment
*/
var x = 10;
>x : number
>10 : number

View File

@@ -0,0 +1,21 @@
//// [doNotEmitPinnedCommentOnNotEmittedNode.ts]
class C {
/*! remove pinned comment anywhere else */
public foo(x: string, y: any)
public foo(x: string, y: number) { }
}
var x = 10;
/*! remove pinned comment anywhere else */
declare var OData: any;
//// [doNotEmitPinnedCommentOnNotEmittedNode.js]
var C = (function () {
function C() {
}
C.prototype.foo = function (x, y) { };
return C;
})();
var x = 10;

View File

@@ -0,0 +1,24 @@
=== tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts ===
class C {
>C : Symbol(C, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 0, 0))
/*! remove pinned comment anywhere else */
public foo(x: string, y: any)
>foo : Symbol(foo, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 1, 9), Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 3, 33))
>x : Symbol(x, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 3, 15))
>y : Symbol(y, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 3, 25))
public foo(x: string, y: number) { }
>foo : Symbol(foo, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 1, 9), Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 3, 33))
>x : Symbol(x, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 4, 15))
>y : Symbol(y, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 4, 25))
}
var x = 10;
>x : Symbol(x, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 7, 3))
/*! remove pinned comment anywhere else */
declare var OData: any;
>OData : Symbol(OData, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 10, 11))

View File

@@ -0,0 +1,25 @@
=== tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts ===
class C {
>C : C
/*! remove pinned comment anywhere else */
public foo(x: string, y: any)
>foo : (x: string, y: any) => any
>x : string
>y : any
public foo(x: string, y: number) { }
>foo : (x: string, y: any) => any
>x : string
>y : number
}
var x = 10;
>x : number
>10 : number
/*! remove pinned comment anywhere else */
declare var OData: any;
>OData : any

View File

@@ -0,0 +1,18 @@
//// [doNotEmitPinnedCommentOnNotEmittedNodets.ts]
class C {
/*! remove pinned comment anywhere else */
public foo(x: string, y: any)
public foo(x: string, y: number) { }
}
/*! remove pinned comment anywhere else */
declare var OData: any;
//// [doNotEmitPinnedCommentOnNotEmittedNodets.js]
var C = (function () {
function C() {
}
C.prototype.foo = function (x, y) { };
return C;
})();

View File

@@ -0,0 +1,21 @@
=== tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts ===
class C {
>C : Symbol(C, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 0, 0))
/*! remove pinned comment anywhere else */
public foo(x: string, y: any)
>foo : Symbol(foo, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 1, 9), Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 3, 33))
>x : Symbol(x, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 3, 15))
>y : Symbol(y, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 3, 25))
public foo(x: string, y: number) { }
>foo : Symbol(foo, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 1, 9), Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 3, 33))
>x : Symbol(x, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 4, 15))
>y : Symbol(y, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 4, 25))
}
/*! remove pinned comment anywhere else */
declare var OData: any;
>OData : Symbol(OData, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 8, 11))

View File

@@ -0,0 +1,21 @@
=== tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts ===
class C {
>C : C
/*! remove pinned comment anywhere else */
public foo(x: string, y: any)
>foo : (x: string, y: any) => any
>x : string
>y : any
public foo(x: string, y: number) { }
>foo : (x: string, y: any) => any
>x : string
>y : number
}
/*! remove pinned comment anywhere else */
declare var OData: any;
>OData : any

View File

@@ -0,0 +1,42 @@
//// [doNotEmitPinnedDetachedComments.ts]
var x = 10;
/*! Single Line comment */
function baz() { }
/*!
multi-line comment
*/
//========================
function bar() {
/*!
Remove this comment
*/
}
function foo() {
/*! Remove this */
return 0;
}
//========================
//// [doNotEmitPinnedDetachedComments.js]
var x = 10;
function baz() { }
function bar() {
}
function foo() {
return 0;
}

View File

@@ -0,0 +1,39 @@
=== tests/cases/compiler/doNotEmitPinnedDetachedComments.ts ===
var x = 10;
>x : Symbol(x, Decl(doNotEmitPinnedDetachedComments.ts, 0, 3))
/*! Single Line comment */
function baz() { }
>baz : Symbol(baz, Decl(doNotEmitPinnedDetachedComments.ts, 0, 11))
/*!
multi-line comment
*/
//========================
function bar() {
>bar : Symbol(bar, Decl(doNotEmitPinnedDetachedComments.ts, 4, 18))
/*!
Remove this comment
*/
}
function foo() {
>foo : Symbol(foo, Decl(doNotEmitPinnedDetachedComments.ts, 21, 1))
/*! Remove this */
return 0;
}
//========================

View File

@@ -0,0 +1,41 @@
=== tests/cases/compiler/doNotEmitPinnedDetachedComments.ts ===
var x = 10;
>x : number
>10 : number
/*! Single Line comment */
function baz() { }
>baz : () => void
/*!
multi-line comment
*/
//========================
function bar() {
>bar : () => void
/*!
Remove this comment
*/
}
function foo() {
>foo : () => number
/*! Remove this */
return 0;
>0 : number
}
//========================

View File

@@ -0,0 +1,10 @@
// @comments: false
var x = 10;
/*!
multi line
comment
*/
var x = 10;

View File

@@ -0,0 +1,13 @@
// @comments: false
class C {
/*! remove pinned comment anywhere else */
public foo(x: string, y: any)
public foo(x: string, y: number) { }
}
// @Filename: file1.ts
var x = 10;
/*! remove pinned comment anywhere else */
declare var OData: any;

View File

@@ -0,0 +1,10 @@
// @comments: false
class C {
/*! remove pinned comment anywhere else */
public foo(x: string, y: any)
public foo(x: string, y: number) { }
}
/*! remove pinned comment anywhere else */
declare var OData: any;

View File

@@ -0,0 +1,32 @@
// @comments: false
var x = 10;
/*! Single Line comment */
function baz() { }
/*!
multi-line comment
*/
//========================
function bar() {
/*!
Remove this comment
*/
}
function foo() {
/*! Remove this */
return 0;
}
//========================