Expand type definitions for path.{get,set}Data to cover symbols (#13044)
This commit is contained in:
parent
238ce0bac8
commit
1ef78ca55b
@ -105,14 +105,14 @@ class NodePath<T extends t.Node = t.Node> {
|
||||
return this.isScope() ? new Scope(this) : scope;
|
||||
}
|
||||
|
||||
setData(key: string, val: any): any {
|
||||
setData(key: string | symbol, val: any): any {
|
||||
if (this.data == null) {
|
||||
this.data = Object.create(null);
|
||||
}
|
||||
return (this.data[key] = val);
|
||||
}
|
||||
|
||||
getData(key: string, def?: any): any {
|
||||
getData(key: string | symbol, def?: any): any {
|
||||
if (this.data == null) {
|
||||
this.data = Object.create(null);
|
||||
}
|
||||
|
||||
@ -824,7 +824,7 @@ export default class Scope {
|
||||
* Set some arbitrary data on the current scope.
|
||||
*/
|
||||
|
||||
setData(key: string, val: any) {
|
||||
setData(key: string | symbol, val: any) {
|
||||
return (this.data[key] = val);
|
||||
}
|
||||
|
||||
@ -832,7 +832,7 @@ export default class Scope {
|
||||
* Recursively walk up scope tree looking for the data `key`.
|
||||
*/
|
||||
|
||||
getData(key: string): any {
|
||||
getData(key: string | symbol): any {
|
||||
let scope: Scope = this;
|
||||
do {
|
||||
const data = scope.data[key];
|
||||
|
||||
@ -39,5 +39,13 @@ describe("NodePath", () => {
|
||||
|
||||
expect(path.getData("__proto__", "test")).toBe("test");
|
||||
});
|
||||
|
||||
it("can use symbols as keys", () => {
|
||||
const path = new NodePath({}, {});
|
||||
const symbol = Symbol("foo");
|
||||
path.setData(symbol, 42);
|
||||
|
||||
expect(path.getData(symbol)).toBe(42);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user