Skip to content

Commit

Permalink
Cherry-pick PR #50343 into release-4.8 (#50374)
Browse files Browse the repository at this point in the history
Component commits:
da3e304 Change type of deprecated 'decorators' property

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

a2588b8 Update deprecation comments

aebe225 Make 'decorators' optional and 'undefined'

46c30f3 Rename '_decorators' to 'illegalDecorators'

6404716 Update baselines

Co-authored-by: Ron Buckton <rbuckton@microsoft.com>
  • Loading branch information
TypeScript Bot and rbuckton authored Aug 20, 2022
1 parent 99b7928 commit 27a7916
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 440 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43956,7 +43956,7 @@ namespace ts {
}

function checkGrammarDecorators(node: Node): boolean {
if (canHaveIllegalDecorators(node) && some(node.decorators)) {
if (canHaveIllegalDecorators(node) && some(node.illegalDecorators)) {
return grammarErrorOnFirstToken(node, Diagnostics.Decorators_are_not_valid_here);
}
if (!canHaveDecorators(node) || !hasDecorators(node)) {
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/debug.ts
Original file line number Diff line number Diff line change
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
56 changes: 28 additions & 28 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ namespace ts {
node.transformFlags = propagateChildFlags(body) | TransformFlags.ContainsClassFields;

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
node.modifiers = undefined;
return node;
}
Expand All @@ -1452,7 +1452,7 @@ namespace ts {

function finishUpdateClassStaticBlockDeclaration(updated: Mutable<ClassStaticBlockDeclaration>, original: ClassStaticBlockDeclaration) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
updated.modifiers = original.modifiers;
}
return update(updated, original);
Expand All @@ -1476,7 +1476,7 @@ namespace ts {
node.transformFlags |= TransformFlags.ContainsES2015;

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
node.typeParameters = undefined;
node.type = undefined;
return node;
Expand All @@ -1498,7 +1498,7 @@ namespace ts {

function finishUpdateConstructorDeclaration(updated: Mutable<ConstructorDeclaration>, original: ConstructorDeclaration) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
updated.typeParameters = original.typeParameters;
updated.type = original.type;
}
Expand Down Expand Up @@ -3657,7 +3657,7 @@ namespace ts {
}

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
return node;
}

Expand Down Expand Up @@ -3686,7 +3686,7 @@ namespace ts {
function finishUpdateFunctionDeclaration(updated: Mutable<FunctionDeclaration>, original: FunctionDeclaration) {
if (updated !== original) {
// copy children used only for error reporting
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
}
return finishUpdateBaseSignatureDeclaration(updated, original);
}
Expand Down Expand Up @@ -3756,7 +3756,7 @@ namespace ts {
node.transformFlags = TransformFlags.ContainsTypeScript;

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
return node;
}

Expand All @@ -3780,7 +3780,7 @@ namespace ts {

function finishUpdateInterfaceDeclaration(updated: Mutable<InterfaceDeclaration>, original: InterfaceDeclaration) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
}
return update(updated, original);
}
Expand All @@ -3802,7 +3802,7 @@ namespace ts {
node.transformFlags = TransformFlags.ContainsTypeScript;

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
return node;
}

Expand All @@ -3824,7 +3824,7 @@ namespace ts {

function finishUpdateTypeAliasDeclaration(updated: Mutable<TypeAliasDeclaration>, original: TypeAliasDeclaration) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
}
return update(updated, original);
}
Expand All @@ -3847,7 +3847,7 @@ namespace ts {
node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Enum declarations cannot contain `await`

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
return node;
}

Expand All @@ -3866,7 +3866,7 @@ namespace ts {

function finishUpdateEnumDeclaration(updated: Mutable<EnumDeclaration>, original: EnumDeclaration) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
}
return update(updated, original);
}
Expand Down Expand Up @@ -3896,7 +3896,7 @@ namespace ts {
node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Module declarations cannot contain `await`.

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
return node;
}

Expand All @@ -3916,7 +3916,7 @@ namespace ts {

function finishUpdateModuleDeclaration(updated: Mutable<ModuleDeclaration>, original: ModuleDeclaration) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
}
return update(updated, original);
}
Expand Down Expand Up @@ -3961,7 +3961,7 @@ namespace ts {
node.transformFlags = TransformFlags.ContainsTypeScript;

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
node.modifiers = undefined;
return node;
}
Expand All @@ -3975,7 +3975,7 @@ namespace ts {

function finishUpdateNamespaceExportDeclaration(updated: Mutable<NamespaceExportDeclaration>, original: NamespaceExportDeclaration) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
updated.modifiers = original.modifiers;
}
return update(updated, original);
Expand All @@ -4000,7 +4000,7 @@ namespace ts {
node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Import= declaration is always parsed in an Await context

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
return node;
}

Expand All @@ -4022,7 +4022,7 @@ namespace ts {

function finishUpdateImportEqualsDeclaration(updated: Mutable<ImportEqualsDeclaration>, original: ImportEqualsDeclaration) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
}
return update(updated, original);
}
Expand All @@ -4045,7 +4045,7 @@ namespace ts {
node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
return node;
}

Expand All @@ -4067,7 +4067,7 @@ namespace ts {

function finishUpdateImportDeclaration(updated: Mutable<ImportDeclaration>, original: ImportDeclaration) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
}
return update(updated, original);
}
Expand Down Expand Up @@ -4235,7 +4235,7 @@ namespace ts {
node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
return node;
}

Expand All @@ -4253,7 +4253,7 @@ namespace ts {

function finishUpdateExportAssignment(updated: Mutable<ExportAssignment>, original: ExportAssignment) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
}
return update(updated, original);
}
Expand All @@ -4279,7 +4279,7 @@ namespace ts {
node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
return node;
}

Expand All @@ -4303,7 +4303,7 @@ namespace ts {

function finishUpdateExportDeclaration(updated: Mutable<ExportDeclaration>, original: ExportDeclaration) {
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
}
return update(updated, original);
}
Expand Down Expand Up @@ -5162,7 +5162,7 @@ namespace ts {
propagateChildFlags(node.initializer);

// The following properties are used only to report grammar errors
node.decorators = undefined;
node.illegalDecorators = undefined;
node.modifiers = undefined;
node.questionToken = undefined;
node.exclamationToken = undefined;
Expand All @@ -5180,7 +5180,7 @@ namespace ts {
function finishUpdatePropertyAssignment(updated: Mutable<PropertyAssignment>, original: PropertyAssignment) {
// copy children used only for error reporting
if (updated !== original) {
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
updated.modifiers = original.modifiers;
updated.questionToken = original.questionToken;
updated.exclamationToken = original.exclamationToken;
Expand All @@ -5202,7 +5202,7 @@ namespace ts {

// The following properties are used only to report grammar errors
node.equalsToken = undefined;
node.decorators = undefined;
node.illegalDecorators = undefined;
node.modifiers = undefined;
node.questionToken = undefined;
node.exclamationToken = undefined;
Expand All @@ -5221,7 +5221,7 @@ namespace ts {
if (updated !== original) {
// copy children used only for error reporting
updated.equalsToken = original.equalsToken;
updated.decorators = original.decorators;
updated.illegalDecorators = original.illegalDecorators;
updated.modifiers = original.modifiers;
updated.questionToken = original.questionToken;
updated.exclamationToken = original.exclamationToken;
Expand Down
Loading

0 comments on commit 27a7916

Please sign in to comment.