Skip to content

Commit

Permalink
fix(typescript-estree): allow writing to deprecated node properties
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Mar 18, 2023
1 parent 28a64b5 commit 844391b
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3319,23 +3319,33 @@ export class Converter {
aliasKey: AliasKey,
valueKey: ValueKey,
): Properties & Record<AliasKey, Properties[ValueKey]> {
let errored = false;
if (this.options.suppressDeprecatedPropertyWarnings) {
(node as any)[aliasKey] = node[valueKey];
return node as Properties & Record<AliasKey, Properties[ValueKey]>;
}

let warned = false;

Object.defineProperty(node, aliasKey, {
get: this.options.suppressDeprecatedPropertyWarnings
? (): Properties[typeof valueKey] => node[valueKey]
: (): Properties[typeof valueKey] => {
if (!this.options.suppressDeprecatedPropertyWarnings) {
if (!errored) {
// eslint-disable-next-line no-console
console.warn(
`The '${aliasKey}' property is deprecated on ${node.type} nodes. Use '${valueKey}' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`,
);
errored = true;
}
}
return node[valueKey];
},
configurable: true,
get(): Properties[typeof valueKey] {
if (!warned) {
// eslint-disable-next-line no-console
console.warn(
`The '${aliasKey}' property is deprecated on ${node.type} nodes. Use '${valueKey}' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`,
);
warned = true;
}

return node[valueKey];
},
set(value): void {
Object.defineProperty(node, aliasKey, {
enumerable: true,
writable: true,
value,
});
},
});

return node as Properties & Record<AliasKey, Properties[ValueKey]>;
Expand Down

0 comments on commit 844391b

Please sign in to comment.