Skip to content

Commit

Permalink
fix 'Invalid Arguments' error for create/update constructor in factory
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Aug 17, 2022
1 parent da3e304 commit a63f47c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/compiler/debug.ts
Expand Up @@ -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<typeof Debug, AnyFunction>;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions src/testRunner/unittests/factory.ts
Expand Up @@ -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,
));
});
});

});
}

0 comments on commit a63f47c

Please sign in to comment.