diff --git a/src/compiler/debug.ts b/src/compiler/debug.ts index 4f9d8dd554304..c48b1114cb4a1 100644 --- a/src/compiler/debug.ts +++ b/src/compiler/debug.ts @@ -30,6 +30,7 @@ namespace ts { export let currentLogLevel = LogLevel.Warning; export let isDebugging = false; export let loggingHost: LoggingHost | undefined; + export let enableDeprecationWarnings = true; /* eslint-enable prefer-const */ type AssertionKeys = MatchingKeys; @@ -732,7 +733,7 @@ namespace ts { function createWarningDeprecation(name: string, errorAfter: Version | undefined, since: Version | undefined, message: string | undefined) { let hasWrittenDeprecation = false; return () => { - if (!hasWrittenDeprecation) { + if (enableDeprecationWarnings && !hasWrittenDeprecation) { log.warn(formatDeprecationMessage(name, /*error*/ false, errorAfter, since, message)); hasWrittenDeprecation = true; } diff --git a/src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts b/src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts index 586d1d5cedd56..4d44bfb84e11a 100644 --- a/src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts +++ b/src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts @@ -477,7 +477,7 @@ namespace ts { (decorators === undefined || !some(decorators, isModifier)) && (modifiers === undefined || !some(modifiers, isParameter)) && (parameters === undefined || isArray(parameters)) && - (body === undefined || !isBlock(body)), + (body === undefined || isBlock(body)), }) .deprecate({ 1: DISALLOW_DECORATORS @@ -505,7 +505,7 @@ namespace ts { (decorators === undefined || !some(decorators, isModifier)) && (modifiers === undefined || !some(modifiers, isParameter)) && (parameters === undefined || isArray(parameters)) && - (body === undefined || !isBlock(body)), + (body === undefined || isBlock(body)), }) .deprecate({ 1: DISALLOW_DECORATORS diff --git a/src/testRunner/unittests/factory.ts b/src/testRunner/unittests/factory.ts index 9bf9feda8744d..93c34c520a712 100644 --- a/src/testRunner/unittests/factory.ts +++ b/src/testRunner/unittests/factory.ts @@ -81,5 +81,40 @@ namespace ts { checkRhs(SyntaxKind.QuestionQuestionEqualsToken, /*expectParens*/ false); }); }); + + describe("deprecations", () => { + beforeEach(() => { + Debug.enableDeprecationWarnings = false; + }); + + afterEach(() => { + Debug.enableDeprecationWarnings = true; + }); + + // https://github.com/microsoft/TypeScript/issues/50259 + it("deprecated createConstructorDeclaration overload does not throw", () => { + const body = factory.createBlock([]); + assert.doesNotThrow(() => factory.createConstructorDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*parameters*/ [], + body, + )); + }); + + // https://github.com/microsoft/TypeScript/issues/50259 + it("deprecated updateConstructorDeclaration overload does not throw", () => { + const body = factory.createBlock([]); + const ctor = factory.createConstructorDeclaration(/*modifiers*/ undefined, [], body); + assert.doesNotThrow(() => factory.updateConstructorDeclaration( + ctor, + ctor.decorators, + ctor.modifiers, + ctor.parameters, + ctor.body, + )); + }); + }); + }); }