Skip to content

Commit a63f47c

Browse files
committed
fix 'Invalid Arguments' error for create/update constructor in factory
1 parent da3e304 commit a63f47c

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/compiler/debug.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace ts {
3030
export let currentLogLevel = LogLevel.Warning;
3131
export let isDebugging = false;
3232
export let loggingHost: LoggingHost | undefined;
33+
export let enableDeprecationWarnings = true;
3334
/* eslint-enable prefer-const */
3435

3536
type AssertionKeys = MatchingKeys<typeof Debug, AnyFunction>;
@@ -732,7 +733,7 @@ namespace ts {
732733
function createWarningDeprecation(name: string, errorAfter: Version | undefined, since: Version | undefined, message: string | undefined) {
733734
let hasWrittenDeprecation = false;
734735
return () => {
735-
if (!hasWrittenDeprecation) {
736+
if (enableDeprecationWarnings && !hasWrittenDeprecation) {
736737
log.warn(formatDeprecationMessage(name, /*error*/ false, errorAfter, since, message));
737738
hasWrittenDeprecation = true;
738739
}

src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ namespace ts {
477477
(decorators === undefined || !some(decorators, isModifier)) &&
478478
(modifiers === undefined || !some(modifiers, isParameter)) &&
479479
(parameters === undefined || isArray(parameters)) &&
480-
(body === undefined || !isBlock(body)),
480+
(body === undefined || isBlock(body)),
481481
})
482482
.deprecate({
483483
1: DISALLOW_DECORATORS
@@ -505,7 +505,7 @@ namespace ts {
505505
(decorators === undefined || !some(decorators, isModifier)) &&
506506
(modifiers === undefined || !some(modifiers, isParameter)) &&
507507
(parameters === undefined || isArray(parameters)) &&
508-
(body === undefined || !isBlock(body)),
508+
(body === undefined || isBlock(body)),
509509
})
510510
.deprecate({
511511
1: DISALLOW_DECORATORS

src/testRunner/unittests/factory.ts

+35
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,40 @@ namespace ts {
8181
checkRhs(SyntaxKind.QuestionQuestionEqualsToken, /*expectParens*/ false);
8282
});
8383
});
84+
85+
describe("deprecations", () => {
86+
beforeEach(() => {
87+
Debug.enableDeprecationWarnings = false;
88+
});
89+
90+
afterEach(() => {
91+
Debug.enableDeprecationWarnings = true;
92+
});
93+
94+
// https://github.com/microsoft/TypeScript/issues/50259
95+
it("deprecated createConstructorDeclaration overload does not throw", () => {
96+
const body = factory.createBlock([]);
97+
assert.doesNotThrow(() => factory.createConstructorDeclaration(
98+
/*decorators*/ undefined,
99+
/*modifiers*/ undefined,
100+
/*parameters*/ [],
101+
body,
102+
));
103+
});
104+
105+
// https://github.com/microsoft/TypeScript/issues/50259
106+
it("deprecated updateConstructorDeclaration overload does not throw", () => {
107+
const body = factory.createBlock([]);
108+
const ctor = factory.createConstructorDeclaration(/*modifiers*/ undefined, [], body);
109+
assert.doesNotThrow(() => factory.updateConstructorDeclaration(
110+
ctor,
111+
ctor.decorators,
112+
ctor.modifiers,
113+
ctor.parameters,
114+
ctor.body,
115+
));
116+
});
117+
});
118+
84119
});
85120
}

0 commit comments

Comments
 (0)