code clean up

This commit is contained in:
zhengbli 2016-04-14 16:51:22 -07:00
parent a3d74ad550
commit 0dddcf4b84
9 changed files with 72 additions and 427 deletions

View File

@ -409,7 +409,6 @@ namespace ts {
return visitNodes(cbNodes, (<JSDocTypeLiteral>node).members);
case SyntaxKind.JSDocPropertyTag:
return visitNode(cbNode, (<JSDocPropertyTag>node).typeExpression) ||
visitNode(cbNode, (<JSDocPropertyTag>node).type) ||
visitNode(cbNode, (<JSDocPropertyTag>node).name);
}
}
@ -4063,9 +4062,9 @@ namespace ts {
const isAsync = !!(node.flags & NodeFlags.Async);
node.name =
isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalIdentifier) :
isGenerator ? doInYieldContext(parseOptionalIdentifier) :
isAsync ? doInAwaitContext(parseOptionalIdentifier) :
parseOptionalIdentifier();
isGenerator ? doInYieldContext(parseOptionalIdentifier) :
isAsync ? doInAwaitContext(parseOptionalIdentifier) :
parseOptionalIdentifier();
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false);
@ -6121,15 +6120,13 @@ namespace ts {
typedefTag.type = typedefTag.jsDocTypeTag.typeExpression.type;
}
}
if (!typedefTag.type && typedefTag.jsDocPropertyTags) {
const childrenTagPoses = ts.map(typedefTag.jsDocPropertyTags, tag => tag.pos);
const childrenTagEnds = ts.map(typedefTag.jsDocPropertyTags, tag => tag.end);
const pos = Math.min(...childrenTagPoses);
const end = Math.max(...childrenTagEnds);
const tagType = <JSDocTypeLiteral>createNode(SyntaxKind.JSDocTypeLiteral, pos);
tagType.members = <NodeArray<JSDocPropertyTag>>[];
addRange(tagType.members, typedefTag.jsDocPropertyTags);
typedefTag.type = finishNode(tagType, end);
if (!typedefTag.type && typedefTag.jsDocPropertyTags && typedefTag.jsDocPropertyTags.length > 0) {
const pos = typedefTag.jsDocPropertyTags[0].pos;
const end = typedefTag.jsDocPropertyTags[typedefTag.jsDocPropertyTags.length - 1].end;
const jsdocTypeLiteral = <JSDocTypeLiteral>createNode(SyntaxKind.JSDocTypeLiteral, pos);
jsdocTypeLiteral.members = <NodeArray<JSDocPropertyTag>>[];
addRange(jsdocTypeLiteral.members, typedefTag.jsDocPropertyTags);
typedefTag.type = finishNode(jsdocTypeLiteral, end);
}
}
@ -6303,23 +6300,18 @@ namespace ts {
result.typeExpression = tryParseTypeExpression();
result = finishNode(result);
let typeTagPartOfParentTag = false;
if (currentParentJSDocTag && currentParentJSDocTag.kind === SyntaxKind.JSDocTypedefTag) {
const parentTag = <JSDocTypedefTag>currentParentJSDocTag;
if (!parentTag.typeExpression && !parentTag.jsDocTypeTag) {
typeTagPartOfParentTag = true;
parentTag.jsDocTypeTag = result;
currentParentJSDocTagEnd = scanner.getStartPos();
return result;
}
}
if (!typeTagPartOfParentTag) {
// If this @type tag is not part of the current parent tag, then
// it denotes the end of the current parent tag.
finishCurrentParentTag();
return result;
}
return undefined;
// If this @type tag is not part of the current parent tag, then
// it denotes the end of the current parent tag.
finishCurrentParentTag();
return result;
}
function handlePropertyTag(atToken: Node, tagName: Identifier): JSDocPropertyTag {

View File

@ -1533,6 +1533,8 @@ namespace ts {
export interface JSDocPropertyTag extends JSDocTag, TypeElement {
name: Identifier;
typeExpression: JSDocTypeExpression;
// Add a "type" property here to make the interface compatible
// with the "VariableLikeDeclaration" definition
type: TypeNode;
}

View File

@ -279,13 +279,16 @@ namespace ts {
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos, /*stopAfterLineBreak*/ false, /*stopAtComments*/ true);
}
if (node.jsDocComments && node.jsDocComments.length > 0 && includeJsDocComment) {
if (includeJsDocComment && node.jsDocComments && node.jsDocComments.length > 0) {
return getTokenPosOfNode(node.jsDocComments[0]);
}
if (node.kind === SyntaxKind.SyntaxList) {
const childrenPoses = ts.map((<SyntaxList>node)._children, child => getTokenPosOfNode(<Node>child, sourceFile, includeJsDocComment));
return Math.min(...childrenPoses);
// For a syntax list, it is possible that one of its children has JSDocComment nodes, while
// the syntax list itself considers them as normal trivia. Therefore if we simply skip
// trivia for the list, we may have skipped the JSDocComment as well. So we should process its
// first child to determine the actual position of its first token.
if (node.kind === SyntaxKind.SyntaxList && (<SyntaxList>node)._children.length > 0) {
return getTokenPosOfNode((<SyntaxList>node)._children[0], sourceFile, includeJsDocComment);
}
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
@ -294,27 +297,6 @@ namespace ts {
export function isJSDocNode(node: Node) {
return node.kind >= SyntaxKind.FirstJSDocNode && node.kind <= SyntaxKind.LastJSDocNode;
}
export function isJSDocType(node: Node) {
switch (node.kind) {
case SyntaxKind.JSDocAllType:
case SyntaxKind.JSDocUnknownType:
case SyntaxKind.JSDocArrayType:
case SyntaxKind.JSDocUnionType:
case SyntaxKind.JSDocTupleType:
case SyntaxKind.JSDocNullableType:
case SyntaxKind.JSDocNonNullableType:
case SyntaxKind.JSDocRecordType:
case SyntaxKind.JSDocRecordMember:
case SyntaxKind.JSDocTypeReference:
case SyntaxKind.JSDocOptionalType:
case SyntaxKind.JSDocFunctionType:
case SyntaxKind.JSDocVariadicType:
case SyntaxKind.JSDocConstructorType:
case SyntaxKind.JSDocThisType:
return true;
}
return false;
}
export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFile): number {
if (nodeIsMissing(node) || !node.decorators) {

View File

@ -222,7 +222,9 @@ namespace Utils {
return k;
}
if (k === (<any>ts).SyntaxKind.FirstJSDocCommentNode || k === (<any>ts).SyntaxKind.LastJSDocCommentNode) {
// For some markers in SyntaxKind, we should print its original syntax name instead of
// the marker name in tests.
if (k === (<any>ts).SyntaxKind.FirstJSDocNode || k === (<any>ts).SyntaxKind.LastJSDocNode) {
for (const kindName in (<any>ts).SyntaxKind) {
if ((<any>ts).SyntaxKind[kindName] === k) {
return kindName;

View File

@ -173,6 +173,7 @@ namespace ts {
"type",
"typedef",
"property",
"prop",
"version"
];
let jsDocCompletionEntries: CompletionEntry[];
@ -274,7 +275,7 @@ namespace ts {
scanner.setText((sourceFile || this.getSourceFile()).text);
children = [];
let pos = this.pos;
const isJSDocTag =
const useJSDocScanner =
this.kind === SyntaxKind.JSDocComment ||
this.kind === SyntaxKind.JSDocParameterTag ||
this.kind === SyntaxKind.JSDocTag ||
@ -286,14 +287,14 @@ namespace ts {
this.kind === SyntaxKind.JSDocPropertyTag;
const processNode = (node: Node) => {
if (pos < node.pos) {
pos = this.addSyntheticNodes(children, pos, node.pos, /*useJSDocScanner*/ isJSDocTag);
pos = this.addSyntheticNodes(children, pos, node.pos, useJSDocScanner);
}
children.push(node);
pos = node.end;
};
const processNodes = (nodes: NodeArray<Node>) => {
if (pos < nodes.pos) {
pos = this.addSyntheticNodes(children, pos, nodes.pos, /*useJSDocScanner*/ isJSDocTag);
pos = this.addSyntheticNodes(children, pos, nodes.pos, useJSDocScanner);
}
children.push(this.createSyntaxList(<NodeArray<Node>>nodes));
pos = nodes.end;
@ -7803,7 +7804,7 @@ namespace ts {
break;
default:
forEachChild(node, walk);
if (node.jsDocComments && node.jsDocComments.length > 0) {
if (node.jsDocComments) {
for (const jsDocComment of node.jsDocComments) {
forEachChild(jsDocComment, walk);
}

View File

@ -41,60 +41,60 @@
////}
////var x = fo/*15*/o2;
// goTo.marker('1');
// verify.quickInfoIs("var myVariable: number", "This is my variable");
goTo.marker('1');
verify.quickInfoIs("var myVariable: number", "This is my variable");
// goTo.marker('2');
// verify.completionListContains("myVariable", "var myVariable: number", "This is my variable");
goTo.marker('2');
verify.completionListContains("myVariable", "var myVariable: number", "This is my variable");
// goTo.marker('3');
// verify.completionListContains("myVariable", "var myVariable: number", "This is my variable");
// verify.completionListContains("d", "var d: number", "d variable");
goTo.marker('3');
verify.completionListContains("myVariable", "var myVariable: number", "This is my variable");
verify.completionListContains("d", "var d: number", "d variable");
goTo.marker('4');
verify.completionListContains("foo", "function foo(): void", "foos comment");
verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment");
// goTo.marker('5');
// verify.currentSignatureHelpDocCommentIs("foos comment");
// goTo.marker('5q');
// verify.quickInfoIs("function foo(): void", "foos comment");
goTo.marker('5');
verify.currentSignatureHelpDocCommentIs("foos comment");
goTo.marker('5q');
verify.quickInfoIs("function foo(): void", "foos comment");
// goTo.marker('6');
// verify.currentSignatureHelpDocCommentIs("");
// goTo.marker('6q');
// verify.quickInfoIs("var fooVar: () => void", "");
goTo.marker('6');
verify.currentSignatureHelpDocCommentIs("");
goTo.marker('6q');
verify.quickInfoIs("var fooVar: () => void", "");
// goTo.marker('7');
// verify.completionListContains("foo", "function foo(): void", "foos comment");
// verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment");
goTo.marker('7');
verify.completionListContains("foo", "function foo(): void", "foos comment");
verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment");
// goTo.marker('8');
// verify.currentSignatureHelpDocCommentIs("foos comment");
// goTo.marker('8q');
// verify.quickInfoIs("function foo(): void", "foos comment");
goTo.marker('8');
verify.currentSignatureHelpDocCommentIs("foos comment");
goTo.marker('8q');
verify.quickInfoIs("function foo(): void", "foos comment");
// goTo.marker('9');
// verify.currentSignatureHelpDocCommentIs("");
// goTo.marker('9q');
// verify.quickInfoIs("var fooVar: () => void", "");
// goTo.marker('9aq');
// verify.quickInfoIs("var fooVar: () => void", "fooVar comment");
goTo.marker('9');
verify.currentSignatureHelpDocCommentIs("");
goTo.marker('9q');
verify.quickInfoIs("var fooVar: () => void", "");
goTo.marker('9aq');
verify.quickInfoIs("var fooVar: () => void", "fooVar comment");
// goTo.marker('10');
// verify.completionListContains("i", "var i: c", "instance comment");
goTo.marker('10');
verify.completionListContains("i", "var i: c", "instance comment");
// goTo.marker('11');
// verify.completionListContains("i1_i", "var i1_i: i1", "interface instance comments");
goTo.marker('11');
verify.completionListContains("i1_i", "var i1_i: i1", "interface instance comments");
// goTo.marker('12');
// verify.quickInfoIs("var fooVar: () => void", "fooVar comment");
goTo.marker('12');
verify.quickInfoIs("var fooVar: () => void", "fooVar comment");
// goTo.marker('13');
// verify.quickInfoIs("var fooVar: () => void", "fooVar comment");
goTo.marker('13');
verify.quickInfoIs("var fooVar: () => void", "fooVar comment");
// goTo.marker('14');
// verify.quickInfoIs("function foo(): void", "foos comment");
goTo.marker('14');
verify.quickInfoIs("function foo(): void", "foos comment");
// goTo.marker('15');
// verify.quickInfoIs("function foo2(a: number): void (+1 overload)", "");
goTo.marker('15');
verify.quickInfoIs("function foo2(a: number): void (+1 overload)", "");

View File

@ -1,45 +0,0 @@
/// <reference path='fourslash.ts' />
/////** This is my variable*/
////var myVariable = 10;
////
/////** d variable*/
////var d = 10;
////myVariable = d;
////
/////** foos comment*/
////function foo() {
////}
/////** fooVar comment*/
////var fooVar: () => void;
/////*4*/
////foo();
////fooVar();
////fooVar = foo;
////
////foo();
////fooVar();
////var fooVarVar = fooVar;
/////**class comment*/
////class c {
//// /** constructor comment*/
//// constructor() {
//// }
////}
/////**instance comment*/
////var i = new c();
////
/////** interface comments*/
////interface i1 {
////}
/////**interface instance comments*/
////var i1_i: i1;
////
////function foo2(a: number): void;
////function foo2(b: string): void;
////function foo2(aOrb) {
////}
////var x = foo2;
goTo.marker('4');
verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment");

View File

@ -1,288 +0,0 @@
/// <reference path='..\src\harness\external\node.d.ts'/>
"use strict";
var http = require("http");
var fs = require("fs");
var path = require("path");
var url = require("url");
var child_process = require("child_process");
var os = require("os");
/// Command line processing ///
if (process.argv[2] == '--help') {
console.log('Runs a node server on port 8888 by default, looking for tests folder in the current directory\n');
console.log('Syntax: node nodeServer.js [port] [typescriptEnlistmentDirectory] [tests] [--browser] [--verbose]\n');
console.log('Examples: \n\tnode nodeServer.js 8888 .');
console.log('\tnode nodeServer.js 3000 D:/src/typescript/public --verbose IE');
}
function switchToForwardSlashes(path) {
return path.replace(/\\/g, "/").replace(/\/\//g, '/');
}
var defaultPort = 8888;
var port = process.argv[2] || defaultPort;
var rootDir = switchToForwardSlashes(__dirname + '/../');
var browser;
if (process.argv[3]) {
browser = process.argv[3];
if (browser !== 'chrome' && browser !== 'IE') {
console.log('Invalid command line arguments. Got ' + browser + ' but expected chrome, IE or nothing.');
}
}
var grep = process.argv[4];
var verbose = false;
if (process.argv[5] == '--verbose') {
verbose = true;
}
else if (process.argv[5] && process.argv[5] !== '--verbose') {
console.log('Invalid command line arguments. Got ' + process.argv[5] + ' but expected --verbose or nothing.');
}
/// Utils ///
function log(msg) {
if (verbose) {
console.log(msg);
}
}
// Copied from the compiler sources
function dir(path, spec, options) {
options = options || {};
function filesInFolder(folder) {
var folder = switchToForwardSlashes(folder);
var paths = [];
// Everything after the current directory is relative
var baseDirectoryLength = process.cwd().length + 1;
try {
var files = fs.readdirSync(folder);
for (var i = 0; i < files.length; i++) {
var stat = fs.statSync(folder + "/" + files[i]);
if (options.recursive && stat.isDirectory()) {
paths = paths.concat(filesInFolder(folder + "/" + files[i]));
}
else if (stat.isFile() && (!spec || files[i].match(spec))) {
var relativePath = folder.substring(baseDirectoryLength);
paths.push(relativePath + "/" + files[i]);
}
}
}
catch (err) {
}
return paths;
}
return filesInFolder(path);
}
// fs.rmdirSync won't delete directories with files in it
function deleteFolderRecursive(path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file, index) {
var curPath = path + "/" + file;
if (fs.statSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath);
}
else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}
;
function writeFile(path, data, opts) {
try {
fs.writeFileSync(path, data);
}
catch (e) {
// assume file was written to a directory that exists, if not, start recursively creating them as necessary
var parts = switchToForwardSlashes(path).split('/');
for (var i = 0; i < parts.length; i++) {
var subDir = parts.slice(0, i).join('/');
if (!fs.existsSync(subDir)) {
fs.mkdir(subDir);
}
}
fs.writeFileSync(path, data);
}
}
/// Request Handling ///
function handleResolutionRequest(filePath, res) {
var resolvedPath = path.resolve(filePath, '');
resolvedPath = resolvedPath.substring(resolvedPath.indexOf('tests'));
resolvedPath = switchToForwardSlashes(resolvedPath);
send('success', res, resolvedPath);
return;
}
function send(result, res, contents, contentType) {
if (contentType === void 0) { contentType = "binary"; }
var responseCode = result === "success" ? 200 : result === "fail" ? 500 : result === 'unknown' ? 404 : parseInt(result);
res.writeHead(responseCode, { "Content-Type": contentType });
res.end(contents);
return;
}
// Reads the data from a post request and passes it to the given callback
function processPost(req, res, callback) {
var queryData = "";
if (typeof callback !== 'function')
return null;
if (req.method == 'POST') {
req.on('data', function (data) {
queryData += data;
if (queryData.length > 1e8) {
queryData = "";
send("413", res, null);
console.log("ERROR: destroying connection");
req.connection.destroy();
}
});
req.on('end', function () {
//res.post = url.parse(req.url).query;
callback(queryData);
});
}
else {
send("405", res, null);
}
}
var RequestType;
(function (RequestType) {
RequestType[RequestType["GetFile"] = 0] = "GetFile";
RequestType[RequestType["GetDir"] = 1] = "GetDir";
RequestType[RequestType["ResolveFile"] = 2] = "ResolveFile";
RequestType[RequestType["WriteFile"] = 3] = "WriteFile";
RequestType[RequestType["DeleteFile"] = 4] = "DeleteFile";
RequestType[RequestType["WriteDir"] = 5] = "WriteDir";
RequestType[RequestType["DeleteDir"] = 6] = "DeleteDir";
RequestType[RequestType["AppendFile"] = 7] = "AppendFile";
RequestType[RequestType["Unknown"] = 8] = "Unknown";
})(RequestType || (RequestType = {}));
function getRequestOperation(req, filename) {
if (req.method === 'GET' && req.url.indexOf('?') === -1) {
if (req.url.indexOf('.') !== -1)
return RequestType.GetFile;
else
return RequestType.GetDir;
}
else {
var queryData = url.parse(req.url, true).query;
if (req.method === 'GET' && queryData.resolve !== undefined)
return RequestType.ResolveFile;
// mocha uses ?grep=<regexp> query string as equivalent to the --grep command line option used to filter tests
if (req.method === 'GET' && queryData.grep !== undefined)
return RequestType.GetFile;
if (req.method === 'POST' && queryData.action) {
var path = req.url.substr(0, req.url.lastIndexOf('?'));
var isFile = path.substring(path.lastIndexOf('/')).indexOf('.') !== -1;
switch (queryData.action.toUpperCase()) {
case 'WRITE':
return isFile ? RequestType.WriteFile : RequestType.WriteDir;
case 'DELETE':
return isFile ? RequestType.DeleteFile : RequestType.DeleteDir;
case 'APPEND':
return isFile ? RequestType.AppendFile : RequestType.Unknown;
}
}
return RequestType.Unknown;
}
}
function handleRequestOperation(req, res, operation, reqPath) {
switch (operation) {
case RequestType.GetDir:
var filesInFolder = dir(reqPath, "", { recursive: true });
send('success', res, filesInFolder.join(','));
break;
case RequestType.GetFile:
fs.readFile(reqPath, function (err, file) {
var ext = reqPath.substr(reqPath.lastIndexOf('.'));
var contentType = 'binary';
if (ext === '.js')
contentType = 'text/javascript';
else if (ext === '.css')
contentType = 'text/javascript';
else if (ext === '.html')
contentType = 'text/html';
err
? send('fail', res, err.message, contentType)
: send('success', res, file, contentType);
});
break;
case RequestType.ResolveFile:
var resolveRequest = req.url.match(/(.*)\?resolve/);
handleResolutionRequest(resolveRequest[1], res);
break;
case RequestType.WriteFile:
processPost(req, res, function (data) {
writeFile(reqPath, data, { recursive: true });
});
send('success', res, null);
break;
case RequestType.WriteDir:
fs.mkdirSync(reqPath);
send('success', res, null);
break;
case RequestType.DeleteFile:
if (fs.existsSync(reqPath)) {
fs.unlinkSync(reqPath);
}
send('success', res, null);
break;
case RequestType.DeleteDir:
if (fs.existsSync(reqPath)) {
fs.rmdirSync(reqPath);
}
send('success', res, null);
break;
case RequestType.AppendFile:
processPost(req, res, function (data) {
fs.appendFileSync(reqPath, data);
});
send('success', res, null);
break;
case RequestType.Unknown:
default:
send('unknown', res, null);
break;
}
}
console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown");
http.createServer(function (req, res) {
log(req.method + ' ' + req.url);
var uri = url.parse(req.url).pathname;
var reqPath = path.join(process.cwd(), uri);
var operation = getRequestOperation(req, reqPath);
handleRequestOperation(req, res, operation, reqPath);
}).listen(8888);
var browserPath;
if ((browser && browser === 'chrome')) {
var defaultChromePath = "";
switch (os.platform()) {
case "win32":
case "win64":
defaultChromePath = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe";
break;
case "darwin":
defaultChromePath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";
break;
case "linux":
defaultChromePath = "/opt/google/chrome/chrome";
break;
default:
console.log("default Chrome location is unknown for platform '" + os.platform() + "'");
break;
}
if (fs.existsSync(defaultChromePath)) {
browserPath = defaultChromePath;
}
else {
browserPath = browser;
}
}
else {
var defaultIEPath = 'C:/Program Files/Internet Explorer/iexplore.exe';
if (fs.existsSync(defaultIEPath)) {
browserPath = defaultIEPath;
}
else {
browserPath = browser;
}
}
console.log('Using browser: ' + browserPath);
var queryString = grep ? "?grep=" + grep : '';
child_process.spawn(browserPath, ['http://localhost:' + port + '/tests/webTestResults.html' + queryString], {
stdio: 'inherit'
});
//# sourceMappingURL=file:///C:/Users/lizhe/Documents/github/TypeScript/tests/webTestServer.js.map

File diff suppressed because one or more lines are too long