Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit a8ffde3

Browse files
committed
add support for well known symbols
1 parent e6f5640 commit a8ffde3

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/transforms/object-type.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ export const ObjectTypeCallProperty = {
138138

139139
export const ObjectTypeProperty = {
140140
exit(path, state) {
141+
let { key } = path.node;
141142
const {
142-
key,
143143
value,
144144
optional,
145145
variance,
@@ -151,9 +151,8 @@ export const ObjectTypeProperty = {
151151
} = path.node; // TODO: static, kind
152152
const typeAnnotation = t.tsTypeAnnotation(value);
153153
const initializer = undefined; // TODO: figure out when this used
154-
const computed = false; // TODO: maybe set this to true for indexers
154+
let computed = false;
155155
const readonly = variance && variance.kind === "plus";
156-
157156
if (variance && variance.kind === "minus") {
158157
// TODO: include file and location of infraction
159158
console.warn("typescript doesn't support writeonly properties");
@@ -162,6 +161,16 @@ export const ObjectTypeProperty = {
162161
console.warn("we don't handle get() or set() yet, :P");
163162
}
164163

164+
if (t.isIdentifier(key)) {
165+
if (key.name.startsWith("@@")) {
166+
key = t.memberExpression(
167+
t.identifier("Symbol"),
168+
t.identifier(key.name.replace("@@", ""))
169+
);
170+
computed = true;
171+
}
172+
}
173+
165174
if (method) {
166175
// TODO: assert value is a FunctionTypeAnnotation
167176
const methodSignature = {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface Iterable<T> {
2+
@@iterator(): Iterator<T>;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface Iterable<T> {
2+
[Symbol.iterator](): Iterator<T>;
3+
}

0 commit comments

Comments
 (0)