Skip to content

Commit

Permalink
typechecker update
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocampinhos committed Jul 19, 2016
1 parent 41c3b67 commit 88c819c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "babel-plugin-transform-niverso",
"version": "0.0.0",
"description": "plugin de teste",
"author": "João Campinhos",
Expand Down
52 changes: 41 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class IntRelation {
return new Array(vv + 1).join(0).split('');
}
}
IntRelation.NOTHING = 0;
IntRelation.EVERYTHING = 0;

let relation = new IntRelation();

Expand Down Expand Up @@ -48,29 +50,57 @@ class VersionedType {
const type = relation.typeToRoot(v);
this.nodes[v] = t;

console.log(path);
console.log(type);
let big = relation.NOTHING;

for (let x of path) {
console.log(x);
console.log(type);
console.log(type.pop());
const tmp = type.pop();
if (!tmp) break;
if (tmp > big) big = tmp;
switch (big) {
case relation.NOTHING:
if (this.nodes[x].type !== t.type) {
throw new Error(`
Incompatible types between version ${v} and ${x}
Name: ${this.id}
type ${v}: ${t.type}
type ${x}: ${this.nodes[x].type}`);
}

break;
case relation.EVERYTHING:
default:
}
}

return this;
}

//Verificações
//console.log(relation.pathToRoot(v));
_compareTypes(t1, t2) {
if (t1.type !== t2.type) return false;

// ...
}
}

export default function ({ types: t }) {
let ids = {};

// let vt = new VersionedType(IntRelation);

return {
visitor: {
CallExpression(path) {
const call = path.node.callee;
if (call.object &&
call.object.name === 'niverso' &&
call.property.name !== 'use' &&
call.property.name !== 'start') {
console.log('---------------------------');
console.log('TODO: Verificar');
console.log(path.node.arguments[0].value);
console.log(path.node.arguments[1].value);
console.log(path.node.arguments[2].body.name);
console.log('---------------------------');
}
},

ArrowFunctionExpression(path) {
const params = path.node.params;
if (params.length === 1 &&
Expand Down Expand Up @@ -98,7 +128,7 @@ export default function ({ types: t }) {
path.scope.rename(name, name + '__' + version);
if (!(name in ids))
ids[name] = new VersionedType(name);
console.log(name,version,type);
//console.log(name,version,type);
ids[name].add(version, type);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/parse flow annotations/actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Name = {
};

(version = 2) => {
let users = (req, res): number => {
let users = (req, res): User => {
return {
name: 'João Campinhos',
age: 24,
Expand Down
45 changes: 43 additions & 2 deletions test/fixtures/parse flow annotations/expected.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
var a = true;
function smth(x) {
// @flow

var a: bool = true;
function smth(x: number): number {
return x;
}

type User = {
name: string;
age: number;
};

type User1 = {
name: Name;
age: number;
};

type Name = {
first: string;
last: string;
};

let users__1 = (req, res): User => {
return {
name: 'João Campinhos',
age: 24
};
};

let users__2 = (req, res): User => {
return {
name: 'João Campinhos',
age: 24
};
};

let users__3 = (req, res): User => {
return {
name: {
first: 'João',
last: 'Campinhos'
},
age: 24
};
};

0 comments on commit 88c819c

Please sign in to comment.