Skip to content

Commit 83926a2

Browse files
authored
Merge pull request #1 from franzbecker/support-symbol-npm-test-publish
Add symbol support and rename package
2 parents 9f74f08 + 7396b62 commit 83926a2

File tree

9 files changed

+30
-6
lines changed

9 files changed

+30
-6
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "@khanacademy/flow-to-ts",
3-
"version": "0.5.2",
2+
"name": "@monzo/flow-to-ts",
3+
"version": "0.5.3",
44
"publishConfig": {
55
"access": "public"
66
},
77
"repository": {
88
"type": "git",
9-
"url": "https://github.com/khan/flow-to-ts"
9+
"url": "https://github.com/monzo/flow-to-ts"
1010
},
1111
"main": "dist/convert.js",
1212
"bin": {

src/transform.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ export const transform = {
277277
path.replaceWith(t.tsArrayType(elementType));
278278
},
279279
},
280+
SymbolTypeAnnotation: {
281+
exit(path) {
282+
path.replaceWith(t.tsSymbolKeyword());
283+
},
284+
},
280285
TupleTypeAnnotation: {
281286
exit(path) {
282287
const { types } = path.node;

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a: symbol;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a: symbol;
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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let obj: string | symbol;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let obj: string | symbol;

0 commit comments

Comments
 (0)