Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typescript-estree): allow writing to deprecated node properties #6670

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 25 additions & 15 deletions packages/typescript-estree/src/convert.ts
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,
});
},
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
});

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