diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4ab47346f16..b524f37d47e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -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); } diff --git a/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.js b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.js new file mode 100644 index 00000000000..8232ad66ef5 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.js @@ -0,0 +1,14 @@ +//// [doNotEmitPinnedCommentNotOnTopOfFile.ts] +var x = 10; + +/*! + + multi line + comment +*/ + +var x = 10; + +//// [doNotEmitPinnedCommentNotOnTopOfFile.js] +var x = 10; +var x = 10; diff --git a/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.symbols b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.symbols new file mode 100644 index 00000000000..97cfb5df214 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.symbols @@ -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)) + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.types b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.types new file mode 100644 index 00000000000..3426c70dfb9 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.types @@ -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 + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.js b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.js new file mode 100644 index 00000000000..99e50801d50 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.js @@ -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; diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.symbols b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.symbols new file mode 100644 index 00000000000..64609266044 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.symbols @@ -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)) + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.types b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.types new file mode 100644 index 00000000000..b0f71137c2d --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.types @@ -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 + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.js b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.js new file mode 100644 index 00000000000..66896350e6d --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.js @@ -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; +})(); diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.symbols b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.symbols new file mode 100644 index 00000000000..dcd27478115 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.symbols @@ -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)) + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.types b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.types new file mode 100644 index 00000000000..4369af63f53 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.types @@ -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 + diff --git a/tests/baselines/reference/doNotEmitPinnedDetachedComments.js b/tests/baselines/reference/doNotEmitPinnedDetachedComments.js new file mode 100644 index 00000000000..5f5a3b19aaa --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedDetachedComments.js @@ -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; +} diff --git a/tests/baselines/reference/doNotEmitPinnedDetachedComments.symbols b/tests/baselines/reference/doNotEmitPinnedDetachedComments.symbols new file mode 100644 index 00000000000..2be35804b38 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedDetachedComments.symbols @@ -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; +} + + +//======================== + diff --git a/tests/baselines/reference/doNotEmitPinnedDetachedComments.types b/tests/baselines/reference/doNotEmitPinnedDetachedComments.types new file mode 100644 index 00000000000..d9e78e2f980 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedDetachedComments.types @@ -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 +} + + +//======================== + diff --git a/tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts b/tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts new file mode 100644 index 00000000000..0fbb1fddd81 --- /dev/null +++ b/tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts @@ -0,0 +1,10 @@ +// @comments: false +var x = 10; + +/*! + + multi line + comment +*/ + +var x = 10; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts b/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts new file mode 100644 index 00000000000..48e02a372f7 --- /dev/null +++ b/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts @@ -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; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts b/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts new file mode 100644 index 00000000000..a59e13df55c --- /dev/null +++ b/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts @@ -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; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitPinnedDetachedComments.ts b/tests/cases/compiler/doNotEmitPinnedDetachedComments.ts new file mode 100644 index 00000000000..534963cf4b7 --- /dev/null +++ b/tests/cases/compiler/doNotEmitPinnedDetachedComments.ts @@ -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; +} + + +//========================