mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix 'Invalid Arguments' error for create/update constructor in factory
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user