Merge branch 'master' into diagnosticsCleanup

This commit is contained in:
Daniel Rosenwasser 2014-08-18 15:42:58 -07:00
commit 8baee8a785
185 changed files with 1557 additions and 5035 deletions

View File

@ -780,7 +780,7 @@ module ts {
// But it cant, hence the accessible is going to be undefined, but that doesnt mean m.c is accessible
// It is accessible if the parent m is accessible because then m.c can be accessed through qualification
meaningToLook = getQualifiedLeftMeaning(meaning);
symbol = symbol.parent;
symbol = getParentOfSymbol(symbol);
}
// This could be a symbol that is not exported in the external module
@ -903,7 +903,7 @@ module ts {
if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
break;
}
symbol = accessibleSymbolChain ? accessibleSymbolChain[0].parent : symbol.parent;
symbol = getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol);
meaning = getQualifiedLeftMeaning(meaning);
}

View File

@ -750,9 +750,8 @@ module ts {
if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) {
pos += 2;
var safeLength = len - 1; // For lookahead.
var commentClosed = false;
while (pos < safeLength) {
while (pos < len) {
var ch = text.charCodeAt(pos);
if (ch === CharacterCodes.asterisk && text.charCodeAt(pos + 1) === CharacterCodes.slash) {
@ -768,7 +767,6 @@ module ts {
}
if (!commentClosed) {
pos++;
error(Diagnostics.Asterisk_Slash_expected);
}

View File

@ -217,7 +217,9 @@ module ts {
FirstKeyword = BreakKeyword,
LastKeyword = StringKeyword,
FirstFutureReservedWord = ImplementsKeyword,
LastFutureReservedWord = YieldKeyword
LastFutureReservedWord = YieldKeyword,
FirstPunctuation= OpenBraceToken,
LastPunctuation = CaretEqualsToken
}
export enum NodeFlags {

View File

@ -167,7 +167,6 @@ module Harness.LanguageService {
}
export class TypeScriptLS implements ts.LanguageServiceShimHost {
private ls: ts.LanguageServiceShim = null;
public newLS: ts.LanguageService;
private fileNameToScript: ts.Map<ScriptInfo> = {};
@ -268,12 +267,13 @@ module Harness.LanguageService {
* To access the non-shim (i.e. actual) language service, use the "ls.languageService" property.
*/
public getLanguageService(): ts.LanguageServiceShim {
var ls = new TypeScript.Services.TypeScriptServicesFactory().createLanguageServiceShim(this);
this.ls = ls;
var hostAdapter = new LanguageServiceShimHostAdapter(this);
this.ls = new TypeScript.Services.TypeScriptServicesFactory().createLanguageServiceShim(this);
return this.ls;
}
this.newLS = ts.createLanguageService(hostAdapter, NonCachingDocumentRegistry.Instance);
return ls;
/** Return a new instance of the classifier service shim */
public getClassifier(): ts.ClassifierShim {
return new TypeScript.Services.TypeScriptServicesFactory().createClassifierShim(this);
}
/** Parse file given its source text */

View File

@ -68,17 +68,11 @@ if (testConfigFile !== '') {
runners.push(new GeneratedFourslashRunner());
break;
case 'unittests':
runners.push(new UnitTestRunner(UnittestTestType.Compiler));
runners.push(new UnitTestRunner());
break;
case 'rwc':
runners.push(new RWCRunner());
break;
case 'ls':
runners.push(new UnitTestRunner(UnittestTestType.LanguageService));
break;
case 'services':
runners.push(new UnitTestRunner(UnittestTestType.Services));
break;
case 'reverse':
reverse = true;
break;
@ -96,9 +90,12 @@ if (runners.length === 0) {
runners.push(new ProjectRunner());
}
//// language services
// language services
runners.push(new FourslashRunner());
//runners.push(new GeneratedFourslashRunner());
// unittests
runners.push(new UnitTestRunner());
}
sys.newLine = '\r\n';

View File

@ -1,31 +1,13 @@
///<reference path="harness.ts" />
///<reference path="runnerbase.ts" />
enum UnittestTestType {
Compiler,
LanguageService,
Services,
}
class UnitTestRunner extends RunnerBase {
constructor(public testType?: UnittestTestType) {
constructor() {
super();
}
public initializeTests() {
switch (this.testType) {
case UnittestTestType.Compiler:
this.tests = this.enumerateFiles('tests/cases/unittests/compiler');
break;
case UnittestTestType.LanguageService:
this.tests = this.enumerateFiles('tests/cases/unittests/ls');
break;
default:
if (this.tests.length === 0) {
throw new Error('Unsupported test cases: ' + this.testType);
}
break;
}
this.tests = this.enumerateFiles('tests/cases/unittests/services');
var outfile = new Harness.Compiler.WriterAggregator()
var outerr = new Harness.Compiler.WriterAggregator();
@ -38,7 +20,7 @@ class UnitTestRunner extends RunnerBase {
});
harnessCompiler.addInputFiles(toBeAdded);
harnessCompiler.setCompilerOptions({ noResolve: true });
var stdout = new Harness.Compiler.EmitterIOHost();
var emitDiagnostics = harnessCompiler.emitAll(stdout);
var results = stdout.toArray();
@ -59,7 +41,9 @@ class UnitTestRunner extends RunnerBase {
before: before,
after: after,
Harness: Harness,
IO: Harness.IO
IO: Harness.IO,
ts: ts,
TypeScript: TypeScript
// FourSlash: FourSlash
};
}

View File

@ -659,6 +659,7 @@ module ts {
InMultiLineCommentTrivia,
InSingleQuoteStringLiteral,
InDoubleQuoteStringLiteral,
EndingWithDotToken,
}
export enum TokenClass {
@ -693,8 +694,7 @@ module ts {
compilationSettings: CompilerOptions,
scriptSnapshot: TypeScript.IScriptSnapshot,
version: number,
isOpen: boolean,
referencedFiles: string[]): SourceFile;
isOpen: boolean): SourceFile;
updateDocument(
sourceFile: SourceFile,
@ -1402,7 +1402,7 @@ module ts {
sourceFile = documentRegistry.updateDocument(sourceFile, filename, compilationSettings, scriptSnapshot, version, isOpen, textChangeRange);
}
else {
sourceFile = documentRegistry.acquireDocument(filename, compilationSettings, scriptSnapshot, version, isOpen, []);
sourceFile = documentRegistry.acquireDocument(filename, compilationSettings, scriptSnapshot, version, isOpen);
}
// Remeber the new sourceFile
@ -2267,50 +2267,41 @@ module ts {
}
/// Classifier
export function createClassifier(host: Logger): Classifier {
var scanner: TypeScript.Scanner.IScanner;
var lastDiagnosticKey: string = null;
var noRegexTable: boolean[];
var reportDiagnostic = (position: number, fullWidth: number, key: string, args: any[]) => {
lastDiagnosticKey = key;
};
if (!noRegexTable) {
noRegexTable = [];
noRegexTable[TypeScript.SyntaxKind.IdentifierName] = true;
noRegexTable[TypeScript.SyntaxKind.StringLiteral] = true;
noRegexTable[TypeScript.SyntaxKind.NumericLiteral] = true;
noRegexTable[TypeScript.SyntaxKind.RegularExpressionLiteral] = true;
noRegexTable[TypeScript.SyntaxKind.ThisKeyword] = true;
noRegexTable[TypeScript.SyntaxKind.PlusPlusToken] = true;
noRegexTable[TypeScript.SyntaxKind.MinusMinusToken] = true;
noRegexTable[TypeScript.SyntaxKind.CloseParenToken] = true;
noRegexTable[TypeScript.SyntaxKind.CloseBracketToken] = true;
noRegexTable[TypeScript.SyntaxKind.CloseBraceToken] = true;
noRegexTable[TypeScript.SyntaxKind.TrueKeyword] = true;
noRegexTable[TypeScript.SyntaxKind.FalseKeyword] = true;
}
var scanner: Scanner;
var noRegexTable: boolean[];
/// We do not have a full parser support to know when we should parse a regex or not
/// If we consider every slash token to be a regex, we could be missing cases like "1/2/3", where
/// we have a series of divide operator. this list allows us to be more accurate by ruling out
/// locations where a regexp cannot exist.
if (!noRegexTable) { noRegexTable = []; noRegexTable[SyntaxKind.Identifier] = true; noRegexTable[SyntaxKind.StringLiteral] = true; noRegexTable[SyntaxKind.NumericLiteral] = true; noRegexTable[SyntaxKind.RegularExpressionLiteral] = true; noRegexTable[SyntaxKind.ThisKeyword] = true; noRegexTable[SyntaxKind.PlusPlusToken] = true; noRegexTable[SyntaxKind.MinusMinusToken] = true; noRegexTable[SyntaxKind.CloseParenToken] = true; noRegexTable[SyntaxKind.CloseBracketToken] = true; noRegexTable[SyntaxKind.CloseBraceToken] = true; noRegexTable[SyntaxKind.TrueKeyword] = true; noRegexTable[SyntaxKind.FalseKeyword] = true; }
function getClassificationsForLine(text: string, lexState: EndOfLineState): ClassificationResult {
var offset = 0;
if (lexState !== EndOfLineState.Start) {
// If we're in a string literal, then prepend: "\
// (and a newline). That way when we lex we'll think we're still in a string literal.
//
// If we're in a multiline comment, then prepend: /*
// (and a newline). That way when we lex we'll think we're still in a multiline comment.
if (lexState === EndOfLineState.InDoubleQuoteStringLiteral) {
text = '"\\\n' + text;
}
else if (lexState === EndOfLineState.InSingleQuoteStringLiteral) {
text = "'\\\n" + text;
}
else if (lexState === EndOfLineState.InMultiLineCommentTrivia) {
text = "/*\n" + text;
}
var lastTokenOrCommentEnd = 0;
var lastToken = SyntaxKind.Unknown;
var inUnterminatedMultiLineComment = false;
offset = 3;
// If we're in a string literal, then prepend: "\
// (and a newline). That way when we lex we'll think we're still in a string literal.
//
// If we're in a multiline comment, then prepend: /*
// (and a newline). That way when we lex we'll think we're still in a multiline comment.
switch (lexState) {
case EndOfLineState.InDoubleQuoteStringLiteral:
text = '"\\\n' + text;
offset = 3;
break;
case EndOfLineState.InSingleQuoteStringLiteral:
text = "'\\\n" + text;
offset = 3;
break;
case EndOfLineState.InMultiLineCommentTrivia:
text = "/*\n" + text;
offset = 3;
break;
case EndOfLineState.EndingWithDotToken:
lastToken = SyntaxKind.DotToken;
break;
}
var result: ClassificationResult = {
@ -2318,94 +2309,174 @@ module ts {
entries: []
};
var simpleText = TypeScript.SimpleText.fromString(text);
scanner = TypeScript.Scanner.createScanner(ScriptTarget.ES5, simpleText, reportDiagnostic);
scanner = createScanner(ScriptTarget.ES5, text, onError, processComment);
var lastTokenKind = TypeScript.SyntaxKind.None;
var token: TypeScript.ISyntaxToken = null;
var token = SyntaxKind.Unknown;
do {
lastDiagnosticKey = null;
token = scanner.scan();
token = scanner.scan(!noRegexTable[lastTokenKind]);
lastTokenKind = token.kind();
processToken(text, simpleText, offset, token, result);
}
while (token.kind() !== TypeScript.SyntaxKind.EndOfFileToken);
lastDiagnosticKey = null;
return result;
}
function processToken(text: string, simpleText: TypeScript.ISimpleText, offset: number, token: TypeScript.ISyntaxToken, result: ClassificationResult): void {
processTriviaList(text, offset, token.leadingTrivia(simpleText), result);
addResult(text, offset, result, TypeScript.width(token), token.kind());
processTriviaList(text, offset, token.trailingTrivia(simpleText), result);
if (TypeScript.fullEnd(token) >= text.length) {
// We're at the end.
if (lastDiagnosticKey === TypeScript.DiagnosticCode.AsteriskSlash_expected) {
result.finalLexState = EndOfLineState.InMultiLineCommentTrivia;
return;
if ((token === SyntaxKind.SlashToken || token === SyntaxKind.SlashEqualsToken) && !noRegexTable[lastToken]) {
if (scanner.reScanSlashToken() === SyntaxKind.RegularExpressionLiteral) {
token = SyntaxKind.RegularExpressionLiteral;
}
}
else if (lastToken === SyntaxKind.DotToken) {
token = SyntaxKind.Identifier;
}
if (token.kind() === TypeScript.SyntaxKind.StringLiteral) {
var tokenText = token.text();
if (tokenText.length > 0 && tokenText.charCodeAt(tokenText.length - 1) === TypeScript.CharacterCodes.backslash) {
var quoteChar = tokenText.charCodeAt(0);
result.finalLexState = quoteChar === TypeScript.CharacterCodes.doubleQuote
? EndOfLineState.InDoubleQuoteStringLiteral
: EndOfLineState.InSingleQuoteStringLiteral;
return;
lastToken = token;
processToken();
}
while (token !== SyntaxKind.EndOfFileToken);
return result;
function onError(message: DiagnosticMessage): void {
inUnterminatedMultiLineComment = message.key === Diagnostics.Asterisk_Slash_expected.key;
}
function processComment(start: number, end: number) {
// add Leading white spaces
addLeadingWhiteSpace(start, end);
// add the comment
addResult(end - start, TokenClass.Comment);
}
function processToken(): void {
var start = scanner.getTokenPos();
var end = scanner.getTextPos();
// add Leading white spaces
addLeadingWhiteSpace(start, end);
// add the token
addResult(end - start, classFromKind(token));
if (end >= text.length) {
// We're at the end.
if (inUnterminatedMultiLineComment) {
result.finalLexState = EndOfLineState.InMultiLineCommentTrivia;
}
else if (token === SyntaxKind.StringLiteral) {
var tokenText = scanner.getTokenText();
if (tokenText.length > 0 && tokenText.charCodeAt(tokenText.length - 1) === CharacterCodes.backslash) {
var quoteChar = tokenText.charCodeAt(0);
result.finalLexState = quoteChar === CharacterCodes.doubleQuote
? EndOfLineState.InDoubleQuoteStringLiteral
: EndOfLineState.InSingleQuoteStringLiteral;
}
}
else if (token === SyntaxKind.DotToken) {
result.finalLexState = EndOfLineState.EndingWithDotToken;
}
}
}
}
function processTriviaList(text: string, offset: number, triviaList: TypeScript.ISyntaxTriviaList, result: ClassificationResult): void {
for (var i = 0, n = triviaList.count(); i < n; i++) {
var trivia = triviaList.syntaxTriviaAt(i);
addResult(text, offset, result, trivia.fullWidth(), trivia.kind());
}
}
function addResult(text: string, offset: number, result: ClassificationResult, length: number, kind: TypeScript.SyntaxKind): void {
if (length > 0) {
// If this is the first classification we're adding to the list, then remove any
// offset we have if we were continuing a construct from the previous line.
if (result.entries.length === 0) {
length -= offset;
function addLeadingWhiteSpace(start: number, end: number): void {
if (start > lastTokenOrCommentEnd) {
addResult(start - lastTokenOrCommentEnd, TokenClass.Whitespace);
}
result.entries.push({ length: length, classification: classFromKind(kind) });
// Remeber the end of the last token
lastTokenOrCommentEnd = end;
}
function addResult(length: number, classification: TokenClass): void {
if (length > 0) {
// If this is the first classification we're adding to the list, then remove any
// offset we have if we were continuing a construct from the previous line.
if (result.entries.length === 0) {
length -= offset;
}
result.entries.push({ length: length, classification: classification });
}
}
}
function classFromKind(kind: TypeScript.SyntaxKind) {
if (TypeScript.SyntaxFacts.isAnyKeyword(kind)) {
function isBinaryExpressionOperatorToken(token: SyntaxKind): boolean {
switch (token) {
case SyntaxKind.AsteriskToken:
case SyntaxKind.SlashToken:
case SyntaxKind.PercentToken:
case SyntaxKind.PlusToken:
case SyntaxKind.MinusToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.LessThanToken:
case SyntaxKind.GreaterThanToken:
case SyntaxKind.LessThanEqualsToken:
case SyntaxKind.GreaterThanEqualsToken:
case SyntaxKind.InstanceOfKeyword:
case SyntaxKind.InKeyword:
case SyntaxKind.EqualsEqualsToken:
case SyntaxKind.ExclamationEqualsToken:
case SyntaxKind.EqualsEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsEqualsToken:
case SyntaxKind.AmpersandToken:
case SyntaxKind.CaretToken:
case SyntaxKind.BarToken:
case SyntaxKind.AmpersandAmpersandToken:
case SyntaxKind.BarBarToken:
case SyntaxKind.BarEqualsToken:
case SyntaxKind.AmpersandEqualsToken:
case SyntaxKind.CaretEqualsToken:
case SyntaxKind.LessThanLessThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
case SyntaxKind.PlusEqualsToken:
case SyntaxKind.MinusEqualsToken:
case SyntaxKind.AsteriskEqualsToken:
case SyntaxKind.SlashEqualsToken:
case SyntaxKind.PercentEqualsToken:
case SyntaxKind.EqualsToken:
case SyntaxKind.CommaToken:
return true;
default: return false;
}
}
function isPrefixUnaryExpressionOperatorToken(token: SyntaxKind): boolean {
switch (token) {
case SyntaxKind.PlusToken:
case SyntaxKind.MinusToken:
case SyntaxKind.TildeToken:
case SyntaxKind.ExclamationToken:
case SyntaxKind.PlusPlusToken:
case SyntaxKind.MinusMinusToken:
return true;
default:
return false;
}
}
function isKeyword(token: SyntaxKind): boolean {
return token >= SyntaxKind.FirstKeyword && token <= SyntaxKind.LastKeyword;
}
function classFromKind(token: SyntaxKind) {
if (isKeyword(token)) {
return TokenClass.Keyword;
}
else if (TypeScript.SyntaxFacts.isBinaryExpressionOperatorToken(kind) ||
TypeScript.SyntaxFacts.isPrefixUnaryExpressionOperatorToken(kind)) {
else if (isBinaryExpressionOperatorToken(token) || isPrefixUnaryExpressionOperatorToken(token)) {
return TokenClass.Operator;
}
else if (TypeScript.SyntaxFacts.isAnyPunctuation(kind)) {
else if (token >= SyntaxKind.FirstPunctuation && token <= SyntaxKind.LastPunctuation) {
return TokenClass.Punctuation;
}
switch (kind) {
case TypeScript.SyntaxKind.WhitespaceTrivia:
return TokenClass.Whitespace;
case TypeScript.SyntaxKind.MultiLineCommentTrivia:
case TypeScript.SyntaxKind.SingleLineCommentTrivia:
return TokenClass.Comment;
case TypeScript.SyntaxKind.NumericLiteral:
switch (token) {
case SyntaxKind.NumericLiteral:
return TokenClass.NumberLiteral;
case TypeScript.SyntaxKind.StringLiteral:
case SyntaxKind.StringLiteral:
return TokenClass.StringLiteral;
case TypeScript.SyntaxKind.RegularExpressionLiteral:
case SyntaxKind.RegularExpressionLiteral:
return TokenClass.RegExpLiteral;
case TypeScript.SyntaxKind.IdentifierName:
case SyntaxKind.Identifier:
default:
return TokenClass.Identifier;
}

View File

@ -840,8 +840,8 @@ module ts {
public createLanguageServiceShim(host: LanguageServiceShimHost): LanguageServiceShim {
try {
var hostAdapter = new LanguageServiceShimHostAdapter(host);
var pullLanguageService = createLanguageService(hostAdapter, this.documentRegistry);
return new LanguageServiceShimObject(this, host, pullLanguageService);
var languageService = createLanguageService(hostAdapter, this.documentRegistry);
return new LanguageServiceShimObject(this, host, languageService);
}
catch (err) {
logInternalError(host, err);

View File

@ -0,0 +1,42 @@
//// [tests/cases/compiler/moduleSymbolMerging.ts] ////
//// [A.ts]
module A { export interface I {} }
//// [B.ts]
///<reference path="A.ts" />
module A { ; }
module B {
export function f(): A.I { return null; }
}
//// [A.js]
//// [B.js]
var A;
(function (A) {
;
})(A || (A = {}));
var B;
(function (B) {
function f() {
return null;
}
B.f = f;
})(B || (B = {}));
//// [A.d.ts]
declare module A {
interface I {
}
}
//// [B.d.ts]
/// <reference path='A.d.ts' />
declare module A {
}
declare module B {
function f(): A.I;
}

View File

@ -0,0 +1,12 @@
// @declaration: true
// @Filename: A.ts
module A { export interface I {} }
// @Filename: B.ts
///<reference path="A.ts" />
module A { ; }
module B {
export function f(): A.I { return null; }
}

View File

@ -1,27 +0,0 @@
///<reference path='..\..\..\..\src\compiler\typescript.ts' />
///<reference path='..\..\..\..\src\harness\harness.ts' />
describe('Compiling unittests\\compiler\\callSignatureTests.ts', function () {
it("If a signature omits a return type annotation, any type is assumed", function () {
var code = 'var foo: {();};';
code += 'var test = foo();'
code += 'test.bar = 2;'
Harness.Compiler.compileString(code, 'call signatures', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("A call signature can have the void return type", function () {
var code = 'var foo: {():void;};';
code += 'var test = foo();'
Harness.Compiler.compileString(code, 'call signatures', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("A call signature can't have the same overload", function () {
var code = 'var foo: { (): string; (): string; };';
Harness.Compiler.compileString(code, 'call signatures', function (result) {
assert.equal(result.errors.length, 0);
});
});
});

View File

@ -1,128 +0,0 @@
/// <reference path='..\..\..\..\src\compiler\typescript.ts' />
/// <reference path='..\..\..\..\src\harness\harness.ts' />
describe('Compiling unittests\\compiler\\classOverloads.ts', function () {
it("Everytype is a subtype of itself", function () {
var code = 'class foo { public bar: number; }';
code += 'class bar extends foo { public bar: number; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("All types except the Void type are subtypes of the Any type", function () {
var code = 'class foo { public bar: any; }';
code += 'class bar extends foo { public bar: number; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("All types are subtypes of the Any type - 2", function () {
var code = 'class baz { public bar(): any { return 1; } }';
code += 'class foo extends baz { public bar(): void {} }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("The Undefined type is a subtype of all types except the Void type", function () {
var code = 'class baz { public bar(): any { return 1 } }';
code += 'class foo extends baz { public bar(){ return undefined} }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("The Undefined type is a subtype of all types except the Void type - 2", function () {
var code = 'class baz { public bar(): void { } }';
code += 'class foo extends baz { public bar(){ return undefined} }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("The Null type is a subtype of all types, except the Undefined and Void types", function () {
var code = 'class baz { public bar:any; }';
code += 'class foo extends baz { public bar = null; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("The Null type is a subtype of all types, except the Undefined and Void types - 3", function () {
var code = 'class baz { public bar():void { } }';
code += 'class foo extends baz { public bar() { return null; } }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
describe('An object type S is a subtype of an object type T', function () {
it("A property in T is matched by a property in S", function () {
var code = 'class baz { public bar: { a: string; }; }';
code += 'class foo extends baz { public bar: { a: number; }; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 1);
});
});
it("A property in T is matched by a property in S - 2", function () {
var code = 'class baz { public bar: { a: string; }; }';
code += 'class foo extends baz { public bar: { a: string; }; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("A property in T is matched by a property in S - 3", function () {
var code = 'class baz { public bar: { a: string; }; }';
code += 'class foo extends baz { public bar: { b: string; }; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 1);
});
});
it("A call, construct or index signature in T is matched by a call, construct or index signature", function () {
var code = 'class baz { public bar: { (); }; }';
code += 'class foo extends baz { public bar: { (); } ;}';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("A call, construct or index signature in T is matched by a call, construct or index signature - 2", function () {
var code = 'class baz { public bar: { [idx:number]: any; }; }';
code += 'class foo extends baz { public bar: { (); }; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 1);
});
});
it("A call, construct or index signature in T is matched by a call, construct or index signature - 3", function () {
var code = 'class baz { public bar: { (a: string); }; }';
code += 'class foo extends baz { public bar: { (); }; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("A call, construct or index signature in T is matched by a call, construct or index signature - 4", function () {
var code = 'class baz { public bar: { (a:string); }; }';
code += 'class foo extends baz { public bar: { (a:string,b:string); }; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 1);
});
});
it("A call, construct or index signature in T is matched by a call, construct or index signature - 5", function () {
var code = 'class baz { public bar: { ():void; }; }';
code += 'class foo extends baz { public bar: { ():void; }; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("A call, construct or index signature in T is matched by a call, construct or index signature - 6", function () {
var code = 'class baz { public bar: { (); }; }';
code += 'class foo extends baz { public bar: { ():void; }; }';
Harness.Compiler.compileString(code, 'subtypes', function (result) {
assert.equal(result.errors.length, 0);
});
});
});
});

View File

@ -1,26 +0,0 @@
///<reference path='..\..\..\..\src\compiler\typescript.ts' />
///<reference path='..\..\..\..\src\harness\harness.ts' />
describe('Compiling tests\\compiler\\constructSignatureTests.ts', function () {
it("If a signature omits a return type annotation, any type is assumed", function () {
var code = 'var foo: {new ();};';
code += 'var test = new foo();'
code += 'test.bar = 2;'
Harness.Compiler.compileString(code, 'construct signatures', function (result) {
assert.equal(result.errors.length, 0);
});
});
it("A call signature can have the void return type", function () {
var code = 'var foo: {new ():void;};';
Harness.Compiler.compileString(code, 'call signatures', function (result) {
assert.equal(result.errors.length, 1);
});
});
it("A construct signature can't have the same overload", function () {
var code = 'var foo: { new (): string; new (): string; };';
Harness.Compiler.compileString(code, 'call signatures', function (result) {
assert.equal(result.errors.length, 0);
});
});
});

View File

@ -1,52 +0,0 @@
///<reference path='..\..\..\..\src\compiler\typescript.ts' />
///<reference path='..\..\..\..\src\harness\harness.ts' />
//@tags 1.1 Declarations
describe('Compiling unittests\\compiler\\declarationTests.ts', function() {
it("Each internal modules export declaration spaces are shared with other internal modules that have the same root module and the " +
"same qualified name starting from that root module", function() {
var code = 'module baz{export var foo;}';
code += 'module baz{export var bar;}'
code += 'baz.foo = baz.bar;'
Harness.Compiler.compileString(code, 'declarations', function(result) {
assert.equal(result.errors.length, 0);
});
});
it("Each object type literal has a declaration space for its members", function() {
var code = 'var foo:{a:number;};';
code += 'foo.a = 2;'
Harness.Compiler.compileString(code, 'declarations', function(result) {
assert.equal(result.errors.length, 0);
});
});
it("Each class declaration has a declaration space for members and a declaration space for statics", function() {
var code = 'class foo {';
code += ' static bar;'
code += ' public bar;'
code += '}'
Harness.Compiler.compileString(code, 'declarations', function(result) {
assert.equal(result.errors.length, 0);
});
});
it("Each function declaration (including member function declarations and static function declarations) has a declaration space for " +
"statics and a declaration space for locals (parameters, variables, and functions).", function() {
var code = 'function foo() {';
code += ' static bar;'
code += ' var bar;'
code += '}'
Harness.Compiler.compileString(code, 'declarations', function(result) {
assert.equal(result.errors.length, 1);
});
});
it("Modules contain separate declaration spaces for variables and types.", function() {
var code = 'module M {';
code += ' class bar {};'
code += ' var bar;'
code += '}'
Harness.Compiler.compileString(code, 'declarations', function(result) {
assert.equal(result.errors.length, 1);
});
});
});

View File

@ -1,25 +0,0 @@
///<reference path='..\..\..\..\src\compiler\typescript.ts' />
///<reference path='..\..\..\..\src\harness\harness.ts' />
describe('Compiling unittests\\compiler\\functionSignatureTests.ts', function() {
it('Check overload with different return types.', function(){
var code = 'var foo: { bar(): string; bar(): number; };\n';
code += 'var bar: { bar: { (): string; (): number; }; };';
code += 'foo = bar;';
Harness.Compiler.compileString(code, 'function signatures', function(result) {
assert.equal(result.errors.length, 0);
});
})
describe('Function Type Literals', function() {
it('Basic sanity check', function() {
var code = 'var foo: { (): string; };';
code += 'var bar: () => string;';
code += 'foo = bar;';
Harness.Compiler.compileString(code, 'function type literal', function(result) {
assert.equal(result.errors.length, 0);
});
});
});
});

View File

@ -1,13 +0,0 @@
///<reference path='..\..\..\..\src\compiler\typescript.ts' />
///<reference path='..\..\..\..\src\harness\harness.ts' />
describe('Compiling tests\\compiler\\identifiers.ts', function() {
it("Everytype is a subtype of itself", function() {
var code = 'class foo { public bar: number; }';
code += 'class bar extends foo { public bar: number; }';
Harness.Compiler.compileString(code, 'subtypes', function(result) {
assert.equal(result.errors.length, 0);
});
});
});

View File

@ -1,14 +0,0 @@
///<reference path='..\..\..\..\src\compiler\typescript.ts' />
///<reference path='..\..\..\..\src\harness\harness.ts' />
describe('Compiling unittests\\compiler\\moduleAlias.ts', function() {
describe('Internal module alias test', function() {
it("basic test", function() {
var code = "module A.B.C { import XYZ = X.Y.Z; export function ping(x: number) { if (x > 0) XYZ.pong(x-1);}};";
code += "module X.Y.Z { import ABC = A.B.C; export function pong(x: number) { if (x > 0) ABC.ping(x-1);}};";
Harness.Compiler.compileString(code, 'module alias', function(result) {
assert.equal(result.errors.length, 0);
});
});
});
});

View File

@ -1,50 +0,0 @@
///<reference path='..\..\..\..\src\compiler\typescript.ts' />
///<reference path='..\..\..\..\src\harness\harness.ts' />
describe('Verifying pathing functions', function () {
it("Normalizes Mac paths", function () {
var result = TypeScript.normalizePath("/Users/Me/somefile.ts");
var expected = "/Users/Me/somefile.ts";
assert.equal(result, expected);
});
it("Normalizes relative Mac paths", function () {
var result = TypeScript.normalizePath("/Users/./Me/../somefile.ts");
var expected = "/Users/somefile.ts";
assert.equal(result, expected);
});
it("Normalizes Windows paths", function () {
var result = TypeScript.normalizePath("C:\\Users\\Me\\somefile.ts");
var expected = "C:/Users/Me/somefile.ts";
assert.equal(result, expected);
});
it("Normalizes relative Windows paths", function () {
var result = TypeScript.normalizePath("C:\\Users\\.\\Me\\..\\somefile.ts");
var expected = "C:/Users/somefile.ts";
assert.equal(result, expected);
});
it("Normalizes . and ..", function () {
var result = TypeScript.normalizePath("..\\Users\\.\\Me\\..\\somefile.ts");
var expected = "../Users/somefile.ts";
assert.equal(result, expected);
});
it("Normalizes UNC paths", function () {
var result = TypeScript.normalizePath("\\\\server\\share\\someFile.ts");
var expected = "file://server/share/someFile.ts";
assert.equal(result, expected);
});
it("Normalizes relative UNC paths with IP addresses", function () {
var result = TypeScript.normalizePath("\\\\127.0.0.1\\share\\..\\elsewhere\\someFile.ts");
var expected = "file://127.0.0.1/elsewhere/someFile.ts";
assert.equal(result, expected);
});
it("Normalizes HTTP paths", function () {
var result = TypeScript.normalizePath("http://www.server.com/share/someFile.ts");
var expected = "http://www.server.com/share/someFile.ts";
assert.equal(result, expected);
});
it("Normalizes relative HTTP paths", function () {
var result = TypeScript.normalizePath("http://www.server.com/share/../someFile.ts");
var expected = "http://www.server.com/someFile.ts";
assert.equal(result, expected);
});
});

View File

@ -1,19 +0,0 @@
///<reference path='..\..\..\..\src\compiler\typescript.ts' />
///<reference path='..\..\..\..\src\harness\harness.ts' />
describe('Compiling unittests\\compiler\\propertySignatureTests.ts', function() {
it('The Identifier of a property signature must be unique within its containing type. ', function(){
var code = 'var foo: { a:string; a: string; };';
Harness.Compiler.compileString(code, 'property signatures', function(result) {
assert.equal(result.errors.length, 1);
//assert.compilerWarning(result, 1, 9, 'Duplicate identifier a');
});
});
it('If a property signature omits a TypeAnnotation, the Any type is assumed.', function(){
var code = 'var foo: { a; }; foo.a = 2; foo.a = "0";';
Harness.Compiler.compileString(code, 'property signatures', function(result) {
assert.equal(result.errors.length, 0);
});
})
});

View File

@ -1,172 +0,0 @@
///<reference path='..\..\..\..\src\compiler\typescript.ts' />
///<reference path='..\..\..\..\src\harness\harness.ts' />
///<reference path='..\..\..\..\src\services\typescriptServices.ts' />
class TestSourceFile {
constructor(
public fileName: string,
public version: number,
public scriptSnapshot: TypeScript.IScriptSnapshot,
public isOpen: boolean,
public byteOrderMark: TypeScript.ByteOrderMark = TypeScript.ByteOrderMark.Utf8) {
}
}
class TestHostSettings {
constructor(
public files: TypeScript.StringHashTable<TestSourceFile>,
public compilationSettings: TypeScript.CompilationSettings = TypeScript.ImmutableCompilationSettings.defaultSettings().toCompilationSettings()) {
}
}
describe("testDocumentRetrievalAndUpdate", () => {
function getHost(settings: TestHostSettings): TypeScript.Services.ILanguageServiceHost {
return {
getCompilationSettings(): TypeScript.CompilationSettings {
return settings.compilationSettings;
},
getScriptFileNames(): string[]{
return settings.files.getAllKeys();
},
getScriptVersion(fileName: string): number {
return settings.files.lookup(fileName).version;
},
getScriptIsOpen(fileName: string): boolean {
return settings.files.lookup(fileName).isOpen;
},
getScriptByteOrderMark(fileName: string): TypeScript.ByteOrderMark {
return settings.files.lookup(fileName).byteOrderMark;
},
getScriptSnapshot(fileName: string): TypeScript.IScriptSnapshot {
return settings.files.lookup(fileName).scriptSnapshot;
},
getDiagnosticsObject(): TypeScript.Services.ILanguageServicesDiagnostics {
throw TypeScript.Errors.notYetImplemented();
},
getLocalizedDiagnosticMessages(): any {
return null;
},
information(): boolean {
return false;
},
debug(): boolean {
return false;
},
warning(): boolean {
return false;
},
error(): boolean {
return false;
},
fatal(): boolean {
return false;
},
log(s: string): void {
},
resolveRelativePath(path: string, directory: string): string {
throw TypeScript.Errors.notYetImplemented();
},
fileExists(path: string): boolean {
throw TypeScript.Errors.notYetImplemented();
},
directoryExists(path: string): boolean {
throw TypeScript.Errors.notYetImplemented();
},
getParentDirectory(path: string): string {
throw TypeScript.Errors.notYetImplemented();
},
getCancellationToken(): TypeScript.ICancellationToken {
return TypeScript.CancellationToken.None;
}
}
}
function getLanguageServiceCompiler(ls: TypeScript.Services.ILanguageService): TypeScript.Services.LanguageServiceCompiler {
return <TypeScript.Services.LanguageServiceCompiler>(<any>ls).compiler
}
it("documents are shared between projects", () => {
function ensureDocumentIsShared(prefix: string, ls1: TypeScript.Services.ILanguageService, ls2: TypeScript.Services.ILanguageService, fileName: string): void {
var c1 = getLanguageServiceCompiler(ls1);
var c2 = getLanguageServiceCompiler(ls2);
// getDocument synchronized its internal state with host
var doc1 = c1.getDocument(fileName);
var doc2 = c2.getDocument(fileName);
if (doc1 !== doc2) {
throw new Error(prefix + ":document should be shared between language services");
}
}
var files = new TypeScript.StringHashTable<TestSourceFile>();
var f1 = new TestSourceFile("file1.ts", 1, TypeScript.ScriptSnapshot.fromString("var x = 1;"), false);
files.add(f1.fileName, f1);
var factory = new TypeScript.Services.TypeScriptServicesFactory();
var hostSettings = new TestHostSettings(files);
var ls1 = factory.createPullLanguageService(getHost(hostSettings));
var ls2 = factory.createPullLanguageService(getHost(hostSettings));
ensureDocumentIsShared("==1==", ls1, ls2, f1.fileName);
f1.version = 2;
f1.scriptSnapshot = TypeScript.ScriptSnapshot.fromString("var x = 2;");
ensureDocumentIsShared("==2==", ls1, ls2, f1.fileName);
});
it("documents are refreshed when settings in compilation settings affect syntax", () => {
var files = new TypeScript.StringHashTable<TestSourceFile>();
var f1 = new TestSourceFile("file1.ts", 1, TypeScript.ScriptSnapshot.fromString("var x = 1;"), false);
files.add(f1.fileName, f1);
var factory = new TypeScript.Services.TypeScriptServicesFactory();
var hostSettings = new TestHostSettings(files);
var factory = new TypeScript.Services.TypeScriptServicesFactory();
var ls = factory.createPullLanguageService(getHost(hostSettings));
var compiler = getLanguageServiceCompiler(ls);
var d1 = compiler.getDocument(f1.fileName);
// change compilation setting that doesn't affect parsing - should have the same document
hostSettings.compilationSettings.generateDeclarationFiles = !hostSettings.compilationSettings.generateDeclarationFiles;
var d2 = compiler.getDocument(f1.fileName);
if (d1 !== d2) {
throw new Error("Expected to have the same document instance");
}
// change value of compilation setting that is used during production of AST - new document is required
hostSettings.compilationSettings.codeGenTarget = TypeScript.LanguageVersion.EcmaScript5;
var d3 = compiler.getDocument(f1.fileName);
if (d2 === d3) {
throw new Error("Changed codeGenTarget: Expected to have different instances of document");
}
hostSettings.compilationSettings.propagateEnumConstants = !hostSettings.compilationSettings.propagateEnumConstants;
var d4 = compiler.getDocument(f1.fileName);
if (d3 === d4) {
throw new Error("Changed propagateEnumConstants: Expected to have different instances of document");
}
hostSettings.compilationSettings.allowAutomaticSemicolonInsertion = !hostSettings.compilationSettings.allowAutomaticSemicolonInsertion;
var d5 = compiler.getDocument(f1.fileName);
if (d4 === d5) {
throw new Error("Changed allowAutomaticSemicolonInsertion: Expected to have different instances of document");
}
});
});

View File

@ -1,4 +0,0 @@
///<reference path='..\..\..\..\src\harness\harness.ts'/>
///<reference path='..\..\..\..\src\compiler\tsc.ts' />
///<reference path='..\..\..\..\src\compiler\typescript.ts' />
///<reference path='..\..\..\..\src\services\typescriptServices.ts' />

View File

@ -1,20 +0,0 @@
///<reference path='..\..\..\src\harness\harness.ts'/>
///<reference path='..\..\..\src\harness\baselining.ts'/>
declare var JSON: any;
describe('Accepting local files as new reference...', function() {
var localPath = 'tests/services/baselines/local';
var outputPath = 'tests/services/baselines/reference';
// Get a list of all the files in the baseline/inputs folder
var files = IO.dir(localPath);
// Copy them to the output folder
for (var i = 0; i < files.length; i++) {
var filename = files[i].substr(files[i].lastIndexOf('\\'));
if(filename.indexOf('.html') === -1) {
var referenceData = IO.readFile(files[i]);
IO.writeFile(outputPath + '/' + filename, referenceData);
}
}
});

View File

@ -1,66 +0,0 @@
/// <reference path='..\..\..\src\harness\harness.ts'/>
/// <reference path='..\..\..\src\harness\baselining.ts'/>
/// <reference path='..\..\..\src\harness\external\json2.ts'/>
describe('Baseline files match (intellisense data)', function() {
var inputPath = 'tests/services/baselines/inputs';
var outputPath = 'tests/services/baselines/local';
var referencePath = 'tests/services/baselines/reference';
var i;
// Might need to create this
IO.createDirectory(outputPath);
// Delete any old reports from the local path
var localFiles = IO.dir(outputPath);
for (i = 0; i < localFiles.length; i++) {
var localFilename = localFiles[i];
if(localFilename.indexOf('.html') > 0) {
IO.deleteFile(localFilename);
}
}
// Get a list of all the files in the baseline/inputs folder
var files = IO.dir(inputPath);
var template = IO.readFile('tests/services/baselines/diff-template.html');
// For each file, get data:
// a) Completion
// b) Type signature
// c) etc...
for (i = 0; i < files.length; i++) {
var filename = files[i].substr(files[i].lastIndexOf('\\'));
var scriptText = IO.readFile(files[i]).trim();
var outputAndCheck = function(nameSuffix: string, process: any) {
describe(nameSuffix + ' data for ' + filename + ' matches the baseline', function() {
var data = process(scriptText);
var stringified = JSON.stringify(data).trim();
var baseFilename = filename + '-' + nameSuffix + '.json';
IO.writeFile(outputPath + '/' + baseFilename, stringified);
var referenceFilename = referencePath + '/' + baseFilename;
var reference = IO.fileExists(referenceFilename) ? IO.readFile(referenceFilename) : '[{file: "(no file)"}]';
reference = reference.trim();
if (reference != stringified) {
// Emit a report file in 'local'
var errorReportFile = outputPath + filename + '-' + nameSuffix + '-diff.html';
IO.writeFile(errorReportFile,
template.replace('/**REFERENCE**/', reference).replace('/**ACTUAL**/', stringified));
throw new Error('Data does not match reference. Refer to diff report ' + errorReportFile);
}
});
};
// Write that data out to a JSON file in the 'local' folder
outputAndCheck('signatures', getIntellisenseSignatureRegions);
outputAndCheck('completions', getIntellisenseCompletionListRegions);
outputAndCheck('definitions', getIntellisenseDefinitionRegions);
outputAndCheck('types', getIntellisenseTypeRegions);
outputAndCheck('members', getIntellisenseMemberListRegions);
}
});

View File

@ -1,23 +0,0 @@
module Foo { var testing = ""; test }
class C1 {
public pubMeth() {this.} // test on 'this.'
private privMeth() {}
public pubProp;
private privProp;
}
var f = new C1();
f. // test on F.
module M {
export class C { public pub; private priv; }
export var V = 0;
}
var c = new M.C();
c. // test on c.
//Test for comment
//c.

View File

@ -1,215 +0,0 @@
interface IOptions {
name: string;
flag: boolean;
short: string;
usage: string;
set: (s: string) => void;
type: string;
}
class OptionsParser {
private DEFAULT_SHORT_FLAG = "-";
private DEFAULT_LONG_FLAG = "--";
constructor (private host: IIO) { }
// Find the option record for the given string. Returns null if not found.
private findOption(arg: string) {
for (var i = 0; i < this.options.length; i++) {
if (arg === this.options[i].short || arg === this.options[i].name) {
return this.options[i];
}
}
return null;
}
public unnamed: string[] = [];
public options: IOptions[] = [];
public printUsage() {
IO.printLine("Syntax: tsc [options] [file ..]");
IO.printLine("");
IO.printLine("Examples: tsc hello.ts");
IO.printLine(" tsc --out foo.js foo.ts");
IO.printLine(" tsc @args.txt");
IO.printLine("");
IO.printLine("Options:");
var output = [];
var maxLength = 0;
this.options = this.options.sort(function(a, b) {
var aName = a.name.toLowerCase();
var bName = b.name.toLowerCase();
if (aName > bName) {
return 1;
} else if (aName < bName) {
return -1;
} else {
return 0;
}
});
// Build up output array
for (var i = 0; i < this.options.length; i++) {
var option = this.options[i];
if (!option.usage)
break;
var usageString = " ";
var type = option.type ? " " + option.type.toUpperCase() : "";
if (option.short) {
usageString += this.DEFAULT_SHORT_FLAG + option.short + type + ", ";
}
usageString += this.DEFAULT_LONG_FLAG + option.name + type;
output.push([usageString, option.usage]);
if (usageString.length > maxLength) {
maxLength = usageString.length;
}
}
output.push([" @<file>", "Insert command line options and files from a file."]);
// Print padded output
for (var i = 0; i < output.length; i++) {
IO.printLine(output[i][0] + (new Array(maxLength - output[i][0].length + 3)).join(" ") + output[i][1]);
}
}
public option(name: string, config: IOptions);
public option(name: string, config: IOptions, short: string) {
if (!config) {
config = <any>short;
short = null;
}
config.name = name;
config.short = short;
config.flag = false;
this.options.push(config);
}
public flag(name: string, config: IOptions);
public flag(name: string, config: IOptions, short: string) {
if (!config) {
config = <any>short;
short = null;
}
config.name = name;
config.short = short;
config.flag = true
this.options.push(config);
}
// Parse an arguments string
public parseString(argString: string) {
var position = 0;
var tokens = argString.match(/\s+|"|[^\s"]+/g);
function peek() {
return tokens[position];
}
function consume() {
return tokens[position++];
}
function consumeQuotedString() {
var value = '';
consume(); // skip opening quote.
var token = peek();
while (token && token !== '"') {
consume();
value += token;
token = peek();
}
consume(); // skip ending quote;
return value;
}
var args: string[] = [];
var currentArg = '';
while (position < tokens.length) {
var token = peek();
if (token === '"') {
currentArg += consumeQuotedString();
} else if (token.match(/\s/)) {
if (currentArg.length > 0) {
args.push(currentArg);
currentArg = '';
}
consume();
} else {
consume();
currentArg += token;
}
}
if (currentArg.length > 0) {
args.push(currentArg);
}
this.parse(args);
}
// Parse arguments as they come from the platform: split into arguments.
public parse(args: string[]) {
var position = 0;
function consume() {
return args[position++];
}
while (position < args.length) {
var current = consume();
var match = current.match(/^(--?|\/|@)(.*)/);
var value = null;
if (match) {
if (match[1] === '@') {
this.parseString(IO.readFile(match[2]));
} else {
var arg = match[2];
var option = this.findOption(arg);
if (option === null) {
IO.printLine("Unknown option " + arg);
IO.printLine("");
this.printUsage();
} else {
if (!option.flag)
value = consume();
option.set(value);
}
}
} else {
this.unnamed.push(current);
}
}
}
}

View File

@ -1,2 +0,0 @@
[{"start":17,"end":31,"data":"0\t17\t34\t\ttesting\t\tFoo"},{"start":33,"end":34,"data":"0\t17\t34\t\ttesting\t\tFoo"},{"start":49,"end":60,"data":"0\t55\t180\t\tC1\t\t__GLO"},{"start":71,"end":79,"data":"0\t64\t88\t\tpubMeth\t\tC1"},{"start":82,"end":87,"data":"0\t55\t180\t\tC1\t\t__GLO"},{"start":118,"end":127,"data":"0\t110\t131\t\tprivMeth\t\tC1"},{"start":134,"end":151,"data":"0\t134\t153\t\tpubProp\t\tC1"},{"start":152,"end":153,"data":"0\t134\t153\t\tpubProp\t\tC1"},{"start":156,"end":175,"data":"0\t156\t177\t\tprivProp\t\tC1"},{"start":176,"end":177,"data":"0\t156\t177\t\tprivProp\t\tC1"},{"start":184,"end":192,"data":"0\t184\t201\t\tf\t\t__GLO"},{"start":192,"end":200,"data":"0\t55\t180\t\tC1\t\t__GLO"},{"start":200,"end":201,"data":"0\t184\t201\t\tf\t\t__GLO"},{"start":203,"end":206,"data":"0\t184\t201\t\tf\t\t__GLO"},{"start":221,"end":230,"data":"0\t221\t315\t\tM\t\t__GLO"},{"start":237,"end":252,"data":"0\t250\t289\t\tC\t\tM"},{"start":254,"end":267,"data":"0\t254\t269\t\tpub\t\tM.C"},{"start":268,"end":269,"data":"0\t254\t269\t\tpub\t\tM.C"},{"start":270,"end":285,"data":"0\t270\t287\t\tpriv\t\tM.C"},{"start":286,"end":287,"data":"0\t270\t287\t\tpriv\t\tM.C"},{"start":295,"end":310,"data":"0\t295\t312\t\tV\t\tM"},{"start":311,"end":312,"data":"0\t295\t312\t\tV\t\tM"},{"start":321,"end":329,"data":"0\t321\t339\t\tc\t\t__GLO"},{"start":329,"end":333,"data":"0\t250\t289\t\tC\t\tM"},{"start":333,"end":335,"data":"0\t221\t315\t\tM\t\t__GLO"},{"start":335,"end":338,"data":"0\t250\t289\t\tC\t\tM"},{"start":338,"end":339,"data":"0\t321\t339\t\tc\t\t__GLO"},{"start":343,"end":346,"data":"0\t321\t339\t\tc\t\t__GLO"}]

View File

@ -1,2 +0,0 @@
[{"start":87,"end":88,"data":"pubMeth\t() => void\npubProp\tnumber\nprivMeth\t() => void\nprivProp\tnumber\n"},{"start":205,"end":206,"data":"pubMeth\t() => void\npubProp\tnumber\n"},{"start":335,"end":336,"data":"C\tnew() => M.C\nV\tnumber\n"},{"start":345,"end":346,"data":"pub\tnumber\n"}]

View File

@ -1,2 +0,0 @@
[{"start":192,"end":200,"data":"C1(): C1\n"},{"start":329,"end":338,"data":"C(): C\n"}]

View File

@ -1,2 +0,0 @@
[{"start":17,"end":34,"data":"string"},{"start":34,"end":39,"data":"Foo"},{"start":39,"end":43,"data":"any"},{"start":43,"end":45,"data":"Foo"},{"start":49,"end":64,"data":"new() => C1"},{"start":64,"end":82,"data":"() => void"},{"start":82,"end":87,"data":"C1"},{"start":87,"end":88,"data":"() => void"},{"start":88,"end":89,"data":"new() => C1"},{"start":108,"end":110,"data":"new() => C1"},{"start":110,"end":131,"data":"() => void"},{"start":131,"end":134,"data":"new() => C1"},{"start":134,"end":153,"data":"number"},{"start":153,"end":156,"data":"new() => C1"},{"start":156,"end":177,"data":"number"},{"start":177,"end":180,"data":"new() => C1"},{"start":184,"end":196,"data":"C1"},{"start":196,"end":198,"data":"new() => C1"},{"start":198,"end":201,"data":"C1"},{"start":203,"end":205,"data":"C1"},{"start":221,"end":237,"data":"M"},{"start":237,"end":254,"data":"new() => C"},{"start":254,"end":269,"data":"number"},{"start":269,"end":270,"data":"new() => C"},{"start":270,"end":287,"data":"number"},{"start":287,"end":289,"data":"new() => C"},{"start":289,"end":295,"data":"M"},{"start":295,"end":312,"data":"number"},{"start":312,"end":315,"data":"M"},{"start":321,"end":333,"data":"M.C"},{"start":333,"end":334,"data":"M"},{"start":334,"end":336,"data":"new() => M.C"},{"start":336,"end":339,"data":"M.C"},{"start":343,"end":345,"data":"M.C"}]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,2 +0,0 @@
[{"start":3649,"end":3659,"data":"consume(): any\n"},{"start":3710,"end":3716,"data":"peek(): any\n"},{"start":3783,"end":3793,"data":"consume(): any\n"},{"start":3856,"end":3862,"data":"peek(): any\n"},{"start":3894,"end":3904,"data":"consume(): any\n"},{"start":4104,"end":4110,"data":"peek(): any\n"},{"start":4179,"end":4200,"data":"consumeQuotedString(): string\n"},{"start":4413,"end":4423,"data":"consume(): any\n"},{"start":4463,"end":4473,"data":"consume(): any\n"},{"start":4636,"end":4653,"data":"parse(args: string[]): void\n"},{"start":4956,"end":4965,"data":"consume(): string\n"},{"start":5147,"end":5164,"data":"parseString(argString: string): void\n"},{"start":5185,"end":5187,"data":"parseString(argString: string): void\n"},{"start":5289,"end":5309,"data":"findOption(arg: string): IOptions\n"},{"start":5489,"end":5507,"data":"printUsage(): void\n"},{"start":5618,"end":5627,"data":"consume(): string\n"},{"start":5656,"end":5674,"data":"set(s: string): void\n"}]

File diff suppressed because one or more lines are too long

View File

@ -1,198 +1,178 @@
///<reference path='_project.ts'/>
interface Classification {
interface Classification {
position: number;
length: number;
class2: TypeScript.TokenClass;
class: ts.TokenClass;
}
interface ClassiferResult {
tuples: Classification[];
finalLexState: TypeScript.LexState;
finalEndOfLineState: ts.EndOfLineState;
}
var TokenClassNames = {};
TokenClassNames[TypeScript.TokenClass.Punctuation] = "Punctuation";
TokenClassNames[TypeScript.TokenClass.Keyword] = "Keyword";
TokenClassNames[TypeScript.TokenClass.Operator] = "Operator";
TokenClassNames[TypeScript.TokenClass.Comment] = "Comment";
TokenClassNames[TypeScript.TokenClass.Whitespace] = "Whitespace";
TokenClassNames[TypeScript.TokenClass.Identifier] = "Identifier";
TokenClassNames[TypeScript.TokenClass.NumberLiteral] = "NumberLiteral";
TokenClassNames[TypeScript.TokenClass.StringLiteral] = "StringLiteral";
TokenClassNames[TypeScript.TokenClass.RegExpLiteral] = "RegExpLiteral";
interface ClassificationEntry {
value: any;
class: ts.TokenClass;
}
describe('Colorization', function () {
var mytypescriptLS = new Harness.LanguageService.TypeScriptLS();
var myclassifier = mytypescriptLS.getClassifier();
describe('Colorization', function() {
var mytypescriptLS = new Harness.TypeScriptLS();
var myls = mytypescriptLS.getLanguageService();
var myclassifier = new Services.ClassifierShim(myls.host);
function getClassifications(code: string, initialLexState?: TypeScript.LexState = TypeScript.LexState.Start): ClassiferResult {
var classResult = myclassifier.getClassificationsForLine(code, initialLexState).split('\n');
function getClassifications(code: string, initialEndOfLineState: ts.EndOfLineState = ts.EndOfLineState.Start): ClassiferResult {
var classResult = myclassifier.getClassificationsForLine(code, initialEndOfLineState).split('\n');
var tuples: Classification[] = [];
var i = 0;
var position = 0;
for (; i < classResult.length - 1; i += 2) {
tuples[i / 2] = {
var t = tuples[i / 2] = {
position: position,
length: parseInt(classResult[i]),
class2: parseInt(classResult[i + 1])
class: parseInt(classResult[i + 1])
};
assert.isTrue(t.length > 0, "Result length should be greater than 0, got :" + t.length);
position += t.length;
}
var finalLexState = classResult[classResult.length - 1];
var finalEndOfLineState = classResult[classResult.length - 1];
assert.equal(position, code.length, "Expected accumilative length of all entries to match the length of the source. expected: " + code.length + ", but got: " + position);
return {
tuples: tuples,
finalLexState: parseInt(finalLexState)
finalEndOfLineState: parseInt(finalEndOfLineState)
};
}
function verifyClassification(classification: Classification, expectedLength: number, expectedClass: number) {
assert.notNull(classification);
assert.is(classification.length === expectedLength, "Classification length does not match expected. Expected: " + expectedLength + ", Actual: " + classification.length);
assert.is(classification.class2 === expectedClass, "Classification class does not match expected. Expected: " + TokenClassNames[expectedClass] + ", Actual: " + TokenClassNames[classification.class2]);
assert.isNotNull(classification);
assert.equal(classification.length, expectedLength, "Classification length does not match expected. Expected: " + expectedLength + ", Actual: " + classification.length);
assert.equal(classification.class, expectedClass, "Classification class does not match expected. Expected: " + ts.TokenClass[expectedClass] + ", Actual: " + ts.TokenClass[classification.class]);
}
describe("test cases for colorization", function() {
var results = getClassifications('var x:string = "foo"; //Hello');
it("checks for a keyword", function() {
verifyClassification(results.tuples[0], 3, TypeScript.TokenClass.Keyword);
function getEntryAtPosistion(result: ClassiferResult, position: number) {
for (var i = 0, n = result.tuples.length; i < n; i++) {
if (result.tuples[i].position === position) return result.tuples[i];
}
return undefined;
}
function punctuation(text: string) { return { value: text, class: ts.TokenClass.Punctuation }; }
function keyword(text: string) { return { value: text, class: ts.TokenClass.Keyword }; }
function operator(text: string) { return { value: text, class: ts.TokenClass.Operator }; }
function comment(text: string) { return { value: text, class: ts.TokenClass.Comment }; }
function whitespace(text: string) { return { value: text, class: ts.TokenClass.Whitespace }; }
function identifier(text: string) { return { value: text, class: ts.TokenClass.Identifier }; }
function numberLiteral(text: string) { return { value: text, class: ts.TokenClass.NumberLiteral }; }
function stringLiteral(text: string) { return { value: text, class: ts.TokenClass.StringLiteral }; }
function regExpLiteral(text: string) { return { value: text, class: ts.TokenClass.RegExpLiteral }; }
function finalEndOfLineState(value: number) { return { value: value, class: undefined }; }
function test(text: string, initialEndOfLineState: ts.EndOfLineState, ...expectedEntries: ClassificationEntry[]): void {
var result = getClassifications(text, initialEndOfLineState);
for (var i = 0, n = expectedEntries.length; i < n; i++) {
var expectedEntry = expectedEntries[i];
if (expectedEntry.class === undefined) {
assert.equal(result.finalEndOfLineState, expectedEntry.value, "final endOfLineState does not match expected.");
}
else {
var actualEntryPosition = text.indexOf(expectedEntry.value);
assert(actualEntryPosition >= 0, "token: '" + expectedEntry.value + "' does not exit in text: '" + text + "'.");
var actualEntry = getEntryAtPosistion(result, actualEntryPosition);
assert(actualEntry, "Could not find classification entry for '" + expectedEntry.value + "' at position: " + actualEntryPosition);
assert.equal(actualEntry.length, expectedEntry.value.length, "Classification class does not match expected.");
assert.equal(actualEntry.class, expectedEntry.class, "Classification class does not match expected.");
}
}
}
describe("test getClassifications", function () {
it("Returns correct token classes", function () {
test("var x: string = \"foo\"; //Hello",
ts.EndOfLineState.Start,
keyword("var"),
whitespace(" "),
identifier("x"),
punctuation(":"),
keyword("string"),
operator("="),
stringLiteral("\"foo\""),
comment("//Hello"),
punctuation(";"));
});
it("checks for a whitespace", function() {
verifyClassification(results.tuples[1], 4, TypeScript.TokenClass.Whitespace);
it("classifies correctelly a comment after a divide operator", function () {
test("1 / 2 // comment",
ts.EndOfLineState.Start,
numberLiteral("1"),
whitespace(" "),
operator("/"),
numberLiteral("2"),
comment("// comment"));
});
it("checks for a identifier", function() {
verifyClassification(results.tuples[2], 5, TypeScript.TokenClass.Identifier);
it("classifies correctelly a literal after a divide operator", function () {
test("1 / 2, 3 / 4",
ts.EndOfLineState.Start,
numberLiteral("1"),
whitespace(" "),
operator("/"),
numberLiteral("2"),
numberLiteral("3"),
numberLiteral("4"),
operator(","));
});
it("checks for an punctuation", function() {
verifyClassification(results.tuples[3], 6, TypeScript.TokenClass.Punctuation);
});
it("checks for a operator", function() {
verifyClassification(results.tuples[6], 14, TypeScript.TokenClass.Operator);
it("classifies correctelly an unterminated multi-line string", function () {
test("'line1\\",
ts.EndOfLineState.Start,
stringLiteral("'line1\\"),
finalEndOfLineState(ts.EndOfLineState.InSingleQuoteStringLiteral));
});
it("checks for a string literal", function() {
verifyClassification(results.tuples[8], 20, TypeScript.TokenClass.StringLiteral);
it("classifies correctelly the second line of an unterminated multi-line string", function () {
test("\\",
ts.EndOfLineState.InDoubleQuoteStringLiteral,
stringLiteral("\\"),
finalEndOfLineState(ts.EndOfLineState.InDoubleQuoteStringLiteral));
});
it("checks for a comment", function() {
verifyClassification(results.tuples[11], 29, TypeScript.TokenClass.Comment);
});
});
describe("test comment colorization after a divide operator", function() {
var results = getClassifications('1 / 1 // comment');
it("checks for a number literal", function() {
verifyClassification(results.tuples[0], 1, TypeScript.TokenClass.NumberLiteral);
it("classifies correctelly the last line of a multi-line string", function () {
test("'",
ts.EndOfLineState.InSingleQuoteStringLiteral,
stringLiteral("'"),
finalEndOfLineState(ts.EndOfLineState.Start));
});
it("checks for a whitespace", function() {
verifyClassification(results.tuples[1], 2, TypeScript.TokenClass.Whitespace);
it("classifies correctelly an unterminated multiline comment", function () {
test("/*",
ts.EndOfLineState.Start,
comment("/*"),
finalEndOfLineState(ts.EndOfLineState.InMultiLineCommentTrivia));
});
it("checks for a operator", function() {
verifyClassification(results.tuples[2], 3, TypeScript.TokenClass.Operator);
it("classifies correctelly an unterminated multiline comment with trailing space", function () {
test("/* ",
ts.EndOfLineState.Start,
comment("/* "),
finalEndOfLineState(ts.EndOfLineState.InMultiLineCommentTrivia));
});
it("checks for a whitespace", function() {
verifyClassification(results.tuples[3], 4, TypeScript.TokenClass.Whitespace);
it("classifies correctelly a keyword after a dot", function () {
test("a.var",
ts.EndOfLineState.Start,
identifier("var"));
});
it("checks for a number literal", function() {
verifyClassification(results.tuples[4], 5, TypeScript.TokenClass.NumberLiteral);
});
it("checks for a whitespace", function() {
verifyClassification(results.tuples[5], 6, TypeScript.TokenClass.Whitespace);
});
it("checks for a comment", function() {
verifyClassification(results.tuples[6], 16, TypeScript.TokenClass.Comment);
});
});
describe("test literal colorization after a divide operator", function() {
var results = getClassifications('1 / 2, 1 / 2');
it("checks for a number literal", function() {
verifyClassification(results.tuples[0], 1, TypeScript.TokenClass.NumberLiteral);
});
it("checks for a whitespace", function() {
verifyClassification(results.tuples[1], 2, TypeScript.TokenClass.Whitespace);
});
it("checks for a operator", function() {
verifyClassification(results.tuples[2], 3, TypeScript.TokenClass.Operator);
});
it("checks for a whitespace", function() {
verifyClassification(results.tuples[3], 4, TypeScript.TokenClass.Whitespace);
});
it("checks for a number literal", function() {
verifyClassification(results.tuples[4], 5, TypeScript.TokenClass.NumberLiteral);
});
it("checks for a operator", function() {
verifyClassification(results.tuples[5], 6, TypeScript.TokenClass.Operator);
});
it("checks for a whitespace", function() {
verifyClassification(results.tuples[6], 7, TypeScript.TokenClass.Whitespace);
});
it("checks for a number literal", function() {
verifyClassification(results.tuples[7], 8, TypeScript.TokenClass.NumberLiteral);
});
it("checks for a whitespace", function() {
verifyClassification(results.tuples[8], 9, TypeScript.TokenClass.Whitespace);
});
it("checks for a operator", function() {
verifyClassification(results.tuples[9], 10, TypeScript.TokenClass.Operator);
});
it("checks for a whitespace", function() {
verifyClassification(results.tuples[10], 11, TypeScript.TokenClass.Whitespace);
});
it("checks for a number literal", function() {
verifyClassification(results.tuples[11], 12, TypeScript.TokenClass.NumberLiteral);
});
});
describe("test cases for colorizing multi-line string", function() {
it("classifies first line correctelly", function() {
var results = getClassifications("'line1\\\n", TypeScript.LexState.Start);
assert.equal(results.tuples.length, 1);
verifyClassification(results.tuples[0], 8, TypeScript.TokenClass.StringLiteral);
assert.equal(results.finalLexState, TypeScript.LexState.InMultilineSingleQuoteString);
});
it("classifies second line correctelly", function() {
var results = getClassifications("\\\n", TypeScript.LexState.InMultilineSingleQuoteString);
assert.equal(results.tuples.length, 1);
verifyClassification(results.tuples[0], 2, TypeScript.TokenClass.StringLiteral);
assert.equal(results.finalLexState, TypeScript.LexState.InMultilineSingleQuoteString);
});
it("classifies third line correctelly", function() {
var results = getClassifications("'", TypeScript.LexState.InMultilineSingleQuoteString);
assert.equal(results.tuples.length, 1);
verifyClassification(results.tuples[0], 1, TypeScript.TokenClass.StringLiteral);
assert.equal(results.finalLexState, TypeScript.LexState.Start);
it("classifies keyword after a dot on previous line", function () {
test("var",
ts.EndOfLineState.EndingWithDotToken,
identifier("var"),
finalEndOfLineState(ts.EndOfLineState.Start));
});
});
});

View File

@ -0,0 +1,38 @@
///<reference path='..\..\..\..\src\harness\harness.ts' />
describe("DocumentRegistry", () => {
it("documents are shared between projects", () => {
var documentRegistry = ts.createDocumentRegistry();
var defaultCompilerOptions = ts.getDefaultCompilerOptions();
var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
assert(f1 === f2, "DocumentRegistry should return the same document for the same name");
});
it("documents are refreshed when settings in compilation settings affect syntax", () => {
var documentRegistry = ts.createDocumentRegistry();
var compilerOptions: ts.CompilerOptions = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.AMD };
// change compilation setting that doesn't affect parsing - should have the same document
compilerOptions.declaration = true;
var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
compilerOptions.declaration = false;
var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
assert(f1 === f2, "Expected to have the same document instance");
// change value of compilation setting that is used during production of AST - new document is required
compilerOptions.target = ts.ScriptTarget.ES3;
var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
assert(f1 !== f3, "Changed target: Expected to have different instances of document");
compilerOptions.module = ts.ModuleKind.CommonJS;
var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
assert(f1 !== f4, "Changed module: Expected to have different instances of document");
});
});

View File

@ -1,3 +0,0 @@
///<reference path='_project.ts'/>
DumpAST.compareDumpFilesWithBaseline();

View File

@ -1,9 +0,0 @@
///<reference path='..\..\..\harness\dumpAST-baselining.ts'/>
describe('dumpAST-create-baselines', function() {
describe("create test baseline files for AST source locations", function() {
it("create baseline files", function() {
DumpAST.generateBaselineFiles();
});
});
});

View File

@ -0,0 +1,79 @@
class a {
constructor ( n : number ) ;
constructor ( s : string ) ;
constructor ( ns : any ) {
}
public pgF ( ) { } ;
public pv ;
public get d ( ) {
return 30 ;
}
public set d ( ) {
}
public static get p2 ( ) {
return { x : 30 , y : 40 } ;
}
private static d2 ( ) {
}
private static get p3 ( ) {
return "string" ;
}
private pv3 ;
private foo ( n : number ) : string ;
private foo ( s : string ) : string ;
private foo ( ns : any ) {
return ns.toString ( ) ;
}
}
class b extends a {
}
class m1b {
}
interface m1ib {
}
class c extends m1b {
}
class ib2 implements m1ib {
}
declare class aAmbient {
constructor ( n : number ) ;
constructor ( s : string ) ;
public pgF ( ) : void ;
public pv ;
public d : number ;
static p2 : { x : number ; y : number ; } ;
static d2 ( ) ;
static p3 ;
private pv3 ;
private foo ( s ) ;
}
class d {
private foo ( n : number ) : string ;
private foo ( ns : any ) {
return ns.toString ( ) ;
}
private foo ( s : string ) : string ;
}
class e {
private foo ( ns : any ) {
return ns.toString ( ) ;
}
private foo ( s : string ) : string ;
private foo ( n : number ) : string ;
}

View File

@ -0,0 +1,79 @@
class a {
constructor(n: number);
constructor(s: string);
constructor(ns: any) {
}
public pgF() { };
public pv;
public get d() {
return 30;
}
public set d() {
}
public static get p2() {
return { x: 30, y: 40 };
}
private static d2() {
}
private static get p3() {
return "string";
}
private pv3;
private foo(n: number): string;
private foo(s: string): string;
private foo(ns: any) {
return ns.toString();
}
}
class b extends a {
}
class m1b {
}
interface m1ib {
}
class c extends m1b {
}
class ib2 implements m1ib {
}
declare class aAmbient {
constructor(n: number);
constructor(s: string);
public pgF(): void;
public pv;
public d: number;
static p2: { x: number; y: number; };
static d2();
static p3;
private pv3;
private foo(s);
}
class d {
private foo(n: number): string;
private foo(ns: any) {
return ns.toString();
}
private foo(s: string): string;
}
class e {
private foo(ns: any) {
return ns.toString();
}
private foo(s: string): string;
private foo(n: number): string;
}

View File

@ -0,0 +1,4 @@
class foo {
constructor (n?: number, m? = 5, o?: string = "") { }
x:number = 1?2:3;
}

View File

@ -0,0 +1,4 @@
class foo {
constructor(n?: number, m? = 5, o?: string = "") { }
x: number = 1 ? 2 : 3;
}

View File

@ -0,0 +1,3 @@
$ ( document ) . ready ( function ( ) {
alert ( 'i am ready' ) ;
} );

View File

@ -0,0 +1,3 @@
$(document).ready(function() {
alert('i am ready');
});

View File

@ -0,0 +1,10 @@
function foo ( x : { } ) { }
foo ( { } ) ;
interface bar {
x : { } ;
y : ( ) => { } ;
}

View File

@ -0,0 +1,10 @@
function foo(x: {}) { }
foo({});
interface bar {
x: {};
y: () => {};
}

View File

@ -0,0 +1,112 @@
// valid
( ) => 1 ;
( arg ) => 2 ;
arg => 2 ;
( arg = 1 ) => 3 ;
( arg ? ) => 4 ;
( arg : number ) => 5 ;
( arg : number = 0 ) => 6 ;
( arg ? : number ) => 7 ;
( ... arg : number [ ] ) => 8 ;
( arg1 , arg2 ) => 12 ;
( arg1 = 1 , arg2 =3 ) => 13 ;
( arg1 ? , arg2 ? ) => 14 ;
( arg1 : number , arg2 : number ) => 15 ;
( arg1 : number = 0 , arg2 : number = 1 ) => 16 ;
( arg1 ? : number , arg2 ? : number ) => 17 ;
( arg1 , ... arg2 : number [ ] ) => 18 ;
( arg1 , arg2 ? : number ) => 19 ;
// in paren
( ( ) => 21 ) ;
( ( arg ) => 22 ) ;
( ( arg = 1 ) => 23 ) ;
( ( arg ? ) => 24 ) ;
( ( arg : number ) => 25 ) ;
( ( arg : number = 0 ) => 26 ) ;
( ( arg ? : number ) => 27 ) ;
( ( ... arg : number [ ] ) => 28 ) ;
// in multiple paren
( ( ( ( ( arg ) => { return 32 ; } ) ) ) ) ;
// in ternary exression
false ? ( ) => 41 : null ;
false ? ( arg ) => 42 : null ;
false ? ( arg = 1 ) => 43 : null ;
false ? ( arg ? ) => 44 : null ;
false ? ( arg : number ) => 45 : null ;
false ? ( arg ? : number ) => 46 : null ;
false ? ( arg ? : number = 0 ) => 47 : null ;
false ? ( ... arg : number [ ] ) => 48 : null ;
// in ternary exression within paren
false ? ( ( ) => 51 ) : null ;
false ? ( ( arg ) => 52 ) : null ;
false ? ( ( arg = 1 ) => 53 ) : null ;
false ? ( ( arg ? ) => 54 ) : null ;
false ? ( ( arg : number ) => 55 ) : null ;
false ? ( ( arg ? : number ) => 56 ) : null ;
false ? ( ( arg ? : number = 0 ) => 57 ) : null ;
false ? ( ( ... arg : number [ ] ) => 58 ) : null ;
// ternary exression's else clause
false ? null : ( ) => 61 ;
false ? null : ( arg ) => 62 ;
false ? null : ( arg = 1 ) => 63 ;
false ? null : ( arg ? ) => 64 ;
false ? null : ( arg : number ) => 65 ;
false ? null : ( arg ? : number ) => 66 ;
false ? null : ( arg ? : number = 0 ) => 67 ;
false ? null : ( ... arg : number [ ] ) => 68 ;
// nested ternary expressions
( a ? ) => { return a ; } ? ( b ? ) => { return b ; } : ( c ? ) => { return c ; } ;
//multiple levels
( a ? ) => { return a ; } ? ( b ) => ( c ) => 81 : ( c ) => ( d ) => 82 ;
// In Expressions
( ( arg ) => 90 ) instanceof Function ;
( ( arg = 1 ) => 91 ) instanceof Function ;
( ( arg ? ) => 92 ) instanceof Function ;
( ( arg : number ) => 93 ) instanceof Function ;
( ( arg : number = 1 ) => 94 ) instanceof Function ;
( ( arg ? : number ) => 95 ) instanceof Function ;
( ( ... arg : number [ ] ) => 96 ) instanceof Function ;
'' + ( arg ) => 100 ;
( ( arg ) => 0 ) + '' + ( arg ) => 101 ;
( ( arg = 1 ) => 0 ) + '' + ( arg = 2 ) => 102 ;
( ( arg ? ) => 0 ) + '' + ( arg ? ) => 103 ;
( ( arg : number ) => 0 ) + '' + ( arg : number ) => 104 ;
( ( arg : number = 1 ) => 0 ) + '' + ( arg : number = 2 ) => 105 ;
( ( arg ? : number = 1 ) => 0 ) + '' + ( arg ? : number = 2 ) => 106 ;
( ( ... arg : number [ ] ) => 0 ) + '' + ( ... arg : number [ ] ) => 107 ;
( ( arg1 , arg2 ? ) => 0 ) + '' + ( arg1 , arg2 ? ) => 108 ;
( ( arg1 , ... arg2 : number [ ] ) => 0 ) + '' + ( arg1 , ... arg2 : number [ ] ) => 108 ;
// Function Parameters
function foo ( ... arg : any [ ] ) { }
foo (
( a ) => 110 ,
( ( a ) => 111 ) ,
( a ) => {
return 112 ;
} ,
( a ? ) => 113 ,
( a , b ? ) => 114 ,
( a : number ) => 115 ,
( a : number = 0 ) => 116 ,
( a = 0 ) => 117 ,
( a ? : number = 0 ) => 118 ,
( a ? , b ? : number = 0 ) => 118 ,
( ... a : number [ ] ) => 119 ,
( a , b ? = 0 , ... c : number [ ] ) => 120 ,
( a ) => ( b ) => ( c ) => 121 ,
false ? ( a ) => 0 : ( b ) => 122
) ;

View File

@ -0,0 +1,112 @@
// valid
() => 1;
(arg) => 2;
arg => 2;
(arg = 1) => 3;
(arg?) => 4;
(arg: number) => 5;
(arg: number = 0) => 6;
(arg?: number) => 7;
(...arg: number[]) => 8;
(arg1, arg2) => 12;
(arg1 = 1, arg2 = 3) => 13;
(arg1?, arg2?) => 14;
(arg1: number, arg2: number) => 15;
(arg1: number = 0, arg2: number = 1) => 16;
(arg1?: number, arg2?: number) => 17;
(arg1, ...arg2: number[]) => 18;
(arg1, arg2?: number) => 19;
// in paren
(() => 21);
((arg) => 22);
((arg = 1) => 23);
((arg?) => 24);
((arg: number) => 25);
((arg: number = 0) => 26);
((arg?: number) => 27);
((...arg: number[]) => 28);
// in multiple paren
(((((arg) => { return 32; }))));
// in ternary exression
false ? () => 41 : null;
false ? (arg) => 42 : null;
false ? (arg = 1) => 43 : null;
false ? (arg?) => 44 : null;
false ? (arg: number) => 45 : null;
false ? (arg?: number) => 46 : null;
false ? (arg?: number = 0) => 47 : null;
false ? (...arg: number[]) => 48 : null;
// in ternary exression within paren
false ? (() => 51) : null;
false ? ((arg) => 52) : null;
false ? ((arg = 1) => 53) : null;
false ? ((arg?) => 54) : null;
false ? ((arg: number) => 55) : null;
false ? ((arg?: number) => 56) : null;
false ? ((arg?: number = 0) => 57) : null;
false ? ((...arg: number[]) => 58) : null;
// ternary exression's else clause
false ? null : () => 61;
false ? null : (arg) => 62;
false ? null : (arg = 1) => 63;
false ? null : (arg?) => 64;
false ? null : (arg: number) => 65;
false ? null : (arg?: number) => 66;
false ? null : (arg?: number = 0) => 67;
false ? null : (...arg: number[]) => 68;
// nested ternary expressions
(a?) => { return a; } ? (b?) => { return b; } : (c?) => { return c; };
//multiple levels
(a?) => { return a; } ? (b) => (c) => 81 : (c) => (d) => 82;
// In Expressions
((arg) => 90) instanceof Function;
((arg = 1) => 91) instanceof Function;
((arg?) => 92) instanceof Function;
((arg: number) => 93) instanceof Function;
((arg: number = 1) => 94) instanceof Function;
((arg?: number) => 95) instanceof Function;
((...arg: number[]) => 96) instanceof Function;
'' + (arg) => 100;
((arg) => 0) + '' + (arg) => 101;
((arg = 1) => 0) + '' + (arg = 2) => 102;
((arg?) => 0) + '' + (arg?) => 103;
((arg: number) => 0) + '' + (arg: number) => 104;
((arg: number = 1) => 0) + '' + (arg: number = 2) => 105;
((arg?: number = 1) => 0) + '' + (arg?: number = 2) => 106;
((...arg: number[]) => 0) + '' + (...arg: number[]) => 107;
((arg1, arg2?) => 0) + '' + (arg1, arg2?) => 108;
((arg1, ...arg2: number[]) => 0) + '' + (arg1, ...arg2: number[]) => 108;
// Function Parameters
function foo(...arg: any[]) { }
foo(
(a) => 110,
((a) => 111),
(a) => {
return 112;
},
(a?) => 113,
(a, b?) => 114,
(a: number) => 115,
(a: number = 0) => 116,
(a = 0) => 117,
(a?: number = 0) => 118,
(a?, b?: number = 0) => 118,
(...a: number[]) => 119,
(a, b? = 0, ...c: number[]) => 120,
(a) => (b) => (c) => 121,
false ? (a) => 0 : (b) => 122
);

View File

@ -0,0 +1,2 @@
if(false){debugger;}
if ( false ) { debugger ; }

Some files were not shown because too many files have changed in this diff Show More