Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@khanacademy/flow-to-ts",
"version": "0.5.2",
"name": "@monzo/flow-to-ts",
"version": "0.5.3",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/khan/flow-to-ts"
"url": "https://github.com/monzo/flow-to-ts"
},
"main": "dist/convert.js",
"bin": {
Expand Down
5 changes: 5 additions & 0 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ export const transform = {
path.replaceWith(t.tsArrayType(elementType));
},
},
SymbolTypeAnnotation: {
exit(path) {
path.replaceWith(t.tsSymbolKeyword());
},
},
TupleTypeAnnotation: {
exit(path) {
const { types } = path.node;
Expand Down
15 changes: 12 additions & 3 deletions src/transforms/object-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ export const ObjectTypeCallProperty = {

export const ObjectTypeProperty = {
exit(path, state) {
let { key } = path.node;
const {
key,
value,
optional,
variance,
Expand All @@ -151,9 +151,8 @@ export const ObjectTypeProperty = {
} = path.node; // TODO: static, kind
const typeAnnotation = t.tsTypeAnnotation(value);
const initializer = undefined; // TODO: figure out when this used
const computed = false; // TODO: maybe set this to true for indexers
let computed = false;
const readonly = variance && variance.kind === "plus";

if (variance && variance.kind === "minus") {
// TODO: include file and location of infraction
console.warn("typescript doesn't support writeonly properties");
Expand All @@ -162,6 +161,16 @@ export const ObjectTypeProperty = {
console.warn("we don't handle get() or set() yet, :P");
}

if (t.isIdentifier(key)) {
if (key.name.startsWith("@@")) {
key = t.memberExpression(
t.identifier("Symbol"),
t.identifier(key.name.replace("@@", ""))
);
computed = true;
}
}

if (method) {
// TODO: assert value is a FunctionTypeAnnotation
const methodSignature = {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/convert/basic-types/symbol01/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let a: symbol;
1 change: 1 addition & 0 deletions test/fixtures/convert/basic-types/symbol01/ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let a: symbol;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Iterable<T> {
@@iterator(): Iterator<T>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Iterable<T> {
[Symbol.iterator](): Iterator<T>;
}
1 change: 1 addition & 0 deletions test/fixtures/convert/intersection-union/union02/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let obj: string | symbol;
1 change: 1 addition & 0 deletions test/fixtures/convert/intersection-union/union02/ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let obj: string | symbol;