Comparing version 0.0.6 to 0.0.7
/// <reference path='./typings/node.d.ts' /> | ||
/// <reference path='./typings/colors.d.ts' /> | ||
/// <reference path='./typings/typescript.d.ts' /> | ||
/// <reference path='./node_modules/typescript/bin/typescript.d.ts' /> | ||
var readline = require('readline'); | ||
@@ -156,2 +156,7 @@ var util = require('util'); | ||
codes += buffer + '\n' + line; | ||
if (':' === line[0]) { | ||
var candidates_1 = ['type', 'detail', 'source', 'paste', 'clear', 'print', 'help']; | ||
candidates_1 = candidates_1.map(function (c) { return ':' + c; }).filter(function (c) { return c.indexOf(line) >= 0; }); | ||
return [candidates_1, line.trim()]; | ||
} | ||
var completions = service.getCompletionsAtPosition(dummyFile, codes.length); | ||
@@ -210,2 +215,11 @@ if (!completions) { | ||
} | ||
// private api hacks | ||
function collectDeclaration(sourceFile) { | ||
var decls = sourceFile.getNamedDeclarations(); | ||
var ret = {}; | ||
for (var decl in decls) { | ||
ret[decl] = decls[decl].map(function (t) { return t.name; }); | ||
} | ||
return ret; | ||
} | ||
var getDeclarations = (function () { | ||
@@ -216,3 +230,4 @@ var declarations = {}; | ||
var file = declFiles[_i]; | ||
declarations[file] = service.getSourceFile(file).getNamedDeclarations().map(function (t) { return t.name; }); | ||
declarations[file] = collectDeclaration(service.getSourceFile(file)); | ||
console.log(declarations[file]); | ||
} | ||
@@ -222,3 +237,3 @@ return function (cached) { | ||
if (!cached) { | ||
declarations[dummyFile] = service.getSourceFile(dummyFile).getNamedDeclarations().map(function (t) { return t.name; }); | ||
declarations[dummyFile] = collectDeclaration(service.getSourceFile(dummyFile)); | ||
} | ||
@@ -229,3 +244,4 @@ return declarations; | ||
function getMemberInfo(member, file, parentDeclaration) { | ||
var pos = member.getEnd(); | ||
// member info is stored as the first | ||
var pos = member.getStart(); | ||
var quickInfo = service.getQuickInfoAtPosition(file, pos); | ||
@@ -238,3 +254,3 @@ if (quickInfo) | ||
return member.getText(); | ||
var declarations = getDeclarations(true)[file].filter(function (d) { return d.getText() === name; }); | ||
var declarations = getDeclarations(true)[file][name]; | ||
for (var _i = 0; _i < declarations.length; _i++) { | ||
@@ -251,2 +267,3 @@ var decl = declarations[_i]; | ||
function getTypeInfo(decl, file, detailed) { | ||
// getStart will count comment | ||
var pos = decl.getEnd(); | ||
@@ -273,2 +290,35 @@ var ret = [("declaration in: " + file)]; | ||
} | ||
function getSource(name) { | ||
var declarations = getDeclarations(); | ||
for (var file in declarations) { | ||
var names = declarations[file]; | ||
if (names[name]) { | ||
var decl = names[name]; | ||
var pager = process.env.PAGER; | ||
var text = decl[0].parent.getFullText(); | ||
if (!pager || text.split('\n').length < 24) { | ||
console.log(text); | ||
repl(defaultPrompt); | ||
return; | ||
} | ||
process.stdin.pause(); | ||
var tty = require('tty'); | ||
tty.setRawMode(false); | ||
var temp = require('temp'); | ||
var tempFile = temp.openSync('dummyFile' + Math.random()); | ||
fs.writeFileSync(tempFile.path, text); | ||
var display = child_process.spawn('less', [tempFile.path], { | ||
'stdio': [0, 1, 2] | ||
}); | ||
display.on('exit', function () { | ||
temp.cleanupSync(); | ||
tty.setRawMode(true); | ||
process.stdin.resume(); | ||
repl(defaultPrompt); | ||
}); | ||
return; | ||
} | ||
} | ||
console.log(("identifier " + name + " not found").yellow); | ||
} | ||
function getType(name, detailed) { | ||
@@ -278,5 +328,4 @@ var declarations = getDeclarations(); | ||
var names = declarations[file]; | ||
var nameText = names.map(function (t) { return t.getText(); }); | ||
if (nameText.indexOf(name) >= 0) { | ||
var decl = names[nameText.indexOf(name)]; | ||
if (names[name]) { | ||
var decl = names[name][0]; | ||
var infoString = getTypeInfo(decl, file, detailed); | ||
@@ -290,3 +339,3 @@ console.log(infoString.join('\n').cyan); | ||
function printHelp() { | ||
console.log("\ntsun repl commands\n:type symbol print the type of an identifier\n:detail symbol print details identifier\n:clear clear all the code\n:print print code input so far\n:help print this manual\n:paste enter paste mode".blue); | ||
console.log("\ntsun repl commands\n:type symbol print the type of an identifier\n:detail symbol print details of identifier\n:source symbol print source of identifier\n:clear clear all the code\n:print print code input so far\n:help print this manual\n:paste enter paste mode".blue); | ||
if (argv.dere) { | ||
@@ -396,2 +445,11 @@ console.log(':baka Who would like some pervert like you, baka~'.blue); | ||
} | ||
if (/^:source/.test(code)) { | ||
var identifier = code.split(' ')[1]; | ||
if (!identifier) { | ||
console.log(':source command need names!'.red); | ||
return repl(prompt); | ||
} | ||
getSource(identifier); | ||
return; | ||
} | ||
if (/^:help/.test(code)) { | ||
@@ -398,0 +456,0 @@ printHelp(); |
{ | ||
"name": "tsun", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "TSUN: a repl for TypeScript Upgraded Node", | ||
@@ -10,3 +10,3 @@ "bin": "./bin/tsun", | ||
"temp": "^0.8.1", | ||
"typescript": "^1.5.0-alpha" | ||
"typescript": "^1.5.0-beta" | ||
}, | ||
@@ -13,0 +13,0 @@ "scripts": { |
81
tsun.ts
/// <reference path='./typings/node.d.ts' /> | ||
/// <reference path='./typings/colors.d.ts' /> | ||
/// <reference path='./typings/typescript.d.ts' /> | ||
/// <reference path='./node_modules/typescript/bin/typescript.d.ts' /> | ||
@@ -173,2 +173,7 @@ import readline = require('readline') | ||
codes += buffer + '\n' + line | ||
if (':' === line[0]) { | ||
let candidates = ['type', 'detail', 'source', 'paste', 'clear', 'print', 'help'] | ||
candidates = candidates.map(c => ':' + c).filter(c => c.indexOf(line) >= 0) | ||
return [candidates, line.trim()] | ||
} | ||
let completions = service.getCompletionsAtPosition(dummyFile, codes.length) | ||
@@ -230,11 +235,22 @@ if (!completions) { | ||
// 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 | ||
} | ||
var getDeclarations = (function() { | ||
var declarations: {[a: string]: ts.DeclarationName[]} = {} | ||
var declarations: {[fileName: string]: {[name: string]: ts.DeclarationName[]}} = {} | ||
let declFiles = getDeclarationFiles().concat(path.join(__dirname, '../node_modules/typescript/bin/lib.core.es6.d.ts')) | ||
for (let file of declFiles) { | ||
declarations[file] = service.getSourceFile(file).getNamedDeclarations().map(t => t.name) | ||
declarations[file] = collectDeclaration(service.getSourceFile(file)) | ||
console.log(declarations[file]) | ||
} | ||
return function(cached: boolean = false) { | ||
if (!cached) { | ||
declarations[dummyFile] = service.getSourceFile(dummyFile).getNamedDeclarations().map(t => t.name) | ||
declarations[dummyFile] = collectDeclaration(service.getSourceFile(dummyFile)) | ||
} | ||
@@ -247,3 +263,4 @@ return declarations | ||
function getMemberInfo(member, file, parentDeclaration): string { | ||
let pos = member.getEnd() | ||
// member info is stored as the first | ||
let pos = member.getStart() | ||
let quickInfo = service.getQuickInfoAtPosition(file, pos) | ||
@@ -254,3 +271,3 @@ if (quickInfo) return ts.displayPartsToString(quickInfo.displayParts) | ||
if (!name) return member.getText() | ||
let declarations = getDeclarations(true)[file].filter(d => d.getText() === name) | ||
let declarations = getDeclarations(true)[file][name] | ||
for (let decl of declarations) { | ||
@@ -267,2 +284,3 @@ let d: any = decl | ||
function getTypeInfo(decl: ts.Node, file: string, detailed: boolean): string[] { | ||
// getStart will count comment | ||
let pos = decl.getEnd() | ||
@@ -289,2 +307,36 @@ let ret = [`declaration in: ${file}`] | ||
function getSource(name) { | ||
let declarations = getDeclarations() | ||
for (let file in declarations) { | ||
let names = declarations[file] | ||
if (names[name]) { | ||
let decl = names[name] | ||
let pager = process.env.PAGER | ||
let text = decl[0].parent.getFullText() | ||
if (!pager || text.split('\n').length < 24) { | ||
console.log(text) | ||
repl(defaultPrompt) | ||
return | ||
} | ||
process.stdin.pause() | ||
var tty = require('tty') | ||
tty.setRawMode(false) | ||
var temp = require('temp') | ||
let tempFile = temp.openSync('dummyFile' + Math.random()) | ||
fs.writeFileSync(tempFile.path, text) | ||
let display = child_process.spawn('less', [tempFile.path], { | ||
'stdio': [0, 1, 2] | ||
}) | ||
display.on('exit', function() { | ||
temp.cleanupSync() | ||
tty.setRawMode(true) | ||
process.stdin.resume() | ||
repl(defaultPrompt) | ||
}) | ||
return | ||
} | ||
} | ||
console.log(`identifier ${name} not found`.yellow) | ||
} | ||
function getType(name, detailed) { | ||
@@ -294,5 +346,4 @@ let declarations = getDeclarations() | ||
let names = declarations[file] | ||
let nameText = names.map(t => t.getText()) | ||
if (nameText.indexOf(name) >= 0) { | ||
let decl = names[nameText.indexOf(name)] | ||
if (names[name]) { | ||
let decl = names[name][0] | ||
let infoString = getTypeInfo(decl, file, detailed) | ||
@@ -310,3 +361,4 @@ console.log(infoString.join('\n').cyan) | ||
:type symbol print the type of an identifier | ||
:detail symbol print details identifier | ||
:detail symbol print details of identifier | ||
:source symbol print source of identifier | ||
:clear clear all the code | ||
@@ -427,2 +479,11 @@ :print print code input so far | ||
} | ||
if (/^:source/.test(code)) { | ||
let identifier = code.split(' ')[1] | ||
if (!identifier) { | ||
console.log(':source command need names!'.red) | ||
return repl(prompt) | ||
} | ||
getSource(identifier) | ||
return | ||
} | ||
if (/^:help/.test(code)) { | ||
@@ -429,0 +490,0 @@ printHelp() |
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
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
278474
12
2350
6
Updatedtypescript@^1.5.0-beta