diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 0d9002a1ddb..fc08a862007 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2267,6 +2267,11 @@ namespace ts { transformFlags |= TransformFlags.AssertTypeScript; } + // If the parameter's name is 'this', then it is TypeScript syntax. + if (node.name && (node.name as Identifier).originalKeywordKind === SyntaxKind.ThisKeyword) { + transformFlags |= TransformFlags.AssertTypeScript; + } + // If a parameter has an accessibility modifier, then it is TypeScript syntax. if (hasModifier(node, ModifierFlags.AccessibilityModifier)) { transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.ContainsParameterPropertyAssignments; diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 9f13f2b64ba..e9cb4118a12 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -359,6 +359,7 @@ namespace ts { // - accessibility modifiers // - the question mark (?) token for optional parameters // - type annotations + // - this parameters return visitParameter(node); case SyntaxKind.ParenthesizedExpression: @@ -2120,10 +2121,14 @@ namespace ts { * This function will be called when one of the following conditions are met: * - The node has an accessibility modifier. * - The node has a questionToken. + * - The node's kind is ThisKeyword. * * @param node The parameter declaration node. */ function visitParameter(node: ParameterDeclaration) { + if (node.name && (node.name as Identifier).originalKeywordKind === SyntaxKind.ThisKeyword) { + return undefined; + } const clone = getMutableClone(node); clone.decorators = undefined; clone.modifiers = undefined; diff --git a/tests/baselines/reference/thisTypeInFunctionsNegative.js b/tests/baselines/reference/thisTypeInFunctionsNegative.js index 124a7c88013..93c65031212 100644 --- a/tests/baselines/reference/thisTypeInFunctionsNegative.js +++ b/tests/baselines/reference/thisTypeInFunctionsNegative.js @@ -341,18 +341,19 @@ var ThisConstructor = (function () { return ThisConstructor; }()); var thisConstructorType; -function notFirst(a, this) { return this.n; } +function notFirst(a) { return this.n; } ///// parse errors ///// function modifiers(, C) { if ( === void 0) { = this; } return this.n; } -function restParam(, C) { return this.n; } +function restParam(C) { return this.n; } function optional(C) { return this.n; } function decorated(, C) { if ( === void 0) { = this; } return this.n; } +function initializer() { } new C(); number; {