blakeembrey / blakeembrey/javascript-stringify
Add support for getters & setters in objects
- 主要语言
- TypeScript
- 星标
- 146
- 派生
- 16
- PR 合并指标
- 30 天内没有已合并 PR
描述
Currently, objects with [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) and [setters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set) are not handled correctly:
```ts
const input = {
_foo: null,
get foo() {
return this._foo;
},
set foo(value) {
this._foo = value;
}
};
const output = "{_foo:null,foo:null}";
```
This problem can be solved by adding an extra case to [the object stringification logic](https://github.com/blakeembrey/javascript-stringify/blob/master/src/object.ts#L8) that checks for the given descriptors:
```ts
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
if (descriptor && (descriptor.get || descriptor.set)) { ... }
```
I made a demo in a forked repo with [this commit](https://github.com/Etheryte/javascript-stringify/commit/f1c0c7b834fc7d0ef2e1f0cfd4dd8273557f4563) demonstrating the approach.
Sadly, I didn't have time to figure out all of the lexer logic on the go so it isn't clean enough for a flat out PR.
贡献指南
这个仓库没有索引到贡献指南
调研方向
从 src/object.ts 中的对象字符串化逻辑开始,并将其与链接的演示 commit 进行比较。跟踪属性描述符和 lexer 逻辑如何生成对象输出,然后验证 getter/setter 示例会序列化为 "{_foo:null,foo:null}",且不会破坏普通属性。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100