From 6fd267c574057c42571c2ae798506db79f8079ed Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Jul 2015 18:15:30 -0700 Subject: [PATCH 01/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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 e78478b76738326fa1b6927826496c165e927e25 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 1 Sep 2015 12:34:29 -0700 Subject: [PATCH 22/56] More flexible rules when destructuring have literal initializers --- src/compiler/checker.ts | 53 +++++++++++++++++++++++++++++++++-------- src/compiler/types.ts | 4 ++-- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e624eb41d86..7c4a438664f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2318,8 +2318,8 @@ namespace ts { // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, // or otherwise the type of the string index signature. type = getTypeOfPropertyOfType(parentType, name.text) || - isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, IndexKind.Number) || - getIndexTypeOfType(parentType, IndexKind.String); + isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, IndexKind.Number) || + getIndexTypeOfType(parentType, IndexKind.String); if (!type) { error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name)); return unknownType; @@ -2456,7 +2456,6 @@ namespace ts { let unionOfElements = getUnionType(elementTypes); return languageVersion >= ScriptTarget.ES6 ? createIterableType(unionOfElements) : createArrayType(unionOfElements); } - // If the pattern has at least one element, and no rest element, then it should imply a tuple type. return createTupleType(elementTypes); } @@ -6607,12 +6606,18 @@ namespace ts { } } if (isBindingPattern(declaration.name)) { - return getTypeFromBindingPattern(declaration.name); + return createImpliedType(getTypeFromBindingPattern(declaration.name)); } } return undefined; } + function createImpliedType(type: Type): Type { + var result = clone(type); + result.flags |= TypeFlags.ImpliedType; + return result; + } + function getContextualTypeForReturnExpression(node: Expression): Type { let func = getContainingFunction(node); if (func && !func.asteriskToken) { @@ -7005,9 +7010,6 @@ namespace ts { function checkArrayLiteral(node: ArrayLiteralExpression, contextualMapper?: TypeMapper): Type { let elements = node.elements; - if (!elements.length) { - return createArrayType(undefinedType); - } let hasSpreadElement = false; let elementTypes: Type[] = []; let inDestructuringPattern = isAssignmentTarget(node); @@ -7039,12 +7041,24 @@ namespace ts { hasSpreadElement = hasSpreadElement || e.kind === SyntaxKind.SpreadElementExpression; } if (!hasSpreadElement) { + if (inDestructuringPattern && elementTypes.length) { + return createImpliedType(createTupleType(elementTypes)); + } let contextualType = getContextualType(node); - if (contextualType && contextualTypeIsTupleLikeType(contextualType) || inDestructuringPattern) { - return createTupleType(elementTypes); + let contextualTupleLikeType = contextualType && contextualTypeIsTupleLikeType(contextualType) ? contextualType : undefined; + if (contextualTupleLikeType) { + if (contextualTupleLikeType.flags & TypeFlags.Tuple && contextualTupleLikeType.flags & TypeFlags.ImpliedType) { + let contextualElementTypes = (contextualTupleLikeType).elementTypes; + for (let i = elementTypes.length; i < contextualElementTypes.length; i++) { + elementTypes.push(contextualElementTypes[i]); + } + } + if (elementTypes.length) { + return createTupleType(elementTypes); + } } } - return createArrayType(getUnionType(elementTypes)); + return createArrayType(elementTypes.length ? getUnionType(elementTypes) : undefinedType) } function isNumericName(name: DeclarationName): boolean { @@ -7131,6 +7145,14 @@ namespace ts { } typeFlags |= type.flags; let prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); + // If object literal is contextually typed by the implied type of a binding pattern, and if the + // binding pattern specifies a default value for the property, make the property optional. + if (contextualType && contextualType.flags & TypeFlags.ImpliedType) { + let impliedProp = getPropertyOfType(contextualType, member.name); + if (impliedProp) { + prop.flags |= impliedProp.flags & SymbolFlags.Optional; + } + } prop.declarations = member.declarations; prop.parent = member.parent; if (member.valueDeclaration) { @@ -7157,6 +7179,17 @@ namespace ts { propertiesArray.push(member); } + // If object literal is contextually typed by the implied type of a binding pattern, augment the result + // type with those properties for which the binding pattern specifies a default value. + if (contextualType && contextualType.flags & TypeFlags.ImpliedType) { + for (let prop of getPropertiesOfType(contextualType)) { + if (prop.flags & SymbolFlags.Optional && !hasProperty(propertiesTable, prop.name)) { + propertiesTable[prop.name] = prop; + propertiesArray.push(prop); + } + } + } + let stringIndexType = getIndexType(IndexKind.String); let numberIndexType = getIndexType(IndexKind.Number); let result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 47182e39527..1313fb5b031 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1795,6 +1795,7 @@ namespace ts { /* @internal */ ContainsAnyFunctionType = 0x00800000, // Type is or contains object literal type ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6 + ImpliedType = 0x02000000, // Type implied by object binding pattern /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, @@ -1864,8 +1865,7 @@ namespace ts { } export interface TupleType extends ObjectType { - elementTypes: Type[]; // Element types - baseArrayType: TypeReference; // Array where T is best common type of element types + elementTypes: Type[]; // Element types } export interface UnionOrIntersectionType extends Type { From c436736e1e127d99f4c9213229e9d7265789ba4d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 1 Sep 2015 13:15:43 -0700 Subject: [PATCH 23/56] Adding a few comments --- src/compiler/checker.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7c4a438664f..d4e68381f7b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7041,12 +7041,16 @@ namespace ts { hasSpreadElement = hasSpreadElement || e.kind === SyntaxKind.SpreadElementExpression; } if (!hasSpreadElement) { + // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such + // that we get the same behavior for "var [x, y] = []" and "[x, y] = []". if (inDestructuringPattern && elementTypes.length) { return createImpliedType(createTupleType(elementTypes)); } let contextualType = getContextualType(node); let contextualTupleLikeType = contextualType && contextualTypeIsTupleLikeType(contextualType) ? contextualType : undefined; if (contextualTupleLikeType) { + // If array literal is contextually typed by the implied type of a binding pattern, pad the resulting + // tuple type with elements from the binding tuple type to make the lengths equal. if (contextualTupleLikeType.flags & TypeFlags.Tuple && contextualTupleLikeType.flags & TypeFlags.ImpliedType) { let contextualElementTypes = (contextualTupleLikeType).elementTypes; for (let i = elementTypes.length; i < contextualElementTypes.length; i++) { From f28e424d31cb06b141a81580122cb43495066e54 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 1 Sep 2015 13:16:54 -0700 Subject: [PATCH 24/56] Adding tests --- .../destructuringWithLiteralInitializers.js | 117 +++++++++ ...structuringWithLiteralInitializers.symbols | 150 +++++++++++ ...destructuringWithLiteralInitializers.types | 235 ++++++++++++++++++ .../destructuringWithLiteralInitializers.ts | 51 ++++ 4 files changed, 553 insertions(+) create mode 100644 tests/baselines/reference/destructuringWithLiteralInitializers.js create mode 100644 tests/baselines/reference/destructuringWithLiteralInitializers.symbols create mode 100644 tests/baselines/reference/destructuringWithLiteralInitializers.types create mode 100644 tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.js b/tests/baselines/reference/destructuringWithLiteralInitializers.js new file mode 100644 index 00000000000..c25216a55f8 --- /dev/null +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.js @@ -0,0 +1,117 @@ +//// [destructuringWithLiteralInitializers.ts] +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +f1({ x: 1, y: 1 }); + +function f2({ x, y = 0 }) { } +f2({ x: 1 }); +f2({ x: 1, y: 1 }); + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +f3({}); +f3({ x: 1 }); +f3({ y: 1 }); +f3({ x: 1, y: 1 }); + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +f4(); +f4({ x: 1, y: 1 }); + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +f5(); +f5({ x: 1 }); +f5({ x: 1, y: 1 }); + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +f6(); +f6({}); +f6({ x: 1 }); +f6({ y: 1 }); +f6({ x: 1, y: 1 }); + +// (arg: [any, any]) => void +function g1([x, y]) { } +g1([1, 1]); + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +g2([1, 1]); + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +g3(); +g3([1, 1]); + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +g4(); +g4([1, 1]); + + +//// [destructuringWithLiteralInitializers.js] +// (arg: { x: any, y: any }) => void +function f1(_a) { + var x = _a.x, y = _a.y; +} +f1({ x: 1, y: 1 }); +function f2(_a) { + var x = _a.x, _b = _a.y, y = _b === void 0 ? 0 : _b; +} +f2({ x: 1 }); +f2({ x: 1, y: 1 }); +// (arg: { x?: number, y?: number }) => void +function f3(_a) { + var _b = _a.x, x = _b === void 0 ? 0 : _b, _c = _a.y, y = _c === void 0 ? 0 : _c; +} +f3({}); +f3({ x: 1 }); +f3({ y: 1 }); +f3({ x: 1, y: 1 }); +// (arg?: { x: number, y: number }) => void +function f4(_a) { + var _b = _a === void 0 ? { x: 0, y: 0 } : _a, x = _b.x, y = _b.y; +} +f4(); +f4({ x: 1, y: 1 }); +// (arg?: { x: number, y?: number }) => void +function f5(_a) { + var _b = _a === void 0 ? { x: 0 } : _a, x = _b.x, _c = _b.y, y = _c === void 0 ? 0 : _c; +} +f5(); +f5({ x: 1 }); +f5({ x: 1, y: 1 }); +// (arg?: { x?: number, y?: number }) => void +function f6(_a) { + var _b = _a === void 0 ? {} : _a, _c = _b.x, x = _c === void 0 ? 0 : _c, _d = _b.y, y = _d === void 0 ? 0 : _d; +} +f6(); +f6({}); +f6({ x: 1 }); +f6({ y: 1 }); +f6({ x: 1, y: 1 }); +// (arg: [any, any]) => void +function g1(_a) { + var x = _a[0], y = _a[1]; +} +g1([1, 1]); +// (arg: [number, number]) => void +function g2(_a) { + var _b = _a[0], x = _b === void 0 ? 0 : _b, _c = _a[1], y = _c === void 0 ? 0 : _c; +} +g2([1, 1]); +// (arg?: [any, any]) => void +function g3(_a) { + var _b = _a === void 0 ? [] : _a, x = _b[0], y = _b[1]; +} +g3(); +g3([1, 1]); +// (arg?: [number, number]) => void +function g4(_a) { + var _b = _a === void 0 ? [0, 0] : _a, x = _b[0], y = _b[1]; +} +g4(); +g4([1, 1]); diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols new file mode 100644 index 00000000000..992a9c3ace5 --- /dev/null +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols @@ -0,0 +1,150 @@ +=== tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts === +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +>f1 : Symbol(f1, Decl(destructuringWithLiteralInitializers.ts, 0, 0)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 1, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 1, 16)) + +f1({ x: 1, y: 1 }); +>f1 : Symbol(f1, Decl(destructuringWithLiteralInitializers.ts, 0, 0)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 2, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 2, 10)) + +function f2({ x, y = 0 }) { } +>f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 4, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 4, 16)) + +f2({ x: 1 }); +>f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 5, 4)) + +f2({ x: 1, y: 1 }); +>f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 6, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 6, 10)) + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 9, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 9, 20)) + +f3({}); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) + +f3({ x: 1 }); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 11, 4)) + +f3({ y: 1 }); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 12, 4)) + +f3({ x: 1, y: 1 }); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 13, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 13, 10)) + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 16, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 16, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 16, 24)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 16, 30)) + +f4(); +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) + +f4({ x: 1, y: 1 }); +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 18, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 18, 10)) + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 21, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 21, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 21, 28)) + +f5(); +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) + +f5({ x: 1 }); +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 23, 4)) + +f5({ x: 1, y: 1 }); +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 24, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 24, 10)) + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 27, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 27, 20)) + +f6(); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) + +f6({}); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) + +f6({ x: 1 }); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 30, 4)) + +f6({ y: 1 }); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 31, 4)) + +f6({ x: 1, y: 1 }); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 32, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 32, 10)) + +// (arg: [any, any]) => void +function g1([x, y]) { } +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 32, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 35, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 35, 15)) + +g1([1, 1]); +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 32, 19)) + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 36, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 39, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 39, 19)) + +g2([1, 1]); +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 36, 11)) + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 43, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 43, 15)) + +g3(); +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) + +g3([1, 1]); +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 48, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 48, 15)) + +g4(); +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) + +g4([1, 1]); +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) + diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types new file mode 100644 index 00000000000..c0577cb9950 --- /dev/null +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -0,0 +1,235 @@ +=== tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts === +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +>f1 : ({ x, y }: { x: any; y: any; }) => void +>x : any +>y : any + +f1({ x: 1, y: 1 }); +>f1({ x: 1, y: 1 }) : void +>f1 : ({ x, y }: { x: any; y: any; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +function f2({ x, y = 0 }) { } +>f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void +>x : any +>y : number +>0 : number + +f2({ x: 1 }); +>f2({ x: 1 }) : void +>f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f2({ x: 1, y: 1 }); +>f2({ x: 1, y: 1 }) : void +>f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>x : number +>0 : number +>y : number +>0 : number + +f3({}); +>f3({}) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{} : {} + +f3({ x: 1 }); +>f3({ x: 1 }) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f3({ y: 1 }); +>f3({ y: 1 }) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{ y: 1 } : { y: number; } +>y : number +>1 : number + +f3({ x: 1, y: 1 }); +>f3({ x: 1, y: 1 }) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +>f4 : ({ x, y }?: { x: number; y: number; }) => void +>x : number +>y : number +>{ x: 0, y: 0 } : { x: number; y: number; } +>x : number +>0 : number +>y : number +>0 : number + +f4(); +>f4() : void +>f4 : ({ x, y }?: { x: number; y: number; }) => void + +f4({ x: 1, y: 1 }); +>f4({ x: 1, y: 1 }) : void +>f4 : ({ x, y }?: { x: number; y: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void +>x : number +>y : number +>0 : number +>{ x: 0 } : { x: number; y?: number; } +>x : number +>0 : number + +f5(); +>f5() : void +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void + +f5({ x: 1 }); +>f5({ x: 1 }) : void +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f5({ x: 1, y: 1 }); +>f5({ x: 1, y: 1 }) : void +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>x : number +>0 : number +>y : number +>0 : number +>{} : { x?: number; y?: number; } + +f6(); +>f6() : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void + +f6({}); +>f6({}) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{} : {} + +f6({ x: 1 }); +>f6({ x: 1 }) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f6({ y: 1 }); +>f6({ y: 1 }) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{ y: 1 } : { y: number; } +>y : number +>1 : number + +f6({ x: 1, y: 1 }); +>f6({ x: 1, y: 1 }) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg: [any, any]) => void +function g1([x, y]) { } +>g1 : ([x, y]: [any, any]) => void +>x : any +>y : any + +g1([1, 1]); +>g1([1, 1]) : void +>g1 : ([x, y]: [any, any]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +>g2 : ([x = 0, y = 0]: [number, number]) => void +>x : number +>0 : number +>y : number +>0 : number + +g2([1, 1]); +>g2([1, 1]) : void +>g2 : ([x = 0, y = 0]: [number, number]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +>g3 : ([x, y]?: [any, any]) => void +>x : any +>y : any +>[] : [any, any] + +g3(); +>g3() : void +>g3 : ([x, y]?: [any, any]) => void + +g3([1, 1]); +>g3([1, 1]) : void +>g3 : ([x, y]?: [any, any]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +>g4 : ([x, y]?: [number, number]) => void +>x : number +>y : number +>[0, 0] : [number, number] +>0 : number +>0 : number + +g4(); +>g4() : void +>g4 : ([x, y]?: [number, number]) => void + +g4([1, 1]); +>g4([1, 1]) : void +>g4 : ([x, y]?: [number, number]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + diff --git a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts new file mode 100644 index 00000000000..8f6b77d95c9 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts @@ -0,0 +1,51 @@ +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +f1({ x: 1, y: 1 }); + +function f2({ x, y = 0 }) { } +f2({ x: 1 }); +f2({ x: 1, y: 1 }); + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +f3({}); +f3({ x: 1 }); +f3({ y: 1 }); +f3({ x: 1, y: 1 }); + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +f4(); +f4({ x: 1, y: 1 }); + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +f5(); +f5({ x: 1 }); +f5({ x: 1, y: 1 }); + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +f6(); +f6({}); +f6({ x: 1 }); +f6({ y: 1 }); +f6({ x: 1, y: 1 }); + +// (arg: [any, any]) => void +function g1([x, y]) { } +g1([1, 1]); + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +g2([1, 1]); + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +g3(); +g3([1, 1]); + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +g4(); +g4([1, 1]); From 66e3abaa12c8fab57d99c77807341f553907a7f5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 1 Sep 2015 13:17:02 -0700 Subject: [PATCH 25/56] Accepting new baselines --- .../reference/arrowFunctionExpressions.types | 6 +++--- .../reference/declarationEmitDestructuring2.js | 4 ++-- ...declarationEmitDestructuringArrayPattern2.types | 2 +- .../declarationsAndAssignments.errors.txt | 14 ++++---------- ...uringArrayBindingPatternAndAssignment1ES5.types | 2 +- ...uringArrayBindingPatternAndAssignment1ES6.types | 2 +- ...ingArrayBindingPatternAndAssignment2.errors.txt | 8 +------- ...ringObjectBindingPatternAndAssignment1ES5.types | 2 +- ...ringObjectBindingPatternAndAssignment1ES6.types | 2 +- .../destructuringVariableDeclaration1ES5.types | 2 +- .../destructuringVariableDeclaration1ES6.types | 2 +- .../baselines/reference/downlevelLetConst12.types | 4 ++-- .../baselines/reference/emitArrowFunctionES6.types | 6 +++--- .../reference/nonIterableRestElement1.types | 2 +- .../reference/nonIterableRestElement2.types | 2 +- 15 files changed, 24 insertions(+), 36 deletions(-) diff --git a/tests/baselines/reference/arrowFunctionExpressions.types b/tests/baselines/reference/arrowFunctionExpressions.types index fc9fdb8a3bd..6ac405e6d7e 100644 --- a/tests/baselines/reference/arrowFunctionExpressions.types +++ b/tests/baselines/reference/arrowFunctionExpressions.types @@ -100,12 +100,12 @@ var p8 = ({ a = 1 }) => { }; >1 : number var p9 = ({ a: { b = 1 } = { b: 1 } }) => { }; ->p9 : ({ a: { b = 1 } = { b: 1 } }: { a?: { b: number; }; }) => void ->({ a: { b = 1 } = { b: 1 } }) => { } : ({ a: { b = 1 } = { b: 1 } }: { a?: { b: number; }; }) => void +>p9 : ({ a: { b = 1 } = { b: 1 } }: { a?: { b?: number; }; }) => void +>({ a: { b = 1 } = { b: 1 } }) => { } : ({ a: { b = 1 } = { b: 1 } }: { a?: { b?: number; }; }) => void >a : any >b : number >1 : number ->{ b: 1 } : { b: number; } +>{ b: 1 } : { b?: number; } >b : number >1 : number diff --git a/tests/baselines/reference/declarationEmitDestructuring2.js b/tests/baselines/reference/declarationEmitDestructuring2.js index eeabbf1ff37..09980c5c9dd 100644 --- a/tests/baselines/reference/declarationEmitDestructuring2.js +++ b/tests/baselines/reference/declarationEmitDestructuring2.js @@ -21,8 +21,8 @@ function h1(_a) { //// [declarationEmitDestructuring2.d.ts] declare function f({x, y: [a, b, c, d]}?: { - x: number; - y: [number, number, number, number]; + x?: number; + y?: [number, number, number, number]; }): void; declare function g([a, b, c, d]?: [number, number, number, number]): void; declare function h([a, [b], [[c]], {x, y: [a, b, c], z: {a1, b1}}]: [any, [any], [[any]], { diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types index eb028aacff4..5820449cde9 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types @@ -23,7 +23,7 @@ var [a11, b11, c11] = []; >a11 : any >b11 : any >c11 : any ->[] : undefined[] +>[] : [any, any, any] var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; >a2 : number diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 828083e7687..3e0666a96c0 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,7 +1,5 @@ -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2493: Tuple type '[number, string]' with length '2' cannot be assigned to tuple with length '3'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(6,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'any', but here has type 'number'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(56,17): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,13): error TS2493: Tuple type '[number]' with length '1' cannot be assigned to tuple with length '3'. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,16): error TS2493: Tuple type '[number]' with length '1' cannot be assigned to tuple with length '3'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2459: Type '{}' has no property 'a' and no string index signature. @@ -18,15 +16,15 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (13 errors) ==== +==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (11 errors) ==== function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; var [x, y] = [1, "hello"]; var [x, y, z] = [1, "hello"]; // Error - ~ -!!! error TS2493: Tuple type '[number, string]' with length '2' cannot be assigned to tuple with length '3'. var [,, z] = [0, 1, 2]; + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'any', but here has type 'number'. var x: number; var y: string; } @@ -86,10 +84,6 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f8() { var [a, b, c] = []; // Ok, [] is an array var [d, e, f] = [1]; // Error, [1] is a tuple - ~ -!!! error TS2493: Tuple type '[number]' with length '1' cannot be assigned to tuple with length '3'. - ~ -!!! error TS2493: Tuple type '[number]' with length '1' cannot be assigned to tuple with length '3'. } function f9() { diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index adff61e407c..9325fbf6b2d 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -93,7 +93,7 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : undefined[] +>[] : [any] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index 0a9e75a8aed..aaa56cde3bc 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -94,7 +94,7 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : undefined[] +>[] : [any] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt index a2e5cb7e17c..5244dd55ec6 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -1,5 +1,3 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2461: Type 'undefined' is not an array type. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. Types of property '1' are incompatible. @@ -13,14 +11,10 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(34,5): error TS2461: Type 'F' is not an array type. -==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (8 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (6 errors) ==== // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, // S is the type Any, or var [[a0], [[a1]]] = [] // Error - ~~~~ -!!! error TS2461: Type 'undefined' is not an array type. - ~~~~~~ -!!! error TS2461: Type 'undefined' is not an array type. var [[a2], [[a3]]] = undefined // Error ~~~~~~~~~~~~~~ !!! error TS2461: Type 'undefined' is not an array type. diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types index f44adab359f..476b5bee0cc 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types @@ -27,7 +27,7 @@ var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; >{ b21: "string" } : { b21: string; } >b21 : string >"string" : string ->{ b2: { b21: "world" } } : { b2: { b21: string; }; } +>{ b2: { b21: "world" } } : { b2?: { b21: string; }; } >b2 : { b21: string; } >{ b21: "world" } : { b21: string; } >b21 : string diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types index 47d4474b63e..7a7f631eddf 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types @@ -27,7 +27,7 @@ var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; >{ b21: "string" } : { b21: string; } >b21 : string >"string" : string ->{ b2: { b21: "world" } } : { b2: { b21: string; }; } +>{ b2: { b21: "world" } } : { b2?: { b21: string; }; } >b2 : { b21: string; } >{ b21: "world" } : { b21: string; } >b21 : string diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index a0630fee995..620ad90d414 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -31,7 +31,7 @@ var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; >{ b11: "string" } : { b11: string; } >b11 : string >"string" : string ->{ b1: { b11: "world" } } : { b1: { b11: string; }; } +>{ b1: { b11: "world" } } : { b1?: { b11: string; }; } >b1 : { b11: string; } >{ b11: "world" } : { b11: string; } >b11 : string diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index f9faf519b0a..a3004f87c82 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -31,7 +31,7 @@ var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; >{ b11: "string" } : { b11: string; } >b11 : string >"string" : string ->{ b1: { b11: "world" } } : { b1: { b11: string; }; } +>{ b1: { b11: "world" } } : { b1?: { b11: string; }; } >b1 : { b11: string; } >{ b11: "world" } : { b11: string; } >b11 : string diff --git a/tests/baselines/reference/downlevelLetConst12.types b/tests/baselines/reference/downlevelLetConst12.types index 51d3b8eb086..85002abbe5e 100644 --- a/tests/baselines/reference/downlevelLetConst12.types +++ b/tests/baselines/reference/downlevelLetConst12.types @@ -13,7 +13,7 @@ const bar = 1; let [baz] = []; >baz : any ->[] : undefined[] +>[] : [any] let {a: baz2} = { a: 1 }; >a : any @@ -24,7 +24,7 @@ let {a: baz2} = { a: 1 }; const [baz3] = [] >baz3 : any ->[] : undefined[] +>[] : [any] const {a: baz4} = { a: 1 }; >a : any diff --git a/tests/baselines/reference/emitArrowFunctionES6.types b/tests/baselines/reference/emitArrowFunctionES6.types index e2ad176fd7d..cc48cecd96a 100644 --- a/tests/baselines/reference/emitArrowFunctionES6.types +++ b/tests/baselines/reference/emitArrowFunctionES6.types @@ -87,12 +87,12 @@ var p8 = ({ a = 1 }) => { }; >1 : number var p9 = ({ a: { b = 1 } = { b: 1 } }) => { }; ->p9 : ({ a: { b = 1 } = { b: 1 } }: { a?: { b: number; }; }) => void ->({ a: { b = 1 } = { b: 1 } }) => { } : ({ a: { b = 1 } = { b: 1 } }: { a?: { b: number; }; }) => void +>p9 : ({ a: { b = 1 } = { b: 1 } }: { a?: { b?: number; }; }) => void +>({ a: { b = 1 } = { b: 1 } }) => { } : ({ a: { b = 1 } = { b: 1 } }: { a?: { b?: number; }; }) => void >a : any >b : number >1 : number ->{ b: 1 } : { b: number; } +>{ b: 1 } : { b?: number; } >b : number >1 : number diff --git a/tests/baselines/reference/nonIterableRestElement1.types b/tests/baselines/reference/nonIterableRestElement1.types index 4973b67d4ae..a15fe5afd38 100644 --- a/tests/baselines/reference/nonIterableRestElement1.types +++ b/tests/baselines/reference/nonIterableRestElement1.types @@ -5,7 +5,7 @@ var c = {}; [...c] = ["", 0]; >[...c] = ["", 0] : (string | number)[] ->[...c] : {}[] +>[...c] : undefined[] >...c : any >c : {} >["", 0] : (string | number)[] diff --git a/tests/baselines/reference/nonIterableRestElement2.types b/tests/baselines/reference/nonIterableRestElement2.types index e6d84d5297e..c39a592d2e6 100644 --- a/tests/baselines/reference/nonIterableRestElement2.types +++ b/tests/baselines/reference/nonIterableRestElement2.types @@ -5,7 +5,7 @@ var c = {}; [...c] = ["", 0]; >[...c] = ["", 0] : (string | number)[] ->[...c] : {}[] +>[...c] : undefined[] >...c : any >c : {} >["", 0] : (string | number)[] From 856f2d895c4f18f1b7c89f4248622788e8c85fd3 Mon Sep 17 00:00:00 2001 From: vilicvane Date: Fri, 4 Sep 2015 21:47:28 +0800 Subject: [PATCH 26/56] 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 27/56] 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 28/56] 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 dc8ad6eb5e34980fca18de037d65f2f1924e444e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 13:17:33 -0700 Subject: [PATCH 29/56] Store binding pattern in contextual type --- src/compiler/checker.ts | 86 ++++++++++++++++++++++------------------- src/compiler/types.ts | 10 +++-- 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d4e68381f7b..e08d30ca9b9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2406,7 +2406,7 @@ namespace ts { // If the declaration specifies a binding pattern, use the type implied by the binding pattern if (isBindingPattern(declaration.name)) { - return getTypeFromBindingPattern(declaration.name); + return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ false); } // No type specified and nothing can be inferred @@ -2421,13 +2421,13 @@ namespace ts { return getWidenedType(checkExpressionCached(element.initializer)); } if (isBindingPattern(element.name)) { - return getTypeFromBindingPattern(element.name); + return getTypeFromBindingPattern(element.name, /*includePatternInType*/ false); } return anyType; } // Return the type implied by an object binding pattern - function getTypeFromObjectBindingPattern(pattern: BindingPattern): Type { + function getTypeFromObjectBindingPattern(pattern: BindingPattern, includePatternInType: boolean): Type { let members: SymbolTable = {}; forEach(pattern.elements, e => { let flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0); @@ -2436,28 +2436,27 @@ namespace ts { symbol.type = getTypeFromBindingElement(e); members[symbol.name] = symbol; }); - return createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined); + let result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined); + if (includePatternInType) { + result.pattern = pattern; + } + return result; } // Return the type implied by an array binding pattern - function getTypeFromArrayBindingPattern(pattern: BindingPattern): Type { - let hasSpreadElement: boolean = false; - let elementTypes: Type[] = []; - forEach(pattern.elements, e => { - elementTypes.push(e.kind === SyntaxKind.OmittedExpression || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e)); - if (e.dotDotDotToken) { - hasSpreadElement = true; - } - }); - if (!elementTypes.length) { + function getTypeFromArrayBindingPattern(pattern: BindingPattern, includePatternInType: boolean): Type { + let elements = pattern.elements; + if (elements.length === 0 || elements[elements.length - 1].dotDotDotToken) { return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType; } - else if (hasSpreadElement) { - let unionOfElements = getUnionType(elementTypes); - return languageVersion >= ScriptTarget.ES6 ? createIterableType(unionOfElements) : createArrayType(unionOfElements); - } // If the pattern has at least one element, and no rest element, then it should imply a tuple type. - return createTupleType(elementTypes); + let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e)); + let result = createTupleType(elementTypes); + if (includePatternInType) { + result = clone(result); + result.pattern = pattern; + } + return result; } // Return the type implied by a binding pattern. This is the type implied purely by the binding pattern itself @@ -2467,10 +2466,10 @@ namespace ts { // used as the contextual type of an initializer associated with the binding pattern. Also, for a destructuring // parameter with no type annotation or initializer, the type implied by the binding pattern becomes the type of // the parameter. - function getTypeFromBindingPattern(pattern: BindingPattern): Type { + function getTypeFromBindingPattern(pattern: BindingPattern, includePatternInType?: boolean): Type { return pattern.kind === SyntaxKind.ObjectBindingPattern - ? getTypeFromObjectBindingPattern(pattern) - : getTypeFromArrayBindingPattern(pattern); + ? getTypeFromObjectBindingPattern(pattern, includePatternInType) + : getTypeFromArrayBindingPattern(pattern, includePatternInType); } // Return the type associated with a variable, parameter, or property declaration. In the simple case this is the type @@ -6606,18 +6605,12 @@ namespace ts { } } if (isBindingPattern(declaration.name)) { - return createImpliedType(getTypeFromBindingPattern(declaration.name)); + return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true); } } return undefined; } - function createImpliedType(type: Type): Type { - var result = clone(type); - result.flags |= TypeFlags.ImpliedType; - return result; - } - function getContextualTypeForReturnExpression(node: Expression): Type { let func = getContainingFunction(node); if (func && !func.asteriskToken) { @@ -7044,17 +7037,28 @@ namespace ts { // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such // that we get the same behavior for "var [x, y] = []" and "[x, y] = []". if (inDestructuringPattern && elementTypes.length) { - return createImpliedType(createTupleType(elementTypes)); + let type = clone(createTupleType(elementTypes)); + type.pattern = node; + return type; } let contextualType = getContextualType(node); - let contextualTupleLikeType = contextualType && contextualTypeIsTupleLikeType(contextualType) ? contextualType : undefined; - if (contextualTupleLikeType) { - // If array literal is contextually typed by the implied type of a binding pattern, pad the resulting - // tuple type with elements from the binding tuple type to make the lengths equal. - if (contextualTupleLikeType.flags & TypeFlags.Tuple && contextualTupleLikeType.flags & TypeFlags.ImpliedType) { - let contextualElementTypes = (contextualTupleLikeType).elementTypes; - for (let i = elementTypes.length; i < contextualElementTypes.length; i++) { - elementTypes.push(contextualElementTypes[i]); + if (contextualType && contextualTypeIsTupleLikeType(contextualType)) { + let pattern = contextualType.pattern; + // If array literal is contextually typed by a binding pattern or an assignment pattern, + // pad the resulting tuple type to make the lengths equal. + if (pattern && pattern.kind === SyntaxKind.ArrayBindingPattern) { + let bindingElements = (pattern).elements; + for (let i = elementTypes.length; i < bindingElements.length; i++) { + let hasDefaultValue = bindingElements[i].initializer; + elementTypes.push(hasDefaultValue ? (contextualType).elementTypes[i] : undefinedType); + } + } + else if (pattern && pattern.kind === SyntaxKind.ArrayLiteralExpression) { + let assignmentElements = (pattern).elements; + for (let i = elementTypes.length; i < assignmentElements.length; i++) { + let hasDefaultValue = assignmentElements[i].kind === SyntaxKind.BinaryExpression && + (assignmentElements[i]).operatorToken.kind === SyntaxKind.EqualsToken; + elementTypes.push(hasDefaultValue ? (contextualType).elementTypes[i] : undefinedType); } } if (elementTypes.length) { @@ -7129,6 +7133,8 @@ namespace ts { let propertiesTable: SymbolTable = {}; let propertiesArray: Symbol[] = []; let contextualType = getContextualType(node); + let contextualTypeHasPattern = contextualType && contextualType.pattern && + contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern; let typeFlags: TypeFlags = 0; for (let memberDecl of node.properties) { @@ -7151,7 +7157,7 @@ namespace ts { let prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); // If object literal is contextually typed by the implied type of a binding pattern, and if the // binding pattern specifies a default value for the property, make the property optional. - if (contextualType && contextualType.flags & TypeFlags.ImpliedType) { + if (contextualTypeHasPattern) { let impliedProp = getPropertyOfType(contextualType, member.name); if (impliedProp) { prop.flags |= impliedProp.flags & SymbolFlags.Optional; @@ -7185,7 +7191,7 @@ namespace ts { // If object literal is contextually typed by the implied type of a binding pattern, augment the result // type with those properties for which the binding pattern specifies a default value. - if (contextualType && contextualType.flags & TypeFlags.ImpliedType) { + if (contextualTypeHasPattern) { for (let prop of getPropertiesOfType(contextualType)) { if (prop.flags & SymbolFlags.Optional && !hasProperty(propertiesTable, prop.name)) { propertiesTable[prop.name] = prop; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1313fb5b031..d23a42e753a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1795,7 +1795,6 @@ namespace ts { /* @internal */ ContainsAnyFunctionType = 0x00800000, // Type is or contains object literal type ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6 - ImpliedType = 0x02000000, // Type implied by object binding pattern /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, @@ -1812,11 +1811,14 @@ namespace ts { PropagatingFlags = ContainsUndefinedOrNull | ContainsObjectLiteral | ContainsAnyFunctionType } + export type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression; + // Properties common to all types export interface Type { - flags: TypeFlags; // Flags - /* @internal */ id: number; // Unique ID - symbol?: Symbol; // Symbol associated with type (if any) + flags: TypeFlags; // Flags + /* @internal */ id: number; // Unique ID + symbol?: Symbol; // Symbol associated with type (if any) + pattern?: DestructuringPattern; // Destructuring pattern represented by type (if any) } /* @internal */ From e40b86f1958be0e70ddc769bbf3e1e0c822a3b51 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 13:19:06 -0700 Subject: [PATCH 30/56] Accepting new baselines --- .../declarationEmitDestructuringArrayPattern2.types | 2 +- ...estructuringArrayBindingPatternAndAssignment1ES5.types | 2 +- ...estructuringArrayBindingPatternAndAssignment1ES6.types | 2 +- ...tructuringArrayBindingPatternAndAssignment2.errors.txt | 8 +++++++- .../reference/destructuringWithLiteralInitializers.types | 2 +- tests/baselines/reference/downlevelLetConst12.types | 4 ++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types index 5820449cde9..57acfe1dde1 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types @@ -23,7 +23,7 @@ var [a11, b11, c11] = []; >a11 : any >b11 : any >c11 : any ->[] : [any, any, any] +>[] : [undefined, undefined, undefined] var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; >a2 : number diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index 9325fbf6b2d..3af7b65c625 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -93,7 +93,7 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : [any] +>[] : [undefined] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index aaa56cde3bc..cded5cdec8e 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -94,7 +94,7 @@ var [c0, c1] = [...temp]; var [c2] = []; >c2 : any ->[] : [any] +>[] : [undefined] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt index 5244dd55ec6..a2e5cb7e17c 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -1,3 +1,5 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. Types of property '1' are incompatible. @@ -11,10 +13,14 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(34,5): error TS2461: Type 'F' is not an array type. -==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (6 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (8 errors) ==== // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, // S is the type Any, or var [[a0], [[a1]]] = [] // Error + ~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + ~~~~~~ +!!! error TS2461: Type 'undefined' is not an array type. var [[a2], [[a3]]] = undefined // Error ~~~~~~~~~~~~~~ !!! error TS2461: Type 'undefined' is not an array type. diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types index c0577cb9950..cbb1e343bf4 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.types +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -200,7 +200,7 @@ function g3([x, y] = []) { } >g3 : ([x, y]?: [any, any]) => void >x : any >y : any ->[] : [any, any] +>[] : [undefined, undefined] g3(); >g3() : void diff --git a/tests/baselines/reference/downlevelLetConst12.types b/tests/baselines/reference/downlevelLetConst12.types index 85002abbe5e..a6146b55dd7 100644 --- a/tests/baselines/reference/downlevelLetConst12.types +++ b/tests/baselines/reference/downlevelLetConst12.types @@ -13,7 +13,7 @@ const bar = 1; let [baz] = []; >baz : any ->[] : [any] +>[] : [undefined] let {a: baz2} = { a: 1 }; >a : any @@ -24,7 +24,7 @@ let {a: baz2} = { a: 1 }; const [baz3] = [] >baz3 : any ->[] : [any] +>[] : [undefined] const {a: baz4} = { a: 1 }; >a : any From bb8179766a46a12bba508f6603eb1c1c1b0320d0 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 15:42:58 -0700 Subject: [PATCH 31/56] Check for excess properties --- src/compiler/checker.ts | 49 +++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e08d30ca9b9..6f617d69798 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7001,6 +7001,11 @@ namespace ts { return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, /*allowStringInput*/ false); } + function hasDefaultValue(node: BindingElement | Expression): boolean { + return (node.kind === SyntaxKind.BindingElement && !!(node).initializer) || + (node.kind === SyntaxKind.BinaryExpression && (node).operatorToken.kind === SyntaxKind.EqualsToken); + } + function checkArrayLiteral(node: ArrayLiteralExpression, contextualMapper?: TypeMapper): Type { let elements = node.elements; let hasSpreadElement = false; @@ -7044,21 +7049,12 @@ namespace ts { let contextualType = getContextualType(node); if (contextualType && contextualTypeIsTupleLikeType(contextualType)) { let pattern = contextualType.pattern; - // If array literal is contextually typed by a binding pattern or an assignment pattern, - // pad the resulting tuple type to make the lengths equal. - if (pattern && pattern.kind === SyntaxKind.ArrayBindingPattern) { - let bindingElements = (pattern).elements; - for (let i = elementTypes.length; i < bindingElements.length; i++) { - let hasDefaultValue = bindingElements[i].initializer; - elementTypes.push(hasDefaultValue ? (contextualType).elementTypes[i] : undefinedType); - } - } - else if (pattern && pattern.kind === SyntaxKind.ArrayLiteralExpression) { - let assignmentElements = (pattern).elements; - for (let i = elementTypes.length; i < assignmentElements.length; i++) { - let hasDefaultValue = assignmentElements[i].kind === SyntaxKind.BinaryExpression && - (assignmentElements[i]).operatorToken.kind === SyntaxKind.EqualsToken; - elementTypes.push(hasDefaultValue ? (contextualType).elementTypes[i] : undefinedType); + // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the + // resulting tuple type to make the lengths equal. + if (pattern && (pattern.kind === SyntaxKind.ArrayBindingPattern || pattern.kind === SyntaxKind.ArrayLiteralExpression)) { + let patternElements = (pattern).elements; + for (let i = elementTypes.length; i < patternElements.length; i++) { + elementTypes.push(hasDefaultValue(patternElements[i]) ? (contextualType).elementTypes[i] : undefinedType); } } if (elementTypes.length) { @@ -7134,7 +7130,8 @@ namespace ts { let propertiesArray: Symbol[] = []; let contextualType = getContextualType(node); let contextualTypeHasPattern = contextualType && contextualType.pattern && - contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern; + (contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression); + let inDestructuringPattern = isAssignmentTarget(node); let typeFlags: TypeFlags = 0; for (let memberDecl of node.properties) { @@ -7155,13 +7152,24 @@ namespace ts { } typeFlags |= type.flags; let prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); - // If object literal is contextually typed by the implied type of a binding pattern, and if the - // binding pattern specifies a default value for the property, make the property optional. - if (contextualTypeHasPattern) { + if (inDestructuringPattern) { + // If object literal is an assignment pattern and if the assignment pattern specifies a default value + // for the property, make the property optional. + if (memberDecl.kind === SyntaxKind.PropertyAssignment && hasDefaultValue((memberDecl).initializer)) { + prop.flags |= SymbolFlags.Optional; + } + } + else if (contextualTypeHasPattern) { + // If object literal is contextually typed by the implied type of a binding pattern, and if the + // binding pattern specifies a default value for the property, make the property optional. let impliedProp = getPropertyOfType(contextualType, member.name); if (impliedProp) { prop.flags |= impliedProp.flags & SymbolFlags.Optional; } + else if (!compilerOptions.suppressExcessPropertyErrors) { + error(memberDecl.name, Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, + symbolToString(member), typeToString(contextualType)); + } } prop.declarations = member.declarations; prop.parent = member.parent; @@ -7205,6 +7213,9 @@ namespace ts { let result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); let freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshObjectLiteral; result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags); + if (inDestructuringPattern) { + result.pattern = node; + } return result; function getIndexType(kind: IndexKind) { From a0ddd437efa1b4fb52b418192176727069debec6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 15:45:20 -0700 Subject: [PATCH 32/56] Modifying tests --- .../destructuring/declarationsAndAssignments.ts | 14 +++++++------- .../destructuringWithLiteralInitializers.ts | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts b/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts index 2202a482f8b..69b7462cd03 100644 --- a/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts +++ b/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts @@ -2,8 +2,8 @@ function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; var [x, y] = [1, "hello"]; - var [x, y, z] = [1, "hello"]; // Error - var [,, z] = [0, 1, 2]; + var [x, y, z] = [1, "hello"]; + var [,, x] = [0, 1, 2]; var x: number; var y: string; } @@ -19,14 +19,14 @@ function f1() { } function f2() { - var { } = { x: 5, y: "hello" }; - var { x } = { x: 5, y: "hello" }; - var { y } = { x: 5, y: "hello" }; + var { } = { x: 5, y: "hello" }; // Error, no x and y in target + var { x } = { x: 5, y: "hello" }; // Error, no y in target + var { y } = { x: 5, y: "hello" }; // Error, no x in target var { x, y } = { x: 5, y: "hello" }; var x: number; var y: string; - var { x: a } = { x: 5, y: "hello" }; - var { y: b } = { x: 5, y: "hello" }; + var { x: a } = { x: 5, y: "hello" }; // Error, no y in target + var { y: b } = { x: 5, y: "hello" }; // Error, no x in target var { x: a, y: b } = { x: 5, y: "hello" }; var a: number; var b: string; diff --git a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts index 8f6b77d95c9..04298d8cbd7 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts @@ -2,6 +2,7 @@ function f1({ x, y }) { } f1({ x: 1, y: 1 }); +// (arg: { x: any, y?: number }) => void function f2({ x, y = 0 }) { } f2({ x: 1 }); f2({ x: 1, y: 1 }); From f80142094614be2483b0d8eff31e5b5843d4edf9 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 15:46:20 -0700 Subject: [PATCH 33/56] Accepting new baselines --- .../declarationEmitDestructuring4.errors.txt | 17 +++ .../declarationEmitDestructuring4.symbols | 21 --- .../declarationEmitDestructuring4.types | 32 ----- ...structuringObjectLiteralPattern.errors.txt | 43 ++++++ ...tDestructuringObjectLiteralPattern.symbols | 89 ------------ ...mitDestructuringObjectLiteralPattern.types | 122 ---------------- ...tructuringObjectLiteralPattern1.errors.txt | 29 ++++ ...DestructuringObjectLiteralPattern1.symbols | 42 ------ ...itDestructuringObjectLiteralPattern1.types | 63 --------- .../declarationsAndAssignments.errors.txt | 37 +++-- .../reference/declarationsAndAssignments.js | 28 ++-- ...ectBindingPatternAndAssignment3.errors.txt | 14 +- .../destructuringWithLiteralInitializers.js | 2 + ...structuringWithLiteralInitializers.symbols | 131 +++++++++--------- ...destructuringWithLiteralInitializers.types | 1 + ...ObjectBindingPatternParameter04.errors.txt | 17 +++ ...ptyObjectBindingPatternParameter04.symbols | 14 -- ...emptyObjectBindingPatternParameter04.types | 18 --- 18 files changed, 228 insertions(+), 492 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitDestructuring4.errors.txt delete mode 100644 tests/baselines/reference/declarationEmitDestructuring4.symbols delete mode 100644 tests/baselines/reference/declarationEmitDestructuring4.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt delete mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols delete mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt delete mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols delete mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types create mode 100644 tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt delete mode 100644 tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols delete mode 100644 tests/baselines/reference/emptyObjectBindingPatternParameter04.types diff --git a/tests/baselines/reference/declarationEmitDestructuring4.errors.txt b/tests/baselines/reference/declarationEmitDestructuring4.errors.txt new file mode 100644 index 00000000000..2787d5e6674 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring4.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/declarationEmitDestructuring4.ts(9,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + + +==== tests/cases/compiler/declarationEmitDestructuring4.ts (1 errors) ==== + // For an array binding pattern with empty elements, + // we will not make any modification and will emit + // the similar binding pattern users' have written + function baz([]) { } + function baz1([] = [1,2,3]) { } + function baz2([[]] = [[1,2,3]]) { } + + function baz3({}) { } + function baz4({} = { x: 10 }) { } + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuring4.symbols b/tests/baselines/reference/declarationEmitDestructuring4.symbols deleted file mode 100644 index 9f2eb162b6f..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuring4.symbols +++ /dev/null @@ -1,21 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuring4.ts === -// For an array binding pattern with empty elements, -// we will not make any modification and will emit -// the similar binding pattern users' have written -function baz([]) { } ->baz : Symbol(baz, Decl(declarationEmitDestructuring4.ts, 0, 0)) - -function baz1([] = [1,2,3]) { } ->baz1 : Symbol(baz1, Decl(declarationEmitDestructuring4.ts, 3, 20)) - -function baz2([[]] = [[1,2,3]]) { } ->baz2 : Symbol(baz2, Decl(declarationEmitDestructuring4.ts, 4, 31)) - -function baz3({}) { } ->baz3 : Symbol(baz3, Decl(declarationEmitDestructuring4.ts, 5, 35)) - -function baz4({} = { x: 10 }) { } ->baz4 : Symbol(baz4, Decl(declarationEmitDestructuring4.ts, 7, 21)) ->x : Symbol(x, Decl(declarationEmitDestructuring4.ts, 8, 20)) - - diff --git a/tests/baselines/reference/declarationEmitDestructuring4.types b/tests/baselines/reference/declarationEmitDestructuring4.types deleted file mode 100644 index 9621d61e02b..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuring4.types +++ /dev/null @@ -1,32 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuring4.ts === -// For an array binding pattern with empty elements, -// we will not make any modification and will emit -// the similar binding pattern users' have written -function baz([]) { } ->baz : ([]: any[]) => void - -function baz1([] = [1,2,3]) { } ->baz1 : ([]?: number[]) => void ->[1,2,3] : number[] ->1 : number ->2 : number ->3 : number - -function baz2([[]] = [[1,2,3]]) { } ->baz2 : ([[]]?: [number[]]) => void ->[[1,2,3]] : [number[]] ->[1,2,3] : number[] ->1 : number ->2 : number ->3 : number - -function baz3({}) { } ->baz3 : ({}: {}) => void - -function baz4({} = { x: 10 }) { } ->baz4 : ({}?: { x: number; }) => void ->{ x: 10 } : { x: number; } ->x : number ->10 : number - - diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt new file mode 100644 index 00000000000..92a8cba2d40 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt @@ -0,0 +1,43 @@ +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(2,13): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(2,19): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(3,23): error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(4,16): error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(6,27): error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(7,20): error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. + + +==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts (6 errors) ==== + + var { } = { x: 5, y: "hello" }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + var { x4 } = { x4: 5, y4: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. + var { y5 } = { x5: 5, y5: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. + var { x6, y6 } = { x6: 5, y6: "hello" }; + var { x7: a1 } = { x7: 5, y7: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. + var { y8: b1 } = { x8: 5, y8: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. + var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + + var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + + function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; + } + var { a4, b4, c4 } = f15(); + + module m { + export var { a4, b4, c4 } = f15(); + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols deleted file mode 100644 index 0a57a93f3d0..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols +++ /dev/null @@ -1,89 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts === - -var { } = { x: 5, y: "hello" }; ->x : Symbol(x, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 1, 11)) ->y : Symbol(y, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 1, 17)) - -var { x4 } = { x4: 5, y4: "hello" }; ->x4 : Symbol(x4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 2, 5)) ->x4 : Symbol(x4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 2, 14)) ->y4 : Symbol(y4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 2, 21)) - -var { y5 } = { x5: 5, y5: "hello" }; ->y5 : Symbol(y5, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 3, 5)) ->x5 : Symbol(x5, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 3, 14)) ->y5 : Symbol(y5, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 3, 21)) - -var { x6, y6 } = { x6: 5, y6: "hello" }; ->x6 : Symbol(x6, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 4, 5)) ->y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 4, 9)) ->x6 : Symbol(x6, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 4, 18)) ->y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 4, 25)) - -var { x7: a1 } = { x7: 5, y7: "hello" }; ->x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 18)) ->a1 : Symbol(a1, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 5)) ->x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 18)) ->y7 : Symbol(y7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 25)) - -var { y8: b1 } = { x8: 5, y8: "hello" }; ->y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 25)) ->b1 : Symbol(b1, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 5)) ->x8 : Symbol(x8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 18)) ->y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 25)) - -var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; ->x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 26)) ->a2 : Symbol(a2, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 5)) ->y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 33)) ->b2 : Symbol(b2, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 13)) ->x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 26)) ->y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 33)) - -var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 46)) ->x11 : Symbol(x11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 5)) ->b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 52)) ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 57)) ->y11 : Symbol(y11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 18)) ->b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 69)) ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 74)) ->z11 : Symbol(z11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 31)) ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 46)) ->b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 52)) ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 57)) ->b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 69)) ->a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 74)) - -function f15() { ->f15 : Symbol(f15, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 89)) - - var a4 = "hello"; ->a4 : Symbol(a4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 12, 7)) - - var b4 = 1; ->b4 : Symbol(b4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 13, 7)) - - var c4 = true; ->c4 : Symbol(c4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 14, 7)) - - return { a4, b4, c4 }; ->a4 : Symbol(a4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 15, 12)) ->b4 : Symbol(b4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 15, 16)) ->c4 : Symbol(c4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 15, 20)) -} -var { a4, b4, c4 } = f15(); ->a4 : Symbol(a4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 17, 5)) ->b4 : Symbol(b4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 17, 9)) ->c4 : Symbol(c4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 17, 13)) ->f15 : Symbol(f15, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 89)) - -module m { ->m : Symbol(m, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 17, 27)) - - export var { a4, b4, c4 } = f15(); ->a4 : Symbol(a4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 20, 16)) ->b4 : Symbol(b4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 20, 20)) ->c4 : Symbol(c4, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 20, 24)) ->f15 : Symbol(f15, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 89)) -} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types deleted file mode 100644 index 0911a27838b..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types +++ /dev/null @@ -1,122 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts === - -var { } = { x: 5, y: "hello" }; ->{ x: 5, y: "hello" } : { x: number; y: string; } ->x : number ->5 : number ->y : string ->"hello" : string - -var { x4 } = { x4: 5, y4: "hello" }; ->x4 : number ->{ x4: 5, y4: "hello" } : { x4: number; y4: string; } ->x4 : number ->5 : number ->y4 : string ->"hello" : string - -var { y5 } = { x5: 5, y5: "hello" }; ->y5 : string ->{ x5: 5, y5: "hello" } : { x5: number; y5: string; } ->x5 : number ->5 : number ->y5 : string ->"hello" : string - -var { x6, y6 } = { x6: 5, y6: "hello" }; ->x6 : number ->y6 : string ->{ x6: 5, y6: "hello" } : { x6: number; y6: string; } ->x6 : number ->5 : number ->y6 : string ->"hello" : string - -var { x7: a1 } = { x7: 5, y7: "hello" }; ->x7 : any ->a1 : number ->{ x7: 5, y7: "hello" } : { x7: number; y7: string; } ->x7 : number ->5 : number ->y7 : string ->"hello" : string - -var { y8: b1 } = { x8: 5, y8: "hello" }; ->y8 : any ->b1 : string ->{ x8: 5, y8: "hello" } : { x8: number; y8: string; } ->x8 : number ->5 : number ->y8 : string ->"hello" : string - -var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; ->x9 : any ->a2 : number ->y9 : any ->b2 : string ->{ x9: 5, y9: "hello" } : { x9: number; y9: string; } ->x9 : number ->5 : number ->y9 : string ->"hello" : string - -var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; ->a : any ->x11 : number ->b : any ->a : any ->y11 : string ->b : any ->a : any ->z11 : boolean ->{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; } ->a : number ->1 : number ->b : { a: string; b: { a: boolean; }; } ->{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; } ->a : string ->"hello" : string ->b : { a: boolean; } ->{ a: true } : { a: boolean; } ->a : boolean ->true : boolean - -function f15() { ->f15 : () => { a4: string; b4: number; c4: boolean; } - - var a4 = "hello"; ->a4 : string ->"hello" : string - - var b4 = 1; ->b4 : number ->1 : number - - var c4 = true; ->c4 : boolean ->true : boolean - - return { a4, b4, c4 }; ->{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; } ->a4 : string ->b4 : number ->c4 : boolean -} -var { a4, b4, c4 } = f15(); ->a4 : string ->b4 : number ->c4 : boolean ->f15() : { a4: string; b4: number; c4: boolean; } ->f15 : () => { a4: string; b4: number; c4: boolean; } - -module m { ->m : typeof m - - export var { a4, b4, c4 } = f15(); ->a4 : string ->b4 : number ->c4 : boolean ->f15() : { a4: string; b4: number; c4: boolean; } ->f15 : () => { a4: string; b4: number; c4: boolean; } -} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt new file mode 100644 index 00000000000..24fbcf99ad1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt @@ -0,0 +1,29 @@ +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(2,13): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(2,19): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(3,23): error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(4,16): error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(6,27): error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. +tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(7,20): error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. + + +==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts (6 errors) ==== + + var { } = { x: 5, y: "hello" }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + var { x4 } = { x4: 5, y4: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. + var { y5 } = { x5: 5, y5: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. + var { x6, y6 } = { x6: 5, y6: "hello" }; + var { x7: a1 } = { x7: 5, y7: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. + var { y8: b1 } = { x8: 5, y8: "hello" }; + ~~ +!!! error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. + var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols deleted file mode 100644 index cac2431411e..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols +++ /dev/null @@ -1,42 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts === - -var { } = { x: 5, y: "hello" }; ->x : Symbol(x, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 1, 11)) ->y : Symbol(y, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 1, 17)) - -var { x4 } = { x4: 5, y4: "hello" }; ->x4 : Symbol(x4, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 2, 5)) ->x4 : Symbol(x4, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 2, 14)) ->y4 : Symbol(y4, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 2, 21)) - -var { y5 } = { x5: 5, y5: "hello" }; ->y5 : Symbol(y5, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 3, 5)) ->x5 : Symbol(x5, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 3, 14)) ->y5 : Symbol(y5, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 3, 21)) - -var { x6, y6 } = { x6: 5, y6: "hello" }; ->x6 : Symbol(x6, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 4, 5)) ->y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 4, 9)) ->x6 : Symbol(x6, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 4, 18)) ->y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 4, 25)) - -var { x7: a1 } = { x7: 5, y7: "hello" }; ->x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 18)) ->a1 : Symbol(a1, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 5)) ->x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 18)) ->y7 : Symbol(y7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 25)) - -var { y8: b1 } = { x8: 5, y8: "hello" }; ->y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 25)) ->b1 : Symbol(b1, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 5)) ->x8 : Symbol(x8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 18)) ->y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 25)) - -var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; ->x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 26)) ->a2 : Symbol(a2, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 5)) ->y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 33)) ->b2 : Symbol(b2, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 13)) ->x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 26)) ->y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 33)) - diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types deleted file mode 100644 index 5411f36fa9a..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types +++ /dev/null @@ -1,63 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts === - -var { } = { x: 5, y: "hello" }; ->{ x: 5, y: "hello" } : { x: number; y: string; } ->x : number ->5 : number ->y : string ->"hello" : string - -var { x4 } = { x4: 5, y4: "hello" }; ->x4 : number ->{ x4: 5, y4: "hello" } : { x4: number; y4: string; } ->x4 : number ->5 : number ->y4 : string ->"hello" : string - -var { y5 } = { x5: 5, y5: "hello" }; ->y5 : string ->{ x5: 5, y5: "hello" } : { x5: number; y5: string; } ->x5 : number ->5 : number ->y5 : string ->"hello" : string - -var { x6, y6 } = { x6: 5, y6: "hello" }; ->x6 : number ->y6 : string ->{ x6: 5, y6: "hello" } : { x6: number; y6: string; } ->x6 : number ->5 : number ->y6 : string ->"hello" : string - -var { x7: a1 } = { x7: 5, y7: "hello" }; ->x7 : any ->a1 : number ->{ x7: 5, y7: "hello" } : { x7: number; y7: string; } ->x7 : number ->5 : number ->y7 : string ->"hello" : string - -var { y8: b1 } = { x8: 5, y8: "hello" }; ->y8 : any ->b1 : string ->{ x8: 5, y8: "hello" } : { x8: number; y8: string; } ->x8 : number ->5 : number ->y8 : string ->"hello" : string - -var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; ->x9 : any ->a2 : number ->y9 : any ->b2 : string ->{ x9: 5, y9: "hello" } : { x9: number; y9: string; } ->x9 : number ->5 : number ->y9 : string ->"hello" : string - diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 3e0666a96c0..802e72562af 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,4 +1,9 @@ -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(6,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'any', but here has type 'number'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(23,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(24,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(28,28): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(29,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(56,17): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. @@ -16,15 +21,13 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (11 errors) ==== +==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (16 errors) ==== function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; var [x, y] = [1, "hello"]; - var [x, y, z] = [1, "hello"]; // Error - var [,, z] = [0, 1, 2]; - ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'any', but here has type 'number'. + var [x, y, z] = [1, "hello"]; + var [,, x] = [0, 1, 2]; var x: number; var y: string; } @@ -40,14 +43,26 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): } function f2() { - var { } = { x: 5, y: "hello" }; - var { x } = { x: 5, y: "hello" }; - var { y } = { x: 5, y: "hello" }; + var { } = { x: 5, y: "hello" }; // Error, no x and y in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + var { x } = { x: 5, y: "hello" }; // Error, no y in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. + var { y } = { x: 5, y: "hello" }; // Error, no x in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. var { x, y } = { x: 5, y: "hello" }; var x: number; var y: string; - var { x: a } = { x: 5, y: "hello" }; - var { y: b } = { x: 5, y: "hello" }; + var { x: a } = { x: 5, y: "hello" }; // Error, no y in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. + var { y: b } = { x: 5, y: "hello" }; // Error, no x in target + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. var { x: a, y: b } = { x: 5, y: "hello" }; var a: number; var b: string; diff --git a/tests/baselines/reference/declarationsAndAssignments.js b/tests/baselines/reference/declarationsAndAssignments.js index 5c47756e7fe..018aa5522ca 100644 --- a/tests/baselines/reference/declarationsAndAssignments.js +++ b/tests/baselines/reference/declarationsAndAssignments.js @@ -3,8 +3,8 @@ function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; var [x, y] = [1, "hello"]; - var [x, y, z] = [1, "hello"]; // Error - var [,, z] = [0, 1, 2]; + var [x, y, z] = [1, "hello"]; + var [,, x] = [0, 1, 2]; var x: number; var y: string; } @@ -20,14 +20,14 @@ function f1() { } function f2() { - var { } = { x: 5, y: "hello" }; - var { x } = { x: 5, y: "hello" }; - var { y } = { x: 5, y: "hello" }; + var { } = { x: 5, y: "hello" }; // Error, no x and y in target + var { x } = { x: 5, y: "hello" }; // Error, no y in target + var { y } = { x: 5, y: "hello" }; // Error, no x in target var { x, y } = { x: 5, y: "hello" }; var x: number; var y: string; - var { x: a } = { x: 5, y: "hello" }; - var { y: b } = { x: 5, y: "hello" }; + var { x: a } = { x: 5, y: "hello" }; // Error, no y in target + var { y: b } = { x: 5, y: "hello" }; // Error, no x in target var { x: a, y: b } = { x: 5, y: "hello" }; var a: number; var b: string; @@ -185,8 +185,8 @@ function f0() { var _a = [1, "hello"]; var x = [1, "hello"][0]; var _b = [1, "hello"], x = _b[0], y = _b[1]; - var _c = [1, "hello"], x = _c[0], y = _c[1], z = _c[2]; // Error - var _d = [0, 1, 2], z = _d[2]; + var _c = [1, "hello"], x = _c[0], y = _c[1], z = _c[2]; + var _d = [0, 1, 2], x = _d[2]; var x; var y; } @@ -200,14 +200,14 @@ function f1() { var z; } function f2() { - var _a = { x: 5, y: "hello" }; - var x = { x: 5, y: "hello" }.x; - var y = { x: 5, y: "hello" }.y; + var _a = { x: 5, y: "hello" }; // Error, no x and y in target + var x = { x: 5, y: "hello" }.x; // Error, no y in target + var y = { x: 5, y: "hello" }.y; // Error, no x in target var _b = { x: 5, y: "hello" }, x = _b.x, y = _b.y; var x; var y; - var a = { x: 5, y: "hello" }.x; - var b = { x: 5, y: "hello" }.y; + var a = { x: 5, y: "hello" }.x; // Error, no y in target + var b = { x: 5, y: "hello" }.y; // Error, no x in target var _c = { x: 5, y: "hello" }, a = _c.x, b = _c.y; var a; var b; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt index 9025f24f992..4cee4314466 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -4,13 +4,17 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,21): error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1180: Property destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,5): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{ d1: any; }'. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,11): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{ d1: any; }'. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,24): error TS2353: Object literal may only specify known properties, and 'e' does not exist in type '{ d1: any; }'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,7): error TS1005: ':' expected. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,15): error TS1005: ':' expected. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,12): error TS1005: ':' expected. -==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (9 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (13 errors) ==== // Error var {h?} = { h?: 1 }; ~ @@ -27,10 +31,18 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs var { f2: {f21} = { f212: "string" } }: any = undefined; ~~~ !!! error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. + ~~~~ +!!! error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. var { ...d1 } = { ~~~ !!! error TS1180: Property destructuring pattern expected. a: 1, b: 1, d1: 9, e: 10 + ~ +!!! error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{ d1: any; }'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{ d1: any; }'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'e' does not exist in type '{ d1: any; }'. } var {1} = { 1 }; ~ diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.js b/tests/baselines/reference/destructuringWithLiteralInitializers.js index c25216a55f8..a8251435d39 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.js +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.js @@ -3,6 +3,7 @@ function f1({ x, y }) { } f1({ x: 1, y: 1 }); +// (arg: { x: any, y?: number }) => void function f2({ x, y = 0 }) { } f2({ x: 1 }); f2({ x: 1, y: 1 }); @@ -58,6 +59,7 @@ function f1(_a) { var x = _a.x, y = _a.y; } f1({ x: 1, y: 1 }); +// (arg: { x: any, y?: number }) => void function f2(_a) { var x = _a.x, _b = _a.y, y = _b === void 0 ? 0 : _b; } diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols index 992a9c3ace5..9dc3960f2af 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols @@ -10,141 +10,142 @@ f1({ x: 1, y: 1 }); >x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 2, 4)) >y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 2, 10)) +// (arg: { x: any, y?: number }) => void function f2({ x, y = 0 }) { } >f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 4, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 4, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 5, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 5, 16)) f2({ x: 1 }); >f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 5, 4)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 6, 4)) f2({ x: 1, y: 1 }); >f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 6, 4)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 6, 10)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 7, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 7, 10)) // (arg: { x?: number, y?: number }) => void function f3({ x = 0, y = 0 }) { } ->f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 9, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 9, 20)) +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 7, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 10, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 10, 20)) f3({}); ->f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 7, 19)) f3({ x: 1 }); ->f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 11, 4)) +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 7, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 12, 4)) f3({ y: 1 }); ->f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 12, 4)) +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 7, 19)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 13, 4)) f3({ x: 1, y: 1 }); ->f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 13, 4)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 13, 10)) +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 7, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 14, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 14, 10)) // (arg?: { x: number, y: number }) => void function f4({ x, y } = { x: 0, y: 0 }) { } ->f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 16, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 16, 16)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 16, 24)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 16, 30)) +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 14, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 17, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 17, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 17, 24)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 17, 30)) f4(); ->f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 14, 19)) f4({ x: 1, y: 1 }); ->f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 18, 4)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 18, 10)) +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 14, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 19, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 19, 10)) // (arg?: { x: number, y?: number }) => void function f5({ x, y = 0 } = { x: 0 }) { } ->f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 21, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 21, 16)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 21, 28)) +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 19, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 22, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 22, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 22, 28)) f5(); ->f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 19, 19)) f5({ x: 1 }); ->f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 23, 4)) +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 19, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 24, 4)) f5({ x: 1, y: 1 }); ->f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 24, 4)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 24, 10)) +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 19, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 25, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 25, 10)) // (arg?: { x?: number, y?: number }) => void function f6({ x = 0, y = 0 } = {}) { } ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 27, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 27, 20)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 28, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 28, 20)) f6(); ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) f6({}); ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) f6({ x: 1 }); ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 30, 4)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 31, 4)) f6({ y: 1 }); ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 31, 4)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 32, 4)) f6({ x: 1, y: 1 }); ->f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 32, 4)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 32, 10)) +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 25, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 33, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 33, 10)) // (arg: [any, any]) => void function g1([x, y]) { } ->g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 32, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 35, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 35, 15)) +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 36, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 36, 15)) g1([1, 1]); ->g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 32, 19)) +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) // (arg: [number, number]) => void function g2([x = 0, y = 0]) { } ->g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 36, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 39, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 39, 19)) +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 37, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 40, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 40, 19)) g2([1, 1]); ->g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 36, 11)) +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 37, 11)) // (arg?: [any, any]) => void function g3([x, y] = []) { } ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 43, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 43, 15)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 44, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 44, 15)) g3(); ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) g3([1, 1]); ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) // (arg?: [number, number]) => void function g4([x, y] = [0, 0]) { } ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 48, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 48, 15)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 49, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 49, 15)) g4(); ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) g4([1, 1]); ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types index cbb1e343bf4..7807ba201c3 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.types +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -14,6 +14,7 @@ f1({ x: 1, y: 1 }); >y : number >1 : number +// (arg: { x: any, y?: number }) => void function f2({ x, y = 0 }) { } >f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void >x : any diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt b/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt new file mode 100644 index 00000000000..cf1b0e9a9a1 --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(3,18): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(3,24): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(3,32): error TS2353: Object literal may only specify known properties, and 'c' does not exist in type '{}'. + + +==== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts (3 errors) ==== + + + function f({} = {a: 1, b: "2", c: true}) { + ~ +!!! error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'c' does not exist in type '{}'. + var x, y, z; + } \ No newline at end of file diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols b/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols deleted file mode 100644 index 9922d4cd074..00000000000 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols +++ /dev/null @@ -1,14 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts === - - -function f({} = {a: 1, b: "2", c: true}) { ->f : Symbol(f, Decl(emptyObjectBindingPatternParameter04.ts, 0, 0)) ->a : Symbol(a, Decl(emptyObjectBindingPatternParameter04.ts, 2, 17)) ->b : Symbol(b, Decl(emptyObjectBindingPatternParameter04.ts, 2, 22)) ->c : Symbol(c, Decl(emptyObjectBindingPatternParameter04.ts, 2, 30)) - - var x, y, z; ->x : Symbol(x, Decl(emptyObjectBindingPatternParameter04.ts, 3, 7)) ->y : Symbol(y, Decl(emptyObjectBindingPatternParameter04.ts, 3, 10)) ->z : Symbol(z, Decl(emptyObjectBindingPatternParameter04.ts, 3, 13)) -} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.types b/tests/baselines/reference/emptyObjectBindingPatternParameter04.types deleted file mode 100644 index 5ee32d422a9..00000000000 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter04.types +++ /dev/null @@ -1,18 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts === - - -function f({} = {a: 1, b: "2", c: true}) { ->f : ({}?: { a: number; b: string; c: boolean; }) => void ->{a: 1, b: "2", c: true} : { a: number; b: string; c: boolean; } ->a : number ->1 : number ->b : string ->"2" : string ->c : boolean ->true : boolean - - var x, y, z; ->x : any ->y : any ->z : any -} From 31f8a8148c952fcc9716b2953d49c23715cc0438 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 15:46:45 -0700 Subject: [PATCH 34/56] Adding test for excess/missing properties --- .../missingAndExcessProperties.errors.txt | 85 +++++++++++++++++++ .../reference/missingAndExcessProperties.js | 69 +++++++++++++++ .../missingAndExcessProperties.ts | 33 +++++++ 3 files changed, 187 insertions(+) create mode 100644 tests/baselines/reference/missingAndExcessProperties.errors.txt create mode 100644 tests/baselines/reference/missingAndExcessProperties.js create mode 100644 tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt new file mode 100644 index 00000000000..294b564a239 --- /dev/null +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -0,0 +1,85 @@ +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2459: Type '{}' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2459: Type '{}' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2459: Type '{}' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2459: Type '{}' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(21,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(22,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(29,14): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(29,20): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(30,22): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; }'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. + + +==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (16 errors) ==== + // Missing properties + function f1() { + var { x, y } = {}; + ~ +!!! error TS2459: Type '{}' has no property 'x' and no string index signature. + ~ +!!! error TS2459: Type '{}' has no property 'y' and no string index signature. + var { x = 1, y } = {}; + ~ +!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. + var { x, y = 1 } = {}; + ~ +!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. + var { x = 1, y = 1 } = {}; + } + + // Missing properties + function f2() { + var x: number, y: number; + ({ x, y } = {}); + ~ +!!! error TS2459: Type '{}' has no property 'x' and no string index signature. + ~ +!!! error TS2459: Type '{}' has no property 'y' and no string index signature. + ({ x: x = 1, y } = {}); + ~ +!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. + ({ x, y: y = 1 } = {}); + ~ +!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. + ({ x: x = 1, y: y = 1 } = {}); + } + + // Excess properties + function f3() { + var { } = { x: 0, y: 0 }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + var { x } = { x: 0, y: 0 }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. + var { y } = { x: 0, y: 0 }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. + var { x, y } = { x: 0, y: 0 }; + } + + // Excess properties + function f4() { + var x: number, y: number; + ({ } = { x: 0, y: 0 }); + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + ({ x } = { x: 0, y: 0 }); + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; }'. + ({ y } = { x: 0, y: 0 }); + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. + ({ x, y } = { x: 0, y: 0 }); + } + \ No newline at end of file diff --git a/tests/baselines/reference/missingAndExcessProperties.js b/tests/baselines/reference/missingAndExcessProperties.js new file mode 100644 index 00000000000..b9fcadd9519 --- /dev/null +++ b/tests/baselines/reference/missingAndExcessProperties.js @@ -0,0 +1,69 @@ +//// [missingAndExcessProperties.ts] +// Missing properties +function f1() { + var { x, y } = {}; + var { x = 1, y } = {}; + var { x, y = 1 } = {}; + var { x = 1, y = 1 } = {}; +} + +// Missing properties +function f2() { + var x: number, y: number; + ({ x, y } = {}); + ({ x: x = 1, y } = {}); + ({ x, y: y = 1 } = {}); + ({ x: x = 1, y: y = 1 } = {}); +} + +// Excess properties +function f3() { + var { } = { x: 0, y: 0 }; + var { x } = { x: 0, y: 0 }; + var { y } = { x: 0, y: 0 }; + var { x, y } = { x: 0, y: 0 }; +} + +// Excess properties +function f4() { + var x: number, y: number; + ({ } = { x: 0, y: 0 }); + ({ x } = { x: 0, y: 0 }); + ({ y } = { x: 0, y: 0 }); + ({ x, y } = { x: 0, y: 0 }); +} + + +//// [missingAndExcessProperties.js] +// Missing properties +function f1() { + var _a = {}, x = _a.x, y = _a.y; + var _b = {}, _c = _b.x, x = _c === void 0 ? 1 : _c, y = _b.y; + var _d = {}, x = _d.x, _e = _d.y, y = _e === void 0 ? 1 : _e; + var _f = {}, _g = _f.x, x = _g === void 0 ? 1 : _g, _h = _f.y, y = _h === void 0 ? 1 : _h; +} +// Missing properties +function f2() { + var x, y; + (_a = {}, x = _a.x, y = _a.y, _a); + (_b = {}, _c = _b.x, x = _c === void 0 ? 1 : _c, y = _b.y, _b); + (_d = {}, x = _d.x, _e = _d.y, y = _e === void 0 ? 1 : _e, _d); + (_f = {}, _g = _f.x, x = _g === void 0 ? 1 : _g, _h = _f.y, y = _h === void 0 ? 1 : _h, _f); + var _a, _b, _c, _d, _e, _f, _g, _h; +} +// Excess properties +function f3() { + var _a = { x: 0, y: 0 }; + var x = { x: 0, y: 0 }.x; + var y = { x: 0, y: 0 }.y; + var _b = { x: 0, y: 0 }, x = _b.x, y = _b.y; +} +// Excess properties +function f4() { + var x, y; + ({ x: 0, y: 0 }); + (_a = { x: 0, y: 0 }, x = _a.x, _a); + (_b = { x: 0, y: 0 }, y = _b.y, _b); + (_c = { x: 0, y: 0 }, x = _c.x, y = _c.y, _c); + var _a, _b, _c; +} diff --git a/tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts b/tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts new file mode 100644 index 00000000000..ef91b8249da --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts @@ -0,0 +1,33 @@ +// Missing properties +function f1() { + var { x, y } = {}; + var { x = 1, y } = {}; + var { x, y = 1 } = {}; + var { x = 1, y = 1 } = {}; +} + +// Missing properties +function f2() { + var x: number, y: number; + ({ x, y } = {}); + ({ x: x = 1, y } = {}); + ({ x, y: y = 1 } = {}); + ({ x: x = 1, y: y = 1 } = {}); +} + +// Excess properties +function f3() { + var { } = { x: 0, y: 0 }; + var { x } = { x: 0, y: 0 }; + var { y } = { x: 0, y: 0 }; + var { x, y } = { x: 0, y: 0 }; +} + +// Excess properties +function f4() { + var x: number, y: number; + ({ } = { x: 0, y: 0 }); + ({ x } = { x: 0, y: 0 }); + ({ y } = { x: 0, y: 0 }); + ({ x, y } = { x: 0, y: 0 }); +} From 546da60a2a9321d50856e28c10bee8be3264c0e2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 6 Sep 2015 08:54:38 -0700 Subject: [PATCH 35/56] Correct propagation of includePatternInType flag --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6f617d69798..91234ebb387 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2416,12 +2416,12 @@ namespace ts { // Return the type implied by a binding pattern element. This is the type of the initializer of the element if // one is present. Otherwise, if the element is itself a binding pattern, it is the type implied by the binding // pattern. Otherwise, it is the type any. - function getTypeFromBindingElement(element: BindingElement): Type { + function getTypeFromBindingElement(element: BindingElement, includePatternInType?: boolean): Type { if (element.initializer) { return getWidenedType(checkExpressionCached(element.initializer)); } if (isBindingPattern(element.name)) { - return getTypeFromBindingPattern(element.name, /*includePatternInType*/ false); + return getTypeFromBindingPattern(element.name, includePatternInType); } return anyType; } @@ -2433,7 +2433,7 @@ namespace ts { let flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0); let name = e.propertyName || e.name; let symbol = createSymbol(flags, name.text); - symbol.type = getTypeFromBindingElement(e); + symbol.type = getTypeFromBindingElement(e, includePatternInType); members[symbol.name] = symbol; }); let result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined); @@ -2450,7 +2450,7 @@ namespace ts { return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType; } // If the pattern has at least one element, and no rest element, then it should imply a tuple type. - let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e)); + let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e, includePatternInType)); let result = createTupleType(elementTypes); if (includePatternInType) { result = clone(result); From 27380f40dccd2b0df0c2b7356e1efff86cded02f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 6 Sep 2015 08:55:13 -0700 Subject: [PATCH 36/56] Adding test --- .../destructuring/destructuringWithLiteralInitializers.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts index 04298d8cbd7..dd3a0ae28a6 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts @@ -33,6 +33,14 @@ f6({ x: 1 }); f6({ y: 1 }); f6({ x: 1, y: 1 }); +// (arg?: { a: { x?: number, y?: number } }) => void +function f7({ a: { x = 0, y = 0 } } = { a: {} }) { } +f7(); +f7({ a: {} }); +f7({ a: { x: 1 } }); +f7({ a: { y: 1 } }); +f7({ a: { x: 1, y: 1 } }); + // (arg: [any, any]) => void function g1([x, y]) { } g1([1, 1]); From 055363c98deaf588dd74fa4bd6215d26382b794b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 6 Sep 2015 08:55:48 -0700 Subject: [PATCH 37/56] Accepting new baselines --- ...ArrayBindingPatternAndAssignment1ES5.types | 14 ++-- ...ArrayBindingPatternAndAssignment1ES6.types | 14 ++-- ...destructuringVariableDeclaration1ES5.types | 6 +- ...destructuringVariableDeclaration1ES6.types | 6 +- .../destructuringWithLiteralInitializers.js | 17 ++++ ...structuringWithLiteralInitializers.symbols | 83 +++++++++++++------ ...destructuringWithLiteralInitializers.types | 52 ++++++++++++ 7 files changed, 146 insertions(+), 46 deletions(-) diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index 3af7b65c625..fcd71e85dbf 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -98,13 +98,13 @@ var [c2] = []; var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any >c4 : any ->[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] ->[[]] : [undefined[]] ->[] : undefined[] ->[[[[]]]] : [[[undefined[]]]] ->[[[]]] : [[undefined[]]] ->[[]] : [undefined[]] ->[] : undefined[] +>[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] +>[[]] : [[undefined]] +>[] : [undefined] +>[[[[]]]] : [[[[undefined]]]] +>[[[]]] : [[[undefined]]] +>[[]] : [[undefined]] +>[] : [undefined] var [[c5], c6]: [[string|number], boolean] = [[1], true]; >c5 : string | number diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index cded5cdec8e..d154f091214 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -99,13 +99,13 @@ var [c2] = []; var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >c3 : any >c4 : any ->[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] ->[[]] : [undefined[]] ->[] : undefined[] ->[[[[]]]] : [[[undefined[]]]] ->[[[]]] : [[undefined[]]] ->[[]] : [undefined[]] ->[] : undefined[] +>[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] +>[[]] : [[undefined]] +>[] : [undefined] +>[[[[]]]] : [[[[undefined]]]] +>[[[]]] : [[[undefined]]] +>[[]] : [[undefined]] +>[] : [undefined] var [[c5], c6]: [[string|number], boolean] = [[1], true]; >c5 : string | number diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index 620ad90d414..c024fdfe862 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } ->f : [number, number, { f3: number; f5: number; }] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } +>f : [number, number, { f3: number; f5: number; }, undefined] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index a3004f87c82..730abd843a2 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } ->f : [number, number, { f3: number; f5: number; }] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } +>f : [number, number, { f3: number; f5: number; }, undefined] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.js b/tests/baselines/reference/destructuringWithLiteralInitializers.js index a8251435d39..640b5a37756 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.js +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.js @@ -34,6 +34,14 @@ f6({ x: 1 }); f6({ y: 1 }); f6({ x: 1, y: 1 }); +// (arg?: { a: { x?: number, y?: number } }) => void +function f7({ a: { x = 0, y = 0 } } = { a: {} }) { } +f7(); +f7({ a: {} }); +f7({ a: { x: 1 } }); +f7({ a: { y: 1 } }); +f7({ a: { x: 1, y: 1 } }); + // (arg: [any, any]) => void function g1([x, y]) { } g1([1, 1]); @@ -95,6 +103,15 @@ f6({}); f6({ x: 1 }); f6({ y: 1 }); f6({ x: 1, y: 1 }); +// (arg?: { a: { x?: number, y?: number } }) => void +function f7(_a) { + var _b = (_a === void 0 ? { a: {} } : _a).a, _c = _b.x, x = _c === void 0 ? 0 : _c, _d = _b.y, y = _d === void 0 ? 0 : _d; +} +f7(); +f7({ a: {} }); +f7({ a: { x: 1 } }); +f7({ a: { y: 1 } }); +f7({ a: { x: 1, y: 1 } }); // (arg: [any, any]) => void function g1(_a) { var x = _a[0], y = _a[1]; diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols index 9dc3960f2af..fc8c7a2f621 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols @@ -107,45 +107,76 @@ f6({ x: 1, y: 1 }); >x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 33, 4)) >y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 33, 10)) +// (arg?: { a: { x?: number, y?: number } }) => void +function f7({ a: { x = 0, y = 0 } } = { a: {} }) { } +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 36, 39)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 36, 18)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 36, 25)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 36, 39)) + +f7(); +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) + +f7({ a: {} }); +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 38, 4)) + +f7({ a: { x: 1 } }); +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 39, 4)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 39, 9)) + +f7({ a: { y: 1 } }); +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 40, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 40, 9)) + +f7({ a: { x: 1, y: 1 } }); +>f7 : Symbol(f7, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) +>a : Symbol(a, Decl(destructuringWithLiteralInitializers.ts, 41, 4)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 41, 9)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 41, 15)) + // (arg: [any, any]) => void function g1([x, y]) { } ->g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 36, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 36, 15)) - -g1([1, 1]); ->g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 33, 19)) - -// (arg: [number, number]) => void -function g2([x = 0, y = 0]) { } ->g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 37, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 40, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 40, 19)) - -g2([1, 1]); ->g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 37, 11)) - -// (arg?: [any, any]) => void -function g3([x, y] = []) { } ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 41, 26)) >x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 44, 13)) >y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 44, 15)) +g1([1, 1]); +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 41, 26)) + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 48, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 48, 19)) + +g2([1, 1]); +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 49, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 52, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 52, 15)) + g3(); ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 49, 11)) g3([1, 1]); ->g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 41, 11)) +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 49, 11)) // (arg?: [number, number]) => void function g4([x, y] = [0, 0]) { } ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) ->x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 49, 13)) ->y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 49, 15)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 54, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 57, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 57, 15)) g4(); ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 54, 11)) g4([1, 1]); ->g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 46, 11)) +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 54, 11)) diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types index 7807ba201c3..97c07bc281d 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.types +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -168,6 +168,58 @@ f6({ x: 1, y: 1 }); >y : number >1 : number +// (arg?: { a: { x?: number, y?: number } }) => void +function f7({ a: { x = 0, y = 0 } } = { a: {} }) { } +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void +>a : any +>x : number +>0 : number +>y : number +>0 : number +>{ a: {} } : { a: { x?: number; y?: number; }; } +>a : { x?: number; y?: number; } +>{} : { x?: number; y?: number; } + +f7(); +>f7() : void +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void + +f7({ a: {} }); +>f7({ a: {} }) : void +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void +>{ a: {} } : { a: {}; } +>a : {} +>{} : {} + +f7({ a: { x: 1 } }); +>f7({ a: { x: 1 } }) : void +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void +>{ a: { x: 1 } } : { a: { x: number; }; } +>a : { x: number; } +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f7({ a: { y: 1 } }); +>f7({ a: { y: 1 } }) : void +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void +>{ a: { y: 1 } } : { a: { y: number; }; } +>a : { y: number; } +>{ y: 1 } : { y: number; } +>y : number +>1 : number + +f7({ a: { x: 1, y: 1 } }); +>f7({ a: { x: 1, y: 1 } }) : void +>f7 : ({ a: { x = 0, y = 0 } }?: { a: { x?: number; y?: number; }; }) => void +>{ a: { x: 1, y: 1 } } : { a: { x: number; y: number; }; } +>a : { x: number; y: number; } +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + // (arg: [any, any]) => void function g1([x, y]) { } >g1 : ([x, y]: [any, any]) => void From 83214150f8eb7bb6360769d745652ccaa21ba5e3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 8 Sep 2015 18:40:30 -0700 Subject: [PATCH 38/56] 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 39/56] 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 40/56] 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 41/56] 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 42/56] 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 43/56] 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 44/56] 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 45/56] 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 46/56] 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 47/56] 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 e0c16b433216409282d9ada5cbc5b63aa173eabd Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 10 Sep 2015 11:36:31 -0700 Subject: [PATCH 48/56] Check if imported file is a proper external module --- src/compiler/checker.ts | 4 +- .../diagnosticInformationMap.generated.ts | 2 + src/compiler/diagnosticMessages.json | 9 +- src/compiler/program.ts | 91 +++++++++---------- src/compiler/types.ts | 17 +++- src/compiler/utilities.ts | 10 +- src/harness/harnessLanguageService.ts | 4 +- src/server/editorServices.ts | 14 +-- src/services/services.ts | 4 +- src/services/shims.ts | 13 ++- tests/baselines/reference/nodeResolution4.js | 17 ++++ .../reference/nodeResolution4.symbols | 14 +++ .../baselines/reference/nodeResolution4.types | 15 +++ .../reference/nodeResolution5.errors.txt | 14 +++ tests/baselines/reference/nodeResolution5.js | 13 +++ .../reference/nodeResolution6.errors.txt | 17 ++++ tests/baselines/reference/nodeResolution6.js | 18 ++++ .../reference/nodeResolution7.errors.txt | 14 +++ tests/baselines/reference/nodeResolution7.js | 13 +++ .../reference/nodeResolution8.errors.txt | 16 ++++ tests/baselines/reference/nodeResolution8.js | 17 ++++ tests/cases/compiler/nodeResolution4.ts | 12 +++ tests/cases/compiler/nodeResolution5.ts | 10 ++ tests/cases/compiler/nodeResolution6.ts | 13 +++ tests/cases/compiler/nodeResolution7.ts | 10 ++ tests/cases/compiler/nodeResolution8.ts | 13 +++ tests/cases/unittests/moduleResolution.ts | 79 +++------------- .../cases/unittests/reuseProgramStructure.ts | 19 +++- 28 files changed, 347 insertions(+), 145 deletions(-) create mode 100644 tests/baselines/reference/nodeResolution4.js create mode 100644 tests/baselines/reference/nodeResolution4.symbols create mode 100644 tests/baselines/reference/nodeResolution4.types create mode 100644 tests/baselines/reference/nodeResolution5.errors.txt create mode 100644 tests/baselines/reference/nodeResolution5.js create mode 100644 tests/baselines/reference/nodeResolution6.errors.txt create mode 100644 tests/baselines/reference/nodeResolution6.js create mode 100644 tests/baselines/reference/nodeResolution7.errors.txt create mode 100644 tests/baselines/reference/nodeResolution7.js create mode 100644 tests/baselines/reference/nodeResolution8.errors.txt create mode 100644 tests/baselines/reference/nodeResolution8.js create mode 100644 tests/cases/compiler/nodeResolution4.ts create mode 100644 tests/cases/compiler/nodeResolution5.ts create mode 100644 tests/cases/compiler/nodeResolution6.ts create mode 100644 tests/cases/compiler/nodeResolution7.ts create mode 100644 tests/cases/compiler/nodeResolution8.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index df432808f30..48ad97ad4f9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -976,8 +976,8 @@ namespace ts { } } - let fileName = getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text); - let sourceFile = fileName && host.getSourceFile(fileName); + let resolvedModule = getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text); + let sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName); if (sourceFile) { if (sourceFile.symbol) { return sourceFile.symbol; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index af48e67d964..efe4ba20d49 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -428,6 +428,8 @@ namespace ts { 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}'." }, + Proper_external_module_that_carries_external_typings_cannot_contain_tripleslash_references: { code: 2654, category: DiagnosticCategory.Error, key: "Proper external module that carries external typings cannot contain tripleslash references." }, + Proper_external_module_that_carries_external_typings_should_be_d_ts_file: { code: 2655, category: DiagnosticCategory.Error, key: "Proper external module that carries external typings should be '.d.ts' file." }, 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 7abec7b7c43..c62f08555df 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1701,7 +1701,14 @@ "category": "Error", "code": 2653 }, - + "Proper external module that carries external typings cannot contain tripleslash references.": { + "category": "Error", + "code": 2654 + }, + "Proper external module that carries external typings should be '.d.ts' file.": { + "category": "Error", + "code": 2655 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index a1861f6b462..ff3f5c2ba8a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -36,7 +36,7 @@ namespace ts { return normalizePath(referencedFileName); } - export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule { + export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { let moduleResolution = compilerOptions.moduleResolution !== undefined ? compilerOptions.moduleResolution : compilerOptions.module === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic; @@ -47,7 +47,7 @@ namespace ts { } } - export function nodeModuleNameResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModule { + export function nodeModuleNameResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { let containingDirectory = getDirectoryPath(containingFile); if (getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) { @@ -56,11 +56,13 @@ namespace ts { let resolvedFileName = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); if (resolvedFileName) { - return { resolvedFileName, failedLookupLocations }; + return { resolvedModule: { resolvedFileName }, failedLookupLocations }; } resolvedFileName = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); - return { resolvedFileName, failedLookupLocations }; + return resolvedFileName + ? { resolvedModule: { resolvedFileName }, failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations }; } else { return loadModuleFromNodeModules(moduleName, containingDirectory, host); @@ -117,7 +119,7 @@ namespace ts { return loadNodeModuleFromFile(combinePaths(candidate, "index"), loadOnlyDts, failedLookupLocation, host); } - function loadModuleFromNodeModules(moduleName: string, directory: string, host: ModuleResolutionHost): ResolvedModule { + function loadModuleFromNodeModules(moduleName: string, directory: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { let failedLookupLocations: string[] = []; directory = normalizeSlashes(directory); while (true) { @@ -127,12 +129,12 @@ namespace ts { let candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName)); let result = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, shouldBeProperExternalModule: true }, failedLookupLocations }; } result = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, shouldBeProperExternalModule: true }, failedLookupLocations }; } } @@ -144,47 +146,19 @@ namespace ts { directory = parentPath; } - return { resolvedFileName: undefined, failedLookupLocations }; - } - - export function baseUrlModuleNameResolver(moduleName: string, containingFile: string, baseUrl: string, host: ModuleResolutionHost): ResolvedModule { - Debug.assert(baseUrl !== undefined); - - let normalizedModuleName = normalizeSlashes(moduleName); - let basePart = useBaseUrl(moduleName) ? baseUrl : getDirectoryPath(containingFile); - let candidate = normalizePath(combinePaths(basePart, moduleName)); - - let failedLookupLocations: string[] = []; - - return forEach(supportedExtensions, ext => tryLoadFile(candidate + ext)) || { resolvedFileName: undefined, failedLookupLocations }; - - function tryLoadFile(location: string): ResolvedModule { - if (host.fileExists(location)) { - return { resolvedFileName: location, failedLookupLocations }; - } - else { - failedLookupLocations.push(location); - return undefined; - } - } + return { resolvedModule: undefined, failedLookupLocations }; } function nameStartsWithDotSlashOrDotDotSlash(name: string) { let i = name.lastIndexOf("./", 1); return i === 0 || (i === 1 && name.charCodeAt(0) === CharacterCodes.dot); } - - function useBaseUrl(moduleName: string): boolean { - // path is not rooted - // module name does not start with './' or '../' - return getRootLength(moduleName) === 0 && !nameStartsWithDotSlashOrDotDotSlash(moduleName); - } - export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule { + export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { // module names that contain '!' are used to reference resources and are not resolved to actual files on disk if (moduleName.indexOf('!') != -1) { - return { resolvedFileName: undefined, failedLookupLocations: [] }; + return { resolvedModule: undefined, failedLookupLocations: [] }; } let searchPath = getDirectoryPath(containingFile); @@ -222,7 +196,9 @@ namespace ts { searchPath = parentPath; } - return { resolvedFileName: referencedSourceFile, failedLookupLocations }; + return referencedSourceFile + ? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations }; } /* @internal */ @@ -371,9 +347,9 @@ namespace ts { host = host || createCompilerHost(options); - const resolveModuleNamesWorker = - host.resolveModuleNames || - ((moduleNames, containingFile) => map(moduleNames, moduleName => resolveModuleName(moduleName, containingFile, options, host).resolvedFileName)); + const resolveModuleNamesWorker = host.resolveModuleNames + ? ((moduleNames: string[], containingFile: string) => host.resolveModuleNames(moduleNames, containingFile)) + : ((moduleNames: string[], containingFile: string) => map(moduleNames, moduleName => resolveModuleName(moduleName, containingFile, options, host).resolvedModule)); let filesByName = createFileMap(fileName => host.getCanonicalFileName(fileName)); @@ -491,10 +467,17 @@ namespace ts { let resolutions = resolveModuleNamesWorker(moduleNames, newSourceFile.fileName); // ensure that module resolution results are still correct for (let i = 0; i < moduleNames.length; ++i) { - let oldResolution = getResolvedModuleFileName(oldSourceFile, moduleNames[i]); - if (oldResolution !== resolutions[i]) { + let newResolution = resolutions[i]; + let oldResolution = getResolvedModule(oldSourceFile, moduleNames[i]); + let resolutionChanged = oldResolution + ? !newResolution || + oldResolution.resolvedFileName !== newResolution.resolvedFileName || + !!oldResolution.shouldBeProperExternalModule !== !!newResolution.shouldBeProperExternalModule + : newResolution; + + if (resolutionChanged) { return false; - } + } } } // pass the cache of module resolutions from the old source file @@ -864,9 +847,23 @@ namespace ts { let resolutions = resolveModuleNamesWorker(moduleNames, file.fileName); for (let i = 0; i < file.imports.length; ++i) { let resolution = resolutions[i]; - setResolvedModuleName(file, moduleNames[i], resolution); + setResolvedModule(file, moduleNames[i], resolution); if (resolution && !options.noResolve) { - findModuleSourceFile(resolution, file.imports[i]); + const importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]); + if (importedFile && resolution.shouldBeProperExternalModule) { + if (!isExternalModule(importedFile)) { + let start = getTokenPosOfNode(file.imports[i], file) + diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.File_0_is_not_a_module, importedFile.fileName)); + } + else if (!fileExtensionIs(importedFile.fileName, ".d.ts")) { + let start = getTokenPosOfNode(file.imports[i], file) + diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Proper_external_module_that_carries_external_typings_should_be_d_ts_file)); + } + else if (importedFile.referencedFiles.length) { + let firstRef = importedFile.referencedFiles[0]; + diagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Proper_external_module_that_carries_external_typings_cannot_contain_tripleslash_references)); + } + } } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 47182e39527..d7bc6b4edbc 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1284,7 +1284,7 @@ namespace ts { // Stores a mapping 'external module reference text' -> 'resolved file name' | undefined // It is used to resolve module names in the checker. // Content of this fiels should never be used directly - use getResolvedModuleFileName/setResolvedModuleFileName functions instead - /* @internal */ resolvedModules: Map; + /* @internal */ resolvedModules: Map; /* @internal */ imports: LiteralExpression[]; } @@ -2269,11 +2269,20 @@ namespace ts { export interface ResolvedModule { resolvedFileName: string; + /* + * Denotes if 'resolvedFileName' should be proper external module: + * - be a .d.ts file + * - use top level imports\exports + * - don't use tripleslash references + */ + shouldBeProperExternalModule?: boolean; + } + + export interface ResolvedModuleWithFailedLookupLocations { + resolvedModule: ResolvedModule; failedLookupLocations: string[]; } - export type ModuleNameResolver = (moduleName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost) => ResolvedModule; - export interface CompilerHost extends ModuleResolutionHost { getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile; getCancellationToken?(): CancellationToken; @@ -2291,7 +2300,7 @@ namespace ts { * If resolveModuleNames is implemented then implementation for members from ModuleResolutionHost can be just * 'throw new Error("NotImplemented")' */ - resolveModuleNames?(moduleNames: string[], containingFile: string): string[]; + resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; } export interface TextSpan { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 99ea06532a0..096907cef62 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -99,20 +99,20 @@ namespace ts { return true; } - export function hasResolvedModuleName(sourceFile: SourceFile, moduleNameText: string): boolean { + export function hasResolvedModule(sourceFile: SourceFile, moduleNameText: string): boolean { return sourceFile.resolvedModules && hasProperty(sourceFile.resolvedModules, moduleNameText); } - export function getResolvedModuleFileName(sourceFile: SourceFile, moduleNameText: string): string { - return hasResolvedModuleName(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; + export function getResolvedModule(sourceFile: SourceFile, moduleNameText: string): ResolvedModule { + return hasResolvedModule(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; } - export function setResolvedModuleName(sourceFile: SourceFile, moduleNameText: string, resolvedFileName: string): void { + export function setResolvedModule(sourceFile: SourceFile, moduleNameText: string, resolvedModule: ResolvedModule): void { if (!sourceFile.resolvedModules) { sourceFile.resolvedModules = {}; } - sourceFile.resolvedModules[moduleNameText] = resolvedFileName; + sourceFile.resolvedModules[moduleNameText] = resolvedModule; } // Returns true if this node contains a parse error anywhere underneath it. diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index f228bc862d8..c97ce50d275 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -225,8 +225,8 @@ module Harness.LanguageService { let imports: ts.Map = {}; for (let module of preprocessInfo.importedFiles) { let resolutionInfo = ts.resolveModuleName(module.fileName, fileName, compilerOptions, moduleResolutionHost); - if (resolutionInfo.resolvedFileName) { - imports[module.fileName] = resolutionInfo.resolvedFileName; + if (resolutionInfo.resolvedModule) { + imports[module.fileName] = resolutionInfo.resolvedModule.resolvedFileName; } } return JSON.stringify(imports); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 76bc586b8bb..7ab46fc689e 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -79,7 +79,7 @@ namespace ts.server { } } - interface TimestampedResolvedModule extends ResolvedModule { + interface TimestampedResolvedModule extends ResolvedModuleWithFailedLookupLocations { lastCheckTime: number; } @@ -99,11 +99,11 @@ namespace ts.server { } } - resolveModuleNames(moduleNames: string[], containingFile: string): string[] { + resolveModuleNames(moduleNames: string[], containingFile: string): ResolvedModule[] { let currentResolutionsInFile = this.resolvedModuleNames.get(containingFile); let newResolutions: Map = {}; - let resolvedFileNames: string[] = []; + let resolvedModules: ResolvedModule[] = []; let compilerOptions = this.getCompilationSettings(); @@ -119,25 +119,25 @@ namespace ts.server { else { resolution = resolveModuleName(moduleName, containingFile, compilerOptions, this.moduleResolutionHost); resolution.lastCheckTime = Date.now(); - newResolutions[moduleName] = resolution; + newResolutions[moduleName] = resolution; } } ts.Debug.assert(resolution !== undefined); - resolvedFileNames.push(resolution.resolvedFileName); + resolvedModules.push(resolution.resolvedModule); } // replace old results with a new one this.resolvedModuleNames.set(containingFile, newResolutions); - return resolvedFileNames; + return resolvedModules; function moduleResolutionIsValid(resolution: TimestampedResolvedModule): boolean { if (!resolution) { return false; } - if (resolution.resolvedFileName) { + if (resolution.resolvedModule) { // TODO: consider checking failedLookupLocations // TODO: use lastCheckTime to track expiration for module name resolution return true; diff --git a/src/services/services.ts b/src/services/services.ts index d5ede917b8f..9fbcc05a5ff 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -802,7 +802,7 @@ namespace ts { public languageVariant: LanguageVariant; public identifiers: Map; public nameTable: Map; - public resolvedModules: Map; + public resolvedModules: Map; public imports: LiteralExpression[]; private namedDeclarations: Map; @@ -1022,7 +1022,7 @@ namespace ts { * if implementation is omitted then language service will use built-in module resolution logic and get answers to * host specific questions using 'getScriptSnapshot'. */ - resolveModuleNames?(moduleNames: string[], containingFile: string): string[]; + resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; } // diff --git a/src/services/shims.ts b/src/services/shims.ts index 307062cebd8..351514a1499 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -273,7 +273,7 @@ namespace ts { private loggingEnabled = false; private tracingEnabled = false; - public resolveModuleNames: (moduleName: string[], containingFile: string) => string[]; + public resolveModuleNames: (moduleName: string[], containingFile: string) => ResolvedModule[]; constructor(private shimHost: LanguageServiceShimHost) { // if shimHost is a COM object then property check will become method call with no arguments. @@ -281,7 +281,10 @@ namespace ts { if ("getModuleResolutionsForFile" in this.shimHost) { this.resolveModuleNames = (moduleNames: string[], containingFile: string) => { let resolutionsInFile = >JSON.parse(this.shimHost.getModuleResolutionsForFile(containingFile)); - return map(moduleNames, name => lookUp(resolutionsInFile, name)); + return map(moduleNames, name => { + const result = lookUp(resolutionsInFile, name); + return result ? { resolvedFileName: result } : undefined; + }); }; } } @@ -942,7 +945,11 @@ namespace ts { public resolveModuleName(fileName: string, moduleName: string, compilerOptionsJson: string): string { return this.forwardJSONCall(`resolveModuleName('${fileName}')`, () => { let compilerOptions = JSON.parse(compilerOptionsJson); - return resolveModuleName(moduleName, normalizeSlashes(fileName), compilerOptions, this.host); + const result = resolveModuleName(moduleName, normalizeSlashes(fileName), compilerOptions, this.host); + return { + resolvedFileName: result.resolvedModule ? result.resolvedModule.resolvedFileName: undefined, + failedLookupLocations: result.failedLookupLocations + }; }); } diff --git a/tests/baselines/reference/nodeResolution4.js b/tests/baselines/reference/nodeResolution4.js new file mode 100644 index 00000000000..0965c257da9 --- /dev/null +++ b/tests/baselines/reference/nodeResolution4.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/nodeResolution4.ts] //// + +//// [ref.ts] + +var x = 1; + +//// [a.ts] +/// +export var y; + +//// [b.ts] +import y = require("./a"); + +//// [ref.js] +var x = 1; +//// [a.js] +//// [b.js] diff --git a/tests/baselines/reference/nodeResolution4.symbols b/tests/baselines/reference/nodeResolution4.symbols new file mode 100644 index 00000000000..b8e0b59284a --- /dev/null +++ b/tests/baselines/reference/nodeResolution4.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/b.ts === +import y = require("./a"); +>y : Symbol(y, Decl(b.ts, 0, 0)) + +=== tests/cases/compiler/ref.ts === + +var x = 1; +>x : Symbol(x, Decl(ref.ts, 1, 3)) + +=== tests/cases/compiler/a.ts === +/// +export var y; +>y : Symbol(y, Decl(a.ts, 1, 10)) + diff --git a/tests/baselines/reference/nodeResolution4.types b/tests/baselines/reference/nodeResolution4.types new file mode 100644 index 00000000000..b273b203bde --- /dev/null +++ b/tests/baselines/reference/nodeResolution4.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/b.ts === +import y = require("./a"); +>y : typeof y + +=== tests/cases/compiler/ref.ts === + +var x = 1; +>x : number +>1 : number + +=== tests/cases/compiler/a.ts === +/// +export var y; +>y : any + diff --git a/tests/baselines/reference/nodeResolution5.errors.txt b/tests/baselines/reference/nodeResolution5.errors.txt new file mode 100644 index 00000000000..1fc4e1cee52 --- /dev/null +++ b/tests/baselines/reference/nodeResolution5.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/b.ts(1,20): error TS2306: File 'tests/cases/compiler/node_modules/a.d.ts' is not a module. + + +==== tests/cases/compiler/b.ts (1 errors) ==== + import y = require("a"); + ~~~ +!!! error TS2306: File 'a.d.ts' is not a module. + +==== tests/cases/compiler/node_modules/a.d.ts (0 errors) ==== + + declare module "a" { + var x: number; + } + \ No newline at end of file diff --git a/tests/baselines/reference/nodeResolution5.js b/tests/baselines/reference/nodeResolution5.js new file mode 100644 index 00000000000..2bc009c1522 --- /dev/null +++ b/tests/baselines/reference/nodeResolution5.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/nodeResolution5.ts] //// + +//// [a.d.ts] + +declare module "a" { + var x: number; +} + +//// [b.ts] +import y = require("a"); + + +//// [b.js] diff --git a/tests/baselines/reference/nodeResolution6.errors.txt b/tests/baselines/reference/nodeResolution6.errors.txt new file mode 100644 index 00000000000..8a462043207 --- /dev/null +++ b/tests/baselines/reference/nodeResolution6.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/node_modules/a.d.ts(1,1): error TS2654: Proper external module that carries external typings cannot contain tripleslash references. + + +==== tests/cases/compiler/b.ts (0 errors) ==== + import y = require("a"); + +==== tests/cases/compiler/node_modules/ref.ts (0 errors) ==== + + var x = 1; + +==== tests/cases/compiler/node_modules/a.d.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2654: Proper external module that carries external typings cannot contain tripleslash references. + export declare var y; + + \ No newline at end of file diff --git a/tests/baselines/reference/nodeResolution6.js b/tests/baselines/reference/nodeResolution6.js new file mode 100644 index 00000000000..140edd61f5a --- /dev/null +++ b/tests/baselines/reference/nodeResolution6.js @@ -0,0 +1,18 @@ +//// [tests/cases/compiler/nodeResolution6.ts] //// + +//// [ref.ts] + +var x = 1; + +//// [a.d.ts] +/// +export declare var y; + + +//// [b.ts] +import y = require("a"); + + +//// [ref.js] +var x = 1; +//// [b.js] diff --git a/tests/baselines/reference/nodeResolution7.errors.txt b/tests/baselines/reference/nodeResolution7.errors.txt new file mode 100644 index 00000000000..1e1f822f0d4 --- /dev/null +++ b/tests/baselines/reference/nodeResolution7.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/b.ts(1,20): error TS2306: File 'tests/cases/compiler/node_modules/a/index.d.ts' is not a module. + + +==== tests/cases/compiler/b.ts (1 errors) ==== + import y = require("a"); + ~~~ +!!! error TS2306: File 'index.d.ts' is not a module. + +==== tests/cases/compiler/node_modules/a/index.d.ts (0 errors) ==== + + declare module "a" { + var x: number; + } + \ No newline at end of file diff --git a/tests/baselines/reference/nodeResolution7.js b/tests/baselines/reference/nodeResolution7.js new file mode 100644 index 00000000000..abfbbad52a6 --- /dev/null +++ b/tests/baselines/reference/nodeResolution7.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/nodeResolution7.ts] //// + +//// [index.d.ts] + +declare module "a" { + var x: number; +} + +//// [b.ts] +import y = require("a"); + + +//// [b.js] diff --git a/tests/baselines/reference/nodeResolution8.errors.txt b/tests/baselines/reference/nodeResolution8.errors.txt new file mode 100644 index 00000000000..82753a2049b --- /dev/null +++ b/tests/baselines/reference/nodeResolution8.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/node_modules/a/index.d.ts(1,1): error TS2654: Proper external module that carries external typings cannot contain tripleslash references. + + +==== tests/cases/compiler/b.ts (0 errors) ==== + import y = require("a"); +==== tests/cases/compiler/node_modules/a/ref.ts (0 errors) ==== + + var x = 1; + +==== tests/cases/compiler/node_modules/a/index.d.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2654: Proper external module that carries external typings cannot contain tripleslash references. + export declare var y; + + \ No newline at end of file diff --git a/tests/baselines/reference/nodeResolution8.js b/tests/baselines/reference/nodeResolution8.js new file mode 100644 index 00000000000..aa67f4bf9cc --- /dev/null +++ b/tests/baselines/reference/nodeResolution8.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/nodeResolution8.ts] //// + +//// [ref.ts] + +var x = 1; + +//// [index.d.ts] +/// +export declare var y; + + +//// [b.ts] +import y = require("a"); + +//// [ref.js] +var x = 1; +//// [b.js] diff --git a/tests/cases/compiler/nodeResolution4.ts b/tests/cases/compiler/nodeResolution4.ts new file mode 100644 index 00000000000..247546c3f0c --- /dev/null +++ b/tests/cases/compiler/nodeResolution4.ts @@ -0,0 +1,12 @@ +// @module: commonjs +// @moduleResolution: node + +// @filename: ref.ts +var x = 1; + +// @filename: a.ts +/// +export var y; + +// @filename: b.ts +import y = require("./a"); \ No newline at end of file diff --git a/tests/cases/compiler/nodeResolution5.ts b/tests/cases/compiler/nodeResolution5.ts new file mode 100644 index 00000000000..313dabd7899 --- /dev/null +++ b/tests/cases/compiler/nodeResolution5.ts @@ -0,0 +1,10 @@ +// @module: commonjs +// @moduleResolution: node + +// @filename: node_modules/a.d.ts +declare module "a" { + var x: number; +} + +// @filename: b.ts +import y = require("a"); diff --git a/tests/cases/compiler/nodeResolution6.ts b/tests/cases/compiler/nodeResolution6.ts new file mode 100644 index 00000000000..3f6dc81c847 --- /dev/null +++ b/tests/cases/compiler/nodeResolution6.ts @@ -0,0 +1,13 @@ +// @module: commonjs +// @moduleResolution: node + +// @filename: node_modules/ref.ts +var x = 1; + +// @filename: node_modules/a.d.ts +/// +export declare var y; + + +// @filename: b.ts +import y = require("a"); diff --git a/tests/cases/compiler/nodeResolution7.ts b/tests/cases/compiler/nodeResolution7.ts new file mode 100644 index 00000000000..b4283edb76a --- /dev/null +++ b/tests/cases/compiler/nodeResolution7.ts @@ -0,0 +1,10 @@ +// @module: commonjs +// @moduleResolution: node + +// @filename: node_modules/a/index.d.ts +declare module "a" { + var x: number; +} + +// @filename: b.ts +import y = require("a"); diff --git a/tests/cases/compiler/nodeResolution8.ts b/tests/cases/compiler/nodeResolution8.ts new file mode 100644 index 00000000000..0a6e528f20a --- /dev/null +++ b/tests/cases/compiler/nodeResolution8.ts @@ -0,0 +1,13 @@ +// @module: commonjs +// @moduleResolution: node + +// @filename: node_modules/a/ref.ts +var x = 1; + +// @filename: node_modules/a/index.d.ts +/// +export declare var y; + + +// @filename: b.ts +import y = require("a"); \ No newline at end of file diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index 0917e72f1ce..ab12119ec5a 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -40,8 +40,9 @@ module ts { let containingFile = { name: containingFileName } let moduleFile = { name: moduleFileNameNoExt + ext } let resolution = nodeModuleNameResolver(moduleName, containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); - + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); + let failedLookupLocations: string[] = []; let dir = getDirectoryPath(containingFileName); for (let e of supportedExtensions) { @@ -78,7 +79,8 @@ module ts { let packageJson = { name: packageJsonFileName, content: JSON.stringify({ "typings": fieldRef }) }; let moduleFile = { name: moduleFileName }; let resolution = nodeModuleNameResolver(moduleName, containingFile.name, createModuleResolutionHost(containingFile, packageJson, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); // expect three failed lookup location - attempt to load module as file with all supported extensions assert.equal(resolution.failedLookupLocations.length, 3); } @@ -95,7 +97,8 @@ module ts { let packageJson = {name: "/a/b/foo/package.json", content: JSON.stringify({main: "/c/d"})}; let indexFile = { name: "/a/b/foo/index.d.ts" }; let resolution = nodeModuleNameResolver("./foo", containingFile.name, createModuleResolutionHost(containingFile, packageJson, indexFile)); - assert.equal(resolution.resolvedFileName, indexFile.name); + assert.equal(resolution.resolvedModule.resolvedFileName, indexFile.name); + assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); assert.deepEqual(resolution.failedLookupLocations, [ "/a/b/foo.ts", "/a/b/foo.tsx", @@ -111,7 +114,7 @@ module ts { let containingFile = { name: "/a/b/c/d/e.ts" }; let moduleFile = { name: "/a/b/node_modules/foo.ts" }; let resolution = nodeModuleNameResolver("foo", containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, undefined); + assert.equal(resolution.resolvedModule, undefined); assert.deepEqual(resolution.failedLookupLocations, [ "/a/b/c/d/node_modules/foo.d.ts", "/a/b/c/d/node_modules/foo/package.json", @@ -135,14 +138,16 @@ module ts { let containingFile = { name: "/a/b/c/d/e.ts" }; let moduleFile = { name: "/a/b/node_modules/foo.d.ts" }; let resolution = nodeModuleNameResolver("foo", containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.shouldBeProperExternalModule, true); }); it("load module as directory", () => { let containingFile = { name: "/a/node_modules/b/c/node_modules/d/e.ts" }; let moduleFile = { name: "/a/node_modules/foo/index.d.ts" }; let resolution = nodeModuleNameResolver("foo", containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.shouldBeProperExternalModule, true); assert.deepEqual(resolution.failedLookupLocations, [ "/a/node_modules/b/c/node_modules/d/node_modules/foo.d.ts", "/a/node_modules/b/c/node_modules/d/node_modules/foo/package.json", @@ -158,64 +163,4 @@ module ts { ]); }); }); - - describe("BaseUrl mode", () => { - - it ("load module as relative url", () => { - function test(containingFileName: string, moduleFileName: string, moduleName: string): void { - let containingFile = {name: containingFileName }; - let moduleFile = { name: moduleFileName }; - let resolution = baseUrlModuleNameResolver(moduleName, containingFile.name, "", createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); - let expectedFailedLookupLocations: string[] = []; - - let moduleNameHasExt = forEach(supportedExtensions, e => fileExtensionIs(moduleName, e)); - if (!moduleNameHasExt) { - let dir = getDirectoryPath(containingFileName); - - // add candidates with extensions that precede extension of the actual module name file in the list of supportd extensions - for (let ext of supportedExtensions) { - - let hasExtension = ext !== ".ts" - ? fileExtensionIs(moduleFileName, ext) - : fileExtensionIs(moduleFileName, ".ts") && !fileExtensionIs(moduleFileName, ".d.ts"); - - if (hasExtension) { - break; - } - else { - expectedFailedLookupLocations.push(normalizePath(combinePaths(dir, moduleName + ext))); - } - } - } - - assert.deepEqual(resolution.failedLookupLocations, expectedFailedLookupLocations) - } - - test("/a/b/c/d.ts", "/foo.ts", "/foo"); - test("/a/b/c/d.ts", "/foo.d.ts", "/foo"); - test("/a/b/c/d.ts", "/foo.tsx", "/foo"); - - test("/a/b/c/d.ts", "/a/b/c/foo.ts", "./foo"); - test("/a/b/c/d.ts", "/a/b/c/foo.d.ts", "./foo"); - test("/a/b/c/d.ts", "/a/b/c/foo.tsx", "./foo"); - - test("/a/b/c/d.ts", "/a/b/foo.ts", "../foo"); - test("/a/b/c/d.ts", "/a/b/foo.d.ts", "../foo"); - test("/a/b/c/d.ts", "/a/b/foo.tsx", "../foo"); - }); - - it ("load module using base url", () => { - function test(containingFileName: string, moduleFileName: string, moduleName: string, baseUrl: string): void { - let containingFile = { name: containingFileName }; - let moduleFile = { name: moduleFileName }; - let resolution = baseUrlModuleNameResolver(moduleName, containingFileName, baseUrl, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); - } - - test("/a/base/c/d.ts", "/a/base/c/d/e.ts", "c/d/e", "/a/base"); - test("/a/base/c/d.ts", "/a/base/c/d/e.d.ts", "c/d/e", "/a/base"); - test("/a/base/c/d.ts", "/a/base/c/d/e.tsx", "c/d/e", "/a/base"); - }); - }); } \ No newline at end of file diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index 6c043299c8f..14bf09d6db8 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -160,7 +160,7 @@ module ts { return size; } - function checkResolvedModulesCache(program: Program, fileName: string, expectedContent: Map): void { + function checkResolvedModulesCache(program: Program, fileName: string, expectedContent: Map): void { let file = program.getSourceFile(fileName); assert.isTrue(file !== undefined, `cannot find file ${fileName}`); if (expectedContent === undefined) { @@ -175,7 +175,16 @@ module ts { for (let id in expectedContent) { if (hasProperty(expectedContent, id)) { assert.isTrue(hasProperty(file.resolvedModules, id), `expected ${id} to be found in resolved modules`); - assert.isTrue(expectedContent[id] === file.resolvedModules[id], `expected '${expectedContent[id]}' to be equal to '${file.resolvedModules[id]}'`); + if (expectedContent[id]) { + const expected = expectedContent[id]; + const actual = file.resolvedModules[id]; + assert.isTrue(actual !== undefined); + assert.isTrue(expected.resolvedFileName === actual.resolvedFileName, `'resolvedFileName': expected '${expected.resolvedFileName}' to be equal to '${actual.resolvedFileName}'`); + assert.isTrue(expected.shouldBeProperExternalModule === actual.shouldBeProperExternalModule, `'shouldBeProperExternalModule': expected '${expected.shouldBeProperExternalModule}' to be equal to '${actual.shouldBeProperExternalModule}'`); + } + else { + assert.isTrue(file.resolvedModules[id] === undefined); + } } } } @@ -230,7 +239,7 @@ module ts { var options: CompilerOptions = { target }; var program_1 = newProgram(files, ["a.ts"], options); - checkResolvedModulesCache(program_1, "a.ts", { "b": "b.ts" }); + checkResolvedModulesCache(program_1, "a.ts", { "b": { resolvedFileName: "b.ts" } }); checkResolvedModulesCache(program_1, "b.ts", undefined); var program_2 = updateProgram(program_1, ["a.ts"], options, files => { @@ -239,7 +248,7 @@ module ts { assert.isTrue(program_1.structureIsReused); // content of resolution cache should not change - checkResolvedModulesCache(program_1, "a.ts", { "b": "b.ts" }); + checkResolvedModulesCache(program_1, "a.ts", { "b": { resolvedFileName: "b.ts" } }); checkResolvedModulesCache(program_1, "b.ts", undefined); // imports has changed - program is not reused @@ -256,7 +265,7 @@ module ts { files[0].text = files[0].text.updateImportsAndExports(newImports); }); assert.isTrue(!program_3.structureIsReused); - checkResolvedModulesCache(program_4, "a.ts", { "b": "b.ts", "c": undefined }); + checkResolvedModulesCache(program_4, "a.ts", { "b": { resolvedFileName: "b.ts" }, "c": undefined }); }); }) } \ No newline at end of file From 32ac25d48fc1d79d6e0686a73717d13957b6ea41 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 10 Sep 2015 16:12:41 -0700 Subject: [PATCH 49/56] 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 From d5ff9ee1e1e20b82a08a44d1183c1ea545af8a3e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 10 Sep 2015 16:22:50 -0700 Subject: [PATCH 50/56] Error when binding element has no value in initializer and no default --- src/compiler/checker.ts | 43 +++++++++++++------ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++ src/compiler/types.ts | 1 + 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 91234ebb387..e4d6929fe6b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2434,6 +2434,7 @@ namespace ts { let name = e.propertyName || e.name; let symbol = createSymbol(flags, name.text); symbol.type = getTypeFromBindingElement(e, includePatternInType); + symbol.bindingElement = e; members[symbol.name] = symbol; }); let result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined); @@ -2451,12 +2452,12 @@ namespace ts { } // If the pattern has at least one element, and no rest element, then it should imply a tuple type. let elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e, includePatternInType)); - let result = createTupleType(elementTypes); if (includePatternInType) { - result = clone(result); + let result = createNewTupleType(elementTypes); result.pattern = pattern; + return result; } - return result; + return createTupleType(elementTypes); } // Return the type implied by a binding pattern. This is the type implied purely by the binding pattern itself @@ -3124,7 +3125,7 @@ namespace ts { } function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature { - for (let s of signatureList) { + for (let s of signatureList) { if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) { return s; } @@ -4045,11 +4046,12 @@ namespace ts { function createTupleType(elementTypes: Type[]) { let id = getTypeListId(elementTypes); - let type = tupleTypes[id]; - if (!type) { - type = tupleTypes[id] = createObjectType(TypeFlags.Tuple | getPropagatingFlagsOfTypes(elementTypes)); - type.elementTypes = elementTypes; - } + return tupleTypes[id] || (tupleTypes[id] = createNewTupleType(elementTypes)); + } + + function createNewTupleType(elementTypes: Type[]) { + let type = createObjectType(TypeFlags.Tuple | getPropagatingFlagsOfTypes(elementTypes)); + type.elementTypes = elementTypes; return type; } @@ -7042,19 +7044,28 @@ namespace ts { // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such // that we get the same behavior for "var [x, y] = []" and "[x, y] = []". if (inDestructuringPattern && elementTypes.length) { - let type = clone(createTupleType(elementTypes)); + let type = createNewTupleType(elementTypes); type.pattern = node; return type; } let contextualType = getContextualType(node); if (contextualType && contextualTypeIsTupleLikeType(contextualType)) { let pattern = contextualType.pattern; - // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the - // resulting tuple type to make the lengths equal. + // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the resulting + // tuple type with the corresponding binding or assignment element types to make the lengths equal. if (pattern && (pattern.kind === SyntaxKind.ArrayBindingPattern || pattern.kind === SyntaxKind.ArrayLiteralExpression)) { let patternElements = (pattern).elements; for (let i = elementTypes.length; i < patternElements.length; i++) { - elementTypes.push(hasDefaultValue(patternElements[i]) ? (contextualType).elementTypes[i] : undefinedType); + let patternElement = patternElements[i]; + if (hasDefaultValue(patternElement)) { + elementTypes.push((contextualType).elementTypes[i]); + } + else { + if (patternElement.kind !== SyntaxKind.OmittedExpression) { + error(patternElement, Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); + } + elementTypes.push(unknownType); + } } } if (elementTypes.length) { @@ -7201,7 +7212,11 @@ namespace ts { // type with those properties for which the binding pattern specifies a default value. if (contextualTypeHasPattern) { for (let prop of getPropertiesOfType(contextualType)) { - if (prop.flags & SymbolFlags.Optional && !hasProperty(propertiesTable, prop.name)) { + if (!hasProperty(propertiesTable, prop.name)) { + if (!(prop.flags & SymbolFlags.Optional)) { + error(prop.valueDeclaration || (prop).bindingElement, + Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); + } propertiesTable[prop.name] = prop; propertiesArray.push(prop); } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index f7351bf6912..9686d6580f5 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -415,6 +415,7 @@ namespace ts { The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." }, yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." }, await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." }, + Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value" }, JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." }, The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." }, JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9fd08ef9bca..515afda49aa 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1649,6 +1649,10 @@ "category": "Error", "code": 2524 }, + "Initializer provides no value for this binding element and the binding element has no default value": { + "category": "Error", + "code": 2525 + }, "JSX element attributes type '{0}' must be an object type.": { "category": "Error", "code": 2600 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d23a42e753a..cfdf869dd77 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1714,6 +1714,7 @@ namespace ts { resolvedExports?: SymbolTable; // Resolved exports of module exportsChecked?: boolean; // True if exports of external module have been checked isNestedRedeclaration?: boolean; // True if symbol is block scoped redeclaration + bindingElement?: BindingElement; // Binding element associated with property symbol } /* @internal */ From a95c42384babcd3915c216e0a799a185db603813 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 10 Sep 2015 16:27:35 -0700 Subject: [PATCH 51/56] Revising test --- .../destructuringWithLiteralInitializers.js | 23 ++++-- ...structuringWithLiteralInitializers.symbols | 18 ++++- ...destructuringWithLiteralInitializers.types | 74 ++++++++++++------- .../destructuringWithLiteralInitializers.ts | 11 ++- 4 files changed, 88 insertions(+), 38 deletions(-) diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.js b/tests/baselines/reference/destructuringWithLiteralInitializers.js index 640b5a37756..740648b04e8 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.js +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.js @@ -50,15 +50,20 @@ g1([1, 1]); function g2([x = 0, y = 0]) { } g2([1, 1]); -// (arg?: [any, any]) => void -function g3([x, y] = []) { } +// (arg?: [number, number]) => void +function g3([x, y] = [0, 0]) { } g3(); g3([1, 1]); // (arg?: [number, number]) => void -function g4([x, y] = [0, 0]) { } +function g4([x, y = 0] = [0]) { } g4(); g4([1, 1]); + +// (arg?: [number, number]) => void +function g5([x = 0, y = 0] = []) { } +g5(); +g5([1, 1]); //// [destructuringWithLiteralInitializers.js] @@ -122,15 +127,21 @@ function g2(_a) { var _b = _a[0], x = _b === void 0 ? 0 : _b, _c = _a[1], y = _c === void 0 ? 0 : _c; } g2([1, 1]); -// (arg?: [any, any]) => void +// (arg?: [number, number]) => void function g3(_a) { - var _b = _a === void 0 ? [] : _a, x = _b[0], y = _b[1]; + var _b = _a === void 0 ? [0, 0] : _a, x = _b[0], y = _b[1]; } g3(); g3([1, 1]); // (arg?: [number, number]) => void function g4(_a) { - var _b = _a === void 0 ? [0, 0] : _a, x = _b[0], y = _b[1]; + var _b = _a === void 0 ? [0] : _a, x = _b[0], _c = _b[1], y = _c === void 0 ? 0 : _c; } g4(); g4([1, 1]); +// (arg?: [number, number]) => void +function g5(_a) { + var _b = _a === void 0 ? [] : _a, _c = _b[0], x = _c === void 0 ? 0 : _c, _d = _b[1], y = _d === void 0 ? 0 : _d; +} +g5(); +g5([1, 1]); diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols index fc8c7a2f621..1141fc140c7 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols @@ -156,8 +156,8 @@ function g2([x = 0, y = 0]) { } g2([1, 1]); >g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) -// (arg?: [any, any]) => void -function g3([x, y] = []) { } +// (arg?: [number, number]) => void +function g3([x, y] = [0, 0]) { } >g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 49, 11)) >x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 52, 13)) >y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 52, 15)) @@ -169,7 +169,7 @@ g3([1, 1]); >g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 49, 11)) // (arg?: [number, number]) => void -function g4([x, y] = [0, 0]) { } +function g4([x, y = 0] = [0]) { } >g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 54, 11)) >x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 57, 13)) >y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 57, 15)) @@ -180,3 +180,15 @@ g4(); g4([1, 1]); >g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 54, 11)) +// (arg?: [number, number]) => void +function g5([x = 0, y = 0] = []) { } +>g5 : Symbol(g5, Decl(destructuringWithLiteralInitializers.ts, 59, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 62, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 62, 19)) + +g5(); +>g5 : Symbol(g5, Decl(destructuringWithLiteralInitializers.ts, 59, 11)) + +g5([1, 1]); +>g5 : Symbol(g5, Decl(destructuringWithLiteralInitializers.ts, 59, 11)) + diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types index 97c07bc281d..da1e4bfd6f3 100644 --- a/tests/baselines/reference/destructuringWithLiteralInitializers.types +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -248,40 +248,62 @@ g2([1, 1]); >1 : number >1 : number -// (arg?: [any, any]) => void -function g3([x, y] = []) { } ->g3 : ([x, y]?: [any, any]) => void ->x : any ->y : any ->[] : [undefined, undefined] - -g3(); ->g3() : void ->g3 : ([x, y]?: [any, any]) => void - -g3([1, 1]); ->g3([1, 1]) : void ->g3 : ([x, y]?: [any, any]) => void ->[1, 1] : [number, number] ->1 : number ->1 : number - // (arg?: [number, number]) => void -function g4([x, y] = [0, 0]) { } ->g4 : ([x, y]?: [number, number]) => void +function g3([x, y] = [0, 0]) { } +>g3 : ([x, y]?: [number, number]) => void >x : number >y : number >[0, 0] : [number, number] >0 : number >0 : number -g4(); ->g4() : void ->g4 : ([x, y]?: [number, number]) => void +g3(); +>g3() : void +>g3 : ([x, y]?: [number, number]) => void -g4([1, 1]); ->g4([1, 1]) : void ->g4 : ([x, y]?: [number, number]) => void +g3([1, 1]); +>g3([1, 1]) : void +>g3 : ([x, y]?: [number, number]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg?: [number, number]) => void +function g4([x, y = 0] = [0]) { } +>g4 : ([x, y = 0]?: [number, number]) => void +>x : number +>y : number +>0 : number +>[0] : [number, number] +>0 : number + +g4(); +>g4() : void +>g4 : ([x, y = 0]?: [number, number]) => void + +g4([1, 1]); +>g4([1, 1]) : void +>g4 : ([x, y = 0]?: [number, number]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg?: [number, number]) => void +function g5([x = 0, y = 0] = []) { } +>g5 : ([x = 0, y = 0]?: [number, number]) => void +>x : number +>0 : number +>y : number +>0 : number +>[] : [number, number] + +g5(); +>g5() : void +>g5 : ([x = 0, y = 0]?: [number, number]) => void + +g5([1, 1]); +>g5([1, 1]) : void +>g5 : ([x = 0, y = 0]?: [number, number]) => void >[1, 1] : [number, number] >1 : number >1 : number diff --git a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts index dd3a0ae28a6..17de6dd2858 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts @@ -49,12 +49,17 @@ g1([1, 1]); function g2([x = 0, y = 0]) { } g2([1, 1]); -// (arg?: [any, any]) => void -function g3([x, y] = []) { } +// (arg?: [number, number]) => void +function g3([x, y] = [0, 0]) { } g3(); g3([1, 1]); // (arg?: [number, number]) => void -function g4([x, y] = [0, 0]) { } +function g4([x, y = 0] = [0]) { } g4(); g4([1, 1]); + +// (arg?: [number, number]) => void +function g5([x = 0, y = 0] = []) { } +g5(); +g5([1, 1]); From 273b9ff1ec12f4a81c8cc96296b3fef0aec6eac2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 10 Sep 2015 16:27:58 -0700 Subject: [PATCH 52/56] Accepting new baselines --- ...nEmitDestructuringArrayPattern2.errors.txt | 22 +++ ...tionEmitDestructuringArrayPattern2.symbols | 40 ---- ...rationEmitDestructuringArrayPattern2.types | 70 ------- .../declarationsAndAssignments.errors.txt | 28 ++- ...BindingPatternAndAssignment1ES5.errors.txt | 65 +++++++ ...rayBindingPatternAndAssignment1ES5.symbols | 105 ----------- ...ArrayBindingPatternAndAssignment1ES5.types | 177 ------------------ ...BindingPatternAndAssignment1ES6.errors.txt | 64 +++++++ ...rayBindingPatternAndAssignment1ES6.symbols | 105 ----------- ...ArrayBindingPatternAndAssignment1ES6.types | 177 ------------------ ...rayBindingPatternAndAssignment2.errors.txt | 8 +- ...ectBindingPatternAndAssignment3.errors.txt | 4 +- ...destructuringVariableDeclaration1ES5.types | 6 +- ...destructuringVariableDeclaration1ES6.types | 6 +- .../reference/downlevelLetConst12.errors.txt | 20 ++ .../reference/downlevelLetConst12.symbols | 26 --- .../reference/downlevelLetConst12.types | 35 ---- .../reference/downlevelLetConst16.errors.txt | 8 +- .../missingAndExcessProperties.errors.txt | 46 +++-- 19 files changed, 242 insertions(+), 770 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt delete mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols delete mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types create mode 100644 tests/baselines/reference/downlevelLetConst12.errors.txt delete mode 100644 tests/baselines/reference/downlevelLetConst12.symbols delete mode 100644 tests/baselines/reference/downlevelLetConst12.types diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt new file mode 100644 index 00000000000..ea5b38a3b2f --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value + + +==== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts (3 errors) ==== + var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; + + var [x11 = 0, y11 = ""] = [1, "hello"]; + var [a11, b11, c11] = []; + ~~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + + var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; + + var [x13, y13] = [1, "hello"]; + var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols deleted file mode 100644 index 0a3c6f4044d..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols +++ /dev/null @@ -1,40 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts === -var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; ->x10 : Symbol(x10, Decl(declarationEmitDestructuringArrayPattern2.ts, 0, 5)) ->y10 : Symbol(y10, Decl(declarationEmitDestructuringArrayPattern2.ts, 0, 11)) ->z10 : Symbol(z10, Decl(declarationEmitDestructuringArrayPattern2.ts, 0, 17)) - -var [x11 = 0, y11 = ""] = [1, "hello"]; ->x11 : Symbol(x11, Decl(declarationEmitDestructuringArrayPattern2.ts, 2, 5)) ->y11 : Symbol(y11, Decl(declarationEmitDestructuringArrayPattern2.ts, 2, 13)) - -var [a11, b11, c11] = []; ->a11 : Symbol(a11, Decl(declarationEmitDestructuringArrayPattern2.ts, 3, 5)) ->b11 : Symbol(b11, Decl(declarationEmitDestructuringArrayPattern2.ts, 3, 9)) ->c11 : Symbol(c11, Decl(declarationEmitDestructuringArrayPattern2.ts, 3, 14)) - -var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; ->a2 : Symbol(a2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 5)) ->b2 : Symbol(b2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 10)) ->x12 : Symbol(x12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 15)) ->y12 : Symbol(y12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 91)) ->c2 : Symbol(c2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 20)) ->x12 : Symbol(x12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 41)) ->y12 : Symbol(y12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 50)) ->x12 : Symbol(x12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 83)) ->y12 : Symbol(y12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 91)) - -var [x13, y13] = [1, "hello"]; ->x13 : Symbol(x13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 5)) ->y13 : Symbol(y13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 9)) - -var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; ->a3 : Symbol(a3, Decl(declarationEmitDestructuringArrayPattern2.ts, 8, 5)) ->b3 : Symbol(b3, Decl(declarationEmitDestructuringArrayPattern2.ts, 8, 8)) ->x13 : Symbol(x13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 5)) ->y13 : Symbol(y13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 9)) ->x : Symbol(x, Decl(declarationEmitDestructuringArrayPattern2.ts, 8, 29)) ->x13 : Symbol(x13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 5)) ->y : Symbol(y, Decl(declarationEmitDestructuringArrayPattern2.ts, 8, 37)) ->y13 : Symbol(y13, Decl(declarationEmitDestructuringArrayPattern2.ts, 7, 9)) - diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types deleted file mode 100644 index 57acfe1dde1..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types +++ /dev/null @@ -1,70 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts === -var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; ->x10 : number ->y10 : string ->z10 : boolean ->[1, ["hello", [true]]] : [number, [string, [boolean]]] ->1 : number ->["hello", [true]] : [string, [boolean]] ->"hello" : string ->[true] : [boolean] ->true : boolean - -var [x11 = 0, y11 = ""] = [1, "hello"]; ->x11 : number ->0 : number ->y11 : string ->"" : string ->[1, "hello"] : [number, string] ->1 : number ->"hello" : string - -var [a11, b11, c11] = []; ->a11 : any ->b11 : any ->c11 : any ->[] : [undefined, undefined, undefined] - -var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; ->a2 : number ->b2 : string ->x12 : number ->y12 : any ->c2 : boolean ->["abc", { x12: 10, y12: false }] : [string, { x12: number; y12: boolean; }] ->"abc" : string ->{ x12: 10, y12: false } : { x12: number; y12: boolean; } ->x12 : number ->10 : number ->y12 : boolean ->false : boolean ->[1, ["hello", { x12: 5, y12: true }]] : [number, [string, { x12: number; y12: boolean; }]] ->1 : number ->["hello", { x12: 5, y12: true }] : [string, { x12: number; y12: boolean; }] ->"hello" : string ->{ x12: 5, y12: true } : { x12: number; y12: boolean; } ->x12 : number ->5 : number ->y12 : boolean ->true : boolean - -var [x13, y13] = [1, "hello"]; ->x13 : number ->y13 : string ->[1, "hello"] : [number, string] ->1 : number ->"hello" : string - -var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; ->a3 : (number | string)[] ->b3 : { x: number; y: string; } ->[[x13, y13], { x: x13, y: y13 }] : [(number | string)[], { x: number; y: string; }] ->[x13, y13] : (number | string)[] ->x13 : number ->y13 : string ->{ x: x13, y: y13 } : { x: number; y: string; } ->x : number ->x13 : number ->y : string ->y13 : string - diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 802e72562af..cd72c12951c 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,3 +1,4 @@ +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(23,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -5,10 +6,15 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(24,19): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(28,28): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(29,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(56,17): error TS2322: Type 'number' is not assignable to type 'string'. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,10): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2459: Type '{}' has no property 'a' and no string index signature. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2459: Type '{}' has no property 'b' and no string index signature. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,11): error TS2459: Type 'undefined[]' has no property 'a' and no string index signature. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,14): error TS2459: Type 'undefined[]' has no property 'b' and no string index signature. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(106,5): error TS2345: Argument of type '[number, [string, { y: boolean; }]]' is not assignable to parameter of type '[number, [string, { x: any; y?: boolean; }]]'. @@ -21,12 +27,14 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (16 errors) ==== +==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (22 errors) ==== function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; var [x, y] = [1, "hello"]; var [x, y, z] = [1, "hello"]; + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var [,, x] = [0, 1, 2]; var x: number; var y: string; @@ -98,7 +106,17 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f8() { var [a, b, c] = []; // Ok, [] is an array + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var [d, e, f] = [1]; // Error, [1] is a tuple + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value } function f9() { @@ -114,9 +132,9 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f10() { var { a, b } = {}; // Error ~ -!!! error TS2459: Type '{}' has no property 'a' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ~ -!!! error TS2459: Type '{}' has no property 'b' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var { a, b } = []; // Error ~ !!! error TS2459: Type 'undefined[]' has no property 'a' and no string index signature. diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt new file mode 100644 index 00000000000..5fd60c296c9 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt @@ -0,0 +1,65 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(43,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value + + +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts (3 errors) ==== + /* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + + // In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. + // An expression of type S is considered assignable to an assignment target V if one of the following is true + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is the type Any, or + + var [a0, a1]: any = undefined; + var [a2 = false, a3 = 1]: any = undefined; + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, + // where N is the numeric index of E in the array assignment pattern, or + var [b0, b1, b2] = [2, 3, 4]; + var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + + function foo() { + return [1, 2, 3]; + } + + var [b6, b7] = foo(); + var [...b8] = foo(); + + // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. + var temp = [1,2,3] + var [c0, c1] = [...temp]; + var [c2] = []; + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + var [[c5], c6]: [[string|number], boolean] = [[1], true]; + var [, c7] = [1, 2, 3]; + var [,,, c8] = [1, 2, 3, 4]; + var [,,, c9] = [1, 2, 3, 4]; + var [,,,...c10] = [1, 2, 3, 4, "hello"]; + var [c11, c12, ...c13] = [1, 2, "string"]; + var [c14, c15, c16] = [1, 2, "string"]; + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols deleted file mode 100644 index d8e319f4120..00000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols +++ /dev/null @@ -1,105 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts === -/* AssignmentPattern: - * ObjectAssignmentPattern - * ArrayAssignmentPattern - * ArrayAssignmentPattern: - * [Elision AssignmentRestElementopt ] - * [AssignmentElementList] - * [AssignmentElementList, Elision AssignmentRestElementopt ] - * AssignmentElementList: - * Elision AssignmentElement - * AssignmentElementList, Elisionopt AssignmentElement - * AssignmentElement: - * LeftHandSideExpression Initialiseropt - * AssignmentPattern Initialiseropt - * AssignmentRestElement: - * ... LeftHandSideExpression - */ - -// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. -// An expression of type S is considered assignable to an assignment target V if one of the following is true - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is the type Any, or - -var [a0, a1]: any = undefined; ->a0 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5)) ->a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8)) ->undefined : Symbol(undefined) - -var [a2 = false, a3 = 1]: any = undefined; ->a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5)) ->a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16)) ->undefined : Symbol(undefined) - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, -// where N is the numeric index of E in the array assignment pattern, or -var [b0, b1, b2] = [2, 3, 4]; ->b0 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5)) ->b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8)) ->b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12)) - -var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5)) ->b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8)) ->b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12)) - -function foo() { ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) - - return [1, 2, 3]; -} - -var [b6, b7] = foo(); ->b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5)) ->b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8)) ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) - -var [...b8] = foo(); ->b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5)) ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) - -// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. -var temp = [1,2,3] ->temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) - -var [c0, c1] = [...temp]; ->c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5)) ->c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8)) ->temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) - -var [c2] = []; ->c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5)) - -var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7)) ->c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17)) - -var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6)) ->c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10)) - -var [, c7] = [1, 2, 3]; ->c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6)) - -var [,,, c8] = [1, 2, 3, 4]; ->c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8)) - -var [,,, c9] = [1, 2, 3, 4]; ->c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8)) - -var [,,,...c10] = [1, 2, 3, 4, "hello"]; ->c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8)) - -var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5)) ->c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9)) ->c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14)) - -var [c14, c15, c16] = [1, 2, "string"]; ->c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5)) ->c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9)) ->c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14)) - - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types deleted file mode 100644 index fcd71e85dbf..00000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ /dev/null @@ -1,177 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts === -/* AssignmentPattern: - * ObjectAssignmentPattern - * ArrayAssignmentPattern - * ArrayAssignmentPattern: - * [Elision AssignmentRestElementopt ] - * [AssignmentElementList] - * [AssignmentElementList, Elision AssignmentRestElementopt ] - * AssignmentElementList: - * Elision AssignmentElement - * AssignmentElementList, Elisionopt AssignmentElement - * AssignmentElement: - * LeftHandSideExpression Initialiseropt - * AssignmentPattern Initialiseropt - * AssignmentRestElement: - * ... LeftHandSideExpression - */ - -// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. -// An expression of type S is considered assignable to an assignment target V if one of the following is true - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is the type Any, or - -var [a0, a1]: any = undefined; ->a0 : any ->a1 : any ->undefined : undefined - -var [a2 = false, a3 = 1]: any = undefined; ->a2 : boolean ->false : boolean ->a3 : number ->1 : number ->undefined : undefined - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, -// where N is the numeric index of E in the array assignment pattern, or -var [b0, b1, b2] = [2, 3, 4]; ->b0 : number ->b1 : number ->b2 : number ->[2, 3, 4] : [number, number, number] ->2 : number ->3 : number ->4 : number - -var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : number ->b4 : number ->b5 : string ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - -function foo() { ->foo : () => number[] - - return [1, 2, 3]; ->[1, 2, 3] : number[] ->1 : number ->2 : number ->3 : number -} - -var [b6, b7] = foo(); ->b6 : number ->b7 : number ->foo() : number[] ->foo : () => number[] - -var [...b8] = foo(); ->b8 : number[] ->foo() : number[] ->foo : () => number[] - -// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. -var temp = [1,2,3] ->temp : number[] ->[1,2,3] : number[] ->1 : number ->2 : number ->3 : number - -var [c0, c1] = [...temp]; ->c0 : number ->c1 : number ->[...temp] : number[] ->...temp : number ->temp : number[] - -var [c2] = []; ->c2 : any ->[] : [undefined] - -var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : any ->c4 : any ->[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] ->[[]] : [[undefined]] ->[] : [undefined] ->[[[[]]]] : [[[[undefined]]]] ->[[[]]] : [[[undefined]]] ->[[]] : [[undefined]] ->[] : [undefined] - -var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : string | number ->c6 : boolean ->[[1], true] : [[number], boolean] ->[1] : [number] ->1 : number ->true : boolean - -var [, c7] = [1, 2, 3]; -> : undefined ->c7 : number ->[1, 2, 3] : [number, number, number] ->1 : number ->2 : number ->3 : number - -var [,,, c8] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->c8 : number ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,, c9] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->c9 : number ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,,...c10] = [1, 2, 3, 4, "hello"]; -> : undefined -> : undefined -> : undefined ->c10 : (number | string)[] ->[1, 2, 3, 4, "hello"] : (number | string)[] ->1 : number ->2 : number ->3 : number ->4 : number ->"hello" : string - -var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : number | string ->c12 : number | string ->c13 : (number | string)[] ->[1, 2, "string"] : (number | string)[] ->1 : number ->2 : number ->"string" : string - -var [c14, c15, c16] = [1, 2, "string"]; ->c14 : number ->c15 : number ->c16 : string ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt new file mode 100644 index 00000000000..a847cc44f0c --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt @@ -0,0 +1,64 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(44,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value + + +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts (3 errors) ==== + + /* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + + // In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. + // An expression of type S is considered assignable to an assignment target V if one of the following is true + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is the type Any, or + + var [a0, a1]: any = undefined; + var [a2 = false, a3 = 1]: any = undefined; + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, + // where N is the numeric index of E in the array assignment pattern, or + var [b0, b1, b2] = [2, 3, 4]; + var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + + function foo() { + return [1, 2, 3]; + } + + var [b6, b7] = foo(); + var [...b8] = foo(); + + // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. + var temp = [1,2,3] + var [c0, c1] = [...temp]; + var [c2] = []; + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + var [[c5], c6]: [[string|number], boolean] = [[1], true]; + var [, c7] = [1, 2, 3]; + var [,,, c8] = [1, 2, 3, 4]; + var [,,, c9] = [1, 2, 3, 4]; + var [,,,...c10] = [1, 2, 3, 4, "hello"]; + var [c11, c12, ...c13] = [1, 2, "string"]; + var [c14, c15, c16] = [1, 2, "string"]; \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols deleted file mode 100644 index 33f9b4e88be..00000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols +++ /dev/null @@ -1,105 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts === - -/* AssignmentPattern: - * ObjectAssignmentPattern - * ArrayAssignmentPattern - * ArrayAssignmentPattern: - * [Elision AssignmentRestElementopt ] - * [AssignmentElementList] - * [AssignmentElementList, Elision AssignmentRestElementopt ] - * AssignmentElementList: - * Elision AssignmentElement - * AssignmentElementList, Elisionopt AssignmentElement - * AssignmentElement: - * LeftHandSideExpression Initialiseropt - * AssignmentPattern Initialiseropt - * AssignmentRestElement: - * ... LeftHandSideExpression - */ - -// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. -// An expression of type S is considered assignable to an assignment target V if one of the following is true - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is the type Any, or - -var [a0, a1]: any = undefined; ->a0 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 5)) ->a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 8)) ->undefined : Symbol(undefined) - -var [a2 = false, a3 = 1]: any = undefined; ->a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 5)) ->a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 16)) ->undefined : Symbol(undefined) - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, -// where N is the numeric index of E in the array assignment pattern, or -var [b0, b1, b2] = [2, 3, 4]; ->b0 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 5)) ->b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 8)) ->b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 12)) - -var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 5)) ->b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 8)) ->b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 12)) - -function foo() { ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) - - return [1, 2, 3]; -} - -var [b6, b7] = foo(); ->b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 5)) ->b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 8)) ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) - -var [...b8] = foo(); ->b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 38, 5)) ->foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) - -// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. -var temp = [1,2,3] ->temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) - -var [c0, c1] = [...temp]; ->c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 5)) ->c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 8)) ->temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) - -var [c2] = []; ->c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 43, 5)) - -var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 7)) ->c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 17)) - -var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 6)) ->c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 10)) - -var [, c7] = [1, 2, 3]; ->c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 46, 6)) - -var [,,, c8] = [1, 2, 3, 4]; ->c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 47, 8)) - -var [,,, c9] = [1, 2, 3, 4]; ->c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 48, 8)) - -var [,,,...c10] = [1, 2, 3, 4, "hello"]; ->c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 49, 8)) - -var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 5)) ->c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 9)) ->c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 14)) - -var [c14, c15, c16] = [1, 2, "string"]; ->c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 5)) ->c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 9)) ->c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 14)) - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types deleted file mode 100644 index d154f091214..00000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ /dev/null @@ -1,177 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts === - -/* AssignmentPattern: - * ObjectAssignmentPattern - * ArrayAssignmentPattern - * ArrayAssignmentPattern: - * [Elision AssignmentRestElementopt ] - * [AssignmentElementList] - * [AssignmentElementList, Elision AssignmentRestElementopt ] - * AssignmentElementList: - * Elision AssignmentElement - * AssignmentElementList, Elisionopt AssignmentElement - * AssignmentElement: - * LeftHandSideExpression Initialiseropt - * AssignmentPattern Initialiseropt - * AssignmentRestElement: - * ... LeftHandSideExpression - */ - -// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. -// An expression of type S is considered assignable to an assignment target V if one of the following is true - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is the type Any, or - -var [a0, a1]: any = undefined; ->a0 : any ->a1 : any ->undefined : undefined - -var [a2 = false, a3 = 1]: any = undefined; ->a2 : boolean ->false : boolean ->a3 : number ->1 : number ->undefined : undefined - -// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, -// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, -// where N is the numeric index of E in the array assignment pattern, or -var [b0, b1, b2] = [2, 3, 4]; ->b0 : number ->b1 : number ->b2 : number ->[2, 3, 4] : [number, number, number] ->2 : number ->3 : number ->4 : number - -var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : number ->b4 : number ->b5 : string ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - -function foo() { ->foo : () => number[] - - return [1, 2, 3]; ->[1, 2, 3] : number[] ->1 : number ->2 : number ->3 : number -} - -var [b6, b7] = foo(); ->b6 : number ->b7 : number ->foo() : number[] ->foo : () => number[] - -var [...b8] = foo(); ->b8 : number[] ->foo() : number[] ->foo : () => number[] - -// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. -var temp = [1,2,3] ->temp : number[] ->[1,2,3] : number[] ->1 : number ->2 : number ->3 : number - -var [c0, c1] = [...temp]; ->c0 : number ->c1 : number ->[...temp] : number[] ->...temp : number ->temp : number[] - -var [c2] = []; ->c2 : any ->[] : [undefined] - -var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : any ->c4 : any ->[[[]], [[[[]]]]] : [[[undefined]], [[[[undefined]]]]] ->[[]] : [[undefined]] ->[] : [undefined] ->[[[[]]]] : [[[[undefined]]]] ->[[[]]] : [[[undefined]]] ->[[]] : [[undefined]] ->[] : [undefined] - -var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : string | number ->c6 : boolean ->[[1], true] : [[number], boolean] ->[1] : [number] ->1 : number ->true : boolean - -var [, c7] = [1, 2, 3]; -> : undefined ->c7 : number ->[1, 2, 3] : [number, number, number] ->1 : number ->2 : number ->3 : number - -var [,,, c8] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->c8 : number ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,, c9] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->c9 : number ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,,...c10] = [1, 2, 3, 4, "hello"]; -> : undefined -> : undefined -> : undefined ->c10 : (number | string)[] ->[1, 2, 3, 4, "hello"] : (number | string)[] ->1 : number ->2 : number ->3 : number ->4 : number ->"hello" : string - -var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : number | string ->c12 : number | string ->c13 : (number | string)[] ->[1, 2, "string"] : (number | string)[] ->1 : number ->2 : number ->"string" : string - -var [c14, c15, c16] = [1, 2, "string"]; ->c14 : number ->c15 : number ->c16 : string ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt index a2e5cb7e17c..082bc7aa72a 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2461: Type 'undefined' is not an array type. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. Types of property '1' are incompatible. @@ -18,9 +18,9 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss // S is the type Any, or var [[a0], [[a1]]] = [] // Error ~~~~ -!!! error TS2461: Type 'undefined' is not an array type. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ~~~~~~ -!!! error TS2461: Type 'undefined' is not an array type. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var [[a2], [[a3]]] = undefined // Error ~~~~~~~~~~~~~~ !!! error TS2461: Type 'undefined' is not an array type. diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt index 4cee4314466..709774fb9b4 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs Type '{ i: number; }' is not assignable to type 'number'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,21): error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1180: Property destructuring pattern expected. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,5): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{ d1: any; }'. @@ -30,7 +30,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs !!! error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. var { f2: {f21} = { f212: "string" } }: any = undefined; ~~~ -!!! error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ~~~~ !!! error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. var { ...d1 } = { diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index c024fdfe862..f8188147a79 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } ->f : [number, number, { f3: number; f5: number; }, undefined] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, any]; } +>f : [number, number, { f3: number; f5: number; }, any] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, any] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index 730abd843a2..7b4fe5409db 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -151,9 +151,9 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f4 : number >f5 : number > : undefined ->{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, undefined]; } ->f : [number, number, { f3: number; f5: number; }, undefined] ->[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, undefined] +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }, any]; } +>f : [number, number, { f3: number; f5: number; }, any] +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }, any] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } diff --git a/tests/baselines/reference/downlevelLetConst12.errors.txt b/tests/baselines/reference/downlevelLetConst12.errors.txt new file mode 100644 index 00000000000..f29d9435dbb --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst12.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/downlevelLetConst12.ts(7,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/downlevelLetConst12.ts(10,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value + + +==== tests/cases/compiler/downlevelLetConst12.ts (2 errors) ==== + + 'use strict' + // top level let\const should not be renamed + let foo; + const bar = 1; + + let [baz] = []; + ~~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + let {a: baz2} = { a: 1 }; + + const [baz3] = [] + ~~~~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + const {a: baz4} = { a: 1 }; \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst12.symbols b/tests/baselines/reference/downlevelLetConst12.symbols deleted file mode 100644 index 97d6d5eebf8..00000000000 --- a/tests/baselines/reference/downlevelLetConst12.symbols +++ /dev/null @@ -1,26 +0,0 @@ -=== tests/cases/compiler/downlevelLetConst12.ts === - -'use strict' -// top level let\const should not be renamed -let foo; ->foo : Symbol(foo, Decl(downlevelLetConst12.ts, 3, 3)) - -const bar = 1; ->bar : Symbol(bar, Decl(downlevelLetConst12.ts, 4, 5)) - -let [baz] = []; ->baz : Symbol(baz, Decl(downlevelLetConst12.ts, 6, 5)) - -let {a: baz2} = { a: 1 }; ->a : Symbol(a, Decl(downlevelLetConst12.ts, 7, 17)) ->baz2 : Symbol(baz2, Decl(downlevelLetConst12.ts, 7, 5)) ->a : Symbol(a, Decl(downlevelLetConst12.ts, 7, 17)) - -const [baz3] = [] ->baz3 : Symbol(baz3, Decl(downlevelLetConst12.ts, 9, 7)) - -const {a: baz4} = { a: 1 }; ->a : Symbol(a, Decl(downlevelLetConst12.ts, 10, 19)) ->baz4 : Symbol(baz4, Decl(downlevelLetConst12.ts, 10, 7)) ->a : Symbol(a, Decl(downlevelLetConst12.ts, 10, 19)) - diff --git a/tests/baselines/reference/downlevelLetConst12.types b/tests/baselines/reference/downlevelLetConst12.types deleted file mode 100644 index a6146b55dd7..00000000000 --- a/tests/baselines/reference/downlevelLetConst12.types +++ /dev/null @@ -1,35 +0,0 @@ -=== tests/cases/compiler/downlevelLetConst12.ts === - -'use strict' ->'use strict' : string - -// top level let\const should not be renamed -let foo; ->foo : any - -const bar = 1; ->bar : number ->1 : number - -let [baz] = []; ->baz : any ->[] : [undefined] - -let {a: baz2} = { a: 1 }; ->a : any ->baz2 : number ->{ a: 1 } : { a: number; } ->a : number ->1 : number - -const [baz3] = [] ->baz3 : any ->[] : [undefined] - -const {a: baz4} = { a: 1 }; ->a : any ->baz4 : number ->{ a: 1 } : { a: number; } ->a : number ->1 : number - diff --git a/tests/baselines/reference/downlevelLetConst16.errors.txt b/tests/baselines/reference/downlevelLetConst16.errors.txt index 94c53360b87..43acc162d7a 100644 --- a/tests/baselines/reference/downlevelLetConst16.errors.txt +++ b/tests/baselines/reference/downlevelLetConst16.errors.txt @@ -1,10 +1,12 @@ +tests/cases/compiler/downlevelLetConst16.ts(151,15): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/downlevelLetConst16.ts(164,17): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/compiler/downlevelLetConst16.ts(195,14): error TS2461: Type 'undefined' is not an array type. tests/cases/compiler/downlevelLetConst16.ts(202,15): error TS2459: Type 'undefined' has no property 'a' and no string index signature. tests/cases/compiler/downlevelLetConst16.ts(216,16): error TS2461: Type 'undefined' is not an array type. tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefined' has no property 'a' and no string index signature. -==== tests/cases/compiler/downlevelLetConst16.ts (4 errors) ==== +==== tests/cases/compiler/downlevelLetConst16.ts (6 errors) ==== 'use strict' declare function use(a: any); @@ -156,6 +158,8 @@ tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefin use(x); } for (let [y] = []; ;) { + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value use(y); } for (let {a: z} = {a: 1}; ;) { @@ -169,6 +173,8 @@ tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefin use(x); } for (const [y] = []; ;) { + ~ +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value use(y); } for (const {a: z} = { a: 1 }; ;) { diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt index 294b564a239..6b015001829 100644 --- a/tests/baselines/reference/missingAndExcessProperties.errors.txt +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -1,11 +1,15 @@ -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2459: Type '{}' has no property 'x' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2459: Type '{}' has no property 'y' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2459: Type '{}' has no property 'x' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2459: Type '{}' has no property 'y' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,14): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(6,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(6,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(21,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -16,21 +20,29 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(30,22): tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. -==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (16 errors) ==== +==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (20 errors) ==== // Missing properties function f1() { var { x, y } = {}; ~ -!!! error TS2459: Type '{}' has no property 'x' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ~ -!!! error TS2459: Type '{}' has no property 'y' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var { x = 1, y } = {}; + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. ~ -!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value var { x, y = 1 } = {}; ~ -!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. var { x = 1, y = 1 } = {}; + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. } // Missing properties @@ -38,15 +50,15 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): var x: number, y: number; ({ x, y } = {}); ~ -!!! error TS2459: Type '{}' has no property 'x' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ~ -!!! error TS2459: Type '{}' has no property 'y' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ({ x: x = 1, y } = {}); ~ -!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ({ x, y: y = 1 } = {}); ~ -!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value ({ x: x = 1, y: y = 1 } = {}); } From 297c60ea01091a1fc65e4fdc301ee5e8303e42d8 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 10 Sep 2015 16:42:02 -0700 Subject: [PATCH 53/56] addressed PR feedback --- src/compiler/diagnosticInformationMap.generated.ts | 4 ++-- src/compiler/diagnosticMessages.json | 4 ++-- src/compiler/program.ts | 12 ++++++------ src/compiler/types.ts | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index efe4ba20d49..3775c9ce405 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -428,8 +428,8 @@ namespace ts { 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}'." }, - Proper_external_module_that_carries_external_typings_cannot_contain_tripleslash_references: { code: 2654, category: DiagnosticCategory.Error, key: "Proper external module that carries external typings cannot contain tripleslash references." }, - Proper_external_module_that_carries_external_typings_should_be_d_ts_file: { code: 2655, category: DiagnosticCategory.Error, key: "Proper external module that carries external typings should be '.d.ts' file." }, + Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition: { code: 2654, category: DiagnosticCategory.Error, key: "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition." }, + Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition: { code: 2655, category: DiagnosticCategory.Error, key: "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition." }, 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 c62f08555df..79fd114e9a3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1701,11 +1701,11 @@ "category": "Error", "code": 2653 }, - "Proper external module that carries external typings cannot contain tripleslash references.": { + "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition.": { "category": "Error", "code": 2654 }, - "Proper external module that carries external typings should be '.d.ts' file.": { + "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition.": { "category": "Error", "code": 2655 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ff3f5c2ba8a..790d121d135 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -129,12 +129,12 @@ namespace ts { let candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName)); let result = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedModule: { resolvedFileName: result, shouldBeProperExternalModule: true }, failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations }; } result = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedModule: { resolvedFileName: result, shouldBeProperExternalModule: true }, failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations }; } } @@ -472,7 +472,7 @@ namespace ts { let resolutionChanged = oldResolution ? !newResolution || oldResolution.resolvedFileName !== newResolution.resolvedFileName || - !!oldResolution.shouldBeProperExternalModule !== !!newResolution.shouldBeProperExternalModule + !!oldResolution.isExternalLibraryImport !== !!newResolution.isExternalLibraryImport : newResolution; if (resolutionChanged) { @@ -850,18 +850,18 @@ namespace ts { setResolvedModule(file, moduleNames[i], resolution); if (resolution && !options.noResolve) { const importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]); - if (importedFile && resolution.shouldBeProperExternalModule) { + if (importedFile && resolution.isExternalLibraryImport) { if (!isExternalModule(importedFile)) { let start = getTokenPosOfNode(file.imports[i], file) diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.File_0_is_not_a_module, importedFile.fileName)); } else if (!fileExtensionIs(importedFile.fileName, ".d.ts")) { let start = getTokenPosOfNode(file.imports[i], file) - diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Proper_external_module_that_carries_external_typings_should_be_d_ts_file)); + diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); } else if (importedFile.referencedFiles.length) { let firstRef = importedFile.referencedFiles[0]; - diagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Proper_external_module_that_carries_external_typings_cannot_contain_tripleslash_references)); + diagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d7bc6b4edbc..fd21cc79ab6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2270,12 +2270,12 @@ namespace ts { export interface ResolvedModule { resolvedFileName: string; /* - * Denotes if 'resolvedFileName' should be proper external module: + * Denotes if 'resolvedFileName' is isExternalLibraryImport and thus should be proper external module: * - be a .d.ts file * - use top level imports\exports * - don't use tripleslash references */ - shouldBeProperExternalModule?: boolean; + isExternalLibraryImport?: boolean; } export interface ResolvedModuleWithFailedLookupLocations { From 87e1569d1f759bb43707ac2f8ae5c1aec645de90 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 10 Sep 2015 17:00:29 -0700 Subject: [PATCH 54/56] resolve merge conflicts, update tests --- src/compiler/program.ts | 6 +++--- tests/baselines/reference/nodeResolution6.errors.txt | 4 ++-- tests/baselines/reference/nodeResolution8.errors.txt | 4 ++-- tests/cases/unittests/moduleResolution.ts | 10 +++++----- tests/cases/unittests/reuseProgramStructure.ts | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 92fbfebce6c..28dd477666b 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -863,15 +863,15 @@ namespace ts { if (importedFile && resolution.isExternalLibraryImport) { if (!isExternalModule(importedFile)) { let start = getTokenPosOfNode(file.imports[i], file) - diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.File_0_is_not_a_module, importedFile.fileName)); + fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.File_0_is_not_a_module, importedFile.fileName)); } else if (!fileExtensionIs(importedFile.fileName, ".d.ts")) { let start = getTokenPosOfNode(file.imports[i], file) - diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); + fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); } else if (importedFile.referencedFiles.length) { let firstRef = importedFile.referencedFiles[0]; - diagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); + fileProcessingDiagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); } } } diff --git a/tests/baselines/reference/nodeResolution6.errors.txt b/tests/baselines/reference/nodeResolution6.errors.txt index 8a462043207..6bab6e34389 100644 --- a/tests/baselines/reference/nodeResolution6.errors.txt +++ b/tests/baselines/reference/nodeResolution6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/node_modules/a.d.ts(1,1): error TS2654: Proper external module that carries external typings cannot contain tripleslash references. +tests/cases/compiler/node_modules/a.d.ts(1,1): error TS2654: Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition. ==== tests/cases/compiler/b.ts (0 errors) ==== @@ -11,7 +11,7 @@ tests/cases/compiler/node_modules/a.d.ts(1,1): error TS2654: Proper external mod ==== tests/cases/compiler/node_modules/a.d.ts (1 errors) ==== /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2654: Proper external module that carries external typings cannot contain tripleslash references. +!!! error TS2654: Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition. export declare var y; \ No newline at end of file diff --git a/tests/baselines/reference/nodeResolution8.errors.txt b/tests/baselines/reference/nodeResolution8.errors.txt index 82753a2049b..3f14a4313c8 100644 --- a/tests/baselines/reference/nodeResolution8.errors.txt +++ b/tests/baselines/reference/nodeResolution8.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/node_modules/a/index.d.ts(1,1): error TS2654: Proper external module that carries external typings cannot contain tripleslash references. +tests/cases/compiler/node_modules/a/index.d.ts(1,1): error TS2654: Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition. ==== tests/cases/compiler/b.ts (0 errors) ==== @@ -10,7 +10,7 @@ tests/cases/compiler/node_modules/a/index.d.ts(1,1): error TS2654: Proper extern ==== tests/cases/compiler/node_modules/a/index.d.ts (1 errors) ==== /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2654: Proper external module that carries external typings cannot contain tripleslash references. +!!! error TS2654: Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition. export declare var y; \ No newline at end of file diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index ab12119ec5a..ed9f0b0a986 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -41,7 +41,7 @@ module ts { let moduleFile = { name: moduleFileNameNoExt + ext } let resolution = nodeModuleNameResolver(moduleName, containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); + assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); let failedLookupLocations: string[] = []; let dir = getDirectoryPath(containingFileName); @@ -80,7 +80,7 @@ module ts { let moduleFile = { name: moduleFileName }; let resolution = nodeModuleNameResolver(moduleName, containingFile.name, createModuleResolutionHost(containingFile, packageJson, moduleFile)); assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); + assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); // expect three failed lookup location - attempt to load module as file with all supported extensions assert.equal(resolution.failedLookupLocations.length, 3); } @@ -98,7 +98,7 @@ module ts { let indexFile = { name: "/a/b/foo/index.d.ts" }; let resolution = nodeModuleNameResolver("./foo", containingFile.name, createModuleResolutionHost(containingFile, packageJson, indexFile)); assert.equal(resolution.resolvedModule.resolvedFileName, indexFile.name); - assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); + assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); assert.deepEqual(resolution.failedLookupLocations, [ "/a/b/foo.ts", "/a/b/foo.tsx", @@ -139,7 +139,7 @@ module ts { let moduleFile = { name: "/a/b/node_modules/foo.d.ts" }; let resolution = nodeModuleNameResolver("foo", containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(resolution.resolvedModule.shouldBeProperExternalModule, true); + assert.equal(resolution.resolvedModule.isExternalLibraryImport, true); }); it("load module as directory", () => { @@ -147,7 +147,7 @@ module ts { let moduleFile = { name: "/a/node_modules/foo/index.d.ts" }; let resolution = nodeModuleNameResolver("foo", containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(resolution.resolvedModule.shouldBeProperExternalModule, true); + assert.equal(resolution.resolvedModule.isExternalLibraryImport, true); assert.deepEqual(resolution.failedLookupLocations, [ "/a/node_modules/b/c/node_modules/d/node_modules/foo.d.ts", "/a/node_modules/b/c/node_modules/d/node_modules/foo/package.json", diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index 4d167cb1bb0..5f313eeae2b 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -180,7 +180,7 @@ module ts { const actual = file.resolvedModules[id]; assert.isTrue(actual !== undefined); assert.isTrue(expected.resolvedFileName === actual.resolvedFileName, `'resolvedFileName': expected '${expected.resolvedFileName}' to be equal to '${actual.resolvedFileName}'`); - assert.isTrue(expected.shouldBeProperExternalModule === actual.shouldBeProperExternalModule, `'shouldBeProperExternalModule': expected '${expected.shouldBeProperExternalModule}' to be equal to '${actual.shouldBeProperExternalModule}'`); + assert.isTrue(expected.isExternalLibraryImport === actual.isExternalLibraryImport, `'shouldBeProperExternalModule': expected '${expected.isExternalLibraryImport}' to be equal to '${actual.isExternalLibraryImport}'`); } else { assert.isTrue(file.resolvedModules[id] === undefined); From 262f122d997c1f82ebfb517a1986d398658591ed Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 10 Sep 2015 17:03:13 -0700 Subject: [PATCH 55/56] Adding "." to error message --- .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- ...nEmitDestructuringArrayPattern2.errors.txt | 12 +++---- .../declarationsAndAssignments.errors.txt | 32 +++++++++---------- ...BindingPatternAndAssignment1ES5.errors.txt | 12 +++---- ...BindingPatternAndAssignment1ES6.errors.txt | 12 +++---- ...rayBindingPatternAndAssignment2.errors.txt | 8 ++--- ...ectBindingPatternAndAssignment3.errors.txt | 4 +-- .../reference/downlevelLetConst12.errors.txt | 8 ++--- .../reference/downlevelLetConst16.errors.txt | 8 ++--- .../missingAndExcessProperties.errors.txt | 32 +++++++++---------- 11 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 9686d6580f5..4f53537d0c3 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -415,7 +415,7 @@ namespace ts { The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." }, yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." }, await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." }, - Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value" }, + Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value." }, JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." }, The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." }, JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 515afda49aa..33749f67285 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1649,7 +1649,7 @@ "category": "Error", "code": 2524 }, - "Initializer provides no value for this binding element and the binding element has no default value": { + "Initializer provides no value for this binding element and the binding element has no default value.": { "category": "Error", "code": 2525 }, diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt index ea5b38a3b2f..26998fd83ae 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ==== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts (3 errors) ==== @@ -9,11 +9,11 @@ tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts(4,16): error T var [x11 = 0, y11 = ""] = [1, "hello"]; var [a11, b11, c11] = []; ~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index cd72c12951c..7c4671022ea 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(23,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -6,15 +6,15 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(24,19): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(28,28): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(29,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(56,17): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,10): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,10): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,11): error TS2459: Type 'undefined[]' has no property 'a' and no string index signature. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,14): error TS2459: Type 'undefined[]' has no property 'b' and no string index signature. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(106,5): error TS2345: Argument of type '[number, [string, { y: boolean; }]]' is not assignable to parameter of type '[number, [string, { x: any; y?: boolean; }]]'. @@ -34,7 +34,7 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): var [x, y] = [1, "hello"]; var [x, y, z] = [1, "hello"]; ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [,, x] = [0, 1, 2]; var x: number; var y: string; @@ -107,16 +107,16 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f8() { var [a, b, c] = []; // Ok, [] is an array ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [d, e, f] = [1]; // Error, [1] is a tuple ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. } function f9() { @@ -132,9 +132,9 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f10() { var { a, b } = {}; // Error ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var { a, b } = []; // Error ~ !!! error TS2459: Type 'undefined[]' has no property 'a' and no string index signature. diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt index 5fd60c296c9..1f1bc85757b 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(43,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(43,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts(44,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts (3 errors) ==== @@ -48,12 +48,12 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss var [c0, c1] = [...temp]; var [c2] = []; ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [[c5], c6]: [[string|number], boolean] = [[1], true]; var [, c7] = [1, 2, 3]; var [,,, c8] = [1, 2, 3, 4]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt index a847cc44f0c..beefbc9a85b 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(44,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(44,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts(45,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts (3 errors) ==== @@ -49,12 +49,12 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss var [c0, c1] = [...temp]; var [c2] = []; ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [[c5], c6]: [[string|number], boolean] = [[1], true]; var [, c7] = [1, 2, 3]; var [,,, c8] = [1, 2, 3, 4]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt index 082bc7aa72a..91405285973 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type. tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. Types of property '1' are incompatible. @@ -18,9 +18,9 @@ tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAss // S is the type Any, or var [[a0], [[a1]]] = [] // Error ~~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~~~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var [[a2], [[a3]]] = undefined // Error ~~~~~~~~~~~~~~ !!! error TS2461: Type 'undefined' is not an array type. diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt index 709774fb9b4..bb4b79987e3 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs Type '{ i: number; }' is not assignable to type 'number'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,21): error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1180: Property destructuring pattern expected. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,5): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{ d1: any; }'. @@ -30,7 +30,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs !!! error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. var { f2: {f21} = { f212: "string" } }: any = undefined; ~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~~~ !!! error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. var { ...d1 } = { diff --git a/tests/baselines/reference/downlevelLetConst12.errors.txt b/tests/baselines/reference/downlevelLetConst12.errors.txt index f29d9435dbb..0af224b017e 100644 --- a/tests/baselines/reference/downlevelLetConst12.errors.txt +++ b/tests/baselines/reference/downlevelLetConst12.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/downlevelLetConst12.ts(7,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/compiler/downlevelLetConst12.ts(10,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/downlevelLetConst12.ts(7,6): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/compiler/downlevelLetConst12.ts(10,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ==== tests/cases/compiler/downlevelLetConst12.ts (2 errors) ==== @@ -11,10 +11,10 @@ tests/cases/compiler/downlevelLetConst12.ts(10,8): error TS2525: Initializer pro let [baz] = []; ~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. let {a: baz2} = { a: 1 }; const [baz3] = [] ~~~~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. const {a: baz4} = { a: 1 }; \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst16.errors.txt b/tests/baselines/reference/downlevelLetConst16.errors.txt index 43acc162d7a..905d1a607e8 100644 --- a/tests/baselines/reference/downlevelLetConst16.errors.txt +++ b/tests/baselines/reference/downlevelLetConst16.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/downlevelLetConst16.ts(151,15): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/compiler/downlevelLetConst16.ts(164,17): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/compiler/downlevelLetConst16.ts(151,15): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/compiler/downlevelLetConst16.ts(164,17): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/compiler/downlevelLetConst16.ts(195,14): error TS2461: Type 'undefined' is not an array type. tests/cases/compiler/downlevelLetConst16.ts(202,15): error TS2459: Type 'undefined' has no property 'a' and no string index signature. tests/cases/compiler/downlevelLetConst16.ts(216,16): error TS2461: Type 'undefined' is not an array type. @@ -159,7 +159,7 @@ tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefin } for (let [y] = []; ;) { ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. use(y); } for (let {a: z} = {a: 1}; ;) { @@ -174,7 +174,7 @@ tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefin } for (const [y] = []; ;) { ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. use(y); } for (const {a: z} = { a: 1 }; ;) { diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt index 6b015001829..0ee69d9af30 100644 --- a/tests/baselines/reference/missingAndExcessProperties.errors.txt +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -1,15 +1,15 @@ -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,14): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(6,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(6,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(21,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -25,17 +25,17 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): function f1() { var { x, y } = {}; ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var { x = 1, y } = {}; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var { x, y = 1 } = {}; ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. var { x = 1, y = 1 } = {}; @@ -50,15 +50,15 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): var x: number, y: number; ({ x, y } = {}); ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ({ x: x = 1, y } = {}); ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ({ x, y: y = 1 } = {}); ~ -!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value +!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ({ x: x = 1, y: y = 1 } = {}); } From c72469a66f6809e092c14b860286cccdefdd787c Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 11 Sep 2015 09:36:17 -0700 Subject: [PATCH 56/56] emit export specifiers in system modules only if export has a value side --- src/compiler/emitter.ts | 6 +- tests/baselines/reference/systemModule17.js | 84 ++++++++++++++++ .../reference/systemModule17.symbols | 93 ++++++++++++++++++ .../baselines/reference/systemModule17.types | 95 +++++++++++++++++++ tests/cases/compiler/systemModule17.ts | 41 ++++++++ 5 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/systemModule17.js create mode 100644 tests/baselines/reference/systemModule17.symbols create mode 100644 tests/baselines/reference/systemModule17.types create mode 100644 tests/cases/compiler/systemModule17.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d84b7b70ada..d3a7615a27f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3142,6 +3142,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitExportSpecifierInSystemModule(specifier: ExportSpecifier): void { Debug.assert(compilerOptions.module === ModuleKind.System); + + if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier) ) { + return; + } writeLine(); emitStart(specifier.name); @@ -6089,7 +6093,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return; } - if (isInternalModuleImportEqualsDeclaration(node)) { + if (isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { if (!hoistedVars) { hoistedVars = []; } diff --git a/tests/baselines/reference/systemModule17.js b/tests/baselines/reference/systemModule17.js new file mode 100644 index 00000000000..90efdc8872a --- /dev/null +++ b/tests/baselines/reference/systemModule17.js @@ -0,0 +1,84 @@ +//// [tests/cases/compiler/systemModule17.ts] //// + +//// [f1.ts] + + +export class A {} +export interface I {} + +//// [f2.ts] + +var x = 1; +interface I { } + +namespace N { + export var x = 1; + export interface I { } +} + +import IX = N.x; +import II = N.I; +import { A, A as EA, I as EI } from "f1"; + +export {x}; +export {x as x1}; + +export {I}; +export {I as I1}; + +export {A}; +export {A as A1}; + +export {EA}; +export {EA as EA1}; + +export {EI }; +export {EI as EI1}; + +export {IX}; +export {IX as IX1}; + +export {II}; +export {II as II1}; + +//// [f1.js] +System.register([], function(exports_1) { + var A; + return { + setters:[], + execute: function() { + A = (function () { + function A() { + } + return A; + })(); + exports_1("A", A); + } + } +}); +//// [f2.js] +System.register(["f1"], function(exports_1) { + var f1_1; + var x, N, IX; + return { + setters:[ + function (f1_1_1) { + f1_1 = f1_1_1; + }], + execute: function() { + x = 1; + (function (N) { + N.x = 1; + })(N || (N = {})); + IX = N.x; + exports_1("x", x); + exports_1("x1", x); + exports_1("A", f1_1.A); + exports_1("A1", f1_1.A); + exports_1("EA", f1_1.A); + exports_1("EA1", f1_1.A); + exports_1("IX", IX); + exports_1("IX1", IX); + } + } +}); diff --git a/tests/baselines/reference/systemModule17.symbols b/tests/baselines/reference/systemModule17.symbols new file mode 100644 index 00000000000..3bf19dad950 --- /dev/null +++ b/tests/baselines/reference/systemModule17.symbols @@ -0,0 +1,93 @@ +=== tests/cases/compiler/f1.ts === + + +export class A {} +>A : Symbol(A, Decl(f1.ts, 0, 0)) + +export interface I {} +>I : Symbol(I, Decl(f1.ts, 2, 17)) + +=== tests/cases/compiler/f2.ts === + +var x = 1; +>x : Symbol(x, Decl(f2.ts, 1, 3)) + +interface I { } +>I : Symbol(I, Decl(f2.ts, 1, 10)) + +namespace N { +>N : Symbol(N, Decl(f2.ts, 2, 15)) + + export var x = 1; +>x : Symbol(x, Decl(f2.ts, 5, 11)) + + export interface I { } +>I : Symbol(I, Decl(f2.ts, 5, 18)) +} + +import IX = N.x; +>IX : Symbol(IX, Decl(f2.ts, 7, 1)) +>N : Symbol(N, Decl(f2.ts, 2, 15)) +>x : Symbol(IX, Decl(f2.ts, 5, 11)) + +import II = N.I; +>II : Symbol(II, Decl(f2.ts, 9, 16)) +>N : Symbol(N, Decl(f2.ts, 2, 15)) +>I : Symbol(II, Decl(f2.ts, 5, 18)) + +import { A, A as EA, I as EI } from "f1"; +>A : Symbol(A, Decl(f2.ts, 11, 8)) +>A : Symbol(EA, Decl(f2.ts, 11, 11)) +>EA : Symbol(EA, Decl(f2.ts, 11, 11)) +>I : Symbol(EI, Decl(f2.ts, 11, 20)) +>EI : Symbol(EI, Decl(f2.ts, 11, 20)) + +export {x}; +>x : Symbol(x, Decl(f2.ts, 13, 8)) + +export {x as x1}; +>x : Symbol(x1, Decl(f2.ts, 14, 8)) +>x1 : Symbol(x1, Decl(f2.ts, 14, 8)) + +export {I}; +>I : Symbol(I, Decl(f2.ts, 16, 8)) + +export {I as I1}; +>I : Symbol(I1, Decl(f2.ts, 17, 8)) +>I1 : Symbol(I1, Decl(f2.ts, 17, 8)) + +export {A}; +>A : Symbol(A, Decl(f2.ts, 19, 8)) + +export {A as A1}; +>A : Symbol(A1, Decl(f2.ts, 20, 8)) +>A1 : Symbol(A1, Decl(f2.ts, 20, 8)) + +export {EA}; +>EA : Symbol(EA, Decl(f2.ts, 22, 8)) + +export {EA as EA1}; +>EA : Symbol(EA1, Decl(f2.ts, 23, 8)) +>EA1 : Symbol(EA1, Decl(f2.ts, 23, 8)) + +export {EI }; +>EI : Symbol(EI, Decl(f2.ts, 25, 8)) + +export {EI as EI1}; +>EI : Symbol(EI1, Decl(f2.ts, 26, 8)) +>EI1 : Symbol(EI1, Decl(f2.ts, 26, 8)) + +export {IX}; +>IX : Symbol(IX, Decl(f2.ts, 28, 8)) + +export {IX as IX1}; +>IX : Symbol(IX1, Decl(f2.ts, 29, 8)) +>IX1 : Symbol(IX1, Decl(f2.ts, 29, 8)) + +export {II}; +>II : Symbol(II, Decl(f2.ts, 31, 8)) + +export {II as II1}; +>II : Symbol(II1, Decl(f2.ts, 32, 8)) +>II1 : Symbol(II1, Decl(f2.ts, 32, 8)) + diff --git a/tests/baselines/reference/systemModule17.types b/tests/baselines/reference/systemModule17.types new file mode 100644 index 00000000000..1f0b1b51842 --- /dev/null +++ b/tests/baselines/reference/systemModule17.types @@ -0,0 +1,95 @@ +=== tests/cases/compiler/f1.ts === + + +export class A {} +>A : A + +export interface I {} +>I : I + +=== tests/cases/compiler/f2.ts === + +var x = 1; +>x : number +>1 : number + +interface I { } +>I : I + +namespace N { +>N : typeof N + + export var x = 1; +>x : number +>1 : number + + export interface I { } +>I : I +} + +import IX = N.x; +>IX : number +>N : typeof N +>x : number + +import II = N.I; +>II : any +>N : typeof N +>I : II + +import { A, A as EA, I as EI } from "f1"; +>A : typeof A +>A : typeof A +>EA : typeof A +>I : any +>EI : any + +export {x}; +>x : number + +export {x as x1}; +>x : number +>x1 : number + +export {I}; +>I : any + +export {I as I1}; +>I : any +>I1 : any + +export {A}; +>A : typeof A + +export {A as A1}; +>A : typeof A +>A1 : typeof A + +export {EA}; +>EA : typeof A + +export {EA as EA1}; +>EA : typeof A +>EA1 : typeof A + +export {EI }; +>EI : any + +export {EI as EI1}; +>EI : any +>EI1 : any + +export {IX}; +>IX : number + +export {IX as IX1}; +>IX : number +>IX1 : number + +export {II}; +>II : any + +export {II as II1}; +>II : any +>II1 : any + diff --git a/tests/cases/compiler/systemModule17.ts b/tests/cases/compiler/systemModule17.ts new file mode 100644 index 00000000000..f6b6d6ea2f2 --- /dev/null +++ b/tests/cases/compiler/systemModule17.ts @@ -0,0 +1,41 @@ +// @module: system + +// @filename: f1.ts + +export class A {} +export interface I {} + +// @filename: f2.ts + +var x = 1; +interface I { } + +namespace N { + export var x = 1; + export interface I { } +} + +import IX = N.x; +import II = N.I; +import { A, A as EA, I as EI } from "f1"; + +export {x}; +export {x as x1}; + +export {I}; +export {I as I1}; + +export {A}; +export {A as A1}; + +export {EA}; +export {EA as EA1}; + +export {EI }; +export {EI as EI1}; + +export {IX}; +export {IX as IX1}; + +export {II}; +export {II as II1}; \ No newline at end of file