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

Commit 564b07d

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

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/transforms/object-type.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as t from "@babel/types";
22
import { trackComments } from "../util";
3+
import { identifier, objectTypeIndexer } from "@babel/types";
34

45
export const ObjectTypeAnnotation = {
56
enter(path, state) {
@@ -138,8 +139,8 @@ export const ObjectTypeCallProperty = {
138139

139140
export const ObjectTypeProperty = {
140141
exit(path, state) {
142+
let { key } = path.node;
141143
const {
142-
key,
143144
value,
144145
optional,
145146
variance,
@@ -151,9 +152,8 @@ export const ObjectTypeProperty = {
151152
} = path.node; // TODO: static, kind
152153
const typeAnnotation = t.tsTypeAnnotation(value);
153154
const initializer = undefined; // TODO: figure out when this used
154-
const computed = false; // TODO: maybe set this to true for indexers
155+
let computed = false;
155156
const readonly = variance && variance.kind === "plus";
156-
157157
if (variance && variance.kind === "minus") {
158158
// TODO: include file and location of infraction
159159
console.warn("typescript doesn't support writeonly properties");
@@ -162,6 +162,16 @@ export const ObjectTypeProperty = {
162162
console.warn("we don't handle get() or set() yet, :P");
163163
}
164164

165+
if (t.isIdentifier(key)) {
166+
if (key.name.startsWith("@@")) {
167+
key = t.memberExpression(
168+
t.identifier("Symbol"),
169+
t.identifier(key.name.replace("@@", ""))
170+
);
171+
computed = true;
172+
}
173+
}
174+
165175
if (method) {
166176
// TODO: assert value is a FunctionTypeAnnotation
167177
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)