From f9eddcebc8cbfe0e37e7abbfe042bec5aa33062a Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Tue, 26 Jan 2016 13:43:53 -0700 Subject: [PATCH 001/297] Update Array.concat type signature to fix #6594 --- src/lib/core.d.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index dbd4d37ef96..05da0e8057a 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1011,12 +1011,7 @@ interface Array { * Combines two or more arrays. * @param items Additional items to add to the end of array1. */ - concat(...items: U[]): T[]; - /** - * Combines two or more arrays. - * @param items Additional items to add to the end of array1. - */ - concat(...items: T[]): T[]; + concat(...items: (T | T[])[]): T[]; /** * Adds all the elements of an array separated by the specified separator string. * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma. From 2c25bea0aaec64e17e12b0c11f456a821abb3064 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 2 Feb 2016 13:10:30 -0800 Subject: [PATCH 002/297] Always show file tokens in JS completion lists Fixes #6654 --- src/services/services.ts | 2 +- .../fourslash/getJavaScriptGlobalCompletions1.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/getJavaScriptGlobalCompletions1.ts diff --git a/src/services/services.ts b/src/services/services.ts index 85b2bfb58e8..1204b63c9fb 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3834,7 +3834,7 @@ namespace ts { const entries: CompletionEntry[] = []; - if (isRightOfDot && isSourceFileJavaScript(sourceFile)) { + if (isSourceFileJavaScript(sourceFile)) { const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries); addRange(entries, getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames)); } diff --git a/tests/cases/fourslash/getJavaScriptGlobalCompletions1.ts b/tests/cases/fourslash/getJavaScriptGlobalCompletions1.ts new file mode 100644 index 00000000000..240df24bf52 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptGlobalCompletions1.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: Foo.js +//// function f() { +//// // helloWorld leaks from here into the global space? +//// if (helloWorld) { +//// return 3; +//// } +//// return 5; +//// } +//// +//// hello/**/ + +verify.completionListContains('helloWorld'); From 6e06bb39a13281c6080e973e1a015aea66e8b9ce Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 2 Feb 2016 13:32:21 -0800 Subject: [PATCH 003/297] Allow parsing TS-style generics in JSDoc Fixes #6814 --- src/compiler/parser.ts | 20 +++++++++++++------- tests/cases/fourslash/jsDocGenerics1.ts | 10 ++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 tests/cases/fourslash/jsDocGenerics1.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b6ba02b987c..99ceafb15cb 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5734,16 +5734,22 @@ namespace ts { const result = createNode(SyntaxKind.JSDocTypeReference); result.name = parseSimplePropertyName(); - while (parseOptional(SyntaxKind.DotToken)) { - if (token === SyntaxKind.LessThanToken) { - result.typeArguments = parseTypeArguments(); - break; - } - else { - result.name = parseQualifiedName(result.name); + if (token === SyntaxKind.LessThanToken) { + result.typeArguments = parseTypeArguments(); + } + else { + while (parseOptional(SyntaxKind.DotToken)) { + if (token === SyntaxKind.LessThanToken) { + result.typeArguments = parseTypeArguments(); + break; + } + else { + result.name = parseQualifiedName(result.name); + } } } + return finishNode(result); } diff --git a/tests/cases/fourslash/jsDocGenerics1.ts b/tests/cases/fourslash/jsDocGenerics1.ts new file mode 100644 index 00000000000..3b5742af8b1 --- /dev/null +++ b/tests/cases/fourslash/jsDocGenerics1.ts @@ -0,0 +1,10 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: Foo.js +//// /** @type {Array} */ +//// var v; +//// v[0]./**/ + +goTo.marker(); +verify.memberListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method"); From 018429bd6ec9629b338c6a591b723d1f33f1ca4f Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 2 Feb 2016 13:39:02 -0800 Subject: [PATCH 004/297] :heart: linter --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 1204b63c9fb..6761c487c6c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3823,7 +3823,7 @@ namespace ts { return undefined; } - const { symbols, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot, isJsDocTagName } = completionData; + const { symbols, isMemberCompletion, isNewIdentifierLocation, location, isJsDocTagName } = completionData; if (isJsDocTagName) { // If the current position is a jsDoc tag name, only tag names should be provided for completion From 202452b521c54237a157d06159896e20cc8c57be Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 2 Feb 2016 15:53:20 -0800 Subject: [PATCH 005/297] emit import declarations without import clause in .d.ts files --- src/compiler/declarationEmitter.ts | 4 ---- tests/baselines/reference/es6ImportWithoutFromClause.js | 1 + tests/baselines/reference/es6ImportWithoutFromClauseAmd.js | 2 ++ tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js | 1 + .../es6ImportWithoutFromClauseNonInstantiatedModule.js | 1 + .../moduleAugmentationCollidingNamesInAugmentation1.js | 2 ++ .../baselines/reference/moduleAugmentationDeclarationEmit1.js | 1 + .../baselines/reference/moduleAugmentationDeclarationEmit2.js | 1 + .../reference/moduleAugmentationExtendAmbientModule2.js | 1 + tests/baselines/reference/moduleAugmentationGlobal3.js | 1 + tests/baselines/reference/moduleAugmentationGlobal4.js | 2 ++ tests/baselines/reference/moduleAugmentationGlobal5.js | 2 ++ .../reference/moduleAugmentationImportsAndExports1.js | 1 + .../reference/moduleAugmentationImportsAndExports2.js | 1 + .../reference/moduleAugmentationImportsAndExports3.js | 1 + .../reference/moduleAugmentationImportsAndExports5.js | 1 + .../reference/moduleAugmentationImportsAndExports6.js | 1 + .../baselines/reference/moduleAugmentationInAmbientModule5.js | 1 + .../baselines/reference/moduleAugmentationsBundledOutput1.js | 2 ++ tests/baselines/reference/moduleAugmentationsImports1.js | 1 + tests/baselines/reference/moduleAugmentationsImports2.js | 2 ++ tests/baselines/reference/moduleAugmentationsImports3.js | 2 ++ tests/baselines/reference/moduleAugmentationsImports4.js | 2 ++ 23 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index ab0b16947fc..5977c84d7f4 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -698,10 +698,6 @@ namespace ts { } function writeImportDeclaration(node: ImportDeclaration) { - if (!node.importClause && !(node.flags & NodeFlags.Export)) { - // do not write non-exported import declarations that don't have import clauses - return; - } emitJsDocComments(node); if (node.flags & NodeFlags.Export) { write("export "); diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index 9666409b924..cc8509baade 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -17,3 +17,4 @@ import "es6ImportWithoutFromClause_0"; //// [es6ImportWithoutFromClause_0.d.ts] export declare var a: number; //// [es6ImportWithoutFromClause_1.d.ts] +import "es6ImportWithoutFromClause_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js index 39b6b04464c..ea533a9a963 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js @@ -36,3 +36,5 @@ export declare var a: number; //// [es6ImportWithoutFromClauseAmd_1.d.ts] export declare var b: number; //// [es6ImportWithoutFromClauseAmd_2.d.ts] +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js index c39cd1172a0..d0f7c9fbe65 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js @@ -18,3 +18,4 @@ require("es6ImportWithoutFromClauseInEs5_0"); //// [es6ImportWithoutFromClauseInEs5_0.d.ts] export declare var a: number; //// [es6ImportWithoutFromClauseInEs5_1.d.ts] +import "es6ImportWithoutFromClauseInEs5_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js index e63dd4bb53a..51bb0f3338d 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js @@ -17,3 +17,4 @@ import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; export interface i { } //// [es6ImportWithoutFromClauseNonInstantiatedModule_1.d.ts] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; diff --git a/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.js b/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.js index 60ba2217349..2e84e1492be 100644 --- a/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.js +++ b/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.js @@ -73,3 +73,5 @@ declare module "./observable" { } export {}; //// [main.d.ts] +import "./map1"; +import "./map2"; diff --git a/tests/baselines/reference/moduleAugmentationDeclarationEmit1.js b/tests/baselines/reference/moduleAugmentationDeclarationEmit1.js index 589d0f506e9..7b44fb7a637 100644 --- a/tests/baselines/reference/moduleAugmentationDeclarationEmit1.js +++ b/tests/baselines/reference/moduleAugmentationDeclarationEmit1.js @@ -66,3 +66,4 @@ declare module "./observable" { } export {}; //// [main.d.ts] +import "./map"; diff --git a/tests/baselines/reference/moduleAugmentationDeclarationEmit2.js b/tests/baselines/reference/moduleAugmentationDeclarationEmit2.js index d8fd65a1464..547d017c502 100644 --- a/tests/baselines/reference/moduleAugmentationDeclarationEmit2.js +++ b/tests/baselines/reference/moduleAugmentationDeclarationEmit2.js @@ -71,3 +71,4 @@ declare module "./observable" { } export {}; //// [main.d.ts] +import "./map"; diff --git a/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.js b/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.js index 733f88e6129..2d65953e2a3 100644 --- a/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.js +++ b/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.js @@ -63,3 +63,4 @@ declare module "observable" { export {}; //// [main.d.ts] /// +import "./map"; diff --git a/tests/baselines/reference/moduleAugmentationGlobal3.js b/tests/baselines/reference/moduleAugmentationGlobal3.js index 4cff75f5df0..caa080a558c 100644 --- a/tests/baselines/reference/moduleAugmentationGlobal3.js +++ b/tests/baselines/reference/moduleAugmentationGlobal3.js @@ -50,3 +50,4 @@ declare global { } export {}; //// [f3.d.ts] +import "./f2"; diff --git a/tests/baselines/reference/moduleAugmentationGlobal4.js b/tests/baselines/reference/moduleAugmentationGlobal4.js index 11c5d968df2..38f186d0e05 100644 --- a/tests/baselines/reference/moduleAugmentationGlobal4.js +++ b/tests/baselines/reference/moduleAugmentationGlobal4.js @@ -45,3 +45,5 @@ declare global { export { }; export {}; //// [f3.d.ts] +import "./f1"; +import "./f2"; diff --git a/tests/baselines/reference/moduleAugmentationGlobal5.js b/tests/baselines/reference/moduleAugmentationGlobal5.js index 3efdd2dbb98..70c81893bd8 100644 --- a/tests/baselines/reference/moduleAugmentationGlobal5.js +++ b/tests/baselines/reference/moduleAugmentationGlobal5.js @@ -32,3 +32,5 @@ require("B"); //// [f3.d.ts] /// /// +import "A"; +import "B"; diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports1.js b/tests/baselines/reference/moduleAugmentationImportsAndExports1.js index 7159e7b5d0c..8e0b7dad19d 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports1.js +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports1.js @@ -69,3 +69,4 @@ declare module "./f1" { } } //// [f4.d.ts] +import "./f3"; diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports2.js b/tests/baselines/reference/moduleAugmentationImportsAndExports2.js index 3a4a807a334..498df8ab90e 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports2.js +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports2.js @@ -74,3 +74,4 @@ export declare class B { n: number; } //// [f4.d.ts] +import "./f3"; diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports3.js b/tests/baselines/reference/moduleAugmentationImportsAndExports3.js index d872a79e985..8d9e69c5076 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports3.js +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports3.js @@ -72,3 +72,4 @@ export declare class B { n: number; } //// [f4.d.ts] +import "./f3"; diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports5.js b/tests/baselines/reference/moduleAugmentationImportsAndExports5.js index c9b622ccf25..c3cba4c01f8 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports5.js +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports5.js @@ -76,3 +76,4 @@ export declare class B { n: number; } //// [f4.d.ts] +import "./f3"; diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports6.js b/tests/baselines/reference/moduleAugmentationImportsAndExports6.js index f0b297720b3..f5aff705eb4 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports6.js +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports6.js @@ -95,3 +95,4 @@ declare module "./f1" { } } //// [f4.d.ts] +import "./f3"; diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule5.js b/tests/baselines/reference/moduleAugmentationInAmbientModule5.js index fab9cebb179..2e6503c4774 100644 --- a/tests/baselines/reference/moduleAugmentationInAmbientModule5.js +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule5.js @@ -33,3 +33,4 @@ var y = x.getA().x; //// [f.d.ts] /// +import "array"; diff --git a/tests/baselines/reference/moduleAugmentationsBundledOutput1.js b/tests/baselines/reference/moduleAugmentationsBundledOutput1.js index 92916206e76..504c015bcb8 100644 --- a/tests/baselines/reference/moduleAugmentationsBundledOutput1.js +++ b/tests/baselines/reference/moduleAugmentationsBundledOutput1.js @@ -139,4 +139,6 @@ declare module "m4" { } } declare module "test" { + import "m2"; + import "m4"; } diff --git a/tests/baselines/reference/moduleAugmentationsImports1.js b/tests/baselines/reference/moduleAugmentationsImports1.js index 2c635a0719e..922bb61d952 100644 --- a/tests/baselines/reference/moduleAugmentationsImports1.js +++ b/tests/baselines/reference/moduleAugmentationsImports1.js @@ -101,4 +101,5 @@ declare module "d" { } } declare module "main" { + import "d"; } diff --git a/tests/baselines/reference/moduleAugmentationsImports2.js b/tests/baselines/reference/moduleAugmentationsImports2.js index f70426b49bd..605a07e29e1 100644 --- a/tests/baselines/reference/moduleAugmentationsImports2.js +++ b/tests/baselines/reference/moduleAugmentationsImports2.js @@ -111,4 +111,6 @@ declare module "e" { } } declare module "main" { + import "d"; + import "e"; } diff --git a/tests/baselines/reference/moduleAugmentationsImports3.js b/tests/baselines/reference/moduleAugmentationsImports3.js index 3654583b5c9..0a946f42be3 100644 --- a/tests/baselines/reference/moduleAugmentationsImports3.js +++ b/tests/baselines/reference/moduleAugmentationsImports3.js @@ -98,4 +98,6 @@ declare module "e" { } } declare module "main" { + import "D"; + import "e"; } diff --git a/tests/baselines/reference/moduleAugmentationsImports4.js b/tests/baselines/reference/moduleAugmentationsImports4.js index 9b64016113f..a48bbb04631 100644 --- a/tests/baselines/reference/moduleAugmentationsImports4.js +++ b/tests/baselines/reference/moduleAugmentationsImports4.js @@ -87,4 +87,6 @@ declare module "b" { } } declare module "main" { + import "D"; + import "E"; } From f7eac73a6f2e72470c581c62857e4ea7263e871e Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 3 Feb 2016 00:09:38 -0800 Subject: [PATCH 006/297] Recognize `=` as equivalent to `?` in JSDoc signatures Fixes #6811 --- src/compiler/parser.ts | 3 +++ tests/cases/fourslash/jsDocFunctionSignatures2.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/cases/fourslash/jsDocFunctionSignatures2.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b6ba02b987c..9fcc2ec34d6 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5727,6 +5727,9 @@ namespace ts { function parseJSDocParameter(): ParameterDeclaration { const parameter = createNode(SyntaxKind.Parameter); parameter.type = parseJSDocType(); + if (parseOptional(SyntaxKind.EqualsToken)) { + parameter.questionToken = createNode(SyntaxKind.QuestionToken); + } return finishNode(parameter); } diff --git a/tests/cases/fourslash/jsDocFunctionSignatures2.ts b/tests/cases/fourslash/jsDocFunctionSignatures2.ts new file mode 100644 index 00000000000..174ea7d6560 --- /dev/null +++ b/tests/cases/fourslash/jsDocFunctionSignatures2.ts @@ -0,0 +1,12 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: Foo.js + +//// /** @type {function(string, boolean=): number} */ +//// var f6; +//// +//// f6('', /**/false) + +goTo.marker(); +verify.currentSignatureHelpIs('f6(p0: string, p1?: boolean): number') From 8aad976c69ef4528f751a0312db2a40ed6a758d8 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 3 Feb 2016 00:18:36 -0800 Subject: [PATCH 007/297] Recognize object literal method JSDoc comments Fixes #6825 --- src/compiler/parser.ts | 4 +-- src/compiler/utilities.ts | 5 +++ .../fourslash/jsDocFunctionSignatures3.ts | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/jsDocFunctionSignatures3.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b6ba02b987c..3ad2cb72507 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3960,7 +3960,7 @@ namespace ts { shorthandDeclaration.equalsToken = equalsToken; shorthandDeclaration.objectAssignmentInitializer = allowInAnd(parseAssignmentExpressionOrHigher); } - return finishNode(shorthandDeclaration); + return addJSDocComment(finishNode(shorthandDeclaration)); } else { const propertyAssignment = createNode(SyntaxKind.PropertyAssignment, fullStart); @@ -3969,7 +3969,7 @@ namespace ts { propertyAssignment.questionToken = questionToken; parseExpected(SyntaxKind.ColonToken); propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher); - return finishNode(propertyAssignment); + return addJSDocComment(finishNode(propertyAssignment)); } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 02b8385d0ff..f794bc81f39 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1220,6 +1220,11 @@ namespace ts { if (isSourceOfAssignmentExpressionStatement) { return node.parent.parent.jsDocComment; } + + const isPropertyAssignmentExpression = node.parent && node.parent.kind === SyntaxKind.PropertyAssignment; + if (isPropertyAssignmentExpression) { + return node.parent.jsDocComment; + } } return undefined; diff --git a/tests/cases/fourslash/jsDocFunctionSignatures3.ts b/tests/cases/fourslash/jsDocFunctionSignatures3.ts new file mode 100644 index 00000000000..3679035d31d --- /dev/null +++ b/tests/cases/fourslash/jsDocFunctionSignatures3.ts @@ -0,0 +1,32 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: Foo.js + +//// var someObject = { +//// /** +//// * @param {string} param1 Some string param. +//// * @param {number} parm2 Some number param. +//// */ +//// someMethod: function(param1, param2) { +//// console.log(param1/*1*/); +//// return false; +//// }, +//// /** +//// * @param {number} p1 Some number param. +//// */ +//// otherMethod(p1) { +//// p1/*2*/ +//// } +//// +//// }; + +goTo.marker('1'); +edit.insert('.'); +verify.memberListContains('substr', undefined, undefined, 'method'); +edit.backspace(); + +goTo.marker('2'); +edit.insert('.'); +verify.memberListContains('toFixed', undefined, undefined, 'method'); +edit.backspace(); From 1c7062313d2dde764ea7f7d20f2415b02d8d6fbb Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 3 Feb 2016 00:44:52 -0800 Subject: [PATCH 008/297] Capture `node.parent` --- src/compiler/utilities.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f794bc81f39..8f66e43c1d6 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1212,18 +1212,19 @@ namespace ts { } // Also recognize when the node is the RHS of an assignment expression + const parent = node.parent; const isSourceOfAssignmentExpressionStatement = - node.parent && node.parent.parent && - node.parent.kind === SyntaxKind.BinaryExpression && - (node.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && - node.parent.parent.kind === SyntaxKind.ExpressionStatement; + parent && parent.parent && + parent.kind === SyntaxKind.BinaryExpression && + (parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && + parent.parent.kind === SyntaxKind.ExpressionStatement; if (isSourceOfAssignmentExpressionStatement) { - return node.parent.parent.jsDocComment; + return parent.parent.jsDocComment; } - const isPropertyAssignmentExpression = node.parent && node.parent.kind === SyntaxKind.PropertyAssignment; + const isPropertyAssignmentExpression = parent && parent.kind === SyntaxKind.PropertyAssignment; if (isPropertyAssignmentExpression) { - return node.parent.jsDocComment; + return parent.jsDocComment; } } From d47097f009ce63eca1021ce646aaa04cab19fa64 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 3 Feb 2016 10:05:58 -0800 Subject: [PATCH 009/297] Use different syntax kind here --- src/compiler/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9fcc2ec34d6..056dd375374 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5728,7 +5728,7 @@ namespace ts { const parameter = createNode(SyntaxKind.Parameter); parameter.type = parseJSDocType(); if (parseOptional(SyntaxKind.EqualsToken)) { - parameter.questionToken = createNode(SyntaxKind.QuestionToken); + parameter.questionToken = createNode(SyntaxKind.EqualsToken); } return finishNode(parameter); } From 10522f9eee43f9515f2ced6f7a46ddd5180eb162 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 3 Feb 2016 14:16:09 -0800 Subject: [PATCH 010/297] Add flag to emit modules in loose mode --- src/compiler/commandLineParser.ts | 5 +++ src/compiler/diagnosticMessages.json | 38 +++++++++++-------- src/compiler/emitter.ts | 8 ++-- src/compiler/types.ts | 1 + .../reference/emitModulesInLooseMode_amd.js | 8 ++++ .../emitModulesInLooseMode_amd.symbols | 5 +++ .../emitModulesInLooseMode_amd.types | 6 +++ .../emitModulesInLooseMode_commonjs.js | 6 +++ .../emitModulesInLooseMode_commonjs.symbols | 5 +++ .../emitModulesInLooseMode_commonjs.types | 6 +++ .../reference/emitModulesInLooseMode_es6.js | 6 +++ .../emitModulesInLooseMode_es6.symbols | 5 +++ .../emitModulesInLooseMode_es6.types | 6 +++ .../emitModulesInLooseMode_system.js | 15 ++++++++ .../emitModulesInLooseMode_system.symbols | 5 +++ .../emitModulesInLooseMode_system.types | 6 +++ .../reference/emitModulesInLooseMode_umd.js | 15 ++++++++ .../emitModulesInLooseMode_umd.symbols | 5 +++ .../emitModulesInLooseMode_umd.types | 6 +++ .../compiler/emitModulesInLooseMode_amd.ts | 4 ++ .../emitModulesInLooseMode_commonjs.ts | 4 ++ .../compiler/emitModulesInLooseMode_es6.ts | 5 +++ .../compiler/emitModulesInLooseMode_system.ts | 4 ++ .../compiler/emitModulesInLooseMode_umd.ts | 4 ++ 24 files changed, 158 insertions(+), 20 deletions(-) create mode 100644 tests/baselines/reference/emitModulesInLooseMode_amd.js create mode 100644 tests/baselines/reference/emitModulesInLooseMode_amd.symbols create mode 100644 tests/baselines/reference/emitModulesInLooseMode_amd.types create mode 100644 tests/baselines/reference/emitModulesInLooseMode_commonjs.js create mode 100644 tests/baselines/reference/emitModulesInLooseMode_commonjs.symbols create mode 100644 tests/baselines/reference/emitModulesInLooseMode_commonjs.types create mode 100644 tests/baselines/reference/emitModulesInLooseMode_es6.js create mode 100644 tests/baselines/reference/emitModulesInLooseMode_es6.symbols create mode 100644 tests/baselines/reference/emitModulesInLooseMode_es6.types create mode 100644 tests/baselines/reference/emitModulesInLooseMode_system.js create mode 100644 tests/baselines/reference/emitModulesInLooseMode_system.symbols create mode 100644 tests/baselines/reference/emitModulesInLooseMode_system.types create mode 100644 tests/baselines/reference/emitModulesInLooseMode_umd.js create mode 100644 tests/baselines/reference/emitModulesInLooseMode_umd.symbols create mode 100644 tests/baselines/reference/emitModulesInLooseMode_umd.types create mode 100644 tests/cases/compiler/emitModulesInLooseMode_amd.ts create mode 100644 tests/cases/compiler/emitModulesInLooseMode_commonjs.ts create mode 100644 tests/cases/compiler/emitModulesInLooseMode_es6.ts create mode 100644 tests/cases/compiler/emitModulesInLooseMode_system.ts create mode 100644 tests/cases/compiler/emitModulesInLooseMode_umd.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index d5bf95a6405..7d635c2aaf5 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -320,6 +320,11 @@ namespace ts { name: "allowSyntheticDefaultImports", type: "boolean", description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking + }, + { + name: "emitModulesInLooseMode", + type: "boolean", + description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output } ]; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b8ae833e5ab..5b93f61bb90 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1,4 +1,4 @@ - { +{ "Unterminated string literal.": { "category": "Error", "code": 1002 @@ -2187,6 +2187,7 @@ "category": "Error", "code": 5062 }, + "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 @@ -2231,10 +2232,10 @@ "category": "Message", "code": 6011 }, - "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": { - "category": "Message", - "code": 6015 - }, + "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": { + "category": "Message", + "code": 6015 + }, "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'": { "category": "Message", "code": 6016 @@ -2571,6 +2572,11 @@ "category": "Message", "code": 6111 }, + "Do not emit 'use strict' directives in module output.": { + "category": "Message", + "code": 6112 + }, + "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 @@ -2757,23 +2763,23 @@ "code": 17004 }, "A constructor cannot contain a 'super' call when its class extends 'null'": { - "category": "Error", - "code": 17005 + "category": "Error", + "code": 17005 }, "An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": { - "category": "Error", - "code": 17006 + "category": "Error", + "code": 17006 }, "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": { - "category": "Error", - "code": 17007 + "category": "Error", + "code": 17007 }, "JSX element '{0}' has no corresponding closing tag.": { - "category": "Error", - "code": 17008 + "category": "Error", + "code": 17008 }, "'super' must be called before accessing 'this' in the constructor of a derived class.": { - "category": "Error", - "code": 17009 + "category": "Error", + "code": 17009 } -} +} \ No newline at end of file diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e86d86603b4..92cb3334f63 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -7179,7 +7179,7 @@ const _super = (function (geti, seti) { write(`], function(${exportFunctionForFile}, ${contextObjectForFile}) {`); writeLine(); increaseIndent(); - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.emitModulesInLooseMode); writeLine(); write(`var __moduleName = ${contextObjectForFile} && ${contextObjectForFile}.id;`); writeLine(); @@ -7285,7 +7285,7 @@ const _super = (function (geti, seti) { writeModuleName(node, emitRelativePathAsModuleName); emitAMDDependencies(node, /*includeNonAmdDependencies*/ true, emitRelativePathAsModuleName); increaseIndent(); - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/!compilerOptions.emitModulesInLooseMode); emitExportStarHelper(); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); @@ -7297,7 +7297,7 @@ const _super = (function (geti, seti) { } function emitCommonJSModule(node: SourceFile) { - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ true); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ !compilerOptions.emitModulesInLooseMode); emitEmitHelpers(node); collectExternalModuleInfo(node); emitExportStarHelper(); @@ -7326,7 +7326,7 @@ const _super = (function (geti, seti) { })(`); emitAMDFactoryHeader(dependencyNames); increaseIndent(); - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.emitModulesInLooseMode); emitExportStarHelper(); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5545fbd162e..97cf2fff3b5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2422,6 +2422,7 @@ namespace ts { traceModuleResolution?: boolean; allowSyntheticDefaultImports?: boolean; allowJs?: boolean; + emitModulesInLooseMode?: boolean; /* @internal */ stripInternal?: boolean; // Skip checking lib.d.ts to help speed up tests. diff --git a/tests/baselines/reference/emitModulesInLooseMode_amd.js b/tests/baselines/reference/emitModulesInLooseMode_amd.js new file mode 100644 index 00000000000..a93ca62de0e --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_amd.js @@ -0,0 +1,8 @@ +//// [emitModulesInLooseMode_amd.ts] + +export var x = 0; + +//// [emitModulesInLooseMode_amd.js] +define(["require", "exports"], function (require, exports) { + exports.x = 0; +}); diff --git a/tests/baselines/reference/emitModulesInLooseMode_amd.symbols b/tests/baselines/reference/emitModulesInLooseMode_amd.symbols new file mode 100644 index 00000000000..d76fea8b7b8 --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_amd.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/emitModulesInLooseMode_amd.ts === + +export var x = 0; +>x : Symbol(x, Decl(emitModulesInLooseMode_amd.ts, 1, 10)) + diff --git a/tests/baselines/reference/emitModulesInLooseMode_amd.types b/tests/baselines/reference/emitModulesInLooseMode_amd.types new file mode 100644 index 00000000000..1c070cc95fa --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_amd.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/emitModulesInLooseMode_amd.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/emitModulesInLooseMode_commonjs.js b/tests/baselines/reference/emitModulesInLooseMode_commonjs.js new file mode 100644 index 00000000000..be24cdf6b91 --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_commonjs.js @@ -0,0 +1,6 @@ +//// [emitModulesInLooseMode_commonjs.ts] + +export var x = 0; + +//// [emitModulesInLooseMode_commonjs.js] +exports.x = 0; diff --git a/tests/baselines/reference/emitModulesInLooseMode_commonjs.symbols b/tests/baselines/reference/emitModulesInLooseMode_commonjs.symbols new file mode 100644 index 00000000000..225286c74de --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_commonjs.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/emitModulesInLooseMode_commonjs.ts === + +export var x = 0; +>x : Symbol(x, Decl(emitModulesInLooseMode_commonjs.ts, 1, 10)) + diff --git a/tests/baselines/reference/emitModulesInLooseMode_commonjs.types b/tests/baselines/reference/emitModulesInLooseMode_commonjs.types new file mode 100644 index 00000000000..b37bb9667ab --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_commonjs.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/emitModulesInLooseMode_commonjs.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/emitModulesInLooseMode_es6.js b/tests/baselines/reference/emitModulesInLooseMode_es6.js new file mode 100644 index 00000000000..95cc14ff609 --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_es6.js @@ -0,0 +1,6 @@ +//// [emitModulesInLooseMode_es6.ts] + +export var x = 0; + +//// [emitModulesInLooseMode_es6.js] +export var x = 0; diff --git a/tests/baselines/reference/emitModulesInLooseMode_es6.symbols b/tests/baselines/reference/emitModulesInLooseMode_es6.symbols new file mode 100644 index 00000000000..4f3c073f7ee --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_es6.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/emitModulesInLooseMode_es6.ts === + +export var x = 0; +>x : Symbol(x, Decl(emitModulesInLooseMode_es6.ts, 1, 10)) + diff --git a/tests/baselines/reference/emitModulesInLooseMode_es6.types b/tests/baselines/reference/emitModulesInLooseMode_es6.types new file mode 100644 index 00000000000..84631ede00f --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_es6.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/emitModulesInLooseMode_es6.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/emitModulesInLooseMode_system.js b/tests/baselines/reference/emitModulesInLooseMode_system.js new file mode 100644 index 00000000000..4cf401a554d --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_system.js @@ -0,0 +1,15 @@ +//// [emitModulesInLooseMode_system.ts] + +export var x = 0; + +//// [emitModulesInLooseMode_system.js] +System.register([], function(exports_1, context_1) { + var __moduleName = context_1 && context_1.id; + var x; + return { + setters:[], + execute: function() { + exports_1("x", x = 0); + } + } +}); diff --git a/tests/baselines/reference/emitModulesInLooseMode_system.symbols b/tests/baselines/reference/emitModulesInLooseMode_system.symbols new file mode 100644 index 00000000000..0682b2b648f --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_system.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/emitModulesInLooseMode_system.ts === + +export var x = 0; +>x : Symbol(x, Decl(emitModulesInLooseMode_system.ts, 1, 10)) + diff --git a/tests/baselines/reference/emitModulesInLooseMode_system.types b/tests/baselines/reference/emitModulesInLooseMode_system.types new file mode 100644 index 00000000000..429908c1de4 --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_system.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/emitModulesInLooseMode_system.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/emitModulesInLooseMode_umd.js b/tests/baselines/reference/emitModulesInLooseMode_umd.js new file mode 100644 index 00000000000..327962d18f2 --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_umd.js @@ -0,0 +1,15 @@ +//// [emitModulesInLooseMode_umd.ts] + +export var x = 0; + +//// [emitModulesInLooseMode_umd.js] +(function (factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + exports.x = 0; +}); diff --git a/tests/baselines/reference/emitModulesInLooseMode_umd.symbols b/tests/baselines/reference/emitModulesInLooseMode_umd.symbols new file mode 100644 index 00000000000..86c9e9b200c --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_umd.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/emitModulesInLooseMode_umd.ts === + +export var x = 0; +>x : Symbol(x, Decl(emitModulesInLooseMode_umd.ts, 1, 10)) + diff --git a/tests/baselines/reference/emitModulesInLooseMode_umd.types b/tests/baselines/reference/emitModulesInLooseMode_umd.types new file mode 100644 index 00000000000..98a32838eb6 --- /dev/null +++ b/tests/baselines/reference/emitModulesInLooseMode_umd.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/emitModulesInLooseMode_umd.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/cases/compiler/emitModulesInLooseMode_amd.ts b/tests/cases/compiler/emitModulesInLooseMode_amd.ts new file mode 100644 index 00000000000..7c3394bebae --- /dev/null +++ b/tests/cases/compiler/emitModulesInLooseMode_amd.ts @@ -0,0 +1,4 @@ +// @module: amd +// @emitModulesInLooseMode: true + +export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitModulesInLooseMode_commonjs.ts b/tests/cases/compiler/emitModulesInLooseMode_commonjs.ts new file mode 100644 index 00000000000..761f1f6ea9f --- /dev/null +++ b/tests/cases/compiler/emitModulesInLooseMode_commonjs.ts @@ -0,0 +1,4 @@ +// @module: commonjs +// @emitModulesInLooseMode: true + +export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitModulesInLooseMode_es6.ts b/tests/cases/compiler/emitModulesInLooseMode_es6.ts new file mode 100644 index 00000000000..22c4368629f --- /dev/null +++ b/tests/cases/compiler/emitModulesInLooseMode_es6.ts @@ -0,0 +1,5 @@ +// @module: es6 +// @target: es6 +// @emitModulesInLooseMode: true + +export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitModulesInLooseMode_system.ts b/tests/cases/compiler/emitModulesInLooseMode_system.ts new file mode 100644 index 00000000000..0face8fabca --- /dev/null +++ b/tests/cases/compiler/emitModulesInLooseMode_system.ts @@ -0,0 +1,4 @@ +// @module: system +// @emitModulesInLooseMode: true + +export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitModulesInLooseMode_umd.ts b/tests/cases/compiler/emitModulesInLooseMode_umd.ts new file mode 100644 index 00000000000..a6a3559986f --- /dev/null +++ b/tests/cases/compiler/emitModulesInLooseMode_umd.ts @@ -0,0 +1,4 @@ +// @module: umd +// @emitModulesInLooseMode: true + +export var x = 0; \ No newline at end of file From f869b41f144be3cbed1aa0ad3c66e125d57f9752 Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Wed, 3 Feb 2016 01:07:09 +0000 Subject: [PATCH 011/297] Added private and protected modifiers to constructors --- src/compiler/checker.ts | 101 ++++++++++++++++++++++----- src/compiler/diagnosticMessages.json | 16 +++++ 2 files changed, 101 insertions(+), 16 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 07ec5023d5b..1ce5b51c66d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5889,16 +5889,20 @@ namespace ts { const sourceSignatures = getSignaturesOfType(source, kind); const targetSignatures = getSignaturesOfType(target, kind); - if (kind === SignatureKind.Construct && sourceSignatures.length && targetSignatures.length && - isAbstractConstructorType(source) && !isAbstractConstructorType(target)) { - // An abstract constructor type is not assignable to a non-abstract constructor type - // as it would otherwise be possible to new an abstract class. Note that the assignablity - // check we perform for an extends clause excludes construct signatures from the target, - // so this check never proceeds. - if (reportErrors) { - reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); + if (kind === SignatureKind.Construct && sourceSignatures.length && targetSignatures.length) { + if (isAbstractConstructorType(source) && !isAbstractConstructorType(target)) { + // An abstract constructor type is not assignable to a non-abstract constructor type + // as it would otherwise be possible to new an abstract class. Note that the assignablity + // check we perform for an extends clause excludes construct signatures from the target, + // so this check never proceeds. + if (reportErrors) { + reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); + } + return Ternary.False; + } + if (!constructorRelatedTo(sourceSignatures[0], targetSignatures[0], reportErrors)) { + return Ternary.False; } - return Ternary.False; } let result = Ternary.True; @@ -6052,6 +6056,32 @@ namespace ts { } return Ternary.True; } + + function constructorRelatedTo(sourceSignature: Signature, targetSignature: Signature, reportErrors: boolean) { + if (sourceSignature && targetSignature && sourceSignature.declaration && targetSignature.declaration) { + const sourceAccessibility = sourceSignature.declaration.flags & (NodeFlags.Private | NodeFlags.Protected); + const targetAccessibility = targetSignature.declaration.flags & (NodeFlags.Private | NodeFlags.Protected); + + const isRelated = sourceAccessibility === targetAccessibility; + if (!isRelated && reportErrors) { + reportError(Diagnostics.Cannot_assign_a_0_constructor_type_to_a_1_constructor_type, flagsToString(sourceAccessibility), flagsToString(targetAccessibility)); + } + + return isRelated; + } + + return true; + + function flagsToString(flags: NodeFlags) { + if (flags === NodeFlags.Private) { + return "private"; + } + if (flags === NodeFlags.Protected) { + return "protected"; + } + return "public"; + } + } } // Return true if the given type is the constructor type for an abstract class @@ -10103,6 +10133,9 @@ namespace ts { // that the user will not add any. const constructSignatures = getSignaturesOfType(expressionType, SignatureKind.Construct); if (constructSignatures.length) { + if (!isConstructorAccessible(node, constructSignatures[0])) { + return resolveErrorCall(node); + } return resolveCall(node, constructSignatures, candidatesOutArray); } @@ -10123,6 +10156,37 @@ namespace ts { return resolveErrorCall(node); } + function isConstructorAccessible(node: NewExpression, signature: Signature) { + if (!signature || !signature.declaration) { + return true; + } + + const declaration = signature.declaration; + const flags = declaration.flags; + + // Public constructor is accessible. + if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) { + return true; + } + + const declaringClass = getDeclaredTypeOfSymbol(declaration.parent.symbol); + const enclosingClassDeclaration = getContainingClass(node); + const enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; + + // A private or protected constructor can only be instantiated within it's own class + if (declaringClass !== enclosingClass) { + if (flags & NodeFlags.Private) { + error(node, Diagnostics.Constructor_of_type_0_is_private_and_only_accessible_within_class_1, signatureToString(signature), typeToString(declaringClass)); + } + if (flags & NodeFlags.Protected) { + error(node, Diagnostics.Constructor_of_type_0_is_protected_and_only_accessible_within_class_1, signatureToString(signature), typeToString(declaringClass)); + } + return false; + } + + return true; + } + function resolveTaggedTemplateExpression(node: TaggedTemplateExpression, candidatesOutArray: Signature[]): Signature { const tagType = checkExpression(node.tag); const apparentType = getApparentType(tagType); @@ -12059,7 +12123,7 @@ namespace ts { error(o.name, Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient); } else if (deviation & (NodeFlags.Private | NodeFlags.Protected)) { - error(o.name, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); + error(o.name || o, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); } else if (deviation & NodeFlags.Abstract) { error(o.name, Diagnostics.Overload_signatures_must_all_be_abstract_or_not_abstract); @@ -13928,6 +13992,7 @@ namespace ts { if (baseTypes.length && produceDiagnostics) { const baseType = baseTypes[0]; const staticBaseType = getBaseConstructorTypeOfClass(type); + checkBaseTypeAccessibility(staticBaseType, baseTypeNode); checkSourceElement(baseTypeNode.expression); if (baseTypeNode.typeArguments) { forEach(baseTypeNode.typeArguments, checkSourceElement); @@ -13983,6 +14048,16 @@ namespace ts { } } + function checkBaseTypeAccessibility(type: ObjectType, node: ExpressionWithTypeArguments) { + const signatures = getSignaturesOfType(type, SignatureKind.Construct); + if (signatures.length) { + const declaration = signatures[0].declaration; + if (declaration && declaration.flags & NodeFlags.Private) { + error(node, Diagnostics.Cannot_extend_private_class_0, (node.expression).text); + } + } + } + function getTargetSymbol(s: Symbol) { // if symbol is instantiated its flags are not copied from the 'target' // so we'll need to get back original 'target' symbol to work with correct set of flags @@ -16348,12 +16423,6 @@ namespace ts { if (flags & NodeFlags.Abstract) { return grammarErrorOnNode(lastStatic, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "abstract"); } - else if (flags & NodeFlags.Protected) { - return grammarErrorOnNode(lastProtected, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected"); - } - else if (flags & NodeFlags.Private) { - return grammarErrorOnNode(lastPrivate, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); - } else if (flags & NodeFlags.Async) { return grammarErrorOnNode(lastAsync, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async"); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index c848ebc3a10..2ee388ff42e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1823,6 +1823,22 @@ "category": "Error", "code": 2671 }, + "Cannot assign a '{0}' constructor type to a '{1}' constructor type.": { + "category": "Error", + "code": 2672 + }, + "Constructor of type '{0}' is private and only accessible within class '{1}'.": { + "category": "Error", + "code": 2673 + }, + "Constructor of type '{0}' is protected and only accessible within class '{1}'.": { + "category": "Error", + "code": 2674 + }, + "Cannot extend private class '{0}'.": { + "category": "Error", + "code": 2675 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 From c351ffcc75c1d257f72a3e86faaa640d8daefdf3 Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Wed, 3 Feb 2016 22:48:33 +0000 Subject: [PATCH 012/297] Added and updated tests for constructor visibility --- .../baselines/reference/Protected3.errors.txt | 9 -- tests/baselines/reference/Protected3.symbols | 6 + tests/baselines/reference/Protected3.types | 6 + .../classConstructorAccessibility.errors.txt | 41 ++--- .../classConstructorAccessibility.js | 53 +++++-- .../classConstructorAccessibility2.errors.txt | 59 +++++++ .../classConstructorAccessibility2.js | 148 ++++++++++++++++++ .../classConstructorAccessibility3.errors.txt | 77 +++++++++ .../classConstructorAccessibility3.js | 98 ++++++++++++ ...nstructorOverloadsAccessibility.errors.txt | 45 ++++++ .../classConstructorOverloadsAccessibility.js | 76 +++++++++ ...implicitAnyInAmbientDeclaration.errors.txt | 5 +- ...licitAnyInAmbientDeclaration2.d.errors.txt | 5 +- .../parserConstructorDeclaration5.errors.txt | 9 -- .../parserConstructorDeclaration5.symbols | 6 + .../parserConstructorDeclaration5.types | 6 + .../reference/protectedMembers.errors.txt | 12 +- tests/baselines/reference/protectedMembers.js | 2 - .../typesWithPrivateConstructor.errors.txt | 28 +--- .../reference/typesWithPrivateConstructor.js | 23 ++- .../typesWithProtectedConstructor.errors.txt | 24 +++ .../typesWithProtectedConstructor.js | 45 ++++++ tests/cases/compiler/protectedMembers.ts | 1 - .../classConstructorAccessibility.ts | 18 ++- .../classConstructorAccessibility2.ts | 42 +++++ .../classConstructorAccessibility3.ts | 35 +++++ .../classConstructorOverloadsAccessibility.ts | 34 ++++ .../members/typesWithPrivateConstructor.ts | 6 +- .../members/typesWithProtectedConstructor.ts | 16 ++ .../quickInfoOnPrivateConstructorCall.ts | 9 ++ .../quickInfoOnProtectedConstructorCall.ts | 9 ++ 31 files changed, 843 insertions(+), 110 deletions(-) delete mode 100644 tests/baselines/reference/Protected3.errors.txt create mode 100644 tests/baselines/reference/Protected3.symbols create mode 100644 tests/baselines/reference/Protected3.types create mode 100644 tests/baselines/reference/classConstructorAccessibility2.errors.txt create mode 100644 tests/baselines/reference/classConstructorAccessibility2.js create mode 100644 tests/baselines/reference/classConstructorAccessibility3.errors.txt create mode 100644 tests/baselines/reference/classConstructorAccessibility3.js create mode 100644 tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt create mode 100644 tests/baselines/reference/classConstructorOverloadsAccessibility.js delete mode 100644 tests/baselines/reference/parserConstructorDeclaration5.errors.txt create mode 100644 tests/baselines/reference/parserConstructorDeclaration5.symbols create mode 100644 tests/baselines/reference/parserConstructorDeclaration5.types create mode 100644 tests/baselines/reference/typesWithProtectedConstructor.errors.txt create mode 100644 tests/baselines/reference/typesWithProtectedConstructor.js create mode 100644 tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts create mode 100644 tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts create mode 100644 tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts create mode 100644 tests/cases/conformance/types/members/typesWithProtectedConstructor.ts create mode 100644 tests/cases/fourslash/quickInfoOnPrivateConstructorCall.ts create mode 100644 tests/cases/fourslash/quickInfoOnProtectedConstructorCall.ts diff --git a/tests/baselines/reference/Protected3.errors.txt b/tests/baselines/reference/Protected3.errors.txt deleted file mode 100644 index 688422a1e0f..00000000000 --- a/tests/baselines/reference/Protected3.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts(2,3): error TS1089: 'protected' modifier cannot appear on a constructor declaration. - - -==== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts (1 errors) ==== - class C { - protected constructor() { } - ~~~~~~~~~ -!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. - } \ No newline at end of file diff --git a/tests/baselines/reference/Protected3.symbols b/tests/baselines/reference/Protected3.symbols new file mode 100644 index 00000000000..a9882189902 --- /dev/null +++ b/tests/baselines/reference/Protected3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts === +class C { +>C : Symbol(C, Decl(Protected3.ts, 0, 0)) + + protected constructor() { } +} diff --git a/tests/baselines/reference/Protected3.types b/tests/baselines/reference/Protected3.types new file mode 100644 index 00000000000..d3f938a4431 --- /dev/null +++ b/tests/baselines/reference/Protected3.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts === +class C { +>C : C + + protected constructor() { } +} diff --git a/tests/baselines/reference/classConstructorAccessibility.errors.txt b/tests/baselines/reference/classConstructorAccessibility.errors.txt index c22f3593bc5..a24ec6c63d1 100644 --- a/tests/baselines/reference/classConstructorAccessibility.errors.txt +++ b/tests/baselines/reference/classConstructorAccessibility.errors.txt @@ -1,29 +1,30 @@ -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(6,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(10,5): error TS1089: 'protected' modifier cannot appear on a constructor declaration. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(23,9): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(27,9): error TS1089: 'protected' modifier cannot appear on a constructor declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(15,9): error TS2673: Constructor of type '(x: number): D' is private and only accessible within class 'D'. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(16,9): error TS2674: Constructor of type '(x: number): E' is protected and only accessible within class 'E'. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(32,13): error TS2673: Constructor of type '(x: T): D' is private and only accessible within class 'D'. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(33,13): error TS2674: Constructor of type '(x: T): E' is protected and only accessible within class 'E'. ==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts (4 errors) ==== + class C { public constructor(public x: number) { } } class D { - private constructor(public x: number) { } // error - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. + private constructor(public x: number) { } } class E { - protected constructor(public x: number) { } // error - ~~~~~~~~~ -!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. + protected constructor(public x: number) { } } var c = new C(1); - var d = new D(1); - var e = new E(1); + var d = new D(1); // error + ~~~~~~~~ +!!! error TS2673: Constructor of type '(x: number): D' is private and only accessible within class 'D'. + var e = new E(1); // error + ~~~~~~~~ +!!! error TS2674: Constructor of type '(x: number): E' is protected and only accessible within class 'E'. module Generic { class C { @@ -31,19 +32,19 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib } class D { - private constructor(public x: T) { } // error - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. + private constructor(public x: T) { } } class E { - protected constructor(public x: T) { } // error - ~~~~~~~~~ -!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. + protected constructor(public x: T) { } } var c = new C(1); - var d = new D(1); - var e = new E(1); + var d = new D(1); // error + ~~~~~~~~ +!!! error TS2673: Constructor of type '(x: T): D' is private and only accessible within class 'D'. + var e = new E(1); // error + ~~~~~~~~ +!!! error TS2674: Constructor of type '(x: T): E' is protected and only accessible within class 'E'. } \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorAccessibility.js b/tests/baselines/reference/classConstructorAccessibility.js index fed96385845..de7e4a83bb8 100644 --- a/tests/baselines/reference/classConstructorAccessibility.js +++ b/tests/baselines/reference/classConstructorAccessibility.js @@ -1,19 +1,20 @@ //// [classConstructorAccessibility.ts] + class C { public constructor(public x: number) { } } class D { - private constructor(public x: number) { } // error + private constructor(public x: number) { } } class E { - protected constructor(public x: number) { } // error + protected constructor(public x: number) { } } var c = new C(1); -var d = new D(1); -var e = new E(1); +var d = new D(1); // error +var e = new E(1); // error module Generic { class C { @@ -21,16 +22,16 @@ module Generic { } class D { - private constructor(public x: T) { } // error + private constructor(public x: T) { } } class E { - protected constructor(public x: T) { } // error + protected constructor(public x: T) { } } var c = new C(1); - var d = new D(1); - var e = new E(1); + var d = new D(1); // error + var e = new E(1); // error } @@ -44,18 +45,18 @@ var C = (function () { var D = (function () { function D(x) { this.x = x; - } // error + } return D; }()); var E = (function () { function E(x) { this.x = x; - } // error + } return E; }()); var c = new C(1); -var d = new D(1); -var e = new E(1); +var d = new D(1); // error +var e = new E(1); // error var Generic; (function (Generic) { var C = (function () { @@ -67,16 +68,36 @@ var Generic; var D = (function () { function D(x) { this.x = x; - } // error + } return D; }()); var E = (function () { function E(x) { this.x = x; - } // error + } return E; }()); var c = new C(1); - var d = new D(1); - var e = new E(1); + var d = new D(1); // error + var e = new E(1); // error })(Generic || (Generic = {})); + + +//// [classConstructorAccessibility.d.ts] +declare class C { + x: number; + constructor(x: number); +} +declare class D { + x: number; + constructor(x); +} +declare class E { + x: number; + constructor(x: number); +} +declare var c: C; +declare var d: any; +declare var e: any; +declare module Generic { +} diff --git a/tests/baselines/reference/classConstructorAccessibility2.errors.txt b/tests/baselines/reference/classConstructorAccessibility2.errors.txt new file mode 100644 index 00000000000..1c6fc46edb3 --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility2.errors.txt @@ -0,0 +1,59 @@ +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(26,28): error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(29,24): error TS2675: Cannot extend private class 'BaseC'. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(32,28): error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(36,10): error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(37,10): error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'. + + +==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts (5 errors) ==== + + class BaseA { + public constructor(public x: number) { } + createInstance() { new BaseA(1); } + } + + class BaseB { + protected constructor(public x: number) { } + createInstance() { new BaseB(1); } + } + + class BaseC { + private constructor(public x: number) { } + createInstance() { new BaseC(1); } + } + + class DerivedA extends BaseA { + constructor(public x: number) { super(x); } + createInstance() { new DerivedA(1); } + createBaseInstance() { new BaseA(1); } + } + + class DerivedB extends BaseB { + constructor(public x: number) { super(x); } + createInstance() { new DerivedB(1); } + createBaseInstance() { new BaseB(1); } // error + ~~~~~~~~~~~~ +!!! error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'. + } + + class DerivedC extends BaseC { // error + ~~~~~ +!!! error TS2675: Cannot extend private class 'BaseC'. + constructor(public x: number) { super(x); } + createInstance() { new DerivedC(1); } + createBaseInstance() { new BaseC(1); } // error + ~~~~~~~~~~~~ +!!! error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'. + } + + var ba = new BaseA(1); + var bb = new BaseB(1); // error + ~~~~~~~~~~~~ +!!! error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'. + var bc = new BaseC(1); // error + ~~~~~~~~~~~~ +!!! error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'. + + var da = new DerivedA(1); + var db = new DerivedB(1); + var dc = new DerivedC(1); \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorAccessibility2.js b/tests/baselines/reference/classConstructorAccessibility2.js new file mode 100644 index 00000000000..47c0b0bc626 --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility2.js @@ -0,0 +1,148 @@ +//// [classConstructorAccessibility2.ts] + +class BaseA { + public constructor(public x: number) { } + createInstance() { new BaseA(1); } +} + +class BaseB { + protected constructor(public x: number) { } + createInstance() { new BaseB(1); } +} + +class BaseC { + private constructor(public x: number) { } + createInstance() { new BaseC(1); } +} + +class DerivedA extends BaseA { + constructor(public x: number) { super(x); } + createInstance() { new DerivedA(1); } + createBaseInstance() { new BaseA(1); } +} + +class DerivedB extends BaseB { + constructor(public x: number) { super(x); } + createInstance() { new DerivedB(1); } + createBaseInstance() { new BaseB(1); } // error +} + +class DerivedC extends BaseC { // error + constructor(public x: number) { super(x); } + createInstance() { new DerivedC(1); } + createBaseInstance() { new BaseC(1); } // error +} + +var ba = new BaseA(1); +var bb = new BaseB(1); // error +var bc = new BaseC(1); // error + +var da = new DerivedA(1); +var db = new DerivedB(1); +var dc = new DerivedC(1); + +//// [classConstructorAccessibility2.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var BaseA = (function () { + function BaseA(x) { + this.x = x; + } + BaseA.prototype.createInstance = function () { new BaseA(1); }; + return BaseA; +}()); +var BaseB = (function () { + function BaseB(x) { + this.x = x; + } + BaseB.prototype.createInstance = function () { new BaseB(1); }; + return BaseB; +}()); +var BaseC = (function () { + function BaseC(x) { + this.x = x; + } + BaseC.prototype.createInstance = function () { new BaseC(1); }; + return BaseC; +}()); +var DerivedA = (function (_super) { + __extends(DerivedA, _super); + function DerivedA(x) { + _super.call(this, x); + this.x = x; + } + DerivedA.prototype.createInstance = function () { new DerivedA(1); }; + DerivedA.prototype.createBaseInstance = function () { new BaseA(1); }; + return DerivedA; +}(BaseA)); +var DerivedB = (function (_super) { + __extends(DerivedB, _super); + function DerivedB(x) { + _super.call(this, x); + this.x = x; + } + DerivedB.prototype.createInstance = function () { new DerivedB(1); }; + DerivedB.prototype.createBaseInstance = function () { new BaseB(1); }; // error + return DerivedB; +}(BaseB)); +var DerivedC = (function (_super) { + __extends(DerivedC, _super); + function DerivedC(x) { + _super.call(this, x); + this.x = x; + } + DerivedC.prototype.createInstance = function () { new DerivedC(1); }; + DerivedC.prototype.createBaseInstance = function () { new BaseC(1); }; // error + return DerivedC; +}(BaseC)); +var ba = new BaseA(1); +var bb = new BaseB(1); // error +var bc = new BaseC(1); // error +var da = new DerivedA(1); +var db = new DerivedB(1); +var dc = new DerivedC(1); + + +//// [classConstructorAccessibility2.d.ts] +declare class BaseA { + x: number; + constructor(x: number); + createInstance(): void; +} +declare class BaseB { + x: number; + constructor(x: number); + createInstance(): void; +} +declare class BaseC { + x: number; + constructor(x); + createInstance(): void; +} +declare class DerivedA extends BaseA { + x: number; + constructor(x: number); + createInstance(): void; + createBaseInstance(): void; +} +declare class DerivedB extends BaseB { + x: number; + constructor(x: number); + createInstance(): void; + createBaseInstance(): void; +} +declare class DerivedC extends BaseC { + x: number; + constructor(x: number); + createInstance(): void; + createBaseInstance(): void; +} +declare var ba: BaseA; +declare var bb: any; +declare var bc: any; +declare var da: DerivedA; +declare var db: DerivedB; +declare var dc: DerivedC; diff --git a/tests/baselines/reference/classConstructorAccessibility3.errors.txt b/tests/baselines/reference/classConstructorAccessibility3.errors.txt new file mode 100644 index 00000000000..c536db1f9da --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility3.errors.txt @@ -0,0 +1,77 @@ +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(21,1): error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Foo'. + Cannot assign a 'protected' constructor type to a 'public' constructor type. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(22,1): error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Foo'. + Cannot assign a 'private' constructor type to a 'public' constructor type. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(26,1): error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Baz'. + Cannot assign a 'public' constructor type to a 'protected' constructor type. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(27,1): error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Baz'. + Cannot assign a 'public' constructor type to a 'protected' constructor type. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(28,1): error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Baz'. + Cannot assign a 'private' constructor type to a 'protected' constructor type. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(32,1): error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Qux'. + Cannot assign a 'public' constructor type to a 'private' constructor type. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(33,1): error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Qux'. + Cannot assign a 'public' constructor type to a 'private' constructor type. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(34,1): error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Qux'. + Cannot assign a 'protected' constructor type to a 'private' constructor type. + + +==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts (8 errors) ==== + + class Foo { + constructor(public x: number) { } + } + + class Bar { + public constructor(public x: number) { } + } + + class Baz { + protected constructor(public x: number) { } + } + + class Qux { + private constructor(public x: number) { } + } + + // b is public + let a = Foo; + a = Bar; + a = Baz; // error Baz is protected + ~ +!!! error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Foo'. +!!! error TS2322: Cannot assign a 'protected' constructor type to a 'public' constructor type. + a = Qux; // error Qux is private + ~ +!!! error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Foo'. +!!! error TS2322: Cannot assign a 'private' constructor type to a 'public' constructor type. + + // b is protected + let b = Baz; + b = Foo; // error Foo is public + ~ +!!! error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Baz'. +!!! error TS2322: Cannot assign a 'public' constructor type to a 'protected' constructor type. + b = Bar; // error Baz is public + ~ +!!! error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Baz'. +!!! error TS2322: Cannot assign a 'public' constructor type to a 'protected' constructor type. + b = Qux; // error Qux is private + ~ +!!! error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Baz'. +!!! error TS2322: Cannot assign a 'private' constructor type to a 'protected' constructor type. + + // c is private + let c = Qux; + c = Foo; // error Foo is public + ~ +!!! error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Qux'. +!!! error TS2322: Cannot assign a 'public' constructor type to a 'private' constructor type. + c = Bar; // error Bar is public + ~ +!!! error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Qux'. +!!! error TS2322: Cannot assign a 'public' constructor type to a 'private' constructor type. + c = Baz; // error Baz is protected + ~ +!!! error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Qux'. +!!! error TS2322: Cannot assign a 'protected' constructor type to a 'private' constructor type. \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorAccessibility3.js b/tests/baselines/reference/classConstructorAccessibility3.js new file mode 100644 index 00000000000..8e900b6eb2d --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility3.js @@ -0,0 +1,98 @@ +//// [classConstructorAccessibility3.ts] + +class Foo { + constructor(public x: number) { } +} + +class Bar { + public constructor(public x: number) { } +} + +class Baz { + protected constructor(public x: number) { } +} + +class Qux { + private constructor(public x: number) { } +} + +// b is public +let a = Foo; +a = Bar; +a = Baz; // error Baz is protected +a = Qux; // error Qux is private + +// b is protected +let b = Baz; +b = Foo; // error Foo is public +b = Bar; // error Baz is public +b = Qux; // error Qux is private + +// c is private +let c = Qux; +c = Foo; // error Foo is public +c = Bar; // error Bar is public +c = Baz; // error Baz is protected + +//// [classConstructorAccessibility3.js] +var Foo = (function () { + function Foo(x) { + this.x = x; + } + return Foo; +}()); +var Bar = (function () { + function Bar(x) { + this.x = x; + } + return Bar; +}()); +var Baz = (function () { + function Baz(x) { + this.x = x; + } + return Baz; +}()); +var Qux = (function () { + function Qux(x) { + this.x = x; + } + return Qux; +}()); +// b is public +var a = Foo; +a = Bar; +a = Baz; // error Baz is protected +a = Qux; // error Qux is private +// b is protected +var b = Baz; +b = Foo; // error Foo is public +b = Bar; // error Baz is public +b = Qux; // error Qux is private +// c is private +var c = Qux; +c = Foo; // error Foo is public +c = Bar; // error Bar is public +c = Baz; // error Baz is protected + + +//// [classConstructorAccessibility3.d.ts] +declare class Foo { + x: number; + constructor(x: number); +} +declare class Bar { + x: number; + constructor(x: number); +} +declare class Baz { + x: number; + constructor(x: number); +} +declare class Qux { + x: number; + constructor(x); +} +declare let a: typeof Foo; +declare let b: typeof Baz; +declare let c: typeof Qux; diff --git a/tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt b/tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt new file mode 100644 index 00000000000..8882b9f0180 --- /dev/null +++ b/tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt @@ -0,0 +1,45 @@ +tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts(3,2): error TS2385: Overload signatures must all be public, private or protected. +tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts(4,2): error TS2385: Overload signatures must all be public, private or protected. +tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts(12,2): error TS2385: Overload signatures must all be public, private or protected. + + +==== tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts (3 errors) ==== + + class A { + public constructor(a: boolean) // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2385: Overload signatures must all be public, private or protected. + protected constructor(a: number) // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2385: Overload signatures must all be public, private or protected. + private constructor(a: string) + private constructor() { + + } + } + + class B { + protected constructor(a: number) // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2385: Overload signatures must all be public, private or protected. + constructor(a: string) + constructor() { + + } + } + + class C { + protected constructor(a: number) + protected constructor(a: string) + protected constructor() { + + } + } + + class D { + constructor(a: number) + constructor(a: string) + public constructor() { + + } + } \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorOverloadsAccessibility.js b/tests/baselines/reference/classConstructorOverloadsAccessibility.js new file mode 100644 index 00000000000..b69257a1c2a --- /dev/null +++ b/tests/baselines/reference/classConstructorOverloadsAccessibility.js @@ -0,0 +1,76 @@ +//// [classConstructorOverloadsAccessibility.ts] + +class A { + public constructor(a: boolean) // error + protected constructor(a: number) // error + private constructor(a: string) + private constructor() { + + } +} + +class B { + protected constructor(a: number) // error + constructor(a: string) + constructor() { + + } +} + +class C { + protected constructor(a: number) + protected constructor(a: string) + protected constructor() { + + } +} + +class D { + constructor(a: number) + constructor(a: string) + public constructor() { + + } +} + +//// [classConstructorOverloadsAccessibility.js] +var A = (function () { + function A() { + } + return A; +}()); +var B = (function () { + function B() { + } + return B; +}()); +var C = (function () { + function C() { + } + return C; +}()); +var D = (function () { + function D() { + } + return D; +}()); + + +//// [classConstructorOverloadsAccessibility.d.ts] +declare class A { + constructor(a: boolean); + constructor(a: number); + constructor(a); +} +declare class B { + constructor(a: number); + constructor(a: string); +} +declare class C { + constructor(a: number); + constructor(a: string); +} +declare class D { + constructor(a: number); + constructor(a: string); +} diff --git a/tests/baselines/reference/implicitAnyInAmbientDeclaration.errors.txt b/tests/baselines/reference/implicitAnyInAmbientDeclaration.errors.txt index 1e66f26d0d2..493fc13db04 100644 --- a/tests/baselines/reference/implicitAnyInAmbientDeclaration.errors.txt +++ b/tests/baselines/reference/implicitAnyInAmbientDeclaration.errors.txt @@ -1,10 +1,9 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(3,9): error TS7008: Member 'publicMember' implicitly has an 'any' type. tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(6,16): error TS7010: 'publicFunction', which lacks return-type annotation, implicitly has an 'any' return type. tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(6,31): error TS7006: Parameter 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(8,9): error TS1089: 'private' modifier cannot appear on a constructor declaration. -==== tests/cases/compiler/implicitAnyInAmbientDeclaration.ts (4 errors) ==== +==== tests/cases/compiler/implicitAnyInAmbientDeclaration.ts (3 errors) ==== module Test { declare class C { public publicMember; // this should be an error @@ -19,7 +18,5 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(8,9): error TS1089: 'pri !!! error TS7006: Parameter 'x' implicitly has an 'any' type. private privateFunction(privateParam); // this should not be an error private constructor(privateParam); - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } } \ No newline at end of file diff --git a/tests/baselines/reference/implicitAnyInAmbientDeclaration2.d.errors.txt b/tests/baselines/reference/implicitAnyInAmbientDeclaration2.d.errors.txt index 54fe39e2efe..03de82c731d 100644 --- a/tests/baselines/reference/implicitAnyInAmbientDeclaration2.d.errors.txt +++ b/tests/baselines/reference/implicitAnyInAmbientDeclaration2.d.errors.txt @@ -4,11 +4,10 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(2,13): error TS7005: tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(4,5): error TS7008: Member 'publicMember' implicitly has an 'any' type. tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(7,12): error TS7010: 'publicFunction', which lacks return-type annotation, implicitly has an 'any' return type. tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(7,27): error TS7006: Parameter 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(9,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(13,24): error TS7006: Parameter 'publicConsParam' implicitly has an 'any' type. -==== tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts (8 errors) ==== +==== tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts (7 errors) ==== declare function foo(x); // this should be an error ~~~ !!! error TS7010: 'foo', which lacks return-type annotation, implicitly has an 'any' return type. @@ -30,8 +29,6 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(13,24): error TS7006: !!! error TS7006: Parameter 'x' implicitly has an 'any' type. private privateFunction(privateParam); // this should not be an error private constructor(privateParam); // this should not be an error - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } declare class D { diff --git a/tests/baselines/reference/parserConstructorDeclaration5.errors.txt b/tests/baselines/reference/parserConstructorDeclaration5.errors.txt deleted file mode 100644 index 4589ad95a32..00000000000 --- a/tests/baselines/reference/parserConstructorDeclaration5.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts(2,3): error TS1089: 'private' modifier cannot appear on a constructor declaration. - - -==== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts (1 errors) ==== - class C { - private constructor() { } - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserConstructorDeclaration5.symbols b/tests/baselines/reference/parserConstructorDeclaration5.symbols new file mode 100644 index 00000000000..6eb3d32a0f0 --- /dev/null +++ b/tests/baselines/reference/parserConstructorDeclaration5.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts === +class C { +>C : Symbol(C, Decl(parserConstructorDeclaration5.ts, 0, 0)) + + private constructor() { } +} diff --git a/tests/baselines/reference/parserConstructorDeclaration5.types b/tests/baselines/reference/parserConstructorDeclaration5.types new file mode 100644 index 00000000000..ae5d2c44b49 --- /dev/null +++ b/tests/baselines/reference/parserConstructorDeclaration5.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts === +class C { +>C : C + + private constructor() { } +} diff --git a/tests/baselines/reference/protectedMembers.errors.txt b/tests/baselines/reference/protectedMembers.errors.txt index c35bc25fe71..666be34d10c 100644 --- a/tests/baselines/reference/protectedMembers.errors.txt +++ b/tests/baselines/reference/protectedMembers.errors.txt @@ -8,16 +8,15 @@ tests/cases/compiler/protectedMembers.ts(48,1): error TS2445: Property 'sx' is p tests/cases/compiler/protectedMembers.ts(49,1): error TS2445: Property 'sf' is protected and only accessible within class 'C2' and its subclasses. tests/cases/compiler/protectedMembers.ts(68,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'C'. tests/cases/compiler/protectedMembers.ts(69,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'C'. -tests/cases/compiler/protectedMembers.ts(86,5): error TS1089: 'protected' modifier cannot appear on a constructor declaration. -tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'B1' is not assignable to type 'A1'. +tests/cases/compiler/protectedMembers.ts(97,1): error TS2322: Type 'B1' is not assignable to type 'A1'. Property 'x' is protected but type 'B1' is not a class derived from 'A1'. -tests/cases/compiler/protectedMembers.ts(99,1): error TS2322: Type 'A1' is not assignable to type 'B1'. +tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'A1' is not assignable to type 'B1'. Property 'x' is protected in type 'A1' but public in type 'B1'. -tests/cases/compiler/protectedMembers.ts(112,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'. +tests/cases/compiler/protectedMembers.ts(111,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'. Property 'x' is protected in type 'B3' but public in type 'A3'. -==== tests/cases/compiler/protectedMembers.ts (14 errors) ==== +==== tests/cases/compiler/protectedMembers.ts (13 errors) ==== // Class with protected members class C1 { protected x: number; @@ -122,10 +121,7 @@ tests/cases/compiler/protectedMembers.ts(112,7): error TS2415: Class 'B3' incorr } class CC { - // Error, constructor cannot be protected protected constructor() { - ~~~~~~~~~ -!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. } } diff --git a/tests/baselines/reference/protectedMembers.js b/tests/baselines/reference/protectedMembers.js index e541f697f44..dcc68e0c946 100644 --- a/tests/baselines/reference/protectedMembers.js +++ b/tests/baselines/reference/protectedMembers.js @@ -83,7 +83,6 @@ interface E extends C { } class CC { - // Error, constructor cannot be protected protected constructor() { } } @@ -214,7 +213,6 @@ var D = (function (_super) { return D; }(C)); var CC = (function () { - // Error, constructor cannot be protected function CC() { } return CC; diff --git a/tests/baselines/reference/typesWithPrivateConstructor.errors.txt b/tests/baselines/reference/typesWithPrivateConstructor.errors.txt index 261038a1f4a..d30bb29e314 100644 --- a/tests/baselines/reference/typesWithPrivateConstructor.errors.txt +++ b/tests/baselines/reference/typesWithPrivateConstructor.errors.txt @@ -1,36 +1,24 @@ -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(4,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(8,5): error TS2322: Type 'Function' is not assignable to type '() => void'. - Type 'Function' provides no match for the signature '(): void' -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(11,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(12,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(15,10): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(6,9): error TS2673: Constructor of type '(): C' is private and only accessible within class 'C'. +tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(14,10): error TS2673: Constructor of type '(x: number): C2' is private and only accessible within class 'C2'. -==== tests/cases/conformance/types/members/typesWithPrivateConstructor.ts (5 errors) ==== - // private constructors are not allowed +==== tests/cases/conformance/types/members/typesWithPrivateConstructor.ts (2 errors) ==== class C { private constructor() { } - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } - var c = new C(); + var c = new C(); // error C is private + ~~~~~~~ +!!! error TS2673: Constructor of type '(): C' is private and only accessible within class 'C'. var r: () => void = c.constructor; - ~ -!!! error TS2322: Type 'Function' is not assignable to type '() => void'. -!!! error TS2322: Type 'Function' provides no match for the signature '(): void' class C2 { private constructor(x: number); - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. private constructor(x: any) { } - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } - var c2 = new C2(); + var c2 = new C2(); // error C2 is private ~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. +!!! error TS2673: Constructor of type '(x: number): C2' is private and only accessible within class 'C2'. var r2: (x: number) => void = c2.constructor; \ No newline at end of file diff --git a/tests/baselines/reference/typesWithPrivateConstructor.js b/tests/baselines/reference/typesWithPrivateConstructor.js index d894eeda49a..b3111ec2a74 100644 --- a/tests/baselines/reference/typesWithPrivateConstructor.js +++ b/tests/baselines/reference/typesWithPrivateConstructor.js @@ -1,11 +1,10 @@ //// [typesWithPrivateConstructor.ts] -// private constructors are not allowed class C { private constructor() { } } -var c = new C(); +var c = new C(); // error C is private var r: () => void = c.constructor; class C2 { @@ -13,22 +12,34 @@ class C2 { private constructor(x: any) { } } -var c2 = new C2(); +var c2 = new C2(); // error C2 is private var r2: (x: number) => void = c2.constructor; //// [typesWithPrivateConstructor.js] -// private constructors are not allowed var C = (function () { function C() { } return C; }()); -var c = new C(); +var c = new C(); // error C is private var r = c.constructor; var C2 = (function () { function C2(x) { } return C2; }()); -var c2 = new C2(); +var c2 = new C2(); // error C2 is private var r2 = c2.constructor; + + +//// [typesWithPrivateConstructor.d.ts] +declare class C { + constructor(); +} +declare var c: any; +declare var r: () => void; +declare class C2 { + constructor(x); +} +declare var c2: any; +declare var r2: (x: number) => void; diff --git a/tests/baselines/reference/typesWithProtectedConstructor.errors.txt b/tests/baselines/reference/typesWithProtectedConstructor.errors.txt new file mode 100644 index 00000000000..4dc8add9fc2 --- /dev/null +++ b/tests/baselines/reference/typesWithProtectedConstructor.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(6,9): error TS2674: Constructor of type '(): C' is protected and only accessible within class 'C'. +tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(14,10): error TS2674: Constructor of type '(x: number): C2' is protected and only accessible within class 'C2'. + + +==== tests/cases/conformance/types/members/typesWithProtectedConstructor.ts (2 errors) ==== + + class C { + protected constructor() { } + } + + var c = new C(); // error C is protected + ~~~~~~~ +!!! error TS2674: Constructor of type '(): C' is protected and only accessible within class 'C'. + var r: () => void = c.constructor; + + class C2 { + protected constructor(x: number); + protected constructor(x: any) { } + } + + var c2 = new C2(); // error C2 is protected + ~~~~~~~~ +!!! error TS2674: Constructor of type '(x: number): C2' is protected and only accessible within class 'C2'. + var r2: (x: number) => void = c2.constructor; \ No newline at end of file diff --git a/tests/baselines/reference/typesWithProtectedConstructor.js b/tests/baselines/reference/typesWithProtectedConstructor.js new file mode 100644 index 00000000000..02f29464533 --- /dev/null +++ b/tests/baselines/reference/typesWithProtectedConstructor.js @@ -0,0 +1,45 @@ +//// [typesWithProtectedConstructor.ts] + +class C { + protected constructor() { } +} + +var c = new C(); // error C is protected +var r: () => void = c.constructor; + +class C2 { + protected constructor(x: number); + protected constructor(x: any) { } +} + +var c2 = new C2(); // error C2 is protected +var r2: (x: number) => void = c2.constructor; + +//// [typesWithProtectedConstructor.js] +var C = (function () { + function C() { + } + return C; +}()); +var c = new C(); // error C is protected +var r = c.constructor; +var C2 = (function () { + function C2(x) { + } + return C2; +}()); +var c2 = new C2(); // error C2 is protected +var r2 = c2.constructor; + + +//// [typesWithProtectedConstructor.d.ts] +declare class C { + constructor(); +} +declare var c: any; +declare var r: () => void; +declare class C2 { + constructor(x: number); +} +declare var c2: any; +declare var r2: (x: number) => void; diff --git a/tests/cases/compiler/protectedMembers.ts b/tests/cases/compiler/protectedMembers.ts index ae32e472425..b7528f26068 100644 --- a/tests/cases/compiler/protectedMembers.ts +++ b/tests/cases/compiler/protectedMembers.ts @@ -82,7 +82,6 @@ interface E extends C { } class CC { - // Error, constructor cannot be protected protected constructor() { } } diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts index c2e4855e63a..1c9a801429d 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts @@ -1,18 +1,20 @@ +// @declaration: true + class C { public constructor(public x: number) { } } class D { - private constructor(public x: number) { } // error + private constructor(public x: number) { } } class E { - protected constructor(public x: number) { } // error + protected constructor(public x: number) { } } var c = new C(1); -var d = new D(1); -var e = new E(1); +var d = new D(1); // error +var e = new E(1); // error module Generic { class C { @@ -20,14 +22,14 @@ module Generic { } class D { - private constructor(public x: T) { } // error + private constructor(public x: T) { } } class E { - protected constructor(public x: T) { } // error + protected constructor(public x: T) { } } var c = new C(1); - var d = new D(1); - var e = new E(1); + var d = new D(1); // error + var e = new E(1); // error } diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts new file mode 100644 index 00000000000..2a961e2c067 --- /dev/null +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts @@ -0,0 +1,42 @@ +// @declaration: true + +class BaseA { + public constructor(public x: number) { } + createInstance() { new BaseA(1); } +} + +class BaseB { + protected constructor(public x: number) { } + createInstance() { new BaseB(1); } +} + +class BaseC { + private constructor(public x: number) { } + createInstance() { new BaseC(1); } +} + +class DerivedA extends BaseA { + constructor(public x: number) { super(x); } + createInstance() { new DerivedA(1); } + createBaseInstance() { new BaseA(1); } +} + +class DerivedB extends BaseB { + constructor(public x: number) { super(x); } + createInstance() { new DerivedB(1); } + createBaseInstance() { new BaseB(1); } // error +} + +class DerivedC extends BaseC { // error + constructor(public x: number) { super(x); } + createInstance() { new DerivedC(1); } + createBaseInstance() { new BaseC(1); } // error +} + +var ba = new BaseA(1); +var bb = new BaseB(1); // error +var bc = new BaseC(1); // error + +var da = new DerivedA(1); +var db = new DerivedB(1); +var dc = new DerivedC(1); \ No newline at end of file diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts new file mode 100644 index 00000000000..8508a40d101 --- /dev/null +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts @@ -0,0 +1,35 @@ +// @declaration: true + +class Foo { + constructor(public x: number) { } +} + +class Bar { + public constructor(public x: number) { } +} + +class Baz { + protected constructor(public x: number) { } +} + +class Qux { + private constructor(public x: number) { } +} + +// b is public +let a = Foo; +a = Bar; +a = Baz; // error Baz is protected +a = Qux; // error Qux is private + +// b is protected +let b = Baz; +b = Foo; // error Foo is public +b = Bar; // error Baz is public +b = Qux; // error Qux is private + +// c is private +let c = Qux; +c = Foo; // error Foo is public +c = Bar; // error Bar is public +c = Baz; // error Baz is protected \ No newline at end of file diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts new file mode 100644 index 00000000000..5ed20d03853 --- /dev/null +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts @@ -0,0 +1,34 @@ +// @declaration: true + +class A { + public constructor(a: boolean) // error + protected constructor(a: number) // error + private constructor(a: string) + private constructor() { + + } +} + +class B { + protected constructor(a: number) // error + constructor(a: string) + constructor() { + + } +} + +class C { + protected constructor(a: number) + protected constructor(a: string) + protected constructor() { + + } +} + +class D { + constructor(a: number) + constructor(a: string) + public constructor() { + + } +} \ No newline at end of file diff --git a/tests/cases/conformance/types/members/typesWithPrivateConstructor.ts b/tests/cases/conformance/types/members/typesWithPrivateConstructor.ts index 4fb24ca58e4..321864e1751 100644 --- a/tests/cases/conformance/types/members/typesWithPrivateConstructor.ts +++ b/tests/cases/conformance/types/members/typesWithPrivateConstructor.ts @@ -1,10 +1,10 @@ -// private constructors are not allowed +// @declaration: true class C { private constructor() { } } -var c = new C(); +var c = new C(); // error C is private var r: () => void = c.constructor; class C2 { @@ -12,5 +12,5 @@ class C2 { private constructor(x: any) { } } -var c2 = new C2(); +var c2 = new C2(); // error C2 is private var r2: (x: number) => void = c2.constructor; \ No newline at end of file diff --git a/tests/cases/conformance/types/members/typesWithProtectedConstructor.ts b/tests/cases/conformance/types/members/typesWithProtectedConstructor.ts new file mode 100644 index 00000000000..e7f6adc38a8 --- /dev/null +++ b/tests/cases/conformance/types/members/typesWithProtectedConstructor.ts @@ -0,0 +1,16 @@ +// @declaration: true + +class C { + protected constructor() { } +} + +var c = new C(); // error C is protected +var r: () => void = c.constructor; + +class C2 { + protected constructor(x: number); + protected constructor(x: any) { } +} + +var c2 = new C2(); // error C2 is protected +var r2: (x: number) => void = c2.constructor; \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnPrivateConstructorCall.ts b/tests/cases/fourslash/quickInfoOnPrivateConstructorCall.ts new file mode 100644 index 00000000000..5ebdcd815b2 --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnPrivateConstructorCall.ts @@ -0,0 +1,9 @@ +/// + +////class A { +//// private constructor() {} +////} +////var x = new A(/*1*/ + +goTo.marker("1"); +verify.not.signatureHelpPresent(); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnProtectedConstructorCall.ts b/tests/cases/fourslash/quickInfoOnProtectedConstructorCall.ts new file mode 100644 index 00000000000..094a07f3d51 --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnProtectedConstructorCall.ts @@ -0,0 +1,9 @@ +/// + +////class A { +//// protected constructor() {} +////} +////var x = new A(/*1*/ + +goTo.marker("1"); +verify.not.signatureHelpPresent(); \ No newline at end of file From daa70e3f23ee9ad91129b4e71ba8dc0007db0962 Mon Sep 17 00:00:00 2001 From: Jesse Schalken Date: Thu, 4 Feb 2016 11:38:21 +1100 Subject: [PATCH 013/297] Fix Stack Overflow and Gitter links in CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1dba1281dd7..7a99bf318d2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,7 @@ Issues that ask questions answered in the FAQ will be closed without elaboration ## 3. Do you have a question? The issue tracker is for **issues**, in other words, bugs and suggestions. -If you have a *question*, please use [http://stackoverflow.com/questions/tagged/typescript](Stack Overflow), [https://gitter.im/Microsoft/TypeScript](Gitter), your favorite search engine, or other resources. +If you have a *question*, please use [Stack Overflow](http://stackoverflow.com/questions/tagged/typescript), [Gitter](https://gitter.im/Microsoft/TypeScript), your favorite search engine, or other resources. Due to increased traffic, we can no longer answer questions in the issue tracker. ## 4. Did you find a bug? From 2c24f81561778b88248ef6c28482ad83fddf0488 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Feb 2016 21:43:31 -0800 Subject: [PATCH 014/297] added tests --- .../baselines/reference/keepImportsInDts1.js | 16 +++++++++++++ .../reference/keepImportsInDts1.symbols | 6 +++++ .../reference/keepImportsInDts1.types | 6 +++++ .../baselines/reference/keepImportsInDts2.js | 22 +++++++++++++++++ .../reference/keepImportsInDts2.symbols | 6 +++++ .../reference/keepImportsInDts2.types | 6 +++++ .../baselines/reference/keepImportsInDts3.js | 24 +++++++++++++++++++ .../reference/keepImportsInDts3.symbols | 6 +++++ .../reference/keepImportsInDts3.types | 6 +++++ .../baselines/reference/keepImportsInDts4.js | 24 +++++++++++++++++++ .../reference/keepImportsInDts4.symbols | 6 +++++ .../reference/keepImportsInDts4.types | 6 +++++ .../baselines/reference/noErrorOnEmptyDts.js | 13 ---------- .../reference/noErrorOnEmptyDts.symbols | 8 ------- .../reference/noErrorOnEmptyDts.types | 8 ------- tests/cases/compiler/keepImportsInDts1.ts | 7 ++++++ tests/cases/compiler/keepImportsInDts2.ts | 7 ++++++ tests/cases/compiler/keepImportsInDts3.ts | 8 +++++++ tests/cases/compiler/keepImportsInDts4.ts | 8 +++++++ tests/cases/compiler/noErrorOnEmptyDts.ts | 8 ------- 20 files changed, 164 insertions(+), 37 deletions(-) create mode 100644 tests/baselines/reference/keepImportsInDts1.js create mode 100644 tests/baselines/reference/keepImportsInDts1.symbols create mode 100644 tests/baselines/reference/keepImportsInDts1.types create mode 100644 tests/baselines/reference/keepImportsInDts2.js create mode 100644 tests/baselines/reference/keepImportsInDts2.symbols create mode 100644 tests/baselines/reference/keepImportsInDts2.types create mode 100644 tests/baselines/reference/keepImportsInDts3.js create mode 100644 tests/baselines/reference/keepImportsInDts3.symbols create mode 100644 tests/baselines/reference/keepImportsInDts3.types create mode 100644 tests/baselines/reference/keepImportsInDts4.js create mode 100644 tests/baselines/reference/keepImportsInDts4.symbols create mode 100644 tests/baselines/reference/keepImportsInDts4.types delete mode 100644 tests/baselines/reference/noErrorOnEmptyDts.js delete mode 100644 tests/baselines/reference/noErrorOnEmptyDts.symbols delete mode 100644 tests/baselines/reference/noErrorOnEmptyDts.types create mode 100644 tests/cases/compiler/keepImportsInDts1.ts create mode 100644 tests/cases/compiler/keepImportsInDts2.ts create mode 100644 tests/cases/compiler/keepImportsInDts3.ts create mode 100644 tests/cases/compiler/keepImportsInDts4.ts delete mode 100644 tests/cases/compiler/noErrorOnEmptyDts.ts diff --git a/tests/baselines/reference/keepImportsInDts1.js b/tests/baselines/reference/keepImportsInDts1.js new file mode 100644 index 00000000000..8189ce43088 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts1.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/keepImportsInDts1.ts] //// + +//// [test.d.ts] + +export {}; +//// [main.ts] +import "test" + +//// [main.js] +define(["require", "exports", "test"], function (require, exports) { + "use strict"; +}); + + +//// [main.d.ts] +import "test"; diff --git a/tests/baselines/reference/keepImportsInDts1.symbols b/tests/baselines/reference/keepImportsInDts1.symbols new file mode 100644 index 00000000000..92bd84c2088 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts1.symbols @@ -0,0 +1,6 @@ +=== c:/test.d.ts === + +No type information for this code.export {}; +No type information for this code.=== c:/app/main.ts === +import "test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/keepImportsInDts1.types b/tests/baselines/reference/keepImportsInDts1.types new file mode 100644 index 00000000000..92bd84c2088 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts1.types @@ -0,0 +1,6 @@ +=== c:/test.d.ts === + +No type information for this code.export {}; +No type information for this code.=== c:/app/main.ts === +import "test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/keepImportsInDts2.js b/tests/baselines/reference/keepImportsInDts2.js new file mode 100644 index 00000000000..559b4814526 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts2.js @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/keepImportsInDts2.ts] //// + +//// [test.ts] + +export {}; +//// [main.ts] +import "./folder/test" + +//// [test.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [main.js] +define(["require", "exports", "./folder/test"], function (require, exports) { + "use strict"; +}); + + +//// [test.d.ts] +export { }; +//// [main.d.ts] +import "./folder/test"; diff --git a/tests/baselines/reference/keepImportsInDts2.symbols b/tests/baselines/reference/keepImportsInDts2.symbols new file mode 100644 index 00000000000..ce6f4c7c168 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts2.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/folder/test.ts === + +No type information for this code.export {}; +No type information for this code.=== tests/cases/compiler/main.ts === +import "./folder/test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/keepImportsInDts2.types b/tests/baselines/reference/keepImportsInDts2.types new file mode 100644 index 00000000000..ce6f4c7c168 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts2.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/folder/test.ts === + +No type information for this code.export {}; +No type information for this code.=== tests/cases/compiler/main.ts === +import "./folder/test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/keepImportsInDts3.js b/tests/baselines/reference/keepImportsInDts3.js new file mode 100644 index 00000000000..e48ba693726 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts3.js @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/keepImportsInDts3.ts] //// + +//// [test.ts] + +export {}; +//// [main.ts] +import "test" + +//// [outputfile.js] +define("test", ["require", "exports"], function (require, exports) { + "use strict"; +}); +define("app/main", ["require", "exports", "test"], function (require, exports) { + "use strict"; +}); + + +//// [outputfile.d.ts] +declare module "test" { + export { }; +} +declare module "app/main" { + import "test"; +} diff --git a/tests/baselines/reference/keepImportsInDts3.symbols b/tests/baselines/reference/keepImportsInDts3.symbols new file mode 100644 index 00000000000..29c4a4e44b4 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts3.symbols @@ -0,0 +1,6 @@ +=== c:/test.ts === + +No type information for this code.export {}; +No type information for this code.=== c:/app/main.ts === +import "test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/keepImportsInDts3.types b/tests/baselines/reference/keepImportsInDts3.types new file mode 100644 index 00000000000..29c4a4e44b4 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts3.types @@ -0,0 +1,6 @@ +=== c:/test.ts === + +No type information for this code.export {}; +No type information for this code.=== c:/app/main.ts === +import "test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/keepImportsInDts4.js b/tests/baselines/reference/keepImportsInDts4.js new file mode 100644 index 00000000000..badec87984e --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts4.js @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/keepImportsInDts4.ts] //// + +//// [test.ts] + +export {}; +//// [main.ts] +import "./folder/test" + +//// [outputfile.js] +define("folder/test", ["require", "exports"], function (require, exports) { + "use strict"; +}); +define("main", ["require", "exports", "folder/test"], function (require, exports) { + "use strict"; +}); + + +//// [outputfile.d.ts] +declare module "folder/test" { + export { }; +} +declare module "main" { + import "folder/test"; +} diff --git a/tests/baselines/reference/keepImportsInDts4.symbols b/tests/baselines/reference/keepImportsInDts4.symbols new file mode 100644 index 00000000000..ce6f4c7c168 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts4.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/folder/test.ts === + +No type information for this code.export {}; +No type information for this code.=== tests/cases/compiler/main.ts === +import "./folder/test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/keepImportsInDts4.types b/tests/baselines/reference/keepImportsInDts4.types new file mode 100644 index 00000000000..ce6f4c7c168 --- /dev/null +++ b/tests/baselines/reference/keepImportsInDts4.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/folder/test.ts === + +No type information for this code.export {}; +No type information for this code.=== tests/cases/compiler/main.ts === +import "./folder/test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/noErrorOnEmptyDts.js b/tests/baselines/reference/noErrorOnEmptyDts.js deleted file mode 100644 index 83595e3d2ad..00000000000 --- a/tests/baselines/reference/noErrorOnEmptyDts.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [tests/cases/compiler/noErrorOnEmptyDts.ts] //// - -//// [test.d.ts] - - -// comment - -//// [main.ts] -import "test" - -//// [main.js] -"use strict"; -require("test"); diff --git a/tests/baselines/reference/noErrorOnEmptyDts.symbols b/tests/baselines/reference/noErrorOnEmptyDts.symbols deleted file mode 100644 index 78446a19fb8..00000000000 --- a/tests/baselines/reference/noErrorOnEmptyDts.symbols +++ /dev/null @@ -1,8 +0,0 @@ -=== c:/node_modules/test.d.ts === - -No type information for this code. -No type information for this code.// comment -No type information for this code. -No type information for this code.=== c:/app/main.ts === -import "test" -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/noErrorOnEmptyDts.types b/tests/baselines/reference/noErrorOnEmptyDts.types deleted file mode 100644 index 78446a19fb8..00000000000 --- a/tests/baselines/reference/noErrorOnEmptyDts.types +++ /dev/null @@ -1,8 +0,0 @@ -=== c:/node_modules/test.d.ts === - -No type information for this code. -No type information for this code.// comment -No type information for this code. -No type information for this code.=== c:/app/main.ts === -import "test" -No type information for this code. \ No newline at end of file diff --git a/tests/cases/compiler/keepImportsInDts1.ts b/tests/cases/compiler/keepImportsInDts1.ts new file mode 100644 index 00000000000..50bdc5830a8 --- /dev/null +++ b/tests/cases/compiler/keepImportsInDts1.ts @@ -0,0 +1,7 @@ +// @module: amd +// @declaration: true + +// @filename: c:/test.d.ts +export {}; +// @filename: c:/app/main.ts +import "test" \ No newline at end of file diff --git a/tests/cases/compiler/keepImportsInDts2.ts b/tests/cases/compiler/keepImportsInDts2.ts new file mode 100644 index 00000000000..407526d7595 --- /dev/null +++ b/tests/cases/compiler/keepImportsInDts2.ts @@ -0,0 +1,7 @@ +// @module: amd +// @declaration: true + +// @filename: folder/test.ts +export {}; +// @filename: main.ts +import "./folder/test" \ No newline at end of file diff --git a/tests/cases/compiler/keepImportsInDts3.ts b/tests/cases/compiler/keepImportsInDts3.ts new file mode 100644 index 00000000000..cdd83dce132 --- /dev/null +++ b/tests/cases/compiler/keepImportsInDts3.ts @@ -0,0 +1,8 @@ +// @module: amd +// @declaration: true +// @out: outputfile.js + +// @filename: c:/test.ts +export {}; +// @filename: c:/app/main.ts +import "test" \ No newline at end of file diff --git a/tests/cases/compiler/keepImportsInDts4.ts b/tests/cases/compiler/keepImportsInDts4.ts new file mode 100644 index 00000000000..272932be488 --- /dev/null +++ b/tests/cases/compiler/keepImportsInDts4.ts @@ -0,0 +1,8 @@ +// @module: amd +// @declaration: true +// @out: outputfile.js + +// @filename: folder/test.ts +export {}; +// @filename: main.ts +import "./folder/test" \ No newline at end of file diff --git a/tests/cases/compiler/noErrorOnEmptyDts.ts b/tests/cases/compiler/noErrorOnEmptyDts.ts deleted file mode 100644 index 1266ea2bd75..00000000000 --- a/tests/cases/compiler/noErrorOnEmptyDts.ts +++ /dev/null @@ -1,8 +0,0 @@ -// @module: commonjs - -// @filename: c:/node_modules/test.d.ts - -// comment - -// @filename: c:/app/main.ts -import "test" \ No newline at end of file From dbcfe110f1c82f0b247e186f68c95ab5afc5f999 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Feb 2016 23:48:24 -0800 Subject: [PATCH 015/297] propagate back assignments to block scoped binding from the loop body --- src/compiler/checker.ts | 44 +++ src/compiler/emitter.ts | 148 +++++++-- src/compiler/types.ts | 1 + .../blockScopedBindingsReassignedInLoop1.js | 23 ++ ...ockScopedBindingsReassignedInLoop1.symbols | 17 + ...blockScopedBindingsReassignedInLoop1.types | 32 ++ .../blockScopedBindingsReassignedInLoop2.js | 128 ++++++++ ...ockScopedBindingsReassignedInLoop2.symbols | 98 ++++++ ...blockScopedBindingsReassignedInLoop2.types | 160 ++++++++++ .../blockScopedBindingsReassignedInLoop3.js | 259 +++++++++++++++ ...ockScopedBindingsReassignedInLoop3.symbols | 203 ++++++++++++ ...blockScopedBindingsReassignedInLoop3.types | 301 ++++++++++++++++++ .../blockScopedBindingsReassignedInLoop4.js | 36 +++ ...ockScopedBindingsReassignedInLoop4.symbols | 28 ++ ...blockScopedBindingsReassignedInLoop4.types | 43 +++ .../blockScopedBindingsReassignedInLoop5.js | 29 ++ ...ockScopedBindingsReassignedInLoop5.symbols | 23 ++ ...blockScopedBindingsReassignedInLoop5.types | 37 +++ .../blockScopedBindingsReassignedInLoop6.js | 78 +++++ ...ockScopedBindingsReassignedInLoop6.symbols | 74 +++++ ...blockScopedBindingsReassignedInLoop6.types | 110 +++++++ .../reference/nestedBlockScopedBindings3.js | 8 + .../reference/nestedBlockScopedBindings4.js | 16 + .../reference/nestedBlockScopedBindings5.js | 12 + .../reference/nestedBlockScopedBindings6.js | 8 + .../blockScopedBindingsReassignedInLoop1.ts | 7 + .../blockScopedBindingsReassignedInLoop2.ts | 41 +++ .../blockScopedBindingsReassignedInLoop3.ts | 91 ++++++ .../blockScopedBindingsReassignedInLoop4.ts | 11 + .../blockScopedBindingsReassignedInLoop5.ts | 7 + .../blockScopedBindingsReassignedInLoop6.ts | 28 ++ 31 files changed, 2081 insertions(+), 20 deletions(-) create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop1.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop1.types create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop2.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop3.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop4.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop5.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop6.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0628e7fd522..65cb3df785f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7264,6 +7264,15 @@ namespace ts { // mark iteration statement as containing block-scoped binding captured in some function getNodeLinks(current).flags |= NodeCheckFlags.LoopWithCapturedBlockScopedBinding; } + + // mark variables that are declared in loop initializer and reassigned inside the body of ForStatement. + // if body of ForStatement will be converted to function then we'll need a extra machinery to propagate reassigned values back. + if (container.kind === SyntaxKind.ForStatement && + getAncestor(symbol.valueDeclaration, SyntaxKind.VariableDeclarationList).parent === container && + isAssignedInBodyOfForStatement(node, container)) { + getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.NeedsLoopOutParameter; + } + // set 'declared inside loop' bit on the block-scoped binding getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.BlockScopedBindingInLoop; } @@ -7273,6 +7282,41 @@ namespace ts { } } + function isAssignedInBodyOfForStatement(node: Identifier, container: ForStatement): boolean { + let current: Node = node; + // skip parenthesized nodes + while (current.parent.kind === SyntaxKind.ParenthesizedExpression) { + current = current.parent; + } + + // check if node is used as LHS in some assignment expression + let isAssigned = false; + if (current.parent.kind === SyntaxKind.BinaryExpression) { + isAssigned = (current.parent).left === current && isAssignmentOperator((current.parent).operatorToken.kind); + } + + if ((current.parent.kind === SyntaxKind.PrefixUnaryExpression || current.parent.kind === SyntaxKind.PostfixUnaryExpression)) { + const expr = current.parent; + isAssigned = expr.operator === SyntaxKind.PlusPlusToken || expr.operator === SyntaxKind.MinusMinusToken; + } + + if (!isAssigned) { + return false; + } + + // at this point we know that node is the target of assignment + // now check that modification happens inside the statement part of the ForStatement + while (current !== container) { + if (current === container.statement) { + return true; + } + else { + current = current.parent; + } + } + return false; + } + function captureLexicalThis(node: Node, container: Node): void { getNodeLinks(node).flags |= NodeCheckFlags.LexicalThis; if (container.kind === SyntaxKind.PropertyDeclaration || container.kind === SyntaxKind.Constructor) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e86d86603b4..be6a4dc36fc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -287,6 +287,54 @@ namespace ts { _i = 0x10000000, // Use/preference flag for '_i' } + const enum CopyDirection { + ToOriginal, + ToOutParameter + } + + /** + * If loop contains block scoped binding captured in some function then loop body is converted to a function. + * Lexical bindings declared in loop initializer will be passed into the loop body function as parameters, + * however if this binding is modified inside the body - this new value should be propagated back to the original binding. + * This is done by declaring new variable (out parameter holder) outside of the loop for every binding that is reassigned inside the body. + * On every iteration this variable is initialized with value of corresponding binding. + * At every point where control flow leaves the loop either explicitly (break/continue) or implicitly (at the end of loop body) + * we copy the value inside the loop to the out parameter holder. + * + * for (let x;;) { + * let a = 1; + * let b = () => a; + * x++ + * if (...) break; + * ... + * } + * + * will be converted to + * + * var out_x; + * var loop = function(x) { + * var a = 1; + * var b = function() { return a; } + * x++; + * if (...) return out_x = x, "break"; + * ... + * out_x = x; + * } + * for (var x;;) { + * out_x = x; + * var state = loop(x); + * x = out_x; + * if (state === "break") break; + * } + * + * NOTE: values to out parameters are not copies if loop is abrupted with 'return' - in this case this will end the entire enclosing function + * so nobody can observe this new value. + */ + interface LoopOutParameter { + originalName: Identifier; + outParamName: string; + } + // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile): EmitResult { // emit output for the __extends helper function @@ -419,6 +467,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge * for (var x;;) loop(x); */ hoistedLocalVariables?: Identifier[]; + + /** + * List of loop out parameters - detailed descripion can be found in the comment to LoopOutParameter + */ + loopOutParameters?: LoopOutParameter[]; } function setLabeledJump(state: ConvertedLoopState, isBreak: boolean, labelText: string, labelMarker: string): void { @@ -2968,11 +3021,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } let loopParameters: string[]; + let loopOutParameters: LoopOutParameter[]; if (loopInitializer && (getCombinedNodeFlags(loopInitializer) & NodeFlags.BlockScoped)) { // if loop initializer contains block scoped variables - they should be passed to converted loop body as parameters loopParameters = []; for (const varDeclaration of loopInitializer.declarations) { - collectNames(varDeclaration.name); + processVariableDeclaration(varDeclaration.name); } } @@ -2982,14 +3036,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge writeLine(); write(`var ${functionName} = function(${paramList})`); - if (!bodyIsBlock) { - write(" {"); - writeLine(); - increaseIndent(); - } - const convertedOuterLoopState = convertedLoopState; - convertedLoopState = {}; + convertedLoopState = { loopOutParameters }; if (convertedOuterLoopState) { // convertedOuterLoopState !== undefined means that this converted loop is nested in another converted loop. @@ -3013,16 +3061,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } - emitEmbeddedStatement(node.statement); + write(" {"); + writeLine(); + increaseIndent(); - if (!bodyIsBlock) { - decreaseIndent(); - writeLine(); - write("}"); + if (bodyIsBlock) { + emitLines((node.statement).statements); } - write(";"); + else { + emit(node.statement); + } + + writeLine(); + // end of loop body -> copy out parameter + copyLoopOutParameters(convertedLoopState, CopyDirection.ToOutParameter, /*emitAsStatements*/true); + + decreaseIndent(); + writeLine(); + write("};"); writeLine(); + if (loopOutParameters) { + // declare variables to hold out params for loop body + write(`var `); + for (let i = 0; i < loopOutParameters.length; i++) { + if (i !== 0) { + write(", "); + } + write(loopOutParameters[i].outParamName); + } + write(";"); + writeLine(); + } if (convertedLoopState.argumentsName) { // if alias for arguments is set if (convertedOuterLoopState) { @@ -3086,14 +3156,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge return { functionName, paramList, state: currentLoopState }; - function collectNames(name: Identifier | BindingPattern): void { + function processVariableDeclaration(name: Identifier | BindingPattern): void { if (name.kind === SyntaxKind.Identifier) { - const nameText = isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(name) ? getGeneratedNameForNode(name) : (name).text; + const nameText = isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(name) + ? getGeneratedNameForNode(name) + : (name).text; + loopParameters.push(nameText); + if (resolver.getNodeCheckFlags(name.parent) & NodeCheckFlags.NeedsLoopOutParameter) { + const reassignedVariable = { originalName: name, outParamName: makeUniqueName(`out_${nameText}`) }; + (loopOutParameters || (loopOutParameters = [])).push(reassignedVariable); + } } else { for (const element of (name).elements) { - collectNames(element.name); + processVariableDeclaration(element.name); } } } @@ -3124,6 +3201,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } + function copyLoopOutParameters(state: ConvertedLoopState, copyDirection: CopyDirection, emitAsStatements: boolean) { + if (state.loopOutParameters) { + for (const outParam of state.loopOutParameters) { + if (copyDirection === CopyDirection.ToOriginal) { + emitIdentifier(outParam.originalName); + write(` = ${outParam.outParamName}`); + } + else { + write(`${outParam.outParamName} = `); + emitIdentifier(outParam.originalName); + } + if (emitAsStatements) { + write(";"); + writeLine(); + } + else { + write(", "); + } + } + } + } + function emitConvertedLoopCall(loop: ConvertedLoop, emitAsBlock: boolean): void { if (emitAsBlock) { write(" {"); @@ -3138,12 +3237,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge !loop.state.labeledNonLocalBreaks && !loop.state.labeledNonLocalContinues; + copyLoopOutParameters(loop.state, CopyDirection.ToOutParameter, /*emitAsStatements*/ true); + writeLine(); + const loopResult = makeUniqueName("state"); if (!isSimpleLoop) { write(`var ${loopResult} = `); } write(`${loop.functionName}(${loop.paramList});`); + writeLine(); + + copyLoopOutParameters(loop.state, CopyDirection.ToOriginal, /*emitAsStatements*/ true); if (!isSimpleLoop) { // for non simple loops we need to store result returned from converted loop function and use it to do dispatching @@ -3463,14 +3568,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge (!node.label && (convertedLoopState.allowedNonLabeledJumps & jump)); if (!canUseBreakOrContinue) { + write ("return "); + // explicit exit from loop -> copy out parameters + copyLoopOutParameters(convertedLoopState, CopyDirection.ToOutParameter, /*emitAsStatements*/ false); if (!node.label) { if (node.kind === SyntaxKind.BreakStatement) { convertedLoopState.nonLocalJumps |= Jump.Break; - write(`return "break";`); + write(`"break";`); } else { convertedLoopState.nonLocalJumps |= Jump.Continue; - write(`return "continue";`); + write(`"continue";`); } } else { @@ -3483,7 +3591,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge labelMarker = `continue-${node.label.text}`; setLabeledJump(convertedLoopState, /*isBreak*/ false, node.label.text, labelMarker); } - write(`return "${labelMarker}";`); + write(`"${labelMarker}";`); } return; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5545fbd162e..b5040ed5eb9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2044,6 +2044,7 @@ namespace ts { HasSeenSuperCall = 0x00080000, // Set during the binding when encounter 'super' ClassWithBodyScopedClassBinding = 0x00100000, // Decorated class that contains a binding to itself inside of the class body. BodyScopedClassBinding = 0x00200000, // Binding to a decorated class inside of the class's body. + NeedsLoopOutParameter = 0x00400000, // Block scoped binding whose value should be explicitly copied outside of the converted loop } /* @internal */ diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js new file mode 100644 index 00000000000..84e013c3b02 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js @@ -0,0 +1,23 @@ +//// [blockScopedBindingsReassignedInLoop1.ts] +declare function use(n: number): void; +(function () { + 'use strict' + for (let i = 0; i < 9; ++i) { + (() => use(++i))(); + } +})(); + +//// [blockScopedBindingsReassignedInLoop1.js] +(function () { + 'use strict'; + var _loop_1 = function(i) { + (function () { return use(++i); })(); + out_i_1 = i; + }; + var out_i_1; + for (var i = 0; i < 9; ++i) { + out_i_1 = i; + _loop_1(i); + i = out_i_1; + } +})(); diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.symbols new file mode 100644 index 00000000000..8024124b04e --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts === +declare function use(n: number): void; +>use : Symbol(use, Decl(blockScopedBindingsReassignedInLoop1.ts, 0, 0)) +>n : Symbol(n, Decl(blockScopedBindingsReassignedInLoop1.ts, 0, 21)) + +(function () { + 'use strict' + for (let i = 0; i < 9; ++i) { +>i : Symbol(i, Decl(blockScopedBindingsReassignedInLoop1.ts, 3, 10)) +>i : Symbol(i, Decl(blockScopedBindingsReassignedInLoop1.ts, 3, 10)) +>i : Symbol(i, Decl(blockScopedBindingsReassignedInLoop1.ts, 3, 10)) + + (() => use(++i))(); +>use : Symbol(use, Decl(blockScopedBindingsReassignedInLoop1.ts, 0, 0)) +>i : Symbol(i, Decl(blockScopedBindingsReassignedInLoop1.ts, 3, 10)) + } +})(); diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.types new file mode 100644 index 00000000000..7ced53508e6 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts === +declare function use(n: number): void; +>use : (n: number) => void +>n : number + +(function () { +>(function () { 'use strict' for (let i = 0; i < 9; ++i) { (() => use(++i))(); }})() : void +>(function () { 'use strict' for (let i = 0; i < 9; ++i) { (() => use(++i))(); }}) : () => void +>function () { 'use strict' for (let i = 0; i < 9; ++i) { (() => use(++i))(); }} : () => void + + 'use strict' +>'use strict' : string + + for (let i = 0; i < 9; ++i) { +>i : number +>0 : number +>i < 9 : boolean +>i : number +>9 : number +>++i : number +>i : number + + (() => use(++i))(); +>(() => use(++i))() : void +>(() => use(++i)) : () => void +>() => use(++i) : () => void +>use(++i) : void +>use : (n: number) => void +>++i : number +>i : number + } +})(); diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js new file mode 100644 index 00000000000..82719448e24 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js @@ -0,0 +1,128 @@ +//// [blockScopedBindingsReassignedInLoop2.ts] +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break; + } + else { + y = 5; + } +} + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue; + } + else { + y = 5; + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break loop; + } + else { + y = 5; + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue loop; + } + else { + y = 5; + } +} + +//// [blockScopedBindingsReassignedInLoop2.js] +var _loop_1 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_1 = x, out_y_1 = y, "break"; + } + else { + y = 5; + } + out_x_1 = x; + out_y_1 = y; +}; +var out_x_1, out_y_1; +for (var x = 1, y = 2; x < y; ++x, --y) { + out_x_1 = x; + out_y_1 = y; + var state_1 = _loop_1(x, y); + x = out_x_1; + y = out_y_1; + if (state_1 === "break") break; +} +var _loop_2 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_2 = x, out_y_2 = y, "continue"; + } + else { + y = 5; + } + out_x_2 = x; + out_y_2 = y; +}; +var out_x_2, out_y_2; +for (var x = 1, y = 2; x < y; ++x, --y) { + out_x_2 = x; + out_y_2 = y; + var state_2 = _loop_2(x, y); + x = out_x_2; + y = out_y_2; + if (state_2 === "continue") continue; +} +var _loop_3 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_3 = x, out_y_3 = y, "break-loop"; + } + else { + y = 5; + } + out_x_3 = x; + out_y_3 = y; +}; +var out_x_3, out_y_3; +loop: for (var x = 1, y = 2; x < y; ++x, --y) { + out_x_3 = x; + out_y_3 = y; + var state_3 = _loop_3(x, y); + x = out_x_3; + y = out_y_3; + switch(state_3) { + case "break-loop": break loop; + } +} +var _loop_4 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_4 = x, out_y_4 = y, "continue-loop"; + } + else { + y = 5; + } + out_x_4 = x; + out_y_4 = y; +}; +var out_x_4, out_y_4; +loop: for (var x = 1, y = 2; x < y; ++x, --y) { + out_x_4 = x; + out_y_4 = y; + var state_4 = _loop_4(x, y); + x = out_x_4; + y = out_y_4; + switch(state_4) { + case "continue-loop": continue loop; + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.symbols new file mode 100644 index 00000000000..fcaea39564f --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.symbols @@ -0,0 +1,98 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts === +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop2.ts, 1, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 8)) + + break; + } + else { + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 15)) + } +} + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop2.ts, 11, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 8)) + + continue; + } + else { + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 15)) + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop2.ts, 22, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 8)) + + break loop; + } + else { + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 15)) + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop2.ts, 33, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 8)) + + continue loop; + } + else { + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 15)) + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types new file mode 100644 index 00000000000..244160dcc6b --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types @@ -0,0 +1,160 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts === +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + break; + } + else { + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + continue; + } + else { + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + +loop: +>loop : any + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + break loop; +>loop : any + } + else { + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + +loop: +>loop : any + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + continue loop; +>loop : any + } + else { + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js new file mode 100644 index 00000000000..8780afbdf54 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js @@ -0,0 +1,259 @@ +//// [blockScopedBindingsReassignedInLoop3.ts] + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break; + } + else { + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + break; + } + else { + y++; + } + } + + y = 5; + } +} + + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue; + } + else { + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + continue; + } + else { + y++; + } + } + + y = 5; + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + break loop1; + } + else { + y++; + break loop2 + } + } + + y = 5; + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + continue loop1; + } + else { + y++; + continue loop2 + } + } + + y = 5; + } +} + + +//// [blockScopedBindingsReassignedInLoop3.js] +var _loop_1 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_1 = x, out_y_1 = y, "break"; + } + else { + var _loop_2 = function(a_1) { + var f = function () { return a_1; }; + if (a_1) { + a_1 = x; + return out_a_1_1 = a_1, "break"; + } + else { + y++; + } + out_a_1_1 = a_1; + }; + var out_a_1_1; + for (var a_1 = 1; a_1 < 5; --a_1) { + out_a_1_1 = a_1; + var state_1 = _loop_2(a_1); + a_1 = out_a_1_1; + if (state_1 === "break") break; + } + y = 5; + } + out_x_1 = x; + out_y_1 = y; +}; +var out_x_1, out_y_1; +for (var x = 1, y = 2; x < y; ++x, --y) { + out_x_1 = x; + out_y_1 = y; + var state_2 = _loop_1(x, y); + x = out_x_1; + y = out_y_1; + if (state_2 === "break") break; +} +var _loop_3 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_2 = x, out_y_2 = y, "continue"; + } + else { + var _loop_4 = function(a_2) { + var f = function () { return a_2; }; + if (a_2) { + a_2 = x; + return out_a_2_1 = a_2, "continue"; + } + else { + y++; + } + out_a_2_1 = a_2; + }; + var out_a_2_1; + for (var a_2 = 1; a_2 < 5; --a_2) { + out_a_2_1 = a_2; + var state_3 = _loop_4(a_2); + a_2 = out_a_2_1; + if (state_3 === "continue") continue; + } + y = 5; + } + out_x_2 = x; + out_y_2 = y; +}; +var out_x_2, out_y_2; +for (var x = 1, y = 2; x < y; ++x, --y) { + out_x_2 = x; + out_y_2 = y; + var state_4 = _loop_3(x, y); + x = out_x_2; + y = out_y_2; + if (state_4 === "continue") continue; +} +var _loop_5 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_3 = x, out_y_3 = y, "break-loop2"; + } + else { + var _loop_6 = function(a_3) { + var f = function () { return a_3; }; + if (a_3) { + a_3 = x; + return out_a_3_1 = a_3, "break-loop1"; + } + else { + y++; + return out_a_3_1 = a_3, "break-loop2"; + } + out_a_3_1 = a_3; + }; + var out_a_3_1; + loop1: for (var a_3 = 1; a_3 < 5; --a_3) { + out_a_3_1 = a_3; + var state_5 = _loop_6(a_3); + a_3 = out_a_3_1; + switch(state_5) { + case "break-loop1": break loop1; + case "break-loop2": return state_5; + } + } + y = 5; + } + out_x_3 = x; + out_y_3 = y; +}; +var out_x_3, out_y_3; +loop2: for (var x = 1, y = 2; x < y; ++x, --y) { + out_x_3 = x; + out_y_3 = y; + var state_6 = _loop_5(x, y); + x = out_x_3; + y = out_y_3; + switch(state_6) { + case "break-loop2": break loop2; + } +} +var _loop_7 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_4 = x, out_y_4 = y, "continue-loop2"; + } + else { + var _loop_8 = function(a_4) { + var f = function () { return a_4; }; + if (a_4) { + a_4 = x; + return out_a_4_1 = a_4, "continue-loop1"; + } + else { + y++; + return out_a_4_1 = a_4, "continue-loop2"; + } + out_a_4_1 = a_4; + }; + var out_a_4_1; + loop1: for (var a_4 = 1; a_4 < 5; --a_4) { + out_a_4_1 = a_4; + var state_7 = _loop_8(a_4); + a_4 = out_a_4_1; + switch(state_7) { + case "continue-loop1": continue loop1; + case "continue-loop2": return state_7; + } + } + y = 5; + } + out_x_4 = x; + out_y_4 = y; +}; +var out_x_4, out_y_4; +loop2: for (var x = 1, y = 2; x < y; ++x, --y) { + out_x_4 = x; + out_y_4 = y; + var state_8 = _loop_7(x, y); + x = out_x_4; + y = out_y_4; + switch(state_8) { + case "continue-loop2": continue loop2; + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.symbols new file mode 100644 index 00000000000..f78cd684c3a --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.symbols @@ -0,0 +1,203 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts === + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 2, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) + + break; + } + else { + for (let a = 1; a < 5; --a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) + + let f = () => a; +>f : Symbol(f, Decl(blockScopedBindingsReassignedInLoop3.ts, 8, 15)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) + + if (a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) + + a = x; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) + + break; + } + else { + y++; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) + } + } + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) + } +} + + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 24, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) + + continue; + } + else { + for (let a = 1; a < 5; --a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) + + let f = () => a; +>f : Symbol(f, Decl(blockScopedBindingsReassignedInLoop3.ts, 30, 15)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) + + if (a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) + + a = x; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) + + continue; + } + else { + y++; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) + } + } + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 46, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) + + break loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) + + let f = () => a; +>f : Symbol(f, Decl(blockScopedBindingsReassignedInLoop3.ts, 53, 15)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) + + if (a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) + + a = x; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) + + break loop1; + } + else { + y++; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) + + break loop2 + } + } + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 70, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) + + continue loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) + + let f = () => a; +>f : Symbol(f, Decl(blockScopedBindingsReassignedInLoop3.ts, 77, 15)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) + + if (a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) + + a = x; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) + + continue loop1; + } + else { + y++; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) + + continue loop2 + } + } + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) + } +} + diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types new file mode 100644 index 00000000000..0753391d5c2 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types @@ -0,0 +1,301 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts === + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + break; + } + else { + for (let a = 1; a < 5; --a) { +>a : number +>1 : number +>a < 5 : boolean +>a : number +>5 : number +>--a : number +>a : number + + let f = () => a; +>f : () => number +>() => a : () => number +>a : number + + if (a) { +>a : number + + a = x; +>a = x : number +>a : number +>x : number + + break; + } + else { + y++; +>y++ : number +>y : number + } + } + + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + continue; + } + else { + for (let a = 1; a < 5; --a) { +>a : number +>1 : number +>a < 5 : boolean +>a : number +>5 : number +>--a : number +>a : number + + let f = () => a; +>f : () => number +>() => a : () => number +>a : number + + if (a) { +>a : number + + a = x; +>a = x : number +>a : number +>x : number + + continue; + } + else { + y++; +>y++ : number +>y : number + } + } + + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + +loop2: +>loop2 : any + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + break loop2; +>loop2 : any + } + else { + loop1: +>loop1 : any + + for (let a = 1; a < 5; --a) { +>a : number +>1 : number +>a < 5 : boolean +>a : number +>5 : number +>--a : number +>a : number + + let f = () => a; +>f : () => number +>() => a : () => number +>a : number + + if (a) { +>a : number + + a = x; +>a = x : number +>a : number +>x : number + + break loop1; +>loop1 : any + } + else { + y++; +>y++ : number +>y : number + + break loop2 +>loop2 : any + } + } + + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + +loop2: +>loop2 : any + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + continue loop2; +>loop2 : any + } + else { + loop1: +>loop1 : any + + for (let a = 1; a < 5; --a) { +>a : number +>1 : number +>a < 5 : boolean +>a : number +>5 : number +>--a : number +>a : number + + let f = () => a; +>f : () => number +>() => a : () => number +>a : number + + if (a) { +>a : number + + a = x; +>a = x : number +>a : number +>x : number + + continue loop1; +>loop1 : any + } + else { + y++; +>y++ : number +>y : number + + continue loop2 +>loop2 : any + } + } + + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js new file mode 100644 index 00000000000..e28c890932a --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js @@ -0,0 +1,36 @@ +//// [blockScopedBindingsReassignedInLoop4.ts] +function f1() { + for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + return 1; + } + else { + y = 5; + } + } +} + +//// [blockScopedBindingsReassignedInLoop4.js] +function f1() { + var _loop_1 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return { value: 1 }; + } + else { + y = 5; + } + out_x_1 = x; + out_y_1 = y; + }; + var out_x_1, out_y_1; + for (var x = 1, y = 2; x < y; ++x, --y) { + out_x_1 = x; + out_y_1 = y; + var state_1 = _loop_1(x, y); + x = out_x_1; + y = out_y_1; + if (typeof state_1 === "object") return state_1.value; + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.symbols new file mode 100644 index 00000000000..90c63914b9f --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts === +function f1() { +>f1 : Symbol(f1, Decl(blockScopedBindingsReassignedInLoop4.ts, 0, 0)) + + for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 12)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 19)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 12)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 19)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 12)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 19)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop4.ts, 2, 11)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 12)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 19)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 12)) + + return 1; + } + else { + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 19)) + } + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types new file mode 100644 index 00000000000..006f536ccca --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts === +function f1() { +>f1 : () => number + + for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + return 1; +>1 : number + } + else { + y = 5; +>y = 5 : number +>y : number +>5 : number + } + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js new file mode 100644 index 00000000000..198303390c9 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js @@ -0,0 +1,29 @@ +//// [blockScopedBindingsReassignedInLoop5.ts] +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else + y = 5; +} + + +//// [blockScopedBindingsReassignedInLoop5.js] +var _loop_1 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) + return out_x_1 = x, out_y_1 = y, "break"; + else + y = 5; + out_x_1 = x; + out_y_1 = y; +}; +var out_x_1, out_y_1; +for (var x = 1, y = 2; x < y; ++x, --y) { + out_x_1 = x; + out_y_1 = y; + var state_1 = _loop_1(x, y); + x = out_x_1; + y = out_y_1; + if (state_1 === "break") break; +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.symbols new file mode 100644 index 00000000000..0edc6abe34d --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.symbols @@ -0,0 +1,23 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts === +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop5.ts, 1, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 15)) + + if (x == 1) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 8)) + + break; + else + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 15)) +} + diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types new file mode 100644 index 00000000000..530978dc722 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts === +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) +>x == 1 : boolean +>x : number +>1 : number + + break; + else + y = 5; +>y = 5 : number +>y : number +>5 : number +} + diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js new file mode 100644 index 00000000000..f958b29c583 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js @@ -0,0 +1,78 @@ +//// [blockScopedBindingsReassignedInLoop6.ts] +function f1() { + for (let [x, y] = [1, 2]; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else if (y == 2) + y = 5; + else + return; + } +} + +function f2() { + for (let [{a: x, b: {c: y}}] = [{a: 1, b: {c: 2}}]; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else if (y == 2) + y = 5; + else + return; + } +} + + + + + + + +//// [blockScopedBindingsReassignedInLoop6.js] +function f1() { + var _loop_1 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) + return out_x_1 = x, out_y_1 = y, "break"; + else if (y == 2) + y = 5; + else + return { value: void 0 }; + out_x_1 = x; + out_y_1 = y; + }; + var out_x_1, out_y_1; + for (var _a = [1, 2], x = _a[0], y = _a[1]; x < y; ++x, --y) { + out_x_1 = x; + out_y_1 = y; + var state_1 = _loop_1(x, y); + x = out_x_1; + y = out_y_1; + if (typeof state_1 === "object") return state_1.value; + if (state_1 === "break") break; + } +} +function f2() { + var _loop_2 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) + return out_x_2 = x, out_y_2 = y, "break"; + else if (y == 2) + y = 5; + else + return { value: void 0 }; + out_x_2 = x; + out_y_2 = y; + }; + var out_x_2, out_y_2; + for (var _a = [{ a: 1, b: { c: 2 } }][0], x = _a.a, y = _a.b.c; x < y; ++x, --y) { + out_x_2 = x; + out_y_2 = y; + var state_2 = _loop_2(x, y); + x = out_x_2; + y = out_y_2; + if (typeof state_2 === "object") return state_2.value; + if (state_2 === "break") break; + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.symbols new file mode 100644 index 00000000000..8dda6eedd47 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.symbols @@ -0,0 +1,74 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts === +function f1() { +>f1 : Symbol(f1, Decl(blockScopedBindingsReassignedInLoop6.ts, 0, 0)) + + for (let [x, y] = [1, 2]; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 14)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 14)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 14)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop6.ts, 2, 11)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 14)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) + + if (x == 1) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 14)) + + break; + else if (y == 2) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) + + else + return; + } +} + +function f2() { +>f2 : Symbol(f2, Decl(blockScopedBindingsReassignedInLoop6.ts, 10, 1)) + + for (let [{a: x, b: {c: y}}] = [{a: 1, b: {c: 2}}]; x < y; ++x, --y) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 37)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 15)) +>b : Symbol(b, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 42)) +>c : Symbol(c, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 47)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 37)) +>b : Symbol(b, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 42)) +>c : Symbol(c, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 47)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 15)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 15)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop6.ts, 14, 11)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 15)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) + + if (x == 1) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 15)) + + break; + else if (y == 2) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) + + else + return; + } +} + + + + + + diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types new file mode 100644 index 00000000000..673c0788a03 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types @@ -0,0 +1,110 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts === +function f1() { +>f1 : () => void + + for (let [x, y] = [1, 2]; x < y; ++x, --y) { +>x : number +>y : number +>[1, 2] : [number, number] +>1 : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) +>x == 1 : boolean +>x : number +>1 : number + + break; + else if (y == 2) +>y == 2 : boolean +>y : number +>2 : number + + y = 5; +>y = 5 : number +>y : number +>5 : number + + else + return; + } +} + +function f2() { +>f2 : () => void + + for (let [{a: x, b: {c: y}}] = [{a: 1, b: {c: 2}}]; x < y; ++x, --y) { +>a : any +>x : number +>b : any +>c : any +>y : number +>[{a: 1, b: {c: 2}}] : [{ a: number; b: { c: number; }; }] +>{a: 1, b: {c: 2}} : { a: number; b: { c: number; }; } +>a : number +>1 : number +>b : { c: number; } +>{c: 2} : { c: number; } +>c : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) +>x == 1 : boolean +>x : number +>1 : number + + break; + else if (y == 2) +>y == 2 : boolean +>y : number +>2 : number + + y = 5; +>y = 5 : number +>y : number +>5 : number + + else + return; + } +} + + + + + + diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.js b/tests/baselines/reference/nestedBlockScopedBindings3.js index 97fba2da301..4570e85d510 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings3.js +++ b/tests/baselines/reference/nestedBlockScopedBindings3.js @@ -123,9 +123,13 @@ function a4() { var _loop_5 = function(x) { x = x + 1; (function () { return x; }); + out_x_1 = x; }; + var out_x_1; for (var x = void 0; x < 1;) { + out_x_1 = x; _loop_5(x); + x = out_x_1; } switch (1) { case 1: @@ -137,9 +141,13 @@ function a5() { var _loop_6 = function(x) { x = x + 1; (function () { return x; }); + out_x_2 = x; }; + var out_x_2; for (var x = void 0; x < 1;) { + out_x_2 = x; _loop_6(x); + x = out_x_2; } switch (1) { case 1: diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.js b/tests/baselines/reference/nestedBlockScopedBindings4.js index 51cddcf676d..832feb588bc 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings4.js +++ b/tests/baselines/reference/nestedBlockScopedBindings4.js @@ -53,9 +53,13 @@ function a1() { var _loop_1 = function(x) { x = x + 1; (function () { return x; }); + out_x_1 = x; }; + var out_x_1; for (var x = void 0; x < 1;) { + out_x_1 = x; _loop_1(x); + x = out_x_1; } for (var x = void 0;;) { x = x + 2; @@ -68,24 +72,36 @@ function a2() { var _loop_2 = function(x) { x = x + 2; (function () { return x; }); + out_x_2 = x; }; + var out_x_2; for (var x = void 0;;) { + out_x_2 = x; _loop_2(x); + x = out_x_2; } } function a3() { var _loop_3 = function(x) { x = x + 1; (function () { return x; }); + out_x_3 = x; }; + var out_x_3; for (var x = void 0; x < 1;) { + out_x_3 = x; _loop_3(x); + x = out_x_3; } var _loop_4 = function(x) { x = x + 2; (function () { return x; }); + out_x_4 = x; }; + var out_x_4; for (var x = void 0;;) { + out_x_4 = x; _loop_4(x); + x = out_x_4; } } diff --git a/tests/baselines/reference/nestedBlockScopedBindings5.js b/tests/baselines/reference/nestedBlockScopedBindings5.js index c80c72c0ed6..af91e9999a6 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings5.js +++ b/tests/baselines/reference/nestedBlockScopedBindings5.js @@ -108,9 +108,13 @@ function a2() { var _loop_2 = function(x) { x = x + 2; (function () { return x; }); + out_x_1 = x; }; + var out_x_1; for (var x = void 0;;) { + out_x_1 = x; _loop_2(x); + x = out_x_1; } } function a3() { @@ -124,9 +128,13 @@ function a3() { var _loop_4 = function(x) { x = x + 2; (function () { return x; }); + out_x_2 = x; }; + var out_x_2; for (var x = void 0; false;) { + out_x_2 = x; _loop_4(x); + x = out_x_2; } switch (1) { case 1: @@ -157,9 +165,13 @@ function a5() { var _loop_5 = function(x) { x = x + 2; (function () { return x; }); + out_x_3 = x; }; + var out_x_3; for (var x = void 0; false;) { + out_x_3 = x; _loop_5(x); + x = out_x_3; } switch (1) { case 1: diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.js b/tests/baselines/reference/nestedBlockScopedBindings6.js index 78207b98fcd..43f61a23bbf 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings6.js +++ b/tests/baselines/reference/nestedBlockScopedBindings6.js @@ -119,9 +119,13 @@ function a2() { var _loop_2 = function(x) { x = x + 2; (function () { return x; }); + out_x_1 = x; }; + var out_x_1; for (var x = void 0;;) { + out_x_1 = x; _loop_2(x); + x = out_x_1; } } function a3() { @@ -136,9 +140,13 @@ function a3() { var _loop_4 = function(x) { x = x + 2; (function () { return x; }); + out_x_2 = x; }; + var out_x_2; for (var x = void 0;;) { + out_x_2 = x; _loop_4(x); + x = out_x_2; } } function a4() { diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts new file mode 100644 index 00000000000..e052702bce2 --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts @@ -0,0 +1,7 @@ +declare function use(n: number): void; +(function () { + 'use strict' + for (let i = 0; i < 9; ++i) { + (() => use(++i))(); + } +})(); \ No newline at end of file diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts new file mode 100644 index 00000000000..84d9f8d214b --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts @@ -0,0 +1,41 @@ +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break; + } + else { + y = 5; + } +} + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue; + } + else { + y = 5; + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break loop; + } + else { + y = 5; + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue loop; + } + else { + y = 5; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts new file mode 100644 index 00000000000..a68c708193a --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts @@ -0,0 +1,91 @@ + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break; + } + else { + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + break; + } + else { + y++; + } + } + + y = 5; + } +} + + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue; + } + else { + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + continue; + } + else { + y++; + } + } + + y = 5; + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + break loop1; + } + else { + y++; + break loop2 + } + } + + y = 5; + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + continue loop1; + } + else { + y++; + continue loop2 + } + } + + y = 5; + } +} diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts new file mode 100644 index 00000000000..82f4bcc5dd0 --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts @@ -0,0 +1,11 @@ +function f1() { + for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + return 1; + } + else { + y = 5; + } + } +} \ No newline at end of file diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts new file mode 100644 index 00000000000..c6c577ea9fb --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts @@ -0,0 +1,7 @@ +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else + y = 5; +} diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts new file mode 100644 index 00000000000..e735bb61ac8 --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts @@ -0,0 +1,28 @@ +function f1() { + for (let [x, y] = [1, 2]; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else if (y == 2) + y = 5; + else + return; + } +} + +function f2() { + for (let [{a: x, b: {c: y}}] = [{a: 1, b: {c: 2}}]; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else if (y == 2) + y = 5; + else + return; + } +} + + + + + From e347c3711cc4b85eda34f1aba844e1a6576ff40c Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 4 Feb 2016 10:14:13 -0800 Subject: [PATCH 016/297] Add more complex test scenarios --- tests/cases/fourslash/jsDocGenerics1.ts | 28 +++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/cases/fourslash/jsDocGenerics1.ts b/tests/cases/fourslash/jsDocGenerics1.ts index 3b5742af8b1..61358e3f490 100644 --- a/tests/cases/fourslash/jsDocGenerics1.ts +++ b/tests/cases/fourslash/jsDocGenerics1.ts @@ -1,10 +1,34 @@ /// // @allowNonTsExtensions: true +// @Filename: ref.d.ts +//// namespace Thing { +//// export interface Thung { +//// a: number; +//// ] +//// ] + + // @Filename: Foo.js +//// //// /** @type {Array} */ //// var v; -//// v[0]./**/ +//// v[0]./*1*/ +//// +//// /** @type {{x: Array>}} */ +//// var w; +//// w.x[0][0]./*2*/ +//// +//// /** @type {Array} */ +//// var x; +//// x[0].a./*3*/ -goTo.marker(); + +goTo.marker('1'); +verify.memberListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method"); + +goTo.marker('2'); +verify.memberListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method"); + +goTo.marker('3'); verify.memberListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method"); From bbf92ce39187727bd8e547af7a4bfaa957ae2e2d Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Thu, 4 Feb 2016 18:32:56 +0000 Subject: [PATCH 017/297] Added constructor visibility in the declaration emitter --- src/compiler/declarationEmitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index ab0b16947fc..2963ddf6c58 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1316,7 +1316,7 @@ namespace ts { if (node.kind === SyntaxKind.FunctionDeclaration) { emitModuleElementDeclarationFlags(node); } - else if (node.kind === SyntaxKind.MethodDeclaration) { + else if (node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.Constructor) { emitClassMemberDeclarationFlags(node.flags); } if (node.kind === SyntaxKind.FunctionDeclaration) { From 3d529a84c533dc382b1203152d3e45d43a04619b Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Thu, 4 Feb 2016 18:33:53 +0000 Subject: [PATCH 018/297] Update baselines --- .../reference/classConstructorAccessibility.js | 4 ++-- .../reference/classConstructorAccessibility2.js | 4 ++-- .../reference/classConstructorAccessibility3.js | 4 ++-- .../classConstructorOverloadsAccessibility.js | 10 +++++----- .../baselines/reference/typesWithPrivateConstructor.js | 4 ++-- .../reference/typesWithProtectedConstructor.js | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/baselines/reference/classConstructorAccessibility.js b/tests/baselines/reference/classConstructorAccessibility.js index de7e4a83bb8..efc3f3c273c 100644 --- a/tests/baselines/reference/classConstructorAccessibility.js +++ b/tests/baselines/reference/classConstructorAccessibility.js @@ -90,11 +90,11 @@ declare class C { } declare class D { x: number; - constructor(x); + private constructor(x); } declare class E { x: number; - constructor(x: number); + protected constructor(x: number); } declare var c: C; declare var d: any; diff --git a/tests/baselines/reference/classConstructorAccessibility2.js b/tests/baselines/reference/classConstructorAccessibility2.js index 47c0b0bc626..e19589ece45 100644 --- a/tests/baselines/reference/classConstructorAccessibility2.js +++ b/tests/baselines/reference/classConstructorAccessibility2.js @@ -114,12 +114,12 @@ declare class BaseA { } declare class BaseB { x: number; - constructor(x: number); + protected constructor(x: number); createInstance(): void; } declare class BaseC { x: number; - constructor(x); + private constructor(x); createInstance(): void; } declare class DerivedA extends BaseA { diff --git a/tests/baselines/reference/classConstructorAccessibility3.js b/tests/baselines/reference/classConstructorAccessibility3.js index 8e900b6eb2d..02f5bb45a86 100644 --- a/tests/baselines/reference/classConstructorAccessibility3.js +++ b/tests/baselines/reference/classConstructorAccessibility3.js @@ -87,11 +87,11 @@ declare class Bar { } declare class Baz { x: number; - constructor(x: number); + protected constructor(x: number); } declare class Qux { x: number; - constructor(x); + private constructor(x); } declare let a: typeof Foo; declare let b: typeof Baz; diff --git a/tests/baselines/reference/classConstructorOverloadsAccessibility.js b/tests/baselines/reference/classConstructorOverloadsAccessibility.js index b69257a1c2a..3914c29b785 100644 --- a/tests/baselines/reference/classConstructorOverloadsAccessibility.js +++ b/tests/baselines/reference/classConstructorOverloadsAccessibility.js @@ -59,16 +59,16 @@ var D = (function () { //// [classConstructorOverloadsAccessibility.d.ts] declare class A { constructor(a: boolean); - constructor(a: number); - constructor(a); + protected constructor(a: number); + private constructor(a); } declare class B { - constructor(a: number); + protected constructor(a: number); constructor(a: string); } declare class C { - constructor(a: number); - constructor(a: string); + protected constructor(a: number); + protected constructor(a: string); } declare class D { constructor(a: number); diff --git a/tests/baselines/reference/typesWithPrivateConstructor.js b/tests/baselines/reference/typesWithPrivateConstructor.js index b3111ec2a74..1795ee6b316 100644 --- a/tests/baselines/reference/typesWithPrivateConstructor.js +++ b/tests/baselines/reference/typesWithPrivateConstructor.js @@ -34,12 +34,12 @@ var r2 = c2.constructor; //// [typesWithPrivateConstructor.d.ts] declare class C { - constructor(); + private constructor(); } declare var c: any; declare var r: () => void; declare class C2 { - constructor(x); + private constructor(x); } declare var c2: any; declare var r2: (x: number) => void; diff --git a/tests/baselines/reference/typesWithProtectedConstructor.js b/tests/baselines/reference/typesWithProtectedConstructor.js index 02f29464533..e75b3b6ecd3 100644 --- a/tests/baselines/reference/typesWithProtectedConstructor.js +++ b/tests/baselines/reference/typesWithProtectedConstructor.js @@ -34,12 +34,12 @@ var r2 = c2.constructor; //// [typesWithProtectedConstructor.d.ts] declare class C { - constructor(); + protected constructor(); } declare var c: any; declare var r: () => void; declare class C2 { - constructor(x: number); + protected constructor(x: number); } declare var c2: any; declare var r2: (x: number) => void; From 1611f5648146ff5f90bf0e11556e1fa5fdbe9398 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 4 Feb 2016 12:44:03 -0800 Subject: [PATCH 019/297] Rename flag --- src/compiler/commandLineParser.ts | 2 +- src/compiler/emitter.ts | 8 ++++---- src/compiler/types.ts | 2 +- .../reference/emitModulesInLooseMode_amd.symbols | 5 ----- .../baselines/reference/emitModulesInLooseMode_amd.types | 6 ------ .../reference/emitModulesInLooseMode_commonjs.js | 6 ------ .../reference/emitModulesInLooseMode_commonjs.symbols | 5 ----- .../reference/emitModulesInLooseMode_commonjs.types | 6 ------ tests/baselines/reference/emitModulesInLooseMode_es6.js | 6 ------ .../reference/emitModulesInLooseMode_es6.symbols | 5 ----- .../baselines/reference/emitModulesInLooseMode_es6.types | 6 ------ .../reference/emitModulesInLooseMode_system.symbols | 5 ----- .../reference/emitModulesInLooseMode_system.types | 6 ------ .../reference/emitModulesInLooseMode_umd.symbols | 5 ----- .../baselines/reference/emitModulesInLooseMode_umd.types | 6 ------ ...ulesInLooseMode_amd.js => emitNonStrictModules_amd.js} | 4 ++-- .../baselines/reference/emitNonStrictModules_amd.symbols | 5 +++++ tests/baselines/reference/emitNonStrictModules_amd.types | 6 ++++++ .../baselines/reference/emitNonStrictModules_commonjs.js | 6 ++++++ .../reference/emitNonStrictModules_commonjs.symbols | 5 +++++ .../reference/emitNonStrictModules_commonjs.types | 6 ++++++ tests/baselines/reference/emitNonStrictModules_es6.js | 6 ++++++ .../baselines/reference/emitNonStrictModules_es6.symbols | 5 +++++ tests/baselines/reference/emitNonStrictModules_es6.types | 6 ++++++ ...LooseMode_system.js => emitNonStrictModules_system.js} | 4 ++-- .../reference/emitNonStrictModules_system.symbols | 5 +++++ .../baselines/reference/emitNonStrictModules_system.types | 6 ++++++ ...ulesInLooseMode_umd.js => emitNonStrictModules_umd.js} | 4 ++-- .../baselines/reference/emitNonStrictModules_umd.symbols | 5 +++++ tests/baselines/reference/emitNonStrictModules_umd.types | 6 ++++++ tests/cases/compiler/emitModulesInLooseMode_amd.ts | 4 ---- tests/cases/compiler/emitModulesInLooseMode_umd.ts | 4 ---- tests/cases/compiler/emitNonStrictModules_amd.ts | 4 ++++ ...eMode_commonjs.ts => emitNonStrictModules_commonjs.ts} | 2 +- ...ulesInLooseMode_es6.ts => emitNonStrictModules_es6.ts} | 2 +- ...LooseMode_system.ts => emitNonStrictModules_system.ts} | 2 +- tests/cases/compiler/emitNonStrictModules_umd.ts | 4 ++++ 37 files changed, 90 insertions(+), 90 deletions(-) delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_amd.symbols delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_amd.types delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_commonjs.js delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_commonjs.symbols delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_commonjs.types delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_es6.js delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_es6.symbols delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_es6.types delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_system.symbols delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_system.types delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_umd.symbols delete mode 100644 tests/baselines/reference/emitModulesInLooseMode_umd.types rename tests/baselines/reference/{emitModulesInLooseMode_amd.js => emitNonStrictModules_amd.js} (56%) create mode 100644 tests/baselines/reference/emitNonStrictModules_amd.symbols create mode 100644 tests/baselines/reference/emitNonStrictModules_amd.types create mode 100644 tests/baselines/reference/emitNonStrictModules_commonjs.js create mode 100644 tests/baselines/reference/emitNonStrictModules_commonjs.symbols create mode 100644 tests/baselines/reference/emitNonStrictModules_commonjs.types create mode 100644 tests/baselines/reference/emitNonStrictModules_es6.js create mode 100644 tests/baselines/reference/emitNonStrictModules_es6.symbols create mode 100644 tests/baselines/reference/emitNonStrictModules_es6.types rename tests/baselines/reference/{emitModulesInLooseMode_system.js => emitNonStrictModules_system.js} (72%) create mode 100644 tests/baselines/reference/emitNonStrictModules_system.symbols create mode 100644 tests/baselines/reference/emitNonStrictModules_system.types rename tests/baselines/reference/{emitModulesInLooseMode_umd.js => emitNonStrictModules_umd.js} (81%) create mode 100644 tests/baselines/reference/emitNonStrictModules_umd.symbols create mode 100644 tests/baselines/reference/emitNonStrictModules_umd.types delete mode 100644 tests/cases/compiler/emitModulesInLooseMode_amd.ts delete mode 100644 tests/cases/compiler/emitModulesInLooseMode_umd.ts create mode 100644 tests/cases/compiler/emitNonStrictModules_amd.ts rename tests/cases/compiler/{emitModulesInLooseMode_commonjs.ts => emitNonStrictModules_commonjs.ts} (52%) rename tests/cases/compiler/{emitModulesInLooseMode_es6.ts => emitNonStrictModules_es6.ts} (57%) rename tests/cases/compiler/{emitModulesInLooseMode_system.ts => emitNonStrictModules_system.ts} (50%) create mode 100644 tests/cases/compiler/emitNonStrictModules_umd.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 7d635c2aaf5..957b38c67de 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -322,7 +322,7 @@ namespace ts { description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking }, { - name: "emitModulesInLooseMode", + name: "emitNonStrictModules", type: "boolean", description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 92cb3334f63..15edb022b11 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -7179,7 +7179,7 @@ const _super = (function (geti, seti) { write(`], function(${exportFunctionForFile}, ${contextObjectForFile}) {`); writeLine(); increaseIndent(); - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.emitModulesInLooseMode); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.emitNonStrictModules); writeLine(); write(`var __moduleName = ${contextObjectForFile} && ${contextObjectForFile}.id;`); writeLine(); @@ -7285,7 +7285,7 @@ const _super = (function (geti, seti) { writeModuleName(node, emitRelativePathAsModuleName); emitAMDDependencies(node, /*includeNonAmdDependencies*/ true, emitRelativePathAsModuleName); increaseIndent(); - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/!compilerOptions.emitModulesInLooseMode); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/!compilerOptions.emitNonStrictModules); emitExportStarHelper(); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); @@ -7297,7 +7297,7 @@ const _super = (function (geti, seti) { } function emitCommonJSModule(node: SourceFile) { - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ !compilerOptions.emitModulesInLooseMode); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ !compilerOptions.emitNonStrictModules); emitEmitHelpers(node); collectExternalModuleInfo(node); emitExportStarHelper(); @@ -7326,7 +7326,7 @@ const _super = (function (geti, seti) { })(`); emitAMDFactoryHeader(dependencyNames); increaseIndent(); - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.emitModulesInLooseMode); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.emitNonStrictModules); emitExportStarHelper(); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 97cf2fff3b5..90a6a9a6752 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2422,7 +2422,7 @@ namespace ts { traceModuleResolution?: boolean; allowSyntheticDefaultImports?: boolean; allowJs?: boolean; - emitModulesInLooseMode?: boolean; + emitNonStrictModules?: boolean; /* @internal */ stripInternal?: boolean; // Skip checking lib.d.ts to help speed up tests. diff --git a/tests/baselines/reference/emitModulesInLooseMode_amd.symbols b/tests/baselines/reference/emitModulesInLooseMode_amd.symbols deleted file mode 100644 index d76fea8b7b8..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_amd.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/emitModulesInLooseMode_amd.ts === - -export var x = 0; ->x : Symbol(x, Decl(emitModulesInLooseMode_amd.ts, 1, 10)) - diff --git a/tests/baselines/reference/emitModulesInLooseMode_amd.types b/tests/baselines/reference/emitModulesInLooseMode_amd.types deleted file mode 100644 index 1c070cc95fa..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_amd.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/emitModulesInLooseMode_amd.ts === - -export var x = 0; ->x : number ->0 : number - diff --git a/tests/baselines/reference/emitModulesInLooseMode_commonjs.js b/tests/baselines/reference/emitModulesInLooseMode_commonjs.js deleted file mode 100644 index be24cdf6b91..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_commonjs.js +++ /dev/null @@ -1,6 +0,0 @@ -//// [emitModulesInLooseMode_commonjs.ts] - -export var x = 0; - -//// [emitModulesInLooseMode_commonjs.js] -exports.x = 0; diff --git a/tests/baselines/reference/emitModulesInLooseMode_commonjs.symbols b/tests/baselines/reference/emitModulesInLooseMode_commonjs.symbols deleted file mode 100644 index 225286c74de..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_commonjs.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/emitModulesInLooseMode_commonjs.ts === - -export var x = 0; ->x : Symbol(x, Decl(emitModulesInLooseMode_commonjs.ts, 1, 10)) - diff --git a/tests/baselines/reference/emitModulesInLooseMode_commonjs.types b/tests/baselines/reference/emitModulesInLooseMode_commonjs.types deleted file mode 100644 index b37bb9667ab..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_commonjs.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/emitModulesInLooseMode_commonjs.ts === - -export var x = 0; ->x : number ->0 : number - diff --git a/tests/baselines/reference/emitModulesInLooseMode_es6.js b/tests/baselines/reference/emitModulesInLooseMode_es6.js deleted file mode 100644 index 95cc14ff609..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_es6.js +++ /dev/null @@ -1,6 +0,0 @@ -//// [emitModulesInLooseMode_es6.ts] - -export var x = 0; - -//// [emitModulesInLooseMode_es6.js] -export var x = 0; diff --git a/tests/baselines/reference/emitModulesInLooseMode_es6.symbols b/tests/baselines/reference/emitModulesInLooseMode_es6.symbols deleted file mode 100644 index 4f3c073f7ee..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_es6.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/emitModulesInLooseMode_es6.ts === - -export var x = 0; ->x : Symbol(x, Decl(emitModulesInLooseMode_es6.ts, 1, 10)) - diff --git a/tests/baselines/reference/emitModulesInLooseMode_es6.types b/tests/baselines/reference/emitModulesInLooseMode_es6.types deleted file mode 100644 index 84631ede00f..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_es6.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/emitModulesInLooseMode_es6.ts === - -export var x = 0; ->x : number ->0 : number - diff --git a/tests/baselines/reference/emitModulesInLooseMode_system.symbols b/tests/baselines/reference/emitModulesInLooseMode_system.symbols deleted file mode 100644 index 0682b2b648f..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_system.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/emitModulesInLooseMode_system.ts === - -export var x = 0; ->x : Symbol(x, Decl(emitModulesInLooseMode_system.ts, 1, 10)) - diff --git a/tests/baselines/reference/emitModulesInLooseMode_system.types b/tests/baselines/reference/emitModulesInLooseMode_system.types deleted file mode 100644 index 429908c1de4..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_system.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/emitModulesInLooseMode_system.ts === - -export var x = 0; ->x : number ->0 : number - diff --git a/tests/baselines/reference/emitModulesInLooseMode_umd.symbols b/tests/baselines/reference/emitModulesInLooseMode_umd.symbols deleted file mode 100644 index 86c9e9b200c..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_umd.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/emitModulesInLooseMode_umd.ts === - -export var x = 0; ->x : Symbol(x, Decl(emitModulesInLooseMode_umd.ts, 1, 10)) - diff --git a/tests/baselines/reference/emitModulesInLooseMode_umd.types b/tests/baselines/reference/emitModulesInLooseMode_umd.types deleted file mode 100644 index 98a32838eb6..00000000000 --- a/tests/baselines/reference/emitModulesInLooseMode_umd.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/emitModulesInLooseMode_umd.ts === - -export var x = 0; ->x : number ->0 : number - diff --git a/tests/baselines/reference/emitModulesInLooseMode_amd.js b/tests/baselines/reference/emitNonStrictModules_amd.js similarity index 56% rename from tests/baselines/reference/emitModulesInLooseMode_amd.js rename to tests/baselines/reference/emitNonStrictModules_amd.js index a93ca62de0e..f2a746280ac 100644 --- a/tests/baselines/reference/emitModulesInLooseMode_amd.js +++ b/tests/baselines/reference/emitNonStrictModules_amd.js @@ -1,8 +1,8 @@ -//// [emitModulesInLooseMode_amd.ts] +//// [emitNonStrictModules_amd.ts] export var x = 0; -//// [emitModulesInLooseMode_amd.js] +//// [emitNonStrictModules_amd.js] define(["require", "exports"], function (require, exports) { exports.x = 0; }); diff --git a/tests/baselines/reference/emitNonStrictModules_amd.symbols b/tests/baselines/reference/emitNonStrictModules_amd.symbols new file mode 100644 index 00000000000..1590ea05ad4 --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_amd.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/emitNonStrictModules_amd.ts === + +export var x = 0; +>x : Symbol(x, Decl(emitNonStrictModules_amd.ts, 1, 10)) + diff --git a/tests/baselines/reference/emitNonStrictModules_amd.types b/tests/baselines/reference/emitNonStrictModules_amd.types new file mode 100644 index 00000000000..650df648d8d --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_amd.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/emitNonStrictModules_amd.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/emitNonStrictModules_commonjs.js b/tests/baselines/reference/emitNonStrictModules_commonjs.js new file mode 100644 index 00000000000..7a2d0720015 --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_commonjs.js @@ -0,0 +1,6 @@ +//// [emitNonStrictModules_commonjs.ts] + +export var x = 0; + +//// [emitNonStrictModules_commonjs.js] +exports.x = 0; diff --git a/tests/baselines/reference/emitNonStrictModules_commonjs.symbols b/tests/baselines/reference/emitNonStrictModules_commonjs.symbols new file mode 100644 index 00000000000..36b487f34d1 --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_commonjs.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/emitNonStrictModules_commonjs.ts === + +export var x = 0; +>x : Symbol(x, Decl(emitNonStrictModules_commonjs.ts, 1, 10)) + diff --git a/tests/baselines/reference/emitNonStrictModules_commonjs.types b/tests/baselines/reference/emitNonStrictModules_commonjs.types new file mode 100644 index 00000000000..f8a24d53641 --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_commonjs.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/emitNonStrictModules_commonjs.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/emitNonStrictModules_es6.js b/tests/baselines/reference/emitNonStrictModules_es6.js new file mode 100644 index 00000000000..535afff7730 --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_es6.js @@ -0,0 +1,6 @@ +//// [emitNonStrictModules_es6.ts] + +export var x = 0; + +//// [emitNonStrictModules_es6.js] +export var x = 0; diff --git a/tests/baselines/reference/emitNonStrictModules_es6.symbols b/tests/baselines/reference/emitNonStrictModules_es6.symbols new file mode 100644 index 00000000000..884189014b0 --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_es6.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/emitNonStrictModules_es6.ts === + +export var x = 0; +>x : Symbol(x, Decl(emitNonStrictModules_es6.ts, 1, 10)) + diff --git a/tests/baselines/reference/emitNonStrictModules_es6.types b/tests/baselines/reference/emitNonStrictModules_es6.types new file mode 100644 index 00000000000..f3208e247da --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_es6.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/emitNonStrictModules_es6.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/emitModulesInLooseMode_system.js b/tests/baselines/reference/emitNonStrictModules_system.js similarity index 72% rename from tests/baselines/reference/emitModulesInLooseMode_system.js rename to tests/baselines/reference/emitNonStrictModules_system.js index 4cf401a554d..f1ad93f0009 100644 --- a/tests/baselines/reference/emitModulesInLooseMode_system.js +++ b/tests/baselines/reference/emitNonStrictModules_system.js @@ -1,8 +1,8 @@ -//// [emitModulesInLooseMode_system.ts] +//// [emitNonStrictModules_system.ts] export var x = 0; -//// [emitModulesInLooseMode_system.js] +//// [emitNonStrictModules_system.js] System.register([], function(exports_1, context_1) { var __moduleName = context_1 && context_1.id; var x; diff --git a/tests/baselines/reference/emitNonStrictModules_system.symbols b/tests/baselines/reference/emitNonStrictModules_system.symbols new file mode 100644 index 00000000000..b772eafe447 --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_system.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/emitNonStrictModules_system.ts === + +export var x = 0; +>x : Symbol(x, Decl(emitNonStrictModules_system.ts, 1, 10)) + diff --git a/tests/baselines/reference/emitNonStrictModules_system.types b/tests/baselines/reference/emitNonStrictModules_system.types new file mode 100644 index 00000000000..352381db379 --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_system.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/emitNonStrictModules_system.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/emitModulesInLooseMode_umd.js b/tests/baselines/reference/emitNonStrictModules_umd.js similarity index 81% rename from tests/baselines/reference/emitModulesInLooseMode_umd.js rename to tests/baselines/reference/emitNonStrictModules_umd.js index 327962d18f2..c1ee0c048c5 100644 --- a/tests/baselines/reference/emitModulesInLooseMode_umd.js +++ b/tests/baselines/reference/emitNonStrictModules_umd.js @@ -1,8 +1,8 @@ -//// [emitModulesInLooseMode_umd.ts] +//// [emitNonStrictModules_umd.ts] export var x = 0; -//// [emitModulesInLooseMode_umd.js] +//// [emitNonStrictModules_umd.js] (function (factory) { if (typeof module === 'object' && typeof module.exports === 'object') { var v = factory(require, exports); if (v !== undefined) module.exports = v; diff --git a/tests/baselines/reference/emitNonStrictModules_umd.symbols b/tests/baselines/reference/emitNonStrictModules_umd.symbols new file mode 100644 index 00000000000..23af4139243 --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_umd.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/emitNonStrictModules_umd.ts === + +export var x = 0; +>x : Symbol(x, Decl(emitNonStrictModules_umd.ts, 1, 10)) + diff --git a/tests/baselines/reference/emitNonStrictModules_umd.types b/tests/baselines/reference/emitNonStrictModules_umd.types new file mode 100644 index 00000000000..83c55b1d4cd --- /dev/null +++ b/tests/baselines/reference/emitNonStrictModules_umd.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/emitNonStrictModules_umd.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/cases/compiler/emitModulesInLooseMode_amd.ts b/tests/cases/compiler/emitModulesInLooseMode_amd.ts deleted file mode 100644 index 7c3394bebae..00000000000 --- a/tests/cases/compiler/emitModulesInLooseMode_amd.ts +++ /dev/null @@ -1,4 +0,0 @@ -// @module: amd -// @emitModulesInLooseMode: true - -export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitModulesInLooseMode_umd.ts b/tests/cases/compiler/emitModulesInLooseMode_umd.ts deleted file mode 100644 index a6a3559986f..00000000000 --- a/tests/cases/compiler/emitModulesInLooseMode_umd.ts +++ /dev/null @@ -1,4 +0,0 @@ -// @module: umd -// @emitModulesInLooseMode: true - -export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitNonStrictModules_amd.ts b/tests/cases/compiler/emitNonStrictModules_amd.ts new file mode 100644 index 00000000000..217e23d91a3 --- /dev/null +++ b/tests/cases/compiler/emitNonStrictModules_amd.ts @@ -0,0 +1,4 @@ +// @module: amd +// @emitNonStrictModules: true + +export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitModulesInLooseMode_commonjs.ts b/tests/cases/compiler/emitNonStrictModules_commonjs.ts similarity index 52% rename from tests/cases/compiler/emitModulesInLooseMode_commonjs.ts rename to tests/cases/compiler/emitNonStrictModules_commonjs.ts index 761f1f6ea9f..3d29c30176f 100644 --- a/tests/cases/compiler/emitModulesInLooseMode_commonjs.ts +++ b/tests/cases/compiler/emitNonStrictModules_commonjs.ts @@ -1,4 +1,4 @@ // @module: commonjs -// @emitModulesInLooseMode: true +// @emitNonStrictModules: true export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitModulesInLooseMode_es6.ts b/tests/cases/compiler/emitNonStrictModules_es6.ts similarity index 57% rename from tests/cases/compiler/emitModulesInLooseMode_es6.ts rename to tests/cases/compiler/emitNonStrictModules_es6.ts index 22c4368629f..426c5aff533 100644 --- a/tests/cases/compiler/emitModulesInLooseMode_es6.ts +++ b/tests/cases/compiler/emitNonStrictModules_es6.ts @@ -1,5 +1,5 @@ // @module: es6 // @target: es6 -// @emitModulesInLooseMode: true +// @emitNonStrictModules: true export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitModulesInLooseMode_system.ts b/tests/cases/compiler/emitNonStrictModules_system.ts similarity index 50% rename from tests/cases/compiler/emitModulesInLooseMode_system.ts rename to tests/cases/compiler/emitNonStrictModules_system.ts index 0face8fabca..23801462b71 100644 --- a/tests/cases/compiler/emitModulesInLooseMode_system.ts +++ b/tests/cases/compiler/emitNonStrictModules_system.ts @@ -1,4 +1,4 @@ // @module: system -// @emitModulesInLooseMode: true +// @emitNonStrictModules: true export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitNonStrictModules_umd.ts b/tests/cases/compiler/emitNonStrictModules_umd.ts new file mode 100644 index 00000000000..1166f512cf2 --- /dev/null +++ b/tests/cases/compiler/emitNonStrictModules_umd.ts @@ -0,0 +1,4 @@ +// @module: umd +// @emitNonStrictModules: true + +export var x = 0; \ No newline at end of file From d436d15304b7b1d45971e3071fe475371453c2ce Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 4 Feb 2016 12:44:31 -0800 Subject: [PATCH 020/297] addressed PR feedback --- src/compiler/emitter.ts | 3 --- .../blockScopedBindingsReassignedInLoop1.js | 1 - .../blockScopedBindingsReassignedInLoop2.js | 8 -------- .../blockScopedBindingsReassignedInLoop3.js | 12 ------------ .../blockScopedBindingsReassignedInLoop4.js | 2 -- .../blockScopedBindingsReassignedInLoop5.js | 2 -- .../blockScopedBindingsReassignedInLoop6.js | 4 ---- .../reference/nestedBlockScopedBindings3.js | 2 -- .../reference/nestedBlockScopedBindings4.js | 4 ---- .../reference/nestedBlockScopedBindings5.js | 3 --- .../reference/nestedBlockScopedBindings6.js | 2 -- 11 files changed, 43 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index be6a4dc36fc..aba0c883aaa 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3237,9 +3237,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge !loop.state.labeledNonLocalBreaks && !loop.state.labeledNonLocalContinues; - copyLoopOutParameters(loop.state, CopyDirection.ToOutParameter, /*emitAsStatements*/ true); - writeLine(); - const loopResult = makeUniqueName("state"); if (!isSimpleLoop) { write(`var ${loopResult} = `); diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js index 84e013c3b02..609d353fbc7 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js @@ -16,7 +16,6 @@ declare function use(n: number): void; }; var out_i_1; for (var i = 0; i < 9; ++i) { - out_i_1 = i; _loop_1(i); i = out_i_1; } diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js index 82719448e24..c48ecd96ffe 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js @@ -55,8 +55,6 @@ var _loop_1 = function(x, y) { }; var out_x_1, out_y_1; for (var x = 1, y = 2; x < y; ++x, --y) { - out_x_1 = x; - out_y_1 = y; var state_1 = _loop_1(x, y); x = out_x_1; y = out_y_1; @@ -75,8 +73,6 @@ var _loop_2 = function(x, y) { }; var out_x_2, out_y_2; for (var x = 1, y = 2; x < y; ++x, --y) { - out_x_2 = x; - out_y_2 = y; var state_2 = _loop_2(x, y); x = out_x_2; y = out_y_2; @@ -95,8 +91,6 @@ var _loop_3 = function(x, y) { }; var out_x_3, out_y_3; loop: for (var x = 1, y = 2; x < y; ++x, --y) { - out_x_3 = x; - out_y_3 = y; var state_3 = _loop_3(x, y); x = out_x_3; y = out_y_3; @@ -117,8 +111,6 @@ var _loop_4 = function(x, y) { }; var out_x_4, out_y_4; loop: for (var x = 1, y = 2; x < y; ++x, --y) { - out_x_4 = x; - out_y_4 = y; var state_4 = _loop_4(x, y); x = out_x_4; y = out_y_4; diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js index 8780afbdf54..10160202621 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js @@ -112,7 +112,6 @@ var _loop_1 = function(x, y) { }; var out_a_1_1; for (var a_1 = 1; a_1 < 5; --a_1) { - out_a_1_1 = a_1; var state_1 = _loop_2(a_1); a_1 = out_a_1_1; if (state_1 === "break") break; @@ -124,8 +123,6 @@ var _loop_1 = function(x, y) { }; var out_x_1, out_y_1; for (var x = 1, y = 2; x < y; ++x, --y) { - out_x_1 = x; - out_y_1 = y; var state_2 = _loop_1(x, y); x = out_x_1; y = out_y_1; @@ -150,7 +147,6 @@ var _loop_3 = function(x, y) { }; var out_a_2_1; for (var a_2 = 1; a_2 < 5; --a_2) { - out_a_2_1 = a_2; var state_3 = _loop_4(a_2); a_2 = out_a_2_1; if (state_3 === "continue") continue; @@ -162,8 +158,6 @@ var _loop_3 = function(x, y) { }; var out_x_2, out_y_2; for (var x = 1, y = 2; x < y; ++x, --y) { - out_x_2 = x; - out_y_2 = y; var state_4 = _loop_3(x, y); x = out_x_2; y = out_y_2; @@ -189,7 +183,6 @@ var _loop_5 = function(x, y) { }; var out_a_3_1; loop1: for (var a_3 = 1; a_3 < 5; --a_3) { - out_a_3_1 = a_3; var state_5 = _loop_6(a_3); a_3 = out_a_3_1; switch(state_5) { @@ -204,8 +197,6 @@ var _loop_5 = function(x, y) { }; var out_x_3, out_y_3; loop2: for (var x = 1, y = 2; x < y; ++x, --y) { - out_x_3 = x; - out_y_3 = y; var state_6 = _loop_5(x, y); x = out_x_3; y = out_y_3; @@ -233,7 +224,6 @@ var _loop_7 = function(x, y) { }; var out_a_4_1; loop1: for (var a_4 = 1; a_4 < 5; --a_4) { - out_a_4_1 = a_4; var state_7 = _loop_8(a_4); a_4 = out_a_4_1; switch(state_7) { @@ -248,8 +238,6 @@ var _loop_7 = function(x, y) { }; var out_x_4, out_y_4; loop2: for (var x = 1, y = 2; x < y; ++x, --y) { - out_x_4 = x; - out_y_4 = y; var state_8 = _loop_7(x, y); x = out_x_4; y = out_y_4; diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js index e28c890932a..8bff867dc95 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js @@ -26,8 +26,6 @@ function f1() { }; var out_x_1, out_y_1; for (var x = 1, y = 2; x < y; ++x, --y) { - out_x_1 = x; - out_y_1 = y; var state_1 = _loop_1(x, y); x = out_x_1; y = out_y_1; diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js index 198303390c9..a891147317d 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js @@ -20,8 +20,6 @@ var _loop_1 = function(x, y) { }; var out_x_1, out_y_1; for (var x = 1, y = 2; x < y; ++x, --y) { - out_x_1 = x; - out_y_1 = y; var state_1 = _loop_1(x, y); x = out_x_1; y = out_y_1; diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js index f958b29c583..a2a074ed4df 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js @@ -44,8 +44,6 @@ function f1() { }; var out_x_1, out_y_1; for (var _a = [1, 2], x = _a[0], y = _a[1]; x < y; ++x, --y) { - out_x_1 = x; - out_y_1 = y; var state_1 = _loop_1(x, y); x = out_x_1; y = out_y_1; @@ -67,8 +65,6 @@ function f2() { }; var out_x_2, out_y_2; for (var _a = [{ a: 1, b: { c: 2 } }][0], x = _a.a, y = _a.b.c; x < y; ++x, --y) { - out_x_2 = x; - out_y_2 = y; var state_2 = _loop_2(x, y); x = out_x_2; y = out_y_2; diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.js b/tests/baselines/reference/nestedBlockScopedBindings3.js index 4570e85d510..f9474381816 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings3.js +++ b/tests/baselines/reference/nestedBlockScopedBindings3.js @@ -127,7 +127,6 @@ function a4() { }; var out_x_1; for (var x = void 0; x < 1;) { - out_x_1 = x; _loop_5(x); x = out_x_1; } @@ -145,7 +144,6 @@ function a5() { }; var out_x_2; for (var x = void 0; x < 1;) { - out_x_2 = x; _loop_6(x); x = out_x_2; } diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.js b/tests/baselines/reference/nestedBlockScopedBindings4.js index 832feb588bc..6b391070d93 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings4.js +++ b/tests/baselines/reference/nestedBlockScopedBindings4.js @@ -57,7 +57,6 @@ function a1() { }; var out_x_1; for (var x = void 0; x < 1;) { - out_x_1 = x; _loop_1(x); x = out_x_1; } @@ -76,7 +75,6 @@ function a2() { }; var out_x_2; for (var x = void 0;;) { - out_x_2 = x; _loop_2(x); x = out_x_2; } @@ -89,7 +87,6 @@ function a3() { }; var out_x_3; for (var x = void 0; x < 1;) { - out_x_3 = x; _loop_3(x); x = out_x_3; } @@ -100,7 +97,6 @@ function a3() { }; var out_x_4; for (var x = void 0;;) { - out_x_4 = x; _loop_4(x); x = out_x_4; } diff --git a/tests/baselines/reference/nestedBlockScopedBindings5.js b/tests/baselines/reference/nestedBlockScopedBindings5.js index af91e9999a6..df4fcf76423 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings5.js +++ b/tests/baselines/reference/nestedBlockScopedBindings5.js @@ -112,7 +112,6 @@ function a2() { }; var out_x_1; for (var x = void 0;;) { - out_x_1 = x; _loop_2(x); x = out_x_1; } @@ -132,7 +131,6 @@ function a3() { }; var out_x_2; for (var x = void 0; false;) { - out_x_2 = x; _loop_4(x); x = out_x_2; } @@ -169,7 +167,6 @@ function a5() { }; var out_x_3; for (var x = void 0; false;) { - out_x_3 = x; _loop_5(x); x = out_x_3; } diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.js b/tests/baselines/reference/nestedBlockScopedBindings6.js index 43f61a23bbf..be9771471e9 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings6.js +++ b/tests/baselines/reference/nestedBlockScopedBindings6.js @@ -123,7 +123,6 @@ function a2() { }; var out_x_1; for (var x = void 0;;) { - out_x_1 = x; _loop_2(x); x = out_x_1; } @@ -144,7 +143,6 @@ function a3() { }; var out_x_2; for (var x = void 0;;) { - out_x_2 = x; _loop_4(x); x = out_x_2; } From 42000519347ecefe60687b9976e654781a69bbec Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Thu, 4 Feb 2016 21:00:37 +0000 Subject: [PATCH 021/297] Addressed PR feedback. --- src/compiler/checker.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1ce5b51c66d..ebb02a2fdad 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1711,6 +1711,16 @@ namespace ts { return result; } + function visibilityToString(flags: NodeFlags) { + if (flags === NodeFlags.Private) { + return "private"; + } + if (flags === NodeFlags.Protected) { + return "protected"; + } + return "public"; + } + function getTypeAliasForTypeLiteral(type: Type): Symbol { if (type.symbol && type.symbol.flags & SymbolFlags.TypeLiteral) { let node = type.symbol.declarations[0].parent; @@ -6059,28 +6069,24 @@ namespace ts { function constructorRelatedTo(sourceSignature: Signature, targetSignature: Signature, reportErrors: boolean) { if (sourceSignature && targetSignature && sourceSignature.declaration && targetSignature.declaration) { + // A public, protected and private signature is assignable to a private signature. + // A public and protected signature is assignable to a protected signature. + // And only a public signature is assignable to public signature. const sourceAccessibility = sourceSignature.declaration.flags & (NodeFlags.Private | NodeFlags.Protected); const targetAccessibility = targetSignature.declaration.flags & (NodeFlags.Private | NodeFlags.Protected); - const isRelated = sourceAccessibility === targetAccessibility; + const isRelated = targetAccessibility === NodeFlags.Private + || (targetAccessibility === NodeFlags.Protected && sourceAccessibility !== NodeFlags.Private) + || (targetAccessibility !== NodeFlags.Protected && !(sourceAccessibility & (NodeFlags.Private | NodeFlags.Protected))); + if (!isRelated && reportErrors) { - reportError(Diagnostics.Cannot_assign_a_0_constructor_type_to_a_1_constructor_type, flagsToString(sourceAccessibility), flagsToString(targetAccessibility)); + reportError(Diagnostics.Cannot_assign_a_0_constructor_type_to_a_1_constructor_type, visibilityToString(sourceAccessibility), visibilityToString(targetAccessibility)); } return isRelated; } return true; - - function flagsToString(flags: NodeFlags) { - if (flags === NodeFlags.Private) { - return "private"; - } - if (flags === NodeFlags.Protected) { - return "protected"; - } - return "public"; - } } } From 4c93eb2e98703ae86c81721d28b03babdf24bc61 Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Thu, 4 Feb 2016 21:00:50 +0000 Subject: [PATCH 022/297] Accept baselines --- .../classConstructorAccessibility3.errors.txt | 37 +++---------------- .../classConstructorAccessibility3.js | 20 +++++----- .../classConstructorAccessibility3.ts | 10 ++--- 3 files changed, 21 insertions(+), 46 deletions(-) diff --git a/tests/baselines/reference/classConstructorAccessibility3.errors.txt b/tests/baselines/reference/classConstructorAccessibility3.errors.txt index c536db1f9da..1b96db289dc 100644 --- a/tests/baselines/reference/classConstructorAccessibility3.errors.txt +++ b/tests/baselines/reference/classConstructorAccessibility3.errors.txt @@ -2,21 +2,11 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib Cannot assign a 'protected' constructor type to a 'public' constructor type. tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(22,1): error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Foo'. Cannot assign a 'private' constructor type to a 'public' constructor type. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(26,1): error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Baz'. - Cannot assign a 'public' constructor type to a 'protected' constructor type. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(27,1): error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Baz'. - Cannot assign a 'public' constructor type to a 'protected' constructor type. tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(28,1): error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Baz'. Cannot assign a 'private' constructor type to a 'protected' constructor type. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(32,1): error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Qux'. - Cannot assign a 'public' constructor type to a 'private' constructor type. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(33,1): error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Qux'. - Cannot assign a 'public' constructor type to a 'private' constructor type. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(34,1): error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Qux'. - Cannot assign a 'protected' constructor type to a 'private' constructor type. -==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts (8 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts (3 errors) ==== class Foo { constructor(public x: number) { } @@ -48,14 +38,8 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib // b is protected let b = Baz; - b = Foo; // error Foo is public - ~ -!!! error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Baz'. -!!! error TS2322: Cannot assign a 'public' constructor type to a 'protected' constructor type. - b = Bar; // error Baz is public - ~ -!!! error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Baz'. -!!! error TS2322: Cannot assign a 'public' constructor type to a 'protected' constructor type. + b = Foo; + b = Bar; b = Qux; // error Qux is private ~ !!! error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Baz'. @@ -63,15 +47,6 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib // c is private let c = Qux; - c = Foo; // error Foo is public - ~ -!!! error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Qux'. -!!! error TS2322: Cannot assign a 'public' constructor type to a 'private' constructor type. - c = Bar; // error Bar is public - ~ -!!! error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Qux'. -!!! error TS2322: Cannot assign a 'public' constructor type to a 'private' constructor type. - c = Baz; // error Baz is protected - ~ -!!! error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Qux'. -!!! error TS2322: Cannot assign a 'protected' constructor type to a 'private' constructor type. \ No newline at end of file + c = Foo; + c = Bar; + c = Baz; \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorAccessibility3.js b/tests/baselines/reference/classConstructorAccessibility3.js index 02f5bb45a86..acc7d38aa55 100644 --- a/tests/baselines/reference/classConstructorAccessibility3.js +++ b/tests/baselines/reference/classConstructorAccessibility3.js @@ -24,15 +24,15 @@ a = Qux; // error Qux is private // b is protected let b = Baz; -b = Foo; // error Foo is public -b = Bar; // error Baz is public +b = Foo; +b = Bar; b = Qux; // error Qux is private // c is private let c = Qux; -c = Foo; // error Foo is public -c = Bar; // error Bar is public -c = Baz; // error Baz is protected +c = Foo; +c = Bar; +c = Baz; //// [classConstructorAccessibility3.js] var Foo = (function () { @@ -66,14 +66,14 @@ a = Baz; // error Baz is protected a = Qux; // error Qux is private // b is protected var b = Baz; -b = Foo; // error Foo is public -b = Bar; // error Baz is public +b = Foo; +b = Bar; b = Qux; // error Qux is private // c is private var c = Qux; -c = Foo; // error Foo is public -c = Bar; // error Bar is public -c = Baz; // error Baz is protected +c = Foo; +c = Bar; +c = Baz; //// [classConstructorAccessibility3.d.ts] diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts index 8508a40d101..91bb4873d96 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts @@ -24,12 +24,12 @@ a = Qux; // error Qux is private // b is protected let b = Baz; -b = Foo; // error Foo is public -b = Bar; // error Baz is public +b = Foo; +b = Bar; b = Qux; // error Qux is private // c is private let c = Qux; -c = Foo; // error Foo is public -c = Bar; // error Bar is public -c = Baz; // error Baz is protected \ No newline at end of file +c = Foo; +c = Bar; +c = Baz; \ No newline at end of file From 5ce0202bc9b93ba53d61f5e298a30dfd9fd1beb2 Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Thu, 4 Feb 2016 21:46:28 +0000 Subject: [PATCH 023/297] Refactored visibility text on modifier grammar check --- src/compiler/checker.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ebb02a2fdad..2351f6913af 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16269,16 +16269,12 @@ namespace ts { case SyntaxKind.PublicKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PrivateKeyword: - let text: string; - if (modifier.kind === SyntaxKind.PublicKeyword) { - text = "public"; - } - else if (modifier.kind === SyntaxKind.ProtectedKeyword) { - text = "protected"; + let text = visibilityToString(modifierToFlag(modifier.kind)); + + if (modifier.kind === SyntaxKind.ProtectedKeyword) { lastProtected = modifier; } - else { - text = "private"; + else if (modifier.kind === SyntaxKind.PrivateKeyword) { lastPrivate = modifier; } From dc1e23506c42b1d5609ae3f430e5bc8943299491 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 4 Feb 2016 14:10:02 -0800 Subject: [PATCH 024/297] fix test baselines --- tests/baselines/reference/arrayConcat2.symbols | 12 ++++++------ tests/baselines/reference/arrayConcat2.types | 12 ++++++------ tests/baselines/reference/arrayConcatMap.symbols | 4 ++-- tests/baselines/reference/arrayConcatMap.types | 4 ++-- tests/baselines/reference/concatError.symbols | 8 ++++---- tests/baselines/reference/concatError.types | 8 ++++---- .../reference/iteratorSpreadInArray6.errors.txt | 8 ++++++-- .../reference/iteratorSpreadInArray7.symbols | 4 ++-- .../baselines/reference/iteratorSpreadInArray7.types | 4 ++-- tests/baselines/reference/underscoreTest1.symbols | 4 ++-- tests/baselines/reference/underscoreTest1.types | 4 ++-- 11 files changed, 38 insertions(+), 34 deletions(-) diff --git a/tests/baselines/reference/arrayConcat2.symbols b/tests/baselines/reference/arrayConcat2.symbols index daedee6e9c8..fb84193c113 100644 --- a/tests/baselines/reference/arrayConcat2.symbols +++ b/tests/baselines/reference/arrayConcat2.symbols @@ -3,21 +3,21 @@ var a: string[] = []; >a : Symbol(a, Decl(arrayConcat2.ts, 0, 3)) a.concat("hello", 'world'); ->a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) >a : Symbol(a, Decl(arrayConcat2.ts, 0, 3)) ->concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) a.concat('Hello'); ->a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) >a : Symbol(a, Decl(arrayConcat2.ts, 0, 3)) ->concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) var b = new Array(); >b : Symbol(b, Decl(arrayConcat2.ts, 5, 3)) >Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) b.concat('hello'); ->b.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) >b : Symbol(b, Decl(arrayConcat2.ts, 5, 3)) ->concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) diff --git a/tests/baselines/reference/arrayConcat2.types b/tests/baselines/reference/arrayConcat2.types index a49046c871f..b7df3749116 100644 --- a/tests/baselines/reference/arrayConcat2.types +++ b/tests/baselines/reference/arrayConcat2.types @@ -5,17 +5,17 @@ var a: string[] = []; a.concat("hello", 'world'); >a.concat("hello", 'world') : string[] ->a.concat : { (...items: U[]): string[]; (...items: string[]): string[]; } +>a.concat : (...items: (string | string[])[]) => string[] >a : string[] ->concat : { (...items: U[]): string[]; (...items: string[]): string[]; } +>concat : (...items: (string | string[])[]) => string[] >"hello" : string >'world' : string a.concat('Hello'); >a.concat('Hello') : string[] ->a.concat : { (...items: U[]): string[]; (...items: string[]): string[]; } +>a.concat : (...items: (string | string[])[]) => string[] >a : string[] ->concat : { (...items: U[]): string[]; (...items: string[]): string[]; } +>concat : (...items: (string | string[])[]) => string[] >'Hello' : string var b = new Array(); @@ -25,8 +25,8 @@ var b = new Array(); b.concat('hello'); >b.concat('hello') : string[] ->b.concat : { (...items: U[]): string[]; (...items: string[]): string[]; } +>b.concat : (...items: (string | string[])[]) => string[] >b : string[] ->concat : { (...items: U[]): string[]; (...items: string[]): string[]; } +>concat : (...items: (string | string[])[]) => string[] >'hello' : string diff --git a/tests/baselines/reference/arrayConcatMap.symbols b/tests/baselines/reference/arrayConcatMap.symbols index 5ef9d811723..bde2686e259 100644 --- a/tests/baselines/reference/arrayConcatMap.symbols +++ b/tests/baselines/reference/arrayConcatMap.symbols @@ -2,8 +2,8 @@ var x = [].concat([{ a: 1 }], [{ a: 2 }]) >x : Symbol(x, Decl(arrayConcatMap.ts, 0, 3)) >[].concat([{ a: 1 }], [{ a: 2 }]) .map : Symbol(Array.map, Decl(lib.d.ts, --, --)) ->[].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>[].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) +>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) >a : Symbol(a, Decl(arrayConcatMap.ts, 0, 20)) >a : Symbol(a, Decl(arrayConcatMap.ts, 0, 32)) diff --git a/tests/baselines/reference/arrayConcatMap.types b/tests/baselines/reference/arrayConcatMap.types index 11342ee848a..38e1a1c49c9 100644 --- a/tests/baselines/reference/arrayConcatMap.types +++ b/tests/baselines/reference/arrayConcatMap.types @@ -4,9 +4,9 @@ var x = [].concat([{ a: 1 }], [{ a: 2 }]) >[].concat([{ a: 1 }], [{ a: 2 }]) .map(b => b.a) : any[] >[].concat([{ a: 1 }], [{ a: 2 }]) .map : (callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[] >[].concat([{ a: 1 }], [{ a: 2 }]) : any[] ->[].concat : { (...items: U[]): any[]; (...items: any[]): any[]; } +>[].concat : (...items: any[]) => any[] >[] : undefined[] ->concat : { (...items: U[]): any[]; (...items: any[]): any[]; } +>concat : (...items: any[]) => any[] >[{ a: 1 }] : { a: number; }[] >{ a: 1 } : { a: number; } >a : number diff --git a/tests/baselines/reference/concatError.symbols b/tests/baselines/reference/concatError.symbols index d4f04531fc7..23cc55c85be 100644 --- a/tests/baselines/reference/concatError.symbols +++ b/tests/baselines/reference/concatError.symbols @@ -14,15 +14,15 @@ var fa: number[]; fa = fa.concat([0]); >fa : Symbol(fa, Decl(concatError.ts, 8, 3)) ->fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) >fa : Symbol(fa, Decl(concatError.ts, 8, 3)) ->concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) fa = fa.concat(0); >fa : Symbol(fa, Decl(concatError.ts, 8, 3)) ->fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) >fa : Symbol(fa, Decl(concatError.ts, 8, 3)) ->concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) diff --git a/tests/baselines/reference/concatError.types b/tests/baselines/reference/concatError.types index c264e0b0204..21a5cc5d089 100644 --- a/tests/baselines/reference/concatError.types +++ b/tests/baselines/reference/concatError.types @@ -16,9 +16,9 @@ fa = fa.concat([0]); >fa = fa.concat([0]) : number[] >fa : number[] >fa.concat([0]) : number[] ->fa.concat : { (...items: U[]): number[]; (...items: number[]): number[]; } +>fa.concat : (...items: (number | number[])[]) => number[] >fa : number[] ->concat : { (...items: U[]): number[]; (...items: number[]): number[]; } +>concat : (...items: (number | number[])[]) => number[] >[0] : number[] >0 : number @@ -26,9 +26,9 @@ fa = fa.concat(0); >fa = fa.concat(0) : number[] >fa : number[] >fa.concat(0) : number[] ->fa.concat : { (...items: U[]): number[]; (...items: number[]): number[]; } +>fa.concat : (...items: (number | number[])[]) => number[] >fa : number[] ->concat : { (...items: U[]): number[]; (...items: number[]): number[]; } +>concat : (...items: (number | number[])[]) => number[] >0 : number diff --git a/tests/baselines/reference/iteratorSpreadInArray6.errors.txt b/tests/baselines/reference/iteratorSpreadInArray6.errors.txt index b90ac5f203c..8148ce43de7 100644 --- a/tests/baselines/reference/iteratorSpreadInArray6.errors.txt +++ b/tests/baselines/reference/iteratorSpreadInArray6.errors.txt @@ -1,11 +1,15 @@ -tests/cases/conformance/es6/spread/iteratorSpreadInArray6.ts(2,14): error TS2345: Argument of type 'symbol[]' is not assignable to parameter of type 'number'. +tests/cases/conformance/es6/spread/iteratorSpreadInArray6.ts(2,14): error TS2345: Argument of type 'symbol[]' is not assignable to parameter of type 'number | number[]'. + Type 'symbol[]' is not assignable to type 'number[]'. + Type 'symbol' is not assignable to type 'number'. ==== tests/cases/conformance/es6/spread/iteratorSpreadInArray6.ts (1 errors) ==== var array: number[] = [0, 1]; array.concat([...new SymbolIterator]); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type 'symbol[]' is not assignable to parameter of type 'number'. +!!! error TS2345: Argument of type 'symbol[]' is not assignable to parameter of type 'number | number[]'. +!!! error TS2345: Type 'symbol[]' is not assignable to type 'number[]'. +!!! error TS2345: Type 'symbol' is not assignable to type 'number'. class SymbolIterator { next() { diff --git a/tests/baselines/reference/iteratorSpreadInArray7.symbols b/tests/baselines/reference/iteratorSpreadInArray7.symbols index e498e68b9eb..64521a9a33e 100644 --- a/tests/baselines/reference/iteratorSpreadInArray7.symbols +++ b/tests/baselines/reference/iteratorSpreadInArray7.symbols @@ -3,9 +3,9 @@ var array: symbol[]; >array : Symbol(array, Decl(iteratorSpreadInArray7.ts, 0, 3)) array.concat([...new SymbolIterator]); ->array.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>array.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) >array : Symbol(array, Decl(iteratorSpreadInArray7.ts, 0, 3)) ->concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) >SymbolIterator : Symbol(SymbolIterator, Decl(iteratorSpreadInArray7.ts, 1, 38)) class SymbolIterator { diff --git a/tests/baselines/reference/iteratorSpreadInArray7.types b/tests/baselines/reference/iteratorSpreadInArray7.types index 6a279838060..f1dd8ebf855 100644 --- a/tests/baselines/reference/iteratorSpreadInArray7.types +++ b/tests/baselines/reference/iteratorSpreadInArray7.types @@ -4,9 +4,9 @@ var array: symbol[]; array.concat([...new SymbolIterator]); >array.concat([...new SymbolIterator]) : symbol[] ->array.concat : { (...items: U[]): symbol[]; (...items: symbol[]): symbol[]; } +>array.concat : (...items: (symbol | symbol[])[]) => symbol[] >array : symbol[] ->concat : { (...items: U[]): symbol[]; (...items: symbol[]): symbol[]; } +>concat : (...items: (symbol | symbol[])[]) => symbol[] >[...new SymbolIterator] : symbol[] >...new SymbolIterator : symbol >new SymbolIterator : SymbolIterator diff --git a/tests/baselines/reference/underscoreTest1.symbols b/tests/baselines/reference/underscoreTest1.symbols index 9de509de417..ee8460e16ed 100644 --- a/tests/baselines/reference/underscoreTest1.symbols +++ b/tests/baselines/reference/underscoreTest1.symbols @@ -71,9 +71,9 @@ var flat = _.reduceRight(list, (a, b) => a.concat(b), []); >list : Symbol(list, Decl(underscoreTest1_underscoreTests.ts, 13, 3)) >a : Symbol(a, Decl(underscoreTest1_underscoreTests.ts, 14, 32)) >b : Symbol(b, Decl(underscoreTest1_underscoreTests.ts, 14, 34)) ->a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) >a : Symbol(a, Decl(underscoreTest1_underscoreTests.ts, 14, 32)) ->concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) >b : Symbol(b, Decl(underscoreTest1_underscoreTests.ts, 14, 34)) var even = _.find([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 7fe233c4490..4d8a05a5c38 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -124,9 +124,9 @@ var flat = _.reduceRight(list, (a, b) => a.concat(b), []); >a : number[] >b : number[] >a.concat(b) : number[] ->a.concat : { (...items: U[]): number[]; (...items: number[]): number[]; } +>a.concat : (...items: (number | number[])[]) => number[] >a : number[] ->concat : { (...items: U[]): number[]; (...items: number[]): number[]; } +>concat : (...items: (number | number[])[]) => number[] >b : number[] >[] : undefined[] From 16b54e0d9fced4351fa8f2431150be29ddd5bfcc Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Thu, 4 Feb 2016 22:52:19 +0000 Subject: [PATCH 025/297] Addressed PR. Diagnostic messages --- src/compiler/checker.ts | 6 +++--- src/compiler/diagnosticMessages.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2351f6913af..5c69bb7f356 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10182,10 +10182,10 @@ namespace ts { // A private or protected constructor can only be instantiated within it's own class if (declaringClass !== enclosingClass) { if (flags & NodeFlags.Private) { - error(node, Diagnostics.Constructor_of_type_0_is_private_and_only_accessible_within_class_1, signatureToString(signature), typeToString(declaringClass)); + error(node, Diagnostics.Constructor_of_class_0_is_private_and_only_accessible_within_the_class_declaration, typeToString(declaringClass)); } if (flags & NodeFlags.Protected) { - error(node, Diagnostics.Constructor_of_type_0_is_protected_and_only_accessible_within_class_1, signatureToString(signature), typeToString(declaringClass)); + error(node, Diagnostics.Constructor_of_class_0_is_protected_and_only_accessible_within_the_class_declaration, typeToString(declaringClass)); } return false; } @@ -14059,7 +14059,7 @@ namespace ts { if (signatures.length) { const declaration = signatures[0].declaration; if (declaration && declaration.flags & NodeFlags.Private) { - error(node, Diagnostics.Cannot_extend_private_class_0, (node.expression).text); + error(node, Diagnostics.Cannot_extend_a_class_0_Class_constructor_is_marked_as_private, (node.expression).text); } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 2ee388ff42e..b88b9b2a0e1 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1827,15 +1827,15 @@ "category": "Error", "code": 2672 }, - "Constructor of type '{0}' is private and only accessible within class '{1}'.": { + "Constructor of class '{0}' is private and only accessible within the class declaration.": { "category": "Error", "code": 2673 }, - "Constructor of type '{0}' is protected and only accessible within class '{1}'.": { + "Constructor of class '{0}' is protected and only accessible within the class declaration.": { "category": "Error", "code": 2674 }, - "Cannot extend private class '{0}'.": { + "Cannot extend a class '{0}'. Class constructor is marked as private.": { "category": "Error", "code": 2675 }, From 037b65781fe268fd3f6206a16a27dfbc7ee4b652 Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Thu, 4 Feb 2016 22:52:38 +0000 Subject: [PATCH 026/297] Accept baselines --- .../classConstructorAccessibility.errors.txt | 16 +++++++-------- .../classConstructorAccessibility2.errors.txt | 20 +++++++++---------- .../typesWithPrivateConstructor.errors.txt | 8 ++++---- .../typesWithProtectedConstructor.errors.txt | 8 ++++---- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/baselines/reference/classConstructorAccessibility.errors.txt b/tests/baselines/reference/classConstructorAccessibility.errors.txt index a24ec6c63d1..c79633ba33d 100644 --- a/tests/baselines/reference/classConstructorAccessibility.errors.txt +++ b/tests/baselines/reference/classConstructorAccessibility.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(15,9): error TS2673: Constructor of type '(x: number): D' is private and only accessible within class 'D'. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(16,9): error TS2674: Constructor of type '(x: number): E' is protected and only accessible within class 'E'. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(32,13): error TS2673: Constructor of type '(x: T): D' is private and only accessible within class 'D'. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(33,13): error TS2674: Constructor of type '(x: T): E' is protected and only accessible within class 'E'. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(15,9): error TS2673: Constructor of class 'D' is private and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(16,9): error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(32,13): error TS2673: Constructor of class 'D' is private and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(33,13): error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. ==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts (4 errors) ==== @@ -21,10 +21,10 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib var c = new C(1); var d = new D(1); // error ~~~~~~~~ -!!! error TS2673: Constructor of type '(x: number): D' is private and only accessible within class 'D'. +!!! error TS2673: Constructor of class 'D' is private and only accessible within the class declaration. var e = new E(1); // error ~~~~~~~~ -!!! error TS2674: Constructor of type '(x: number): E' is protected and only accessible within class 'E'. +!!! error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. module Generic { class C { @@ -42,9 +42,9 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib var c = new C(1); var d = new D(1); // error ~~~~~~~~ -!!! error TS2673: Constructor of type '(x: T): D' is private and only accessible within class 'D'. +!!! error TS2673: Constructor of class 'D' is private and only accessible within the class declaration. var e = new E(1); // error ~~~~~~~~ -!!! error TS2674: Constructor of type '(x: T): E' is protected and only accessible within class 'E'. +!!! error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. } \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorAccessibility2.errors.txt b/tests/baselines/reference/classConstructorAccessibility2.errors.txt index 1c6fc46edb3..7bd784ac268 100644 --- a/tests/baselines/reference/classConstructorAccessibility2.errors.txt +++ b/tests/baselines/reference/classConstructorAccessibility2.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(26,28): error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(29,24): error TS2675: Cannot extend private class 'BaseC'. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(32,28): error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(36,10): error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(37,10): error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(26,28): error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(29,24): error TS2675: Cannot extend a class 'BaseC'. Class constructor is marked as private. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(32,28): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(36,10): error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(37,10): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. ==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts (5 errors) ==== @@ -33,26 +33,26 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib createInstance() { new DerivedB(1); } createBaseInstance() { new BaseB(1); } // error ~~~~~~~~~~~~ -!!! error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'. +!!! error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. } class DerivedC extends BaseC { // error ~~~~~ -!!! error TS2675: Cannot extend private class 'BaseC'. +!!! error TS2675: Cannot extend a class 'BaseC'. Class constructor is marked as private. constructor(public x: number) { super(x); } createInstance() { new DerivedC(1); } createBaseInstance() { new BaseC(1); } // error ~~~~~~~~~~~~ -!!! error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'. +!!! error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. } var ba = new BaseA(1); var bb = new BaseB(1); // error ~~~~~~~~~~~~ -!!! error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'. +!!! error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. var bc = new BaseC(1); // error ~~~~~~~~~~~~ -!!! error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'. +!!! error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. var da = new DerivedA(1); var db = new DerivedB(1); diff --git a/tests/baselines/reference/typesWithPrivateConstructor.errors.txt b/tests/baselines/reference/typesWithPrivateConstructor.errors.txt index d30bb29e314..ab8ea4e26ad 100644 --- a/tests/baselines/reference/typesWithPrivateConstructor.errors.txt +++ b/tests/baselines/reference/typesWithPrivateConstructor.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(6,9): error TS2673: Constructor of type '(): C' is private and only accessible within class 'C'. -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(14,10): error TS2673: Constructor of type '(x: number): C2' is private and only accessible within class 'C2'. +tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(6,9): error TS2673: Constructor of class 'C' is private and only accessible within the class declaration. +tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(14,10): error TS2673: Constructor of class 'C2' is private and only accessible within the class declaration. ==== tests/cases/conformance/types/members/typesWithPrivateConstructor.ts (2 errors) ==== @@ -10,7 +10,7 @@ tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(14,10): err var c = new C(); // error C is private ~~~~~~~ -!!! error TS2673: Constructor of type '(): C' is private and only accessible within class 'C'. +!!! error TS2673: Constructor of class 'C' is private and only accessible within the class declaration. var r: () => void = c.constructor; class C2 { @@ -20,5 +20,5 @@ tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(14,10): err var c2 = new C2(); // error C2 is private ~~~~~~~~ -!!! error TS2673: Constructor of type '(x: number): C2' is private and only accessible within class 'C2'. +!!! error TS2673: Constructor of class 'C2' is private and only accessible within the class declaration. var r2: (x: number) => void = c2.constructor; \ No newline at end of file diff --git a/tests/baselines/reference/typesWithProtectedConstructor.errors.txt b/tests/baselines/reference/typesWithProtectedConstructor.errors.txt index 4dc8add9fc2..2a5a059f44d 100644 --- a/tests/baselines/reference/typesWithProtectedConstructor.errors.txt +++ b/tests/baselines/reference/typesWithProtectedConstructor.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(6,9): error TS2674: Constructor of type '(): C' is protected and only accessible within class 'C'. -tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(14,10): error TS2674: Constructor of type '(x: number): C2' is protected and only accessible within class 'C2'. +tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(6,9): error TS2674: Constructor of class 'C' is protected and only accessible within the class declaration. +tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(14,10): error TS2674: Constructor of class 'C2' is protected and only accessible within the class declaration. ==== tests/cases/conformance/types/members/typesWithProtectedConstructor.ts (2 errors) ==== @@ -10,7 +10,7 @@ tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(14,10): e var c = new C(); // error C is protected ~~~~~~~ -!!! error TS2674: Constructor of type '(): C' is protected and only accessible within class 'C'. +!!! error TS2674: Constructor of class 'C' is protected and only accessible within the class declaration. var r: () => void = c.constructor; class C2 { @@ -20,5 +20,5 @@ tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(14,10): e var c2 = new C2(); // error C2 is protected ~~~~~~~~ -!!! error TS2674: Constructor of type '(x: number): C2' is protected and only accessible within class 'C2'. +!!! error TS2674: Constructor of class 'C2' is protected and only accessible within the class declaration. var r2: (x: number) => void = c2.constructor; \ No newline at end of file From f35ab8c62043242c8579fb43486b74ea9076ecad Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 4 Feb 2016 14:18:23 -0800 Subject: [PATCH 027/297] Port fix6901 from release-1.8 to master Fix where we start checking for super-call Update baselines Address PR --- src/compiler/checker.ts | 4 -- src/compiler/emitter.ts | 34 +++++++++------- src/compiler/utilities.ts | 4 ++ ...BeforeEmitParameterPropertyDeclaration1.js | 37 ++++++++++++++++++ ...eEmitParameterPropertyDeclaration1.symbols | 23 +++++++++++ ...oreEmitParameterPropertyDeclaration1.types | 29 ++++++++++++++ ...oreEmitParameterPropertyDeclaration1ES6.js | 29 ++++++++++++++ ...itParameterPropertyDeclaration1ES6.symbols | 23 +++++++++++ ...EmitParameterPropertyDeclaration1ES6.types | 29 ++++++++++++++ ...SuperCallBeforeEmitPropertyDeclaration1.js | 39 +++++++++++++++++++ ...CallBeforeEmitPropertyDeclaration1.symbols | 23 +++++++++++ ...erCallBeforeEmitPropertyDeclaration1.types | 30 ++++++++++++++ ...erCallBeforeEmitPropertyDeclaration1ES6.js | 29 ++++++++++++++ ...lBeforeEmitPropertyDeclaration1ES6.symbols | 22 +++++++++++ ...allBeforeEmitPropertyDeclaration1ES6.types | 27 +++++++++++++ ...arationAndParameterPropertyDeclaration1.js | 38 ++++++++++++++++++ ...onAndParameterPropertyDeclaration1.symbols | 25 ++++++++++++ ...tionAndParameterPropertyDeclaration1.types | 32 +++++++++++++++ ...tionAndParameterPropertyDeclaration1ES6.js | 30 ++++++++++++++ ...ndParameterPropertyDeclaration1ES6.symbols | 25 ++++++++++++ ...nAndParameterPropertyDeclaration1ES6.types | 32 +++++++++++++++ .../reference/strictModeInConstructor.js | 2 +- 22 files changed, 548 insertions(+), 18 deletions(-) create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.js create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.symbols create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.types create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.js create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.symbols create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.types create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.js create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.symbols create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.types create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.js create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.symbols create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.types create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.js create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.symbols create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.types create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.js create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.symbols create mode 100644 tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 65cb3df785f..63a4185a8bb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11834,10 +11834,6 @@ namespace ts { return; } - function isSuperCallExpression(n: Node): boolean { - return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; - } - function containsSuperCallAsComputedPropertyName(n: Declaration): boolean { return n.name && containsSuperCall(n.name); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index aba0c883aaa..52ee502b25f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4895,18 +4895,24 @@ const _super = (function (geti, seti) { emitToken(SyntaxKind.CloseBraceToken, body.statements.end); } - function findInitialSuperCall(ctor: ConstructorDeclaration): ExpressionStatement { - if (ctor.body) { - const statement = (ctor.body).statements[0]; - if (statement && statement.kind === SyntaxKind.ExpressionStatement) { - const expr = (statement).expression; - if (expr && expr.kind === SyntaxKind.CallExpression) { - const func = (expr).expression; - if (func && func.kind === SyntaxKind.SuperKeyword) { - return statement; - } - } - } + /** + * Return the statement at a given index if it is a super-call statement + * @param ctor a constructor declaration + * @param index an index to constructor's body to check + */ + function getSuperCallAtGivenIndex(ctor: ConstructorDeclaration, index: number): ExpressionStatement { + if (!ctor.body) { + return undefined; + } + const statements = ctor.body.statements; + + if (!statements || index >= statements.length) { + return undefined; + } + + const statement = statements[index]; + if (statement.kind === SyntaxKind.ExpressionStatement) { + return isSuperCallExpression((statement).expression) ? statement : undefined; } } @@ -5190,13 +5196,15 @@ const _super = (function (geti, seti) { if (ctor) { emitDefaultValueAssignments(ctor); emitRestParameter(ctor); + if (baseTypeElement) { - superCall = findInitialSuperCall(ctor); + superCall = getSuperCallAtGivenIndex(ctor, startIndex); if (superCall) { writeLine(); emit(superCall); } } + emitParameterPropertyAssignments(ctor); } else { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8f66e43c1d6..09100eb61ed 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -464,6 +464,10 @@ namespace ts { return !!(getCombinedNodeFlags(node) & NodeFlags.Let); } + export function isSuperCallExpression(n: Node): boolean { + return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; + } + export function isPrologueDirective(node: Node): boolean { return node.kind === SyntaxKind.ExpressionStatement && (node).expression.kind === SyntaxKind.StringLiteral; } diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.js b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.js new file mode 100644 index 00000000000..88ce3f1418b --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.js @@ -0,0 +1,37 @@ +//// [emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts] +class A { + blub = 6; +} + + +class B extends A { + constructor(public x: number) { + "use strict"; + 'someStringForEgngInject'; + super() + } +} + + +//// [emitSuperCallBeforeEmitParameterPropertyDeclaration1.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var A = (function () { + function A() { + this.blub = 6; + } + return A; +}()); +var B = (function (_super) { + __extends(B, _super); + function B(x) { + "use strict"; + 'someStringForEgngInject'; + _super.call(this); + this.x = x; + } + return B; +}(A)); diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.symbols b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.symbols new file mode 100644 index 00000000000..3931a7115f6 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.symbols @@ -0,0 +1,23 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts === +class A { +>A : Symbol(A, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts, 0, 0)) + + blub = 6; +>blub : Symbol(blub, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts, 0, 9)) +} + + +class B extends A { +>B : Symbol(B, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts, 2, 1)) +>A : Symbol(A, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts, 0, 0)) + + constructor(public x: number) { +>x : Symbol(x, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts, 6, 16)) + + "use strict"; + 'someStringForEgngInject'; + super() +>super : Symbol(A, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.types b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.types new file mode 100644 index 00000000000..cfdf0af0300 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1.types @@ -0,0 +1,29 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts === +class A { +>A : A + + blub = 6; +>blub : number +>6 : number +} + + +class B extends A { +>B : B +>A : A + + constructor(public x: number) { +>x : number + + "use strict"; +>"use strict" : string + + 'someStringForEgngInject'; +>'someStringForEgngInject' : string + + super() +>super() : void +>super : typeof A + } +} + diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.js b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.js new file mode 100644 index 00000000000..2e594dba0ec --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.js @@ -0,0 +1,29 @@ +//// [emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts] +class A { + blub = 6; +} + + +class B extends A { + constructor(public x: number) { + "use strict"; + 'someStringForEgngInject'; + super() + } +} + + +//// [emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.js] +class A { + constructor() { + this.blub = 6; + } +} +class B extends A { + constructor(x) { + "use strict"; + 'someStringForEgngInject'; + super(); + this.x = x; + } +} diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.symbols b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.symbols new file mode 100644 index 00000000000..8b8c09f2611 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.symbols @@ -0,0 +1,23 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts === +class A { +>A : Symbol(A, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts, 0, 0)) + + blub = 6; +>blub : Symbol(blub, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts, 0, 9)) +} + + +class B extends A { +>B : Symbol(B, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts, 2, 1)) +>A : Symbol(A, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts, 0, 0)) + + constructor(public x: number) { +>x : Symbol(x, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts, 6, 16)) + + "use strict"; + 'someStringForEgngInject'; + super() +>super : Symbol(A, Decl(emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.types b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.types new file mode 100644 index 00000000000..4424042c241 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.types @@ -0,0 +1,29 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts === +class A { +>A : A + + blub = 6; +>blub : number +>6 : number +} + + +class B extends A { +>B : B +>A : A + + constructor(public x: number) { +>x : number + + "use strict"; +>"use strict" : string + + 'someStringForEgngInject'; +>'someStringForEgngInject' : string + + super() +>super() : void +>super : typeof A + } +} + diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.js b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.js new file mode 100644 index 00000000000..920ad1f7bda --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.js @@ -0,0 +1,39 @@ +//// [emitSuperCallBeforeEmitPropertyDeclaration1.ts] +class A { + blub = 6; +} + + +class B extends A { + + blub = 12; + + constructor() { + "use strict"; + 'someStringForEgngInject'; + super() + } +} + +//// [emitSuperCallBeforeEmitPropertyDeclaration1.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var A = (function () { + function A() { + this.blub = 6; + } + return A; +}()); +var B = (function (_super) { + __extends(B, _super); + function B() { + "use strict"; + 'someStringForEgngInject'; + _super.call(this); + this.blub = 12; + } + return B; +}(A)); diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.symbols b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.symbols new file mode 100644 index 00000000000..0b118b7c991 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.symbols @@ -0,0 +1,23 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1.ts === +class A { +>A : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclaration1.ts, 0, 0)) + + blub = 6; +>blub : Symbol(blub, Decl(emitSuperCallBeforeEmitPropertyDeclaration1.ts, 0, 9)) +} + + +class B extends A { +>B : Symbol(B, Decl(emitSuperCallBeforeEmitPropertyDeclaration1.ts, 2, 1)) +>A : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclaration1.ts, 0, 0)) + + blub = 12; +>blub : Symbol(blub, Decl(emitSuperCallBeforeEmitPropertyDeclaration1.ts, 5, 19)) + + constructor() { + "use strict"; + 'someStringForEgngInject'; + super() +>super : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclaration1.ts, 0, 0)) + } +} diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.types b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.types new file mode 100644 index 00000000000..2d16fed121d --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1.ts === +class A { +>A : A + + blub = 6; +>blub : number +>6 : number +} + + +class B extends A { +>B : B +>A : A + + blub = 12; +>blub : number +>12 : number + + constructor() { + "use strict"; +>"use strict" : string + + 'someStringForEgngInject'; +>'someStringForEgngInject' : string + + super() +>super() : void +>super : typeof A + } +} diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.js b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.js new file mode 100644 index 00000000000..4b3e9e73b9f --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.js @@ -0,0 +1,29 @@ +//// [emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts] +class A { + blub = 6; +} + + +class B extends A { + + blub = 12; + + constructor() { + 'someStringForEgngInject'; + super() + } +} + +//// [emitSuperCallBeforeEmitPropertyDeclaration1ES6.js] +class A { + constructor() { + this.blub = 6; + } +} +class B extends A { + constructor() { + 'someStringForEgngInject'; + super(); + this.blub = 12; + } +} diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.symbols b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.symbols new file mode 100644 index 00000000000..4d4b01a3666 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts === +class A { +>A : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts, 0, 0)) + + blub = 6; +>blub : Symbol(blub, Decl(emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts, 0, 9)) +} + + +class B extends A { +>B : Symbol(B, Decl(emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts, 2, 1)) +>A : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts, 0, 0)) + + blub = 12; +>blub : Symbol(blub, Decl(emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts, 5, 19)) + + constructor() { + 'someStringForEgngInject'; + super() +>super : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts, 0, 0)) + } +} diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.types b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.types new file mode 100644 index 00000000000..39e8f885777 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclaration1ES6.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts === +class A { +>A : A + + blub = 6; +>blub : number +>6 : number +} + + +class B extends A { +>B : B +>A : A + + blub = 12; +>blub : number +>12 : number + + constructor() { + 'someStringForEgngInject'; +>'someStringForEgngInject' : string + + super() +>super() : void +>super : typeof A + } +} diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.js b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.js new file mode 100644 index 00000000000..3fa18140034 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.js @@ -0,0 +1,38 @@ +//// [emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts] +class A { + blub = 6; +} + + +class B extends A { + blah = 2; + constructor(public x: number) { + "use strict"; + 'someStringForEgngInject'; + super() + } +} + +//// [emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var A = (function () { + function A() { + this.blub = 6; + } + return A; +}()); +var B = (function (_super) { + __extends(B, _super); + function B(x) { + "use strict"; + 'someStringForEgngInject'; + _super.call(this); + this.x = x; + this.blah = 2; + } + return B; +}(A)); diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.symbols b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.symbols new file mode 100644 index 00000000000..1fb4ed01d85 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts === +class A { +>A : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts, 0, 0)) + + blub = 6; +>blub : Symbol(blub, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts, 0, 9)) +} + + +class B extends A { +>B : Symbol(B, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts, 2, 1)) +>A : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts, 0, 0)) + + blah = 2; +>blah : Symbol(blah, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts, 5, 19)) + + constructor(public x: number) { +>x : Symbol(x, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts, 7, 16)) + + "use strict"; + 'someStringForEgngInject'; + super() +>super : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts, 0, 0)) + } +} diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.types b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.types new file mode 100644 index 00000000000..acb5703581a --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts === +class A { +>A : A + + blub = 6; +>blub : number +>6 : number +} + + +class B extends A { +>B : B +>A : A + + blah = 2; +>blah : number +>2 : number + + constructor(public x: number) { +>x : number + + "use strict"; +>"use strict" : string + + 'someStringForEgngInject'; +>'someStringForEgngInject' : string + + super() +>super() : void +>super : typeof A + } +} diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.js b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.js new file mode 100644 index 00000000000..5e27acf8d9a --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.js @@ -0,0 +1,30 @@ +//// [emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts] +class A { + blub = 6; +} + + +class B extends A { + blah = 2; + constructor(public x: number) { + "use strict"; + 'someStringForEgngInject'; + super() + } +} + +//// [emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.js] +class A { + constructor() { + this.blub = 6; + } +} +class B extends A { + constructor(x) { + "use strict"; + 'someStringForEgngInject'; + super(); + this.x = x; + this.blah = 2; + } +} diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.symbols b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.symbols new file mode 100644 index 00000000000..41cb20f3841 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts === +class A { +>A : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts, 0, 0)) + + blub = 6; +>blub : Symbol(blub, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts, 0, 9)) +} + + +class B extends A { +>B : Symbol(B, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts, 2, 1)) +>A : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts, 0, 0)) + + blah = 2; +>blah : Symbol(blah, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts, 5, 19)) + + constructor(public x: number) { +>x : Symbol(x, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts, 7, 16)) + + "use strict"; + 'someStringForEgngInject'; + super() +>super : Symbol(A, Decl(emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts, 0, 0)) + } +} diff --git a/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.types b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.types new file mode 100644 index 00000000000..96fc1fc2dc3 --- /dev/null +++ b/tests/baselines/reference/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts === +class A { +>A : A + + blub = 6; +>blub : number +>6 : number +} + + +class B extends A { +>B : B +>A : A + + blah = 2; +>blah : number +>2 : number + + constructor(public x: number) { +>x : number + + "use strict"; +>"use strict" : string + + 'someStringForEgngInject'; +>'someStringForEgngInject' : string + + super() +>super() : void +>super : typeof A + } +} diff --git a/tests/baselines/reference/strictModeInConstructor.js b/tests/baselines/reference/strictModeInConstructor.js index 3b315861548..bcfbdf22414 100644 --- a/tests/baselines/reference/strictModeInConstructor.js +++ b/tests/baselines/reference/strictModeInConstructor.js @@ -75,8 +75,8 @@ var B = (function (_super) { __extends(B, _super); function B() { "use strict"; // No error - this.s = 9; _super.call(this); + this.s = 9; } return B; }(A)); From a6a5a22a32e99c2bfd2d7eb658e7e6ce8c9588b3 Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Fri, 5 Feb 2016 18:53:08 +0000 Subject: [PATCH 028/297] Addressed PR --- src/compiler/checker.ts | 46 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5c69bb7f356..9a7a92b91ec 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5910,7 +5910,7 @@ namespace ts { } return Ternary.False; } - if (!constructorRelatedTo(sourceSignatures[0], targetSignatures[0], reportErrors)) { + if (!constructorVisibilitiesAreCompatible(sourceSignatures[0], targetSignatures[0], reportErrors)) { return Ternary.False; } } @@ -6067,26 +6067,34 @@ namespace ts { return Ternary.True; } - function constructorRelatedTo(sourceSignature: Signature, targetSignature: Signature, reportErrors: boolean) { - if (sourceSignature && targetSignature && sourceSignature.declaration && targetSignature.declaration) { - // A public, protected and private signature is assignable to a private signature. - // A public and protected signature is assignable to a protected signature. - // And only a public signature is assignable to public signature. - const sourceAccessibility = sourceSignature.declaration.flags & (NodeFlags.Private | NodeFlags.Protected); - const targetAccessibility = targetSignature.declaration.flags & (NodeFlags.Private | NodeFlags.Protected); - - const isRelated = targetAccessibility === NodeFlags.Private - || (targetAccessibility === NodeFlags.Protected && sourceAccessibility !== NodeFlags.Private) - || (targetAccessibility !== NodeFlags.Protected && !(sourceAccessibility & (NodeFlags.Private | NodeFlags.Protected))); - - if (!isRelated && reportErrors) { - reportError(Diagnostics.Cannot_assign_a_0_constructor_type_to_a_1_constructor_type, visibilityToString(sourceAccessibility), visibilityToString(targetAccessibility)); - } - - return isRelated; + function constructorVisibilitiesAreCompatible(sourceSignature: Signature, targetSignature: Signature, reportErrors: boolean) { + if (!sourceSignature.declaration || !targetSignature.declaration) { + return true; } - return true; + const sourceAccessibility = sourceSignature.declaration.flags & (NodeFlags.Private | NodeFlags.Protected); + const targetAccessibility = targetSignature.declaration.flags & (NodeFlags.Private | NodeFlags.Protected); + + // A public, protected and private signature is assignable to a private signature. + if (targetAccessibility === NodeFlags.Private) { + return true; + } + + // A public and protected signature is assignable to a protected signature. + if (targetAccessibility === NodeFlags.Protected && sourceAccessibility !== NodeFlags.Private) { + return true; + } + + // Only a public signature is assignable to public signature. + if (targetAccessibility !== NodeFlags.Protected && !sourceAccessibility) { + return true; + } + + if (reportErrors) { + reportError(Diagnostics.Cannot_assign_a_0_constructor_type_to_a_1_constructor_type, visibilityToString(sourceAccessibility), visibilityToString(targetAccessibility)); + } + + return false; } } From 95396cc2bcc925db4e820aa05d053bcf5e0950e9 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Fri, 5 Feb 2016 21:03:27 +0000 Subject: [PATCH 029/297] spelling fixes for services.ts * aliases * analyze * asterisks * constructor * diagnostic * existing * referring * revisiting * search * source * visible --- src/services/services.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 211b1358c50..78c0f57ccf8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -502,7 +502,7 @@ namespace ts { spacesToRemoveAfterAsterisk = 0; } - // Analyse text on this line + // Analyze text on this line while (pos < end && !isLineBreak(sourceFile.text.charCodeAt(pos))) { const ch = sourceFile.text.charAt(pos); if (ch === "@") { @@ -641,7 +641,7 @@ namespace ts { paramHelpStringMargin = undefined; } - // If this is the start of another tag, continue with the loop in seach of param tag with symbol name + // If this is the start of another tag, continue with the loop in search of param tag with symbol name if (sourceFile.text.charCodeAt(pos) === CharacterCodes.at) { continue; } @@ -2822,7 +2822,7 @@ namespace ts { } // Check if the language version has changed since we last created a program; if they are the same, - // it is safe to reuse the souceFiles; if not, then the shape of the AST can change, and the oldSourceFile + // it is safe to reuse the sourceFiles; if not, then the shape of the AST can change, and the oldSourceFile // can not be reused. we have to dump all syntax trees and create new ones. if (!changesInCompilationSettingsAffectSyntax) { // Check if the old program had this file already @@ -2916,7 +2916,7 @@ namespace ts { } /** - * getSemanticDiagnostiscs return array of Diagnostics. If '-d' is not enabled, only report semantic errors + * getSemanticDiagnostics return array of Diagnostics. If '-d' is not enabled, only report semantic errors * If '-d' enabled, report both semantic and emitter errors */ function getSemanticDiagnostics(fileName: string): Diagnostic[] { @@ -3725,7 +3725,7 @@ namespace ts { * do not occur at the current position and have not otherwise been typed. */ function filterNamedImportOrExportCompletionItems(exportsOfModule: Symbol[], namedImportsOrExports: ImportOrExportSpecifier[]): Symbol[] { - const exisingImportsOrExports: Map = {}; + const existingImportsOrExports: Map = {}; for (const element of namedImportsOrExports) { // If this is the current item we are editing right now, do not filter it out @@ -3734,14 +3734,14 @@ namespace ts { } const name = element.propertyName || element.name; - exisingImportsOrExports[name.text] = true; + existingImportsOrExports[name.text] = true; } - if (isEmpty(exisingImportsOrExports)) { + if (isEmpty(existingImportsOrExports)) { return exportsOfModule; } - return filter(exportsOfModule, e => !lookUp(exisingImportsOrExports, e.name)); + return filter(exportsOfModule, e => !lookUp(existingImportsOrExports, e.name)); } /** @@ -5574,7 +5574,7 @@ namespace ts { } // If the symbol is an import we would like to find it if we are looking for what it imports. - // So consider it visibile outside its declaration scope. + // So consider it visible outside its declaration scope. if (symbol.flags & SymbolFlags.Alias) { return undefined; } @@ -5974,12 +5974,12 @@ namespace ts { // The search set contains at least the current symbol let result = [symbol]; - // If the symbol is an alias, add what it alaises to the list + // If the symbol is an alias, add what it aliases to the list if (isImportSpecifierSymbol(symbol)) { result.push(typeChecker.getAliasedSymbol(symbol)); } - // For export specifiers, the exported name can be refering to a local symbol, e.g.: + // For export specifiers, the exported name can be referring to a local symbol, e.g.: // import {a} from "mod"; // export {a as somethingElse} // We want the *local* declaration of 'a' as declared in the import, @@ -6015,7 +6015,7 @@ namespace ts { // If the symbol.valueDeclaration is a property parameter declaration, // we should include both parameter declaration symbol and property declaration symbol - // Parameter Declaration symbol is only visible within function scope, so the symbol is stored in contructor.locals. + // Parameter Declaration symbol is only visible within function scope, so the symbol is stored in constructor.locals. // Property Declaration symbol is a member of the class, so the symbol is stored in its class Declaration.symbol.members if (symbol.valueDeclaration && symbol.valueDeclaration.kind === SyntaxKind.Parameter && isParameterPropertyDeclaration(symbol.valueDeclaration)) { @@ -6041,9 +6041,9 @@ namespace ts { /** * Find symbol of the given property-name and add the symbol to the given result array * @param symbol a symbol to start searching for the given propertyName - * @param propertyName a name of property to serach for + * @param propertyName a name of property to search for * @param result an array of symbol of found property symbols - * @param previousIterationSymbolsCache a cache of symbol from previous iterations of calling this function to prevent infinite revisitng of the same symbol. + * @param previousIterationSymbolsCache a cache of symbol from previous iterations of calling this function to prevent infinite revisiting of the same symbol. * The value of previousIterationSymbol is undefined when the function is first called. */ function getPropertySymbolsFromBaseTypes(symbol: Symbol, propertyName: string, result: Symbol[], @@ -7386,12 +7386,12 @@ namespace ts { // comment portion. const singleLineCommentStart = /(?:\/\/+\s*)/.source; const multiLineCommentStart = /(?:\/\*+\s*)/.source; - const anyNumberOfSpacesAndAsterixesAtStartOfLine = /(?:^(?:\s|\*)*)/.source; + const anyNumberOfSpacesAndAsterisksAtStartOfLine = /(?:^(?:\s|\*)*)/.source; // Match any of the above three TODO comment start regexps. // Note that the outermost group *is* a capture group. We want to capture the preamble // so that we can determine the starting position of the TODO comment match. - const preamble = "(" + anyNumberOfSpacesAndAsterixesAtStartOfLine + "|" + singleLineCommentStart + "|" + multiLineCommentStart + ")"; + const preamble = "(" + anyNumberOfSpacesAndAsterisksAtStartOfLine + "|" + singleLineCommentStart + "|" + multiLineCommentStart + ")"; // Takes the descriptors and forms a regexp that matches them as if they were literals. // For example, if the descriptors are "TODO(jason)" and "HACK", then this will be: From 6f804e40efc6cdc153f9aee594382df74aa8db0c Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 5 Feb 2016 16:30:01 -0800 Subject: [PATCH 030/297] change flag name --- src/compiler/commandLineParser.ts | 2 +- src/compiler/emitter.ts | 8 ++++---- src/compiler/types.ts | 2 +- .../baselines/reference/emitNonStrictModules_amd.symbols | 5 ----- tests/baselines/reference/emitNonStrictModules_amd.types | 6 ------ .../baselines/reference/emitNonStrictModules_commonjs.js | 6 ------ .../reference/emitNonStrictModules_commonjs.symbols | 5 ----- .../reference/emitNonStrictModules_commonjs.types | 6 ------ tests/baselines/reference/emitNonStrictModules_es6.js | 6 ------ .../baselines/reference/emitNonStrictModules_es6.symbols | 5 ----- tests/baselines/reference/emitNonStrictModules_es6.types | 6 ------ .../reference/emitNonStrictModules_system.symbols | 5 ----- .../baselines/reference/emitNonStrictModules_system.types | 6 ------ .../baselines/reference/emitNonStrictModules_umd.symbols | 5 ----- tests/baselines/reference/emitNonStrictModules_umd.types | 6 ------ ...NonStrictModules_amd.js => noImplicitUseStrict_amd.js} | 4 ++-- tests/baselines/reference/noImplicitUseStrict_amd.symbols | 5 +++++ tests/baselines/reference/noImplicitUseStrict_amd.types | 6 ++++++ tests/baselines/reference/noImplicitUseStrict_commonjs.js | 6 ++++++ .../reference/noImplicitUseStrict_commonjs.symbols | 5 +++++ .../reference/noImplicitUseStrict_commonjs.types | 6 ++++++ tests/baselines/reference/noImplicitUseStrict_es6.js | 6 ++++++ tests/baselines/reference/noImplicitUseStrict_es6.symbols | 5 +++++ tests/baselines/reference/noImplicitUseStrict_es6.types | 6 ++++++ ...ictModules_system.js => noImplicitUseStrict_system.js} | 4 ++-- .../reference/noImplicitUseStrict_system.symbols | 5 +++++ .../baselines/reference/noImplicitUseStrict_system.types | 6 ++++++ ...NonStrictModules_umd.js => noImplicitUseStrict_umd.js} | 4 ++-- tests/baselines/reference/noImplicitUseStrict_umd.symbols | 5 +++++ tests/baselines/reference/noImplicitUseStrict_umd.types | 6 ++++++ ...NonStrictModules_amd.ts => noImplicitUseStrict_amd.ts} | 2 +- ...odules_commonjs.ts => noImplicitUseStrict_commonjs.ts} | 2 +- ...NonStrictModules_es6.ts => noImplicitUseStrict_es6.ts} | 2 +- ...ictModules_system.ts => noImplicitUseStrict_system.ts} | 2 +- ...NonStrictModules_umd.ts => noImplicitUseStrict_umd.ts} | 2 +- 35 files changed, 84 insertions(+), 84 deletions(-) delete mode 100644 tests/baselines/reference/emitNonStrictModules_amd.symbols delete mode 100644 tests/baselines/reference/emitNonStrictModules_amd.types delete mode 100644 tests/baselines/reference/emitNonStrictModules_commonjs.js delete mode 100644 tests/baselines/reference/emitNonStrictModules_commonjs.symbols delete mode 100644 tests/baselines/reference/emitNonStrictModules_commonjs.types delete mode 100644 tests/baselines/reference/emitNonStrictModules_es6.js delete mode 100644 tests/baselines/reference/emitNonStrictModules_es6.symbols delete mode 100644 tests/baselines/reference/emitNonStrictModules_es6.types delete mode 100644 tests/baselines/reference/emitNonStrictModules_system.symbols delete mode 100644 tests/baselines/reference/emitNonStrictModules_system.types delete mode 100644 tests/baselines/reference/emitNonStrictModules_umd.symbols delete mode 100644 tests/baselines/reference/emitNonStrictModules_umd.types rename tests/baselines/reference/{emitNonStrictModules_amd.js => noImplicitUseStrict_amd.js} (57%) create mode 100644 tests/baselines/reference/noImplicitUseStrict_amd.symbols create mode 100644 tests/baselines/reference/noImplicitUseStrict_amd.types create mode 100644 tests/baselines/reference/noImplicitUseStrict_commonjs.js create mode 100644 tests/baselines/reference/noImplicitUseStrict_commonjs.symbols create mode 100644 tests/baselines/reference/noImplicitUseStrict_commonjs.types create mode 100644 tests/baselines/reference/noImplicitUseStrict_es6.js create mode 100644 tests/baselines/reference/noImplicitUseStrict_es6.symbols create mode 100644 tests/baselines/reference/noImplicitUseStrict_es6.types rename tests/baselines/reference/{emitNonStrictModules_system.js => noImplicitUseStrict_system.js} (73%) create mode 100644 tests/baselines/reference/noImplicitUseStrict_system.symbols create mode 100644 tests/baselines/reference/noImplicitUseStrict_system.types rename tests/baselines/reference/{emitNonStrictModules_umd.js => noImplicitUseStrict_umd.js} (81%) create mode 100644 tests/baselines/reference/noImplicitUseStrict_umd.symbols create mode 100644 tests/baselines/reference/noImplicitUseStrict_umd.types rename tests/cases/compiler/{emitNonStrictModules_amd.ts => noImplicitUseStrict_amd.ts} (50%) rename tests/cases/compiler/{emitNonStrictModules_commonjs.ts => noImplicitUseStrict_commonjs.ts} (53%) rename tests/cases/compiler/{emitNonStrictModules_es6.ts => noImplicitUseStrict_es6.ts} (58%) rename tests/cases/compiler/{emitNonStrictModules_system.ts => noImplicitUseStrict_system.ts} (52%) rename tests/cases/compiler/{emitNonStrictModules_umd.ts => noImplicitUseStrict_umd.ts} (50%) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 957b38c67de..065fb3a9737 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -322,7 +322,7 @@ namespace ts { description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking }, { - name: "emitNonStrictModules", + name: "noImplicitUseStrict", type: "boolean", description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 15edb022b11..7d602c58400 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -7179,7 +7179,7 @@ const _super = (function (geti, seti) { write(`], function(${exportFunctionForFile}, ${contextObjectForFile}) {`); writeLine(); increaseIndent(); - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.emitNonStrictModules); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict); writeLine(); write(`var __moduleName = ${contextObjectForFile} && ${contextObjectForFile}.id;`); writeLine(); @@ -7285,7 +7285,7 @@ const _super = (function (geti, seti) { writeModuleName(node, emitRelativePathAsModuleName); emitAMDDependencies(node, /*includeNonAmdDependencies*/ true, emitRelativePathAsModuleName); increaseIndent(); - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/!compilerOptions.emitNonStrictModules); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/!compilerOptions.noImplicitUseStrict); emitExportStarHelper(); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); @@ -7297,7 +7297,7 @@ const _super = (function (geti, seti) { } function emitCommonJSModule(node: SourceFile) { - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ !compilerOptions.emitNonStrictModules); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict); emitEmitHelpers(node); collectExternalModuleInfo(node); emitExportStarHelper(); @@ -7326,7 +7326,7 @@ const _super = (function (geti, seti) { })(`); emitAMDFactoryHeader(dependencyNames); increaseIndent(); - const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.emitNonStrictModules); + const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict); emitExportStarHelper(); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 90a6a9a6752..1b992bb11ef 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2422,7 +2422,7 @@ namespace ts { traceModuleResolution?: boolean; allowSyntheticDefaultImports?: boolean; allowJs?: boolean; - emitNonStrictModules?: boolean; + noImplicitUseStrict?: boolean; /* @internal */ stripInternal?: boolean; // Skip checking lib.d.ts to help speed up tests. diff --git a/tests/baselines/reference/emitNonStrictModules_amd.symbols b/tests/baselines/reference/emitNonStrictModules_amd.symbols deleted file mode 100644 index 1590ea05ad4..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_amd.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/emitNonStrictModules_amd.ts === - -export var x = 0; ->x : Symbol(x, Decl(emitNonStrictModules_amd.ts, 1, 10)) - diff --git a/tests/baselines/reference/emitNonStrictModules_amd.types b/tests/baselines/reference/emitNonStrictModules_amd.types deleted file mode 100644 index 650df648d8d..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_amd.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/emitNonStrictModules_amd.ts === - -export var x = 0; ->x : number ->0 : number - diff --git a/tests/baselines/reference/emitNonStrictModules_commonjs.js b/tests/baselines/reference/emitNonStrictModules_commonjs.js deleted file mode 100644 index 7a2d0720015..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_commonjs.js +++ /dev/null @@ -1,6 +0,0 @@ -//// [emitNonStrictModules_commonjs.ts] - -export var x = 0; - -//// [emitNonStrictModules_commonjs.js] -exports.x = 0; diff --git a/tests/baselines/reference/emitNonStrictModules_commonjs.symbols b/tests/baselines/reference/emitNonStrictModules_commonjs.symbols deleted file mode 100644 index 36b487f34d1..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_commonjs.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/emitNonStrictModules_commonjs.ts === - -export var x = 0; ->x : Symbol(x, Decl(emitNonStrictModules_commonjs.ts, 1, 10)) - diff --git a/tests/baselines/reference/emitNonStrictModules_commonjs.types b/tests/baselines/reference/emitNonStrictModules_commonjs.types deleted file mode 100644 index f8a24d53641..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_commonjs.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/emitNonStrictModules_commonjs.ts === - -export var x = 0; ->x : number ->0 : number - diff --git a/tests/baselines/reference/emitNonStrictModules_es6.js b/tests/baselines/reference/emitNonStrictModules_es6.js deleted file mode 100644 index 535afff7730..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_es6.js +++ /dev/null @@ -1,6 +0,0 @@ -//// [emitNonStrictModules_es6.ts] - -export var x = 0; - -//// [emitNonStrictModules_es6.js] -export var x = 0; diff --git a/tests/baselines/reference/emitNonStrictModules_es6.symbols b/tests/baselines/reference/emitNonStrictModules_es6.symbols deleted file mode 100644 index 884189014b0..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_es6.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/emitNonStrictModules_es6.ts === - -export var x = 0; ->x : Symbol(x, Decl(emitNonStrictModules_es6.ts, 1, 10)) - diff --git a/tests/baselines/reference/emitNonStrictModules_es6.types b/tests/baselines/reference/emitNonStrictModules_es6.types deleted file mode 100644 index f3208e247da..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_es6.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/emitNonStrictModules_es6.ts === - -export var x = 0; ->x : number ->0 : number - diff --git a/tests/baselines/reference/emitNonStrictModules_system.symbols b/tests/baselines/reference/emitNonStrictModules_system.symbols deleted file mode 100644 index b772eafe447..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_system.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/emitNonStrictModules_system.ts === - -export var x = 0; ->x : Symbol(x, Decl(emitNonStrictModules_system.ts, 1, 10)) - diff --git a/tests/baselines/reference/emitNonStrictModules_system.types b/tests/baselines/reference/emitNonStrictModules_system.types deleted file mode 100644 index 352381db379..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_system.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/emitNonStrictModules_system.ts === - -export var x = 0; ->x : number ->0 : number - diff --git a/tests/baselines/reference/emitNonStrictModules_umd.symbols b/tests/baselines/reference/emitNonStrictModules_umd.symbols deleted file mode 100644 index 23af4139243..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_umd.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/emitNonStrictModules_umd.ts === - -export var x = 0; ->x : Symbol(x, Decl(emitNonStrictModules_umd.ts, 1, 10)) - diff --git a/tests/baselines/reference/emitNonStrictModules_umd.types b/tests/baselines/reference/emitNonStrictModules_umd.types deleted file mode 100644 index 83c55b1d4cd..00000000000 --- a/tests/baselines/reference/emitNonStrictModules_umd.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/emitNonStrictModules_umd.ts === - -export var x = 0; ->x : number ->0 : number - diff --git a/tests/baselines/reference/emitNonStrictModules_amd.js b/tests/baselines/reference/noImplicitUseStrict_amd.js similarity index 57% rename from tests/baselines/reference/emitNonStrictModules_amd.js rename to tests/baselines/reference/noImplicitUseStrict_amd.js index f2a746280ac..ac15f548c47 100644 --- a/tests/baselines/reference/emitNonStrictModules_amd.js +++ b/tests/baselines/reference/noImplicitUseStrict_amd.js @@ -1,8 +1,8 @@ -//// [emitNonStrictModules_amd.ts] +//// [noImplicitUseStrict_amd.ts] export var x = 0; -//// [emitNonStrictModules_amd.js] +//// [noImplicitUseStrict_amd.js] define(["require", "exports"], function (require, exports) { exports.x = 0; }); diff --git a/tests/baselines/reference/noImplicitUseStrict_amd.symbols b/tests/baselines/reference/noImplicitUseStrict_amd.symbols new file mode 100644 index 00000000000..de1faa2213c --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_amd.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/noImplicitUseStrict_amd.ts === + +export var x = 0; +>x : Symbol(x, Decl(noImplicitUseStrict_amd.ts, 1, 10)) + diff --git a/tests/baselines/reference/noImplicitUseStrict_amd.types b/tests/baselines/reference/noImplicitUseStrict_amd.types new file mode 100644 index 00000000000..c9e1b5749dc --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_amd.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/noImplicitUseStrict_amd.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/noImplicitUseStrict_commonjs.js b/tests/baselines/reference/noImplicitUseStrict_commonjs.js new file mode 100644 index 00000000000..9c726938f04 --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_commonjs.js @@ -0,0 +1,6 @@ +//// [noImplicitUseStrict_commonjs.ts] + +export var x = 0; + +//// [noImplicitUseStrict_commonjs.js] +exports.x = 0; diff --git a/tests/baselines/reference/noImplicitUseStrict_commonjs.symbols b/tests/baselines/reference/noImplicitUseStrict_commonjs.symbols new file mode 100644 index 00000000000..af53dc272d2 --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_commonjs.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/noImplicitUseStrict_commonjs.ts === + +export var x = 0; +>x : Symbol(x, Decl(noImplicitUseStrict_commonjs.ts, 1, 10)) + diff --git a/tests/baselines/reference/noImplicitUseStrict_commonjs.types b/tests/baselines/reference/noImplicitUseStrict_commonjs.types new file mode 100644 index 00000000000..9999d3b94ba --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_commonjs.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/noImplicitUseStrict_commonjs.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/noImplicitUseStrict_es6.js b/tests/baselines/reference/noImplicitUseStrict_es6.js new file mode 100644 index 00000000000..27dbbc7ea79 --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_es6.js @@ -0,0 +1,6 @@ +//// [noImplicitUseStrict_es6.ts] + +export var x = 0; + +//// [noImplicitUseStrict_es6.js] +export var x = 0; diff --git a/tests/baselines/reference/noImplicitUseStrict_es6.symbols b/tests/baselines/reference/noImplicitUseStrict_es6.symbols new file mode 100644 index 00000000000..31bc1904ff9 --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_es6.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/noImplicitUseStrict_es6.ts === + +export var x = 0; +>x : Symbol(x, Decl(noImplicitUseStrict_es6.ts, 1, 10)) + diff --git a/tests/baselines/reference/noImplicitUseStrict_es6.types b/tests/baselines/reference/noImplicitUseStrict_es6.types new file mode 100644 index 00000000000..838c7316be0 --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_es6.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/noImplicitUseStrict_es6.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/emitNonStrictModules_system.js b/tests/baselines/reference/noImplicitUseStrict_system.js similarity index 73% rename from tests/baselines/reference/emitNonStrictModules_system.js rename to tests/baselines/reference/noImplicitUseStrict_system.js index f1ad93f0009..cf5a7e1b261 100644 --- a/tests/baselines/reference/emitNonStrictModules_system.js +++ b/tests/baselines/reference/noImplicitUseStrict_system.js @@ -1,8 +1,8 @@ -//// [emitNonStrictModules_system.ts] +//// [noImplicitUseStrict_system.ts] export var x = 0; -//// [emitNonStrictModules_system.js] +//// [noImplicitUseStrict_system.js] System.register([], function(exports_1, context_1) { var __moduleName = context_1 && context_1.id; var x; diff --git a/tests/baselines/reference/noImplicitUseStrict_system.symbols b/tests/baselines/reference/noImplicitUseStrict_system.symbols new file mode 100644 index 00000000000..62b89a6593d --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_system.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/noImplicitUseStrict_system.ts === + +export var x = 0; +>x : Symbol(x, Decl(noImplicitUseStrict_system.ts, 1, 10)) + diff --git a/tests/baselines/reference/noImplicitUseStrict_system.types b/tests/baselines/reference/noImplicitUseStrict_system.types new file mode 100644 index 00000000000..1da563f938b --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_system.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/noImplicitUseStrict_system.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/baselines/reference/emitNonStrictModules_umd.js b/tests/baselines/reference/noImplicitUseStrict_umd.js similarity index 81% rename from tests/baselines/reference/emitNonStrictModules_umd.js rename to tests/baselines/reference/noImplicitUseStrict_umd.js index c1ee0c048c5..ca252daeb9d 100644 --- a/tests/baselines/reference/emitNonStrictModules_umd.js +++ b/tests/baselines/reference/noImplicitUseStrict_umd.js @@ -1,8 +1,8 @@ -//// [emitNonStrictModules_umd.ts] +//// [noImplicitUseStrict_umd.ts] export var x = 0; -//// [emitNonStrictModules_umd.js] +//// [noImplicitUseStrict_umd.js] (function (factory) { if (typeof module === 'object' && typeof module.exports === 'object') { var v = factory(require, exports); if (v !== undefined) module.exports = v; diff --git a/tests/baselines/reference/noImplicitUseStrict_umd.symbols b/tests/baselines/reference/noImplicitUseStrict_umd.symbols new file mode 100644 index 00000000000..a72a251ad09 --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_umd.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/noImplicitUseStrict_umd.ts === + +export var x = 0; +>x : Symbol(x, Decl(noImplicitUseStrict_umd.ts, 1, 10)) + diff --git a/tests/baselines/reference/noImplicitUseStrict_umd.types b/tests/baselines/reference/noImplicitUseStrict_umd.types new file mode 100644 index 00000000000..6a3fd6ece77 --- /dev/null +++ b/tests/baselines/reference/noImplicitUseStrict_umd.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/noImplicitUseStrict_umd.ts === + +export var x = 0; +>x : number +>0 : number + diff --git a/tests/cases/compiler/emitNonStrictModules_amd.ts b/tests/cases/compiler/noImplicitUseStrict_amd.ts similarity index 50% rename from tests/cases/compiler/emitNonStrictModules_amd.ts rename to tests/cases/compiler/noImplicitUseStrict_amd.ts index 217e23d91a3..3a2a4760221 100644 --- a/tests/cases/compiler/emitNonStrictModules_amd.ts +++ b/tests/cases/compiler/noImplicitUseStrict_amd.ts @@ -1,4 +1,4 @@ // @module: amd -// @emitNonStrictModules: true +// @noImplicitUseStrict: true export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitNonStrictModules_commonjs.ts b/tests/cases/compiler/noImplicitUseStrict_commonjs.ts similarity index 53% rename from tests/cases/compiler/emitNonStrictModules_commonjs.ts rename to tests/cases/compiler/noImplicitUseStrict_commonjs.ts index 3d29c30176f..f8377dba07a 100644 --- a/tests/cases/compiler/emitNonStrictModules_commonjs.ts +++ b/tests/cases/compiler/noImplicitUseStrict_commonjs.ts @@ -1,4 +1,4 @@ // @module: commonjs -// @emitNonStrictModules: true +// @noImplicitUseStrict: true export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitNonStrictModules_es6.ts b/tests/cases/compiler/noImplicitUseStrict_es6.ts similarity index 58% rename from tests/cases/compiler/emitNonStrictModules_es6.ts rename to tests/cases/compiler/noImplicitUseStrict_es6.ts index 426c5aff533..f56b0fd9021 100644 --- a/tests/cases/compiler/emitNonStrictModules_es6.ts +++ b/tests/cases/compiler/noImplicitUseStrict_es6.ts @@ -1,5 +1,5 @@ // @module: es6 // @target: es6 -// @emitNonStrictModules: true +// @noImplicitUseStrict: true export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitNonStrictModules_system.ts b/tests/cases/compiler/noImplicitUseStrict_system.ts similarity index 52% rename from tests/cases/compiler/emitNonStrictModules_system.ts rename to tests/cases/compiler/noImplicitUseStrict_system.ts index 23801462b71..37ff5de469d 100644 --- a/tests/cases/compiler/emitNonStrictModules_system.ts +++ b/tests/cases/compiler/noImplicitUseStrict_system.ts @@ -1,4 +1,4 @@ // @module: system -// @emitNonStrictModules: true +// @noImplicitUseStrict: true export var x = 0; \ No newline at end of file diff --git a/tests/cases/compiler/emitNonStrictModules_umd.ts b/tests/cases/compiler/noImplicitUseStrict_umd.ts similarity index 50% rename from tests/cases/compiler/emitNonStrictModules_umd.ts rename to tests/cases/compiler/noImplicitUseStrict_umd.ts index 1166f512cf2..f26f2ee2aff 100644 --- a/tests/cases/compiler/emitNonStrictModules_umd.ts +++ b/tests/cases/compiler/noImplicitUseStrict_umd.ts @@ -1,4 +1,4 @@ // @module: umd -// @emitNonStrictModules: true +// @noImplicitUseStrict: true export var x = 0; \ No newline at end of file From b9e26e7649f73fa449e4339eb12402d5d8e87def Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 6 Feb 2016 08:37:09 -0800 Subject: [PATCH 031/297] Correct handling of intersection types in allConstituentTypesHaveKind --- src/compiler/checker.ts | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 65cb3df785f..6fd464c38bc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10337,9 +10337,8 @@ namespace ts { const widenedType = getWidenedType(exprType); // Permit 'number[] | "foo"' to be asserted to 'string'. - const bothAreStringLike = - someConstituentTypeHasKind(targetType, TypeFlags.StringLike) && - someConstituentTypeHasKind(widenedType, TypeFlags.StringLike); + const bothAreStringLike = someConstituentTypeHasKind(targetType, TypeFlags.StringLike) && + someConstituentTypeHasKind(widenedType, TypeFlags.StringLike); if (!bothAreStringLike && !(isTypeAssignableTo(targetType, widenedType))) { checkTypeAssignableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); } @@ -10594,7 +10593,7 @@ namespace ts { } // Functions with with an explicitly specified 'void' or 'any' return type don't need any return expressions. - if (returnType === voidType || isTypeAny(returnType) || (returnType && (returnType.flags & TypeFlags.Union) && someConstituentTypeHasKind(returnType, TypeFlags.Any | TypeFlags.Void))) { + if (returnType && someConstituentTypeHasKind(returnType, TypeFlags.Any | TypeFlags.Void)) { return; } @@ -10882,38 +10881,47 @@ namespace ts { return numberType; } - // Just like isTypeOfKind below, except that it returns true if *any* constituent - // has this kind. + // Return true if type might be of the given kind. A union or intersection type might be of a given + // kind if at least one constituent type is of the given kind. function someConstituentTypeHasKind(type: Type, kind: TypeFlags): boolean { if (type.flags & kind) { return true; } if (type.flags & TypeFlags.UnionOrIntersection) { const types = (type).types; - for (const current of types) { - if (current.flags & kind) { + for (const t of types) { + if (someConstituentTypeHasKind(t, kind)) { return true; } } - return false; } return false; } - // Return true if type has the given flags, or is a union or intersection type composed of types that all have those flags. + // Return true if type is of the given kind. A union type is of a given kind if all constituent types + // are of the given kind. An intersection type is of a given kind if at least one constituent type is + // of the given kind. function allConstituentTypesHaveKind(type: Type, kind: TypeFlags): boolean { if (type.flags & kind) { return true; } - if (type.flags & TypeFlags.UnionOrIntersection) { + if (type.flags & TypeFlags.Union) { const types = (type).types; - for (const current of types) { - if (!(current.flags & kind)) { + for (const t of types) { + if (!allConstituentTypesHaveKind(t, kind)) { return false; } } return true; } + if (type.flags & TypeFlags.Intersection) { + const types = (type).types; + for (const t of types) { + if (allConstituentTypesHaveKind(t, kind)) { + return true; + } + } + } return false; } From 6f85e13c72763443d758a1f473fcc49796472e0a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 6 Feb 2016 08:39:31 -0800 Subject: [PATCH 032/297] Rename allConstituentTypesHaveKind/someConstituentTypeHasKind to isTypeOfKind/maybeTypeOfKind --- src/compiler/checker.ts | 52 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6fd464c38bc..22280a05725 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5591,7 +5591,7 @@ namespace ts { } function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean { - if (!(target.flags & TypeFlags.ObjectLiteralPatternWithComputedProperties) && someConstituentTypeHasKind(target, TypeFlags.ObjectType)) { + if (!(target.flags & TypeFlags.ObjectLiteralPatternWithComputedProperties) && maybeTypeOfKind(target, TypeFlags.ObjectType)) { for (const prop of getPropertiesOfObjectType(source)) { if (!isKnownProperty(target, prop.name)) { if (reportErrors) { @@ -8178,7 +8178,7 @@ namespace ts { } function isTypeAnyOrAllConstituentTypesHaveKind(type: Type, kind: TypeFlags): boolean { - return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); + return isTypeAny(type) || isTypeOfKind(type, kind); } function isNumericLiteralName(name: string) { @@ -9684,7 +9684,7 @@ namespace ts { case SyntaxKind.ComputedPropertyName: const nameType = checkComputedPropertyName(element.name); - if (allConstituentTypesHaveKind(nameType, TypeFlags.ESSymbol)) { + if (isTypeOfKind(nameType, TypeFlags.ESSymbol)) { return nameType; } else { @@ -10337,8 +10337,8 @@ namespace ts { const widenedType = getWidenedType(exprType); // Permit 'number[] | "foo"' to be asserted to 'string'. - const bothAreStringLike = someConstituentTypeHasKind(targetType, TypeFlags.StringLike) && - someConstituentTypeHasKind(widenedType, TypeFlags.StringLike); + const bothAreStringLike = maybeTypeOfKind(targetType, TypeFlags.StringLike) && + maybeTypeOfKind(widenedType, TypeFlags.StringLike); if (!bothAreStringLike && !(isTypeAssignableTo(targetType, widenedType))) { checkTypeAssignableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); } @@ -10593,7 +10593,7 @@ namespace ts { } // Functions with with an explicitly specified 'void' or 'any' return type don't need any return expressions. - if (returnType && someConstituentTypeHasKind(returnType, TypeFlags.Any | TypeFlags.Void)) { + if (returnType && maybeTypeOfKind(returnType, TypeFlags.Any | TypeFlags.Void)) { return; } @@ -10849,7 +10849,7 @@ namespace ts { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: case SyntaxKind.TildeToken: - if (someConstituentTypeHasKind(operandType, TypeFlags.ESSymbol)) { + if (maybeTypeOfKind(operandType, TypeFlags.ESSymbol)) { error(node.operand, Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, tokenToString(node.operator)); } return numberType; @@ -10883,14 +10883,14 @@ namespace ts { // Return true if type might be of the given kind. A union or intersection type might be of a given // kind if at least one constituent type is of the given kind. - function someConstituentTypeHasKind(type: Type, kind: TypeFlags): boolean { + function maybeTypeOfKind(type: Type, kind: TypeFlags): boolean { if (type.flags & kind) { return true; } if (type.flags & TypeFlags.UnionOrIntersection) { const types = (type).types; for (const t of types) { - if (someConstituentTypeHasKind(t, kind)) { + if (maybeTypeOfKind(t, kind)) { return true; } } @@ -10901,14 +10901,14 @@ namespace ts { // Return true if type is of the given kind. A union type is of a given kind if all constituent types // are of the given kind. An intersection type is of a given kind if at least one constituent type is // of the given kind. - function allConstituentTypesHaveKind(type: Type, kind: TypeFlags): boolean { + function isTypeOfKind(type: Type, kind: TypeFlags): boolean { if (type.flags & kind) { return true; } if (type.flags & TypeFlags.Union) { const types = (type).types; for (const t of types) { - if (!allConstituentTypesHaveKind(t, kind)) { + if (!isTypeOfKind(t, kind)) { return false; } } @@ -10917,7 +10917,7 @@ namespace ts { if (type.flags & TypeFlags.Intersection) { const types = (type).types; for (const t of types) { - if (allConstituentTypesHaveKind(t, kind)) { + if (isTypeOfKind(t, kind)) { return true; } } @@ -10939,7 +10939,7 @@ namespace ts { // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (allConstituentTypesHaveKind(leftType, TypeFlags.Primitive)) { + if (isTypeOfKind(leftType, TypeFlags.Primitive)) { error(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported @@ -11154,13 +11154,13 @@ namespace ts { if (rightType.flags & (TypeFlags.Undefined | TypeFlags.Null)) rightType = leftType; let resultType: Type; - if (allConstituentTypesHaveKind(leftType, TypeFlags.NumberLike) && allConstituentTypesHaveKind(rightType, TypeFlags.NumberLike)) { + if (isTypeOfKind(leftType, TypeFlags.NumberLike) && isTypeOfKind(rightType, TypeFlags.NumberLike)) { // Operands of an enum type are treated as having the primitive type Number. // If both operands are of the Number primitive type, the result is of the Number primitive type. resultType = numberType; } else { - if (allConstituentTypesHaveKind(leftType, TypeFlags.StringLike) || allConstituentTypesHaveKind(rightType, TypeFlags.StringLike)) { + if (isTypeOfKind(leftType, TypeFlags.StringLike) || isTypeOfKind(rightType, TypeFlags.StringLike)) { // If one or both operands are of the String primitive type, the result is of the String primitive type. resultType = stringType; } @@ -11198,7 +11198,7 @@ namespace ts { case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: // Permit 'number[] | "foo"' to be asserted to 'string'. - if (someConstituentTypeHasKind(leftType, TypeFlags.StringLike) && someConstituentTypeHasKind(rightType, TypeFlags.StringLike)) { + if (maybeTypeOfKind(leftType, TypeFlags.StringLike) && maybeTypeOfKind(rightType, TypeFlags.StringLike)) { return booleanType; } if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { @@ -11223,8 +11223,8 @@ namespace ts { // Return true if there was no error, false if there was an error. function checkForDisallowedESSymbolOperand(operator: SyntaxKind): boolean { const offendingSymbolOperand = - someConstituentTypeHasKind(leftType, TypeFlags.ESSymbol) ? left : - someConstituentTypeHasKind(rightType, TypeFlags.ESSymbol) ? right : + maybeTypeOfKind(leftType, TypeFlags.ESSymbol) ? left : + maybeTypeOfKind(rightType, TypeFlags.ESSymbol) ? right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, tokenToString(operator)); @@ -13712,7 +13712,7 @@ namespace ts { let hasDuplicateDefaultClause = false; const expressionType = checkExpression(node.expression); - const expressionTypeIsStringLike = someConstituentTypeHasKind(expressionType, TypeFlags.StringLike); + const expressionTypeIsStringLike = maybeTypeOfKind(expressionType, TypeFlags.StringLike); forEach(node.caseBlock.clauses, clause => { // Grammar check for duplicate default clauses, skip if we already report duplicate default clause if (clause.kind === SyntaxKind.DefaultClause && !hasDuplicateDefaultClause) { @@ -13736,7 +13736,7 @@ namespace ts { const expressionTypeIsAssignableToCaseType = // Permit 'number[] | "foo"' to be asserted to 'string'. - (expressionTypeIsStringLike && someConstituentTypeHasKind(caseType, TypeFlags.StringLike)) || + (expressionTypeIsStringLike && maybeTypeOfKind(caseType, TypeFlags.StringLike)) || isTypeAssignableTo(expressionType, caseType); if (!expressionTypeIsAssignableToCaseType) { @@ -15942,22 +15942,22 @@ namespace ts { else if (type.flags & TypeFlags.Any) { return TypeReferenceSerializationKind.ObjectType; } - else if (allConstituentTypesHaveKind(type, TypeFlags.Void)) { + else if (isTypeOfKind(type, TypeFlags.Void)) { return TypeReferenceSerializationKind.VoidType; } - else if (allConstituentTypesHaveKind(type, TypeFlags.Boolean)) { + else if (isTypeOfKind(type, TypeFlags.Boolean)) { return TypeReferenceSerializationKind.BooleanType; } - else if (allConstituentTypesHaveKind(type, TypeFlags.NumberLike)) { + else if (isTypeOfKind(type, TypeFlags.NumberLike)) { return TypeReferenceSerializationKind.NumberLikeType; } - else if (allConstituentTypesHaveKind(type, TypeFlags.StringLike)) { + else if (isTypeOfKind(type, TypeFlags.StringLike)) { return TypeReferenceSerializationKind.StringLikeType; } - else if (allConstituentTypesHaveKind(type, TypeFlags.Tuple)) { + else if (isTypeOfKind(type, TypeFlags.Tuple)) { return TypeReferenceSerializationKind.ArrayLikeType; } - else if (allConstituentTypesHaveKind(type, TypeFlags.ESSymbol)) { + else if (isTypeOfKind(type, TypeFlags.ESSymbol)) { return TypeReferenceSerializationKind.ESSymbolType; } else if (isFunctionType(type)) { From 45409982895306bf78e598604b7bc80ffa6f0ea8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 6 Feb 2016 15:33:56 -0800 Subject: [PATCH 033/297] Adding test --- .../operatorsAndIntersectionTypes.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts diff --git a/tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts b/tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts new file mode 100644 index 00000000000..5689d221840 --- /dev/null +++ b/tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts @@ -0,0 +1,30 @@ +type Guid = string & { $Guid }; // Tagged string type +type SerialNo = number & { $SerialNo }; // Tagged number type + +function createGuid() { + return "21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid; +} + +function createSerialNo() { + return 12345 as SerialNo; +} + +let map1: { [x: string]: number } = {}; +let guid = createGuid(); +map1[guid] = 123; // Can with tagged string + +let map2: { [x: number]: string } = {}; +let serialNo = createSerialNo(); +map2[serialNo] = "hello"; // Can index with tagged number + +const s1 = "{" + guid + "}"; +const s2 = guid.toLowerCase(); +const s3 = guid + guid; +const s4 = guid + serialNo; +const s5 = serialNo.toPrecision(0); +const n1 = serialNo * 3; +const n2 = serialNo + serialNo; +const b1 = guid === ""; +const b2 = guid === guid; +const b3 = serialNo === 0; +const b4 = serialNo === serialNo; From 788ba3c6ac01141e264e4ccbf780ac624a46d928 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 6 Feb 2016 15:34:32 -0800 Subject: [PATCH 034/297] Accepting new baselines --- .../operatorsAndIntersectionTypes.js | 57 ++++++++ .../operatorsAndIntersectionTypes.symbols | 100 +++++++++++++ .../operatorsAndIntersectionTypes.types | 132 ++++++++++++++++++ 3 files changed, 289 insertions(+) create mode 100644 tests/baselines/reference/operatorsAndIntersectionTypes.js create mode 100644 tests/baselines/reference/operatorsAndIntersectionTypes.symbols create mode 100644 tests/baselines/reference/operatorsAndIntersectionTypes.types diff --git a/tests/baselines/reference/operatorsAndIntersectionTypes.js b/tests/baselines/reference/operatorsAndIntersectionTypes.js new file mode 100644 index 00000000000..6f5b3d329d1 --- /dev/null +++ b/tests/baselines/reference/operatorsAndIntersectionTypes.js @@ -0,0 +1,57 @@ +//// [operatorsAndIntersectionTypes.ts] +type Guid = string & { $Guid }; // Tagged string type +type SerialNo = number & { $SerialNo }; // Tagged number type + +function createGuid() { + return "21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid; +} + +function createSerialNo() { + return 12345 as SerialNo; +} + +let map1: { [x: string]: number } = {}; +let guid = createGuid(); +map1[guid] = 123; // Can with tagged string + +let map2: { [x: number]: string } = {}; +let serialNo = createSerialNo(); +map2[serialNo] = "hello"; // Can index with tagged number + +const s1 = "{" + guid + "}"; +const s2 = guid.toLowerCase(); +const s3 = guid + guid; +const s4 = guid + serialNo; +const s5 = serialNo.toPrecision(0); +const n1 = serialNo * 3; +const n2 = serialNo + serialNo; +const b1 = guid === ""; +const b2 = guid === guid; +const b3 = serialNo === 0; +const b4 = serialNo === serialNo; + + +//// [operatorsAndIntersectionTypes.js] +function createGuid() { + return "21EC2020-3AEA-4069-A2DD-08002B30309D"; +} +function createSerialNo() { + return 12345; +} +var map1 = {}; +var guid = createGuid(); +map1[guid] = 123; // Can with tagged string +var map2 = {}; +var serialNo = createSerialNo(); +map2[serialNo] = "hello"; // Can index with tagged number +var s1 = "{" + guid + "}"; +var s2 = guid.toLowerCase(); +var s3 = guid + guid; +var s4 = guid + serialNo; +var s5 = serialNo.toPrecision(0); +var n1 = serialNo * 3; +var n2 = serialNo + serialNo; +var b1 = guid === ""; +var b2 = guid === guid; +var b3 = serialNo === 0; +var b4 = serialNo === serialNo; diff --git a/tests/baselines/reference/operatorsAndIntersectionTypes.symbols b/tests/baselines/reference/operatorsAndIntersectionTypes.symbols new file mode 100644 index 00000000000..7ffc093e4af --- /dev/null +++ b/tests/baselines/reference/operatorsAndIntersectionTypes.symbols @@ -0,0 +1,100 @@ +=== tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts === +type Guid = string & { $Guid }; // Tagged string type +>Guid : Symbol(Guid, Decl(operatorsAndIntersectionTypes.ts, 0, 0)) +>$Guid : Symbol($Guid, Decl(operatorsAndIntersectionTypes.ts, 0, 22)) + +type SerialNo = number & { $SerialNo }; // Tagged number type +>SerialNo : Symbol(SerialNo, Decl(operatorsAndIntersectionTypes.ts, 0, 31)) +>$SerialNo : Symbol($SerialNo, Decl(operatorsAndIntersectionTypes.ts, 1, 26)) + +function createGuid() { +>createGuid : Symbol(createGuid, Decl(operatorsAndIntersectionTypes.ts, 1, 39)) + + return "21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid; +>Guid : Symbol(Guid, Decl(operatorsAndIntersectionTypes.ts, 0, 0)) +} + +function createSerialNo() { +>createSerialNo : Symbol(createSerialNo, Decl(operatorsAndIntersectionTypes.ts, 5, 1)) + + return 12345 as SerialNo; +>SerialNo : Symbol(SerialNo, Decl(operatorsAndIntersectionTypes.ts, 0, 31)) +} + +let map1: { [x: string]: number } = {}; +>map1 : Symbol(map1, Decl(operatorsAndIntersectionTypes.ts, 11, 3)) +>x : Symbol(x, Decl(operatorsAndIntersectionTypes.ts, 11, 13)) + +let guid = createGuid(); +>guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) +>createGuid : Symbol(createGuid, Decl(operatorsAndIntersectionTypes.ts, 1, 39)) + +map1[guid] = 123; // Can with tagged string +>map1 : Symbol(map1, Decl(operatorsAndIntersectionTypes.ts, 11, 3)) +>guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) + +let map2: { [x: number]: string } = {}; +>map2 : Symbol(map2, Decl(operatorsAndIntersectionTypes.ts, 15, 3)) +>x : Symbol(x, Decl(operatorsAndIntersectionTypes.ts, 15, 13)) + +let serialNo = createSerialNo(); +>serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) +>createSerialNo : Symbol(createSerialNo, Decl(operatorsAndIntersectionTypes.ts, 5, 1)) + +map2[serialNo] = "hello"; // Can index with tagged number +>map2 : Symbol(map2, Decl(operatorsAndIntersectionTypes.ts, 15, 3)) +>serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) + +const s1 = "{" + guid + "}"; +>s1 : Symbol(s1, Decl(operatorsAndIntersectionTypes.ts, 19, 5)) +>guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) + +const s2 = guid.toLowerCase(); +>s2 : Symbol(s2, Decl(operatorsAndIntersectionTypes.ts, 20, 5)) +>guid.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + +const s3 = guid + guid; +>s3 : Symbol(s3, Decl(operatorsAndIntersectionTypes.ts, 21, 5)) +>guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) +>guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) + +const s4 = guid + serialNo; +>s4 : Symbol(s4, Decl(operatorsAndIntersectionTypes.ts, 22, 5)) +>guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) +>serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) + +const s5 = serialNo.toPrecision(0); +>s5 : Symbol(s5, Decl(operatorsAndIntersectionTypes.ts, 23, 5)) +>serialNo.toPrecision : Symbol(Number.toPrecision, Decl(lib.d.ts, --, --)) +>serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) +>toPrecision : Symbol(Number.toPrecision, Decl(lib.d.ts, --, --)) + +const n1 = serialNo * 3; +>n1 : Symbol(n1, Decl(operatorsAndIntersectionTypes.ts, 24, 5)) +>serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) + +const n2 = serialNo + serialNo; +>n2 : Symbol(n2, Decl(operatorsAndIntersectionTypes.ts, 25, 5)) +>serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) +>serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) + +const b1 = guid === ""; +>b1 : Symbol(b1, Decl(operatorsAndIntersectionTypes.ts, 26, 5)) +>guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) + +const b2 = guid === guid; +>b2 : Symbol(b2, Decl(operatorsAndIntersectionTypes.ts, 27, 5)) +>guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) +>guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) + +const b3 = serialNo === 0; +>b3 : Symbol(b3, Decl(operatorsAndIntersectionTypes.ts, 28, 5)) +>serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) + +const b4 = serialNo === serialNo; +>b4 : Symbol(b4, Decl(operatorsAndIntersectionTypes.ts, 29, 5)) +>serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) +>serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) + diff --git a/tests/baselines/reference/operatorsAndIntersectionTypes.types b/tests/baselines/reference/operatorsAndIntersectionTypes.types new file mode 100644 index 00000000000..70611776fc1 --- /dev/null +++ b/tests/baselines/reference/operatorsAndIntersectionTypes.types @@ -0,0 +1,132 @@ +=== tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts === +type Guid = string & { $Guid }; // Tagged string type +>Guid : string & { $Guid: any; } +>$Guid : any + +type SerialNo = number & { $SerialNo }; // Tagged number type +>SerialNo : number & { $SerialNo: any; } +>$SerialNo : any + +function createGuid() { +>createGuid : () => string & { $Guid: any; } + + return "21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid; +>"21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid : string & { $Guid: any; } +>"21EC2020-3AEA-4069-A2DD-08002B30309D" : string +>Guid : string & { $Guid: any; } +} + +function createSerialNo() { +>createSerialNo : () => number & { $SerialNo: any; } + + return 12345 as SerialNo; +>12345 as SerialNo : number & { $SerialNo: any; } +>12345 : number +>SerialNo : number & { $SerialNo: any; } +} + +let map1: { [x: string]: number } = {}; +>map1 : { [x: string]: number; } +>x : string +>{} : { [x: string]: undefined; } + +let guid = createGuid(); +>guid : string & { $Guid: any; } +>createGuid() : string & { $Guid: any; } +>createGuid : () => string & { $Guid: any; } + +map1[guid] = 123; // Can with tagged string +>map1[guid] = 123 : number +>map1[guid] : number +>map1 : { [x: string]: number; } +>guid : string & { $Guid: any; } +>123 : number + +let map2: { [x: number]: string } = {}; +>map2 : { [x: number]: string; } +>x : number +>{} : { [x: number]: undefined; } + +let serialNo = createSerialNo(); +>serialNo : number & { $SerialNo: any; } +>createSerialNo() : number & { $SerialNo: any; } +>createSerialNo : () => number & { $SerialNo: any; } + +map2[serialNo] = "hello"; // Can index with tagged number +>map2[serialNo] = "hello" : string +>map2[serialNo] : string +>map2 : { [x: number]: string; } +>serialNo : number & { $SerialNo: any; } +>"hello" : string + +const s1 = "{" + guid + "}"; +>s1 : string +>"{" + guid + "}" : string +>"{" + guid : string +>"{" : string +>guid : string & { $Guid: any; } +>"}" : string + +const s2 = guid.toLowerCase(); +>s2 : string +>guid.toLowerCase() : string +>guid.toLowerCase : () => string +>guid : string & { $Guid: any; } +>toLowerCase : () => string + +const s3 = guid + guid; +>s3 : string +>guid + guid : string +>guid : string & { $Guid: any; } +>guid : string & { $Guid: any; } + +const s4 = guid + serialNo; +>s4 : string +>guid + serialNo : string +>guid : string & { $Guid: any; } +>serialNo : number & { $SerialNo: any; } + +const s5 = serialNo.toPrecision(0); +>s5 : string +>serialNo.toPrecision(0) : string +>serialNo.toPrecision : (precision?: number) => string +>serialNo : number & { $SerialNo: any; } +>toPrecision : (precision?: number) => string +>0 : number + +const n1 = serialNo * 3; +>n1 : number +>serialNo * 3 : number +>serialNo : number & { $SerialNo: any; } +>3 : number + +const n2 = serialNo + serialNo; +>n2 : number +>serialNo + serialNo : number +>serialNo : number & { $SerialNo: any; } +>serialNo : number & { $SerialNo: any; } + +const b1 = guid === ""; +>b1 : boolean +>guid === "" : boolean +>guid : string & { $Guid: any; } +>"" : string + +const b2 = guid === guid; +>b2 : boolean +>guid === guid : boolean +>guid : string & { $Guid: any; } +>guid : string & { $Guid: any; } + +const b3 = serialNo === 0; +>b3 : boolean +>serialNo === 0 : boolean +>serialNo : number & { $SerialNo: any; } +>0 : number + +const b4 = serialNo === serialNo; +>b4 : boolean +>serialNo === serialNo : boolean +>serialNo : number & { $SerialNo: any; } +>serialNo : number & { $SerialNo: any; } + From 6b303271f08c78474c4b7838b6288d85fe404ade Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Sun, 7 Feb 2016 19:54:38 +0800 Subject: [PATCH 035/297] Go to defininition should not go to named import --- src/services/services.ts | 8 +++++++- tests/cases/fourslash/goToDefinitionImportedNames3.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 6761c487c6c..d291078f7b8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4639,7 +4639,13 @@ namespace ts { // to jump to the implementation directly. if (symbol.flags & SymbolFlags.Alias) { const declaration = symbol.declarations[0]; - if (node.kind === SyntaxKind.Identifier && node.parent === declaration) { + + // We want go to the original declaration if the aliased symbol was declared in the location's parent node. + // Except for cases when the aliased symbol is originating from a named import. + if (node.kind === SyntaxKind.Identifier && + (node.parent === declaration || + (declaration.kind === SyntaxKind.ImportSpecifier && declaration.parent && declaration.parent.kind === SyntaxKind.NamedImports))) { + symbol = typeChecker.getAliasedSymbol(symbol); } } diff --git a/tests/cases/fourslash/goToDefinitionImportedNames3.ts b/tests/cases/fourslash/goToDefinitionImportedNames3.ts index d55137575ef..70fce1749e4 100644 --- a/tests/cases/fourslash/goToDefinitionImportedNames3.ts +++ b/tests/cases/fourslash/goToDefinitionImportedNames3.ts @@ -31,7 +31,7 @@ goTo.file("e.ts"); goTo.marker('classReference'); goTo.definition(); -verify.caretAtMarker('classAliasDefinition'); +verify.caretAtMarker('classDefinition'); goTo.marker('classAliasDefinition'); goTo.definition(); From 3d8a472527e4f0809c75df42a28d03731dadab35 Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Sun, 7 Feb 2016 20:09:14 +0800 Subject: [PATCH 036/297] Updated comment --- src/services/services.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index d291078f7b8..7493e894d1c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4640,8 +4640,11 @@ namespace ts { if (symbol.flags & SymbolFlags.Alias) { const declaration = symbol.declarations[0]; - // We want go to the original declaration if the aliased symbol was declared in the location's parent node. - // Except for cases when the aliased symbol is originating from a named import. + // Go to the original declaration for cases: + // + // (1) when the aliased symbol was declared in location(parent). + // (2) when the aliased symbol is originating from a named import. + // if (node.kind === SyntaxKind.Identifier && (node.parent === declaration || (declaration.kind === SyntaxKind.ImportSpecifier && declaration.parent && declaration.parent.kind === SyntaxKind.NamedImports))) { From 43d2054eaca403fb2eebd5fe784b925e75f5d7c6 Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Sun, 7 Feb 2016 20:10:59 +0800 Subject: [PATCH 037/297] Fixes typo --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 7493e894d1c..211b1358c50 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4642,7 +4642,7 @@ namespace ts { // Go to the original declaration for cases: // - // (1) when the aliased symbol was declared in location(parent). + // (1) when the aliased symbol was declared in the location(parent). // (2) when the aliased symbol is originating from a named import. // if (node.kind === SyntaxKind.Identifier && From bd8aba956f234ee5a365bb14b5da2631007e295b Mon Sep 17 00:00:00 2001 From: Bill Ticehurst Date: Sat, 6 Feb 2016 18:41:23 -0800 Subject: [PATCH 038/297] Fix emitted file extension for JavaScript files with JSX.Preserve (cherry picked from commit af0a0eedd85298d049f89f754364497e36efe671) --- src/compiler/utilities.ts | 18 ++++++++-- .../reference/jsxPreserveWithJsInput.js | 29 +++++++++++++++ .../reference/jsxPreserveWithJsInput.symbols | 27 ++++++++++++++ .../reference/jsxPreserveWithJsInput.types | 35 +++++++++++++++++++ .../cases/compiler/jsxPreserveWithJsInput.ts | 18 ++++++++++ 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/jsxPreserveWithJsInput.js create mode 100644 tests/baselines/reference/jsxPreserveWithJsInput.symbols create mode 100644 tests/baselines/reference/jsxPreserveWithJsInput.types create mode 100644 tests/cases/compiler/jsxPreserveWithJsInput.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 09100eb61ed..083e8fc1c4c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2040,8 +2040,22 @@ namespace ts { } function onSingleFileEmit(host: EmitHost, sourceFile: SourceFile) { - const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, - sourceFile.languageVariant === LanguageVariant.JSX && options.jsx === JsxEmit.Preserve ? ".jsx" : ".js"); + // JavaScript files are always LanguageVariant.JSX, as JSX syntax is allowed in .js files also. + // So for JavaScript files, '.jsx' is only emitted if the input was '.jsx', and JsxEmit.Preserve. + // For TypeScript, the only time to emit with a '.jsx' extension, is on JSX input, and JsxEmit.Preserve + let extension = ".js"; + if (options.jsx === JsxEmit.Preserve) { + if (isSourceFileJavaScript(sourceFile)) { + if (fileExtensionIs(sourceFile.fileName, ".jsx")) { + extension = ".jsx"; + } + } + else if (sourceFile.languageVariant === LanguageVariant.JSX) { + // TypeScript source file preserving JSX syntax + extension = ".jsx"; + } + } + const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, extension); const emitFileNames: EmitFileNames = { jsFilePath, sourceMapFilePath: getSourceMapFilePath(jsFilePath, options), diff --git a/tests/baselines/reference/jsxPreserveWithJsInput.js b/tests/baselines/reference/jsxPreserveWithJsInput.js new file mode 100644 index 00000000000..2cc59ffa355 --- /dev/null +++ b/tests/baselines/reference/jsxPreserveWithJsInput.js @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/jsxPreserveWithJsInput.ts] //// + +//// [a.js] + +var elemA = 42; + +//// [b.jsx] +var elemB = {"test"}; + +//// [c.js] +var elemC = {42}; + +//// [d.ts] +var elemD = 42; + +//// [e.tsx] +var elemE = {true}; + + +//// [a.js] +var elemA = 42; +//// [b.jsx] +var elemB = {"test"}; +//// [c.js] +var elemC = {42}; +//// [d.js] +var elemD = 42; +//// [e.jsx] +var elemE = {true}; diff --git a/tests/baselines/reference/jsxPreserveWithJsInput.symbols b/tests/baselines/reference/jsxPreserveWithJsInput.symbols new file mode 100644 index 00000000000..6ad2f614875 --- /dev/null +++ b/tests/baselines/reference/jsxPreserveWithJsInput.symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/a.js === + +var elemA = 42; +>elemA : Symbol(elemA, Decl(a.js, 1, 3)) + +=== tests/cases/compiler/b.jsx === +var elemB = {"test"}; +>elemB : Symbol(elemB, Decl(b.jsx, 0, 3)) +>b : Symbol(unknown) +>b : Symbol(unknown) + +=== tests/cases/compiler/c.js === +var elemC = {42}; +>elemC : Symbol(elemC, Decl(c.js, 0, 3)) +>c : Symbol(unknown) +>c : Symbol(unknown) + +=== tests/cases/compiler/d.ts === +var elemD = 42; +>elemD : Symbol(elemD, Decl(d.ts, 0, 3)) + +=== tests/cases/compiler/e.tsx === +var elemE = {true}; +>elemE : Symbol(elemE, Decl(e.tsx, 0, 3)) +>e : Symbol(unknown) +>e : Symbol(unknown) + diff --git a/tests/baselines/reference/jsxPreserveWithJsInput.types b/tests/baselines/reference/jsxPreserveWithJsInput.types new file mode 100644 index 00000000000..7f4ed6daa2b --- /dev/null +++ b/tests/baselines/reference/jsxPreserveWithJsInput.types @@ -0,0 +1,35 @@ +=== tests/cases/compiler/a.js === + +var elemA = 42; +>elemA : number +>42 : number + +=== tests/cases/compiler/b.jsx === +var elemB = {"test"}; +>elemB : any +>{"test"} : any +>b : any +>"test" : string +>b : any + +=== tests/cases/compiler/c.js === +var elemC = {42}; +>elemC : any +>{42} : any +>c : any +>42 : number +>c : any + +=== tests/cases/compiler/d.ts === +var elemD = 42; +>elemD : number +>42 : number + +=== tests/cases/compiler/e.tsx === +var elemE = {true}; +>elemE : any +>{true} : any +>e : any +>true : boolean +>e : any + diff --git a/tests/cases/compiler/jsxPreserveWithJsInput.ts b/tests/cases/compiler/jsxPreserveWithJsInput.ts new file mode 100644 index 00000000000..f229e40a550 --- /dev/null +++ b/tests/cases/compiler/jsxPreserveWithJsInput.ts @@ -0,0 +1,18 @@ +// @outdir: out +// @jsx: preserve +// @allowjs: true + +// @filename: a.js +var elemA = 42; + +// @filename: b.jsx +var elemB = {"test"}; + +// @filename: c.js +var elemC = {42}; + +// @filename: d.ts +var elemD = 42; + +// @filename: e.tsx +var elemE = {true}; From 116bce37ea71a5b4422dbba72454f640b944c4b2 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 8 Feb 2016 10:52:01 -0800 Subject: [PATCH 039/297] Add missing tests from portfix6901 --- ...CallBeforeEmitParameterPropertyDeclaration1.ts | 12 ++++++++++++ ...lBeforeEmitParameterPropertyDeclaration1ES6.ts | 13 +++++++++++++ ...emitSuperCallBeforeEmitPropertyDeclaration1.ts | 15 +++++++++++++++ ...tSuperCallBeforeEmitPropertyDeclaration1ES6.ts | 15 +++++++++++++++ ...DeclarationAndParameterPropertyDeclaration1.ts | 13 +++++++++++++ ...larationAndParameterPropertyDeclaration1ES6.ts | 14 ++++++++++++++ 6 files changed, 82 insertions(+) create mode 100644 tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts create mode 100644 tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts create mode 100644 tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1.ts create mode 100644 tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts create mode 100644 tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts create mode 100644 tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts diff --git a/tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts b/tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts new file mode 100644 index 00000000000..5172ccfe21f --- /dev/null +++ b/tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1.ts @@ -0,0 +1,12 @@ +class A { + blub = 6; +} + + +class B extends A { + constructor(public x: number) { + "use strict"; + 'someStringForEgngInject'; + super() + } +} diff --git a/tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts b/tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts new file mode 100644 index 00000000000..e62f753d725 --- /dev/null +++ b/tests/cases/compiler/emitSuperCallBeforeEmitParameterPropertyDeclaration1ES6.ts @@ -0,0 +1,13 @@ +// @target: ES6 +class A { + blub = 6; +} + + +class B extends A { + constructor(public x: number) { + "use strict"; + 'someStringForEgngInject'; + super() + } +} diff --git a/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1.ts b/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1.ts new file mode 100644 index 00000000000..52d41c3731a --- /dev/null +++ b/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1.ts @@ -0,0 +1,15 @@ +class A { + blub = 6; +} + + +class B extends A { + + blub = 12; + + constructor() { + "use strict"; + 'someStringForEgngInject'; + super() + } +} \ No newline at end of file diff --git a/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts b/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts new file mode 100644 index 00000000000..f6c7164ae75 --- /dev/null +++ b/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts @@ -0,0 +1,15 @@ +// @target: ES6 +class A { + blub = 6; +} + + +class B extends A { + + blub = 12; + + constructor() { + 'someStringForEgngInject'; + super() + } +} \ No newline at end of file diff --git a/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts b/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts new file mode 100644 index 00000000000..a2d8bf8473f --- /dev/null +++ b/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1.ts @@ -0,0 +1,13 @@ +class A { + blub = 6; +} + + +class B extends A { + blah = 2; + constructor(public x: number) { + "use strict"; + 'someStringForEgngInject'; + super() + } +} \ No newline at end of file diff --git a/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts b/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts new file mode 100644 index 00000000000..8bd8420f8f7 --- /dev/null +++ b/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclarationAndParameterPropertyDeclaration1ES6.ts @@ -0,0 +1,14 @@ +// @target: ES6 +class A { + blub = 6; +} + + +class B extends A { + blah = 2; + constructor(public x: number) { + "use strict"; + 'someStringForEgngInject'; + super() + } +} \ No newline at end of file From b104342c63715eb83aeedadbb524393bc6037dcb Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 8 Feb 2016 17:30:26 -0800 Subject: [PATCH 040/297] Add 'wiki' and 'handbook' directories to the docs folder with READMEs. --- doc/handbook/README.md | 4 ++++ doc/wiki/README.md | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 doc/handbook/README.md create mode 100644 doc/wiki/README.md diff --git a/doc/handbook/README.md b/doc/handbook/README.md new file mode 100644 index 00000000000..2d2e0e83a46 --- /dev/null +++ b/doc/handbook/README.md @@ -0,0 +1,4 @@ +# The TypeScript Handbook + +The contents of the TypeScript Handbook can be read from [its GitHub repository](https://github.com/Microsoft/TypeScript-Handbook). +Issues and pull requests should be directed there. \ No newline at end of file diff --git a/doc/wiki/README.md b/doc/wiki/README.md new file mode 100644 index 00000000000..19961197840 --- /dev/null +++ b/doc/wiki/README.md @@ -0,0 +1,6 @@ +# The TypeScript Wiki + +To read the wiki, [visit the wiki on GitHub](https://github.com/Microsoft/TypeScript/wiki). + +To contribute by filing an issue or sending a pull request, [visit the wiki repository](https://github.com/Microsoft/TypeScript-wiki). + From e848e95babd29f9fa42632faa469696899017f7f Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Tue, 9 Feb 2016 18:16:36 +0000 Subject: [PATCH 041/297] spelling fixes for checker.ts, declarationEmitter.ts, types.ts * accessibility * accessor * annotate * anything * apply * assignability * collection * conservatively * constituent * constructor * containing * contextual * contributed * declaration * excessively * exclusion * field * indistinguishable * initializer * intrinsic * knowing * noisiness * occurred * overridden * parameter * perspective * properties * property * prototype * rewritten * specifies * symbolFromSymbolTable --- src/compiler/checker.ts | 84 +++++++++---------- src/compiler/declarationEmitter.ts | 124 ++++++++++++++--------------- src/compiler/types.ts | 18 ++--- 3 files changed, 113 insertions(+), 113 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 63a4185a8bb..01a279c3a4f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -467,10 +467,10 @@ namespace ts { * @return a tuple of two symbols */ function getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): [Symbol, Symbol] { - const constructoDeclaration = parameter.parent; + const constructorDeclaration = parameter.parent; const classDeclaration = parameter.parent.parent; - const parameterSymbol = getSymbol(constructoDeclaration.locals, parameterName, SymbolFlags.Value); + const parameterSymbol = getSymbol(constructorDeclaration.locals, parameterName, SymbolFlags.Value); const propertySymbol = getSymbol(classDeclaration.symbol.members, parameterName, SymbolFlags.Value); if (parameterSymbol && propertySymbol) { @@ -1460,7 +1460,7 @@ namespace ts { function isAccessible(symbolFromSymbolTable: Symbol, resolvedAliasSymbol?: Symbol) { if (symbol === (resolvedAliasSymbol || symbolFromSymbolTable)) { // if the symbolFromSymbolTable is not external module (it could be if it was determined as ambient external module and would be in globals table) - // and if symbolfrom symbolTable or alias resolution matches the symbol, + // and if symbolFromSymbolTable or alias resolution matches the symbol, // check the symbol can be qualified, it is only then this symbol is accessible return !forEach(symbolFromSymbolTable.declarations, hasExternalModuleSymbol) && canQualifySymbol(symbolFromSymbolTable, meaning); @@ -1531,7 +1531,7 @@ namespace ts { return qualify; } - function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult { + function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessibilityResult { if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) { const initialSymbol = symbol; let meaningToLook = meaning; @@ -1541,7 +1541,7 @@ namespace ts { if (accessibleSymbolChain) { const hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]); if (!hasAccessibleDeclarations) { - return { + return { accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning), errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, SymbolFlags.Namespace) : undefined, @@ -2140,10 +2140,10 @@ namespace ts { } } - function buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags) { + function buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags) { const targetSymbol = getTargetSymbol(symbol); if (targetSymbol.flags & SymbolFlags.Class || targetSymbol.flags & SymbolFlags.Interface || targetSymbol.flags & SymbolFlags.TypeAlias) { - buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol), writer, enclosingDeclaraiton, flags); + buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol), writer, enclosingDeclaration, flags); } } @@ -3421,7 +3421,7 @@ namespace ts { // Returns true if the class or interface member given by the symbol is free of "this" references. The // function may return false for symbols that are actually free of "this" references because it is not // feasible to perform a complete analysis in all cases. In particular, property members with types - // inferred from their initializers and function members with inferred return types are convervatively + // inferred from their initializers and function members with inferred return types are conservatively // assumed not to be free of "this" references. function isIndependentMember(symbol: Symbol): boolean { if (symbol.declarations && symbol.declarations.length === 1) { @@ -5892,7 +5892,7 @@ namespace ts { if (kind === SignatureKind.Construct && sourceSignatures.length && targetSignatures.length && isAbstractConstructorType(source) && !isAbstractConstructorType(target)) { // An abstract constructor type is not assignable to a non-abstract constructor type - // as it would otherwise be possible to new an abstract class. Note that the assignablity + // as it would otherwise be possible to new an abstract class. Note that the assignability // check we perform for an extends clause excludes construct signatures from the target, // so this check never proceeds. if (reportErrors) { @@ -6579,7 +6579,7 @@ namespace ts { } } else if (source.flags & TypeFlags.UnionOrIntersection) { - // Source is a union or intersection type, infer from each consituent type + // Source is a union or intersection type, infer from each constituent type const sourceTypes = (source).types; for (const sourceType of sourceTypes) { inferFromTypes(sourceType, target); @@ -7397,7 +7397,7 @@ namespace ts { if (container.kind === SyntaxKind.FunctionExpression) { if (getSpecialPropertyAssignmentKind(container.parent) === SpecialPropertyAssignmentKind.PrototypeProperty) { // Get the 'x' of 'x.prototype.y = f' (here, 'f' is 'container') - const className = (((container.parent as BinaryExpression) // x.protoype.y = f + const className = (((container.parent as BinaryExpression) // x.prototype.y = f .left as PropertyAccessExpression) // x.prototype.y .expression as PropertyAccessExpression) // x.prototype .expression; // x @@ -7920,7 +7920,7 @@ namespace ts { * Otherwise this may not be very useful. * * In cases where you *are* working on this function, you should understand - * when it is appropriate to use 'getContextualType' and 'getApparentTypeOfContetxualType'. + * when it is appropriate to use 'getContextualType' and 'getApparentTypeOfContextualType'. * * - Use 'getContextualType' when you are simply going to propagate the result to the expression. * - Use 'getApparentTypeOfContextualType' when you're going to need the members of the type. @@ -8587,10 +8587,10 @@ namespace ts { } /// e.g. "props" for React.d.ts, - /// or 'undefined' if ElementAttributesPropery doesn't exist (which means all + /// or 'undefined' if ElementAttributesProperty doesn't exist (which means all /// non-intrinsic elements' attributes type is 'any'), /// or '' if it has 0 properties (which means every - /// non-instrinsic elements' attributes type is the element instance type) + /// non-intrinsic elements' attributes type is the element instance type) function getJsxElementPropertiesName() { // JSX const jsxNamespace = getGlobalSymbol(JsxNames.JSX, SymbolFlags.Namespace, /*diagnosticMessage*/undefined); @@ -8598,7 +8598,7 @@ namespace ts { const attribsPropTypeSym = jsxNamespace && getSymbol(jsxNamespace.exports, JsxNames.ElementAttributesPropertyNameContainer, SymbolFlags.Type); // JSX.ElementAttributesProperty [type] const attribPropType = attribsPropTypeSym && getDeclaredTypeOfSymbol(attribsPropTypeSym); - // The properites of JSX.ElementAttributesProperty + // The properties of JSX.ElementAttributesProperty const attribProperties = attribPropType && getPropertiesOfType(attribPropType); if (attribProperties) { @@ -9429,7 +9429,7 @@ namespace ts { // Tagged template expressions will always have `undefined` for `excludeArgument[0]`. if (excludeArgument) { for (let i = 0; i < argCount; i++) { - // No need to check for omitted args and template expressions, their exlusion value is always undefined + // No need to check for omitted args and template expressions, their exclusion value is always undefined if (excludeArgument[i] === false) { const arg = args[i]; const paramType = getTypeAtPosition(signature, i); @@ -9710,7 +9710,7 @@ namespace ts { */ function getEffectiveDecoratorThirdArgumentType(node: Node) { // The third argument to a decorator is either its `descriptor` for a method decorator - // or its `parameterIndex` for a paramter decorator + // or its `parameterIndex` for a parameter decorator if (node.kind === SyntaxKind.ClassDeclaration) { Debug.fail("Class decorators should not have a third synthetic argument."); return unknownType; @@ -10078,7 +10078,7 @@ namespace ts { // We exclude union types because we may have a union of function types that happen to have // no common signatures. if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { - // The unknownType indicates that an error already occured (and was reported). No + // The unknownType indicates that an error already occurred (and was reported). No // need to report another error in this case. if (funcType !== unknownType && node.typeArguments) { error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); @@ -10288,10 +10288,10 @@ namespace ts { const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { - const containgFunction = getContainingFunction(node.expression); + const containingFunction = getContainingFunction(node.expression); - if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) { - getNodeLinks(containgFunction).flags |= NodeCheckFlags.HasSeenSuperCall; + if (containingFunction && containingFunction.kind === SyntaxKind.Constructor) { + getNodeLinks(containingFunction).flags |= NodeCheckFlags.HasSeenSuperCall; } return voidType; } @@ -11812,7 +11812,7 @@ namespace ts { function checkConstructorDeclaration(node: ConstructorDeclaration) { // Grammar check on signature of constructor and modifier of the constructor is done in checkSignatureDeclaration function. checkSignatureDeclaration(node); - // Grammar check for checking only related to constructoDeclaration + // Grammar check for checking only related to constructorDeclaration checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node); checkSourceElement(node.body); @@ -12324,7 +12324,7 @@ namespace ts { } } - // Spaces for anyting not declared a 'default export'. + // Spaces for anything not declared a 'default export'. const nonDefaultExportedDeclarationSpaces = exportedDeclarationSpaces | nonExportedDeclarationSpaces; const commonDeclarationSpacesForExportsAndLocals = exportedDeclarationSpaces & nonExportedDeclarationSpaces; @@ -12335,7 +12335,7 @@ namespace ts { for (const d of symbol.declarations) { const declarationSpaces = getDeclarationSpaces(d); - // Only error on the declarations that conributed to the intersecting spaces. + // Only error on the declarations that contributed to the intersecting spaces. if (declarationSpaces & commonDeclarationSpacesForDefaultAndNonDefault) { error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead, declarationNameToString(d.name)); } @@ -13551,7 +13551,7 @@ namespace ts { * This function does the following steps: * 1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents. * 2. Take the element types of the array constituents. - * 3. Return the union of the element types, and string if there was a string constitutent. + * 3. Return the union of the element types, and string if there was a string constituent. * * For example: * string -> string @@ -13625,7 +13625,7 @@ namespace ts { // TODO: Check that target label is valid } - function isGetAccessorWithAnnotatatedSetAccessor(node: FunctionLikeDeclaration) { + function isGetAccessorWithAnnotatedSetAccessor(node: FunctionLikeDeclaration) { return !!(node.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(getDeclarationOfKind(node.symbol, SyntaxKind.SetAccessor))); } @@ -13661,7 +13661,7 @@ namespace ts { error(node.expression, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } - else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func) || returnType.flags & TypeFlags.PredicateType) { + else if (func.type || isGetAccessorWithAnnotatedSetAccessor(func) || returnType.flags & TypeFlags.PredicateType) { if (isAsyncFunctionLike(func)) { const promisedType = getPromisedType(returnType); const awaitedType = checkAwaitedType(exprType, node.expression, Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); @@ -14064,7 +14064,7 @@ namespace ts { Debug.assert(!!derived, "derived should point to something, even if it is the base class' declaration."); if (derived) { - // In order to resolve whether the inherited method was overriden in the base class or not, + // In order to resolve whether the inherited method was overridden in the base class or not, // we compare the Symbols obtained. Since getTargetSymbol returns the symbol on the *uninstantiated* // type declaration, derived and base resolve to the same symbol even in the case of generic classes. if (derived === base) { @@ -14966,7 +14966,7 @@ namespace ts { const kind = node.kind; if (cancellationToken) { - // Only bother checking on a few construct kinds. We don't want to be excessivly + // Only bother checking on a few construct kinds. We don't want to be excessively // hitting the cancellation token on every node we check. switch (kind) { case SyntaxKind.ModuleDeclaration: @@ -15747,13 +15747,13 @@ namespace ts { function isSymbolOfDeclarationWithCollidingName(symbol: Symbol): boolean { if (symbol.flags & SymbolFlags.BlockScoped) { const links = getSymbolLinks(symbol); - if (links.isDeclaratonWithCollidingName === undefined) { + if (links.isDeclarationWithCollidingName === undefined) { const container = getEnclosingBlockScopeContainer(symbol.valueDeclaration); if (isStatementWithLocals(container)) { const nodeLinks = getNodeLinks(symbol.valueDeclaration); if (!!resolveName(container.parent, symbol.name, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined)) { // redeclaration - always should be renamed - links.isDeclaratonWithCollidingName = true; + links.isDeclarationWithCollidingName = true; } else if (nodeLinks.flags & NodeCheckFlags.CapturedBlockScopedBinding) { // binding is captured in the function @@ -15768,21 +15768,21 @@ namespace ts { // console.log(b()); // should print '100' // OR // - binding is declared inside loop but not in inside initializer of iteration statement or directly inside loop body - // * variables from initializer are passed to rewritted loop body as parameters so they are not captured directly + // * variables from initializer are passed to rewritten loop body as parameters so they are not captured directly // * variables that are declared immediately in loop body will become top level variable after loop is rewritten and thus // they will not collide with anything const isDeclaredInLoop = nodeLinks.flags & NodeCheckFlags.BlockScopedBindingInLoop; const inLoopInitializer = isIterationStatement(container, /*lookInLabeledStatements*/ false); const inLoopBodyBlock = container.kind === SyntaxKind.Block && isIterationStatement(container.parent, /*lookInLabeledStatements*/ false); - links.isDeclaratonWithCollidingName = !isBlockScopedContainerTopLevel(container) && (!isDeclaredInLoop || (!inLoopInitializer && !inLoopBodyBlock)); + links.isDeclarationWithCollidingName = !isBlockScopedContainerTopLevel(container) && (!isDeclaredInLoop || (!inLoopInitializer && !inLoopBodyBlock)); } else { - links.isDeclaratonWithCollidingName = false; + links.isDeclarationWithCollidingName = false; } } } - return links.isDeclaratonWithCollidingName; + return links.isDeclarationWithCollidingName; } return false; } @@ -15833,7 +15833,7 @@ namespace ts { if (target === unknownSymbol && compilerOptions.isolatedModules) { return true; } - // const enums and modules that contain only const enums are not considered values from the emit perespective + // const enums and modules that contain only const enums are not considered values from the emit perspective // unless 'preserveConstEnums' option is set to true return target !== unknownSymbol && target && @@ -16693,8 +16693,8 @@ namespace ts { const seen: Map = {}; const Property = 1; const GetAccessor = 2; - const SetAccesor = 4; - const GetOrSetAccessor = GetAccessor | SetAccesor; + const SetAccessor = 4; + const GetOrSetAccessor = GetAccessor | SetAccessor; for (const prop of node.properties) { const name = prop.name; @@ -16718,7 +16718,7 @@ namespace ts { } }); - // ECMA-262 11.1.5 Object Initialiser + // ECMA-262 11.1.5 Object Initializer // If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true // a.This production is contained in strict code and IsDataDescriptor(previous) is true and // IsDataDescriptor(propId.descriptor) is true. @@ -16728,7 +16728,7 @@ namespace ts { // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields let currentKind: number; if (prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment) { - // Grammar checking for computedPropertName and shorthandPropertyAssignment + // Grammar checking for computedPropertyName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, (prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional); if (name.kind === SyntaxKind.NumericLiteral) { checkGrammarNumericLiteral(name); @@ -16742,7 +16742,7 @@ namespace ts { currentKind = GetAccessor; } else if (prop.kind === SyntaxKind.SetAccessor) { - currentKind = SetAccesor; + currentKind = SetAccessor; } else { Debug.fail("Unexpected syntax kind:" + prop.kind); @@ -17214,7 +17214,7 @@ namespace ts { // We are either parented by another statement, or some sort of block. // If we're in a block, we only want to really report an error once - // to prevent noisyness. So use a bit on the block to indicate if + // to prevent noisiness. So use a bit on the block to indicate if // this has already been reported, and don't report if it has. // if (node.parent.kind === SyntaxKind.Block || node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) { diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 5977c84d7f4..21317fe4918 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -18,7 +18,7 @@ namespace ts { referencePathsOutput: string; } - type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic; + type GetSymbolAccessibilityDiagnostic = (symbolAccessibilityResult: SymbolAccessibilityResult) => SymbolAccessibilityDiagnostic; interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter { getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic; @@ -252,30 +252,30 @@ namespace ts { setWriter(oldWriter); } - function handleSymbolAccessibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { - if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { + function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) { + if (symbolAccessibilityResult.accessibility === SymbolAccessibility.Accessible) { // write the aliases - if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { - writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible); + if (symbolAccessibilityResult && symbolAccessibilityResult.aliasesToMakeVisible) { + writeAsynchronousModuleElements(symbolAccessibilityResult.aliasesToMakeVisible); } } else { // Report error reportedDeclarationError = true; - const errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); + const errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccessibilityResult); if (errorInfo) { if (errorInfo.typeName) { - emitterDiagnostics.add(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, + emitterDiagnostics.add(createDiagnosticForNode(symbolAccessibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, getTextOfNodeFromSourceText(currentText, errorInfo.typeName), - symbolAccesibilityResult.errorSymbolName, - symbolAccesibilityResult.errorModuleName)); + symbolAccessibilityResult.errorSymbolName, + symbolAccessibilityResult.errorModuleName)); } else { - emitterDiagnostics.add(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, + emitterDiagnostics.add(createDiagnosticForNode(symbolAccessibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, - symbolAccesibilityResult.errorSymbolName, - symbolAccesibilityResult.errorModuleName)); + symbolAccessibilityResult.errorSymbolName, + symbolAccessibilityResult.errorModuleName)); } } } @@ -548,7 +548,7 @@ namespace ts { writeAsynchronousModuleElements(nodes); } - function getDefaultExportAccessibilityDiagnostic(diagnostic: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + function getDefaultExportAccessibilityDiagnostic(diagnostic: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { return { diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, errorNode: node @@ -677,7 +677,7 @@ namespace ts { } writer.writeLine(); - function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + function getImportEntityNameVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { return { diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1, errorNode: node, @@ -733,7 +733,7 @@ namespace ts { function emitExternalModuleSpecifier(parent: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration) { // emitExternalModuleSpecifier is usually called when we emit something in the.d.ts file that will make it an external module (i.e. import/export declarations). // the only case when it is not true is when we call it to emit correct name for module augmentation - d.ts files with just module augmentations are not considered - // external modules since they are indistingushable from script files with ambient modules. To fix this in such d.ts files we'll emit top level 'export {}' + // external modules since they are indistinguishable from script files with ambient modules. To fix this in such d.ts files we'll emit top level 'export {}' // so compiler will treat them as external modules. resultHasExternalModuleIndicator = resultHasExternalModuleIndicator || parent.kind !== SyntaxKind.ModuleDeclaration; let moduleSpecifier: Node; @@ -850,7 +850,7 @@ namespace ts { writeLine(); enclosingDeclaration = prevEnclosingDeclaration; - function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + function getTypeAliasDeclarationVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { return { diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, errorNode: node.type, @@ -917,7 +917,7 @@ namespace ts { } } - function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + function getTypeParameterConstraintVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { // Type parameter constraints are named by user so we should always be able to name it let diagnosticMessage: DiagnosticMessage; switch (node.parent.kind) { @@ -987,7 +987,7 @@ namespace ts { write("null"); } - function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + function getHeritageClauseVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { let diagnosticMessage: DiagnosticMessage; // Heritage clause is written by user so it can always be named if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { @@ -1104,10 +1104,10 @@ namespace ts { } } - function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult) { + function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) { if (node.kind === SyntaxKind.VariableDeclaration) { - return symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; @@ -1116,30 +1116,30 @@ namespace ts { else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & NodeFlags.Static) { - return symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { - return symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { // Interfaces cannot have types that cannot be named - return symbolAccesibilityResult.errorModuleName ? + return symbolAccessibilityResult.errorModuleName ? Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; } } } - function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - const diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + function getVariableDeclarationTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + const diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult); return diagnosticMessage !== undefined ? { diagnosticMessage, errorNode: node, @@ -1163,8 +1163,8 @@ namespace ts { } function emitBindingElement(bindingElement: BindingElement) { - function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - const diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + function getBindingElementTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + const diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult); return diagnosticMessage !== undefined ? { diagnosticMessage, errorNode: bindingElement, @@ -1255,17 +1255,17 @@ namespace ts { } } - function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + function getAccessorDeclarationTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { let diagnosticMessage: DiagnosticMessage; if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) { // Setters have to have type named and cannot infer it so, the type should always be named if (accessorWithTypeAnnotation.parent.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; } else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; } @@ -1278,15 +1278,15 @@ namespace ts { } else { if (accessorWithTypeAnnotation.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; } else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; @@ -1385,26 +1385,26 @@ namespace ts { writeLine(); } - function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + function getReturnTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { let diagnosticMessage: DiagnosticMessage; switch (node.kind) { case SyntaxKind.ConstructSignature: // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; break; case SyntaxKind.CallSignature: // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; break; case SyntaxKind.IndexSignature: // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; @@ -1412,30 +1412,30 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: if (node.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; } else { // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; case SyntaxKind.FunctionDeclaration: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + diagnosticMessage = symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; @@ -1481,8 +1481,8 @@ namespace ts { writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); } - function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - const diagnosticMessage: DiagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + function getParameterDeclarationTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + const diagnosticMessage: DiagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult); return diagnosticMessage !== undefined ? { diagnosticMessage, errorNode: node, @@ -1490,53 +1490,53 @@ namespace ts { } : undefined; } - function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult): DiagnosticMessage { + function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult): DiagnosticMessage { switch (node.parent.kind) { case SyntaxKind.Constructor: - return symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; case SyntaxKind.ConstructSignature: // Interfaces cannot have parameter types that cannot be named - return symbolAccesibilityResult.errorModuleName ? + return symbolAccessibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; case SyntaxKind.CallSignature: // Interfaces cannot have parameter types that cannot be named - return symbolAccesibilityResult.errorModuleName ? + return symbolAccessibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: if (node.parent.flags & NodeFlags.Static) { - return symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { - return symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { // Interfaces cannot have parameter types that cannot be named - return symbolAccesibilityResult.errorModuleName ? + return symbolAccessibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } case SyntaxKind.FunctionDeclaration: - return symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + return symbolAccessibilityResult.errorModuleName ? + symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 05b22fd2634..31448c2859c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1559,7 +1559,7 @@ namespace ts { /* @internal */ classifiableNames?: Map; // 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 + // Content of this field should never be used directly - use getResolvedModuleFileName/setResolvedModuleFileName functions instead /* @internal */ resolvedModules: Map; /* @internal */ imports: LiteralExpression[]; /* @internal */ moduleAugmentations: LiteralExpression[]; @@ -1753,7 +1753,7 @@ namespace ts { buildSignatureDisplay(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): void; buildParameterDisplay(parameter: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; - buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void; + buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; @@ -1846,7 +1846,7 @@ namespace ts { } /* @internal */ - export interface SymbolAccessiblityResult extends SymbolVisibilityResult { + export interface SymbolAccessibilityResult extends SymbolVisibilityResult { errorModuleName?: string; // If the symbol is not visible from module, module's name } @@ -1888,7 +1888,7 @@ namespace ts { writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; - isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; + isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessibilityResult; isEntityNameVisible(entityName: EntityName | Expression, enclosingDeclaration: Node): SymbolVisibilityResult; // Returns the constant value this property access resolves to, or 'undefined' for a non-constant getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; @@ -2013,7 +2013,7 @@ namespace ts { containingType?: UnionOrIntersectionType; // Containing union or intersection type for synthetic property resolvedExports?: SymbolTable; // Resolved exports of module exportsChecked?: boolean; // True if exports of external module have been checked - isDeclaratonWithCollidingName?: boolean; // True if symbol is block scoped redeclaration + isDeclarationWithCollidingName?: boolean; // True if symbol is block scoped redeclaration bindingElement?: BindingElement; // Binding element associated with property symbol exportsSomeValue?: boolean; // true if module exports some value (not just types) } @@ -2062,7 +2062,7 @@ namespace ts { assignmentChecks?: Map; // Cache of assignment checks hasReportedStatementInAmbientContext?: boolean; // Cache boolean if we report statements in ambient context importOnRightSide?: Symbol; // for import declarations - import that appear on the right side - jsxFlags?: JsxFlags; // flags for knowning what kind of element/attributes we're dealing with + jsxFlags?: JsxFlags; // flags for knowing what kind of element/attributes we're dealing with resolvedJsxType?: Type; // resolved element attributes type of a JSX openinglike element } @@ -2167,7 +2167,7 @@ namespace ts { // Type references (TypeFlags.Reference). When a class or interface has type parameters or // a "this" type, references to the class or interface are made using type references. The - // typeArguments property specififes the types to substitute for the type parameters of the + // typeArguments property specifies the types to substitute for the type parameters of the // class or interface and optionally includes an extra element that specifies the type to // substitute for "this" in the resulting instantiation. When no extra argument is present, // the type reference itself is substituted for "this". The typeArguments property is undefined @@ -2694,7 +2694,7 @@ namespace ts { /* * CompilerHost must either implement resolveModuleNames (in case if it wants to be completely in charge of * module name resolution) or provide implementation for methods from ModuleResolutionHost (in this case compiler - * will appply built-in module resolution logic and use members of ModuleResolutionHost to ask host specific questions). + * will apply built-in module resolution logic and use members of ModuleResolutionHost to ask host specific questions). * If resolveModuleNames is implemented then implementation for members from ModuleResolutionHost can be just * 'throw new Error("NotImplemented")' */ @@ -2720,7 +2720,7 @@ namespace ts { getGlobalDiagnostics(): Diagnostic[]; // If fileName is provided, gets all the diagnostics associated with that file name. - // Otherwise, returns all the diagnostics (global and file associated) in this colletion. + // Otherwise, returns all the diagnostics (global and file associated) in this collection. getDiagnostics(fileName?: string): Diagnostic[]; // Gets a count of how many times this collection has been modified. This value changes From 1d428b9fe01a83b334bdad4562295b12345a4786 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 9 Feb 2016 14:31:09 -0800 Subject: [PATCH 042/297] Implicit index signatures for object literal types --- src/compiler/checker.ts | 69 ++++++++++++++++++++++++---- src/compiler/diagnosticMessages.json | 4 ++ 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b198b827d0c..2f236ed6e44 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3987,6 +3987,19 @@ namespace ts { return getIndexTypeOfStructuredType(getApparentType(type), kind); } + function getImplicitIndexTypeOfType(type: Type, kind: IndexKind): Type { + if (isObjectLiteralType(type)) { + const propTypes: Type[] = []; + for (const prop of getPropertiesOfType(type)) { + if (kind === IndexKind.String || isNumericLiteralName(prop.name)) { + propTypes.push(getTypeOfSymbol(prop)); + } + } + return getUnionType(propTypes); + } + return undefined; + } + function getTypeParametersFromJSDocTemplate(declaration: SignatureDeclaration): TypeParameter[] { if (declaration.flags & NodeFlags.JavaScriptFile) { const templateTag = getJSDocTemplateTag(declaration); @@ -5951,6 +5964,23 @@ namespace ts { return result; } + function eachPropertyRelatedTo(source: Type, target: Type, numericPropertiesOnly: boolean, reportErrors: boolean): Ternary { + let result = Ternary.True; + for (const prop of getPropertiesOfObjectType(source)) { + if (!numericPropertiesOnly || isNumericLiteralName(prop.name)) { + const related = isRelatedTo(getTypeOfSymbol(prop), target, reportErrors); + if (!related) { + if (reportErrors) { + reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop)); + } + return Ternary.False; + } + result &= related; + } + } + return result; + } + function stringIndexTypesRelatedTo(source: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { if (relation === identityRelation) { return indexTypesIdenticalTo(IndexKind.String, source, target); @@ -5964,6 +5994,9 @@ namespace ts { } const sourceInfo = getIndexInfoOfType(source, IndexKind.String); if (!sourceInfo) { + if (isObjectLiteralType(source)) { + return eachPropertyRelatedTo(source, targetInfo.type, /* numericPropertiesOnly*/ false, reportErrors); + } if (reportErrors) { reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } @@ -5995,6 +6028,9 @@ namespace ts { const sourceStringInfo = getIndexInfoOfType(source, IndexKind.String); const sourceNumberInfo = getIndexInfoOfType(source, IndexKind.Number); if (!(sourceStringInfo || sourceNumberInfo)) { + if (isObjectLiteralType(source)) { + return eachPropertyRelatedTo(source, targetInfo.type, /* numericPropertiesOnly*/ true, reportErrors); + } if (reportErrors) { reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } @@ -6263,6 +6299,15 @@ namespace ts { return !!(type.flags & TypeFlags.Tuple); } + /** + * Return true if type was inferred from an object literal or written as an object type literal + */ + function isObjectLiteralType(type: Type) { + return type.symbol && (type.symbol.flags & (SymbolFlags.ObjectLiteral | SymbolFlags.TypeLiteral)) !== 0 && + getSignaturesOfType(type, SignatureKind.Call).length === 0 && + getSignaturesOfType(type, SignatureKind.Construct).length === 0; + } + function getRegularTypeOfObjectLiteral(type: Type): Type { if (type.flags & TypeFlags.FreshObjectLiteral) { let regularType = (type).regularType; @@ -6610,9 +6655,7 @@ namespace ts { inferFromProperties(source, target); inferFromSignatures(source, target, SignatureKind.Call); inferFromSignatures(source, target, SignatureKind.Construct); - inferFromIndexTypes(source, target, IndexKind.String, IndexKind.String); - inferFromIndexTypes(source, target, IndexKind.Number, IndexKind.Number); - inferFromIndexTypes(source, target, IndexKind.String, IndexKind.Number); + inferFromIndexTypes(source, target); depth--; } } @@ -6644,12 +6687,22 @@ namespace ts { inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); } - function inferFromIndexTypes(source: Type, target: Type, sourceKind: IndexKind, targetKind: IndexKind) { - const targetIndexType = getIndexTypeOfType(target, targetKind); - if (targetIndexType) { - const sourceIndexType = getIndexTypeOfType(source, sourceKind); + function inferFromIndexTypes(source: Type, target: Type) { + const targetStringIndexType = getIndexTypeOfType(target, IndexKind.String); + if (targetStringIndexType) { + const sourceIndexType = getIndexTypeOfType(source, IndexKind.String) || + getImplicitIndexTypeOfType(source, IndexKind.String); if (sourceIndexType) { - inferFromTypes(sourceIndexType, targetIndexType); + inferFromTypes(sourceIndexType, targetStringIndexType); + } + } + const targetNumberIndexType = getIndexTypeOfType(target, IndexKind.Number); + if (targetNumberIndexType) { + const sourceIndexType = getIndexTypeOfType(source, IndexKind.Number) || + getIndexTypeOfType(source, IndexKind.String) || + getImplicitIndexTypeOfType(source, IndexKind.Number); + if (sourceIndexType) { + inferFromTypes(sourceIndexType, targetNumberIndexType); } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5b93f61bb90..2458e68f23c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1699,6 +1699,10 @@ "category": "Error", "code": 2529 }, + "Property '{0}' is incompatible with index signature.": { + "category": "Error", + "code": 2530 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 From 837e6dbda36cdf34befbf0536592f4913c59d645 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 9 Feb 2016 14:33:24 -0800 Subject: [PATCH 043/297] Accepting new baselines --- ...eAssignmentCompatIndexSignature.errors.txt | 7 +-- ...tionshipObjectsOnIndexSignature.errors.txt | 52 +------------------ ...ontextualTypingOfObjectLiterals.errors.txt | 23 -------- .../contextualTypingOfObjectLiterals.symbols | 32 ++++++++++++ .../contextualTypingOfObjectLiterals.types | 41 +++++++++++++++ .../reference/indexerAssignability.errors.txt | 28 ---------- .../reference/indexerAssignability.symbols | 36 +++++++++++++ .../reference/indexerAssignability.types | 42 +++++++++++++++ .../numericIndexerConstraint2.errors.txt | 6 ++- .../numericIndexerConstraint5.errors.txt | 6 ++- .../stringIndexerAssignments1.errors.txt | 7 +-- 11 files changed, 163 insertions(+), 117 deletions(-) delete mode 100644 tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt create mode 100644 tests/baselines/reference/contextualTypingOfObjectLiterals.symbols create mode 100644 tests/baselines/reference/contextualTypingOfObjectLiterals.types delete mode 100644 tests/baselines/reference/indexerAssignability.errors.txt create mode 100644 tests/baselines/reference/indexerAssignability.symbols create mode 100644 tests/baselines/reference/indexerAssignability.types diff --git a/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt b/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt index eb5020e97f9..e99cac7968c 100644 --- a/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt +++ b/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt @@ -1,10 +1,8 @@ -tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts(15,5): error TS2322: Type '{}' is not assignable to type '{ [n: number]: Foo; }'. - Index signature is missing in type '{}'. tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts(19,5): error TS2322: Type '() => void' is not assignable to type '{ [n: number]: Bar; }'. Index signature is missing in type '() => void'. -==== tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts (2 errors) ==== +==== tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts (1 errors) ==== interface Foo { a } interface Bar { b } @@ -20,9 +18,6 @@ tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignatur var f = () => { }; var v1: { - ~~ -!!! error TS2322: Type '{}' is not assignable to type '{ [n: number]: Foo; }'. -!!! error TS2322: Index signature is missing in type '{}'. [n: number]: Foo } = o; // Should be allowed diff --git a/tests/baselines/reference/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.errors.txt b/tests/baselines/reference/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.errors.txt index fe608b14379..2efaf2e5ae2 100644 --- a/tests/baselines/reference/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.errors.txt +++ b/tests/baselines/reference/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.errors.txt @@ -1,70 +1,54 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(26,12): error TS2365: Operator '<' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(27,12): error TS2365: Operator '<' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(28,12): error TS2365: Operator '<' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(29,12): error TS2365: Operator '<' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(31,12): error TS2365: Operator '<' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(32,12): error TS2365: Operator '<' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(33,12): error TS2365: Operator '<' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(34,12): error TS2365: Operator '<' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(37,12): error TS2365: Operator '>' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(38,12): error TS2365: Operator '>' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(39,12): error TS2365: Operator '>' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(40,12): error TS2365: Operator '>' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(42,12): error TS2365: Operator '>' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(43,12): error TS2365: Operator '>' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(44,12): error TS2365: Operator '>' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(45,12): error TS2365: Operator '>' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(48,12): error TS2365: Operator '<=' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(49,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(50,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(51,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(53,12): error TS2365: Operator '<=' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(54,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(55,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(56,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(59,12): error TS2365: Operator '>=' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(60,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(61,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(62,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(64,12): error TS2365: Operator '>=' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(65,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(66,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(67,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(70,12): error TS2365: Operator '==' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(71,12): error TS2365: Operator '==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(72,12): error TS2365: Operator '==' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(73,12): error TS2365: Operator '==' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(75,12): error TS2365: Operator '==' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(76,12): error TS2365: Operator '==' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(77,12): error TS2365: Operator '==' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(78,12): error TS2365: Operator '==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(81,12): error TS2365: Operator '!=' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(82,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(83,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(84,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(86,12): error TS2365: Operator '!=' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(87,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(88,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(89,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(92,12): error TS2365: Operator '===' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(93,12): error TS2365: Operator '===' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(94,12): error TS2365: Operator '===' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(95,12): error TS2365: Operator '===' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(97,12): error TS2365: Operator '===' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(98,12): error TS2365: Operator '===' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(99,12): error TS2365: Operator '===' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(100,12): error TS2365: Operator '===' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(103,12): error TS2365: Operator '!==' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(104,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(105,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(106,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(108,12): error TS2365: Operator '!==' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(109,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(110,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(111,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. -==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts (64 errors) ==== +==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts (48 errors) ==== class Base { public a: string; } @@ -100,8 +84,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~ !!! error TS2365: Operator '<' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r1a4 = a4 < b4; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r1b1 = b1 < a1; ~~~~~~~ @@ -113,8 +95,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~ !!! error TS2365: Operator '<' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r1b4 = b4 < a4; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator > var r2a1 = a1 > b1; @@ -127,8 +107,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~ !!! error TS2365: Operator '>' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r2a4 = a4 > b4; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r2b1 = b1 > a1; ~~~~~~~ @@ -140,8 +118,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~ !!! error TS2365: Operator '>' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r2b4 = b4 > a4; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator <= var r3a1 = a1 <= b1; @@ -154,8 +130,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r3a4 = a4 <= b4; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r3b1 = b1 <= a1; ~~~~~~~~ @@ -167,8 +141,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r3b4 = b4 <= a4; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator >= var r4a1 = a1 >= b1; @@ -181,8 +153,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r4a4 = a4 >= b4; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r4b1 = b1 >= a1; ~~~~~~~~ @@ -194,8 +164,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r4b4 = b4 >= a4; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator == var r5a1 = a1 == b1; @@ -208,8 +176,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '==' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r5a4 = a4 == b4; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r5b1 = b1 == a1; ~~~~~~~~ @@ -221,8 +187,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '==' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r5b4 = b4 == a4; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator != var r6a1 = a1 != b1; @@ -235,8 +199,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r6a4 = a4 != b4; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r6b1 = b1 != a1; ~~~~~~~~ @@ -248,8 +210,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r6b4 = b4 != a4; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator === var r7a1 = a1 === b1; @@ -262,8 +222,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~~ !!! error TS2365: Operator '===' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r7a4 = a4 === b4; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r7b1 = b1 === a1; ~~~~~~~~~ @@ -275,8 +233,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~~ !!! error TS2365: Operator '===' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r7b4 = b4 === a4; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator !== var r8a1 = a1 !== b1; @@ -289,8 +245,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~~ !!! error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r8a4 = a4 !== b4; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r8b1 = b1 !== a1; ~~~~~~~~~ @@ -301,6 +255,4 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r8b3 = b3 !== a3; ~~~~~~~~~ !!! error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. - var r8b4 = b4 !== a4; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. \ No newline at end of file + var r8b4 = b4 !== a4; \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt b/tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt deleted file mode 100644 index ac8063a4378..00000000000 --- a/tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/compiler/contextualTypingOfObjectLiterals.ts(4,1): error TS2322: Type '{ x: string; }' is not assignable to type '{ [x: string]: string; }'. - Index signature is missing in type '{ x: string; }'. -tests/cases/compiler/contextualTypingOfObjectLiterals.ts(10,3): error TS2345: Argument of type '{ x: string; }' is not assignable to parameter of type '{ [s: string]: string; }'. - Index signature is missing in type '{ x: string; }'. - - -==== tests/cases/compiler/contextualTypingOfObjectLiterals.ts (2 errors) ==== - var obj1: { [x: string]: string; }; - var obj2 = {x: ""}; - obj1 = {}; // Ok - obj1 = obj2; // Error - indexer doesn't match - ~~~~ -!!! error TS2322: Type '{ x: string; }' is not assignable to type '{ [x: string]: string; }'. -!!! error TS2322: Index signature is missing in type '{ x: string; }'. - - function f(x: { [s: string]: string }) { } - - f({}); // Ok - f(obj1); // Ok - f(obj2); // Error - indexer doesn't match - ~~~~ -!!! error TS2345: Argument of type '{ x: string; }' is not assignable to parameter of type '{ [s: string]: string; }'. -!!! error TS2345: Index signature is missing in type '{ x: string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingOfObjectLiterals.symbols b/tests/baselines/reference/contextualTypingOfObjectLiterals.symbols new file mode 100644 index 00000000000..afa34cfe481 --- /dev/null +++ b/tests/baselines/reference/contextualTypingOfObjectLiterals.symbols @@ -0,0 +1,32 @@ +=== tests/cases/compiler/contextualTypingOfObjectLiterals.ts === +var obj1: { [x: string]: string; }; +>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3)) +>x : Symbol(x, Decl(contextualTypingOfObjectLiterals.ts, 0, 13)) + +var obj2 = {x: ""}; +>obj2 : Symbol(obj2, Decl(contextualTypingOfObjectLiterals.ts, 1, 3)) +>x : Symbol(x, Decl(contextualTypingOfObjectLiterals.ts, 1, 12)) + +obj1 = {}; // Ok +>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3)) + +obj1 = obj2; // Error - indexer doesn't match +>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3)) +>obj2 : Symbol(obj2, Decl(contextualTypingOfObjectLiterals.ts, 1, 3)) + +function f(x: { [s: string]: string }) { } +>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12)) +>x : Symbol(x, Decl(contextualTypingOfObjectLiterals.ts, 5, 11)) +>s : Symbol(s, Decl(contextualTypingOfObjectLiterals.ts, 5, 17)) + +f({}); // Ok +>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12)) + +f(obj1); // Ok +>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12)) +>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3)) + +f(obj2); // Error - indexer doesn't match +>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12)) +>obj2 : Symbol(obj2, Decl(contextualTypingOfObjectLiterals.ts, 1, 3)) + diff --git a/tests/baselines/reference/contextualTypingOfObjectLiterals.types b/tests/baselines/reference/contextualTypingOfObjectLiterals.types new file mode 100644 index 00000000000..5b3068e8029 --- /dev/null +++ b/tests/baselines/reference/contextualTypingOfObjectLiterals.types @@ -0,0 +1,41 @@ +=== tests/cases/compiler/contextualTypingOfObjectLiterals.ts === +var obj1: { [x: string]: string; }; +>obj1 : { [x: string]: string; } +>x : string + +var obj2 = {x: ""}; +>obj2 : { x: string; } +>{x: ""} : { x: string; } +>x : string +>"" : string + +obj1 = {}; // Ok +>obj1 = {} : { [x: string]: undefined; } +>obj1 : { [x: string]: string; } +>{} : { [x: string]: undefined; } + +obj1 = obj2; // Error - indexer doesn't match +>obj1 = obj2 : { x: string; } +>obj1 : { [x: string]: string; } +>obj2 : { x: string; } + +function f(x: { [s: string]: string }) { } +>f : (x: { [s: string]: string; }) => void +>x : { [s: string]: string; } +>s : string + +f({}); // Ok +>f({}) : void +>f : (x: { [s: string]: string; }) => void +>{} : { [x: string]: undefined; } + +f(obj1); // Ok +>f(obj1) : void +>f : (x: { [s: string]: string; }) => void +>obj1 : { [x: string]: string; } + +f(obj2); // Error - indexer doesn't match +>f(obj2) : void +>f : (x: { [s: string]: string; }) => void +>obj2 : { x: string; } + diff --git a/tests/baselines/reference/indexerAssignability.errors.txt b/tests/baselines/reference/indexerAssignability.errors.txt deleted file mode 100644 index 44c2184517e..00000000000 --- a/tests/baselines/reference/indexerAssignability.errors.txt +++ /dev/null @@ -1,28 +0,0 @@ -tests/cases/compiler/indexerAssignability.ts(5,1): error TS2322: Type '{ [n: number]: string; }' is not assignable to type '{ [s: string]: string; }'. - Index signature is missing in type '{ [n: number]: string; }'. -tests/cases/compiler/indexerAssignability.ts(6,1): error TS2322: Type '{}' is not assignable to type '{ [s: string]: string; }'. - Index signature is missing in type '{}'. -tests/cases/compiler/indexerAssignability.ts(8,1): error TS2322: Type '{}' is not assignable to type '{ [n: number]: string; }'. - Index signature is missing in type '{}'. - - -==== tests/cases/compiler/indexerAssignability.ts (3 errors) ==== - var a: { [s: string]: string; }; - var b: { [n: number]: string; }; - var c: {}; - - a = b; - ~ -!!! error TS2322: Type '{ [n: number]: string; }' is not assignable to type '{ [s: string]: string; }'. -!!! error TS2322: Index signature is missing in type '{ [n: number]: string; }'. - a = c; - ~ -!!! error TS2322: Type '{}' is not assignable to type '{ [s: string]: string; }'. -!!! error TS2322: Index signature is missing in type '{}'. - b = a; - b = c; - ~ -!!! error TS2322: Type '{}' is not assignable to type '{ [n: number]: string; }'. -!!! error TS2322: Index signature is missing in type '{}'. - c = a; - c = b; \ No newline at end of file diff --git a/tests/baselines/reference/indexerAssignability.symbols b/tests/baselines/reference/indexerAssignability.symbols new file mode 100644 index 00000000000..379a2885e2c --- /dev/null +++ b/tests/baselines/reference/indexerAssignability.symbols @@ -0,0 +1,36 @@ +=== tests/cases/compiler/indexerAssignability.ts === +var a: { [s: string]: string; }; +>a : Symbol(a, Decl(indexerAssignability.ts, 0, 3)) +>s : Symbol(s, Decl(indexerAssignability.ts, 0, 10)) + +var b: { [n: number]: string; }; +>b : Symbol(b, Decl(indexerAssignability.ts, 1, 3)) +>n : Symbol(n, Decl(indexerAssignability.ts, 1, 10)) + +var c: {}; +>c : Symbol(c, Decl(indexerAssignability.ts, 2, 3)) + +a = b; +>a : Symbol(a, Decl(indexerAssignability.ts, 0, 3)) +>b : Symbol(b, Decl(indexerAssignability.ts, 1, 3)) + +a = c; +>a : Symbol(a, Decl(indexerAssignability.ts, 0, 3)) +>c : Symbol(c, Decl(indexerAssignability.ts, 2, 3)) + +b = a; +>b : Symbol(b, Decl(indexerAssignability.ts, 1, 3)) +>a : Symbol(a, Decl(indexerAssignability.ts, 0, 3)) + +b = c; +>b : Symbol(b, Decl(indexerAssignability.ts, 1, 3)) +>c : Symbol(c, Decl(indexerAssignability.ts, 2, 3)) + +c = a; +>c : Symbol(c, Decl(indexerAssignability.ts, 2, 3)) +>a : Symbol(a, Decl(indexerAssignability.ts, 0, 3)) + +c = b; +>c : Symbol(c, Decl(indexerAssignability.ts, 2, 3)) +>b : Symbol(b, Decl(indexerAssignability.ts, 1, 3)) + diff --git a/tests/baselines/reference/indexerAssignability.types b/tests/baselines/reference/indexerAssignability.types new file mode 100644 index 00000000000..bd301b59224 --- /dev/null +++ b/tests/baselines/reference/indexerAssignability.types @@ -0,0 +1,42 @@ +=== tests/cases/compiler/indexerAssignability.ts === +var a: { [s: string]: string; }; +>a : { [s: string]: string; } +>s : string + +var b: { [n: number]: string; }; +>b : { [n: number]: string; } +>n : number + +var c: {}; +>c : {} + +a = b; +>a = b : { [n: number]: string; } +>a : { [s: string]: string; } +>b : { [n: number]: string; } + +a = c; +>a = c : {} +>a : { [s: string]: string; } +>c : {} + +b = a; +>b = a : { [s: string]: string; } +>b : { [n: number]: string; } +>a : { [s: string]: string; } + +b = c; +>b = c : {} +>b : { [n: number]: string; } +>c : {} + +c = a; +>c = a : { [s: string]: string; } +>c : {} +>a : { [s: string]: string; } + +c = b; +>c = b : { [n: number]: string; } +>c : {} +>b : { [n: number]: string; } + diff --git a/tests/baselines/reference/numericIndexerConstraint2.errors.txt b/tests/baselines/reference/numericIndexerConstraint2.errors.txt index 385efbcead2..5c0337acc32 100644 --- a/tests/baselines/reference/numericIndexerConstraint2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstraint2.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/numericIndexerConstraint2.ts(4,1): error TS2322: Type '{ one: number; }' is not assignable to type '{ [index: string]: Foo; }'. - Index signature is missing in type '{ one: number; }'. + Property 'one' is incompatible with index signature. + Type 'number' is not assignable to type 'Foo'. ==== tests/cases/compiler/numericIndexerConstraint2.ts (1 errors) ==== @@ -9,4 +10,5 @@ tests/cases/compiler/numericIndexerConstraint2.ts(4,1): error TS2322: Type '{ on x = a; ~ !!! error TS2322: Type '{ one: number; }' is not assignable to type '{ [index: string]: Foo; }'. -!!! error TS2322: Index signature is missing in type '{ one: number; }'. \ No newline at end of file +!!! error TS2322: Property 'one' is incompatible with index signature. +!!! error TS2322: Type 'number' is not assignable to type 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/numericIndexerConstraint5.errors.txt b/tests/baselines/reference/numericIndexerConstraint5.errors.txt index 98acc65eeb7..cb888de08c4 100644 --- a/tests/baselines/reference/numericIndexerConstraint5.errors.txt +++ b/tests/baselines/reference/numericIndexerConstraint5.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/numericIndexerConstraint5.ts(2,5): error TS2322: Type '{ 0: Date; name: string; }' is not assignable to type '{ [name: number]: string; }'. - Index signature is missing in type '{ 0: Date; name: string; }'. + Property '0' is incompatible with index signature. + Type 'Date' is not assignable to type 'string'. ==== tests/cases/compiler/numericIndexerConstraint5.ts (1 errors) ==== @@ -7,4 +8,5 @@ tests/cases/compiler/numericIndexerConstraint5.ts(2,5): error TS2322: Type '{ 0: var z: { [name: number]: string } = x; ~ !!! error TS2322: Type '{ 0: Date; name: string; }' is not assignable to type '{ [name: number]: string; }'. -!!! error TS2322: Index signature is missing in type '{ 0: Date; name: string; }'. \ No newline at end of file +!!! error TS2322: Property '0' is incompatible with index signature. +!!! error TS2322: Type 'Date' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/stringIndexerAssignments1.errors.txt b/tests/baselines/reference/stringIndexerAssignments1.errors.txt index 908371bc7dd..ac99b239779 100644 --- a/tests/baselines/reference/stringIndexerAssignments1.errors.txt +++ b/tests/baselines/reference/stringIndexerAssignments1.errors.txt @@ -1,18 +1,13 @@ -tests/cases/compiler/stringIndexerAssignments1.ts(4,1): error TS2322: Type '{ one: string; }' is not assignable to type '{ [index: string]: string; one: string; }'. - Index signature is missing in type '{ one: string; }'. tests/cases/compiler/stringIndexerAssignments1.ts(5,1): error TS2322: Type '{ one: number; two: string; }' is not assignable to type '{ [index: string]: string; one: string; }'. Types of property 'one' are incompatible. Type 'number' is not assignable to type 'string'. -==== tests/cases/compiler/stringIndexerAssignments1.ts (2 errors) ==== +==== tests/cases/compiler/stringIndexerAssignments1.ts (1 errors) ==== var x: { [index: string]: string; one: string; }; var a: { one: string; }; var b: { one: number; two: string; }; x = a; - ~ -!!! error TS2322: Type '{ one: string; }' is not assignable to type '{ [index: string]: string; one: string; }'. -!!! error TS2322: Index signature is missing in type '{ one: string; }'. x = b; // error ~ !!! error TS2322: Type '{ one: number; two: string; }' is not assignable to type '{ [index: string]: string; one: string; }'. From 040effd603cf870eaef49d912403a597a7714950 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 9 Feb 2016 15:35:55 -0800 Subject: [PATCH 044/297] Include index signatures in object literal types only when computed properties are present --- src/compiler/checker.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2f236ed6e44..e6dec1d45ad 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8288,6 +8288,7 @@ namespace ts { const contextualTypeHasPattern = contextualType && contextualType.pattern && (contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression); let typeFlags: TypeFlags = 0; + let hasDynamicProperties = false; let patternWithComputedProperties = false; for (const memberDecl of node.properties) { @@ -8353,7 +8354,10 @@ namespace ts { checkAccessorDeclaration(memberDecl); } - if (!hasDynamicName(memberDecl)) { + if (hasDynamicName(memberDecl)) { + hasDynamicProperties = true; + } + else { propertiesTable[member.name] = member; } propertiesArray.push(member); @@ -8385,7 +8389,7 @@ namespace ts { return result; function getIndexInfo(kind: IndexKind) { - if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { + if (hasDynamicProperties && contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { const propTypes: Type[] = []; for (let i = 0; i < propertiesArray.length; i++) { const propertyDecl = node.properties[i]; From d9fc61b32fb7479f5b10cca2a3efa943dadae24e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 9 Feb 2016 15:36:40 -0800 Subject: [PATCH 045/297] Accepting new baselines --- .../reference/badOverloadError.types | 2 +- .../bestCommonTypeWithContextualTyping.types | 2 +- ...ndAdditionAssignmentLHSCanBeAssigned.types | 2 +- .../reference/constEnumPropertyAccess1.types | 2 +- .../reference/contextualTypeAny.errors.txt | 15 ++++++++++++++ .../reference/contextualTypeAny.symbols | 15 -------------- .../reference/contextualTypeAny.types | 19 ------------------ .../contextualTypeArrayReturnType.types | 10 +++++----- ...tualTypeWithUnionTypeIndexSignatures.types | 20 +++++++++---------- .../contextualTypingOfObjectLiterals.types | 6 +++--- .../declarationsAndAssignments.errors.txt | 8 ++++---- ...bjectBindingPatternAndAssignment1ES5.types | 6 +++--- ...bjectBindingPatternAndAssignment1ES6.types | 6 +++--- ...ndingClassFromAliasAndUsageInIndexer.types | 2 +- .../genericBaseClassLiteralProperty2.types | 4 ++-- .../genericCallWithTupleType.errors.txt | 8 ++++---- ...nericWithIndexerOfTypeParameterType1.types | 2 +- .../indexSignaturesInferentialTyping.types | 12 +++++------ tests/baselines/reference/indexer.types | 2 +- tests/baselines/reference/indexer2.types | 2 +- tests/baselines/reference/indexer3.types | 2 +- tests/baselines/reference/indexerA.types | 2 +- ...nferentialTypingObjectLiteralMethod2.types | 4 ++-- .../inferentialTypingUsingApparentType3.types | 12 +++++------ .../reference/interfaceContextualType.types | 8 ++++---- .../reference/noErrorsInCallback.errors.txt | 8 ++++---- .../noImplicitAnyIndexingSuppressed.types | 2 +- ...rConstrainsPropertyDeclarations.errors.txt | 14 ++++++------- ...ConstrainsPropertyDeclarations2.errors.txt | 14 ++++++------- .../reference/numericIndexerConstraint4.types | 2 +- .../reference/numericIndexingResults.types | 4 ++-- tests/baselines/reference/objectIndexer.types | 4 ++-- .../objectLiteralIndexerErrors.errors.txt | 19 ++++++++++++------ .../objectLiteralIndexerNoImplicitAny.types | 2 +- .../reference/objectLiteralIndexers.types | 10 +++++----- ...ectTypesIdentityWithNumericIndexers1.types | 2 +- ...ectTypesIdentityWithNumericIndexers2.types | 2 +- ...ectTypesIdentityWithNumericIndexers3.types | 2 +- ...bjectTypesIdentityWithStringIndexers.types | 2 +- ...jectTypesIdentityWithStringIndexers2.types | 2 +- .../operatorsAndIntersectionTypes.types | 4 ++-- .../restElementWithNullInitializer.errors.txt | 4 ++-- ...rConstrainsPropertyDeclarations.errors.txt | 14 ++++++------- ...ConstrainsPropertyDeclarations2.errors.txt | 8 ++++---- .../reference/stringIndexingResults.types | 2 +- ...tringsArrayTypeDefinedInES5Mode.errors.txt | 8 ++++---- ...ringsArrayTypeNotDefinedES5Mode.errors.txt | 8 ++++---- ...ingsArrayTypeRedefinedInES6Mode.errors.txt | 8 ++++---- .../typeParameterFixingWithConstraints.types | 12 +++++------ .../baselines/reference/underscoreTest1.types | 6 +++--- .../reference/widenedTypes.errors.txt | 8 ++++---- ...wrappedAndRecursiveConstraints4.errors.txt | 4 ++-- 52 files changed, 165 insertions(+), 183 deletions(-) create mode 100644 tests/baselines/reference/contextualTypeAny.errors.txt delete mode 100644 tests/baselines/reference/contextualTypeAny.symbols delete mode 100644 tests/baselines/reference/contextualTypeAny.types diff --git a/tests/baselines/reference/badOverloadError.types b/tests/baselines/reference/badOverloadError.types index b8ae583a73c..198582af2db 100644 --- a/tests/baselines/reference/badOverloadError.types +++ b/tests/baselines/reference/badOverloadError.types @@ -6,6 +6,6 @@ function method() { >dictionary : { [index: string]: string; } ><{ [index: string]: string; }>{} : { [index: string]: string; } >index : string ->{} : { [x: string]: undefined; } +>{} : {} } diff --git a/tests/baselines/reference/bestCommonTypeWithContextualTyping.types b/tests/baselines/reference/bestCommonTypeWithContextualTyping.types index 628fe82012a..5baca43b752 100644 --- a/tests/baselines/reference/bestCommonTypeWithContextualTyping.types +++ b/tests/baselines/reference/bestCommonTypeWithContextualTyping.types @@ -36,7 +36,7 @@ var obj: { [s: string]: Contextual } = { s: e }; // { s: Ellement; [s: string]: >obj : { [s: string]: Contextual; } >s : string >Contextual : Contextual ->{ s: e } : { [x: string]: Ellement; s: Ellement; } +>{ s: e } : { s: Ellement; } >s : Ellement >e : Ellement diff --git a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types index 92835611c6d..e40422450b4 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types +++ b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types @@ -98,7 +98,7 @@ x2 += E.a; x2 += {}; >x2 += {} : string >x2 : string ->{} : { [x: number]: undefined; } +>{} : {} x2 += null; >x2 += null : string diff --git a/tests/baselines/reference/constEnumPropertyAccess1.types b/tests/baselines/reference/constEnumPropertyAccess1.types index 5ed2b932bd0..f0e00fe7717 100644 --- a/tests/baselines/reference/constEnumPropertyAccess1.types +++ b/tests/baselines/reference/constEnumPropertyAccess1.types @@ -35,7 +35,7 @@ var o: { >idx : number } = { ->{ 1: true } : { [x: number]: boolean; 1: boolean; } +>{ 1: true } : { 1: boolean; } 1: true >true : boolean diff --git a/tests/baselines/reference/contextualTypeAny.errors.txt b/tests/baselines/reference/contextualTypeAny.errors.txt new file mode 100644 index 00000000000..09970be986d --- /dev/null +++ b/tests/baselines/reference/contextualTypeAny.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/contextualTypeAny.ts(3,5): error TS2322: Type '{ p: string; q: any; }' is not assignable to type '{ [s: string]: number; }'. + Property 'p' is incompatible with index signature. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/compiler/contextualTypeAny.ts (1 errors) ==== + var x: any; + + var obj: { [s: string]: number } = { p: "", q: x }; + ~~~ +!!! error TS2322: Type '{ p: string; q: any; }' is not assignable to type '{ [s: string]: number; }'. +!!! error TS2322: Property 'p' is incompatible with index signature. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + + var arr: number[] = ["", x]; \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypeAny.symbols b/tests/baselines/reference/contextualTypeAny.symbols deleted file mode 100644 index 5132c948a2e..00000000000 --- a/tests/baselines/reference/contextualTypeAny.symbols +++ /dev/null @@ -1,15 +0,0 @@ -=== tests/cases/compiler/contextualTypeAny.ts === -var x: any; ->x : Symbol(x, Decl(contextualTypeAny.ts, 0, 3)) - -var obj: { [s: string]: number } = { p: "", q: x }; ->obj : Symbol(obj, Decl(contextualTypeAny.ts, 2, 3)) ->s : Symbol(s, Decl(contextualTypeAny.ts, 2, 12)) ->p : Symbol(p, Decl(contextualTypeAny.ts, 2, 36)) ->q : Symbol(q, Decl(contextualTypeAny.ts, 2, 43)) ->x : Symbol(x, Decl(contextualTypeAny.ts, 0, 3)) - -var arr: number[] = ["", x]; ->arr : Symbol(arr, Decl(contextualTypeAny.ts, 4, 3)) ->x : Symbol(x, Decl(contextualTypeAny.ts, 0, 3)) - diff --git a/tests/baselines/reference/contextualTypeAny.types b/tests/baselines/reference/contextualTypeAny.types deleted file mode 100644 index cace92d6567..00000000000 --- a/tests/baselines/reference/contextualTypeAny.types +++ /dev/null @@ -1,19 +0,0 @@ -=== tests/cases/compiler/contextualTypeAny.ts === -var x: any; ->x : any - -var obj: { [s: string]: number } = { p: "", q: x }; ->obj : { [s: string]: number; } ->s : string ->{ p: "", q: x } : { [x: string]: any; p: string; q: any; } ->p : string ->"" : string ->q : any ->x : any - -var arr: number[] = ["", x]; ->arr : number[] ->["", x] : any[] ->"" : string ->x : any - diff --git a/tests/baselines/reference/contextualTypeArrayReturnType.types b/tests/baselines/reference/contextualTypeArrayReturnType.types index f270b33f568..6c91fd7b8b9 100644 --- a/tests/baselines/reference/contextualTypeArrayReturnType.types +++ b/tests/baselines/reference/contextualTypeArrayReturnType.types @@ -26,18 +26,18 @@ interface Transform3D { var style: IBookStyle = { >style : IBookStyle >IBookStyle : IBookStyle ->{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => { [x: string]: any; 'ry': any; }[]; } +>{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => { 'ry': any; }[]; } initialLeftPageTransforms: (width: number) => { ->initialLeftPageTransforms : (width: number) => { [x: string]: any; 'ry': any; }[] ->(width: number) => { return [ {'ry': null } ]; } : (width: number) => { [x: string]: any; 'ry': any; }[] +>initialLeftPageTransforms : (width: number) => { 'ry': any; }[] +>(width: number) => { return [ {'ry': null } ]; } : (width: number) => { 'ry': any; }[] >width : number return [ ->[ {'ry': null } ] : { [x: string]: null; 'ry': null; }[] +>[ {'ry': null } ] : { 'ry': null; }[] {'ry': null } ->{'ry': null } : { [x: string]: null; 'ry': null; } +>{'ry': null } : { 'ry': null; } >null : null ]; diff --git a/tests/baselines/reference/contextualTypeWithUnionTypeIndexSignatures.types b/tests/baselines/reference/contextualTypeWithUnionTypeIndexSignatures.types index 2f24ad08227..965e4d21d99 100644 --- a/tests/baselines/reference/contextualTypeWithUnionTypeIndexSignatures.types +++ b/tests/baselines/reference/contextualTypeWithUnionTypeIndexSignatures.types @@ -69,7 +69,7 @@ var x: IWithNoStringIndexSignature | IWithStringIndexSignature1 = { z: a => a }; >x : IWithNoStringIndexSignature | IWithStringIndexSignature1 >IWithNoStringIndexSignature : IWithNoStringIndexSignature >IWithStringIndexSignature1 : IWithStringIndexSignature1 ->{ z: a => a } : { [x: string]: (a: number) => number; z: (a: number) => number; } +>{ z: a => a } : { z: (a: number) => number; } >z : (a: number) => number >a => a : (a: number) => number >a : number @@ -79,7 +79,7 @@ var x: IWithNoStringIndexSignature | IWithStringIndexSignature1 = { foo: a => a >x : IWithNoStringIndexSignature | IWithStringIndexSignature1 >IWithNoStringIndexSignature : IWithNoStringIndexSignature >IWithStringIndexSignature1 : IWithStringIndexSignature1 ->{ foo: a => a } : { [x: string]: (a: any) => any; foo: (a: any) => any; } +>{ foo: a => a } : { foo: (a: any) => any; } >foo : (a: any) => any >a => a : (a: any) => any >a : any @@ -89,7 +89,7 @@ var x: IWithNoStringIndexSignature | IWithStringIndexSignature1 = { foo: "hello" >x : IWithNoStringIndexSignature | IWithStringIndexSignature1 >IWithNoStringIndexSignature : IWithNoStringIndexSignature >IWithStringIndexSignature1 : IWithStringIndexSignature1 ->{ foo: "hello" } : { [x: string]: string; foo: string; } +>{ foo: "hello" } : { foo: string; } >foo : string >"hello" : string @@ -97,7 +97,7 @@ var x2: IWithStringIndexSignature1 | IWithStringIndexSignature2 = { z: a => a.to >x2 : IWithStringIndexSignature1 | IWithStringIndexSignature2 >IWithStringIndexSignature1 : IWithStringIndexSignature1 >IWithStringIndexSignature2 : IWithStringIndexSignature2 ->{ z: a => a.toString() } : { [x: string]: (a: number) => string; z: (a: number) => string; } +>{ z: a => a.toString() } : { z: (a: number) => string; } >z : (a: number) => string >a => a.toString() : (a: number) => string >a : number @@ -110,7 +110,7 @@ var x2: IWithStringIndexSignature1 | IWithStringIndexSignature2 = { z: a => a }; >x2 : IWithStringIndexSignature1 | IWithStringIndexSignature2 >IWithStringIndexSignature1 : IWithStringIndexSignature1 >IWithStringIndexSignature2 : IWithStringIndexSignature2 ->{ z: a => a } : { [x: string]: (a: number) => number; z: (a: number) => number; } +>{ z: a => a } : { z: (a: number) => number; } >z : (a: number) => number >a => a : (a: number) => number >a : number @@ -124,7 +124,7 @@ var x3: IWithNoNumberIndexSignature | IWithNumberIndexSignature1 = { 1: a => a } >x3 : IWithNoNumberIndexSignature | IWithNumberIndexSignature1 >IWithNoNumberIndexSignature : IWithNoNumberIndexSignature >IWithNumberIndexSignature1 : IWithNumberIndexSignature1 ->{ 1: a => a } : { [x: number]: (a: number) => number; 1: (a: number) => number; } +>{ 1: a => a } : { 1: (a: number) => number; } >a => a : (a: number) => number >a : number >a : number @@ -133,7 +133,7 @@ var x3: IWithNoNumberIndexSignature | IWithNumberIndexSignature1 = { 0: a => a } >x3 : IWithNoNumberIndexSignature | IWithNumberIndexSignature1 >IWithNoNumberIndexSignature : IWithNoNumberIndexSignature >IWithNumberIndexSignature1 : IWithNumberIndexSignature1 ->{ 0: a => a } : { [x: number]: (a: any) => any; 0: (a: any) => any; } +>{ 0: a => a } : { 0: (a: any) => any; } >a => a : (a: any) => any >a : any >a : any @@ -142,14 +142,14 @@ var x3: IWithNoNumberIndexSignature | IWithNumberIndexSignature1 = { 0: "hello" >x3 : IWithNoNumberIndexSignature | IWithNumberIndexSignature1 >IWithNoNumberIndexSignature : IWithNoNumberIndexSignature >IWithNumberIndexSignature1 : IWithNumberIndexSignature1 ->{ 0: "hello" } : { [x: number]: string; 0: string; } +>{ 0: "hello" } : { 0: string; } >"hello" : string var x4: IWithNumberIndexSignature1 | IWithNumberIndexSignature2 = { 1: a => a.toString() }; // a should be number >x4 : IWithNumberIndexSignature1 | IWithNumberIndexSignature2 >IWithNumberIndexSignature1 : IWithNumberIndexSignature1 >IWithNumberIndexSignature2 : IWithNumberIndexSignature2 ->{ 1: a => a.toString() } : { [x: number]: (a: number) => string; 1: (a: number) => string; } +>{ 1: a => a.toString() } : { 1: (a: number) => string; } >a => a.toString() : (a: number) => string >a : number >a.toString() : string @@ -161,7 +161,7 @@ var x4: IWithNumberIndexSignature1 | IWithNumberIndexSignature2 = { 1: a => a }; >x4 : IWithNumberIndexSignature1 | IWithNumberIndexSignature2 >IWithNumberIndexSignature1 : IWithNumberIndexSignature1 >IWithNumberIndexSignature2 : IWithNumberIndexSignature2 ->{ 1: a => a } : { [x: number]: (a: number) => number; 1: (a: number) => number; } +>{ 1: a => a } : { 1: (a: number) => number; } >a => a : (a: number) => number >a : number >a : number diff --git a/tests/baselines/reference/contextualTypingOfObjectLiterals.types b/tests/baselines/reference/contextualTypingOfObjectLiterals.types index 5b3068e8029..a99fb2f39af 100644 --- a/tests/baselines/reference/contextualTypingOfObjectLiterals.types +++ b/tests/baselines/reference/contextualTypingOfObjectLiterals.types @@ -10,9 +10,9 @@ var obj2 = {x: ""}; >"" : string obj1 = {}; // Ok ->obj1 = {} : { [x: string]: undefined; } +>obj1 = {} : {} >obj1 : { [x: string]: string; } ->{} : { [x: string]: undefined; } +>{} : {} obj1 = obj2; // Error - indexer doesn't match >obj1 = obj2 : { x: string; } @@ -27,7 +27,7 @@ function f(x: { [s: string]: string }) { } f({}); // Ok >f({}) : void >f : (x: { [s: string]: string; }) => void ->{} : { [x: string]: undefined; } +>{} : {} f(obj1); // Ok >f(obj1) : void diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 7c4671022ea..517eaafe4ab 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -11,8 +11,8 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,13): 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(67,9): error TS2461: Type '{}' is not an array type. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ 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(74,11): error TS2459: Type 'undefined[]' has no property 'a' and no string index signature. @@ -122,10 +122,10 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f9() { var [a, b] = {}; // Error, not array type ~~~~~~ -!!! error TS2461: Type '{ [x: number]: undefined; }' is not an array type. +!!! error TS2461: Type '{}' is not an array type. var [c, d] = { 0: 10, 1: 20 }; // Error, not array type ~~~~~~ -!!! error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. +!!! error TS2461: Type '{ 0: number; 1: number; }' is not an array type. var [e, f] = [10, 20]; } diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types index 476b5bee0cc..cb6052d93fd 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types @@ -69,7 +69,7 @@ function foo(): F { >F : F return { ->{ 1: true } : { [x: number]: boolean; 1: boolean; } +>{ 1: true } : { 1: boolean; } 1: true >true : boolean @@ -82,7 +82,7 @@ function bar(): F { >F : F return { ->{ 2: true } : { [x: number]: boolean; 2: boolean; } +>{ 2: true } : { 2: boolean; } 2: true >true : boolean @@ -114,7 +114,7 @@ function foo1(): F1 { >F1 : F1 return { ->{ "prop1": 2 } : { [x: string]: number; "prop1": number; } +>{ "prop1": 2 } : { "prop1": number; } "prop1": 2 >2 : number diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types index 7a7f631eddf..2d77c20f65b 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types @@ -69,7 +69,7 @@ function foo(): F { >F : F return { ->{ 1: true } : { [x: number]: boolean; 1: boolean; } +>{ 1: true } : { 1: boolean; } 1: true >true : boolean @@ -82,7 +82,7 @@ function bar(): F { >F : F return { ->{ 2: true } : { [x: number]: boolean; 2: boolean; } +>{ 2: true } : { 2: boolean; } 2: true >true : boolean @@ -114,7 +114,7 @@ function foo1(): F1 { >F1 : F1 return { ->{ "prop1": 2 } : { [x: string]: number; "prop1": number; } +>{ "prop1": 2 } : { "prop1": number; } "prop1": 2 >2 : number diff --git a/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types b/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types index e1bfd195698..9825a75a220 100644 --- a/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types +++ b/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types @@ -26,7 +26,7 @@ var moduleMap: { [key: string]: IHasVisualizationModel } = { >moduleMap : { [key: string]: IHasVisualizationModel; } >key : string >IHasVisualizationModel : IHasVisualizationModel ->{ "moduleA": moduleA, "moduleB": moduleB} : { [x: string]: typeof moduleA; "moduleA": typeof moduleA; "moduleB": typeof moduleB; } +>{ "moduleA": moduleA, "moduleB": moduleB} : { "moduleA": typeof moduleA; "moduleB": typeof moduleB; } "moduleA": moduleA, >moduleA : typeof moduleA diff --git a/tests/baselines/reference/genericBaseClassLiteralProperty2.types b/tests/baselines/reference/genericBaseClassLiteralProperty2.types index d7d512165f0..3e320824925 100644 --- a/tests/baselines/reference/genericBaseClassLiteralProperty2.types +++ b/tests/baselines/reference/genericBaseClassLiteralProperty2.types @@ -14,11 +14,11 @@ class BaseCollection2 { constructor() { this._itemsByKey = {}; ->this._itemsByKey = {} : { [x: string]: undefined; } +>this._itemsByKey = {} : {} >this._itemsByKey : { [key: string]: TItem; } >this : this >_itemsByKey : { [key: string]: TItem; } ->{} : { [x: string]: undefined; } +>{} : {} } } diff --git a/tests/baselines/reference/genericCallWithTupleType.errors.txt b/tests/baselines/reference/genericCallWithTupleType.errors.txt index d03f8d5e68a..bcf580320e5 100644 --- a/tests/baselines/reference/genericCallWithTupleType.errors.txt +++ b/tests/baselines/reference/genericCallWithTupleType.errors.txt @@ -9,9 +9,9 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(22,1): error TS2322: Type '[number, string]' is not assignable to type '[string, number]'. Types of property '0' are incompatible. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(23,1): error TS2322: Type '[{ [x: number]: undefined; }, {}]' is not assignable to type '[string, number]'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(23,1): error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]'. Types of property '0' are incompatible. - Type '{ [x: number]: undefined; }' is not assignable to type 'string'. + Type '{}' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(24,1): error TS2322: Type '[{}]' is not assignable to type '[{}, {}]'. Property '1' is missing in type '[{}]'. @@ -55,9 +55,9 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup !!! error TS2322: Type 'number' is not assignable to type 'string'. i1.tuple1 = [{}, {}]; ~~~~~~~~~ -!!! error TS2322: Type '[{ [x: number]: undefined; }, {}]' is not assignable to type '[string, number]'. +!!! error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]'. !!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type '{ [x: number]: undefined; }' is not assignable to type 'string'. +!!! error TS2322: Type '{}' is not assignable to type 'string'. i2.tuple1 = [{}]; ~~~~~~~~~ !!! error TS2322: Type '[{}]' is not assignable to type '[{}, {}]'. diff --git a/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types b/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types index 337993dc2a6..a316773e5c8 100644 --- a/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types +++ b/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types @@ -8,7 +8,7 @@ class LazyArray { ><{ [objectId: string]: T; }>{} : { [objectId: string]: T; } >objectId : string >T : T ->{} : { [x: string]: undefined; } +>{} : {} array() { >array : () => { [objectId: string]: T; } diff --git a/tests/baselines/reference/indexSignaturesInferentialTyping.types b/tests/baselines/reference/indexSignaturesInferentialTyping.types index 328dbc18e4f..8545a7d4ca9 100644 --- a/tests/baselines/reference/indexSignaturesInferentialTyping.types +++ b/tests/baselines/reference/indexSignaturesInferentialTyping.types @@ -21,15 +21,15 @@ var x1 = foo({ 0: 0, 1: 1 }); // type should be number >x1 : number >foo({ 0: 0, 1: 1 }) : number >foo : (items: { [index: number]: T; }) => T ->{ 0: 0, 1: 1 } : { [x: number]: number; 0: number; 1: number; } +>{ 0: 0, 1: 1 } : { 0: number; 1: number; } >0 : number >1 : number var x2 = foo({ zero: 0, one: 1 }); ->x2 : any ->foo({ zero: 0, one: 1 }) : any +>x2 : {} +>foo({ zero: 0, one: 1 }) : {} >foo : (items: { [index: number]: T; }) => T ->{ zero: 0, one: 1 } : { [x: number]: undefined; zero: number; one: number; } +>{ zero: 0, one: 1 } : { zero: number; one: number; } >zero : number >0 : number >one : number @@ -39,7 +39,7 @@ var x3 = bar({ 0: 0, 1: 1 }); >x3 : number >bar({ 0: 0, 1: 1 }) : number >bar : (items: { [index: string]: T; }) => T ->{ 0: 0, 1: 1 } : { [x: string]: number; 0: number; 1: number; } +>{ 0: 0, 1: 1 } : { 0: number; 1: number; } >0 : number >1 : number @@ -47,7 +47,7 @@ var x4 = bar({ zero: 0, one: 1 }); // type should be number >x4 : number >bar({ zero: 0, one: 1 }) : number >bar : (items: { [index: string]: T; }) => T ->{ zero: 0, one: 1 } : { [x: string]: number; zero: number; one: number; } +>{ zero: 0, one: 1 } : { zero: number; one: number; } >zero : number >0 : number >one : number diff --git a/tests/baselines/reference/indexer.types b/tests/baselines/reference/indexer.types index a0142bb9383..f24c90f6ea1 100644 --- a/tests/baselines/reference/indexer.types +++ b/tests/baselines/reference/indexer.types @@ -17,7 +17,7 @@ interface JQuery { var jq:JQuery={ 0: { id : "a" }, 1: { id : "b" } }; >jq : JQuery >JQuery : JQuery ->{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: { id: string; }; 0: { id: string; }; 1: { id: string; }; } +>{ 0: { id : "a" }, 1: { id : "b" } } : { 0: { id: string; }; 1: { id: string; }; } >{ id : "a" } : { id: string; } >id : string >"a" : string diff --git a/tests/baselines/reference/indexer2.types b/tests/baselines/reference/indexer2.types index 7f1ccd41cb5..ff82707edd3 100644 --- a/tests/baselines/reference/indexer2.types +++ b/tests/baselines/reference/indexer2.types @@ -17,5 +17,5 @@ var directChildrenMap = {}; >directChildrenMap : IDirectChildrenMap >{} : IDirectChildrenMap >IDirectChildrenMap : IDirectChildrenMap ->{} : { [x: number]: undefined; } +>{} : {} diff --git a/tests/baselines/reference/indexer3.types b/tests/baselines/reference/indexer3.types index 8f0582f782a..28bcd9cab0c 100644 --- a/tests/baselines/reference/indexer3.types +++ b/tests/baselines/reference/indexer3.types @@ -3,7 +3,7 @@ var dateMap: { [x: string]: Date; } = {} >dateMap : { [x: string]: Date; } >x : string >Date : Date ->{} : { [x: string]: undefined; } +>{} : {} var r: Date = dateMap["hello"] // result type includes indexer using BCT >r : Date diff --git a/tests/baselines/reference/indexerA.types b/tests/baselines/reference/indexerA.types index c6ff81b3a26..ee6351eae33 100644 --- a/tests/baselines/reference/indexerA.types +++ b/tests/baselines/reference/indexerA.types @@ -17,7 +17,7 @@ class JQuery { var jq:JQuery={ 0: { id : "a" }, 1: { id : "b" } }; >jq : JQuery >JQuery : JQuery ->{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: { id: string; }; 0: { id: string; }; 1: { id: string; }; } +>{ 0: { id : "a" }, 1: { id : "b" } } : { 0: { id: string; }; 1: { id: string; }; } >{ id : "a" } : { id: string; } >id : string >"a" : string diff --git a/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types b/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types index be937410cef..f70305739b8 100644 --- a/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types +++ b/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types @@ -30,13 +30,13 @@ foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } } >foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }) : string >foo : (x: T, y: Int, z: Int) => T >"" : string ->{ method(p1) { return p1.length } } : { [x: string]: (p1: string) => number; method(p1: string): number; } +>{ method(p1) { return p1.length } } : { method(p1: string): number; } >method : (p1: string) => number >p1 : string >p1.length : number >p1 : string >length : number ->{ method(p2) { return undefined } } : { [x: string]: (p2: number) => any; method(p2: number): any; } +>{ method(p2) { return undefined } } : { method(p2: number): any; } >method : (p2: number) => any >p2 : number >undefined : undefined diff --git a/tests/baselines/reference/inferentialTypingUsingApparentType3.types b/tests/baselines/reference/inferentialTypingUsingApparentType3.types index 9e0a4ceaea6..e375fe981e8 100644 --- a/tests/baselines/reference/inferentialTypingUsingApparentType3.types +++ b/tests/baselines/reference/inferentialTypingUsingApparentType3.types @@ -49,10 +49,10 @@ class ObjectField }> { } var person = new ObjectField({ ->person : ObjectField<{}, { [x: string]: NumberField | CharField; id: NumberField; name: CharField; }> ->new ObjectField({ id: new NumberField(), name: new CharField()}) : ObjectField<{}, { [x: string]: NumberField | CharField; id: NumberField; name: CharField; }> +>person : ObjectField<{}, { id: NumberField; name: CharField; }> +>new ObjectField({ id: new NumberField(), name: new CharField()}) : ObjectField<{}, { id: NumberField; name: CharField; }> >ObjectField : typeof ObjectField ->{ id: new NumberField(), name: new CharField()} : { [x: string]: NumberField | CharField; id: NumberField; name: CharField; } +>{ id: new NumberField(), name: new CharField()} : { id: NumberField; name: CharField; } id: new NumberField(), >id : NumberField @@ -68,8 +68,8 @@ var person = new ObjectField({ person.fields.id; >person.fields.id : NumberField ->person.fields : { [x: string]: NumberField | CharField; id: NumberField; name: CharField; } ->person : ObjectField<{}, { [x: string]: NumberField | CharField; id: NumberField; name: CharField; }> ->fields : { [x: string]: NumberField | CharField; id: NumberField; name: CharField; } +>person.fields : { id: NumberField; name: CharField; } +>person : ObjectField<{}, { id: NumberField; name: CharField; }> +>fields : { id: NumberField; name: CharField; } >id : NumberField diff --git a/tests/baselines/reference/interfaceContextualType.types b/tests/baselines/reference/interfaceContextualType.types index e827f9a9d9b..0e835a2f1f9 100644 --- a/tests/baselines/reference/interfaceContextualType.types +++ b/tests/baselines/reference/interfaceContextualType.types @@ -27,11 +27,11 @@ class Bug { >ok : () => void this.values = {}; ->this.values = {} : { [x: string]: undefined; } +>this.values = {} : {} >this.values : IMap >this : this >values : IMap ->{} : { [x: string]: undefined; } +>{} : {} this.values['comments'] = { italic: true }; >this.values['comments'] = { italic: true } : { italic: boolean; } @@ -48,11 +48,11 @@ class Bug { >shouldBeOK : () => void this.values = { ->this.values = { comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } +>this.values = { comments: { italic: true } } : { comments: { italic: boolean; }; } >this.values : IMap >this : this >values : IMap ->{ comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } +>{ comments: { italic: true } } : { comments: { italic: boolean; }; } comments: { italic: true } >comments : { italic: boolean; } diff --git a/tests/baselines/reference/noErrorsInCallback.errors.txt b/tests/baselines/reference/noErrorsInCallback.errors.txt index 90fdbbd77a5..f0bfe00199e 100644 --- a/tests/baselines/reference/noErrorsInCallback.errors.txt +++ b/tests/baselines/reference/noErrorsInCallback.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/noErrorsInCallback.ts(4,19): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'string'. -tests/cases/compiler/noErrorsInCallback.ts(6,23): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'string'. +tests/cases/compiler/noErrorsInCallback.ts(4,19): error TS2345: Argument of type '{}' is not assignable to parameter of type 'string'. +tests/cases/compiler/noErrorsInCallback.ts(6,23): error TS2345: Argument of type '{}' is not assignable to parameter of type 'string'. ==== tests/cases/compiler/noErrorsInCallback.ts (2 errors) ==== @@ -8,10 +8,10 @@ tests/cases/compiler/noErrorsInCallback.ts(6,23): error TS2345: Argument of type } var one = new Bar({}); // Error ~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'string'. +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'string'. [].forEach(() => { var two = new Bar({}); // No error? ~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'string'. +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'string'. }); \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types index b7b21bf8f92..d82b37e0f9e 100644 --- a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types +++ b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types @@ -87,7 +87,7 @@ interface MyMap { var m: MyMap = { >m : MyMap >MyMap : MyMap ->{ "0": 0, "1": 1, "2": 2, "Okay that's enough for today.": NaN} : { [x: string]: number; "0": number; "1": number; "2": number; "Okay that's enough for today.": number; } +>{ "0": 0, "1": 1, "2": 2, "Okay that's enough for today.": NaN} : { "0": number; "1": number; "2": number; "Okay that's enough for today.": number; } "0": 0, >0 : number diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index 35673eb3072..bb01b2fe125 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -5,10 +5,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(36,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. - Index signatures are incompatible. - Type 'string | number' is not assignable to type 'string'. - Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. + Property '2.0' is incompatible with index signature. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(88,9): error TS2304: Cannot find name 'Myn'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(90,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(93,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -108,10 +107,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: string; } = { ~ -!!! error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. -!!! error TS2322: Index signatures are incompatible. -!!! error TS2322: Type 'string | number' is not assignable to type 'string'. -!!! error TS2322: Type 'number' is not assignable to type 'string'. +!!! error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. +!!! error TS2322: Property '2.0' is incompatible with index signature. +!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, c: () => { }, diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt index ff18160e9a5..332b356c732 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt @@ -1,10 +1,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(16,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(25,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(34,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: A | number; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. - Index signatures are incompatible. - Type 'A | number' is not assignable to type 'A'. - Type 'number' is not assignable to type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. + Property '3.0' is incompatible with index signature. + Type 'number' is not assignable to type 'A'. ==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts (4 errors) ==== @@ -54,10 +53,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: A } = { ~ -!!! error TS2322: Type '{ [x: number]: A | number; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. -!!! error TS2322: Index signatures are incompatible. -!!! error TS2322: Type 'A | number' is not assignable to type 'A'. -!!! error TS2322: Type 'number' is not assignable to type 'A'. +!!! error TS2322: Type '{ 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. +!!! error TS2322: Property '3.0' is incompatible with index signature. +!!! error TS2322: Type 'number' is not assignable to type 'A'. 1.0: new A(), 2.0: new B(), "2.5": new B(), diff --git a/tests/baselines/reference/numericIndexerConstraint4.types b/tests/baselines/reference/numericIndexerConstraint4.types index 97e72b5088d..c8af4d54a9a 100644 --- a/tests/baselines/reference/numericIndexerConstraint4.types +++ b/tests/baselines/reference/numericIndexerConstraint4.types @@ -22,7 +22,7 @@ var x: { >A : A } = { data: new B() } ->{ data: new B() } : { [x: number]: undefined; data: B; } +>{ data: new B() } : { data: B; } >data : B >new B() : B >B : typeof B diff --git a/tests/baselines/reference/numericIndexingResults.types b/tests/baselines/reference/numericIndexingResults.types index 560bbdc74a8..9a060b388e3 100644 --- a/tests/baselines/reference/numericIndexingResults.types +++ b/tests/baselines/reference/numericIndexingResults.types @@ -151,7 +151,7 @@ var r6 = a[3]; var b: { [x: number]: string } = { 1: '', "2": '' } >b : { [x: number]: string; } >x : number ->{ 1: '', "2": '' } : { [x: number]: string; 1: string; "2": string; } +>{ 1: '', "2": '' } : { 1: string; "2": string; } >'' : string >'' : string @@ -194,7 +194,7 @@ var r6 = b[3]; var b2: { [x: number]: string; 1: string; "2": string; } = { 1: '', "2": '' } >b2 : { [x: number]: string; 1: string; "2": string; } >x : number ->{ 1: '', "2": '' } : { [x: number]: string; 1: string; "2": string; } +>{ 1: '', "2": '' } : { 1: string; "2": string; } >'' : string >'' : string diff --git a/tests/baselines/reference/objectIndexer.types b/tests/baselines/reference/objectIndexer.types index 3dcd7bcb77e..b11c475a386 100644 --- a/tests/baselines/reference/objectIndexer.types +++ b/tests/baselines/reference/objectIndexer.types @@ -23,11 +23,11 @@ class Emitter { constructor () { this.listeners = {}; ->this.listeners = {} : { [x: string]: undefined; } +>this.listeners = {} : {} >this.listeners : IMap >this : this >listeners : IMap ->{} : { [x: string]: undefined; } +>{} : {} } } diff --git a/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt b/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt index f825c416311..9d5ff7ea0a2 100644 --- a/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt @@ -1,10 +1,13 @@ -tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2322: Type '{ [x: string]: A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. - Index signatures are incompatible. +tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2322: Type '{ 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. + Property '0' is incompatible with index signature. Type 'A' is not assignable to type 'B'. Property 'y' is missing in type 'A'. +tests/cases/compiler/objectLiteralIndexerErrors.ts(14,1): error TS2322: Type '{ 0: A; x: any; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. + Property '0' is incompatible with index signature. + Type 'A' is not assignable to type 'B'. -==== tests/cases/compiler/objectLiteralIndexerErrors.ts (1 errors) ==== +==== tests/cases/compiler/objectLiteralIndexerErrors.ts (2 errors) ==== interface A { x: number; } @@ -19,8 +22,12 @@ tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2322: Type '{ var o1: { [s: string]: A;[n: number]: B; } = { x: b, 0: a }; // both indexers are A ~~ -!!! error TS2322: Type '{ [x: string]: A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: Type '{ 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. +!!! error TS2322: Property '0' is incompatible with index signature. !!! error TS2322: Type 'A' is not assignable to type 'B'. !!! error TS2322: Property 'y' is missing in type 'A'. - o1 = { x: c, 0: a }; // string indexer is any, number indexer is A \ No newline at end of file + o1 = { x: c, 0: a }; // string indexer is any, number indexer is A + ~~ +!!! error TS2322: Type '{ 0: A; x: any; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. +!!! error TS2322: Property '0' is incompatible with index signature. +!!! error TS2322: Type 'A' is not assignable to type 'B'. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types b/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types index a49f76d02e9..b0ddd9f60d0 100644 --- a/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types +++ b/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types @@ -9,7 +9,7 @@ interface I { var x: I = { >x : I >I : I ->{ p: null} : { [x: string]: null; p: null; } +>{ p: null} : { p: null; } p: null >p : null diff --git a/tests/baselines/reference/objectLiteralIndexers.types b/tests/baselines/reference/objectLiteralIndexers.types index d5add00ebaf..9e3aa4bac49 100644 --- a/tests/baselines/reference/objectLiteralIndexers.types +++ b/tests/baselines/reference/objectLiteralIndexers.types @@ -31,23 +31,23 @@ var o1: { [s: string]: A;[n: number]: B; } = { x: a, 0: b }; // string indexer i >A : A >n : number >B : B ->{ x: a, 0: b } : { [x: string]: A; [x: number]: B; 0: B; x: A; } +>{ x: a, 0: b } : { 0: B; x: A; } >x : A >a : A >b : B o1 = { x: b, 0: c }; // both indexers are any ->o1 = { x: b, 0: c } : { [x: string]: any; [x: number]: any; 0: any; x: B; } +>o1 = { x: b, 0: c } : { 0: any; x: B; } >o1 : { [s: string]: A; [n: number]: B; } ->{ x: b, 0: c } : { [x: string]: any; [x: number]: any; 0: any; x: B; } +>{ x: b, 0: c } : { 0: any; x: B; } >x : B >b : B >c : any o1 = { x: c, 0: b }; // string indexer is any, number indexer is B ->o1 = { x: c, 0: b } : { [x: string]: any; [x: number]: B; 0: B; x: any; } +>o1 = { x: c, 0: b } : { 0: B; x: any; } >o1 : { [s: string]: A; [n: number]: B; } ->{ x: c, 0: b } : { [x: string]: any; [x: number]: B; 0: B; x: any; } +>{ x: c, 0: b } : { 0: B; x: any; } >x : any >c : any >b : B diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types index 2284d06ffbd..c5de5c7b9b4 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types @@ -50,7 +50,7 @@ var a: { var b: { [x: number]: string; } = { foo: '' }; >b : { [x: number]: string; } >x : number ->{ foo: '' } : { [x: number]: undefined; foo: string; } +>{ foo: '' } : { foo: string; } >foo : string >'' : string diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types index 1a580297b1b..17fc6a07a00 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types @@ -64,7 +64,7 @@ var b: { [x: number]: Derived; } = { foo: null }; >b : { [x: number]: Derived; } >x : number >Derived : Derived ->{ foo: null } : { [x: number]: undefined; foo: Derived; } +>{ foo: null } : { foo: Derived; } >foo : Derived >null : Derived >Derived : Derived diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types index ae384bbb4db..99e6b8c8632 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types @@ -50,7 +50,7 @@ var a: { var b: { [x: number]: string; } = { foo: '' }; >b : { [x: number]: string; } >x : number ->{ foo: '' } : { [x: number]: undefined; foo: string; } +>{ foo: '' } : { foo: string; } >foo : string >'' : string diff --git a/tests/baselines/reference/objectTypesIdentityWithStringIndexers.types b/tests/baselines/reference/objectTypesIdentityWithStringIndexers.types index a7eeb672504..8393eaf68a0 100644 --- a/tests/baselines/reference/objectTypesIdentityWithStringIndexers.types +++ b/tests/baselines/reference/objectTypesIdentityWithStringIndexers.types @@ -50,7 +50,7 @@ var a: { var b: { [x: string]: string; } = { foo: '' }; >b : { [x: string]: string; } >x : string ->{ foo: '' } : { [x: string]: string; foo: string; } +>{ foo: '' } : { foo: string; } >foo : string >'' : string diff --git a/tests/baselines/reference/objectTypesIdentityWithStringIndexers2.types b/tests/baselines/reference/objectTypesIdentityWithStringIndexers2.types index d1394252117..814d0c91814 100644 --- a/tests/baselines/reference/objectTypesIdentityWithStringIndexers2.types +++ b/tests/baselines/reference/objectTypesIdentityWithStringIndexers2.types @@ -64,7 +64,7 @@ var b: { [x: string]: Derived; } = { foo: null }; >b : { [x: string]: Derived; } >x : string >Derived : Derived ->{ foo: null } : { [x: string]: Derived; foo: Derived; } +>{ foo: null } : { foo: Derived; } >foo : Derived >null : Derived >Derived : Derived diff --git a/tests/baselines/reference/operatorsAndIntersectionTypes.types b/tests/baselines/reference/operatorsAndIntersectionTypes.types index 70611776fc1..6b5987d3a69 100644 --- a/tests/baselines/reference/operatorsAndIntersectionTypes.types +++ b/tests/baselines/reference/operatorsAndIntersectionTypes.types @@ -28,7 +28,7 @@ function createSerialNo() { let map1: { [x: string]: number } = {}; >map1 : { [x: string]: number; } >x : string ->{} : { [x: string]: undefined; } +>{} : {} let guid = createGuid(); >guid : string & { $Guid: any; } @@ -45,7 +45,7 @@ map1[guid] = 123; // Can with tagged string let map2: { [x: number]: string } = {}; >map2 : { [x: number]: string; } >x : number ->{} : { [x: number]: undefined; } +>{} : {} let serialNo = createSerialNo(); >serialNo : number & { $SerialNo: any; } diff --git a/tests/baselines/reference/restElementWithNullInitializer.errors.txt b/tests/baselines/reference/restElementWithNullInitializer.errors.txt index 7beb7b9a642..4658acc5ff4 100644 --- a/tests/baselines/reference/restElementWithNullInitializer.errors.txt +++ b/tests/baselines/reference/restElementWithNullInitializer.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(1,15): error TS2461: Type 'null' is not an array type. tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(4,15): error TS2461: Type 'undefined' is not an array type. -tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(7,15): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. +tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(7,15): error TS2461: Type '{}' is not an array type. ==== tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts (3 errors) ==== @@ -16,7 +16,7 @@ tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(7,15 function foo3([...r] = {}) { ~~~~~~ -!!! error TS2461: Type '{ [x: number]: undefined; }' is not an array type. +!!! error TS2461: Type '{}' is not an array type. } function foo4([...r] = []) { diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index 08881be2a86..8f4bbe2025a 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -22,10 +22,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(71,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(74,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | (() => void) | MyString; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. - Index signatures are incompatible. - Type 'string | number | (() => void) | MyString' is not assignable to type 'string'. - Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. + Property '2.0' is incompatible with index signature. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(90,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(93,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -158,10 +157,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: string; } = { ~ -!!! error TS2322: Type '{ [x: string]: string | number | (() => void) | MyString; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. -!!! error TS2322: Index signatures are incompatible. -!!! error TS2322: Type 'string | number | (() => void) | MyString' is not assignable to type 'string'. -!!! error TS2322: Type 'number' is not assignable to type 'string'. +!!! error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. +!!! error TS2322: Property '2.0' is incompatible with index signature. +!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, c: () => { }, diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt index faef7905453..dacfb1a522d 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt @@ -4,8 +4,8 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(24,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(31,5): error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(32,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(36,5): error TS2322: Type '{ [x: string]: typeof A; a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. - Index signatures are incompatible. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(36,5): error TS2322: Type '{ a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. + Property 'a' is incompatible with index signature. Type 'typeof A' is not assignable to type 'A'. Property 'foo' is missing in type 'typeof A'. @@ -60,8 +60,8 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: A } = { ~ -!!! error TS2322: Type '{ [x: string]: typeof A; a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: Type '{ a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. +!!! error TS2322: Property 'a' is incompatible with index signature. !!! error TS2322: Type 'typeof A' is not assignable to type 'A'. !!! error TS2322: Property 'foo' is missing in type 'typeof A'. a: A, diff --git a/tests/baselines/reference/stringIndexingResults.types b/tests/baselines/reference/stringIndexingResults.types index 9f613312e5a..1fdc580b1a2 100644 --- a/tests/baselines/reference/stringIndexingResults.types +++ b/tests/baselines/reference/stringIndexingResults.types @@ -95,7 +95,7 @@ var r9 = a[1]; var b: { [x: string]: string } = { y: '' } >b : { [x: string]: string; } >x : string ->{ y: '' } : { [x: string]: string; y: string; } +>{ y: '' } : { y: string; } >y : string >'' : string diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt index e6910840d39..94ab5028647 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. - Property 'raw' is missing in type '{ [x: number]: undefined; }'. +tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. + Property 'raw' is missing in type '{}'. ==== tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2 f({}, 10, 10); ~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. -!!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. +!!! error TS2345: Property 'raw' is missing in type '{}'. f `abcdef${ 1234 }${ 5678 }ghijkl`; \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt index e8bf38c1048..1201c82f4d0 100644 --- a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(5,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. - Property 'raw' is missing in type '{ [x: number]: undefined; }'. +tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(5,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. + Property 'raw' is missing in type '{}'. ==== tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts (1 errors) ==== @@ -9,7 +9,7 @@ tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(5,3): error TS f({}, 10, 10); ~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. -!!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. +!!! error TS2345: Property 'raw' is missing in type '{}'. f `abcdef${ 1234 }${ 5678 }ghijkl`; \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt index ac30556a235..f410d408482 100644 --- a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. - Property 'raw' is missing in type '{ [x: number]: undefined; }'. +tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. + Property 'raw' is missing in type '{}'. ==== tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error T f({}, 10, 10); ~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. -!!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. +!!! error TS2345: Property 'raw' is missing in type '{}'. f `abcdef${ 1234 }${ 5678 }ghijkl`; \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterFixingWithConstraints.types b/tests/baselines/reference/typeParameterFixingWithConstraints.types index 22d294f9d2e..1e71f439e5e 100644 --- a/tests/baselines/reference/typeParameterFixingWithConstraints.types +++ b/tests/baselines/reference/typeParameterFixingWithConstraints.types @@ -31,17 +31,17 @@ var foo: IFoo; >IFoo : IFoo foo.foo({ bar: null }, bar => null, bar => null); ->foo.foo({ bar: null }, bar => null, bar => null) : { [x: string]: any; bar: any; } +>foo.foo({ bar: null }, bar => null, bar => null) : { bar: any; } >foo.foo : (bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar) => TBar >foo : IFoo >foo : (bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar) => TBar ->{ bar: null } : { [x: string]: null; bar: null; } +>{ bar: null } : { bar: null; } >bar : null >null : null ->bar => null : (bar: { [x: string]: any; bar: any; }) => any ->bar : { [x: string]: any; bar: any; } +>bar => null : (bar: { bar: any; }) => any +>bar : { bar: any; } >null : null ->bar => null : (bar: { [x: string]: any; bar: any; }) => any ->bar : { [x: string]: any; bar: any; } +>bar => null : (bar: { bar: any; }) => any +>bar : { bar: any; } >null : null diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 4d8a05a5c38..37f3bdb12ab 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -31,7 +31,7 @@ _.each({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => alert(valu >_.each : { (list: T[], iterator: Iterator, context?: any): void; (list: Dictionary, iterator: Iterator, context?: any): void; } >_ : Underscore.Static >each : { (list: T[], iterator: Iterator, context?: any): void; (list: Dictionary, iterator: Iterator, context?: any): void; } ->{ one: 1, two: 2, three: 3 } : { [x: string]: number; one: number; two: number; three: number; } +>{ one: 1, two: 2, three: 3 } : { one: number; two: number; three: number; } >one : number >1 : number >two : number @@ -68,7 +68,7 @@ _.map({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => value * 3); >_.map : { (list: T[], iterator: Iterator, context?: any): U[]; (list: Dictionary, iterator: Iterator, context?: any): U[]; } >_ : Underscore.Static >map : { (list: T[], iterator: Iterator, context?: any): U[]; (list: Dictionary, iterator: Iterator, context?: any): U[]; } ->{ one: 1, two: 2, three: 3 } : { [x: string]: number; one: number; two: number; three: number; } +>{ one: 1, two: 2, three: 3 } : { one: number; two: number; three: number; } >one : number >1 : number >two : number @@ -449,7 +449,7 @@ _.size({ one: 1, two: 2, three: 3 }); >_.size : { (list: T[]): number; (list: Dictionary): number; } >_ : Underscore.Static >size : { (list: T[]): number; (list: Dictionary): number; } ->{ one: 1, two: 2, three: 3 } : { [x: string]: number; one: number; two: number; three: number; } +>{ one: 1, two: 2, three: 3 } : { one: number; two: number; three: number; } >one : number >1 : number >two : number diff --git a/tests/baselines/reference/widenedTypes.errors.txt b/tests/baselines/reference/widenedTypes.errors.txt index 2277ef6eea7..beda634c2a6 100644 --- a/tests/baselines/reference/widenedTypes.errors.txt +++ b/tests/baselines/reference/widenedTypes.errors.txt @@ -6,8 +6,8 @@ tests/cases/compiler/widenedTypes.ts(11,1): error TS2322: Type 'string' is not a tests/cases/compiler/widenedTypes.ts(18,1): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/compiler/widenedTypes.ts(23,5): error TS2322: Type 'number[]' is not assignable to type 'string[]'. Type 'number' is not assignable to type 'string'. -tests/cases/compiler/widenedTypes.ts(24,5): error TS2322: Type '{ [x: string]: number; x: number; y: null; }' is not assignable to type '{ [x: string]: string; }'. - Index signatures are incompatible. +tests/cases/compiler/widenedTypes.ts(24,5): error TS2322: Type '{ x: number; y: null; }' is not assignable to type '{ [x: string]: string; }'. + Property 'x' is incompatible with index signature. Type 'number' is not assignable to type 'string'. @@ -52,6 +52,6 @@ tests/cases/compiler/widenedTypes.ts(24,5): error TS2322: Type '{ [x: string]: n !!! error TS2322: Type 'number' is not assignable to type 'string'. var obj: { [x: string]: string; } = { x: 3, y: null }; // assignable because null is widened, and therefore BCT is any ~~~ -!!! error TS2322: Type '{ [x: string]: number; x: number; y: null; }' is not assignable to type '{ [x: string]: string; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: Type '{ x: number; y: null; }' is not assignable to type '{ [x: string]: string; }'. +!!! error TS2322: Property 'x' is incompatible with index signature. !!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/wrappedAndRecursiveConstraints4.errors.txt b/tests/baselines/reference/wrappedAndRecursiveConstraints4.errors.txt index 60602351b46..47e8e6ff4f2 100644 --- a/tests/baselines/reference/wrappedAndRecursiveConstraints4.errors.txt +++ b/tests/baselines/reference/wrappedAndRecursiveConstraints4.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/wrappedAndRecursiveConstraints4.ts(13,12): error TS2345: Argument of type '{ [x: number]: undefined; length: number; charAt: (x: number) => void; }' is not assignable to parameter of type 'string'. +tests/cases/conformance/types/typeParameters/typeArgumentLists/wrappedAndRecursiveConstraints4.ts(13,12): error TS2345: Argument of type '{ length: number; charAt: (x: number) => void; }' is not assignable to parameter of type 'string'. ==== tests/cases/conformance/types/typeParameters/typeArgumentLists/wrappedAndRecursiveConstraints4.ts (1 errors) ==== @@ -16,4 +16,4 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/wrappedAndRecursi var r = c.foo(''); var r2 = r({ length: 3, charAt: (x: number) => { '' } }); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; length: number; charAt: (x: number) => void; }' is not assignable to parameter of type 'string'. \ No newline at end of file +!!! error TS2345: Argument of type '{ length: number; charAt: (x: number) => void; }' is not assignable to parameter of type 'string'. \ No newline at end of file From 0355d1fdc89cf74d9ba68663c165f9f9b1790ba3 Mon Sep 17 00:00:00 2001 From: vladima Date: Wed, 10 Feb 2016 00:20:40 -0800 Subject: [PATCH 046/297] fix source maps for in-browser tests --- Jakefile.js | 75 +++++++++++++++++++++++------------------- src/harness/harness.ts | 2 +- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 7b85aacaa89..84248ca34d1 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -223,51 +223,59 @@ var builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename); * @param prereqs: prerequisite tasks to compiling the file * @param prefixes: a list of files to prepend to the target file * @param useBuiltCompiler: true to use the built compiler, false to use the LKG - * @param noOutFile: true to compile without using --out - * @param generateDeclarations: true to compile using --declaration - * @param outDir: true to compile using --outDir - * @param keepComments: false to compile using --removeComments + * @parap {Object} opts - property bag containing auxiliary options + * @param {boolean} opts.noOutFile: true to compile without using --out + * @param {boolean} opts.generateDeclarations: true to compile using --declaration + * @param {string} opts.outDir: value for '--outDir' command line option + * @param {boolean} opts.keepComments: false to compile using --removeComments + * @param {boolean} opts.preserveConstEnums: true if compiler should keep const enums in code + * @param {boolean} opts.noResolve: true if compiler should not include non-rooted files in compilation + * @param {boolean} opts.stripInternal: true if compiler should remove declarations marked as @internal + * @param {boolean} opts.noMapRoot: true if compiler omit mapRoot option * @param callback: a function to execute after the compilation process ends */ -function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, preserveConstEnums, keepComments, noResolve, stripInternal, callback) { +function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts, callback) { file(outFile, prereqs, function() { var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler; var options = "--noImplicitAny --noEmitOnError --pretty"; - + opts = opts || {}; // Keep comments when specifically requested // or when in debug mode. - if (!(keepComments || useDebugMode)) { + if (!(opts.keepComments || useDebugMode)) { options += " --removeComments"; } - if (generateDeclarations) { + if (opts.generateDeclarations) { options += " --declaration"; } - if (preserveConstEnums || useDebugMode) { + if (opts.preserveConstEnums || useDebugMode) { options += " --preserveConstEnums"; } - if (outDir) { - options += " --outDir " + outDir; + if (opts.outDir) { + options += " --outDir " + opts.outDir; } - if (!noOutFile) { + if (!opts.noOutFile) { options += " --out " + outFile; } else { options += " --module commonjs" } - if(noResolve) { + if(opts.noResolve) { options += " --noResolve"; } if (useDebugMode) { - options += " -sourcemap -mapRoot file:///" + path.resolve(path.dirname(outFile)); + options += " -sourcemap"; + if (!opts.noMapRoot) { + options += " -mapRoot file:///" + path.resolve(path.dirname(outFile)); + } } - if (stripInternal) { + if (opts.stripInternal) { options += " --stripInternal" } @@ -382,13 +390,7 @@ compileFile(/*outfile*/configureNightlyJs, /*prereqs*/ [configureNightlyTs], /*prefixes*/ [], /*useBuiltCompiler*/ false, - /*noOutFile*/ false, - /*generateDeclarations*/ false, - /*outDir*/ undefined, - /*preserveConstEnums*/ undefined, - /*keepComments*/ false, - /*noResolve*/ false, - /*stripInternal*/ false); + { noOutFile: false, generateDeclarations: false, keepComments: false, noResolve: false, stripInternal: false }); task("setDebugMode", function() { useDebugMode = true; @@ -438,6 +440,7 @@ var tscFile = path.join(builtLocalDirectory, compilerFilename); compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false); var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js"); +var servicesFileInBrowserTest = path.join(builtLocalDirectory, "typescriptServicesInBrowserTest.js"); var standaloneDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts"); var nodePackageFile = path.join(builtLocalDirectory, "typescript.js"); var nodeDefinitionsFile = path.join(builtLocalDirectory, "typescript.d.ts"); @@ -446,13 +449,7 @@ var nodeStandaloneDefinitionsFile = path.join(builtLocalDirectory, "typescript_s compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, - /*noOutFile*/ false, - /*generateDeclarations*/ true, - /*outDir*/ undefined, - /*preserveConstEnums*/ true, - /*keepComments*/ true, - /*noResolve*/ false, - /*stripInternal*/ true, + { noOutFile: false, generateDeclarations: true, preserveConstEnums: true, keepComments: true, noResolve: false, stripInternal: true }, /*callback*/ function () { jake.cpR(servicesFile, nodePackageFile, {silent: true}); @@ -475,6 +472,16 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca fs.writeFileSync(nodeStandaloneDefinitionsFile, nodeStandaloneDefinitionsFileContents); }); +compileFile(servicesFileInBrowserTest, servicesSources,[builtLocalDirectory, copyright].concat(servicesSources), + /*prefixes*/ [copyright], + /*useBuiltCompiler*/ true, + { noOutFile: false, generateDeclarations: true, preserveConstEnums: true, keepComments: true, noResolve: false, stripInternal: true, noMapRoot: true }, + /*callback*/ function () { + var content = fs.readFileSync(servicesFileInBrowserTest).toString(); + var i = content.lastIndexOf("\n"); + fs.writeFileSync(servicesFileInBrowserTest, content.substring(0, i) + "\r\n//# sourceURL=../built/local/typeScriptServices.js" + content.substring(i)); + }); + var serverFile = path.join(builtLocalDirectory, "tsserver.js"); compileFile(serverFile, serverSources,[builtLocalDirectory, copyright].concat(serverSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true); @@ -486,8 +493,7 @@ compileFile( [builtLocalDirectory, copyright].concat(languageServiceLibrarySources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, - /*noOutFile*/ false, - /*generateDeclarations*/ true); + { noOutFile: false, generateDeclarations: true }); // Local target to build the language service server library desc("Builds language service server library"); @@ -720,7 +726,7 @@ task("generate-code-coverage", ["tests", builtLocalDirectory], function () { // Browser tests var nodeServerOutFile = 'tests/webTestServer.js' var nodeServerInFile = 'tests/webTestServer.ts' -compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile], [], /*useBuiltCompiler:*/ true, /*noOutFile*/ true); +compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile], [], /*useBuiltCompiler:*/ true, { noOutFile: true }); desc("Runs browserify on run.js to produce a file suitable for running tests in the browser"); task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() { @@ -729,7 +735,7 @@ task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() }, {async: true}); desc("Runs the tests using the built run.js file like 'jake runtests'. Syntax is jake runtests-browser. Additional optional parameters tests=[regex], port=, browser=[chrome|IE]"); -task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function() { +task("runtests-browser", ["tests", "browserify", builtLocalDirectory, servicesFileInBrowserTest], function() { cleanTestDirs(); host = "node" port = process.env.port || process.env.p || '8888'; @@ -881,7 +887,8 @@ var tslintRulesOutFiles = tslintRules.map(function(p) { desc("Compiles tslint rules to js"); task("build-rules", tslintRulesOutFiles); tslintRulesFiles.forEach(function(ruleFile, i) { - compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ false, /*noOutFile*/ true, /*generateDeclarations*/ false, path.join(builtLocalDirectory, "tslint")); + compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ false, + { noOutFile: true, generateDeclarations: false, outDir: path.join(builtLocalDirectory, "tslint")}); }); function getLinterOptions() { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 848b0d4e063..a21495f27bd 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -746,7 +746,7 @@ namespace Harness { namespace Harness { export const libFolder = "built/local/"; - const tcServicesFileName = ts.combinePaths(libFolder, "typescriptServices.js"); + const tcServicesFileName = ts.combinePaths(libFolder, Utils.getExecutionEnvironment() === Utils.ExecutionEnvironment.Browser ? "typescriptServicesInBrowserTest.js" : "typescriptServices.js"); export const tcServicesFile = IO.readFile(tcServicesFileName); export interface SourceMapEmitterCallback { From bb7ba1dcea57c6ac35391a271e7f5aec0d636972 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 10 Feb 2016 06:56:25 -0800 Subject: [PATCH 047/297] Adding test --- .../reference/implicitIndexSignatures.js | 85 ++++++++ .../reference/implicitIndexSignatures.symbols | 166 +++++++++++++++ .../reference/implicitIndexSignatures.types | 201 ++++++++++++++++++ .../cases/compiler/implicitIndexSignatures.ts | 45 ++++ 4 files changed, 497 insertions(+) create mode 100644 tests/baselines/reference/implicitIndexSignatures.js create mode 100644 tests/baselines/reference/implicitIndexSignatures.symbols create mode 100644 tests/baselines/reference/implicitIndexSignatures.types create mode 100644 tests/cases/compiler/implicitIndexSignatures.ts diff --git a/tests/baselines/reference/implicitIndexSignatures.js b/tests/baselines/reference/implicitIndexSignatures.js new file mode 100644 index 00000000000..6403f1f1543 --- /dev/null +++ b/tests/baselines/reference/implicitIndexSignatures.js @@ -0,0 +1,85 @@ +//// [implicitIndexSignatures.ts] +type StringMap = { [x: string]: string }; + +const empty1 = {}; +let empty2: {}; +const names1 = { a: "foo", b: "bar" }; +let names2: { a: string, b: string }; +let map: StringMap; +map = { x: "xxx", y: "yyy" }; +map = empty1; +map = empty2; +map = names1; +map = names2; + +declare function getStringIndexValue(map: { [x: string]: T }): T; +declare function getNumberIndexValue(map: { [x: number]: T }): T; + +function f1() { + const o1 = { a: 1, b: 2 }; + let o2: { a: number, b: number }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f2() { + const o1 = { a: "1", b: "2" }; + let o2: { a: string, b: string }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f3() { + const o1 = { a: 1, b: "2" }; + let o2: { a: number, b: string }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f4() { + const o1 = { 0: "0", 1: "1", count: 2 }; + let o2: { 0: string, 1: string, count: number }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); + const v3 = getNumberIndexValue(o1); + const v4 = getNumberIndexValue(o2); +} + + +//// [implicitIndexSignatures.js] +var empty1 = {}; +var empty2; +var names1 = { a: "foo", b: "bar" }; +var names2; +var map; +map = { x: "xxx", y: "yyy" }; +map = empty1; +map = empty2; +map = names1; +map = names2; +function f1() { + var o1 = { a: 1, b: 2 }; + var o2; + var v1 = getStringIndexValue(o1); + var v2 = getStringIndexValue(o2); +} +function f2() { + var o1 = { a: "1", b: "2" }; + var o2; + var v1 = getStringIndexValue(o1); + var v2 = getStringIndexValue(o2); +} +function f3() { + var o1 = { a: 1, b: "2" }; + var o2; + var v1 = getStringIndexValue(o1); + var v2 = getStringIndexValue(o2); +} +function f4() { + var o1 = { 0: "0", 1: "1", count: 2 }; + var o2; + var v1 = getStringIndexValue(o1); + var v2 = getStringIndexValue(o2); + var v3 = getNumberIndexValue(o1); + var v4 = getNumberIndexValue(o2); +} diff --git a/tests/baselines/reference/implicitIndexSignatures.symbols b/tests/baselines/reference/implicitIndexSignatures.symbols new file mode 100644 index 00000000000..a014e7e942c --- /dev/null +++ b/tests/baselines/reference/implicitIndexSignatures.symbols @@ -0,0 +1,166 @@ +=== tests/cases/compiler/implicitIndexSignatures.ts === +type StringMap = { [x: string]: string }; +>StringMap : Symbol(StringMap, Decl(implicitIndexSignatures.ts, 0, 0)) +>x : Symbol(x, Decl(implicitIndexSignatures.ts, 0, 20)) + +const empty1 = {}; +>empty1 : Symbol(empty1, Decl(implicitIndexSignatures.ts, 2, 5)) + +let empty2: {}; +>empty2 : Symbol(empty2, Decl(implicitIndexSignatures.ts, 3, 3)) + +const names1 = { a: "foo", b: "bar" }; +>names1 : Symbol(names1, Decl(implicitIndexSignatures.ts, 4, 5)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 4, 16)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 4, 26)) + +let names2: { a: string, b: string }; +>names2 : Symbol(names2, Decl(implicitIndexSignatures.ts, 5, 3)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 5, 13)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 5, 24)) + +let map: StringMap; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>StringMap : Symbol(StringMap, Decl(implicitIndexSignatures.ts, 0, 0)) + +map = { x: "xxx", y: "yyy" }; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>x : Symbol(x, Decl(implicitIndexSignatures.ts, 7, 7)) +>y : Symbol(y, Decl(implicitIndexSignatures.ts, 7, 17)) + +map = empty1; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>empty1 : Symbol(empty1, Decl(implicitIndexSignatures.ts, 2, 5)) + +map = empty2; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>empty2 : Symbol(empty2, Decl(implicitIndexSignatures.ts, 3, 3)) + +map = names1; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>names1 : Symbol(names1, Decl(implicitIndexSignatures.ts, 4, 5)) + +map = names2; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>names2 : Symbol(names2, Decl(implicitIndexSignatures.ts, 5, 3)) + +declare function getStringIndexValue(map: { [x: string]: T }): T; +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 13, 37)) +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 13, 40)) +>x : Symbol(x, Decl(implicitIndexSignatures.ts, 13, 48)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 13, 37)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 13, 37)) + +declare function getNumberIndexValue(map: { [x: number]: T }): T; +>getNumberIndexValue : Symbol(getNumberIndexValue, Decl(implicitIndexSignatures.ts, 13, 68)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 14, 37)) +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 14, 40)) +>x : Symbol(x, Decl(implicitIndexSignatures.ts, 14, 48)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 14, 37)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 14, 37)) + +function f1() { +>f1 : Symbol(f1, Decl(implicitIndexSignatures.ts, 14, 68)) + + const o1 = { a: 1, b: 2 }; +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 17, 9)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 17, 16)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 17, 22)) + + let o2: { a: number, b: number }; +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 18, 7)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 18, 13)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 18, 24)) + + const v1 = getStringIndexValue(o1); +>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 19, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 17, 9)) + + const v2 = getStringIndexValue(o2); +>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 20, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 18, 7)) +} + +function f2() { +>f2 : Symbol(f2, Decl(implicitIndexSignatures.ts, 21, 1)) + + const o1 = { a: "1", b: "2" }; +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 24, 9)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 24, 16)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 24, 24)) + + let o2: { a: string, b: string }; +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 25, 7)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 25, 13)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 25, 24)) + + const v1 = getStringIndexValue(o1); +>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 26, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 24, 9)) + + const v2 = getStringIndexValue(o2); +>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 27, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 25, 7)) +} + +function f3() { +>f3 : Symbol(f3, Decl(implicitIndexSignatures.ts, 28, 1)) + + const o1 = { a: 1, b: "2" }; +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 31, 9)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 31, 16)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 31, 22)) + + let o2: { a: number, b: string }; +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 32, 7)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 32, 13)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 32, 24)) + + const v1 = getStringIndexValue(o1); +>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 33, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 31, 9)) + + const v2 = getStringIndexValue(o2); +>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 34, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 32, 7)) +} + +function f4() { +>f4 : Symbol(f4, Decl(implicitIndexSignatures.ts, 35, 1)) + + const o1 = { 0: "0", 1: "1", count: 2 }; +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 38, 9)) +>count : Symbol(count, Decl(implicitIndexSignatures.ts, 38, 32)) + + let o2: { 0: string, 1: string, count: number }; +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 39, 7)) +>count : Symbol(count, Decl(implicitIndexSignatures.ts, 39, 35)) + + const v1 = getStringIndexValue(o1); +>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 40, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 38, 9)) + + const v2 = getStringIndexValue(o2); +>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 41, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 39, 7)) + + const v3 = getNumberIndexValue(o1); +>v3 : Symbol(v3, Decl(implicitIndexSignatures.ts, 42, 9)) +>getNumberIndexValue : Symbol(getNumberIndexValue, Decl(implicitIndexSignatures.ts, 13, 68)) +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 38, 9)) + + const v4 = getNumberIndexValue(o2); +>v4 : Symbol(v4, Decl(implicitIndexSignatures.ts, 43, 9)) +>getNumberIndexValue : Symbol(getNumberIndexValue, Decl(implicitIndexSignatures.ts, 13, 68)) +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 39, 7)) +} + diff --git a/tests/baselines/reference/implicitIndexSignatures.types b/tests/baselines/reference/implicitIndexSignatures.types new file mode 100644 index 00000000000..7d335c00491 --- /dev/null +++ b/tests/baselines/reference/implicitIndexSignatures.types @@ -0,0 +1,201 @@ +=== tests/cases/compiler/implicitIndexSignatures.ts === +type StringMap = { [x: string]: string }; +>StringMap : { [x: string]: string; } +>x : string + +const empty1 = {}; +>empty1 : {} +>{} : {} + +let empty2: {}; +>empty2 : {} + +const names1 = { a: "foo", b: "bar" }; +>names1 : { a: string; b: string; } +>{ a: "foo", b: "bar" } : { a: string; b: string; } +>a : string +>"foo" : string +>b : string +>"bar" : string + +let names2: { a: string, b: string }; +>names2 : { a: string; b: string; } +>a : string +>b : string + +let map: StringMap; +>map : { [x: string]: string; } +>StringMap : { [x: string]: string; } + +map = { x: "xxx", y: "yyy" }; +>map = { x: "xxx", y: "yyy" } : { x: string; y: string; } +>map : { [x: string]: string; } +>{ x: "xxx", y: "yyy" } : { x: string; y: string; } +>x : string +>"xxx" : string +>y : string +>"yyy" : string + +map = empty1; +>map = empty1 : {} +>map : { [x: string]: string; } +>empty1 : {} + +map = empty2; +>map = empty2 : {} +>map : { [x: string]: string; } +>empty2 : {} + +map = names1; +>map = names1 : { a: string; b: string; } +>map : { [x: string]: string; } +>names1 : { a: string; b: string; } + +map = names2; +>map = names2 : { a: string; b: string; } +>map : { [x: string]: string; } +>names2 : { a: string; b: string; } + +declare function getStringIndexValue(map: { [x: string]: T }): T; +>getStringIndexValue : (map: { [x: string]: T; }) => T +>T : T +>map : { [x: string]: T; } +>x : string +>T : T +>T : T + +declare function getNumberIndexValue(map: { [x: number]: T }): T; +>getNumberIndexValue : (map: { [x: number]: T; }) => T +>T : T +>map : { [x: number]: T; } +>x : number +>T : T +>T : T + +function f1() { +>f1 : () => void + + const o1 = { a: 1, b: 2 }; +>o1 : { a: number; b: number; } +>{ a: 1, b: 2 } : { a: number; b: number; } +>a : number +>1 : number +>b : number +>2 : number + + let o2: { a: number, b: number }; +>o2 : { a: number; b: number; } +>a : number +>b : number + + const v1 = getStringIndexValue(o1); +>v1 : number +>getStringIndexValue(o1) : number +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o1 : { a: number; b: number; } + + const v2 = getStringIndexValue(o2); +>v2 : number +>getStringIndexValue(o2) : number +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o2 : { a: number; b: number; } +} + +function f2() { +>f2 : () => void + + const o1 = { a: "1", b: "2" }; +>o1 : { a: string; b: string; } +>{ a: "1", b: "2" } : { a: string; b: string; } +>a : string +>"1" : string +>b : string +>"2" : string + + let o2: { a: string, b: string }; +>o2 : { a: string; b: string; } +>a : string +>b : string + + const v1 = getStringIndexValue(o1); +>v1 : string +>getStringIndexValue(o1) : string +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o1 : { a: string; b: string; } + + const v2 = getStringIndexValue(o2); +>v2 : string +>getStringIndexValue(o2) : string +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o2 : { a: string; b: string; } +} + +function f3() { +>f3 : () => void + + const o1 = { a: 1, b: "2" }; +>o1 : { a: number; b: string; } +>{ a: 1, b: "2" } : { a: number; b: string; } +>a : number +>1 : number +>b : string +>"2" : string + + let o2: { a: number, b: string }; +>o2 : { a: number; b: string; } +>a : number +>b : string + + const v1 = getStringIndexValue(o1); +>v1 : number | string +>getStringIndexValue(o1) : number | string +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o1 : { a: number; b: string; } + + const v2 = getStringIndexValue(o2); +>v2 : number | string +>getStringIndexValue(o2) : number | string +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o2 : { a: number; b: string; } +} + +function f4() { +>f4 : () => void + + const o1 = { 0: "0", 1: "1", count: 2 }; +>o1 : { 0: string; 1: string; count: number; } +>{ 0: "0", 1: "1", count: 2 } : { 0: string; 1: string; count: number; } +>"0" : string +>"1" : string +>count : number +>2 : number + + let o2: { 0: string, 1: string, count: number }; +>o2 : { 0: string; 1: string; count: number; } +>count : number + + const v1 = getStringIndexValue(o1); +>v1 : string | number +>getStringIndexValue(o1) : string | number +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o1 : { 0: string; 1: string; count: number; } + + const v2 = getStringIndexValue(o2); +>v2 : string | number +>getStringIndexValue(o2) : string | number +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o2 : { 0: string; 1: string; count: number; } + + const v3 = getNumberIndexValue(o1); +>v3 : string +>getNumberIndexValue(o1) : string +>getNumberIndexValue : (map: { [x: number]: T; }) => T +>o1 : { 0: string; 1: string; count: number; } + + const v4 = getNumberIndexValue(o2); +>v4 : string +>getNumberIndexValue(o2) : string +>getNumberIndexValue : (map: { [x: number]: T; }) => T +>o2 : { 0: string; 1: string; count: number; } +} + diff --git a/tests/cases/compiler/implicitIndexSignatures.ts b/tests/cases/compiler/implicitIndexSignatures.ts new file mode 100644 index 00000000000..2e36a91bada --- /dev/null +++ b/tests/cases/compiler/implicitIndexSignatures.ts @@ -0,0 +1,45 @@ +type StringMap = { [x: string]: string }; + +const empty1 = {}; +let empty2: {}; +const names1 = { a: "foo", b: "bar" }; +let names2: { a: string, b: string }; +let map: StringMap; +map = { x: "xxx", y: "yyy" }; +map = empty1; +map = empty2; +map = names1; +map = names2; + +declare function getStringIndexValue(map: { [x: string]: T }): T; +declare function getNumberIndexValue(map: { [x: number]: T }): T; + +function f1() { + const o1 = { a: 1, b: 2 }; + let o2: { a: number, b: number }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f2() { + const o1 = { a: "1", b: "2" }; + let o2: { a: string, b: string }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f3() { + const o1 = { a: 1, b: "2" }; + let o2: { a: number, b: string }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f4() { + const o1 = { 0: "0", 1: "1", count: 2 }; + let o2: { 0: string, 1: string, count: number }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); + const v3 = getNumberIndexValue(o1); + const v4 = getNumberIndexValue(o2); +} From 5b1469aece62f30c2c8c0c0341e6c81609aa8b4c Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 10 Feb 2016 10:41:52 -0800 Subject: [PATCH 048/297] Add undefined checks for malformed type tags Fixes #7002 --- src/compiler/checker.ts | 4 ++-- src/harness/harness.ts | 3 +++ tests/baselines/reference/malformedTags.js | 17 +++++++++++++++++ tests/baselines/reference/malformedTags.symbols | 13 +++++++++++++ tests/baselines/reference/malformedTags.types | 13 +++++++++++++ tests/cases/conformance/salsa/malformedTags.ts | 10 ++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/malformedTags.js create mode 100644 tests/baselines/reference/malformedTags.symbols create mode 100644 tests/baselines/reference/malformedTags.types create mode 100644 tests/cases/conformance/salsa/malformedTags.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 61fe8f3a794..a3555eca745 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2613,7 +2613,7 @@ namespace ts { function getJSDocTypeForVariableLikeDeclarationFromJSDocComment(declaration: VariableLikeDeclaration): JSDocType { // First, see if this node has an @type annotation on it directly. const typeTag = getJSDocTypeTag(declaration); - if (typeTag) { + if (typeTag && typeTag.typeExpression) { return typeTag.typeExpression.type; } @@ -2623,7 +2623,7 @@ namespace ts { // @type annotation might have been on the variable statement, try that instead. const annotation = getJSDocTypeTag(declaration.parent.parent); - if (annotation) { + if (annotation && annotation.typeExpression) { return annotation.typeExpression.type; } } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 848b0d4e063..6b9ae6a15db 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -938,6 +938,9 @@ namespace Harness { } } } + else if (name === 'suppressOutputPathCheck') { + options.suppressOutputPathCheck = true; + } else { throw new Error(`Unknown compiler option '${name}'.`); } diff --git a/tests/baselines/reference/malformedTags.js b/tests/baselines/reference/malformedTags.js new file mode 100644 index 00000000000..33b2c1e6f41 --- /dev/null +++ b/tests/baselines/reference/malformedTags.js @@ -0,0 +1,17 @@ +//// [myFile02.js] + +/** + * Checks if `value` is classified as an `Array` object. + * + * @type Function + */ +var isArray = Array.isArray; + + +//// [myFile02.js] +/** + * Checks if `value` is classified as an `Array` object. + * + * @type Function + */ +var isArray = Array.isArray; diff --git a/tests/baselines/reference/malformedTags.symbols b/tests/baselines/reference/malformedTags.symbols new file mode 100644 index 00000000000..df953a82497 --- /dev/null +++ b/tests/baselines/reference/malformedTags.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/salsa/myFile02.js === + +/** + * Checks if `value` is classified as an `Array` object. + * + * @type Function + */ +var isArray = Array.isArray; +>isArray : Symbol(isArray, Decl(myFile02.js, 6, 3)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/malformedTags.types b/tests/baselines/reference/malformedTags.types new file mode 100644 index 00000000000..acf442f7cba --- /dev/null +++ b/tests/baselines/reference/malformedTags.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/salsa/myFile02.js === + +/** + * Checks if `value` is classified as an `Array` object. + * + * @type Function + */ +var isArray = Array.isArray; +>isArray : (arg: any) => arg is any[] +>Array.isArray : (arg: any) => arg is any[] +>Array : ArrayConstructor +>isArray : (arg: any) => arg is any[] + diff --git a/tests/cases/conformance/salsa/malformedTags.ts b/tests/cases/conformance/salsa/malformedTags.ts new file mode 100644 index 00000000000..1128ce73f15 --- /dev/null +++ b/tests/cases/conformance/salsa/malformedTags.ts @@ -0,0 +1,10 @@ +// @allowJS: true +// @suppressOutputPathCheck: true + +// @filename: myFile02.js +/** + * Checks if `value` is classified as an `Array` object. + * + * @type Function + */ +var isArray = Array.isArray; From d64bbc0becc7c4390692f712646ca784a42c2671 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 10 Feb 2016 11:18:02 -0800 Subject: [PATCH 049/297] :heart: linter --- src/harness/harness.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 6b9ae6a15db..230b680eab7 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -938,7 +938,7 @@ namespace Harness { } } } - else if (name === 'suppressOutputPathCheck') { + else if (name === "suppressOutputPathCheck") { options.suppressOutputPathCheck = true; } else { From 8c9baf81c53b44ca7551adf7a64405827708c0eb Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 10 Feb 2016 11:30:21 -0800 Subject: [PATCH 050/297] Check in other places too --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a3555eca745..76323f83e08 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7414,7 +7414,7 @@ namespace ts { function getTypeForThisExpressionFromJSDoc(node: Node) { const typeTag = getJSDocTypeTag(node); - if (typeTag && typeTag.typeExpression.type.kind === SyntaxKind.JSDocFunctionType) { + if (typeTag && typeTag.typeExpression && typeTag.typeExpression.type && typeTag.typeExpression.type.kind === SyntaxKind.JSDocFunctionType) { const jsDocFunctionType = typeTag.typeExpression.type; if (jsDocFunctionType.parameters.length > 0 && jsDocFunctionType.parameters[0].type.kind === SyntaxKind.JSDocThisType) { return getTypeFromTypeNode(jsDocFunctionType.parameters[0].type); From 259a89e2cfdfe730c1ad4463970d8f213983cf9e Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 10 Feb 2016 12:51:21 -0800 Subject: [PATCH 051/297] Move suppress option to appropriate place --- src/harness/harness.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 230b680eab7..4d48537a911 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -895,7 +895,8 @@ namespace Harness { { name: "includeBuiltFile", type: "string" }, { name: "fileName", type: "string" }, { name: "libFiles", type: "string" }, - { name: "noErrorTruncation", type: "boolean" } + { name: "noErrorTruncation", type: "boolean" }, + { name: "suppressOutputPathCheck", type: "boolean" } ]; let optionsIndex: ts.Map; @@ -938,9 +939,6 @@ namespace Harness { } } } - else if (name === "suppressOutputPathCheck") { - options.suppressOutputPathCheck = true; - } else { throw new Error(`Unknown compiler option '${name}'.`); } From 196d90a4cee527d0d837b2c37903a8eb14c860e7 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Wed, 10 Feb 2016 20:57:53 +0000 Subject: [PATCH 052/297] spelling fixes for src/compiler/binder.ts src/compiler/parser.ts * accidentally * children * exhaustive * initialize * initializer * otherwise * argument * current * delimiter * differently * expression * further * increment * precedence * presence * proceed * signatures * specifier * that * this * unusable --- src/compiler/binder.ts | 20 +++++++++--------- src/compiler/parser.ts | 48 +++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 0e169ca7aca..140902aa4af 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -12,7 +12,7 @@ namespace ts { } const enum Reachability { - Unintialized = 1 << 0, + Uninitialized = 1 << 0, Reachable = 1 << 1, Unreachable = 1 << 2, ReportedUnreachable = 1 << 3 @@ -393,7 +393,7 @@ namespace ts { // the getLocalNameOfContainer function in the type checker to validate that the local name // used for a container is unique. function bindChildren(node: Node) { - // Before we recurse into a node's chilren, we first save the existing parent, container + // Before we recurse into a node's children, we first save the existing parent, container // and block-container. Then after we pop out of processing the children, we restore // these saved values. const saveParent = parent; @@ -418,7 +418,7 @@ namespace ts { // Finally, if this is a block-container, then we clear out any existing .locals object // it may contain within it. This happens in incremental scenarios. Because we can be // reusing a node from a previous compilation, that node may have had 'locals' created - // for it. We must clear this so we don't accidently move any stale data forward from + // for it. We must clear this so we don't accidentally move any stale data forward from // a previous compilation. const containerFlags = getContainerFlags(node); if (containerFlags & ContainerFlags.IsContainer) { @@ -699,7 +699,7 @@ namespace ts { const hasDefault = forEach(n.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause); - // post switch state is unreachable if switch is exaustive (has a default case ) and does not have fallthrough from the last case + // post switch state is unreachable if switch is exhaustive (has a default case ) and does not have fallthrough from the last case const postSwitchState = hasDefault && currentReachabilityState !== Reachability.Reachable ? Reachability.Unreachable : preSwitchState; popImplicitLabel(postSwitchLabel, postSwitchState); @@ -766,7 +766,7 @@ namespace ts { case SyntaxKind.Block: // do not treat blocks directly inside a function as a block-scoped-container. - // Locals that reside in this block should go to the function locals. Othewise 'x' + // Locals that reside in this block should go to the function locals. Otherwise 'x' // would not appear to be a redeclaration of a block scoped local in the following // example: // @@ -956,7 +956,7 @@ namespace ts { const identifier = prop.name; - // ECMA-262 11.1.5 Object Initialiser + // ECMA-262 11.1.5 Object Initializer // If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true // a.This production is contained in strict code and IsDataDescriptor(previous) is true and // IsDataDescriptor(propId.descriptor) is true. @@ -1629,14 +1629,14 @@ namespace ts { if (hasProperty(labelIndexMap, name.text)) { return false; } - labelIndexMap[name.text] = labelStack.push(Reachability.Unintialized) - 1; + labelIndexMap[name.text] = labelStack.push(Reachability.Uninitialized) - 1; return true; } function pushImplicitLabel(): number { initializeReachabilityStateIfNecessary(); - const index = labelStack.push(Reachability.Unintialized) - 1; + const index = labelStack.push(Reachability.Uninitialized) - 1; implicitLabels.push(index); return index; } @@ -1666,7 +1666,7 @@ namespace ts { } function setCurrentStateAtLabel(innerMergedState: Reachability, outerState: Reachability, label: Identifier): void { - if (innerMergedState === Reachability.Unintialized) { + if (innerMergedState === Reachability.Uninitialized) { if (label && !options.allowUnusedLabels) { file.bindDiagnostics.push(createDiagnosticForNode(label, Diagnostics.Unused_label)); } @@ -1687,7 +1687,7 @@ namespace ts { return false; } const stateAtLabel = labelStack[index]; - labelStack[index] = stateAtLabel === Reachability.Unintialized ? outerState : or(stateAtLabel, outerState); + labelStack[index] = stateAtLabel === Reachability.Uninitialized ? outerState : or(stateAtLabel, outerState); return true; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c80883cf890..66d33f9d7d9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -577,7 +577,7 @@ namespace ts { scanner.setText(""); scanner.setOnError(undefined); - // Clear any data. We don't want to accidently hold onto it for too long. + // Clear any data. We don't want to accidentally hold onto it for too long. parseDiagnostics = undefined; sourceFile = undefined; identifiers = undefined; @@ -1442,8 +1442,8 @@ namespace ts { // We can only reuse a node if it was parsed under the same strict mode that we're // currently in. i.e. if we originally parsed a node in non-strict mode, but then // the user added 'using strict' at the top of the file, then we can't use that node - // again as the presense of strict mode may cause us to parse the tokens in the file - // differetly. + // again as the presence of strict mode may cause us to parse the tokens in the file + // differently. // // Note: we *can* reuse tokens when the strict mode changes. That's because tokens // are unaffected by strict mode. It's just the parser will decide what to do with it @@ -1456,7 +1456,7 @@ namespace ts { } // Ok, we have a node that looks like it could be reused. Now verify that it is valid - // in the currest list parsing context that we're currently at. + // in the current list parsing context that we're currently at. if (!canReuseNode(node, parsingContext)) { return undefined; } @@ -1719,7 +1719,7 @@ namespace ts { }; // Parses a comma-delimited list of elements - function parseDelimitedList(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimeter?: boolean): NodeArray { + function parseDelimitedList(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimiter?: boolean): NodeArray { const saveParsingContext = parsingContext; parsingContext |= 1 << kind; const result = >[]; @@ -1748,7 +1748,7 @@ namespace ts { // parse errors. For example, this can happen when people do things like use // a semicolon to delimit object literal members. Note: we'll have already // reported an error when we called parseExpected above. - if (considerSemicolonAsDelimeter && token === SyntaxKind.SemicolonToken && !scanner.hasPrecedingLineBreak()) { + if (considerSemicolonAsDelimiter && token === SyntaxKind.SemicolonToken && !scanner.hasPrecedingLineBreak()) { nextToken(); } continue; @@ -2221,7 +2221,7 @@ namespace ts { method.name = name; method.questionToken = questionToken; - // Method signatues don't exist in expression contexts. So they have neither + // Method signatures don't exist in expression contexts. So they have neither // [Yield] nor [Await] fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, method); parseTypeMemberSemicolon(); @@ -2719,7 +2719,7 @@ namespace ts { function isYieldExpression(): boolean { if (token === SyntaxKind.YieldKeyword) { - // If we have a 'yield' keyword, and htis is a context where yield expressions are + // If we have a 'yield' keyword, and this is a context where yield expressions are // allowed, then definitely parse out a yield expression. if (inYieldContext()) { return true; @@ -2738,7 +2738,7 @@ namespace ts { // // for now we just check if the next token is an identifier. More heuristics // can be added here later as necessary. We just need to make sure that we - // don't accidently consume something legal. + // don't accidentally consume something legal. return lookAhead(nextTokenIsIdentifierOrKeywordOrNumberOnSameLine); } @@ -2767,7 +2767,7 @@ namespace ts { } else { // if the next token is not on the same line as yield. or we don't have an '*' or - // the start of an expressin, then this is just a simple "yield" expression. + // the start of an expression, then this is just a simple "yield" expression. return finishNode(node); } } @@ -3060,7 +3060,7 @@ namespace ts { // Check the precedence to see if we should "take" this operator // - For left associative operator (all operator but **), consume the operator, // recursively call the function below, and parse binaryExpression as a rightOperand - // of the caller if the new precendence of the operator is greater then or equal to the current precendence. + // of the caller if the new precedence of the operator is greater then or equal to the current precedence. // For example: // a - b - c; // ^token; leftOperand = b. Return b to the caller as a rightOperand @@ -3069,8 +3069,8 @@ namespace ts { // a - b * c; // ^token; leftOperand = b. Return b * c to the caller as a rightOperand // - For right associative operator (**), consume the operator, recursively call the function - // and parse binaryExpression as a rightOperand of the caller if the new precendence of - // the operator is strictly grater than the current precendence + // and parse binaryExpression as a rightOperand of the caller if the new precedence of + // the operator is strictly grater than the current precedence // For example: // a ** b ** c; // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand @@ -3311,7 +3311,7 @@ namespace ts { */ function isIncrementExpression(): boolean { // This function is called inside parseUnaryExpression to decide - // whether to call parseSimpleUnaryExpression or call parseIncrmentExpression directly + // whether to call parseSimpleUnaryExpression or call parseIncrementExpression directly switch (token) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: @@ -3799,7 +3799,7 @@ namespace ts { return undefined; } - // If we have a '<', then only parse this as a arugment list if the type arguments + // If we have a '<', then only parse this as a argument list if the type arguments // are complete and we have an open paren. if we don't, rewind and return nothing. return typeArguments && canFollowTypeArgumentsInExpression() ? typeArguments @@ -3996,7 +3996,7 @@ namespace ts { node.multiLine = true; } - node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimeter*/ true); + node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimiter*/ true); parseExpected(SyntaxKind.CloseBraceToken); return finishNode(node); } @@ -4792,8 +4792,8 @@ namespace ts { // off. The grammar would look something like this: // // MemberVariableDeclaration[Yield]: - // AccessibilityModifier_opt PropertyName TypeAnnotation_opt Initialiser_opt[In]; - // AccessibilityModifier_opt static_opt PropertyName TypeAnnotation_opt Initialiser_opt[In, ?Yield]; + // AccessibilityModifier_opt PropertyName TypeAnnotation_opt Initializer_opt[In]; + // AccessibilityModifier_opt static_opt PropertyName TypeAnnotation_opt Initializer_opt[In, ?Yield]; // // The checker may still error in the static case to explicitly disallow the yield expression. property.initializer = modifiers && modifiers.flags & NodeFlags.Static @@ -5394,7 +5394,7 @@ namespace ts { // ImportSpecifier: // BindingIdentifier // IdentifierName as BindingIdentifier - // ExportSpecififer: + // ExportSpecifier: // IdentifierName // IdentifierName as IdentifierName let checkIdentifierIsKeyword = isKeyword(token) && !isIdentifier(); @@ -6238,7 +6238,7 @@ namespace ts { } // Make sure we're not trying to incrementally update a source file more than once. Once - // we do an update the original source file is considered unusbale from that point onwards. + // we do an update the original source file is considered unusable from that point onwards. // // This is because we do incremental parsing in-place. i.e. we take nodes from the old // tree and give them new positions and parents. From that point on, trusting the old @@ -6369,7 +6369,7 @@ namespace ts { // We have an element that intersects the change range in some way. It may have its // start, or its end (or both) in the changed range. We want to adjust any part // that intersects such that the final tree is in a consistent state. i.e. all - // chlidren have spans within the span of their parent, and all siblings are ordered + // children have spans within the span of their parent, and all siblings are ordered // properly. // We may need to update both the 'pos' and the 'end' of the element. @@ -6391,7 +6391,7 @@ namespace ts { // -------------------ZZZ----------------- // // In this case, any element that started in the 'X' range will keep its position. - // However any element htat started after that will have their pos adjusted to be + // However any element that started after that will have their pos adjusted to be // at the end of the new range. i.e. any node that started in the 'Y' range will // be adjusted to have their start at the end of the 'Z' range. // @@ -6416,7 +6416,7 @@ namespace ts { // -------------------ZZZ----------------- // // In this case, any element that ended in the 'X' range will keep its position. - // However any element htat ended after that will have their pos adjusted to be + // However any element that ended after that will have their pos adjusted to be // at the end of the new range. i.e. any node that ended in the 'Y' range will // be adjusted to have their end at the end of the 'Z' range. if (element.end >= changeRangeOldEnd) { @@ -6746,7 +6746,7 @@ namespace ts { // Position was within this node. Keep searching deeper to find the node. forEachChild(node, visitNode, visitArray); - // don't procede any futher in the search. + // don't proceed any further in the search. return true; } From 5b7b57626c51932ef738f7c7425925d436779599 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 10 Feb 2016 13:58:31 -0800 Subject: [PATCH 053/297] split declaration and initialization of writer variable --- src/compiler/declarationEmitter.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 21317fe4918..d8bdd2fb52f 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -51,7 +51,9 @@ namespace ts { let decreaseIndent: () => void; let writeTextOfNode: (text: string, node: Node) => void; - let writer = createAndSetNewTextWriterWithSymbolWriter(); + let writer: EmitTextWriterWithSymbolWriter; + + createAndSetNewTextWriterWithSymbolWriter(); let enclosingDeclaration: Node; let resultHasExternalModuleIndicator: boolean; @@ -174,7 +176,7 @@ namespace ts { } } - function createAndSetNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { + function createAndSetNewTextWriterWithSymbolWriter(): void { const writer = createTextWriter(newLine); writer.trackSymbol = trackSymbol; writer.reportInaccessibleThisError = reportInaccessibleThisError; @@ -186,7 +188,6 @@ namespace ts { writer.writeParameter = writer.write; writer.writeSymbol = writer.write; setWriter(writer); - return writer; } function setWriter(newWriter: EmitTextWriterWithSymbolWriter) { From 5f95c75403a0fbc36032b1cc7865ff2e73bf5233 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 11 Feb 2016 06:18:04 -0800 Subject: [PATCH 054/297] Simplify indexTypesRelatedTo function --- src/compiler/checker.ts | 112 ++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 73 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e6dec1d45ad..0dd945bcb98 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5760,9 +5760,9 @@ namespace ts { if (result) { result &= signaturesRelatedTo(source, target, SignatureKind.Construct, reportErrors); if (result) { - result &= stringIndexTypesRelatedTo(source, originalSource, target, reportErrors); + result &= indexTypesRelatedTo(source, originalSource, target, IndexKind.String, reportErrors); if (result) { - result &= numberIndexTypesRelatedTo(source, originalSource, target, reportErrors); + result &= indexTypesRelatedTo(source, originalSource, target, IndexKind.Number, reportErrors); } } } @@ -5964,10 +5964,10 @@ namespace ts { return result; } - function eachPropertyRelatedTo(source: Type, target: Type, numericPropertiesOnly: boolean, reportErrors: boolean): Ternary { + function eachPropertyRelatedTo(source: Type, target: Type, kind: IndexKind, reportErrors: boolean): Ternary { let result = Ternary.True; for (const prop of getPropertiesOfObjectType(source)) { - if (!numericPropertiesOnly || isNumericLiteralName(prop.name)) { + if (kind === IndexKind.String || isNumericLiteralName(prop.name)) { const related = isRelatedTo(getTypeOfSymbol(prop), target, reportErrors); if (!related) { if (reportErrors) { @@ -5981,82 +5981,48 @@ namespace ts { return result; } - function stringIndexTypesRelatedTo(source: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { - if (relation === identityRelation) { - return indexTypesIdenticalTo(IndexKind.String, source, target); + function indexInfoRelatedTo(sourceInfo: IndexInfo, targetInfo: IndexInfo, reportErrors: boolean) { + const related = isRelatedTo(sourceInfo.type, targetInfo.type, reportErrors); + if (!related && reportErrors) { + reportError(Diagnostics.Index_signatures_are_incompatible); } - const targetInfo = getIndexInfoOfType(target, IndexKind.String); - if (targetInfo) { - if ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { - // non-primitive assignment to any is always allowed, eg - // `var x: { [index: string]: any } = { property: 12 };` - return Ternary.True; + return related; + } + + function indexTypesRelatedTo(source: Type, originalSource: Type, target: Type, kind: IndexKind, reportErrors: boolean) { + if (relation === identityRelation) { + return indexTypesIdenticalTo(source, target, kind); + } + const targetInfo = getIndexInfoOfType(target, kind); + if (!targetInfo || ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive))) { + // Index signature of type any permits assignment from everything but primitives + return Ternary.True; + } + const sourceInfo = getIndexInfoOfType(source, kind) || + kind === IndexKind.Number && getIndexInfoOfType(source, IndexKind.String); + if (sourceInfo) { + return indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors); + } + if (isObjectLiteralType(source)) { + let related = Ternary.True; + if (kind === IndexKind.String) { + const sourceNumberInfo = getIndexInfoOfType(source, IndexKind.Number); + if (sourceNumberInfo) { + related = indexInfoRelatedTo(sourceNumberInfo, targetInfo, reportErrors); + } } - const sourceInfo = getIndexInfoOfType(source, IndexKind.String); - if (!sourceInfo) { - if (isObjectLiteralType(source)) { - return eachPropertyRelatedTo(source, targetInfo.type, /* numericPropertiesOnly*/ false, reportErrors); - } - if (reportErrors) { - reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return Ternary.False; - } - const related = isRelatedTo(sourceInfo.type, targetInfo.type, reportErrors); - if (!related) { - if (reportErrors) { - reportError(Diagnostics.Index_signatures_are_incompatible); - } - return Ternary.False; + if (related) { + related &= eachPropertyRelatedTo(source, targetInfo.type, kind, reportErrors); } return related; } - return Ternary.True; + if (reportErrors) { + reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); + } + return Ternary.False; } - function numberIndexTypesRelatedTo(source: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { - if (relation === identityRelation) { - return indexTypesIdenticalTo(IndexKind.Number, source, target); - } - const targetInfo = getIndexInfoOfType(target, IndexKind.Number); - if (targetInfo) { - if ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { - // non-primitive assignment to any is always allowed, eg - // `var x: { [index: number]: any } = { property: 12 };` - return Ternary.True; - } - const sourceStringInfo = getIndexInfoOfType(source, IndexKind.String); - const sourceNumberInfo = getIndexInfoOfType(source, IndexKind.Number); - if (!(sourceStringInfo || sourceNumberInfo)) { - if (isObjectLiteralType(source)) { - return eachPropertyRelatedTo(source, targetInfo.type, /* numericPropertiesOnly*/ true, reportErrors); - } - if (reportErrors) { - reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return Ternary.False; - } - let related: Ternary; - if (sourceStringInfo && sourceNumberInfo) { - // If we know for sure we're testing both string and numeric index types then only report errors from the second one - related = isRelatedTo(sourceStringInfo.type, targetInfo.type, /*reportErrors*/ false) || - isRelatedTo(sourceNumberInfo.type, targetInfo.type, reportErrors); - } - else { - related = isRelatedTo((sourceStringInfo || sourceNumberInfo).type, targetInfo.type, reportErrors); - } - if (!related) { - if (reportErrors) { - reportError(Diagnostics.Index_signatures_are_incompatible); - } - return Ternary.False; - } - return related; - } - return Ternary.True; - } - - function indexTypesIdenticalTo(indexKind: IndexKind, source: Type, target: Type): Ternary { + function indexTypesIdenticalTo(source: Type, target: Type, indexKind: IndexKind): Ternary { const targetInfo = getIndexInfoOfType(target, indexKind); const sourceInfo = getIndexInfoOfType(source, indexKind); if (!sourceInfo && !targetInfo) { From 284b26f49fa59b2eb349303704e35b4109bccff9 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Thu, 11 Feb 2016 16:56:45 +0000 Subject: [PATCH 055/297] spelling fixes for src/compiler * after * aggressive * appear * asterisks * candidate * conflict * directory * dollar * ellipsis * exports * failures * folder * followed * highlight * inferred * location * occurred * output * propagated * push * rather * remaining * search * stabilized * substitution * successful * even though * will * with --- src/compiler/core.ts | 4 ++-- src/compiler/emitter.ts | 20 ++++++++++---------- src/compiler/program.ts | 18 +++++++++--------- src/compiler/scanner.ts | 4 ++-- src/compiler/sys.ts | 2 +- src/compiler/tsc.ts | 8 ++++---- src/compiler/utilities.ts | 12 ++++++------ 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 21536da36ff..702ded96a3f 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -667,7 +667,7 @@ namespace ts { } function getNormalizedPathComponentsOfUrl(url: string) { - // Get root length of http://www.website.com/folder1/foler2/ + // Get root length of http://www.website.com/folder1/folder2/ // In this example the root is: http://www.website.com/ // normalized path components should be ["http://www.website.com/", "folder1", "folder2"] @@ -695,7 +695,7 @@ namespace ts { const indexOfNextSlash = url.indexOf(directorySeparator, rootLength); if (indexOfNextSlash !== -1) { // Found the "/" after the website.com so the root is length of http://www.website.com/ - // and get components afetr the root normally like any other folder components + // and get components after the root normally like any other folder components rootLength = indexOfNextSlash + 1; return normalizedPathComponents(url, rootLength); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 68f5963157e..f08082d72c8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -407,14 +407,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge interface ConvertedLoopState { /* - * set of labels that occured inside the converted loop + * set of labels that occurred inside the converted loop * used to determine if labeled jump can be emitted as is or it should be dispatched to calling code */ labels?: Map; /* * collection of labeled jumps that transfer control outside the converted loop. * maps store association 'label -> labelMarker' where - * - label - value of label as it apprear in code + * - label - value of label as it appear in code * - label marker - return value that should be interpreted by calling code as 'jump to