From 6fd267c574057c42571c2ae798506db79f8079ed Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Jul 2015 18:15:30 -0700 Subject: [PATCH 01/37] Fix CRLF --- src/compiler/commandLineParser.ts | 2 +- src/compiler/program.ts | 4 ++-- src/compiler/scanner.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index ba7d8ca9ce3..4bcc37e0ecc 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -425,7 +425,7 @@ namespace ts { } else { let exclude = json["exclude"] instanceof Array ? map(json["exclude"], normalizeSlashes) : undefined; - let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude)); + let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude)); for (let i = 0; i < sysFiles.length; i++) { let name = sysFiles[i]; if (fileExtensionIs(name, ".d.ts")) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 5ce4846b43b..ca12f6de03d 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -341,7 +341,7 @@ namespace ts { }); } - function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] { + function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] { return runWithCancellationToken(() => { if (!isDeclarationFile(sourceFile)) { let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken); @@ -350,7 +350,7 @@ namespace ts { return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } }); - } + } function getOptionsDiagnostics(): Diagnostic[] { let allDiagnostics: Diagnostic[] = []; diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index d52f96c912b..a30e23f6170 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -629,9 +629,9 @@ namespace ts { ch >= CharacterCodes._0 && ch <= CharacterCodes._9 || ch === CharacterCodes.$ || ch === CharacterCodes._ || ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion); } - + /* @internal */ - // Creates a scanner over a (possibly unspecified) range of a piece of text. + // Creates a scanner over a (possibly unspecified) range of a piece of text. export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, languageVariant = LanguageVariant.Standard, From 24eea0349defa34c90590153860b2cf0906369aa Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 15 Jul 2015 11:49:00 -0700 Subject: [PATCH 02/37] Add tests --- ...mitTripleSlashCommentsEvenInAmbientDeclaration.ts | 8 ++++++++ tests/cases/compiler/doNotEmitTripleSlashComments.ts | 7 +++++++ ...tTripleSlashCommentsButPreserveDetachComments1.ts | 11 +++++++++++ ...tTripleSlashCommentsButPreserveDetachComments2.ts | 12 ++++++++++++ ...tTripleSlashCommentsButPreserveDetachComments3.ts | 10 ++++++++++ ...mitTripleSlashCommentsEvenInAmbientDeclaration.ts | 8 ++++++++ 6 files changed, 56 insertions(+) create mode 100644 doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts create mode 100644 tests/cases/compiler/doNotEmitTripleSlashComments.ts create mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments1.ts create mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments2.ts create mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments3.ts create mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts diff --git a/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts b/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts new file mode 100644 index 00000000000..3a89b600c66 --- /dev/null +++ b/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts @@ -0,0 +1,8 @@ +// @comments: false + +// @Filename: file0.ts + +// @Fileame: file1.ts + +/// +declare var OData: any; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashComments.ts b/tests/cases/compiler/doNotEmitTripleSlashComments.ts new file mode 100644 index 00000000000..11e7dee5796 --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashComments.ts @@ -0,0 +1,7 @@ +// @comments: false + +// @Filename: file0.ts + +// @Filename: file1.ts +/// +var OData: any; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments1.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments1.ts new file mode 100644 index 00000000000..f511e75085b --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments1.ts @@ -0,0 +1,11 @@ +// @comments: false + +// @Filename: file0.ts + +// @Filename: file1.ts + +// +// Copy Right comment +// + +/// diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments2.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments2.ts new file mode 100644 index 00000000000..424c7374717 --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments2.ts @@ -0,0 +1,12 @@ +// @comments: false + +// @Filename: file0.ts + +// @Filename: file1.ts + +// +// Copy Right comment +// + +/// +var x = 10; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments3.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments3.ts new file mode 100644 index 00000000000..95f1bb4cbbb --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments3.ts @@ -0,0 +1,10 @@ +// @comments: false + +// @Filename: file0.ts + +// @Filename: file1.ts + +// +// Copy Right comment +// +/// diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts new file mode 100644 index 00000000000..99f6a292342 --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts @@ -0,0 +1,8 @@ +// @comments: false + +// @Filename: file0.ts + +// @Filename: file1.ts + +/// +declare var OData: any; \ No newline at end of file From 87c1c6573c8489b0965155b611dc0323eef2bf1d Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 15 Jul 2015 11:49:27 -0700 Subject: [PATCH 03/37] Only remove triple-slash when compilerOptions.removecomments is true --- src/compiler/emitter.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fd0d4ad796e..ba781f4b060 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6891,12 +6891,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; } + // Omit /// comment if compilerOptions.removeComments is true. // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text // so that we don't end up computing comment string and doing match for all // comments - else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && + if (!compilerOptions.removeComments && (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && comment.pos + 2 < comment.end && currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash && - currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) { + currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx))) { return true; } } From 675aa0242f1c45b7f65b250f3287ee8469d97af5 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 15 Jul 2015 15:02:18 -0700 Subject: [PATCH 04/37] Add more tests and update baselines --- .../reference/doNotEmitTripleSlashComments.js | 17 ++++++++++++++++ .../doNotEmitTripleSlashComments.symbols | 13 ++++++++++++ .../doNotEmitTripleSlashComments.types | 13 ++++++++++++ ...SlashCommentsButPreserveDetachComments1.js | 19 ++++++++++++++++++ ...CommentsButPreserveDetachComments1.symbols | 12 +++++++++++ ...shCommentsButPreserveDetachComments1.types | 12 +++++++++++ ...SlashCommentsButPreserveDetachComments2.js | 20 +++++++++++++++++++ ...CommentsButPreserveDetachComments2.symbols | 14 +++++++++++++ ...shCommentsButPreserveDetachComments2.types | 15 ++++++++++++++ ...SlashCommentsButPreserveDetachComments3.js | 15 ++++++++++++++ ...CommentsButPreserveDetachComments3.symbols | 11 ++++++++++ ...shCommentsButPreserveDetachComments3.types | 11 ++++++++++ ...leSlashCommentsEvenInAmbientDeclaration.js | 12 +++++++++++ ...shCommentsEvenInAmbientDeclaration.symbols | 10 ++++++++++ ...lashCommentsEvenInAmbientDeclaration.types | 10 ++++++++++ ...tEmitTripleSlashCommentsEvenInEmptyFile.js | 15 ++++++++++++++ ...TripleSlashCommentsEvenInEmptyFile.symbols | 10 ++++++++++ ...itTripleSlashCommentsEvenInEmptyFile.types | 10 ++++++++++ .../compiler/doNotEmitTripleSlashComments.ts | 4 ++++ ...tEmitTripleSlashCommentsEvenInEmptyFile.ts | 10 ++++++++++ 20 files changed, 253 insertions(+) create mode 100644 tests/baselines/reference/doNotEmitTripleSlashComments.js create mode 100644 tests/baselines/reference/doNotEmitTripleSlashComments.symbols create mode 100644 tests/baselines/reference/doNotEmitTripleSlashComments.types create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.js create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.symbols create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.types create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.js create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.symbols create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.types create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.js create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.symbols create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.types create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.js create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.symbols create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.types create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.js create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.symbols create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.types create mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInEmptyFile.ts diff --git a/tests/baselines/reference/doNotEmitTripleSlashComments.js b/tests/baselines/reference/doNotEmitTripleSlashComments.js new file mode 100644 index 00000000000..42d48f62b23 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashComments.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashComments.ts] //// + +//// [file0.ts] + + +//// [file2.ts] + +//// [file1.ts] +/// +/// +/// +var OData: any; + +//// [file0.js] +//// [file2.js] +//// [file1.js] +var OData; diff --git a/tests/baselines/reference/doNotEmitTripleSlashComments.symbols b/tests/baselines/reference/doNotEmitTripleSlashComments.symbols new file mode 100644 index 00000000000..7dfcc026914 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashComments.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/file1.ts === +/// +/// +/// +var OData: any; +>OData : Symbol(OData, Decl(file1.ts, 3, 3)) + +=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code.=== tests/cases/compiler/file2.ts === + +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashComments.types b/tests/baselines/reference/doNotEmitTripleSlashComments.types new file mode 100644 index 00000000000..51316501655 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashComments.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/file1.ts === +/// +/// +/// +var OData: any; +>OData : any + +=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code.=== tests/cases/compiler/file2.ts === + +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.js new file mode 100644 index 00000000000..1319052ee92 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments1.ts] //// + +//// [file0.ts] + + +//// [file1.ts] + +// +// Copy Right comment +// + +/// + + +//// [file0.js] +//// [file1.js] +// +// Copy Right comment +// diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.symbols new file mode 100644 index 00000000000..2928e218121 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/file1.ts === + +No type information for this code.// +No type information for this code.// Copy Right comment +No type information for this code.// +No type information for this code. +No type information for this code./// +No type information for this code. +No type information for this code.=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.types new file mode 100644 index 00000000000..2928e218121 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/file1.ts === + +No type information for this code.// +No type information for this code.// Copy Right comment +No type information for this code.// +No type information for this code. +No type information for this code./// +No type information for this code. +No type information for this code.=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.js new file mode 100644 index 00000000000..753abd0e3b0 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments2.ts] //// + +//// [file0.ts] + + +//// [file1.ts] + +// +// Copy Right comment +// + +/// +var x = 10; + +//// [file0.js] +//// [file1.js] +// +// Copy Right comment +// +var x = 10; diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.symbols new file mode 100644 index 00000000000..6df1bcf1b7c --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/file1.ts === + +// +// Copy Right comment +// + +/// +var x = 10; +>x : Symbol(x, Decl(file1.ts, 6, 3)) + +=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.types new file mode 100644 index 00000000000..0058d1a4028 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/file1.ts === + +// +// Copy Right comment +// + +/// +var x = 10; +>x : number +>10 : number + +=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.js new file mode 100644 index 00000000000..b1353fa92b2 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments3.ts] //// + +//// [file0.ts] + + +//// [file1.ts] + +// +// Copy Right comment +// +/// + + +//// [file0.js] +//// [file1.js] diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.symbols new file mode 100644 index 00000000000..b5f22abf23b --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/file1.ts === + +No type information for this code.// +No type information for this code.// Copy Right comment +No type information for this code.// +No type information for this code./// +No type information for this code. +No type information for this code.=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.types new file mode 100644 index 00000000000..b5f22abf23b --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/file1.ts === + +No type information for this code.// +No type information for this code.// Copy Right comment +No type information for this code.// +No type information for this code./// +No type information for this code. +No type information for this code.=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.js new file mode 100644 index 00000000000..bf69047bce0 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts] //// + +//// [file0.ts] + + +//// [file1.ts] + +/// +declare var OData: any; + +//// [file0.js] +//// [file1.js] diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.symbols new file mode 100644 index 00000000000..f3566dc7e33 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/file1.ts === + +/// +declare var OData: any; +>OData : Symbol(OData, Decl(file1.ts, 2, 11)) + +=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.types new file mode 100644 index 00000000000..37ae645a302 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/file1.ts === + +/// +declare var OData: any; +>OData : any + +=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.js new file mode 100644 index 00000000000..55dd71c6f09 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInEmptyFile.ts] //// + +//// [file0.ts] + + +//// [file2.ts] + +//// [file1.ts] +/// +/// +/// + +//// [file0.js] +//// [file2.js] +//// [file1.js] diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.symbols new file mode 100644 index 00000000000..7993a31b91e --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/file1.ts === +/// +No type information for this code./// +No type information for this code./// +No type information for this code.=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code.=== tests/cases/compiler/file2.ts === + +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.types new file mode 100644 index 00000000000..7993a31b91e --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/file1.ts === +/// +No type information for this code./// +No type information for this code./// +No type information for this code.=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code.=== tests/cases/compiler/file2.ts === + +No type information for this code. \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashComments.ts b/tests/cases/compiler/doNotEmitTripleSlashComments.ts index 11e7dee5796..e89586acfa0 100644 --- a/tests/cases/compiler/doNotEmitTripleSlashComments.ts +++ b/tests/cases/compiler/doNotEmitTripleSlashComments.ts @@ -2,6 +2,10 @@ // @Filename: file0.ts +// @Filename: file2.ts + // @Filename: file1.ts /// +/// +/// var OData: any; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInEmptyFile.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInEmptyFile.ts new file mode 100644 index 00000000000..41ca8dcab22 --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInEmptyFile.ts @@ -0,0 +1,10 @@ +// @comments: false + +// @Filename: file0.ts + +// @Filename: file2.ts + +// @Filename: file1.ts +/// +/// +/// \ No newline at end of file From d11fc480665ada08f13767c2d5e8939a570feb88 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 20 Jul 2015 09:55:04 -0700 Subject: [PATCH 05/37] Only remove triple-slash if it is not at top of file --- src/compiler/emitter.ts | 80 +++++++++++++++++++++++---------------- src/compiler/scanner.ts | 8 ++-- src/compiler/utilities.ts | 1 + 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ba781f4b060..16ad4e2e206 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6759,17 +6759,48 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return leadingComments; } - function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[] { - // If we're removing comments, then we want to strip out all but the pinned or - // triple slash comments. - if (ranges && onlyPinnedOrTripleSlashComments) { - ranges = filter(ranges, isPinnedOrTripleSlashComment); - if (ranges.length === 0) { - return undefined; - } - } + function filterComments(ranges: CommentRange[], removeComments: boolean, isTopOfFileComments: boolean): CommentRange[] { + // If removeComments flag is false, then do not filter out any comment + if (!removeComments || !ranges) return ranges; - return ranges; + // IF removeComments flag is true, then filter out comment by following: + // - Pinned comments : keep all + // - /// comments : keep it if the comments are at the top of the file otherwise remove + // - normal comments: remove all + if (removeComments) { + if (isTopOfFileComments) { + ranges = filter(ranges, isTripleSlashOrPinnedComments); + } + else { + ranges = filter(ranges, isPinnedComments); + } + return ranges.length === 0 ? undefined : ranges; + } + } + + function isPinnedComments(comment: CommentRange) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { + return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; + } + } + + /** + * Determine if the given comment is a triple-slash or pinned comment + * + * @return true if the comment is a triple-slash comment at the top of the file or a pinned comment else false + **/ + function isTripleSlashOrPinnedComments(comment: CommentRange) { + // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text + // so that we don't end up computing comment string and doing match for all // comments + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && + comment.pos + 2 < comment.end && + currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash) { + let textSubStr = currentSourceFile.text.substring(comment.pos, comment.end); + return textSubStr.match(fullTripleSlashReferencePathRegEx) || + textSubStr.match(fullTripleSlashAMDReferencePathRegEx) ? + true : false; + } + return isPinnedComments(comment); } function getLeadingCommentsToEmit(node: Node) { @@ -6798,27 +6829,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitOnlyPinnedOrTripleSlashComments(node: Node) { - emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ true); + emitLeadingCommentsWorker(node, /*removeComments:*/ true); } function emitLeadingComments(node: Node) { - return emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + return emitLeadingCommentsWorker(node, compilerOptions.removeComments); } - function emitLeadingCommentsWorker(node: Node, onlyPinnedOrTripleSlashComments: boolean) { + function emitLeadingCommentsWorker(node: Node, removeComments: boolean) { // If the caller only wants pinned or triple slash comments, then always filter // down to that set. Otherwise, filter based on the current compiler options. - let leadingComments = filterComments(getLeadingCommentsToEmit(node), onlyPinnedOrTripleSlashComments); + let leadingComments = filterComments(getLeadingCommentsToEmit(node), /*removeComments:*/ removeComments, /*isTopOfFileComments:*/ node.pos === 0); emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space - emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); + emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator:*/ true, newLine, writeComment); } function emitTrailingComments(node: Node) { // Emit the trailing comments only if the parent's end doesn't match - let trailingComments = filterComments(getTrailingCommentsToEmit(node), /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + let trailingComments = filterComments(getTrailingCommentsToEmit(node), /*removeComments*/ compilerOptions.removeComments, /*isTopOfFileComments:*/ node.pos === 0); // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); @@ -6835,7 +6866,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi leadingComments = getLeadingCommentRanges(currentSourceFile.text, pos); } - leadingComments = filterComments(leadingComments, compilerOptions.removeComments); + leadingComments = filterComments(leadingComments, /*removeComments:*/ compilerOptions.removeComments, pos === 0); emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space @@ -6886,21 +6917,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } } - - function isPinnedOrTripleSlashComment(comment: CommentRange) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; - } - // Omit /// comment if compilerOptions.removeComments is true. - // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text - // so that we don't end up computing comment string and doing match for all // comments - if (!compilerOptions.removeComments && (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && - comment.pos + 2 < comment.end && - currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash && - currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx))) { - return true; - } - } } function emitFile(jsFilePath: string, sourceFile?: SourceFile) { diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index a30e23f6170..69090f7bf7f 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -532,9 +532,11 @@ namespace ts { // false, whitespace is skipped until the first line break and comments between that location // and the next token are returned.If trailing is true, comments occurring between the given // position and the next line break are returned.The return value is an array containing a - // TextRange for each comment. Single-line comment ranges include the beginning '//' characters - // but not the ending line break. Multi - line comment ranges include the beginning '/* and - // ending '*/' characters.The return value is undefined if no comments were found. + // TextRange for each comment. + // + // Single - line comment ranges include the beginning '//' characters but not the ending line break. + // Multi - line comment ranges include the beginning '/* and ending '*/' characters. + // The return value is undefined if no comments were found. function getCommentRanges(text: string, pos: number, trailing: boolean): CommentRange[] { let result: CommentRange[]; let collecting = trailing || pos === 0; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 5174589cdcf..437b6ecaf81 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -409,6 +409,7 @@ namespace ts { } export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; + export let fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*/; export function isTypeNode(node: Node): boolean { if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) { From ed5bc319cbdab912fd388baaa331ccc0218d9930 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 20 Jul 2015 09:55:28 -0700 Subject: [PATCH 06/37] Update tests and baselines --- ...SlashCommentsButPreserveDetachComments1.js | 19 ------------------ ...CommentsButPreserveDetachComments1.symbols | 12 ----------- ...shCommentsButPreserveDetachComments1.types | 12 ----------- ...SlashCommentsButPreserveDetachComments2.js | 20 ------------------- ...CommentsButPreserveDetachComments2.symbols | 14 ------------- ...shCommentsButPreserveDetachComments2.types | 15 -------------- ...SlashCommentsButPreserveDetachComments3.js | 15 -------------- ...CommentsButPreserveDetachComments3.symbols | 11 ---------- ...shCommentsButPreserveDetachComments3.types | 11 ---------- ...leSlashCommentsEvenInAmbientDeclaration.js | 12 ----------- ...doNotEmitTripleSlashCommentsInTheMiddle.js | 16 +++++++++++++++ ...EmitTripleSlashCommentsInTheMiddle.symbols | 13 ++++++++++++ ...otEmitTripleSlashCommentsInTheMiddle.types | 15 ++++++++++++++ ...Comments.js => emitTripleSlashComments.js} | 5 ++++- ...ymbols => emitTripleSlashComments.symbols} | 0 ...ts.types => emitTripleSlashComments.types} | 0 ...leSlashCommentsEvenInAmbientDeclaration.js | 13 ++++++++++++ ...hCommentsEvenInAmbientDeclaration.symbols} | 0 ...ashCommentsEvenInAmbientDeclaration.types} | 0 ...emitTripleSlashCommentsEvenInEmptyFile.js} | 5 ++++- ...ripleSlashCommentsEvenInEmptyFile.symbols} | 0 ...tTripleSlashCommentsEvenInEmptyFile.types} | 0 ...SlashCommentsButPreserveDetachComments1.ts | 11 ---------- ...SlashCommentsButPreserveDetachComments2.ts | 12 ----------- ...SlashCommentsButPreserveDetachComments3.ts | 10 ---------- ...doNotEmitTripleSlashCommentsInTheMiddle.ts | 9 +++++++++ ...Comments.ts => emitTripleSlashComments.ts} | 0 ...eSlashCommentsEvenInAmbientDeclaration.ts} | 0 ...emitTripleSlashCommentsEvenInEmptyFile.ts} | 0 29 files changed, 74 insertions(+), 176 deletions(-) delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.js delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.symbols delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.types delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.js delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.symbols delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.types delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.js delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.symbols delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.types delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.js create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.symbols create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.types rename tests/baselines/reference/{doNotEmitTripleSlashComments.js => emitTripleSlashComments.js} (55%) rename tests/baselines/reference/{doNotEmitTripleSlashComments.symbols => emitTripleSlashComments.symbols} (100%) rename tests/baselines/reference/{doNotEmitTripleSlashComments.types => emitTripleSlashComments.types} (100%) create mode 100644 tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.js rename tests/baselines/reference/{doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.symbols => emitTripleSlashCommentsEvenInAmbientDeclaration.symbols} (100%) rename tests/baselines/reference/{doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.types => emitTripleSlashCommentsEvenInAmbientDeclaration.types} (100%) rename tests/baselines/reference/{doNotEmitTripleSlashCommentsEvenInEmptyFile.js => emitTripleSlashCommentsEvenInEmptyFile.js} (51%) rename tests/baselines/reference/{doNotEmitTripleSlashCommentsEvenInEmptyFile.symbols => emitTripleSlashCommentsEvenInEmptyFile.symbols} (100%) rename tests/baselines/reference/{doNotEmitTripleSlashCommentsEvenInEmptyFile.types => emitTripleSlashCommentsEvenInEmptyFile.types} (100%) delete mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments1.ts delete mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments2.ts delete mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments3.ts create mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle.ts rename tests/cases/compiler/{doNotEmitTripleSlashComments.ts => emitTripleSlashComments.ts} (100%) rename tests/cases/compiler/{doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts => emitTripleSlashCommentsEvenInAmbientDeclaration.ts} (100%) rename tests/cases/compiler/{doNotEmitTripleSlashCommentsEvenInEmptyFile.ts => emitTripleSlashCommentsEvenInEmptyFile.ts} (100%) diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.js deleted file mode 100644 index 1319052ee92..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.js +++ /dev/null @@ -1,19 +0,0 @@ -//// [tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments1.ts] //// - -//// [file0.ts] - - -//// [file1.ts] - -// -// Copy Right comment -// - -/// - - -//// [file0.js] -//// [file1.js] -// -// Copy Right comment -// diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.symbols deleted file mode 100644 index 2928e218121..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.symbols +++ /dev/null @@ -1,12 +0,0 @@ -=== tests/cases/compiler/file1.ts === - -No type information for this code.// -No type information for this code.// Copy Right comment -No type information for this code.// -No type information for this code. -No type information for this code./// -No type information for this code. -No type information for this code.=== tests/cases/compiler/file0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.types deleted file mode 100644 index 2928e218121..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments1.types +++ /dev/null @@ -1,12 +0,0 @@ -=== tests/cases/compiler/file1.ts === - -No type information for this code.// -No type information for this code.// Copy Right comment -No type information for this code.// -No type information for this code. -No type information for this code./// -No type information for this code. -No type information for this code.=== tests/cases/compiler/file0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.js deleted file mode 100644 index 753abd0e3b0..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.js +++ /dev/null @@ -1,20 +0,0 @@ -//// [tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments2.ts] //// - -//// [file0.ts] - - -//// [file1.ts] - -// -// Copy Right comment -// - -/// -var x = 10; - -//// [file0.js] -//// [file1.js] -// -// Copy Right comment -// -var x = 10; diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.symbols deleted file mode 100644 index 6df1bcf1b7c..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.symbols +++ /dev/null @@ -1,14 +0,0 @@ -=== tests/cases/compiler/file1.ts === - -// -// Copy Right comment -// - -/// -var x = 10; ->x : Symbol(x, Decl(file1.ts, 6, 3)) - -=== tests/cases/compiler/file0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.types deleted file mode 100644 index 0058d1a4028..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments2.types +++ /dev/null @@ -1,15 +0,0 @@ -=== tests/cases/compiler/file1.ts === - -// -// Copy Right comment -// - -/// -var x = 10; ->x : number ->10 : number - -=== tests/cases/compiler/file0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.js deleted file mode 100644 index b1353fa92b2..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.js +++ /dev/null @@ -1,15 +0,0 @@ -//// [tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments3.ts] //// - -//// [file0.ts] - - -//// [file1.ts] - -// -// Copy Right comment -// -/// - - -//// [file0.js] -//// [file1.js] diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.symbols deleted file mode 100644 index b5f22abf23b..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.symbols +++ /dev/null @@ -1,11 +0,0 @@ -=== tests/cases/compiler/file1.ts === - -No type information for this code.// -No type information for this code.// Copy Right comment -No type information for this code.// -No type information for this code./// -No type information for this code. -No type information for this code.=== tests/cases/compiler/file0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.types deleted file mode 100644 index b5f22abf23b..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsButPreserveDetachComments3.types +++ /dev/null @@ -1,11 +0,0 @@ -=== tests/cases/compiler/file1.ts === - -No type information for this code.// -No type information for this code.// Copy Right comment -No type information for this code.// -No type information for this code./// -No type information for this code. -No type information for this code.=== tests/cases/compiler/file0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.js deleted file mode 100644 index bf69047bce0..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.js +++ /dev/null @@ -1,12 +0,0 @@ -//// [tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts] //// - -//// [file0.ts] - - -//// [file1.ts] - -/// -declare var OData: any; - -//// [file0.js] -//// [file1.js] diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js new file mode 100644 index 00000000000..58a9e2caf66 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle.ts] //// + +//// [0.ts] + + +//// [1.ts] +/// +var x = 10; +/// +var y = 1000; + +//// [0.js] +//// [1.js] +/// +var x = 10; +var y = 1000; diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.symbols new file mode 100644 index 00000000000..353b90f3812 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/1.ts === +/// +var x = 10; +>x : Symbol(x, Decl(1.ts, 1, 3)) + +/// +var y = 1000; +>y : Symbol(y, Decl(1.ts, 3, 3)) + +=== tests/cases/compiler/0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.types new file mode 100644 index 00000000000..e26f99fa1a7 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/1.ts === +/// +var x = 10; +>x : number +>10 : number + +/// +var y = 1000; +>y : number +>1000 : number + +=== tests/cases/compiler/0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashComments.js b/tests/baselines/reference/emitTripleSlashComments.js similarity index 55% rename from tests/baselines/reference/doNotEmitTripleSlashComments.js rename to tests/baselines/reference/emitTripleSlashComments.js index 42d48f62b23..ac86bc880f1 100644 --- a/tests/baselines/reference/doNotEmitTripleSlashComments.js +++ b/tests/baselines/reference/emitTripleSlashComments.js @@ -1,4 +1,4 @@ -//// [tests/cases/compiler/doNotEmitTripleSlashComments.ts] //// +//// [tests/cases/compiler/emitTripleSlashComments.ts] //// //// [file0.ts] @@ -14,4 +14,7 @@ var OData: any; //// [file0.js] //// [file2.js] //// [file1.js] +/// +/// +/// var OData; diff --git a/tests/baselines/reference/doNotEmitTripleSlashComments.symbols b/tests/baselines/reference/emitTripleSlashComments.symbols similarity index 100% rename from tests/baselines/reference/doNotEmitTripleSlashComments.symbols rename to tests/baselines/reference/emitTripleSlashComments.symbols diff --git a/tests/baselines/reference/doNotEmitTripleSlashComments.types b/tests/baselines/reference/emitTripleSlashComments.types similarity index 100% rename from tests/baselines/reference/doNotEmitTripleSlashComments.types rename to tests/baselines/reference/emitTripleSlashComments.types diff --git a/tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.js b/tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.js new file mode 100644 index 00000000000..2cc952a8f3a --- /dev/null +++ b/tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/emitTripleSlashCommentsEvenInAmbientDeclaration.ts] //// + +//// [file0.ts] + + +//// [file1.ts] + +/// +declare var OData: any; + +//// [file0.js] +//// [file1.js] +/// diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.symbols b/tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.symbols similarity index 100% rename from tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.symbols rename to tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.symbols diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.types b/tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.types similarity index 100% rename from tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.types rename to tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.types diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.js b/tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.js similarity index 51% rename from tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.js rename to tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.js index 55dd71c6f09..6a827528bec 100644 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.js +++ b/tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.js @@ -1,4 +1,4 @@ -//// [tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInEmptyFile.ts] //// +//// [tests/cases/compiler/emitTripleSlashCommentsEvenInEmptyFile.ts] //// //// [file0.ts] @@ -13,3 +13,6 @@ //// [file0.js] //// [file2.js] //// [file1.js] +/// +/// +/// diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.symbols b/tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.symbols similarity index 100% rename from tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.symbols rename to tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.symbols diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.types b/tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.types similarity index 100% rename from tests/baselines/reference/doNotEmitTripleSlashCommentsEvenInEmptyFile.types rename to tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.types diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments1.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments1.ts deleted file mode 100644 index f511e75085b..00000000000 --- a/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments1.ts +++ /dev/null @@ -1,11 +0,0 @@ -// @comments: false - -// @Filename: file0.ts - -// @Filename: file1.ts - -// -// Copy Right comment -// - -/// diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments2.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments2.ts deleted file mode 100644 index 424c7374717..00000000000 --- a/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments2.ts +++ /dev/null @@ -1,12 +0,0 @@ -// @comments: false - -// @Filename: file0.ts - -// @Filename: file1.ts - -// -// Copy Right comment -// - -/// -var x = 10; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments3.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments3.ts deleted file mode 100644 index 95f1bb4cbbb..00000000000 --- a/tests/cases/compiler/doNotEmitTripleSlashCommentsButPreserveDetachComments3.ts +++ /dev/null @@ -1,10 +0,0 @@ -// @comments: false - -// @Filename: file0.ts - -// @Filename: file1.ts - -// -// Copy Right comment -// -/// diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle.ts new file mode 100644 index 00000000000..a0aeecd07f5 --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle.ts @@ -0,0 +1,9 @@ +// @comments: false + +// @Filename: 0.ts + +// @filename: 1.ts +/// +var x = 10; +/// +var y = 1000; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashComments.ts b/tests/cases/compiler/emitTripleSlashComments.ts similarity index 100% rename from tests/cases/compiler/doNotEmitTripleSlashComments.ts rename to tests/cases/compiler/emitTripleSlashComments.ts diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts b/tests/cases/compiler/emitTripleSlashCommentsEvenInAmbientDeclaration.ts similarity index 100% rename from tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts rename to tests/cases/compiler/emitTripleSlashCommentsEvenInAmbientDeclaration.ts diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInEmptyFile.ts b/tests/cases/compiler/emitTripleSlashCommentsEvenInEmptyFile.ts similarity index 100% rename from tests/cases/compiler/doNotEmitTripleSlashCommentsEvenInEmptyFile.ts rename to tests/cases/compiler/emitTripleSlashCommentsEvenInEmptyFile.ts From 880202d9828fefe49dd458a5cb67f341133dcf0a Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 21 Jul 2015 09:05:56 -0700 Subject: [PATCH 07/37] Clean up some code --- src/compiler/emitter.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 16ad4e2e206..2e2eaabd9cc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6763,17 +6763,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // If removeComments flag is false, then do not filter out any comment if (!removeComments || !ranges) return ranges; - // IF removeComments flag is true, then filter out comment by following: + // If removeComments flag is true, then filter out comment by following: // - Pinned comments : keep all // - /// comments : keep it if the comments are at the top of the file otherwise remove // - normal comments: remove all if (removeComments) { - if (isTopOfFileComments) { - ranges = filter(ranges, isTripleSlashOrPinnedComments); - } - else { - ranges = filter(ranges, isPinnedComments); - } + ranges = isTopOfFileComments ? filter(ranges, isTripleSlashOrPinnedComments) : filter(ranges, isPinnedComments); return ranges.length === 0 ? undefined : ranges; } } From deb6eeebe1dd29be1a3a4afcc0ef1fa83131b710 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 21 Jul 2015 09:06:17 -0700 Subject: [PATCH 08/37] Add tests --- .../doNotEmitTripleSlashCommentsInTheMiddle2.js | 14 ++++++++++++++ ...oNotEmitTripleSlashCommentsInTheMiddle2.symbols | 11 +++++++++++ .../doNotEmitTripleSlashCommentsInTheMiddle2.types | 11 +++++++++++ .../doNotEmitTripleSlashCommentsInTheMiddle2.ts | 9 +++++++++ 4 files changed, 45 insertions(+) create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.js create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.symbols create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.types create mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle2.ts diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.js new file mode 100644 index 00000000000..520a08983fe --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle2.ts] //// + +//// [file0.ts] + + +//// [file1.ts] + +/// +declare var OData: any; +/// + +//// [file0.js] +//// [file1.js] +/// diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.symbols new file mode 100644 index 00000000000..f3a41855553 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/file1.ts === + +/// +declare var OData: any; +>OData : Symbol(OData, Decl(file1.ts, 2, 11)) + +/// +=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.types new file mode 100644 index 00000000000..ec6f6e5a2cc --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/file1.ts === + +/// +declare var OData: any; +>OData : any + +/// +=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle2.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle2.ts new file mode 100644 index 00000000000..c06ab1abf76 --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle2.ts @@ -0,0 +1,9 @@ +// @comments: false + +// @Filename: file0.ts + +// @Filename: file1.ts + +/// +declare var OData: any; +/// \ No newline at end of file From 248d85720c80dde9dc6ddfe1a01f97d47ca99d04 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 19 Aug 2015 16:12:33 -0700 Subject: [PATCH 09/37] Update tests to remove /// if removeComment is true --- ...tEmitTripleSlashCommentsInAmbientDeclaration.js | 12 ++++++++++++ ...ripleSlashCommentsInAmbientDeclaration.symbols} | 0 ...tTripleSlashCommentsInAmbientDeclaration.types} | 0 ... => doNotEmitTripleSlashCommentsInEmptyFile.js} | 5 +---- ...oNotEmitTripleSlashCommentsInEmptyFile.symbols} | 0 ... doNotEmitTripleSlashCommentsInEmptyFile.types} | 0 .../doNotEmitTripleSlashCommentsInTheMiddle.js | 1 - .../doNotEmitTripleSlashCommentsInTheMiddle2.js | 14 -------------- ...oNotEmitTripleSlashCommentsInTheMiddle2.symbols | 11 ----------- .../doNotEmitTripleSlashCommentsInTheMiddle2.types | 11 ----------- ...Comments.js => doNotemitTripleSlashComments.js} | 5 +---- ...ymbols => doNotemitTripleSlashComments.symbols} | 0 ...ts.types => doNotemitTripleSlashComments.types} | 0 ...tTripleSlashCommentsEvenInAmbientDeclaration.js | 13 ------------- ...EmitTripleSlashCommentsInAmbientDeclaration.ts} | 0 ... => doNotEmitTripleSlashCommentsInEmptyFile.ts} | 0 .../doNotEmitTripleSlashCommentsInTheMiddle2.ts | 9 --------- ...Comments.ts => doNotemitTripleSlashComments.ts} | 0 18 files changed, 14 insertions(+), 67 deletions(-) create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js rename tests/baselines/reference/{emitTripleSlashCommentsEvenInAmbientDeclaration.symbols => doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols} (100%) rename tests/baselines/reference/{emitTripleSlashCommentsEvenInAmbientDeclaration.types => doNotEmitTripleSlashCommentsInAmbientDeclaration.types} (100%) rename tests/baselines/reference/{emitTripleSlashCommentsEvenInEmptyFile.js => doNotEmitTripleSlashCommentsInEmptyFile.js} (51%) rename tests/baselines/reference/{emitTripleSlashCommentsEvenInEmptyFile.symbols => doNotEmitTripleSlashCommentsInEmptyFile.symbols} (100%) rename tests/baselines/reference/{emitTripleSlashCommentsEvenInEmptyFile.types => doNotEmitTripleSlashCommentsInEmptyFile.types} (100%) delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.js delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.symbols delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.types rename tests/baselines/reference/{emitTripleSlashComments.js => doNotemitTripleSlashComments.js} (55%) rename tests/baselines/reference/{emitTripleSlashComments.symbols => doNotemitTripleSlashComments.symbols} (100%) rename tests/baselines/reference/{emitTripleSlashComments.types => doNotemitTripleSlashComments.types} (100%) delete mode 100644 tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.js rename tests/cases/compiler/{emitTripleSlashCommentsEvenInAmbientDeclaration.ts => doNotEmitTripleSlashCommentsInAmbientDeclaration.ts} (100%) rename tests/cases/compiler/{emitTripleSlashCommentsEvenInEmptyFile.ts => doNotEmitTripleSlashCommentsInEmptyFile.ts} (100%) delete mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle2.ts rename tests/cases/compiler/{emitTripleSlashComments.ts => doNotemitTripleSlashComments.ts} (100%) diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js new file mode 100644 index 00000000000..d3c461fe8c2 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts] //// + +//// [file0.ts] + + +//// [file1.ts] + +/// +declare var OData: any; + +//// [file0.js] +//// [file1.js] diff --git a/tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols similarity index 100% rename from tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.symbols rename to tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols diff --git a/tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.types similarity index 100% rename from tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.types rename to tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.types diff --git a/tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.js similarity index 51% rename from tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.js rename to tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.js index 6a827528bec..38f6980e5c7 100644 --- a/tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.js +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.js @@ -1,4 +1,4 @@ -//// [tests/cases/compiler/emitTripleSlashCommentsEvenInEmptyFile.ts] //// +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts] //// //// [file0.ts] @@ -13,6 +13,3 @@ //// [file0.js] //// [file2.js] //// [file1.js] -/// -/// -/// diff --git a/tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.symbols similarity index 100% rename from tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.symbols rename to tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.symbols diff --git a/tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.types similarity index 100% rename from tests/baselines/reference/emitTripleSlashCommentsEvenInEmptyFile.types rename to tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.types diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js index 58a9e2caf66..5a1c65a2b6b 100644 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js @@ -11,6 +11,5 @@ var y = 1000; //// [0.js] //// [1.js] -/// var x = 10; var y = 1000; diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.js deleted file mode 100644 index 520a08983fe..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.js +++ /dev/null @@ -1,14 +0,0 @@ -//// [tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle2.ts] //// - -//// [file0.ts] - - -//// [file1.ts] - -/// -declare var OData: any; -/// - -//// [file0.js] -//// [file1.js] -/// diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.symbols deleted file mode 100644 index f3a41855553..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.symbols +++ /dev/null @@ -1,11 +0,0 @@ -=== tests/cases/compiler/file1.ts === - -/// -declare var OData: any; ->OData : Symbol(OData, Decl(file1.ts, 2, 11)) - -/// -=== tests/cases/compiler/file0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.types deleted file mode 100644 index ec6f6e5a2cc..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle2.types +++ /dev/null @@ -1,11 +0,0 @@ -=== tests/cases/compiler/file1.ts === - -/// -declare var OData: any; ->OData : any - -/// -=== tests/cases/compiler/file0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/emitTripleSlashComments.js b/tests/baselines/reference/doNotemitTripleSlashComments.js similarity index 55% rename from tests/baselines/reference/emitTripleSlashComments.js rename to tests/baselines/reference/doNotemitTripleSlashComments.js index ac86bc880f1..a2ae1666498 100644 --- a/tests/baselines/reference/emitTripleSlashComments.js +++ b/tests/baselines/reference/doNotemitTripleSlashComments.js @@ -1,4 +1,4 @@ -//// [tests/cases/compiler/emitTripleSlashComments.ts] //// +//// [tests/cases/compiler/doNotemitTripleSlashComments.ts] //// //// [file0.ts] @@ -14,7 +14,4 @@ var OData: any; //// [file0.js] //// [file2.js] //// [file1.js] -/// -/// -/// var OData; diff --git a/tests/baselines/reference/emitTripleSlashComments.symbols b/tests/baselines/reference/doNotemitTripleSlashComments.symbols similarity index 100% rename from tests/baselines/reference/emitTripleSlashComments.symbols rename to tests/baselines/reference/doNotemitTripleSlashComments.symbols diff --git a/tests/baselines/reference/emitTripleSlashComments.types b/tests/baselines/reference/doNotemitTripleSlashComments.types similarity index 100% rename from tests/baselines/reference/emitTripleSlashComments.types rename to tests/baselines/reference/doNotemitTripleSlashComments.types diff --git a/tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.js b/tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.js deleted file mode 100644 index 2cc952a8f3a..00000000000 --- a/tests/baselines/reference/emitTripleSlashCommentsEvenInAmbientDeclaration.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [tests/cases/compiler/emitTripleSlashCommentsEvenInAmbientDeclaration.ts] //// - -//// [file0.ts] - - -//// [file1.ts] - -/// -declare var OData: any; - -//// [file0.js] -//// [file1.js] -/// diff --git a/tests/cases/compiler/emitTripleSlashCommentsEvenInAmbientDeclaration.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts similarity index 100% rename from tests/cases/compiler/emitTripleSlashCommentsEvenInAmbientDeclaration.ts rename to tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts diff --git a/tests/cases/compiler/emitTripleSlashCommentsEvenInEmptyFile.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts similarity index 100% rename from tests/cases/compiler/emitTripleSlashCommentsEvenInEmptyFile.ts rename to tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle2.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle2.ts deleted file mode 100644 index c06ab1abf76..00000000000 --- a/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle2.ts +++ /dev/null @@ -1,9 +0,0 @@ -// @comments: false - -// @Filename: file0.ts - -// @Filename: file1.ts - -/// -declare var OData: any; -/// \ No newline at end of file diff --git a/tests/cases/compiler/emitTripleSlashComments.ts b/tests/cases/compiler/doNotemitTripleSlashComments.ts similarity index 100% rename from tests/cases/compiler/emitTripleSlashComments.ts rename to tests/cases/compiler/doNotemitTripleSlashComments.ts From 5d15218cbe5458a766db8d7ed46b40470563a207 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 19 Aug 2015 16:19:17 -0700 Subject: [PATCH 10/37] Remove /// comment when removeComment is true --- src/compiler/emitter.ts | 69 +++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0d0e968e5b7..0363122f11f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3651,7 +3651,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitFunctionDeclaration(node: FunctionLikeDeclaration) { if (nodeIsMissing(node.body)) { - return emitOnlyPinnedOrTripleSlashComments(node); + return emitCommentsOnNotEmittedNode(node); } // TODO (yuisu) : we should not have special cases to condition emitting comments @@ -4123,7 +4123,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } else if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { - return emitOnlyPinnedOrTripleSlashComments(member); + return emitCommentsOnNotEmittedNode(member); } writeLine(); @@ -4192,7 +4192,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitMemberFunctionsForES6AndHigher(node: ClassLikeDeclaration) { for (let member of node.members) { if ((member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) && !(member).body) { - emitOnlyPinnedOrTripleSlashComments(member); + emitCommentsOnNotEmittedNode(member); } else if (member.kind === SyntaxKind.MethodDeclaration || member.kind === SyntaxKind.GetAccessor || @@ -4249,7 +4249,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // Emit the constructor overload pinned comments forEach(node.members, member => { if (member.kind === SyntaxKind.Constructor && !(member).body) { - emitOnlyPinnedOrTripleSlashComments(member); + emitCommentsOnNotEmittedNode(member); } // Check if there is any non-static property assignment if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer && (member.flags & NodeFlags.Static) === 0) { @@ -5151,7 +5151,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitInterfaceDeclaration(node: InterfaceDeclaration) { - emitOnlyPinnedOrTripleSlashComments(node); + emitCommentsOnNotEmittedNode(node); } function shouldEmitEnumDeclaration(node: EnumDeclaration) { @@ -5273,7 +5273,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let shouldEmit = shouldEmitModuleDeclaration(node); if (!shouldEmit) { - return emitOnlyPinnedOrTripleSlashComments(node); + return emitCommentsOnNotEmittedNode(node); } let hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node); let emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node); @@ -6675,7 +6675,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } if (node.flags & NodeFlags.Ambient) { - return emitOnlyPinnedOrTripleSlashComments(node); + return emitCommentsOnNotEmittedNode(node); } let emitComments = shouldEmitLeadingAndTrailingComments(node); @@ -6922,18 +6922,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return leadingComments; } - function filterComments(ranges: CommentRange[], removeComments: boolean, isTopOfFileComments: boolean): CommentRange[] { - // If removeComments flag is false, then do not filter out any comment - if (!removeComments || !ranges) return ranges; - - // If removeComments flag is true, then filter out comment by following: - // - Pinned comments : keep all - // - /// comments : keep it if the comments are at the top of the file otherwise remove - // - normal comments: remove all - if (removeComments) { - ranges = isTopOfFileComments ? filter(ranges, isTripleSlashOrPinnedComments) : filter(ranges, isPinnedComments); - return ranges.length === 0 ? undefined : ranges; + function filterComments(ranges: CommentRange[], isTopOfFileComments: boolean, isEmittedNode=true): CommentRange[] { + if (compilerOptions.removeComments) { + ranges = filter(ranges, isPinnedComments); } + else { + // TODO (yuisu): comment + if (!isEmittedNode) { + ranges = isTopOfFileComments ? filter(ranges, isTripleSlashOrPinnedComments) : filter(ranges, isPinnedComments); + } + } + + return ranges; } function isPinnedComments(comment: CommentRange) { @@ -6945,7 +6945,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi /** * Determine if the given comment is a triple-slash or pinned comment * - * @return true if the comment is a triple-slash comment at the top of the file or a pinned comment else false + * @return true if the comment is a triple-slash comment or a pinned comment else false **/ function isTripleSlashOrPinnedComments(comment: CommentRange) { // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text @@ -6986,18 +6986,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function emitOnlyPinnedOrTripleSlashComments(node: Node) { - emitLeadingCommentsWorker(node, /*removeComments:*/ true); + function emitCommentsOnNotEmittedNode(node: Node) { + /// TODO (yuisu): comments + emitLeadingCommentsWorker(node, /*isEmittedNode:*/ false); } function emitLeadingComments(node: Node) { - return emitLeadingCommentsWorker(node, compilerOptions.removeComments); + return emitLeadingCommentsWorker(node, /*isEmittedNode:*/ true); } - function emitLeadingCommentsWorker(node: Node, removeComments: boolean) { + function emitLeadingCommentsWorker(node: Node, isEmittedNode: boolean) { // If the caller only wants pinned or triple slash comments, then always filter // down to that set. Otherwise, filter based on the current compiler options. - let leadingComments = filterComments(getLeadingCommentsToEmit(node), /*removeComments:*/ removeComments, /*isTopOfFileComments:*/ node.pos === 0); + let leadingComments = filterComments(getLeadingCommentsToEmit(node), /*isTopOfFileComments:*/ node.pos === 0, isEmittedNode); emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); @@ -7007,7 +7008,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitTrailingComments(node: Node) { // Emit the trailing comments only if the parent's end doesn't match - let trailingComments = filterComments(getTrailingCommentsToEmit(node), /*removeComments*/ compilerOptions.removeComments, /*isTopOfFileComments:*/ node.pos === 0); + let trailingComments = filterComments(getTrailingCommentsToEmit(node), /*isTopOfFileComments:*/ node.pos === 0); // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); @@ -7019,7 +7020,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi * ^ => pos; the function will emit "comment1" in the emitJS */ function emitTrailingCommentsOfPosition(pos: number) { - let trailingComments = filterComments(getTrailingCommentRanges(currentSourceFile.text, pos), /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments, pos === 0); + let trailingComments = filterComments(getTrailingCommentRanges(currentSourceFile.text, pos), /*isTopOfFileComments*/ pos === 0); // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ true, newLine, writeComment); @@ -7036,7 +7037,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi leadingComments = getLeadingCommentRanges(currentSourceFile.text, pos); } - leadingComments = filterComments(leadingComments, /*removeComments:*/ compilerOptions.removeComments, pos === 0); + leadingComments = filterComments(leadingComments, /*isTopOfFileComments*/ pos === 0); emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space @@ -7094,20 +7095,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(shebang); } } - - function isPinnedOrTripleSlashComment(comment: CommentRange) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; - } - // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text - // so that we don't end up computing comment string and doing match for all // comments - else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && - comment.pos + 2 < comment.end && - currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash && - currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) { - return true; - } - } } function emitFile(jsFilePath: string, sourceFile?: SourceFile) { From 21ebc7132583bf306b5b3b27f0478dc6afa84289 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 20 Aug 2015 09:47:45 -0700 Subject: [PATCH 11/37] Don't emit detached comment if removeComment is true --- src/compiler/emitter.ts | 2 +- ...NotEmitdetachedCommentAtStartOfFunctionBody.js | 15 +++++++++++++++ ...itdetachedCommentAtStartOfFunctionBody.symbols | 12 ++++++++++++ ...EmitdetachedCommentAtStartOfFunctionBody.types | 13 +++++++++++++ ...NotEmitdetachedCommentAtStartOfFunctionBody.ts | 10 ++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.js create mode 100644 tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.symbols create mode 100644 tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.types create mode 100644 tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0363122f11f..4ab47346f16 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -7045,7 +7045,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitDetachedComments(node: TextRange) { - let leadingComments = getLeadingCommentRanges(currentSourceFile.text, node.pos); + let leadingComments = filterComments(getLeadingCommentRanges(currentSourceFile.text, node.pos), node.pos === 0); if (leadingComments) { let detachedComments: CommentRange[] = []; let lastComment: CommentRange; diff --git a/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.js b/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.js new file mode 100644 index 00000000000..7dd9c7ce679 --- /dev/null +++ b/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.js @@ -0,0 +1,15 @@ +//// [doNotEmitdetachedCommentAtStartOfFunctionBody.ts] +function foo() { + /* + + multi line + comment + */ + + return 42; +} + +//// [doNotEmitdetachedCommentAtStartOfFunctionBody.js] +function foo() { + return 42; +} diff --git a/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.symbols b/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.symbols new file mode 100644 index 00000000000..a6f8e1514b5 --- /dev/null +++ b/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts === +function foo() { +>foo : Symbol(foo, Decl(doNotEmitdetachedCommentAtStartOfFunctionBody.ts, 0, 0)) + + /* + + multi line + comment + */ + + return 42; +} diff --git a/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.types b/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.types new file mode 100644 index 00000000000..4271584ecbe --- /dev/null +++ b/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts === +function foo() { +>foo : () => number + + /* + + multi line + comment + */ + + return 42; +>42 : number +} diff --git a/tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts b/tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts new file mode 100644 index 00000000000..3d99de36d0a --- /dev/null +++ b/tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts @@ -0,0 +1,10 @@ +// @comments: false +function foo() { + /* + + multi line + comment + */ + + return 42; +} \ No newline at end of file From 4b7e2b31398781c3cf5676f1294f80ed1d643853 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 20 Aug 2015 11:31:51 -0700 Subject: [PATCH 12/37] Update tests file for /// and detached comments --- ...leSlashCommentsEvenInAmbientDeclaration.ts | 8 --- .../reference/doNotEmitDetachedComments.js | 33 ++++++++++ .../doNotEmitDetachedComments.symbols | 31 +++++++++ .../reference/doNotEmitDetachedComments.types | 32 ++++++++++ ...mitDetachedCommentsAtStartOfConstructor.js | 64 +++++++++++++++++++ ...tachedCommentsAtStartOfConstructor.symbols | 50 +++++++++++++++ ...DetachedCommentsAtStartOfConstructor.types | 54 ++++++++++++++++ ...itDetachedCommentsAtStartOfFunctionBody.js | 48 ++++++++++++++ ...achedCommentsAtStartOfFunctionBody.symbols | 42 ++++++++++++ ...etachedCommentsAtStartOfFunctionBody.types | 46 +++++++++++++ ...DetachedCommentsAtStartOfLambdaFunction.js | 45 +++++++++++++ ...hedCommentsAtStartOfLambdaFunction.symbols | 32 ++++++++++ ...achedCommentsAtStartOfLambdaFunction.types | 43 +++++++++++++ ...TripleSlashCommentsInAmbientDeclaration.js | 9 ++- ...eSlashCommentsInAmbientDeclaration.symbols | 8 +-- ...pleSlashCommentsInAmbientDeclaration.types | 7 +- ...doNotEmitTripleSlashCommentsInEmptyFile.js | 8 +-- ...EmitTripleSlashCommentsInEmptyFile.symbols | 6 +- ...otEmitTripleSlashCommentsInEmptyFile.types | 6 +- ...doNotEmitTripleSlashCommentsInTheMiddle.js | 15 ----- ...EmitTripleSlashCommentsInTheMiddle.symbols | 13 ---- ...otEmitTripleSlashCommentsInTheMiddle.types | 15 ----- ...mitdetachedCommentAtStartOfFunctionBody.js | 15 ----- ...tachedCommentAtStartOfFunctionBody.symbols | 12 ---- ...detachedCommentAtStartOfFunctionBody.types | 13 ---- .../reference/doNotemitTripleSlashComments.js | 43 +++++++++++-- .../doNotemitTripleSlashComments.symbols | 45 ++++++++++--- .../doNotemitTripleSlashComments.types | 48 +++++++++++--- .../emitPinnedCommentsOnTopOfFile.js | 16 +++++ .../emitPinnedCommentsOnTopOfFile.symbols | 10 +++ .../emitPinnedCommentsOnTopOfFile.types | 11 ++++ .../compiler/doNotEmitDetachedComments.ts | 27 ++++++++ ...mitDetachedCommentsAtStartOfConstructor.ts | 38 +++++++++++ ...itDetachedCommentsAtStartOfFunctionBody.ts | 33 ++++++++++ ...DetachedCommentsAtStartOfLambdaFunction.ts | 30 +++++++++ ...TripleSlashCommentsInAmbientDeclaration.ts | 7 ++ ...doNotEmitTripleSlashCommentsInEmptyFile.ts | 6 +- ...doNotEmitTripleSlashCommentsInTheMiddle.ts | 9 --- ...mitdetachedCommentAtStartOfFunctionBody.ts | 10 --- .../compiler/doNotemitTripleSlashComments.ts | 32 ++++++++-- .../compiler/emitPinnedCommentsOnTopOfFile.ts | 8 +++ 41 files changed, 866 insertions(+), 162 deletions(-) delete mode 100644 doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts create mode 100644 tests/baselines/reference/doNotEmitDetachedComments.js create mode 100644 tests/baselines/reference/doNotEmitDetachedComments.symbols create mode 100644 tests/baselines/reference/doNotEmitDetachedComments.types create mode 100644 tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.js create mode 100644 tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.symbols create mode 100644 tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.types create mode 100644 tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.js create mode 100644 tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.symbols create mode 100644 tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.types create mode 100644 tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.js create mode 100644 tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.symbols create mode 100644 tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.types delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.symbols delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.types delete mode 100644 tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.js delete mode 100644 tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.symbols delete mode 100644 tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.types create mode 100644 tests/baselines/reference/emitPinnedCommentsOnTopOfFile.js create mode 100644 tests/baselines/reference/emitPinnedCommentsOnTopOfFile.symbols create mode 100644 tests/baselines/reference/emitPinnedCommentsOnTopOfFile.types create mode 100644 tests/cases/compiler/doNotEmitDetachedComments.ts create mode 100644 tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts create mode 100644 tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts create mode 100644 tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts delete mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle.ts delete mode 100644 tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts create mode 100644 tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts diff --git a/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts b/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts deleted file mode 100644 index 3a89b600c66..00000000000 --- a/doNotEmitTripleSlashCommentsEvenInAmbientDeclaration.ts +++ /dev/null @@ -1,8 +0,0 @@ -// @comments: false - -// @Filename: file0.ts - -// @Fileame: file1.ts - -/// -declare var OData: any; \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitDetachedComments.js b/tests/baselines/reference/doNotEmitDetachedComments.js new file mode 100644 index 00000000000..74acb537fa8 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedComments.js @@ -0,0 +1,33 @@ +//// [doNotEmitDetachedComments.ts] +/* + + multi line + comment +*/ + +var x = 10; + +// Single Line comment + +function foo() { } + + +/* + multi-line comment + +*/ + + +//======================== + + +function bar() { } + + +//======================== + + +//// [doNotEmitDetachedComments.js] +var x = 10; +function foo() { } +function bar() { } diff --git a/tests/baselines/reference/doNotEmitDetachedComments.symbols b/tests/baselines/reference/doNotEmitDetachedComments.symbols new file mode 100644 index 00000000000..c718da7bb9a --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedComments.symbols @@ -0,0 +1,31 @@ +=== tests/cases/compiler/doNotEmitDetachedComments.ts === +/* + + multi line + comment +*/ + +var x = 10; +>x : Symbol(x, Decl(doNotEmitDetachedComments.ts, 6, 3)) + +// Single Line comment + +function foo() { } +>foo : Symbol(foo, Decl(doNotEmitDetachedComments.ts, 6, 11)) + + +/* + multi-line comment + +*/ + + +//======================== + + +function bar() { } +>bar : Symbol(bar, Decl(doNotEmitDetachedComments.ts, 10, 18)) + + +//======================== + diff --git a/tests/baselines/reference/doNotEmitDetachedComments.types b/tests/baselines/reference/doNotEmitDetachedComments.types new file mode 100644 index 00000000000..d9b5f0634c2 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedComments.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/doNotEmitDetachedComments.ts === +/* + + multi line + comment +*/ + +var x = 10; +>x : number +>10 : number + +// Single Line comment + +function foo() { } +>foo : () => void + + +/* + multi-line comment + +*/ + + +//======================== + + +function bar() { } +>bar : () => void + + +//======================== + diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.js b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.js new file mode 100644 index 00000000000..ba6dbf8b743 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.js @@ -0,0 +1,64 @@ +//// [doNotEmitDetachedCommentsAtStartOfConstructor.ts] +class A { + constructor() { + // Single Line Comment + + var x = 10; + } +} + +class B { + constructor() { + /* + Multi-line comment + */ + + var y = 10; + } +} + +class C { + constructor() { + // Single Line Comment with more than one blank line + + + var x = 10; + } +} + +class D { + constructor() { + /* + Multi-line comment with more than one blank line + */ + + + var y = 10; + } +} + +//// [doNotEmitDetachedCommentsAtStartOfConstructor.js] +var A = (function () { + function A() { + var x = 10; + } + return A; +})(); +var B = (function () { + function B() { + var y = 10; + } + return B; +})(); +var C = (function () { + function C() { + var x = 10; + } + return C; +})(); +var D = (function () { + function D() { + var y = 10; + } + return D; +})(); diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.symbols b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.symbols new file mode 100644 index 00000000000..d7c4f5b2ca9 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.symbols @@ -0,0 +1,50 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts === +class A { +>A : Symbol(A, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 0, 0)) + + constructor() { + // Single Line Comment + + var x = 10; +>x : Symbol(x, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 4, 11)) + } +} + +class B { +>B : Symbol(B, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 6, 1)) + + constructor() { + /* + Multi-line comment + */ + + var y = 10; +>y : Symbol(y, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 14, 11)) + } +} + +class C { +>C : Symbol(C, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 16, 1)) + + constructor() { + // Single Line Comment with more than one blank line + + + var x = 10; +>x : Symbol(x, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 23, 11)) + } +} + +class D { +>D : Symbol(D, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 25, 1)) + + constructor() { + /* + Multi-line comment with more than one blank line + */ + + + var y = 10; +>y : Symbol(y, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 34, 11)) + } +} diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.types b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.types new file mode 100644 index 00000000000..c316c6403c0 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.types @@ -0,0 +1,54 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts === +class A { +>A : A + + constructor() { + // Single Line Comment + + var x = 10; +>x : number +>10 : number + } +} + +class B { +>B : B + + constructor() { + /* + Multi-line comment + */ + + var y = 10; +>y : number +>10 : number + } +} + +class C { +>C : C + + constructor() { + // Single Line Comment with more than one blank line + + + var x = 10; +>x : number +>10 : number + } +} + +class D { +>D : D + + constructor() { + /* + Multi-line comment with more than one blank line + */ + + + var y = 10; +>y : number +>10 : number + } +} diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.js b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.js new file mode 100644 index 00000000000..dbd0f0be783 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.js @@ -0,0 +1,48 @@ +//// [doNotEmitDetachedCommentsAtStartOfFunctionBody.ts] +function foo1() { + // Single line comment + + return 42; +} + +function foo2() { + /* + + multi line + comment + */ + + return 42; +} + +function foo3() { + // Single line comment with more than one blank line + + + return 42; +} + +function foo4() { + /* + + multi line comment with more than one blank line + */ + + return 42; +} + + + +//// [doNotEmitDetachedCommentsAtStartOfFunctionBody.js] +function foo1() { + return 42; +} +function foo2() { + return 42; +} +function foo3() { + return 42; +} +function foo4() { + return 42; +} diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.symbols b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.symbols new file mode 100644 index 00000000000..c1680100369 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.symbols @@ -0,0 +1,42 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts === +function foo1() { +>foo1 : Symbol(foo1, Decl(doNotEmitDetachedCommentsAtStartOfFunctionBody.ts, 0, 0)) + + // Single line comment + + return 42; +} + +function foo2() { +>foo2 : Symbol(foo2, Decl(doNotEmitDetachedCommentsAtStartOfFunctionBody.ts, 4, 1)) + + /* + + multi line + comment + */ + + return 42; +} + +function foo3() { +>foo3 : Symbol(foo3, Decl(doNotEmitDetachedCommentsAtStartOfFunctionBody.ts, 14, 1)) + + // Single line comment with more than one blank line + + + return 42; +} + +function foo4() { +>foo4 : Symbol(foo4, Decl(doNotEmitDetachedCommentsAtStartOfFunctionBody.ts, 21, 1)) + + /* + + multi line comment with more than one blank line + */ + + return 42; +} + + diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.types b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.types new file mode 100644 index 00000000000..3b4814bbbb2 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.types @@ -0,0 +1,46 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts === +function foo1() { +>foo1 : () => number + + // Single line comment + + return 42; +>42 : number +} + +function foo2() { +>foo2 : () => number + + /* + + multi line + comment + */ + + return 42; +>42 : number +} + +function foo3() { +>foo3 : () => number + + // Single line comment with more than one blank line + + + return 42; +>42 : number +} + +function foo4() { +>foo4 : () => number + + /* + + multi line comment with more than one blank line + */ + + return 42; +>42 : number +} + + diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.js b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.js new file mode 100644 index 00000000000..7fd5c2b8f8e --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.js @@ -0,0 +1,45 @@ +//// [doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts] +() => { + // Single line comment + + return 0; +} + +() => { + /* + multi-line comment + */ + + return 0; +} + +() => { + // Single line comment with more than one blank line + + + return 0; +} + +() => { + /* + multi-line comment with more than one blank line + */ + + + return 0; +} + + +//// [doNotEmitDetachedCommentsAtStartOfLambdaFunction.js] +(function () { + return 0; +}); +(function () { + return 0; +}); +(function () { + return 0; +}); +(function () { + return 0; +}); diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.symbols b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.symbols new file mode 100644 index 00000000000..e57fc793920 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.symbols @@ -0,0 +1,32 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts === +() => { +No type information for this code. // Single line comment +No type information for this code. +No type information for this code. return 0; +No type information for this code.} +No type information for this code. +No type information for this code.() => { +No type information for this code. /* +No type information for this code. multi-line comment +No type information for this code. */ +No type information for this code. +No type information for this code. return 0; +No type information for this code.} +No type information for this code. +No type information for this code.() => { +No type information for this code. // Single line comment with more than one blank line +No type information for this code. +No type information for this code. +No type information for this code. return 0; +No type information for this code.} +No type information for this code. +No type information for this code.() => { +No type information for this code. /* +No type information for this code. multi-line comment with more than one blank line +No type information for this code. */ +No type information for this code. +No type information for this code. +No type information for this code. return 0; +No type information for this code.} +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.types b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.types new file mode 100644 index 00000000000..d90e93d84c5 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts === +() => { +>() => { // Single line comment return 0;} : () => number + + // Single line comment + + return 0; +>0 : number +} + +() => { +>() => { /* multi-line comment */ return 0;} : () => number + + /* + multi-line comment + */ + + return 0; +>0 : number +} + +() => { +>() => { // Single line comment with more than one blank line return 0;} : () => number + + // Single line comment with more than one blank line + + + return 0; +>0 : number +} + +() => { +>() => { /* multi-line comment with more than one blank line */ return 0;} : () => number + + /* + multi-line comment with more than one blank line + */ + + + return 0; +>0 : number +} + diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js index d3c461fe8c2..065c08afefb 100644 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js @@ -2,11 +2,18 @@ //// [file0.ts] +/// +class C { + /// + public foo(x: string, y: any) + public foo(x: string, y: number) { } +} //// [file1.ts] +var x = 10; /// declare var OData: any; -//// [file0.js] //// [file1.js] +var x = 10; diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols index f3566dc7e33..c41f7ed5822 100644 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols @@ -1,10 +1,8 @@ === tests/cases/compiler/file1.ts === +var x = 10; +>x : Symbol(x, Decl(file1.ts, 0, 3)) /// declare var OData: any; ->OData : Symbol(OData, Decl(file1.ts, 2, 11)) +>OData : Symbol(OData, Decl(file1.ts, 3, 11)) -=== tests/cases/compiler/file0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.types index 37ae645a302..f4bb0bbc964 100644 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.types +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.types @@ -1,10 +1,9 @@ === tests/cases/compiler/file1.ts === +var x = 10; +>x : number +>10 : number /// declare var OData: any; >OData : any -=== tests/cases/compiler/file0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.js index 38f6980e5c7..f3b0888a78f 100644 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.js +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.js @@ -3,13 +3,13 @@ //// [file0.ts] -//// [file2.ts] - //// [file1.ts] + +//// [file2.ts] /// -/// +/// /// //// [file0.js] -//// [file2.js] //// [file1.js] +//// [file2.js] diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.symbols index 7993a31b91e..d18810db280 100644 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.symbols +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.symbols @@ -1,10 +1,10 @@ -=== tests/cases/compiler/file1.ts === +=== tests/cases/compiler/file2.ts === /// -No type information for this code./// +No type information for this code./// No type information for this code./// No type information for this code.=== tests/cases/compiler/file0.ts === No type information for this code. -No type information for this code.=== tests/cases/compiler/file2.ts === +No type information for this code.=== tests/cases/compiler/file1.ts === No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.types index 7993a31b91e..d18810db280 100644 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.types +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.types @@ -1,10 +1,10 @@ -=== tests/cases/compiler/file1.ts === +=== tests/cases/compiler/file2.ts === /// -No type information for this code./// +No type information for this code./// No type information for this code./// No type information for this code.=== tests/cases/compiler/file0.ts === No type information for this code. -No type information for this code.=== tests/cases/compiler/file2.ts === +No type information for this code.=== tests/cases/compiler/file1.ts === No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js deleted file mode 100644 index 5a1c65a2b6b..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.js +++ /dev/null @@ -1,15 +0,0 @@ -//// [tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle.ts] //// - -//// [0.ts] - - -//// [1.ts] -/// -var x = 10; -/// -var y = 1000; - -//// [0.js] -//// [1.js] -var x = 10; -var y = 1000; diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.symbols deleted file mode 100644 index 353b90f3812..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.symbols +++ /dev/null @@ -1,13 +0,0 @@ -=== tests/cases/compiler/1.ts === -/// -var x = 10; ->x : Symbol(x, Decl(1.ts, 1, 3)) - -/// -var y = 1000; ->y : Symbol(y, Decl(1.ts, 3, 3)) - -=== tests/cases/compiler/0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.types deleted file mode 100644 index e26f99fa1a7..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInTheMiddle.types +++ /dev/null @@ -1,15 +0,0 @@ -=== tests/cases/compiler/1.ts === -/// -var x = 10; ->x : number ->10 : number - -/// -var y = 1000; ->y : number ->1000 : number - -=== tests/cases/compiler/0.ts === - -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.js b/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.js deleted file mode 100644 index 7dd9c7ce679..00000000000 --- a/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.js +++ /dev/null @@ -1,15 +0,0 @@ -//// [doNotEmitdetachedCommentAtStartOfFunctionBody.ts] -function foo() { - /* - - multi line - comment - */ - - return 42; -} - -//// [doNotEmitdetachedCommentAtStartOfFunctionBody.js] -function foo() { - return 42; -} diff --git a/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.symbols b/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.symbols deleted file mode 100644 index a6f8e1514b5..00000000000 --- a/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.symbols +++ /dev/null @@ -1,12 +0,0 @@ -=== tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts === -function foo() { ->foo : Symbol(foo, Decl(doNotEmitdetachedCommentAtStartOfFunctionBody.ts, 0, 0)) - - /* - - multi line - comment - */ - - return 42; -} diff --git a/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.types b/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.types deleted file mode 100644 index 4271584ecbe..00000000000 --- a/tests/baselines/reference/doNotEmitdetachedCommentAtStartOfFunctionBody.types +++ /dev/null @@ -1,13 +0,0 @@ -=== tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts === -function foo() { ->foo : () => number - - /* - - multi line - comment - */ - - return 42; ->42 : number -} diff --git a/tests/baselines/reference/doNotemitTripleSlashComments.js b/tests/baselines/reference/doNotemitTripleSlashComments.js index a2ae1666498..fe17db54cb1 100644 --- a/tests/baselines/reference/doNotemitTripleSlashComments.js +++ b/tests/baselines/reference/doNotemitTripleSlashComments.js @@ -2,16 +2,45 @@ //// [file0.ts] - -//// [file2.ts] +/// +/// +/// +var x = 10; + +/// +var y = "hello"; + + +/// //// [file1.ts] /// -/// -/// -var OData: any; + +function foo() { } + + +/// + + +var z = "world"; + +//// [file2.ts] +/// + + +/// ==================================== + + +function bar() { } + + + //// [file0.js] -//// [file2.js] +var x = 10; +var y = "hello"; //// [file1.js] -var OData; +function foo() { } +var z = "world"; +//// [file2.js] +function bar() { } diff --git a/tests/baselines/reference/doNotemitTripleSlashComments.symbols b/tests/baselines/reference/doNotemitTripleSlashComments.symbols index 7dfcc026914..36b31842f8b 100644 --- a/tests/baselines/reference/doNotemitTripleSlashComments.symbols +++ b/tests/baselines/reference/doNotemitTripleSlashComments.symbols @@ -1,13 +1,40 @@ -=== tests/cases/compiler/file1.ts === -/// -/// -/// -var OData: any; ->OData : Symbol(OData, Decl(file1.ts, 3, 3)) +=== tests/cases/compiler/file2.ts === +/// + + +/// ==================================== + + +function bar() { } +>bar : Symbol(bar, Decl(file2.ts, 0, 0)) + + === tests/cases/compiler/file0.ts === -No type information for this code. -No type information for this code.=== tests/cases/compiler/file2.ts === +/// +/// +/// +var x = 10; +>x : Symbol(x, Decl(file0.ts, 4, 3)) + +/// +var y = "hello"; +>y : Symbol(y, Decl(file0.ts, 7, 3)) + + +/// + +=== tests/cases/compiler/file1.ts === +/// + +function foo() { } +>foo : Symbol(foo, Decl(file1.ts, 0, 0)) + + +/// + + +var z = "world"; +>z : Symbol(z, Decl(file1.ts, 8, 3)) -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotemitTripleSlashComments.types b/tests/baselines/reference/doNotemitTripleSlashComments.types index 51316501655..edebe5687f6 100644 --- a/tests/baselines/reference/doNotemitTripleSlashComments.types +++ b/tests/baselines/reference/doNotemitTripleSlashComments.types @@ -1,13 +1,43 @@ -=== tests/cases/compiler/file1.ts === -/// -/// -/// -var OData: any; ->OData : any +=== tests/cases/compiler/file2.ts === +/// + + +/// ==================================== + + +function bar() { } +>bar : () => void + + === tests/cases/compiler/file0.ts === -No type information for this code. -No type information for this code.=== tests/cases/compiler/file2.ts === +/// +/// +/// +var x = 10; +>x : number +>10 : number + +/// +var y = "hello"; +>y : string +>"hello" : string + + +/// + +=== tests/cases/compiler/file1.ts === +/// + +function foo() { } +>foo : () => void + + +/// + + +var z = "world"; +>z : string +>"world" : string -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.js b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.js new file mode 100644 index 00000000000..a30fcbf045d --- /dev/null +++ b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.js @@ -0,0 +1,16 @@ +//// [emitPinnedCommentsOnTopOfFile.ts] +/*! + + multi line + comment +*/ + +var x = 10; + +//// [emitPinnedCommentsOnTopOfFile.js] +/*! + + multi line + comment +*/ +var x = 10; diff --git a/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.symbols b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.symbols new file mode 100644 index 00000000000..c9eb5905303 --- /dev/null +++ b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts === +/*! + + multi line + comment +*/ + +var x = 10; +>x : Symbol(x, Decl(emitPinnedCommentsOnTopOfFile.ts, 6, 3)) + diff --git a/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.types b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.types new file mode 100644 index 00000000000..0ada89e2802 --- /dev/null +++ b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts === +/*! + + multi line + comment +*/ + +var x = 10; +>x : number +>10 : number + diff --git a/tests/cases/compiler/doNotEmitDetachedComments.ts b/tests/cases/compiler/doNotEmitDetachedComments.ts new file mode 100644 index 00000000000..412dbeac19b --- /dev/null +++ b/tests/cases/compiler/doNotEmitDetachedComments.ts @@ -0,0 +1,27 @@ +// @comments: false +/* + + multi line + comment +*/ + +var x = 10; + +// Single Line comment + +function foo() { } + + +/* + multi-line comment + +*/ + + +//======================== + + +function bar() { } + + +//======================== diff --git a/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts new file mode 100644 index 00000000000..1ea96993a5e --- /dev/null +++ b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts @@ -0,0 +1,38 @@ +// @comments: false +class A { + constructor() { + // Single Line Comment + + var x = 10; + } +} + +class B { + constructor() { + /* + Multi-line comment + */ + + var y = 10; + } +} + +class C { + constructor() { + // Single Line Comment with more than one blank line + + + var x = 10; + } +} + +class D { + constructor() { + /* + Multi-line comment with more than one blank line + */ + + + var y = 10; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts new file mode 100644 index 00000000000..31adbc18de8 --- /dev/null +++ b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts @@ -0,0 +1,33 @@ +// @comments: false +function foo1() { + // Single line comment + + return 42; +} + +function foo2() { + /* + + multi line + comment + */ + + return 42; +} + +function foo3() { + // Single line comment with more than one blank line + + + return 42; +} + +function foo4() { + /* + + multi line comment with more than one blank line + */ + + return 42; +} + diff --git a/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts new file mode 100644 index 00000000000..c6a9cfc9e25 --- /dev/null +++ b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts @@ -0,0 +1,30 @@ +// @comments: false +() => { + // Single line comment + + return 0; +} + +() => { + /* + multi-line comment + */ + + return 0; +} + +() => { + // Single line comment with more than one blank line + + + return 0; +} + +() => { + /* + multi-line comment with more than one blank line + */ + + + return 0; +} diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts index 99f6a292342..7075c9e3b30 100644 --- a/tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts @@ -1,8 +1,15 @@ // @comments: false // @Filename: file0.ts +/// +class C { + /// + public foo(x: string, y: any) + public foo(x: string, y: number) { } +} // @Filename: file1.ts +var x = 10; /// declare var OData: any; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts index 41ca8dcab22..047510e2ec9 100644 --- a/tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts @@ -2,9 +2,9 @@ // @Filename: file0.ts -// @Filename: file2.ts - // @Filename: file1.ts + +// @Filename: file2.ts /// -/// +/// /// \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle.ts deleted file mode 100644 index a0aeecd07f5..00000000000 --- a/tests/cases/compiler/doNotEmitTripleSlashCommentsInTheMiddle.ts +++ /dev/null @@ -1,9 +0,0 @@ -// @comments: false - -// @Filename: 0.ts - -// @filename: 1.ts -/// -var x = 10; -/// -var y = 1000; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts b/tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts deleted file mode 100644 index 3d99de36d0a..00000000000 --- a/tests/cases/compiler/doNotEmitdetachedCommentAtStartOfFunctionBody.ts +++ /dev/null @@ -1,10 +0,0 @@ -// @comments: false -function foo() { - /* - - multi line - comment - */ - - return 42; -} \ No newline at end of file diff --git a/tests/cases/compiler/doNotemitTripleSlashComments.ts b/tests/cases/compiler/doNotemitTripleSlashComments.ts index e89586acfa0..f3b90662159 100644 --- a/tests/cases/compiler/doNotemitTripleSlashComments.ts +++ b/tests/cases/compiler/doNotemitTripleSlashComments.ts @@ -1,11 +1,35 @@ // @comments: false // @Filename: file0.ts +/// +/// +/// +var x = 10; -// @Filename: file2.ts +/// +var y = "hello"; + + +/// // @Filename: file1.ts /// -/// -/// -var OData: any; \ No newline at end of file + +function foo() { } + + +/// + + +var z = "world"; + +// @Filename: file2.ts +/// + + +/// ==================================== + + +function bar() { } + + diff --git a/tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts b/tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts new file mode 100644 index 00000000000..bbe6c400601 --- /dev/null +++ b/tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts @@ -0,0 +1,8 @@ +// @comments: false +/*! + + multi line + comment +*/ + +var x = 10; \ No newline at end of file From 3f66968776915aab765f769368ea254a2d159bd0 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 20 Aug 2015 15:01:59 -0700 Subject: [PATCH 13/37] Only preseve pinned comment at the top of file --- src/compiler/emitter.ts | 4 +- .../doNotEmitPinnedCommentNotOnTopOfFile.js | 14 +++++++ ...NotEmitPinnedCommentNotOnTopOfFile.symbols | 13 ++++++ ...doNotEmitPinnedCommentNotOnTopOfFile.types | 15 +++++++ .../doNotEmitPinnedCommentOnNotEmittedNode.js | 21 ++++++++++ ...tEmitPinnedCommentOnNotEmittedNode.symbols | 24 +++++++++++ ...NotEmitPinnedCommentOnNotEmittedNode.types | 25 +++++++++++ ...oNotEmitPinnedCommentOnNotEmittedNodets.js | 18 ++++++++ ...mitPinnedCommentOnNotEmittedNodets.symbols | 21 ++++++++++ ...tEmitPinnedCommentOnNotEmittedNodets.types | 21 ++++++++++ .../doNotEmitPinnedDetachedComments.js | 42 +++++++++++++++++++ .../doNotEmitPinnedDetachedComments.symbols | 39 +++++++++++++++++ .../doNotEmitPinnedDetachedComments.types | 41 ++++++++++++++++++ .../doNotEmitPinnedCommentNotOnTopOfFile.ts | 10 +++++ .../doNotEmitPinnedCommentOnNotEmittedNode.ts | 13 ++++++ ...oNotEmitPinnedCommentOnNotEmittedNodets.ts | 10 +++++ .../doNotEmitPinnedDetachedComments.ts | 32 ++++++++++++++ 17 files changed, 361 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.js create mode 100644 tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.symbols create mode 100644 tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.types create mode 100644 tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.js create mode 100644 tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.symbols create mode 100644 tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.types create mode 100644 tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.js create mode 100644 tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.symbols create mode 100644 tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.types create mode 100644 tests/baselines/reference/doNotEmitPinnedDetachedComments.js create mode 100644 tests/baselines/reference/doNotEmitPinnedDetachedComments.symbols create mode 100644 tests/baselines/reference/doNotEmitPinnedDetachedComments.types create mode 100644 tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts create mode 100644 tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts create mode 100644 tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts create mode 100644 tests/cases/compiler/doNotEmitPinnedDetachedComments.ts 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; +} + + +//======================== From 8eff741961d7ffff748cd4ac251da9c24e56c47c Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 20 Aug 2015 15:02:46 -0700 Subject: [PATCH 14/37] Add test in case of remove /// on node that will not be emitted when removeComment is true --- ...TripleSlashCommentsInAmbientDeclaration.js | 19 ------------------- ...eSlashCommentsInAmbientDeclaration.symbols | 8 -------- ...EmitTripleSlashCommentsOnNotEmittedNode.js | 15 +++++++++++++++ ...ripleSlashCommentsOnNotEmittedNode.symbols | 12 ++++++++++++ ...TripleSlashCommentsOnNotEmittedNode.types} | 11 +++++++---- ...TripleSlashCommentsInAmbientDeclaration.ts | 15 --------------- ...EmitTripleSlashCommentsOnNotEmittedNode.ts | 10 ++++++++++ 7 files changed, 44 insertions(+), 46 deletions(-) delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js delete mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.js create mode 100644 tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.symbols rename tests/baselines/reference/{doNotEmitTripleSlashCommentsInAmbientDeclaration.types => doNotEmitTripleSlashCommentsOnNotEmittedNode.types} (50%) delete mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts create mode 100644 tests/cases/compiler/doNotEmitTripleSlashCommentsOnNotEmittedNode.ts diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js deleted file mode 100644 index 065c08afefb..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.js +++ /dev/null @@ -1,19 +0,0 @@ -//// [tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts] //// - -//// [file0.ts] - -/// -class C { - /// - public foo(x: string, y: any) - public foo(x: string, y: number) { } -} - -//// [file1.ts] -var x = 10; - -/// -declare var OData: any; - -//// [file1.js] -var x = 10; diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols deleted file mode 100644 index c41f7ed5822..00000000000 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.symbols +++ /dev/null @@ -1,8 +0,0 @@ -=== tests/cases/compiler/file1.ts === -var x = 10; ->x : Symbol(x, Decl(file1.ts, 0, 3)) - -/// -declare var OData: any; ->OData : Symbol(OData, Decl(file1.ts, 3, 11)) - diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.js new file mode 100644 index 00000000000..9067b5b80a9 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsOnNotEmittedNode.ts] //// + +//// [file0.ts] + +/// +declare var OData: any; + +//// [file1.ts] +/// +interface F { } + + + +//// [file0.js] +//// [file1.js] diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.symbols new file mode 100644 index 00000000000..bb920d2ee1c --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/file1.ts === +/// +interface F { } +>F : Symbol(F, Decl(file1.ts, 0, 0)) + + +=== tests/cases/compiler/file0.ts === + +/// +declare var OData: any; +>OData : Symbol(OData, Decl(file0.ts, 2, 11)) + diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.types similarity index 50% rename from tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.types rename to tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.types index f4bb0bbc964..59b63ea1a2f 100644 --- a/tests/baselines/reference/doNotEmitTripleSlashCommentsInAmbientDeclaration.types +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.types @@ -1,9 +1,12 @@ === tests/cases/compiler/file1.ts === -var x = 10; ->x : number ->10 : number - /// +interface F { } +>F : F + + +=== tests/cases/compiler/file0.ts === + +/// declare var OData: any; >OData : any diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts deleted file mode 100644 index 7075c9e3b30..00000000000 --- a/tests/cases/compiler/doNotEmitTripleSlashCommentsInAmbientDeclaration.ts +++ /dev/null @@ -1,15 +0,0 @@ -// @comments: false - -// @Filename: file0.ts -/// -class C { - /// - public foo(x: string, y: any) - public foo(x: string, y: number) { } -} - -// @Filename: file1.ts -var x = 10; - -/// -declare var OData: any; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsOnNotEmittedNode.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsOnNotEmittedNode.ts new file mode 100644 index 00000000000..91941a6cf81 --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsOnNotEmittedNode.ts @@ -0,0 +1,10 @@ +// @comments: false + +// @Filename: file0.ts +/// +declare var OData: any; + +// @Filename: file1.ts +/// +interface F { } + From c851a60ed9447791e3f6fe4abf199ffb845c8639 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 20 Aug 2015 16:16:17 -0700 Subject: [PATCH 15/37] Add test to make sure /// is preserved when removeComments is false --- ...OnNotEmittedNodeIfRemoveCommentsIsFalse.js | 20 +++++++++++++++++++ ...EmittedNodeIfRemoveCommentsIsFalse.symbols | 16 +++++++++++++++ ...otEmittedNodeIfRemoveCommentsIsFalse.types | 17 ++++++++++++++++ ...OnNotEmittedNodeIfRemoveCommentsIsFalse.ts | 13 ++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.js create mode 100644 tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.symbols create mode 100644 tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.types create mode 100644 tests/cases/compiler/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.ts diff --git a/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.js b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.js new file mode 100644 index 00000000000..ff358518568 --- /dev/null +++ b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.ts] //// + +//// [file0.ts] + +var x = 10 + +//// [file1.ts] +/// +declare var OData: any; + +/// +interface F { } + + + + +//// [file0.js] +var x = 10; +//// [file1.js] +/// diff --git a/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.symbols b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.symbols new file mode 100644 index 00000000000..1c0e48e00f2 --- /dev/null +++ b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/file1.ts === +/// +declare var OData: any; +>OData : Symbol(OData, Decl(file1.ts, 1, 11)) + +/// +interface F { } +>F : Symbol(F, Decl(file1.ts, 1, 23)) + + + +=== tests/cases/compiler/file0.ts === + +var x = 10 +>x : Symbol(x, Decl(file0.ts, 1, 3)) + diff --git a/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.types b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.types new file mode 100644 index 00000000000..637196fdc22 --- /dev/null +++ b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/file1.ts === +/// +declare var OData: any; +>OData : any + +/// +interface F { } +>F : F + + + +=== tests/cases/compiler/file0.ts === + +var x = 10 +>x : number +>10 : number + diff --git a/tests/cases/compiler/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.ts b/tests/cases/compiler/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.ts new file mode 100644 index 00000000000..20c04702544 --- /dev/null +++ b/tests/cases/compiler/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.ts @@ -0,0 +1,13 @@ +// @comments: true + +// @Filename: file0.ts +var x = 10 + +// @Filename: file1.ts +/// +declare var OData: any; + +/// +interface F { } + + From eda9aead1149abc0c12fd33f5f9ab03e8b89d469 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 20 Aug 2015 16:21:58 -0700 Subject: [PATCH 16/37] Add comments --- src/compiler/emitter.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b524f37d47e..4b85f22e7ca 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6922,13 +6922,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return leadingComments; } + /** + * Filter comment when removeComments is true according to following rules: + * - Pinned Comments - remove all but the top of the file one + * - Normal Comments - remove all + * - // Comments - remove all + * @param isTopOfFileComments boolean indicating whether comments are at the top of file + * @param isEmittedNode boolean indicating whether node associated with the comments will be + * emitted in javascript file + */ function filterComments(ranges: CommentRange[], isTopOfFileComments: boolean, isEmittedNode=true): CommentRange[] { - // TODO (yuisu): comment if (compilerOptions.removeComments) { + // Only preserve pinned comments at the top of the file ranges = isTopOfFileComments ? filter(ranges, isPinnedComments) : []; } else { if (!isEmittedNode) { + // If the node will not be emitted in JS, remove all the comments(normal, pinned and ///) associated with the node, + // unless it is a triple slash comment at the top of the file. + // For Example: + // /// + // declare var x; + // /// + // interface F {} + // The first /// will NOT be removed while the second one will be removed eventhough both node will not be emitted ranges = isTopOfFileComments ? filter(ranges, isTripleSlashOrPinnedComments) : filter(ranges, isPinnedComments); } } From c88908e30097a757bfb2c7d7c73b678eb52a7d07 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 20 Aug 2015 16:29:55 -0700 Subject: [PATCH 17/37] Add comments --- src/compiler/emitter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4b85f22e7ca..d07373613ac 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -7003,8 +7003,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } + /** + * Emit comments associated with node that will not be emitted into JS file + */ function emitCommentsOnNotEmittedNode(node: Node) { - /// TODO (yuisu): comments emitLeadingCommentsWorker(node, /*isEmittedNode:*/ false); } From e36285c82c3a8458508a78df9fc4d0279a1df6d3 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 25 Aug 2015 13:47:02 -0700 Subject: [PATCH 18/37] Optimize removing comment when removeComment flag is true --- src/compiler/emitter.ts | 83 ++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d07373613ac..9a5e0b9f700 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6922,37 +6922,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return leadingComments; } - /** - * Filter comment when removeComments is true according to following rules: - * - Pinned Comments - remove all but the top of the file one - * - Normal Comments - remove all - * - // Comments - remove all - * @param isTopOfFileComments boolean indicating whether comments are at the top of file - * @param isEmittedNode boolean indicating whether node associated with the comments will be - * emitted in javascript file - */ - function filterComments(ranges: CommentRange[], isTopOfFileComments: boolean, isEmittedNode=true): CommentRange[] { - if (compilerOptions.removeComments) { - // Only preserve pinned comments at the top of the file - ranges = isTopOfFileComments ? filter(ranges, isPinnedComments) : []; - } - else { - if (!isEmittedNode) { - // If the node will not be emitted in JS, remove all the comments(normal, pinned and ///) associated with the node, - // unless it is a triple slash comment at the top of the file. - // For Example: - // /// - // declare var x; - // /// - // interface F {} - // The first /// will NOT be removed while the second one will be removed eventhough both node will not be emitted - ranges = isTopOfFileComments ? filter(ranges, isTripleSlashOrPinnedComments) : filter(ranges, isPinnedComments); - } - } - - return ranges; - } - function isPinnedComments(comment: CommentRange) { if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; @@ -6960,11 +6929,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } /** - * Determine if the given comment is a triple-slash or pinned comment + * Determine if the given comment is a triple-slash * - * @return true if the comment is a triple-slash comment or a pinned comment else false + * @return true if the comment is a triple-slash comment else false **/ - function isTripleSlashOrPinnedComments(comment: CommentRange) { + function isTripleSlashComments(comment: CommentRange) { // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text // so that we don't end up computing comment string and doing match for all // comments if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && @@ -6975,7 +6944,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi textSubStr.match(fullTripleSlashAMDReferencePathRegEx) ? true : false; } - return isPinnedComments(comment); + return false; } function getLeadingCommentsToEmit(node: Node) { @@ -7015,9 +6984,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitLeadingCommentsWorker(node: Node, isEmittedNode: boolean) { - // If the caller only wants pinned or triple slash comments, then always filter - // down to that set. Otherwise, filter based on the current compiler options. - let leadingComments = filterComments(getLeadingCommentsToEmit(node), /*isTopOfFileComments:*/ node.pos === 0, isEmittedNode); + if (compilerOptions.removeComments) return; + let leadingComments: CommentRange[]; + + if (isEmittedNode) { + leadingComments = getLeadingCommentsToEmit(node); + } + else { + // If the node will not be emitted in JS, remove all the comments(normal, pinned and ///) associated with the node, + // unless it is a triple slash comment at the top of the file. + // For Example: + // /// + // declare var x; + // /// + // interface F {} + // The first /// will NOT be removed while the second one will be removed eventhough both node will not be emitted + leadingComments = node.pos === 0 ? filter(getLeadingCommentsToEmit(node), isTripleSlashComments) : []; + } emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); @@ -7026,8 +7009,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitTrailingComments(node: Node) { + if (compilerOptions.removeComments) return; // Emit the trailing comments only if the parent's end doesn't match - let trailingComments = filterComments(getTrailingCommentsToEmit(node), /*isTopOfFileComments:*/ node.pos === 0); + let trailingComments = getTrailingCommentsToEmit(node); // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); @@ -7039,13 +7023,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi * ^ => pos; the function will emit "comment1" in the emitJS */ function emitTrailingCommentsOfPosition(pos: number) { - let trailingComments = filterComments(getTrailingCommentRanges(currentSourceFile.text, pos), /*isTopOfFileComments*/ pos === 0); + if (compilerOptions.removeComments) return; + let trailingComments = getTrailingCommentRanges(currentSourceFile.text, pos); // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ true, newLine, writeComment); } function emitLeadingCommentsOfPosition(pos: number) { + if (compilerOptions.removeComments) return; let leadingComments: CommentRange[]; if (hasDetachedComments(pos)) { // get comments without detached comments @@ -7056,7 +7042,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi leadingComments = getLeadingCommentRanges(currentSourceFile.text, pos); } - leadingComments = filterComments(leadingComments, /*isTopOfFileComments*/ pos === 0); emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space @@ -7064,7 +7049,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitDetachedComments(node: TextRange) { - let leadingComments = filterComments(getLeadingCommentRanges(currentSourceFile.text, node.pos), node.pos === 0); + let leadingComments: CommentRange[]; + if (compilerOptions.removeComments) { + // removeComments is true, only reserve pinned comment at the top of file + // For example: + // /*! Pinned Comment */ + // + // var x = 10; + leadingComments = node.pos === 0 ? + filter(getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments) : []; + } + else { + // removeComments is false, just get detached as normal and bypass the process to filter comment + leadingComments = getLeadingCommentRanges(currentSourceFile.text, node.pos); + } + if (leadingComments) { let detachedComments: CommentRange[] = []; let lastComment: CommentRange; From 40cbd33e65b8f97d96892d99b0287e5b3506e232 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 25 Aug 2015 13:47:45 -0700 Subject: [PATCH 19/37] Update testcase only preserve pinned comment at the top of the file --- .../reference/commentOnAmbientClass1.js | 12 +++++- .../reference/commentOnAmbientClass1.symbols | 9 ++++- .../reference/commentOnAmbientClass1.types | 7 +++- .../reference/commentOnAmbientEnum.js | 12 +++++- .../reference/commentOnAmbientEnum.symbols | 15 ++++--- .../reference/commentOnAmbientEnum.types | 7 +++- .../reference/commentOnAmbientModule.js | 12 +++++- .../reference/commentOnAmbientModule.symbols | 19 +++++---- .../reference/commentOnAmbientModule.types | 7 +++- .../reference/commentOnAmbientVariable1.js | 12 +++++- .../commentOnAmbientVariable1.symbols | 11 ++++-- .../reference/commentOnAmbientVariable1.types | 7 +++- .../reference/commentOnAmbientfunction.js | 12 +++++- .../commentOnAmbientfunction.symbols | 11 ++++-- .../reference/commentOnAmbientfunction.types | 7 +++- .../reference/commentOnElidedModule1.js | 12 +++++- .../reference/commentOnElidedModule1.symbols | 9 ++++- .../reference/commentOnElidedModule1.types | 7 +++- .../reference/commentOnInterface1.js | 12 +++++- .../reference/commentOnInterface1.symbols | 9 ++++- .../reference/commentOnInterface1.types | 7 +++- .../reference/commentOnSignature1.js | 14 +++++-- .../reference/commentOnSignature1.symbols | 39 +++++++++++-------- .../reference/commentOnSignature1.types | 7 +++- tests/baselines/reference/pinnedComments1.js | 11 +++++- .../reference/pinnedComments1.symbols | 6 ++- .../baselines/reference/pinnedComments1.types | 6 ++- .../cases/compiler/commentOnAmbientClass1.ts | 7 +++- tests/cases/compiler/commentOnAmbientEnum.ts | 7 +++- .../cases/compiler/commentOnAmbientModule.ts | 7 +++- .../compiler/commentOnAmbientVariable1.ts | 7 +++- .../compiler/commentOnAmbientfunction.ts | 7 +++- .../cases/compiler/commentOnElidedModule1.ts | 7 +++- tests/cases/compiler/commentOnInterface1.ts | 7 +++- tests/cases/compiler/commentOnSignature1.ts | 7 +++- tests/cases/compiler/pinnedComments1.ts | 6 ++- 36 files changed, 281 insertions(+), 80 deletions(-) diff --git a/tests/baselines/reference/commentOnAmbientClass1.js b/tests/baselines/reference/commentOnAmbientClass1.js index beacc71335c..9837da4c371 100644 --- a/tests/baselines/reference/commentOnAmbientClass1.js +++ b/tests/baselines/reference/commentOnAmbientClass1.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnAmbientClass1.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare class C { } @@ -15,6 +20,9 @@ declare class E extends C { } //// [a.js] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnAmbientClass1.symbols b/tests/baselines/reference/commentOnAmbientClass1.symbols index 899c5f19a24..a08bb744df4 100644 --- a/tests/baselines/reference/commentOnAmbientClass1.symbols +++ b/tests/baselines/reference/commentOnAmbientClass1.symbols @@ -5,13 +5,18 @@ declare class E extends C { >C : Symbol(C, Decl(a.ts, 0, 0)) } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare class C { >C : Symbol(C, Decl(a.ts, 0, 0)) } // Don't keep this comment. declare class D { ->D : Symbol(D, Decl(a.ts, 2, 1)) +>D : Symbol(D, Decl(a.ts, 7, 1)) } diff --git a/tests/baselines/reference/commentOnAmbientClass1.types b/tests/baselines/reference/commentOnAmbientClass1.types index 44c0334ef6c..b0212056505 100644 --- a/tests/baselines/reference/commentOnAmbientClass1.types +++ b/tests/baselines/reference/commentOnAmbientClass1.types @@ -5,7 +5,12 @@ declare class E extends C { >C : C } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare class C { >C : C } diff --git a/tests/baselines/reference/commentOnAmbientEnum.js b/tests/baselines/reference/commentOnAmbientEnum.js index d602c68a0e5..f6c9d92ebff 100644 --- a/tests/baselines/reference/commentOnAmbientEnum.js +++ b/tests/baselines/reference/commentOnAmbientEnum.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnAmbientEnum.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare enum C { a, b, @@ -18,6 +23,9 @@ declare enum E { } //// [a.js] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnAmbientEnum.symbols b/tests/baselines/reference/commentOnAmbientEnum.symbols index d86d490113d..3a6e8089d4b 100644 --- a/tests/baselines/reference/commentOnAmbientEnum.symbols +++ b/tests/baselines/reference/commentOnAmbientEnum.symbols @@ -4,22 +4,27 @@ declare enum E { >E : Symbol(E, Decl(b.ts, 0, 0)) } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare enum C { >C : Symbol(C, Decl(a.ts, 0, 0)) a, ->a : Symbol(C.a, Decl(a.ts, 1, 16)) +>a : Symbol(C.a, Decl(a.ts, 6, 16)) b, ->b : Symbol(C.b, Decl(a.ts, 2, 6)) +>b : Symbol(C.b, Decl(a.ts, 7, 6)) c ->c : Symbol(C.c, Decl(a.ts, 3, 6)) +>c : Symbol(C.c, Decl(a.ts, 8, 6)) } // Don't keep this comment. declare enum D { ->D : Symbol(D, Decl(a.ts, 5, 1)) +>D : Symbol(D, Decl(a.ts, 10, 1)) } diff --git a/tests/baselines/reference/commentOnAmbientEnum.types b/tests/baselines/reference/commentOnAmbientEnum.types index 4a0193b7937..95f3d61b75f 100644 --- a/tests/baselines/reference/commentOnAmbientEnum.types +++ b/tests/baselines/reference/commentOnAmbientEnum.types @@ -4,7 +4,12 @@ declare enum E { >E : E } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare enum C { >C : C diff --git a/tests/baselines/reference/commentOnAmbientModule.js b/tests/baselines/reference/commentOnAmbientModule.js index d5a536302b5..2d43b502f29 100644 --- a/tests/baselines/reference/commentOnAmbientModule.js +++ b/tests/baselines/reference/commentOnAmbientModule.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnAmbientModule.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare module C { function foo(); } @@ -20,6 +25,9 @@ declare module E { } //// [a.js] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnAmbientModule.symbols b/tests/baselines/reference/commentOnAmbientModule.symbols index c1412c17880..e7525e6306f 100644 --- a/tests/baselines/reference/commentOnAmbientModule.symbols +++ b/tests/baselines/reference/commentOnAmbientModule.symbols @@ -5,28 +5,33 @@ declare module E { class foobar extends D.bar { >foobar : Symbol(foobar, Decl(b.ts, 1, 18)) ->D.bar : Symbol(D.bar, Decl(a.ts, 6, 18)) ->D : Symbol(D, Decl(a.ts, 3, 1)) ->bar : Symbol(D.bar, Decl(a.ts, 6, 18)) +>D.bar : Symbol(D.bar, Decl(a.ts, 11, 18)) +>D : Symbol(D, Decl(a.ts, 8, 1)) +>bar : Symbol(D.bar, Decl(a.ts, 11, 18)) foo(); >foo : Symbol(foo, Decl(b.ts, 2, 32)) } } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare module C { >C : Symbol(C, Decl(a.ts, 0, 0)) function foo(); ->foo : Symbol(foo, Decl(a.ts, 1, 18)) +>foo : Symbol(foo, Decl(a.ts, 6, 18)) } // Don't keep this comment. declare module D { ->D : Symbol(D, Decl(a.ts, 3, 1)) +>D : Symbol(D, Decl(a.ts, 8, 1)) class bar { } ->bar : Symbol(bar, Decl(a.ts, 6, 18)) +>bar : Symbol(bar, Decl(a.ts, 11, 18)) } diff --git a/tests/baselines/reference/commentOnAmbientModule.types b/tests/baselines/reference/commentOnAmbientModule.types index 629395a4e80..f54d248b461 100644 --- a/tests/baselines/reference/commentOnAmbientModule.types +++ b/tests/baselines/reference/commentOnAmbientModule.types @@ -14,7 +14,12 @@ declare module E { } } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare module C { >C : typeof C diff --git a/tests/baselines/reference/commentOnAmbientVariable1.js b/tests/baselines/reference/commentOnAmbientVariable1.js index b76fd3345b5..79c5dc85f23 100644 --- a/tests/baselines/reference/commentOnAmbientVariable1.js +++ b/tests/baselines/reference/commentOnAmbientVariable1.js @@ -1,9 +1,17 @@ //// [commentOnAmbientVariable1.ts] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare var v: number; // Don't keep this comment. declare var y: number; //// [commentOnAmbientVariable1.js] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ diff --git a/tests/baselines/reference/commentOnAmbientVariable1.symbols b/tests/baselines/reference/commentOnAmbientVariable1.symbols index 153653e7827..7847b4b85ad 100644 --- a/tests/baselines/reference/commentOnAmbientVariable1.symbols +++ b/tests/baselines/reference/commentOnAmbientVariable1.symbols @@ -1,9 +1,14 @@ === tests/cases/compiler/commentOnAmbientVariable1.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare var v: number; ->v : Symbol(v, Decl(commentOnAmbientVariable1.ts, 1, 11)) +>v : Symbol(v, Decl(commentOnAmbientVariable1.ts, 6, 11)) // Don't keep this comment. declare var y: number; ->y : Symbol(y, Decl(commentOnAmbientVariable1.ts, 4, 11)) +>y : Symbol(y, Decl(commentOnAmbientVariable1.ts, 9, 11)) diff --git a/tests/baselines/reference/commentOnAmbientVariable1.types b/tests/baselines/reference/commentOnAmbientVariable1.types index feff50f4293..645e1f099d4 100644 --- a/tests/baselines/reference/commentOnAmbientVariable1.types +++ b/tests/baselines/reference/commentOnAmbientVariable1.types @@ -1,5 +1,10 @@ === tests/cases/compiler/commentOnAmbientVariable1.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare var v: number; >v : number diff --git a/tests/baselines/reference/commentOnAmbientfunction.js b/tests/baselines/reference/commentOnAmbientfunction.js index 6290d407727..22613236941 100644 --- a/tests/baselines/reference/commentOnAmbientfunction.js +++ b/tests/baselines/reference/commentOnAmbientfunction.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnAmbientfunction.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare function foo(); // Don't keep this comment. @@ -12,6 +17,9 @@ declare function bar(); declare function foobar(a: typeof foo): typeof bar; //// [a.js] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnAmbientfunction.symbols b/tests/baselines/reference/commentOnAmbientfunction.symbols index c6afb72eb9c..4d83d2794a0 100644 --- a/tests/baselines/reference/commentOnAmbientfunction.symbols +++ b/tests/baselines/reference/commentOnAmbientfunction.symbols @@ -4,14 +4,19 @@ declare function foobar(a: typeof foo): typeof bar; >foobar : Symbol(foobar, Decl(b.ts, 0, 0)) >a : Symbol(a, Decl(b.ts, 1, 24)) >foo : Symbol(foo, Decl(a.ts, 0, 0)) ->bar : Symbol(bar, Decl(a.ts, 1, 23)) +>bar : Symbol(bar, Decl(a.ts, 6, 23)) === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare function foo(); >foo : Symbol(foo, Decl(a.ts, 0, 0)) // Don't keep this comment. declare function bar(); ->bar : Symbol(bar, Decl(a.ts, 1, 23)) +>bar : Symbol(bar, Decl(a.ts, 6, 23)) diff --git a/tests/baselines/reference/commentOnAmbientfunction.types b/tests/baselines/reference/commentOnAmbientfunction.types index f75f7b377fb..3347a55bf68 100644 --- a/tests/baselines/reference/commentOnAmbientfunction.types +++ b/tests/baselines/reference/commentOnAmbientfunction.types @@ -7,7 +7,12 @@ declare function foobar(a: typeof foo): typeof bar; >bar : () => any === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare function foo(); >foo : () => any diff --git a/tests/baselines/reference/commentOnElidedModule1.js b/tests/baselines/reference/commentOnElidedModule1.js index 8a7b8d91b4c..72585e6a9e8 100644 --- a/tests/baselines/reference/commentOnElidedModule1.js +++ b/tests/baselines/reference/commentOnElidedModule1.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnElidedModule1.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ module ElidedModule { } @@ -15,6 +20,9 @@ module ElidedModule3 { } //// [a.js] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnElidedModule1.symbols b/tests/baselines/reference/commentOnElidedModule1.symbols index 63ce4dadf97..57b55adeee4 100644 --- a/tests/baselines/reference/commentOnElidedModule1.symbols +++ b/tests/baselines/reference/commentOnElidedModule1.symbols @@ -4,13 +4,18 @@ module ElidedModule3 { >ElidedModule3 : Symbol(ElidedModule3, Decl(b.ts, 0, 0)) } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ module ElidedModule { >ElidedModule : Symbol(ElidedModule, Decl(a.ts, 0, 0)) } // Don't keep this comment. module ElidedModule2 { ->ElidedModule2 : Symbol(ElidedModule2, Decl(a.ts, 2, 1)) +>ElidedModule2 : Symbol(ElidedModule2, Decl(a.ts, 7, 1)) } diff --git a/tests/baselines/reference/commentOnElidedModule1.types b/tests/baselines/reference/commentOnElidedModule1.types index 8e095b8102f..d028b62519a 100644 --- a/tests/baselines/reference/commentOnElidedModule1.types +++ b/tests/baselines/reference/commentOnElidedModule1.types @@ -4,7 +4,12 @@ module ElidedModule3 { >ElidedModule3 : any } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ module ElidedModule { >ElidedModule : any } diff --git a/tests/baselines/reference/commentOnInterface1.js b/tests/baselines/reference/commentOnInterface1.js index bde6202f03f..c51658e2dfa 100644 --- a/tests/baselines/reference/commentOnInterface1.js +++ b/tests/baselines/reference/commentOnInterface1.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnInterface1.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ interface I { } @@ -15,6 +20,9 @@ interface I3 { } //// [a.js] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnInterface1.symbols b/tests/baselines/reference/commentOnInterface1.symbols index 9564d9b4cfa..8ed7e020712 100644 --- a/tests/baselines/reference/commentOnInterface1.symbols +++ b/tests/baselines/reference/commentOnInterface1.symbols @@ -4,13 +4,18 @@ interface I3 { >I3 : Symbol(I3, Decl(b.ts, 0, 0)) } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ interface I { >I : Symbol(I, Decl(a.ts, 0, 0)) } // Don't keep this comment. interface I2 { ->I2 : Symbol(I2, Decl(a.ts, 2, 1)) +>I2 : Symbol(I2, Decl(a.ts, 7, 1)) } diff --git a/tests/baselines/reference/commentOnInterface1.types b/tests/baselines/reference/commentOnInterface1.types index d03b1939026..34b0e0ce14f 100644 --- a/tests/baselines/reference/commentOnInterface1.types +++ b/tests/baselines/reference/commentOnInterface1.types @@ -4,7 +4,12 @@ interface I3 { >I3 : I3 } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ interface I { >I : I } diff --git a/tests/baselines/reference/commentOnSignature1.js b/tests/baselines/reference/commentOnSignature1.js index 1b2327f9861..d29710c631c 100644 --- a/tests/baselines/reference/commentOnSignature1.js +++ b/tests/baselines/reference/commentOnSignature1.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnSignature1.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ function foo(n: number): void; // Don't keep this comment. function foo(s: string): void; @@ -33,14 +38,15 @@ function foo2(a: any): void { } //// [a.js] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ function foo(a) { } var c = (function () { - /*! keep this pinned comment */ function c(a) { } - /*! keep this pinned comment */ c.prototype.foo = function (a) { }; return c; diff --git a/tests/baselines/reference/commentOnSignature1.symbols b/tests/baselines/reference/commentOnSignature1.symbols index 0d39565fb61..7f0d48401cd 100644 --- a/tests/baselines/reference/commentOnSignature1.symbols +++ b/tests/baselines/reference/commentOnSignature1.symbols @@ -14,49 +14,54 @@ function foo2(a: any): void { >a : Symbol(a, Decl(b.ts, 4, 14)) } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ function foo(n: number): void; ->foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 1, 30), Decl(a.ts, 3, 30)) ->n : Symbol(n, Decl(a.ts, 1, 13)) +>foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 6, 30), Decl(a.ts, 8, 30)) +>n : Symbol(n, Decl(a.ts, 6, 13)) // Don't keep this comment. function foo(s: string): void; ->foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 1, 30), Decl(a.ts, 3, 30)) ->s : Symbol(s, Decl(a.ts, 3, 13)) +>foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 6, 30), Decl(a.ts, 8, 30)) +>s : Symbol(s, Decl(a.ts, 8, 13)) function foo(a: any): void { ->foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 1, 30), Decl(a.ts, 3, 30)) ->a : Symbol(a, Decl(a.ts, 4, 13)) +>foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 6, 30), Decl(a.ts, 8, 30)) +>a : Symbol(a, Decl(a.ts, 9, 13)) } class c { ->c : Symbol(c, Decl(a.ts, 5, 1)) +>c : Symbol(c, Decl(a.ts, 10, 1)) // dont keep this comment constructor(a: string); ->a : Symbol(a, Decl(a.ts, 9, 16)) +>a : Symbol(a, Decl(a.ts, 14, 16)) /*! keep this pinned comment */ constructor(a: number); ->a : Symbol(a, Decl(a.ts, 11, 16)) +>a : Symbol(a, Decl(a.ts, 16, 16)) constructor(a: any) { ->a : Symbol(a, Decl(a.ts, 12, 16)) +>a : Symbol(a, Decl(a.ts, 17, 16)) } // dont keep this comment foo(a: string); ->foo : Symbol(foo, Decl(a.ts, 13, 5), Decl(a.ts, 16, 19), Decl(a.ts, 18, 19)) ->a : Symbol(a, Decl(a.ts, 16, 8)) +>foo : Symbol(foo, Decl(a.ts, 18, 5), Decl(a.ts, 21, 19), Decl(a.ts, 23, 19)) +>a : Symbol(a, Decl(a.ts, 21, 8)) /*! keep this pinned comment */ foo(a: number); ->foo : Symbol(foo, Decl(a.ts, 13, 5), Decl(a.ts, 16, 19), Decl(a.ts, 18, 19)) ->a : Symbol(a, Decl(a.ts, 18, 8)) +>foo : Symbol(foo, Decl(a.ts, 18, 5), Decl(a.ts, 21, 19), Decl(a.ts, 23, 19)) +>a : Symbol(a, Decl(a.ts, 23, 8)) foo(a: any) { ->foo : Symbol(foo, Decl(a.ts, 13, 5), Decl(a.ts, 16, 19), Decl(a.ts, 18, 19)) ->a : Symbol(a, Decl(a.ts, 19, 8)) +>foo : Symbol(foo, Decl(a.ts, 18, 5), Decl(a.ts, 21, 19), Decl(a.ts, 23, 19)) +>a : Symbol(a, Decl(a.ts, 24, 8)) } } diff --git a/tests/baselines/reference/commentOnSignature1.types b/tests/baselines/reference/commentOnSignature1.types index 790aaaf7523..30898e22851 100644 --- a/tests/baselines/reference/commentOnSignature1.types +++ b/tests/baselines/reference/commentOnSignature1.types @@ -14,7 +14,12 @@ function foo2(a: any): void { >a : any } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ function foo(n: number): void; >foo : { (n: number): void; (s: string): void; } >n : number diff --git a/tests/baselines/reference/pinnedComments1.js b/tests/baselines/reference/pinnedComments1.js index c4b8b41fbd7..9ab2a147e6a 100644 --- a/tests/baselines/reference/pinnedComments1.js +++ b/tests/baselines/reference/pinnedComments1.js @@ -1,12 +1,19 @@ //// [pinnedComments1.ts] +/*!========= + Keep this pinned comment + ========= +*/ /* unpinned comment */ -/*! pinned comment */ +/*! pinned comment that need to be removed */ class C { } //// [pinnedComments1.js] -/*! pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ var C = (function () { function C() { } diff --git a/tests/baselines/reference/pinnedComments1.symbols b/tests/baselines/reference/pinnedComments1.symbols index 53d46ecbaf6..6ee37435dfa 100644 --- a/tests/baselines/reference/pinnedComments1.symbols +++ b/tests/baselines/reference/pinnedComments1.symbols @@ -1,7 +1,11 @@ === tests/cases/compiler/pinnedComments1.ts === +/*!========= + Keep this pinned comment + ========= +*/ /* unpinned comment */ -/*! pinned comment */ +/*! pinned comment that need to be removed */ class C { >C : Symbol(C, Decl(pinnedComments1.ts, 0, 0)) } diff --git a/tests/baselines/reference/pinnedComments1.types b/tests/baselines/reference/pinnedComments1.types index d55feb67659..df97cbdbec9 100644 --- a/tests/baselines/reference/pinnedComments1.types +++ b/tests/baselines/reference/pinnedComments1.types @@ -1,7 +1,11 @@ === tests/cases/compiler/pinnedComments1.ts === +/*!========= + Keep this pinned comment + ========= +*/ /* unpinned comment */ -/*! pinned comment */ +/*! pinned comment that need to be removed */ class C { >C : C } diff --git a/tests/cases/compiler/commentOnAmbientClass1.ts b/tests/cases/compiler/commentOnAmbientClass1.ts index c13e4193512..1c153e86bf2 100644 --- a/tests/cases/compiler/commentOnAmbientClass1.ts +++ b/tests/cases/compiler/commentOnAmbientClass1.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare class C { } diff --git a/tests/cases/compiler/commentOnAmbientEnum.ts b/tests/cases/compiler/commentOnAmbientEnum.ts index a9ebe107c98..20d89c1b70d 100644 --- a/tests/cases/compiler/commentOnAmbientEnum.ts +++ b/tests/cases/compiler/commentOnAmbientEnum.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare enum C { a, b, diff --git a/tests/cases/compiler/commentOnAmbientModule.ts b/tests/cases/compiler/commentOnAmbientModule.ts index 41e12a61902..a8aeab7efba 100644 --- a/tests/cases/compiler/commentOnAmbientModule.ts +++ b/tests/cases/compiler/commentOnAmbientModule.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare module C { function foo(); } diff --git a/tests/cases/compiler/commentOnAmbientVariable1.ts b/tests/cases/compiler/commentOnAmbientVariable1.ts index 0124be05053..ef539441bd2 100644 --- a/tests/cases/compiler/commentOnAmbientVariable1.ts +++ b/tests/cases/compiler/commentOnAmbientVariable1.ts @@ -1,4 +1,9 @@ -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare var v: number; // Don't keep this comment. diff --git a/tests/cases/compiler/commentOnAmbientfunction.ts b/tests/cases/compiler/commentOnAmbientfunction.ts index d549303fc4f..51f3b6194b5 100644 --- a/tests/cases/compiler/commentOnAmbientfunction.ts +++ b/tests/cases/compiler/commentOnAmbientfunction.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare function foo(); // Don't keep this comment. diff --git a/tests/cases/compiler/commentOnElidedModule1.ts b/tests/cases/compiler/commentOnElidedModule1.ts index 22014a86f5b..0cdb7694273 100644 --- a/tests/cases/compiler/commentOnElidedModule1.ts +++ b/tests/cases/compiler/commentOnElidedModule1.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ module ElidedModule { } diff --git a/tests/cases/compiler/commentOnInterface1.ts b/tests/cases/compiler/commentOnInterface1.ts index a394da0dd2c..c22229b7ccf 100644 --- a/tests/cases/compiler/commentOnInterface1.ts +++ b/tests/cases/compiler/commentOnInterface1.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ interface I { } diff --git a/tests/cases/compiler/commentOnSignature1.ts b/tests/cases/compiler/commentOnSignature1.ts index 770c103a9fc..e8d2d831e8b 100644 --- a/tests/cases/compiler/commentOnSignature1.ts +++ b/tests/cases/compiler/commentOnSignature1.ts @@ -1,5 +1,10 @@ // @filename: a.ts -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ function foo(n: number): void; // Don't keep this comment. function foo(s: string): void; diff --git a/tests/cases/compiler/pinnedComments1.ts b/tests/cases/compiler/pinnedComments1.ts index 474769e9b20..4de91b33e56 100644 --- a/tests/cases/compiler/pinnedComments1.ts +++ b/tests/cases/compiler/pinnedComments1.ts @@ -1,6 +1,10 @@ // @comments: false +/*!========= + Keep this pinned comment + ========= +*/ /* unpinned comment */ -/*! pinned comment */ +/*! pinned comment that need to be removed */ class C { } \ No newline at end of file From 758cdf337872067758ab65efbb850cfd6465da1d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 30 Aug 2015 15:07:04 -0700 Subject: [PATCH 20/37] Only obtain regular type of fresh object literal type if necessary --- src/compiler/checker.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e624eb41d86..58b7e920bff 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4640,7 +4640,9 @@ namespace ts { // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. - source = getRegularTypeOfObjectLiteral(source); + if (target.flags & TypeFlags.UnionOrIntersection) { + source = getRegularTypeOfObjectLiteral(source); + } } let saveErrorInfo = errorInfo; From 1854adb56b47d39a84073972beb61a05e3223397 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 31 Aug 2015 20:33:02 -0700 Subject: [PATCH 21/37] address PR --- src/compiler/emitter.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 99c69c91e43..6e4bdff069b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -7047,9 +7047,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitLeadingCommentsWorker(node: Node, isEmittedNode: boolean) { - if (compilerOptions.removeComments) return; + if (compilerOptions.removeComments) { + return; + } + let leadingComments: CommentRange[]; - if (isEmittedNode) { leadingComments = getLeadingCommentsToEmit(node); } @@ -7062,7 +7064,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // /// // interface F {} // The first /// will NOT be removed while the second one will be removed eventhough both node will not be emitted - leadingComments = node.pos === 0 ? filter(getLeadingCommentsToEmit(node), isTripleSlashComments) : []; + if (node.pos === 0) { + leadingComments = filter(getLeadingCommentsToEmit(node), isTripleSlashComments); + } } emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); @@ -7072,7 +7076,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitTrailingComments(node: Node) { - if (compilerOptions.removeComments) return; + if (compilerOptions.removeComments) { + return; + } + // Emit the trailing comments only if the parent's end doesn't match let trailingComments = getTrailingCommentsToEmit(node); @@ -7086,7 +7093,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi * ^ => pos; the function will emit "comment1" in the emitJS */ function emitTrailingCommentsOfPosition(pos: number) { - if (compilerOptions.removeComments) return; + if (compilerOptions.removeComments) { + return; + } + let trailingComments = getTrailingCommentRanges(currentSourceFile.text, pos); // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ @@ -7094,7 +7104,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitLeadingCommentsOfPosition(pos: number) { - if (compilerOptions.removeComments) return; + if (compilerOptions.removeComments) { + return; + } + let leadingComments: CommentRange[]; if (hasDetachedComments(pos)) { // get comments without detached comments @@ -7119,8 +7132,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // /*! Pinned Comment */ // // var x = 10; - leadingComments = node.pos === 0 ? - filter(getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments) : []; + if (node.pos === 0) { + leadingComments = filter(getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments); + } } else { // removeComments is false, just get detached as normal and bypass the process to filter comment From 856f2d895c4f18f1b7c89f4248622788e8c85fd3 Mon Sep 17 00:00:00 2001 From: vilicvane Date: Fri, 4 Sep 2015 21:47:28 +0800 Subject: [PATCH 22/37] Fix issue #4603 --- src/compiler/emitter.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index eeaab6d2123..8a04be99caa 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -897,6 +897,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(text); } } + + function getEmittingNumericLiteralText(node: LiteralExpression): string { + let text = getLiteralText(node); + + if (languageVersion < ScriptTarget.ES6 && isBinaryOrOctalIntegerLiteral(node, text)) { + return node.text; + } else { + return text; + } + } function getLiteralText(node: LiteralExpression) { // Any template literal or string literal with an extended escape @@ -2352,7 +2362,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi operand.kind !== SyntaxKind.PostfixUnaryExpression && operand.kind !== SyntaxKind.NewExpression && !(operand.kind === SyntaxKind.CallExpression && node.parent.kind === SyntaxKind.NewExpression) && - !(operand.kind === SyntaxKind.FunctionExpression && node.parent.kind === SyntaxKind.CallExpression)) { + !(operand.kind === SyntaxKind.FunctionExpression && node.parent.kind === SyntaxKind.CallExpression) && + !(operand.kind === SyntaxKind.NumericLiteral && node.parent.kind === SyntaxKind.PropertyAccessExpression && !/^0[box]|[e.]/i.test(getEmittingNumericLiteralText(operand)))) { emit(operand); return; } From 32d8a22990612e3616068960042803d63b5b3150 Mon Sep 17 00:00:00 2001 From: vilicvane Date: Fri, 4 Sep 2015 22:15:10 +0800 Subject: [PATCH 23/37] Add tests for issue #4603 --- .../reference/castExpressionParentheses.js | 14 ++++++ .../castExpressionParentheses.symbols | 27 +++++++---- .../reference/castExpressionParentheses.types | 48 +++++++++++++++++++ .../castExpressionParentheses_ES6.js | 11 +++++ .../castExpressionParentheses_ES6.symbols | 7 +++ .../castExpressionParentheses_ES6.types | 11 +++++ .../compiler/castExpressionParentheses.ts | 7 +++ .../compiler/castExpressionParentheses_ES6.ts | 5 ++ 8 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 tests/baselines/reference/castExpressionParentheses_ES6.js create mode 100644 tests/baselines/reference/castExpressionParentheses_ES6.symbols create mode 100644 tests/baselines/reference/castExpressionParentheses_ES6.types create mode 100644 tests/cases/compiler/castExpressionParentheses_ES6.ts diff --git a/tests/baselines/reference/castExpressionParentheses.js b/tests/baselines/reference/castExpressionParentheses.js index ec18d6e373e..22316df7f43 100644 --- a/tests/baselines/reference/castExpressionParentheses.js +++ b/tests/baselines/reference/castExpressionParentheses.js @@ -7,6 +7,11 @@ declare var a; ([1,3,]); ("string"); (23.0); +(1); +(1.).foo; +(1.0).foo; +(12e+34).foo; +(0xff).foo; (/regexp/g); (false); (true); @@ -23,6 +28,8 @@ declare var a; declare var A; // should keep the parentheses in emit +(1).foo; +((1.0)).foo; (new A).foo; (typeof A).x; (-A).x; @@ -46,6 +53,11 @@ new (A()); [1, 3,]; "string"; 23.0; +1; +1..foo; +1.0.foo; +12e+34.foo; +0xff.foo; /regexp/g; false; true; @@ -59,6 +71,8 @@ a[0]; a.b["0"]; a().x; // should keep the parentheses in emit +(1).foo; +(1.0).foo; (new A).foo; (typeof A).x; (-A).x; diff --git a/tests/baselines/reference/castExpressionParentheses.symbols b/tests/baselines/reference/castExpressionParentheses.symbols index 7bc8169e40f..a7f51f9f2cb 100644 --- a/tests/baselines/reference/castExpressionParentheses.symbols +++ b/tests/baselines/reference/castExpressionParentheses.symbols @@ -10,6 +10,11 @@ declare var a; ([1,3,]); ("string"); (23.0); +(1); +(1.).foo; +(1.0).foo; +(12e+34).foo; +(0xff).foo; (/regexp/g); (false); (true); @@ -33,36 +38,38 @@ declare var a; >a : Symbol(a, Decl(castExpressionParentheses.ts, 0, 11)) declare var A; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) // should keep the parentheses in emit +(1).foo; +((1.0)).foo; (new A).foo; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) (typeof A).x; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) (-A).x; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) new (A()); ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) (()=> {})(); ->Tany : Symbol(Tany, Decl(castExpressionParentheses.ts, 28, 2)) +>Tany : Symbol(Tany, Decl(castExpressionParentheses.ts, 35, 2)) (function foo() { })(); ->foo : Symbol(foo, Decl(castExpressionParentheses.ts, 29, 6)) +>foo : Symbol(foo, Decl(castExpressionParentheses.ts, 36, 6)) (-A).x; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) // nested cast, should keep one pair of parenthese ((-A)).x; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) // nested parenthesized expression, should keep one pair of parenthese ((A)) ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) diff --git a/tests/baselines/reference/castExpressionParentheses.types b/tests/baselines/reference/castExpressionParentheses.types index ab563a4e8b7..1d203958555 100644 --- a/tests/baselines/reference/castExpressionParentheses.types +++ b/tests/baselines/reference/castExpressionParentheses.types @@ -28,6 +28,39 @@ declare var a; >23.0 : any >23.0 : number +(1); +>(1) : any +>1 : any +>1 : number + +(1.).foo; +>(1.).foo : any +>(1.) : any +>1. : any +>1. : number +>foo : any + +(1.0).foo; +>(1.0).foo : any +>(1.0) : any +>1.0 : any +>1.0 : number +>foo : any + +(12e+34).foo; +>(12e+34).foo : any +>(12e+34) : any +>12e+34 : any +>12e+34 : number +>foo : any + +(0xff).foo; +>(0xff).foo : any +>(0xff) : any +>0xff : any +>0xff : number +>foo : any + (/regexp/g); >(/regexp/g) : any >/regexp/g : any @@ -104,6 +137,21 @@ declare var A; >A : any // should keep the parentheses in emit +(1).foo; +>(1).foo : any +>(1) : any +>1 : any +>1 : number +>foo : any + +((1.0)).foo; +>((1.0)).foo : any +>((1.0)) : any +>(1.0) : any +>(1.0) : number +>1.0 : number +>foo : any + (new A).foo; >(new A).foo : any >(new A) : any diff --git a/tests/baselines/reference/castExpressionParentheses_ES6.js b/tests/baselines/reference/castExpressionParentheses_ES6.js new file mode 100644 index 00000000000..6ffbe7c2885 --- /dev/null +++ b/tests/baselines/reference/castExpressionParentheses_ES6.js @@ -0,0 +1,11 @@ +//// [castExpressionParentheses_ES6.ts] + +// parentheses should be omitted +// numeric literal +(0o123).foo; + + +//// [castExpressionParentheses_ES6.js] +// parentheses should be omitted +// numeric literal +0o123.foo; diff --git a/tests/baselines/reference/castExpressionParentheses_ES6.symbols b/tests/baselines/reference/castExpressionParentheses_ES6.symbols new file mode 100644 index 00000000000..c1b31043cb1 --- /dev/null +++ b/tests/baselines/reference/castExpressionParentheses_ES6.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/castExpressionParentheses_ES6.ts === + +No type information for this code.// parentheses should be omitted +No type information for this code.// numeric literal +No type information for this code.(0o123).foo; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/castExpressionParentheses_ES6.types b/tests/baselines/reference/castExpressionParentheses_ES6.types new file mode 100644 index 00000000000..41f968a834f --- /dev/null +++ b/tests/baselines/reference/castExpressionParentheses_ES6.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/castExpressionParentheses_ES6.ts === + +// parentheses should be omitted +// numeric literal +(0o123).foo; +>(0o123).foo : any +>(0o123) : any +>0o123 : any +>0o123 : number +>foo : any + diff --git a/tests/cases/compiler/castExpressionParentheses.ts b/tests/cases/compiler/castExpressionParentheses.ts index 93b26ebaf4e..e6ed4d82785 100644 --- a/tests/cases/compiler/castExpressionParentheses.ts +++ b/tests/cases/compiler/castExpressionParentheses.ts @@ -6,6 +6,11 @@ declare var a; ([1,3,]); ("string"); (23.0); +(1); +(1.).foo; +(1.0).foo; +(12e+34).foo; +(0xff).foo; (/regexp/g); (false); (true); @@ -22,6 +27,8 @@ declare var a; declare var A; // should keep the parentheses in emit +(1).foo; +((1.0)).foo; (new A).foo; (typeof A).x; (-A).x; diff --git a/tests/cases/compiler/castExpressionParentheses_ES6.ts b/tests/cases/compiler/castExpressionParentheses_ES6.ts new file mode 100644 index 00000000000..03d6d8ae5fa --- /dev/null +++ b/tests/cases/compiler/castExpressionParentheses_ES6.ts @@ -0,0 +1,5 @@ +// @target: es6 + +// parentheses should be omitted +// numeric literal +(0o123).foo; From 8d457113957da422b5cc88e5149bc0936bc8cf1f Mon Sep 17 00:00:00 2001 From: vilicvane Date: Sat, 5 Sep 2015 06:43:37 +0800 Subject: [PATCH 24/37] Else on the next line --- src/compiler/emitter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8a04be99caa..8fcd13c3ada 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -903,7 +903,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (languageVersion < ScriptTarget.ES6 && isBinaryOrOctalIntegerLiteral(node, text)) { return node.text; - } else { + } + else { return text; } } From 3a08af1450fdcefedca850e718deaafffee0b9f9 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 4 Sep 2015 17:45:57 -0700 Subject: [PATCH 25/37] Check for class expressions as well as class declarations --- src/compiler/checker.ts | 18 +++++++++--- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 7 ++++- ...xpressionExtendingAbstractClass.errors.txt | 14 ++++++++++ .../classExpressionExtendingAbstractClass.js | 28 +++++++++++++++++++ .../classExpressionExtendingAbstractClass.ts | 7 +++++ 6 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/classExpressionExtendingAbstractClass.errors.txt create mode 100644 tests/baselines/reference/classExpressionExtendingAbstractClass.js create mode 100644 tests/cases/compiler/classExpressionExtendingAbstractClass.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a7e9561c57f..45ea200a091 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12625,6 +12625,10 @@ namespace ts { return s.flags & SymbolFlags.Instantiated ? getSymbolLinks(s).target : s; } + function getClassLikeDeclarationOfSymbol(symbol: Symbol): Declaration { + return forEach(symbol.declarations, d => isClassLike(d) ? d : undefined); + } + function checkKindsOfPropertyMemberOverrides(type: InterfaceType, baseType: ObjectType): void { // TypeScript 1.0 spec (April 2014): 8.2.3 @@ -12662,14 +12666,20 @@ namespace ts { if (derived === base) { // derived class inherits base without override/redeclaration - let derivedClassDecl = getDeclarationOfKind(type.symbol, SyntaxKind.ClassDeclaration); + let derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol); // It is an error to inherit an abstract member without implementing it or being declared abstract. // If there is no declaration for the derived class (as in the case of class expressions), // then the class cannot be declared abstract. - if ( baseDeclarationFlags & NodeFlags.Abstract && (!derivedClassDecl || !(derivedClassDecl.flags & NodeFlags.Abstract))) { - error(derivedClassDecl, Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2, - typeToString(type), symbolToString(baseProperty), typeToString(baseType)); + if (baseDeclarationFlags & NodeFlags.Abstract && (!derivedClassDecl || !(derivedClassDecl.flags & NodeFlags.Abstract))) { + if (derivedClassDecl.kind === SyntaxKind.ClassExpression) { + error(derivedClassDecl, Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1, + symbolToString(baseProperty), typeToString(baseType)); + } + else { + error(derivedClassDecl, Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2, + typeToString(type), symbolToString(baseProperty), typeToString(baseType)); + } } } else { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index f7351bf6912..e1b1bf3bc9d 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -427,6 +427,7 @@ namespace ts { Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: { code: 2651, category: DiagnosticCategory.Error, key: "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums." }, Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." }, + Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1: { code: 2653, category: DiagnosticCategory.Error, key: "Non-abstract class expression does not implement inherited abstract member '{0}' from class '{1}'." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9fd08ef9bca..f41e24461c4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1692,11 +1692,16 @@ "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums.": { "category": "Error", "code": 2651 - }, + }, "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead.": { "category": "Error", "code": 2652 }, + "Non-abstract class expression does not implement inherited abstract member '{0}' from class '{1}'.": { + "category": "Error", + "code": 2653 + }, + "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/tests/baselines/reference/classExpressionExtendingAbstractClass.errors.txt b/tests/baselines/reference/classExpressionExtendingAbstractClass.errors.txt new file mode 100644 index 00000000000..b5d709fbf60 --- /dev/null +++ b/tests/baselines/reference/classExpressionExtendingAbstractClass.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/classExpressionExtendingAbstractClass.ts(5,9): error TS2653: Non-abstract class expression does not implement inherited abstract member 'foo' from class 'A'. + + +==== tests/cases/compiler/classExpressionExtendingAbstractClass.ts (1 errors) ==== + abstract class A { + abstract foo(): void; + } + + var C = class extends A { // no error reported! + ~~~~~ +!!! error TS2653: Non-abstract class expression does not implement inherited abstract member 'foo' from class 'A'. + }; + + \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionExtendingAbstractClass.js b/tests/baselines/reference/classExpressionExtendingAbstractClass.js new file mode 100644 index 00000000000..a5149538da2 --- /dev/null +++ b/tests/baselines/reference/classExpressionExtendingAbstractClass.js @@ -0,0 +1,28 @@ +//// [classExpressionExtendingAbstractClass.ts] +abstract class A { + abstract foo(): void; +} + +var C = class extends A { // no error reported! +}; + + + +//// [classExpressionExtendingAbstractClass.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var A = (function () { + function A() { + } + return A; +})(); +var C = (function (_super) { + __extends(class_1, _super); + function class_1() { + _super.apply(this, arguments); + } + return class_1; +})(A); diff --git a/tests/cases/compiler/classExpressionExtendingAbstractClass.ts b/tests/cases/compiler/classExpressionExtendingAbstractClass.ts new file mode 100644 index 00000000000..aadec5be7a4 --- /dev/null +++ b/tests/cases/compiler/classExpressionExtendingAbstractClass.ts @@ -0,0 +1,7 @@ +abstract class A { + abstract foo(): void; +} + +var C = class extends A { // no error reported! +}; + From d8c6f7edc32d6eeba06b19cbe2d17f0355fc1a21 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 4 Sep 2015 17:46:26 -0700 Subject: [PATCH 26/37] fix additional places where class expression should be queried --- src/compiler/checker.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 45ea200a091..0c40780d8e4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5105,8 +5105,8 @@ namespace ts { function abstractSignatureRelatedTo(source: Type, sourceSig: Signature, target: Type, targetSig: Signature) { if (sourceSig && targetSig) { - let sourceDecl = source.symbol && getDeclarationOfKind(source.symbol, SyntaxKind.ClassDeclaration); - let targetDecl = target.symbol && getDeclarationOfKind(target.symbol, SyntaxKind.ClassDeclaration); + let sourceDecl = source.symbol && getClassLikeDeclarationOfSymbol(source.symbol); + let targetDecl = target.symbol && getClassLikeDeclarationOfSymbol(target.symbol); if (!sourceDecl) { // If the source object isn't itself a class declaration, it can be freely assigned, regardless @@ -5120,8 +5120,8 @@ namespace ts { let sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature); let targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature); - let sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getDeclarationOfKind(sourceReturnType.symbol, SyntaxKind.ClassDeclaration); - let targetReturnDecl = targetReturnType && targetReturnType.symbol && getDeclarationOfKind(targetReturnType.symbol, SyntaxKind.ClassDeclaration); + let sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getClassLikeDeclarationOfSymbol(sourceReturnType.symbol); + let targetReturnDecl = targetReturnType && targetReturnType.symbol && getClassLikeDeclarationOfSymbol(targetReturnType.symbol); let sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & NodeFlags.Abstract; let targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & NodeFlags.Abstract; @@ -8873,7 +8873,7 @@ namespace ts { // Note, only class declarations can be declared abstract. // In the case of a merged class-module or class-interface declaration, // only the class declaration node will have the Abstract flag set. - let valueDecl = expressionType.symbol && getDeclarationOfKind(expressionType.symbol, SyntaxKind.ClassDeclaration); + let valueDecl = expressionType.symbol && getClassLikeDeclarationOfSymbol(expressionType.symbol); if (valueDecl && valueDecl.flags & NodeFlags.Abstract) { error(node, Diagnostics.Cannot_create_an_instance_of_the_abstract_class_0, declarationNameToString(valueDecl.name)); return resolveErrorCall(node); From 83214150f8eb7bb6360769d745652ccaa21ba5e3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 8 Sep 2015 18:40:30 -0700 Subject: [PATCH 27/37] do not emit '=' in jsx attribute if initializer is missing --- src/compiler/emitter.ts | 6 ++++-- .../reference/jsxEmitAttributeWithPreserve.js | 7 +++++++ .../reference/jsxEmitAttributeWithPreserve.symbols | 8 ++++++++ .../reference/jsxEmitAttributeWithPreserve.types | 10 ++++++++++ .../baselines/reference/jsxInvalidEsprimaTestSuite.js | 6 +++--- tests/baselines/reference/jsxReactTestSuite.js | 4 ++-- tests/baselines/reference/tsxAttributeResolution6.js | 6 +++--- .../reference/tsxGenericArrowFunctionParsing.js | 2 +- tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx | 4 ++++ 9 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 tests/baselines/reference/jsxEmitAttributeWithPreserve.js create mode 100644 tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols create mode 100644 tests/baselines/reference/jsxEmitAttributeWithPreserve.types create mode 100644 tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d84b7b70ada..c83c743e4a2 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1292,8 +1292,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function jsxEmitPreserve(node: JsxElement|JsxSelfClosingElement) { function emitJsxAttribute(node: JsxAttribute) { emit(node.name); - write("="); - emit(node.initializer); + if (node.initializer) { + write("="); + emit(node.initializer); + } } function emitJsxSpreadAttribute(node: JsxSpreadAttribute) { diff --git a/tests/baselines/reference/jsxEmitAttributeWithPreserve.js b/tests/baselines/reference/jsxEmitAttributeWithPreserve.js new file mode 100644 index 00000000000..07cb0dee485 --- /dev/null +++ b/tests/baselines/reference/jsxEmitAttributeWithPreserve.js @@ -0,0 +1,7 @@ +//// [jsxEmitAttributeWithPreserve.tsx] + +declare var React: any; + + +//// [jsxEmitAttributeWithPreserve.jsx] +; diff --git a/tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols b/tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols new file mode 100644 index 00000000000..4ffadb8e888 --- /dev/null +++ b/tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx === + +declare var React: any; +>React : Symbol(React, Decl(jsxEmitAttributeWithPreserve.tsx, 1, 11)) + + +>data : Symbol(unknown) + diff --git a/tests/baselines/reference/jsxEmitAttributeWithPreserve.types b/tests/baselines/reference/jsxEmitAttributeWithPreserve.types new file mode 100644 index 00000000000..972ca1c3d88 --- /dev/null +++ b/tests/baselines/reference/jsxEmitAttributeWithPreserve.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx === + +declare var React: any; +>React : any + + +> : any +>foo : any +>data : any + diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js index daf344b08da..d623e127be7 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js @@ -47,9 +47,9 @@ a / > ; < a; b > ; b > ; -; +; b.c > ; -; +; c > ; ; < .a > ; @@ -67,7 +67,7 @@ var x =
one
two
;; var x =
one
/* intervening comment */ /* intervening comment */
two
;; {"str"}}; id="b" />; -
>; +
>;
;
stuff
...props}>; diff --git a/tests/baselines/reference/jsxReactTestSuite.js b/tests/baselines/reference/jsxReactTestSuite.js index 300274a1614..18013d4be9b 100644 --- a/tests/baselines/reference/jsxReactTestSuite.js +++ b/tests/baselines/reference/jsxReactTestSuite.js @@ -158,14 +158,14 @@ var x =
; ; ; -; +; ; ; ; ; ; ; -; +; ; ; Text; diff --git a/tests/baselines/reference/tsxAttributeResolution6.js b/tests/baselines/reference/tsxAttributeResolution6.js index f4af0ba875a..5d6ad1e20c6 100644 --- a/tests/baselines/reference/tsxAttributeResolution6.js +++ b/tests/baselines/reference/tsxAttributeResolution6.js @@ -20,10 +20,10 @@ declare module JSX { //// [tsxAttributeResolution6.jsx] // Error -; +; ; ; // OK -; +; ; -; +; diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js index f493347ca9c..ece48831f8e 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js @@ -42,5 +42,5 @@ x3(); var x4 = () => ; x4.isElement; // This is an element -var x5 = () => ; +var x5 = () => ; x5.isElement; diff --git a/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx b/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx new file mode 100644 index 00000000000..dc32ef7a0ca --- /dev/null +++ b/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx @@ -0,0 +1,4 @@ +//@jsx: preserve + +declare var React: any; + \ No newline at end of file From aa29644c2a17a9ea20aca894bf67c44c78f46b2d Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 8 Sep 2015 22:40:16 -0700 Subject: [PATCH 28/37] allow to use keywords as jsx identifiers --- src/compiler/parser.ts | 6 +++++- src/compiler/scanner.ts | 2 +- tests/baselines/reference/keywordInJsxIdentifier.js | 7 +++++++ .../baselines/reference/keywordInJsxIdentifier.symbols | 8 ++++++++ tests/baselines/reference/keywordInJsxIdentifier.types | 10 ++++++++++ tests/cases/compiler/keywordInJsxIdentifier.tsx | 4 ++++ 6 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/keywordInJsxIdentifier.js create mode 100644 tests/baselines/reference/keywordInJsxIdentifier.symbols create mode 100644 tests/baselines/reference/keywordInJsxIdentifier.types create mode 100644 tests/cases/compiler/keywordInJsxIdentifier.tsx diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 350b9d450b8..57e19156568 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -12,6 +12,10 @@ namespace ts { export function createNode(kind: SyntaxKind): Node { return new (getNodeConstructor(kind))(); } + + export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean { + return token >= SyntaxKind.Identifier; + } function visitNode(cbNode: (node: Node) => T, node: Node): T { if (node) { @@ -4102,7 +4106,7 @@ namespace ts { } function isIdentifierOrKeyword() { - return token >= SyntaxKind.Identifier; + return tokenIsIdentifierOrKeyword(token); } function nextTokenIsIdentifierOrKeywordOnSameLine() { diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 199e7e9b638..2e10a1f1b84 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -1590,7 +1590,7 @@ namespace ts { // Scans a JSX identifier; these differ from normal identifiers in that // they allow dashes function scanJsxIdentifier(): SyntaxKind { - if (token === SyntaxKind.Identifier) { + if (tokenIsIdentifierOrKeyword(token)) { let firstCharPosition = pos; while (pos < end) { let ch = text.charCodeAt(pos); diff --git a/tests/baselines/reference/keywordInJsxIdentifier.js b/tests/baselines/reference/keywordInJsxIdentifier.js new file mode 100644 index 00000000000..8a00a68e334 --- /dev/null +++ b/tests/baselines/reference/keywordInJsxIdentifier.js @@ -0,0 +1,7 @@ +//// [keywordInJsxIdentifier.tsx] + +declare var React: any; + + +//// [keywordInJsxIdentifier.js] +React.createElement("foo", {"class-id": true}); diff --git a/tests/baselines/reference/keywordInJsxIdentifier.symbols b/tests/baselines/reference/keywordInJsxIdentifier.symbols new file mode 100644 index 00000000000..6617a640dca --- /dev/null +++ b/tests/baselines/reference/keywordInJsxIdentifier.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/keywordInJsxIdentifier.tsx === + +declare var React: any; +>React : Symbol(React, Decl(keywordInJsxIdentifier.tsx, 1, 11)) + + +>class-id : Symbol(unknown) + diff --git a/tests/baselines/reference/keywordInJsxIdentifier.types b/tests/baselines/reference/keywordInJsxIdentifier.types new file mode 100644 index 00000000000..888d027fddb --- /dev/null +++ b/tests/baselines/reference/keywordInJsxIdentifier.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/keywordInJsxIdentifier.tsx === + +declare var React: any; +>React : any + + +> : any +>foo : any +>class-id : any + diff --git a/tests/cases/compiler/keywordInJsxIdentifier.tsx b/tests/cases/compiler/keywordInJsxIdentifier.tsx new file mode 100644 index 00000000000..8c09c90b170 --- /dev/null +++ b/tests/cases/compiler/keywordInJsxIdentifier.tsx @@ -0,0 +1,4 @@ +//@jsx: react + +declare var React: any; + \ No newline at end of file From 44009fa9512b8bf64c20f8e3849742f65f0d22f5 Mon Sep 17 00:00:00 2001 From: SaschaNaz Date: Thu, 10 Sep 2015 01:37:34 +0900 Subject: [PATCH 29/37] Housekeeping part from #4609 --- src/services/formatting/rules.ts | 39 +++++++++----------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 876efa3a9e1..38a2bb74372 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -213,25 +213,15 @@ namespace ts.formatting { public NoSpaceBetweenYieldKeywordAndStar: Rule; public SpaceBetweenYieldOrYieldStarAndOperand: Rule; - // Async-await + // Async functions public SpaceBetweenAsyncAndFunctionKeyword: Rule; - public NoSpaceBetweenAsyncAndFunctionKeyword: Rule; - public SpaceAfterAwaitKeyword: Rule; - public NoSpaceAfterAwaitKeyword: Rule; - - // Type alias declaration - public SpaceAfterTypeKeyword: Rule; - public NoSpaceAfterTypeKeyword: Rule; // Tagged template string public SpaceBetweenTagAndTemplateString: Rule; - public NoSpaceBetweenTagAndTemplateString: Rule; // Type operation public SpaceBeforeBar: Rule; - public NoSpaceBeforeBar: Rule; public SpaceAfterBar: Rule; - public NoSpaceAfterBar: Rule; public SpaceBeforeAmpersand: Rule; public SpaceAfterAmpersand: Rule; @@ -315,7 +305,7 @@ namespace ts.formatting { this.NoSpaceBeforeComma = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CommaToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); - this.SpaceAfterCertainKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.VarKeyword, SyntaxKind.ThrowKeyword, SyntaxKind.NewKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); + this.SpaceAfterCertainKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.VarKeyword, SyntaxKind.ThrowKeyword, SyntaxKind.NewKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword, SyntaxKind.AwaitKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); this.SpaceAfterLetConstInVariableDeclaration = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.LetKeyword, SyntaxKind.ConstKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), RuleAction.Space)); this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), RuleAction.Delete)); this.SpaceAfterFunctionInFuncDecl = new Rule(RuleDescriptor.create3(SyntaxKind.FunctionKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space)); @@ -348,7 +338,12 @@ namespace ts.formatting { this.NoSpaceAfterModuleImport = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.ModuleKeyword, SyntaxKind.RequireKeyword]), SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); + this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([ + SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, + SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, + SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword, + SyntaxKind.TypeKeyword + ]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); this.SpaceBeforeCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.ExtendsKeyword, SyntaxKind.ImplementsKeyword])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { @@ -384,23 +379,13 @@ namespace ts.formatting { // Async-await this.SpaceBetweenAsyncAndFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.AsyncKeyword, SyntaxKind.FunctionKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceBetweenAsyncAndFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.AsyncKeyword, SyntaxKind.FunctionKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); - this.SpaceAfterAwaitKeyword = new Rule(RuleDescriptor.create3(SyntaxKind.AwaitKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceAfterAwaitKeyword = new Rule(RuleDescriptor.create3(SyntaxKind.AwaitKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); - - // Type alias declaration - this.SpaceAfterTypeKeyword = new Rule(RuleDescriptor.create3(SyntaxKind.TypeKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceAfterTypeKeyword = new Rule(RuleDescriptor.create3(SyntaxKind.TypeKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); // template string this.SpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); // type operation this.SpaceBeforeBar = new Rule(RuleDescriptor.create3(SyntaxKind.BarToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceBeforeBar = new Rule(RuleDescriptor.create3(SyntaxKind.BarToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); this.SpaceAfterBar = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.BarToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceAfterBar = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.BarToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); this.SpaceBeforeAmpersand = new Rule(RuleDescriptor.create3(SyntaxKind.AmpersandToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); this.SpaceAfterAmpersand = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.AmpersandToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); @@ -430,11 +415,9 @@ namespace ts.formatting { this.NoSpaceBeforeOpenParenInFuncCall, this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, this.SpaceAfterVoidOperator, - this.SpaceBetweenAsyncAndFunctionKeyword, this.NoSpaceBetweenAsyncAndFunctionKeyword, - this.SpaceAfterAwaitKeyword, this.NoSpaceAfterAwaitKeyword, - this.SpaceAfterTypeKeyword, this.NoSpaceAfterTypeKeyword, - this.SpaceBetweenTagAndTemplateString, this.NoSpaceBetweenTagAndTemplateString, - this.SpaceBeforeBar, this.NoSpaceBeforeBar, this.SpaceAfterBar, this.NoSpaceAfterBar, + this.SpaceBetweenAsyncAndFunctionKeyword, + this.SpaceBetweenTagAndTemplateString, + this.SpaceBeforeBar, this.SpaceAfterBar, this.SpaceBeforeAmpersand, this.SpaceAfterAmpersand, // TypeScript-specific rules From 8cd8f863b36d8c072ebb8d7becffeee5f9753b24 Mon Sep 17 00:00:00 2001 From: SaschaNaz Date: Thu, 10 Sep 2015 01:41:21 +0900 Subject: [PATCH 30/37] remove type operation rules, add types instead --- src/services/formatting/rules.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 38a2bb74372..0db1865e352 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -219,12 +219,6 @@ namespace ts.formatting { // Tagged template string public SpaceBetweenTagAndTemplateString: Rule; - // Type operation - public SpaceBeforeBar: Rule; - public SpaceAfterBar: Rule; - public SpaceBeforeAmpersand: Rule; - public SpaceAfterAmpersand: Rule; - constructor() { /// /// Common Rules @@ -383,12 +377,6 @@ namespace ts.formatting { // template string this.SpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - // type operation - this.SpaceBeforeBar = new Rule(RuleDescriptor.create3(SyntaxKind.BarToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.SpaceAfterBar = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.BarToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.SpaceBeforeAmpersand = new Rule(RuleDescriptor.create3(SyntaxKind.AmpersandToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.SpaceAfterAmpersand = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.AmpersandToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = [ @@ -417,8 +405,6 @@ namespace ts.formatting { this.SpaceAfterVoidOperator, this.SpaceBetweenAsyncAndFunctionKeyword, this.SpaceBetweenTagAndTemplateString, - this.SpaceBeforeBar, this.SpaceAfterBar, - this.SpaceBeforeAmpersand, this.SpaceAfterAmpersand, // TypeScript-specific rules this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, @@ -522,6 +508,8 @@ namespace ts.formatting { case SyntaxKind.ConditionalExpression: case SyntaxKind.AsExpression: case SyntaxKind.TypePredicate: + case SyntaxKind.UnionType: + case SyntaxKind.IntersectionType: return true; // equals in binding elements: function foo([[x, y] = [1, 2]]) From eb2d86aa7b9881fa53dc890e13b632313edcf15f Mon Sep 17 00:00:00 2001 From: SaschaNaz Date: Thu, 10 Sep 2015 02:20:15 +0900 Subject: [PATCH 31/37] revert newlines --- src/services/formatting/rules.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 0db1865e352..02e785f6b3e 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -332,12 +332,7 @@ namespace ts.formatting { this.NoSpaceAfterModuleImport = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.ModuleKeyword, SyntaxKind.RequireKeyword]), SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([ - SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, - SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, - SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword, - SyntaxKind.TypeKeyword - ]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); + this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword, SyntaxKind.TypeKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); this.SpaceBeforeCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.ExtendsKeyword, SyntaxKind.ImplementsKeyword])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { From c05650aea3c473f41f4de0687080620758310527 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 9 Sep 2015 16:38:04 -0700 Subject: [PATCH 32/37] Actually cache regular version of fresh object literal type --- src/compiler/checker.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 58b7e920bff..3d1250616ef 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5507,6 +5507,7 @@ namespace ts { regularType.constructSignatures = (type).constructSignatures; regularType.stringIndexType = (type).stringIndexType; regularType.numberIndexType = (type).numberIndexType; + (type).regularType = regularType; } return regularType; } From 6e245701356ebc7f5dbca7fbd31407e9f4495685 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 10 Sep 2015 10:46:39 -0700 Subject: [PATCH 33/37] reattach file diagnostics for modified files when reusing program structure --- src/compiler/program.ts | 78 +++++++++++-------- src/compiler/types.ts | 3 + src/compiler/utilities.ts | 13 +++- .../cases/unittests/reuseProgramStructure.ts | 9 ++- 4 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index a1861f6b462..d86a80a5387 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -358,7 +358,8 @@ namespace ts { export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program { let program: Program; let files: SourceFile[] = []; - let diagnostics = createDiagnosticCollection(); + let fileProcessingDiagnostics = createDiagnosticCollection(); + let programDiagnostics = createDiagnosticCollection(); let commonSourceDirectory: string; let diagnosticsProducingTypeChecker: TypeChecker; @@ -428,6 +429,7 @@ namespace ts { getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(), getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(), getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(), + getFileProcessingDiagnostics: () => fileProcessingDiagnostics }; return program; @@ -460,6 +462,7 @@ namespace ts { // check if program source files has changed in the way that can affect structure of the program let newSourceFiles: SourceFile[] = []; + let modifiedSourceFiles: SourceFile[] = []; for (let oldSourceFile of oldProgram.getSourceFiles()) { let newSourceFile = host.getSourceFile(oldSourceFile.fileName, options.target); if (!newSourceFile) { @@ -499,6 +502,7 @@ namespace ts { } // pass the cache of module resolutions from the old source file newSourceFile.resolvedModules = oldSourceFile.resolvedModules; + modifiedSourceFiles.push(newSourceFile); } else { // file has no changes - use it as is @@ -515,7 +519,11 @@ namespace ts { } files = newSourceFiles; + fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics(); + for (let modifiedFile of modifiedSourceFiles) { + fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile); + } oldProgram.structureIsReused = true; return true; @@ -645,9 +653,10 @@ namespace ts { Debug.assert(!!sourceFile.bindDiagnostics); let bindDiagnostics = sourceFile.bindDiagnostics; let checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken); - let programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName); + let fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); + let programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); - return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); + return bindDiagnostics.concat(checkDiagnostics).concat(fileProcessingDiagnosticsInFile).concat(programDiagnosticsInFile); }); } @@ -664,7 +673,8 @@ namespace ts { function getOptionsDiagnostics(): Diagnostic[] { let allDiagnostics: Diagnostic[] = []; - addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics()) + addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics()); return sortAndDeduplicateDiagnostics(allDiagnostics); } @@ -772,10 +782,10 @@ namespace ts { if (diagnostic) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { - diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, diagnostic, ...diagnosticArgument)); + fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, diagnostic, ...diagnosticArgument)); } else { - diagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument)); + fileProcessingDiagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument)); } } } @@ -797,11 +807,11 @@ namespace ts { // We haven't looked for this file, do so now and cache result let file = host.getSourceFile(fileName, options.target, hostErrorMessage => { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, + fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } else { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); filesByName.set(canonicalName, file); @@ -837,11 +847,11 @@ namespace ts { let sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, + fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } else { - diagnostics.add(createCompilerDiagnostic(Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } } } @@ -877,7 +887,7 @@ namespace ts { return; function findModuleSourceFile(fileName: string, nameLiteral: Expression) { - return findSourceFile(fileName, /* isDefaultLib */ false, file, nameLiteral.pos, nameLiteral.end); + return findSourceFile(fileName, /* isDefaultLib */ false, file, skipTrivia(file.text, nameLiteral.pos), nameLiteral.end); } } @@ -902,7 +912,7 @@ namespace ts { for (let i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { if (commonPathComponents[i] !== sourcePathComponents[i]) { if (i === 0) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); return; } @@ -931,7 +941,7 @@ namespace ts { if (!isDeclarationFile(sourceFile)) { let absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); allFilesBelongToPath = false; } } @@ -944,52 +954,52 @@ namespace ts { function verifyCompilerOptions() { if (options.isolatedModules) { if (options.declaration) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); } if (options.noEmitOnError) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); } if (options.out) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); } if (options.outFile) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); } } if (options.inlineSourceMap) { if (options.sourceMap) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); } if (options.mapRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); } if (options.sourceRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); } } if (options.inlineSources) { if (!options.sourceMap && !options.inlineSourceMap) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); } } if (options.out && options.outFile) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); } if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { // Error to specify --mapRoot or --sourceRoot without mapSourceFiles if (options.mapRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); } if (options.sourceRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); } return; } @@ -1000,24 +1010,24 @@ namespace ts { let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); if (options.isolatedModules) { if (!options.module && languageVersion < ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } let firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !isDeclarationFile(f) ? f : undefined); if (firstNonExternalModuleSourceFile) { let span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); + programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); + programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } // Cannot specify module gen target when in es6 or above if (options.module && languageVersion >= ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); } // there has to be common source directory if user specified --outdir || --sourceRoot @@ -1046,30 +1056,30 @@ namespace ts { if (options.noEmit) { if (options.out) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); } if (options.outFile) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); } if (options.outDir) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); } if (options.declaration) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); } } if (options.emitDecoratorMetadata && !options.experimentalDecorators) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } if (options.experimentalAsyncFunctions && options.target !== ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 47182e39527..265fa5c86fb 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1359,6 +1359,7 @@ namespace ts { /* @internal */ getSymbolCount(): number; /* @internal */ getTypeCount(): number; + /* @internal */ getFileProcessingDiagnostics(): DiagnosticCollection; // For testing purposes only. /* @internal */ structureIsReused?: boolean; } @@ -2322,5 +2323,7 @@ namespace ts { // operation caused diagnostics to be returned by storing and comparing the return value // of this method before/after the operation is performed. getModificationCount(): number; + + /* @internal */ reattachFileDiagnostics(newFile: SourceFile): void; } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 99ea06532a0..6c5bd8df95d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1507,12 +1507,23 @@ namespace ts { add, getGlobalDiagnostics, getDiagnostics, - getModificationCount + getModificationCount, + reattachFileDiagnostics }; function getModificationCount() { return modificationCount; } + + function reattachFileDiagnostics(newFile: SourceFile): void { + if (!hasProperty(fileDiagnostics, newFile.fileName)) { + return; + } + + for (let diagnostic of fileDiagnostics[newFile.fileName]) { + diagnostic.file = newFile; + } + } function add(diagnostic: Diagnostic): void { let diagnostics: Diagnostic[]; diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index 6c043299c8f..56b1dedbcbb 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -184,7 +184,11 @@ module ts { describe("Reuse program structure", () => { let target = ScriptTarget.Latest; let files = [ - { name: "a.ts", text: SourceText.New(`/// `, "", `var x = 1`) }, + { name: "a.ts", text: SourceText.New( + ` +/// +/// +`, "",`var x = 1`) }, { name: "b.ts", text: SourceText.New(`/// `, "", `var y = 2`) }, { name: "c.ts", text: SourceText.New("", "", `var z = 1;`) }, ] @@ -195,6 +199,9 @@ module ts { files[0].text = files[0].text.updateProgram("var x = 100"); }); assert.isTrue(program_1.structureIsReused); + let program1Diagnostics = program_1.getSemanticDiagnostics(program_1.getSourceFile("a.ts")) + let program2Diagnostics = program_2.getSemanticDiagnostics(program_1.getSourceFile("a.ts")) + assert.equal(program1Diagnostics.length, program2Diagnostics.length); }); it("fails if change affects tripleslash references", () => { From 5989d4826755286588975d5863e4eda2fc727694 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 10 Sep 2015 12:05:23 -0700 Subject: [PATCH 34/37] addressed PR feedback --- src/compiler/parser.ts | 34 +++++++------------ src/compiler/scanner.ts | 5 +++ .../reference/keywordInJsxIdentifier.js | 9 ++++- .../reference/keywordInJsxIdentifier.symbols | 11 +++++- .../reference/keywordInJsxIdentifier.types | 17 +++++++++- .../cases/compiler/keywordInJsxIdentifier.tsx | 5 ++- 6 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 57e19156568..330ad05518b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -12,10 +12,6 @@ namespace ts { export function createNode(kind: SyntaxKind): Node { return new (getNodeConstructor(kind))(); } - - export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean { - return token >= SyntaxKind.Identifier; - } function visitNode(cbNode: (node: Node) => T, node: Node): T { if (node) { @@ -1062,11 +1058,11 @@ namespace ts { } function parseIdentifierName(): Identifier { - return createIdentifier(isIdentifierOrKeyword()); + return createIdentifier(tokenIsIdentifierOrKeyword(token)); } function isLiteralPropertyName(): boolean { - return isIdentifierOrKeyword() || + return tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral; } @@ -1090,7 +1086,7 @@ namespace ts { } function isSimplePropertyName() { - return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || isIdentifierOrKeyword(); + return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || tokenIsIdentifierOrKeyword(token); } function parseComputedPropertyName(): ComputedPropertyName { @@ -1217,9 +1213,9 @@ namespace ts { case ParsingContext.HeritageClauses: return isHeritageClause(); case ParsingContext.ImportOrExportSpecifiers: - return isIdentifierOrKeyword(); + return tokenIsIdentifierOrKeyword(token); case ParsingContext.JsxAttributes: - return isIdentifierOrKeyword() || token === SyntaxKind.OpenBraceToken; + return tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.OpenBraceToken; case ParsingContext.JsxChildren: return true; case ParsingContext.JSDocFunctionParameters: @@ -1258,7 +1254,7 @@ namespace ts { function nextTokenIsIdentifierOrKeyword() { nextToken(); - return isIdentifierOrKeyword(); + return tokenIsIdentifierOrKeyword(token); } function isHeritageClauseExtendsOrImplementsKeyword(): boolean { @@ -1828,7 +1824,7 @@ namespace ts { // the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword". // In the first case though, ASI will not take effect because there is not a // line terminator after the identifier or keyword. - if (scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword()) { + if (scanner.hasPrecedingLineBreak() && tokenIsIdentifierOrKeyword(token)) { let matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); if (matchesPattern) { @@ -2286,7 +2282,7 @@ namespace ts { } } - if (isIdentifierOrKeyword()) { + if (tokenIsIdentifierOrKeyword(token)) { return parsePropertyOrMethodSignature(); } } @@ -4105,13 +4101,9 @@ namespace ts { } } - function isIdentifierOrKeyword() { - return tokenIsIdentifierOrKeyword(token); - } - function nextTokenIsIdentifierOrKeywordOnSameLine() { nextToken(); - return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + return tokenIsIdentifierOrKeyword(token) && !scanner.hasPrecedingLineBreak(); } function nextTokenIsFunctionKeywordOnSameLine() { @@ -4121,7 +4113,7 @@ namespace ts { function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() { nextToken(); - return (isIdentifierOrKeyword() || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak(); + return (tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak(); } function isDeclaration(): boolean { @@ -4174,7 +4166,7 @@ namespace ts { case SyntaxKind.ImportKeyword: nextToken(); return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || isIdentifierOrKeyword(); + token === SyntaxKind.OpenBraceToken || tokenIsIdentifierOrKeyword(token); case SyntaxKind.ExportKeyword: nextToken(); if (token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken || @@ -4781,7 +4773,7 @@ namespace ts { // It is very important that we check this *after* checking indexers because // the [ token can start an index signature or a computed property name - if (isIdentifierOrKeyword() || + if (tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || token === SyntaxKind.AsteriskToken || @@ -5324,7 +5316,7 @@ namespace ts { return true; } - return isIdentifierOrKeyword(); + return tokenIsIdentifierOrKeyword(token); } export function parseJSDocTypeExpressionForTests(content: string, start: number, length: number) { diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 2e10a1f1b84..82fbc8c2a59 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -6,6 +6,11 @@ namespace ts { (message: DiagnosticMessage, length: number): void; } + /* @internal */ + export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean { + return token >= SyntaxKind.Identifier; + } + export interface Scanner { getStartPos(): number; getToken(): SyntaxKind; diff --git a/tests/baselines/reference/keywordInJsxIdentifier.js b/tests/baselines/reference/keywordInJsxIdentifier.js index 8a00a68e334..677a79138e6 100644 --- a/tests/baselines/reference/keywordInJsxIdentifier.js +++ b/tests/baselines/reference/keywordInJsxIdentifier.js @@ -1,7 +1,14 @@ //// [keywordInJsxIdentifier.tsx] declare var React: any; - +; +; +; +; + //// [keywordInJsxIdentifier.js] React.createElement("foo", {"class-id": true}); +React.createElement("foo", {"class": true}); +React.createElement("foo", {"class-id": "1"}); +React.createElement("foo", {"class": "1"}); diff --git a/tests/baselines/reference/keywordInJsxIdentifier.symbols b/tests/baselines/reference/keywordInJsxIdentifier.symbols index 6617a640dca..874d7801a7f 100644 --- a/tests/baselines/reference/keywordInJsxIdentifier.symbols +++ b/tests/baselines/reference/keywordInJsxIdentifier.symbols @@ -3,6 +3,15 @@ declare var React: any; >React : Symbol(React, Decl(keywordInJsxIdentifier.tsx, 1, 11)) - +; >class-id : Symbol(unknown) +; +>class : Symbol(unknown) + +; +>class-id : Symbol(unknown) + +; +>class : Symbol(unknown) + diff --git a/tests/baselines/reference/keywordInJsxIdentifier.types b/tests/baselines/reference/keywordInJsxIdentifier.types index 888d027fddb..745fa5998b5 100644 --- a/tests/baselines/reference/keywordInJsxIdentifier.types +++ b/tests/baselines/reference/keywordInJsxIdentifier.types @@ -3,8 +3,23 @@ declare var React: any; >React : any - +; > : any >foo : any >class-id : any +; +> : any +>foo : any +>class : any + +; +> : any +>foo : any +>class-id : any + +; +> : any +>foo : any +>class : any + diff --git a/tests/cases/compiler/keywordInJsxIdentifier.tsx b/tests/cases/compiler/keywordInJsxIdentifier.tsx index 8c09c90b170..ce858edae5d 100644 --- a/tests/cases/compiler/keywordInJsxIdentifier.tsx +++ b/tests/cases/compiler/keywordInJsxIdentifier.tsx @@ -1,4 +1,7 @@ //@jsx: react declare var React: any; - \ No newline at end of file +; +; +; +; From c3323c9a6939d1ba754db50829886472a468b519 Mon Sep 17 00:00:00 2001 From: vilicvane Date: Fri, 11 Sep 2015 03:06:13 +0800 Subject: [PATCH 35/37] Keep parentheses for all numeric literals with property access expression --- src/compiler/emitter.ts | 13 +---- .../reference/castExpressionParentheses.js | 28 +++++++---- .../castExpressionParentheses.symbols | 20 +++++--- .../reference/castExpressionParentheses.types | 50 +++++++++++++------ .../castExpressionParentheses_ES6.js | 11 ---- .../castExpressionParentheses_ES6.symbols | 7 --- .../castExpressionParentheses_ES6.types | 11 ---- .../compiler/castExpressionParentheses.ts | 16 +++--- .../compiler/castExpressionParentheses_ES6.ts | 5 -- 9 files changed, 75 insertions(+), 86 deletions(-) delete mode 100644 tests/baselines/reference/castExpressionParentheses_ES6.js delete mode 100644 tests/baselines/reference/castExpressionParentheses_ES6.symbols delete mode 100644 tests/baselines/reference/castExpressionParentheses_ES6.types delete mode 100644 tests/cases/compiler/castExpressionParentheses_ES6.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8fcd13c3ada..85607fd73d3 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -897,17 +897,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(text); } } - - function getEmittingNumericLiteralText(node: LiteralExpression): string { - let text = getLiteralText(node); - - if (languageVersion < ScriptTarget.ES6 && isBinaryOrOctalIntegerLiteral(node, text)) { - return node.text; - } - else { - return text; - } - } function getLiteralText(node: LiteralExpression) { // Any template literal or string literal with an extended escape @@ -2364,7 +2353,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi operand.kind !== SyntaxKind.NewExpression && !(operand.kind === SyntaxKind.CallExpression && node.parent.kind === SyntaxKind.NewExpression) && !(operand.kind === SyntaxKind.FunctionExpression && node.parent.kind === SyntaxKind.CallExpression) && - !(operand.kind === SyntaxKind.NumericLiteral && node.parent.kind === SyntaxKind.PropertyAccessExpression && !/^0[box]|[e.]/i.test(getEmittingNumericLiteralText(operand)))) { + !(operand.kind === SyntaxKind.NumericLiteral && node.parent.kind === SyntaxKind.PropertyAccessExpression)) { emit(operand); return; } diff --git a/tests/baselines/reference/castExpressionParentheses.js b/tests/baselines/reference/castExpressionParentheses.js index 22316df7f43..b4754d0ad41 100644 --- a/tests/baselines/reference/castExpressionParentheses.js +++ b/tests/baselines/reference/castExpressionParentheses.js @@ -8,10 +8,10 @@ declare var a; ("string"); (23.0); (1); -(1.).foo; -(1.0).foo; -(12e+34).foo; -(0xff).foo; +(1.); +(1.0); +(12e+34); +(0xff); (/regexp/g); (false); (true); @@ -28,8 +28,12 @@ declare var a; declare var A; // should keep the parentheses in emit -(1).foo; -((1.0)).foo; +(1).foo; +(1.).foo; +(1.0).foo; +(12e+34).foo; +(0xff).foo; +((1.0)); (new A).foo; (typeof A).x; (-A).x; @@ -54,10 +58,10 @@ new (A()); "string"; 23.0; 1; -1..foo; -1.0.foo; -12e+34.foo; -0xff.foo; +1.; +1.0; +12e+34; +0xff; /regexp/g; false; true; @@ -72,7 +76,11 @@ a.b["0"]; a().x; // should keep the parentheses in emit (1).foo; +(1.).foo; (1.0).foo; +(12e+34).foo; +(0xff).foo; +(1.0); (new A).foo; (typeof A).x; (-A).x; diff --git a/tests/baselines/reference/castExpressionParentheses.symbols b/tests/baselines/reference/castExpressionParentheses.symbols index a7f51f9f2cb..ef31ee0f226 100644 --- a/tests/baselines/reference/castExpressionParentheses.symbols +++ b/tests/baselines/reference/castExpressionParentheses.symbols @@ -11,10 +11,10 @@ declare var a; ("string"); (23.0); (1); -(1.).foo; -(1.0).foo; -(12e+34).foo; -(0xff).foo; +(1.); +(1.0); +(12e+34); +(0xff); (/regexp/g); (false); (true); @@ -41,8 +41,12 @@ declare var A; >A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) // should keep the parentheses in emit -(1).foo; -((1.0)).foo; +(1).foo; +(1.).foo; +(1.0).foo; +(12e+34).foo; +(0xff).foo; +((1.0)); (new A).foo; >A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) @@ -56,10 +60,10 @@ new (A()); >A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) (()=> {})(); ->Tany : Symbol(Tany, Decl(castExpressionParentheses.ts, 35, 2)) +>Tany : Symbol(Tany, Decl(castExpressionParentheses.ts, 39, 2)) (function foo() { })(); ->foo : Symbol(foo, Decl(castExpressionParentheses.ts, 36, 6)) +>foo : Symbol(foo, Decl(castExpressionParentheses.ts, 40, 6)) (-A).x; >A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) diff --git a/tests/baselines/reference/castExpressionParentheses.types b/tests/baselines/reference/castExpressionParentheses.types index 1d203958555..cdfbf4f7db2 100644 --- a/tests/baselines/reference/castExpressionParentheses.types +++ b/tests/baselines/reference/castExpressionParentheses.types @@ -33,33 +33,25 @@ declare var a; >1 : any >1 : number -(1.).foo; ->(1.).foo : any +(1.); >(1.) : any >1. : any >1. : number ->foo : any -(1.0).foo; ->(1.0).foo : any +(1.0); >(1.0) : any >1.0 : any >1.0 : number ->foo : any -(12e+34).foo; ->(12e+34).foo : any +(12e+34); >(12e+34) : any >12e+34 : any >12e+34 : number ->foo : any -(0xff).foo; ->(0xff).foo : any +(0xff); >(0xff) : any >0xff : any >0xff : number ->foo : any (/regexp/g); >(/regexp/g) : any @@ -137,20 +129,46 @@ declare var A; >A : any // should keep the parentheses in emit -(1).foo; +(1).foo; >(1).foo : any >(1) : any >1 : any >1 : number >foo : any -((1.0)).foo; ->((1.0)).foo : any +(1.).foo; +>(1.).foo : any +>(1.) : any +>1. : any +>1. : number +>foo : any + +(1.0).foo; +>(1.0).foo : any +>(1.0) : any +>1.0 : any +>1.0 : number +>foo : any + +(12e+34).foo; +>(12e+34).foo : any +>(12e+34) : any +>12e+34 : any +>12e+34 : number +>foo : any + +(0xff).foo; +>(0xff).foo : any +>(0xff) : any +>0xff : any +>0xff : number +>foo : any + +((1.0)); >((1.0)) : any >(1.0) : any >(1.0) : number >1.0 : number ->foo : any (new A).foo; >(new A).foo : any diff --git a/tests/baselines/reference/castExpressionParentheses_ES6.js b/tests/baselines/reference/castExpressionParentheses_ES6.js deleted file mode 100644 index 6ffbe7c2885..00000000000 --- a/tests/baselines/reference/castExpressionParentheses_ES6.js +++ /dev/null @@ -1,11 +0,0 @@ -//// [castExpressionParentheses_ES6.ts] - -// parentheses should be omitted -// numeric literal -(0o123).foo; - - -//// [castExpressionParentheses_ES6.js] -// parentheses should be omitted -// numeric literal -0o123.foo; diff --git a/tests/baselines/reference/castExpressionParentheses_ES6.symbols b/tests/baselines/reference/castExpressionParentheses_ES6.symbols deleted file mode 100644 index c1b31043cb1..00000000000 --- a/tests/baselines/reference/castExpressionParentheses_ES6.symbols +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/compiler/castExpressionParentheses_ES6.ts === - -No type information for this code.// parentheses should be omitted -No type information for this code.// numeric literal -No type information for this code.(0o123).foo; -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/castExpressionParentheses_ES6.types b/tests/baselines/reference/castExpressionParentheses_ES6.types deleted file mode 100644 index 41f968a834f..00000000000 --- a/tests/baselines/reference/castExpressionParentheses_ES6.types +++ /dev/null @@ -1,11 +0,0 @@ -=== tests/cases/compiler/castExpressionParentheses_ES6.ts === - -// parentheses should be omitted -// numeric literal -(0o123).foo; ->(0o123).foo : any ->(0o123) : any ->0o123 : any ->0o123 : number ->foo : any - diff --git a/tests/cases/compiler/castExpressionParentheses.ts b/tests/cases/compiler/castExpressionParentheses.ts index e6ed4d82785..06908f39936 100644 --- a/tests/cases/compiler/castExpressionParentheses.ts +++ b/tests/cases/compiler/castExpressionParentheses.ts @@ -7,10 +7,10 @@ declare var a; ("string"); (23.0); (1); -(1.).foo; -(1.0).foo; -(12e+34).foo; -(0xff).foo; +(1.); +(1.0); +(12e+34); +(0xff); (/regexp/g); (false); (true); @@ -27,8 +27,12 @@ declare var a; declare var A; // should keep the parentheses in emit -(1).foo; -((1.0)).foo; +(1).foo; +(1.).foo; +(1.0).foo; +(12e+34).foo; +(0xff).foo; +((1.0)); (new A).foo; (typeof A).x; (-A).x; diff --git a/tests/cases/compiler/castExpressionParentheses_ES6.ts b/tests/cases/compiler/castExpressionParentheses_ES6.ts deleted file mode 100644 index 03d6d8ae5fa..00000000000 --- a/tests/cases/compiler/castExpressionParentheses_ES6.ts +++ /dev/null @@ -1,5 +0,0 @@ -// @target: es6 - -// parentheses should be omitted -// numeric literal -(0o123).foo; From 40f05b7f7dd4090e9123b68900b5c9310c659fb5 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 10 Sep 2015 13:05:51 -0700 Subject: [PATCH 36/37] Address CR --- src/compiler/emitter.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6e4bdff069b..ec14100e197 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -190,6 +190,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi /** Sourcemap data that will get encoded */ let sourceMapData: SourceMapData; + /** If removeComments is true, no leading-comments needed to be emitted **/ + let emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos: number) { } : emitLeadingCommentsOfPositionWorker; + if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { initializeEmitterWithSourceMaps(); } @@ -6986,9 +6989,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function isPinnedComments(comment: CommentRange) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; - } + return currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk && + currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; } /** @@ -6996,7 +6998,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi * * @return true if the comment is a triple-slash comment else false **/ - function isTripleSlashComments(comment: CommentRange) { + function isTripleSlashComment(comment: CommentRange) { // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text // so that we don't end up computing comment string and doing match for all // comments if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && @@ -7065,7 +7067,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // interface F {} // The first /// will NOT be removed while the second one will be removed eventhough both node will not be emitted if (node.pos === 0) { - leadingComments = filter(getLeadingCommentsToEmit(node), isTripleSlashComments); + leadingComments = filter(getLeadingCommentsToEmit(node), isTripleSlashComment); } } @@ -7103,7 +7105,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ true, newLine, writeComment); } - function emitLeadingCommentsOfPosition(pos: number) { + function emitLeadingCommentsOfPositionWorker(pos: number) { if (compilerOptions.removeComments) { return; } From 32ac25d48fc1d79d6e0686a73717d13957b6ea41 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 10 Sep 2015 16:12:41 -0700 Subject: [PATCH 37/37] rename .settings to .vscode --- {.settings => .vscode}/tasks.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {.settings => .vscode}/tasks.json (100%) diff --git a/.settings/tasks.json b/.vscode/tasks.json similarity index 100% rename from .settings/tasks.json rename to .vscode/tasks.json