Comparing version 0.0.13 to 0.0.14
{ | ||
"name": "tsun", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "TSUN: a repl for TypeScript Upgraded Node", | ||
@@ -10,3 +10,3 @@ "bin": "./bin/tsun", | ||
"temp": "^0.8.1", | ||
"typescript": "^1.8.0-dev.20151219" | ||
"typescript": "1.8.0-dev.20160101" | ||
}, | ||
@@ -13,0 +13,0 @@ "scripts": { |
97
tsun.ts
/// <reference path='./typings/node.d.ts' /> | ||
/// <reference path='./typings/colors.d.ts' /> | ||
/// <reference path='./node_modules/typescript/lib/typescript.d.ts' /> | ||
import readline = require('readline') | ||
import util = require('util') | ||
import vm = require('vm') | ||
import path = require('path') | ||
import ConsoleModule = require('console') | ||
import ts = require('typescript') | ||
import fs = require('fs') | ||
import colors = require('colors') | ||
import os = require('os') | ||
import child_process = require('child_process') | ||
import * as readline from 'readline' | ||
import * as util from 'util' | ||
import * as vm from 'vm' | ||
import * as path from 'path' | ||
import {Console} from 'console' | ||
import * as ts from 'typescript' | ||
import * as fs from 'fs' | ||
import * as colors from 'colors' | ||
import * as os from 'os' | ||
import * as child_process from 'child_process' | ||
var Console = ConsoleModule.Console | ||
var builtinLibs = require('repl')._builtinLibs | ||
@@ -80,3 +78,3 @@ | ||
function linkDir(src, dest) { | ||
function linkDir(src: string, dest: string) { | ||
let files = ['node_modules', 'typings'] | ||
@@ -145,2 +143,3 @@ for (let file of files) { | ||
target: ts.ScriptTarget.ES5, | ||
newLine: ts.NewLineKind.LineFeed, | ||
experimentalDecorators: true | ||
@@ -172,3 +171,3 @@ }), | ||
output: process.stdout, | ||
completer(line) { | ||
completer(line: string) { | ||
// append new line to get completions, then revert new line | ||
@@ -180,3 +179,3 @@ versionCounter++ | ||
let candidates = ['type', 'detail', 'source', 'paste', 'clear', 'print', 'help'] | ||
candidates = candidates.map(c => ':' + c).filter(c => c.indexOf(line) >= 0) | ||
candidates = candidates.map(c => ':' + c).filter(c => c.indexOf(line) >= 0) | ||
return [candidates, line.trim()] | ||
@@ -190,3 +189,3 @@ } | ||
let prefix = /[A-Za-z_$]+$/.exec(line) | ||
let candidates = [] | ||
let candidates: string[] = [] | ||
if (prefix) { | ||
@@ -210,3 +209,3 @@ let prefixStr = prefix[0] | ||
'use strict'; | ||
var context; | ||
var context: any; | ||
context = vm.createContext(); | ||
@@ -223,3 +222,3 @@ for (var g in global) { | ||
// Lazy load modules on use | ||
builtinLibs.forEach(function (name) { | ||
builtinLibs.forEach(function (name: string) { | ||
Object.defineProperty(context, name, { | ||
@@ -232,3 +231,3 @@ get: function () { | ||
// Allow creation of globals of the same name | ||
set: function (val) { | ||
set: function (val: any) { | ||
delete context[name]; | ||
@@ -245,9 +244,9 @@ context[name] = val; | ||
// private api hacks | ||
function collectDeclaration(sourceFile): any { | ||
let decls = sourceFile.getNamedDeclarations() | ||
var ret = {} | ||
for (let decl in decls) { | ||
ret[decl] = decls[decl].map(t => t.name) | ||
} | ||
return ret | ||
function collectDeclaration(sourceFile: any): any { | ||
let decls = sourceFile.getNamedDeclarations() | ||
var ret: any = {} | ||
for (let decl in decls) { | ||
ret[decl] = decls[decl].map((t: any) => t.name) | ||
} | ||
return ret | ||
} | ||
@@ -263,3 +262,3 @@ | ||
if (!cached) { | ||
declarations[dummyFile] = collectDeclaration(service.getSourceFile(dummyFile)) | ||
declarations[dummyFile] = collectDeclaration(service.getSourceFile(dummyFile)) | ||
} | ||
@@ -271,3 +270,3 @@ return declarations | ||
function getMemberInfo(member, file, parentDeclaration): string { | ||
function getMemberInfo(member: ts.ClassElement, file: string, parentDeclaration: any): string { | ||
// member info is stored as the first | ||
@@ -314,3 +313,3 @@ let pos = member.getStart() | ||
function getSource(name) { | ||
function getSource(name: string) { | ||
let declarations = getDeclarations() | ||
@@ -349,3 +348,3 @@ for (let file in declarations) { | ||
function getType(name, detailed) { | ||
function getType(name: string, detailed: boolean) { | ||
let declarations = getDeclarations() | ||
@@ -380,3 +379,2 @@ for (let file in declarations) { | ||
function getDiagnostics() { | ||
let emit = service.getEmitOutput(dummyFile) | ||
let allDiagnostics = service.getCompilerOptionsDiagnostics() | ||
@@ -393,3 +391,12 @@ .concat(service.getSyntacticDiagnostics(dummyFile)) | ||
function startEvaluate(code) { | ||
var storedLine = 0 | ||
function getCurrentCode() { | ||
let emit = service.getEmitOutput(dummyFile) | ||
let lines = emit.outputFiles[0].text.split('\r\n').filter(k => !!k) | ||
let ret = lines.slice(storedLine).join('\n') | ||
storedLine = lines.length | ||
return ret | ||
} | ||
function startEvaluate(code: string) { | ||
buffer = '' | ||
@@ -402,14 +409,10 @@ let fallback = codes | ||
codes = fallback | ||
if (defaultPrompt != '> ') { | ||
console.log('') | ||
console.log(defaultPrompt, 'URUSAI URUSAI URUSAI'.magenta) | ||
console.log('') | ||
} | ||
if (defaultPrompt != '> ') { | ||
console.log('') | ||
console.log(defaultPrompt, 'URUSAI URUSAI URUSAI'.magenta) | ||
console.log('') | ||
} | ||
return repl(defaultPrompt); | ||
} | ||
let current = ts.transpile(code) | ||
// workaround | ||
if (code.trim().substr(0, 6) === 'import' && !current.trim()) { | ||
current = code.replace(/^\s*import/, 'var') | ||
} | ||
let current = getCurrentCode() | ||
if (verbose) { | ||
@@ -441,3 +444,3 @@ console.log(current.green); | ||
function replLoop(prompt, code) { | ||
function replLoop(prompt: string, code: string) { | ||
code = buffer + '\n' + code; | ||
@@ -458,3 +461,3 @@ var openCurly = (code.match(/\{/g) || []).length; | ||
function addLine(line) { | ||
function addLine(line: string) { | ||
buffer += '\n' + line | ||
@@ -469,3 +472,3 @@ } | ||
rl.on('line', addLine) | ||
rl.once('close', (d) => { | ||
rl.once('close', (d: any) => { | ||
console.log('evaluating...'.cyan) | ||
@@ -480,5 +483,5 @@ rl.removeListener('line', addLine) | ||
// main loop | ||
function repl(prompt) { | ||
function repl(prompt: string) { | ||
'use strict'; | ||
rl.question(prompt, function (code) { | ||
rl.question(prompt, function (code: string) { | ||
if (/^:(type|detail)/.test(code)) { | ||
@@ -485,0 +488,0 @@ let identifier = code.split(' ')[1] |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
0
261705
1883
+ Addedtypescript@1.8.0-dev.20160101(transitive)
- Removedtypescript@1.8.10(transitive)