From 7259b9fd4aa29ffb83acfffd14f55e6bee8c5d87 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 27 Jan 2016 14:00:33 -0800 Subject: [PATCH 1/2] Allow multiple 'this' property assignments in Salsa Fixes issue #6645 --- src/compiler/binder.ts | 3 ++- .../getJavaScriptSemanticDiagnostics23.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics23.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 88a1a62ce4..dbfe3a5195 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1435,7 +1435,8 @@ namespace ts { // Declare a 'member' in case it turns out the container was an ES5 class if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) { container.symbol.members = container.symbol.members || {}; - declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + // It's acceptable for multiple 'this' assignments of the same identifier to occur + declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property); } } diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics23.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics23.ts new file mode 100644 index 0000000000..2524e50e66 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics23.ts @@ -0,0 +1,14 @@ +/// + +// @allowJs: true +// @Filename: a.js +//// function Person(age) { +//// if (age >= 18) { +//// this.canVote = true; +//// } else { +//// this.canVote = false; +//// } +//// } + +verify.getSyntacticDiagnostics(`[]`); +verify.getSemanticDiagnostics(`[]`); From a4c6f666862d14e187bb7e09615fdfc0c92ab875 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 1 Feb 2016 20:59:37 -0800 Subject: [PATCH 2/2] Treat multiple prototype property assignments as union property declarations --- src/compiler/checker.ts | 2 +- .../getJavaScriptSemanticDiagnostics24.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 61c05d7688..5cce092feb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2827,7 +2827,7 @@ namespace ts { } // Handle module.exports = expr if (declaration.kind === SyntaxKind.BinaryExpression) { - return links.type = checkExpression((declaration).right); + return links.type = getUnionType(map(symbol.declarations, (decl: BinaryExpression) => checkExpressionCached(decl.right))); } if (declaration.kind === SyntaxKind.PropertyAccessExpression) { // Declarations only exist for property access expressions for certain diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts new file mode 100644 index 0000000000..cf70f883e9 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts @@ -0,0 +1,16 @@ +/// + +// @allowJs: true +// @Filename: a.js +//// function Person(age) { +//// if (age >= 18) { +//// this.canVote = true; +//// } else { +//// this.canVote = 23; +//// } +//// } +//// let x = new Person(100); +//// x.canVote/**/; + +goTo.marker(); +verify.quickInfoIs('(property) Person.canVote: boolean | number');