fix 'Invalid Arguments' error for create/update constructor in factory

This commit is contained in:
Ron Buckton
2022-08-17 16:06:13 -04:00
parent da3e3040e8
commit a63f47cf4f
3 changed files with 39 additions and 3 deletions
+2 -1
View File
@@ -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>;
@@ -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;
}
@@ -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
+35
View File
@@ -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,
));
});
});
});
}