typescript.api
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -91,6 +91,10 @@ | ||
var api = load_typescript_api(); | ||
var sorted = api.Resolve.UnitTopology.sort(sourceUnits); | ||
return sorted; | ||
return api.Resolve.Topology.sort(sourceUnits); | ||
} | ||
exports.sort = sort; | ||
function graph(sourceUnits) { | ||
var api = load_typescript_api(); | ||
return api.Resolve.Topology.graph(sourceUnits); | ||
} | ||
exports.graph = graph; | ||
function compile(sourceUnits, callback) { | ||
@@ -97,0 +101,0 @@ var api = load_typescript_api(); |
{ | ||
"name": "typescript.api", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -178,2 +178,58 @@ # typescript.api | ||
### typescript.sort ( units ) | ||
Will attempt to sort source units in order of dependency. If cyclic referencing | ||
occurs, the sort will return the units in order in which they are received. | ||
__arguments__ | ||
* units - An array of source units to be sorted. | ||
* returns - the sorted units in order of dependency. | ||
__example__ | ||
The following will create a series of source units which reference each other | ||
as in the following graph. The units are first randomized and then sorted. The | ||
resulting sort will be the order of a, b, c, d, e, f. | ||
```javascript | ||
/* | ||
[a] | ||
/ \ | ||
[b] [c] | ||
/ \ / \ | ||
[d] [e] [f] | ||
*/ | ||
function shuffle(o) { | ||
for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); | ||
return o; | ||
}; | ||
var units = [ | ||
typescript.create("a.ts", ""), | ||
typescript.create("b.ts", "/// <reference path='a.ts' />"), | ||
typescript.create("c.ts", "/// <reference path='a.ts' />"), | ||
typescript.create("d.ts", "/// <reference path='b.ts' />"), | ||
typescript.create("e.ts", "/// <reference path='b.ts' />\n/// <reference path='c.ts' />\n"), | ||
typescript.create("f.ts", "/// <reference path='c.ts' />"), | ||
]; | ||
// shuffle | ||
units = shuffle(units); | ||
// sort | ||
units = typescript.sort(units); | ||
// display | ||
for (var n in units) { | ||
console.log(units[n].path); | ||
} | ||
``` | ||
### typescript.compile ( units, callback ) | ||
@@ -180,0 +236,0 @@ |
@@ -116,5 +116,13 @@ declare module TypeScript.Api.Units { | ||
declare module TypeScript.Api.Resolve { | ||
class UnitTopology { | ||
class Node { | ||
public path: string; | ||
public references: string[]; | ||
constructor(); | ||
} | ||
class Topology { | ||
static graph(units: Units.SourceUnit[]): Node[]; | ||
static sort(units: Units.SourceUnit[]): Units.SourceUnit[]; | ||
} | ||
} | ||
declare module TypeScript.Api.Resolve { | ||
class LoadParameter { | ||
@@ -121,0 +129,0 @@ public parent_filename: string; |
Sorry, the diff of this file is too big to display
2855136
55716
323