Merge branch 'master' into constLet

This commit is contained in:
Sheetal Nandi 2014-11-20 21:06:08 -08:00
commit 28c41e869a
14 changed files with 1603 additions and 1418 deletions

1
.gitignore vendored
View File

@ -39,4 +39,5 @@ scripts/debug.bat
scripts/run.bat
scripts/word2md.js
scripts/ior.js
scripts/*.js.map
coverage/

View File

@ -82,6 +82,7 @@ module ts {
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
getDiagnostics,
getDeclarationDiagnostics,
getGlobalDiagnostics,
checkProgram,
invokeEmitter,
@ -999,6 +1000,7 @@ module ts {
// Type Reference or TypeAlias entity = Identifier
meaning = SymbolFlags.Type;
}
var firstIdentifier = getFirstIdentifier(entityName);
var symbol = resolveName(enclosingDeclaration, (<Identifier>firstIdentifier).text, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
@ -8544,6 +8546,12 @@ module ts {
return getSortedDiagnostics();
}
function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[] {
var resolver = createResolver();
checkSourceFile(targetSourceFile);
return ts.getDeclarationDiagnostics(program, resolver, targetSourceFile);
}
function getGlobalDiagnostics(): Diagnostic[] {
return filter(getSortedDiagnostics(), d => !d.file);
}
@ -9137,8 +9145,8 @@ module ts {
getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
}
function invokeEmitter(targetSourceFile?: SourceFile) {
var resolver: EmitResolver = {
function createResolver(): EmitResolver {
return {
getProgram: () => program,
getLocalNameOfContainer,
getExpressionNamePrefix,
@ -9157,6 +9165,10 @@ module ts {
isEntityNameVisible,
getConstantValue,
};
}
function invokeEmitter(targetSourceFile?: SourceFile) {
var resolver = createResolver();
checkProgram();
return emitFiles(resolver, targetSourceFile);
}

File diff suppressed because it is too large Load Diff

View File

@ -48,13 +48,17 @@ module ts {
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
}
export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string {
var text = sourceFile.text;
return text.substring(skipTrivia(text, node.pos), node.end);
}
export function getTextOfNodeFromSourceText(sourceText: string, node: Node): string {
return sourceText.substring(skipTrivia(sourceText, node.pos), node.end);
}
export function getTextOfNode(node: Node): string {
var text = getSourceFileOfNode(node).text;
return text.substring(skipTrivia(text, node.pos), node.end);
return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node);
}
// Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__'
@ -122,7 +126,7 @@ module ts {
}
export function isConstEnumDeclaration(node: Declaration): boolean {
return node.kind === SyntaxKind.EnumDeclaration && !!(node.flags & NodeFlags.Const);
return node.kind === SyntaxKind.EnumDeclaration && isConst(node);
}
export function isConst(node: Declaration): boolean {

View File

@ -731,6 +731,7 @@ module ts {
export interface TypeChecker {
getProgram(): Program;
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getDeclarationDiagnostics(sourceFile: SourceFile): Diagnostic[];
getGlobalDiagnostics(): Diagnostic[];
getNodeCount(): number;
getIdentifierCount(): number;

View File

@ -911,6 +911,8 @@ module ts {
getEmitOutput(fileName: string): EmitOutput;
getSourceFile(filename: string): SourceFile;
dispose(): void;
}
@ -1143,7 +1145,7 @@ module ts {
}
export interface Classifier {
getClassificationsForLine(text: string, lexState: EndOfLineState): ClassificationResult;
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
}
export interface DocumentRegistry {
@ -2063,8 +2065,12 @@ module ts {
localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages();
}
function getCanonicalFileName(filename: string) {
return useCaseSensitivefilenames ? filename : filename.toLowerCase();
}
function getSourceFile(filename: string): SourceFile {
return lookUp(sourceFilesByName, filename);
return lookUp(sourceFilesByName, getCanonicalFileName(filename));
}
function getFullTypeCheckChecker() {
@ -2160,7 +2166,7 @@ module ts {
var filename = oldSourceFiles[i].filename;
if (!hostCache.contains(filename) || changesInCompilationSettingsAffectSyntax) {
documentRegistry.releaseDocument(filename, oldSettings);
delete sourceFilesByName[filename];
delete sourceFilesByName[getCanonicalFileName(filename)];
}
}
}
@ -2203,7 +2209,7 @@ module ts {
}
// Remember the new sourceFile
sourceFilesByName[filename] = sourceFile;
sourceFilesByName[getCanonicalFileName(filename)] = sourceFile;
}
// Now create a new compiler
@ -2258,11 +2264,7 @@ module ts {
var allDiagnostics = checker.getDiagnostics(targetSourceFile);
if (compilerOptions.declaration) {
// If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface
// Get emitter-diagnostics requires calling TypeChecker.emitFiles so we have to define CompilerHost.writer which does nothing because emitFiles function has side effects defined by CompilerHost.writer
var savedWriter = writer;
writer = (filename: string, data: string, writeByteOrderMark: boolean) => { };
allDiagnostics = allDiagnostics.concat(checker.invokeEmitter(targetSourceFile).diagnostics);
writer = savedWriter;
allDiagnostics = allDiagnostics.concat(checker.getDeclarationDiagnostics(targetSourceFile));
}
return allDiagnostics
}
@ -5383,6 +5385,7 @@ module ts {
getFormattingEditsForDocument,
getFormattingEditsAfterKeystroke,
getEmitOutput,
getSourceFile: getCurrentSourceFile,
};
}
@ -5442,7 +5445,8 @@ module ts {
return true;
}
function getClassificationsForLine(text: string, lexState: EndOfLineState): ClassificationResult {
// 'classifyKeywordsInGenerics' should be 'true' when a syntactic classifier is not present.
function getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult {
var offset = 0;
var token = SyntaxKind.Unknown;
var lastNonTriviaToken = SyntaxKind.Unknown;
@ -5529,7 +5533,7 @@ module ts {
token === SyntaxKind.StringKeyword ||
token === SyntaxKind.NumberKeyword ||
token === SyntaxKind.BooleanKeyword) {
if (angleBracketStack > 0) {
if (angleBracketStack > 0 && !classifyKeywordsInGenerics) {
// If it looks like we're could be in something generic, don't classify this
// as a keyword. We may just get overwritten by the syntactic classifier,
// causing a noisy experience for the user.

View File

@ -161,7 +161,7 @@ module ts {
}
export interface ClassifierShim extends Shim {
getClassificationsForLine(text: string, lexState: EndOfLineState): string;
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): string;
}
export interface CoreServicesShim extends Shim {
@ -794,8 +794,8 @@ module ts {
}
/// COLORIZATION
public getClassificationsForLine(text: string, lexState: EndOfLineState): string {
var classification = this.classifier.getClassificationsForLine(text, lexState);
public getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): string {
var classification = this.classifier.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics);
var items = classification.entries;
var result = "";
for (var i = 0; i < items.length; i++) {

View File

@ -0,0 +1,29 @@
//// [tests/cases/compiler/declFileAliasUseBeforeDeclaration.ts] ////
//// [declFileAliasUseBeforeDeclaration_foo.ts]
export class Foo { }
//// [declFileAliasUseBeforeDeclaration_test.ts]
export function bar(a: foo.Foo) { }
import foo = require("declFileAliasUseBeforeDeclaration_foo");
//// [declFileAliasUseBeforeDeclaration_foo.js]
var Foo = (function () {
function Foo() {
}
return Foo;
})();
exports.Foo = Foo;
//// [declFileAliasUseBeforeDeclaration_test.js]
function bar(a) {
}
exports.bar = bar;
//// [declFileAliasUseBeforeDeclaration_foo.d.ts]
export declare class Foo {
}
//// [declFileAliasUseBeforeDeclaration_test.d.ts]
export declare function bar(a: foo.Foo): void;
import foo = require("declFileAliasUseBeforeDeclaration_foo");

View File

@ -0,0 +1,15 @@
=== tests/cases/compiler/declFileAliasUseBeforeDeclaration_test.ts ===
export function bar(a: foo.Foo) { }
>bar : (a: foo.Foo) => void
>a : foo.Foo
>foo : unknown
>Foo : foo.Foo
import foo = require("declFileAliasUseBeforeDeclaration_foo");
>foo : typeof foo
=== tests/cases/compiler/declFileAliasUseBeforeDeclaration_foo.ts ===
export class Foo { }
>Foo : Foo

View File

@ -0,0 +1,25 @@
//// [declFileAliasUseBeforeDeclaration2.ts]
declare module "test" {
module A {
class C {
}
}
class B extends E {
}
import E = A.C;
}
//// [declFileAliasUseBeforeDeclaration2.js]
//// [declFileAliasUseBeforeDeclaration2.d.ts]
declare module "test" {
module A {
class C {
}
}
class B extends E {
}
import E = A.C;
}

View File

@ -0,0 +1,19 @@
=== tests/cases/compiler/declFileAliasUseBeforeDeclaration2.ts ===
declare module "test" {
module A {
>A : typeof A
class C {
>C : C
}
}
class B extends E {
>B : B
>E : E
}
import E = A.C;
>E : typeof E
>A : typeof A
>C : E
}

View File

@ -0,0 +1,9 @@
//@module: commonjs
//@declaration: true
// @Filename: declFileAliasUseBeforeDeclaration_foo.ts
export class Foo { }
// @Filename: declFileAliasUseBeforeDeclaration_test.ts
export function bar(a: foo.Foo) { }
import foo = require("declFileAliasUseBeforeDeclaration_foo");

View File

@ -0,0 +1,12 @@
//@module: commonjs
//@declaration: true
declare module "test" {
module A {
class C {
}
}
class B extends E {
}
import E = A.C;
}

View File

@ -0,0 +1,19 @@
/// <reference path="fourslash.ts" />
// @declaration: true
// @out: true
// @Filename: inputFile1.ts
//// module m {
//// export class C implements I { }
//// interface I { }
//// } /*1*/
// @Filename: input2.ts
//// var x = "hello world"; /*2*/
goTo.marker("1");
verify.numberOfErrorsInCurrentFile(1);
goTo.marker("2");
verify.numberOfErrorsInCurrentFile(0);