New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

typescript.api

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript.api - npm Package Compare versions

Comparing version 0.2.6 to 0.3.0

113

index.js

@@ -1,16 +0,13 @@

var _vm = require("vm");
var _fs = require("fs");
var _path = require("path");
exports.allowRemote = false;
exports.debug = false;
exports.compiler;
function check(units) {
for(var n in units) {
for (var n in units) {
if (units[n].hasError()) {

@@ -20,10 +17,12 @@ return false;

}
return true;
}
exports.check = check;
function register() {
require.extensions['.ts'] = function (_module) {
var output_diagnostics = function (units) {
for(var n in units) {
for(var m in units[n].diagnostics) {
for (var n in units) {
for (var m in units[n].diagnostics) {
console.log(_fs.basename(units[n].path) + ':' + units[n].diagnostics[m].toString());

@@ -33,12 +32,17 @@ }

};
var api = load_typescript_api();
var io = new api.IO.IOSync();
var logger = new api.Loggers.BufferedLogger();
var resolver = new api.Resolve.Resolver(io, logger);
var diagnostics = [];
resolver.resolve([
_module.filename
], function (sourceUnits) {
resolver.resolve([_module.filename], function (sourceUnits) {
if (exports.check(sourceUnits)) {
var compiler = new api.Compile.Compiler(logger);
compiler.compile(sourceUnits, function (compiledUnits) {

@@ -60,7 +64,10 @@ if (exports.check(compiledUnits)) {

exports.register = register;
function create(path, content) {
var api = load_typescript_api();
return new api.Units.SourceUnit(path, content, [], false);
}
exports.create = create;
function resolve(sources, callback) {

@@ -70,40 +77,60 @@ var getType = function (obj) {

};
var _sources = [];
switch(getType(sources)) {
switch (getType(sources)) {
case "string":
_sources.push(sources);
break;
case "array":
_sources = sources;
break;
}
var api = load_typescript_api();
var io = new api.IO.IOAsync();
var logger = new api.Loggers.NullLogger();
if (exports.allowRemote) {
io = new api.IO.IORemoteAsync();
}
if (exports.debug) {
logger = new api.Loggers.ConsoleLogger();
}
var resolver = new api.Resolve.Resolver(io, logger);
resolver.resolve(_sources, callback);
}
exports.resolve = resolve;
function sort(sourceUnits) {
var api = load_typescript_api();
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) {
var api = load_typescript_api();
var logger = new api.Loggers.NullLogger();
if (exports.debug) {
logger = new api.Loggers.ConsoleLogger();
}
if (!exports.compiler) {

@@ -115,18 +142,27 @@ exports.compiler = new api.Compile.Compiler(logger);

exports.compile = compile;
function reset() {
var api = load_typescript_api();
var logger = new api.Loggers.NullLogger();
exports.compiler = new api.Compile.Compiler(logger);
}
exports.reset = reset;
function reflect(compiledUnits, callback) {
var api = load_typescript_api();
var reflection = new api.Reflect.Reflection();
for(var n in compiledUnits) {
for (var n in compiledUnits) {
var script = api.Reflect.Script.create(compiledUnits[n].path, compiledUnits[n].ast);
reflection.scripts.push(script);
}
callback(reflection);
}
exports.reflect = reflect;
function run(compiledUnits, sandbox, callback) {

@@ -137,11 +173,17 @@ try {

}
var sources = [];
for(var n in compiledUnits) {
for (var n in compiledUnits) {
sources.push(compiledUnits[n].content);
}
var script = _vm.createScript(sources.join(''), "typescript-compilation.js");
script.runInNewContext(sandbox);
callback(sandbox.exports);
} catch (e) {
callback(null);
console.log(e);

@@ -151,22 +193,37 @@ }

exports.run = run;
function get_default_sandbox() {
var sandbox = {};
if (!sandbox) {
sandbox = {};
for(var n in global) {
for (var n in global) {
sandbox[n] = global[n];
}
}
sandbox.require = require;
sandbox.process = process;
sandbox.console = console;
sandbox.global = global;
sandbox.__dirname = _path.dirname(process.mainModule.filename);
sandbox.__filename = _path.join(sandbox.__dirname, "typescript-compilation.js");
sandbox.exports = {};
return sandbox;
}
var cache = {};
var typescript_filename = _path.join(__dirname, "typescript.js");
var typescript_api_filename = _path.join(__dirname, "typescript.api.js");
function load_typescript_api() {

@@ -176,2 +233,3 @@ if (cache.typescript_api) {

}
var sandbox = {

@@ -187,7 +245,8 @@ TypeScript: load_typescript(),

};
cache.typescript_api = load_module(typescript_api_filename, sandbox, [
"TypeScript"
]).Api;
cache.typescript_api = load_module(typescript_api_filename, sandbox, ["TypeScript"]).Api;
return cache.typescript_api;
}
function load_typescript() {

@@ -200,15 +259,21 @@ if (cache.typescript) {

};
cache.typescript = load_module(typescript_filename, sandbox, [
"TypeScript"
]);
cache.typescript = load_module(typescript_filename, sandbox, ["TypeScript"]);
return cache.typescript;
}
function load_module(filename, sandbox, export_type_names) {
var source = _fs.readFileSync(filename, 'utf8');
for(var n in export_type_names) {
for (var n in export_type_names) {
source = source.concat('\n\nexports = ' + export_type_names[n] + ';');
}
var script = _vm.createScript(source, _path.basename(filename));
script.runInNewContext(sandbox);
return sandbox.exports;
}
{
"name": "typescript.api",
"version": "0.2.6",
"version": "0.3.0",
"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",

@@ -13,3 +13,3 @@ # typescript.api

TypeScript 0.9 alpha
TypeScript 0.9 - (6/6/2013)

@@ -16,0 +16,0 @@ ## quick start

@@ -18,4 +18,4 @@ declare module TypeScript.Api.Units {

public content: string;
public diagnostics: Diagnostic[];
constructor(path: string, content: string, diagnostics: Diagnostic[]);
public diagnostics: Units.Diagnostic[];
constructor(path: string, content: string, diagnostics: Units.Diagnostic[]);
public hasError(): boolean;

@@ -25,7 +25,7 @@ }

declare module TypeScript.Api.Units {
class SourceUnit extends Unit {
class SourceUnit extends Units.Unit {
public remote: boolean;
public syntaxChecked: boolean;
public typeChecked: boolean;
constructor(path: string, content: string, diagnostics: Diagnostic[], remote: boolean);
constructor(path: string, content: string, diagnostics: Units.Diagnostic[], remote: boolean);
public references(): string[];

@@ -36,3 +36,3 @@ }

interface IIO {
readFile(filename: string, callback: (unit: Units.SourceUnit) => void): void;
readFile(filename: string, callback: (unit: Api.Units.SourceUnit) => void): void;
}

@@ -46,14 +46,14 @@ }

declare module TypeScript.Api.IO {
class IOSync implements IIO {
public readFile(path: string, callback: (sourceUnit: Units.SourceUnit) => void): void;
class IOSync implements IO.IIO {
public readFile(path: string, callback: (sourceUnit: Api.Units.SourceUnit) => void): void;
}
}
declare module TypeScript.Api.IO {
class IOAsync implements IIO {
public readFile(path: string, callback: (sourceUnit: Units.SourceUnit) => void): void;
class IOAsync implements IO.IIO {
public readFile(path: string, callback: (sourceUnit: Api.Units.SourceUnit) => void): void;
}
}
declare module TypeScript.Api.IO {
class IORemoteAsync implements IIO {
public readFile(path: string, callback: (unit: Units.SourceUnit) => void): void;
class IORemoteAsync implements IO.IIO {
public readFile(path: string, callback: (unit: Api.Units.SourceUnit) => void): void;
private readFileFromDisk(path, callback);

@@ -66,3 +66,3 @@ private readFileFromHttp(path, callback);

declare module TypeScript.Api.Loggers {
class NullLogger implements ILogger {
class NullLogger implements TypeScript.ILogger {
public information(): boolean;

@@ -77,3 +77,3 @@ public debug(): boolean;

declare module TypeScript.Api.Loggers {
class ConsoleLogger implements ILogger {
class ConsoleLogger implements TypeScript.ILogger {
public information(): boolean;

@@ -99,3 +99,3 @@ public debug(): boolean;

declare module TypeScript.Api.Loggers {
class BufferedLogger implements ILogger {
class BufferedLogger implements TypeScript.ILogger {
private writer;

@@ -129,4 +129,4 @@ constructor();

class Topology {
static graph(units: Units.SourceUnit[]): Node[];
static sort(units: Units.SourceUnit[]): Units.SourceUnit[];
static graph(units: Api.Units.SourceUnit[]): Node[];
static sort(units: Api.Units.SourceUnit[]): Api.Units.SourceUnit[];
}

@@ -141,9 +141,9 @@ }

class Resolver {
public io: IO.IIO;
public logger: ILogger;
public io: Api.IO.IIO;
public logger: TypeScript.ILogger;
private pending;
private closed;
private units;
constructor(io: IO.IIO, logger: ILogger);
public resolve(sources: string[], callback: (units: Units.SourceUnit[]) => void): void;
constructor(io: Api.IO.IIO, logger: TypeScript.ILogger);
public resolve(sources: string[], callback: (units: Api.Units.SourceUnit[]) => void): void;
private load(callback);

@@ -155,6 +155,6 @@ private next(callback);

declare module TypeScript.Api.Units {
class CompiledUnit extends Unit {
public ast: AST;
class CompiledUnit extends Units.Unit {
public ast: TypeScript.AST;
public declaration: string;
constructor(path: string, content: string, diagnostics: Diagnostic[], ast: AST, declaration: string);
constructor(path: string, content: string, diagnostics: Units.Diagnostic[], ast: TypeScript.AST, declaration: string);
public references(): string[];

@@ -168,8 +168,8 @@ }

resolvePath(path: string): string;
createFile(path: string, useUTF8?: boolean): ITextWriter;
writeFile(fileName: string, contents: string, writeByteOrderMark: boolean): void;
}
class Emitter implements IEmitter {
public files: ITextWriter[];
public files: string[];
constructor();
public createFile(path: string, useUTF8?: boolean): ITextWriter;
public writeFile(fileName: string, contents: string, writeByteOrderMark: boolean): void;
public directoryExists(path: string): boolean;

@@ -182,6 +182,6 @@ public fileExists(path: string): boolean;

class Compiler {
public compiler: TypeScriptCompiler;
public logger: ILogger;
public sourceUnits: Units.SourceUnit[];
constructor(logger: ILogger);
public compiler: TypeScript.TypeScriptCompiler;
public logger: TypeScript.ILogger;
public sourceUnits: Api.Units.SourceUnit[];
constructor(logger: TypeScript.ILogger);
private isSourceUnitInCache(sourceUnit);

@@ -193,3 +193,3 @@ private isSourceUnitUpdated(sourceUnit);

private emitUnits(sourceUnits);
public compile(sourceUnits: Units.SourceUnit[], callback: (compiledUnits: Units.CompiledUnit[]) => void): void;
public compile(sourceUnits: Api.Units.SourceUnit[], callback: (compiledUnits: Api.Units.CompiledUnit[]) => void): void;
}

@@ -203,3 +203,3 @@ }

public minChar: number;
static create(ast: ImportDeclaration): Import;
static create(ast: TypeScript.ImportDeclaration): Import;
}

@@ -216,3 +216,3 @@ }

private static qualifyName(ast);
static create(ast: AST): Type;
static create(ast: TypeScript.AST): Type;
}

@@ -223,7 +223,7 @@ }

public name: string;
public type: Type;
public type: Reflect.Type;
public limChar: number;
public minChar: number;
private static load_type(result, ast);
static create(ast: Parameter): Parameter;
static create(ast: TypeScript.Parameter): Parameter;
}

@@ -234,4 +234,4 @@ }

public name: string;
public parameters: Parameter[];
public returns: Type;
public parameters: Reflect.Parameter[];
public returns: Reflect.Type;
public isStatic: boolean;

@@ -253,4 +253,4 @@ public isAccessor: boolean;

private static load_returns(result, ast);
static load_parameters(result: Method, ast: FunctionDeclaration): void;
static create(ast: FunctionDeclaration): Method;
static load_parameters(result: Method, ast: TypeScript.FunctionDeclaration): void;
static create(ast: TypeScript.FunctionDeclaration): Method;
}

@@ -261,3 +261,3 @@ }

public name: string;
public type: Type;
public type: Reflect.Type;
public isProperty: boolean;

@@ -275,3 +275,3 @@ public isStatic: boolean;

private static load_type(result, ast);
static create(ast: VariableDeclarator): Variable;
static create(ast: TypeScript.VariableDeclarator): Variable;
}

@@ -281,6 +281,6 @@ }

class Interface {
public methods: Method[];
public variables: Variable[];
public methods: Reflect.Method[];
public variables: Reflect.Variable[];
public parameters: string[];
public extends: Type[];
public extends: Reflect.Type[];
public name: string;

@@ -294,3 +294,3 @@ public limChar: number;

private static load_variables(result, ast);
static create(ast: InterfaceDeclaration): Interface;
static create(ast: TypeScript.InterfaceDeclaration): Interface;
}

@@ -300,7 +300,7 @@ }

class Class {
public methods: Method[];
public variables: Variable[];
public methods: Reflect.Method[];
public variables: Reflect.Variable[];
public parameters: string[];
public extends: Type[];
public implements: Type[];
public extends: Reflect.Type[];
public implements: Reflect.Type[];
public name: string;

@@ -315,3 +315,3 @@ public limChar: number;

private static load_variables(result, ast);
static create(ast: ClassDeclaration): Class;
static create(ast: TypeScript.ClassDeclaration): Class;
}

@@ -321,8 +321,8 @@ }

class Module {
public imports: Import[];
public imports: Reflect.Import[];
public modules: Module[];
public interfaces: Interface[];
public classes: Class[];
public methods: Method[];
public variables: Variable[];
public interfaces: Reflect.Interface[];
public classes: Reflect.Class[];
public methods: Reflect.Method[];
public variables: Reflect.Variable[];
public name: string;

@@ -338,3 +338,3 @@ public limChar: number;

private static load_variables(result, ast);
static create(ast: ModuleDeclaration): Module;
static create(ast: TypeScript.ModuleDeclaration): Module;
}

@@ -344,7 +344,7 @@ }

class Script {
public modules: Module[];
public interfaces: Interface[];
public classes: Class[];
public methods: Method[];
public variables: Variable[];
public modules: Reflect.Module[];
public interfaces: Reflect.Interface[];
public classes: Reflect.Class[];
public methods: Reflect.Method[];
public variables: Reflect.Variable[];
public path: string;

@@ -357,3 +357,3 @@ constructor();

private static load_variables(result, ast);
static create(path: string, ast: Script): Script;
static create(path: string, ast: TypeScript.Script): Script;
}

@@ -363,5 +363,5 @@ }

class Reflection {
public scripts: Script[];
public scripts: Reflect.Script[];
constructor();
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc