Merge branch 'master' of https://github.com/Microsoft/TypeScript into deeplyNestedTypeArgumentInference

This commit is contained in:
Jason Freeman 2015-06-12 13:58:09 -07:00
commit aeda84704c
46 changed files with 132 additions and 74 deletions

View file

@ -55,7 +55,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
'// <auto-generated />\r\n' + '// <auto-generated />\r\n' +
'/// <reference path="types.ts" />\r\n' + '/// <reference path="types.ts" />\r\n' +
'/* @internal */\r\n' + '/* @internal */\r\n' +
'module ts {\r\n' + 'namespace ts {\r\n' +
' export var Diagnostics = {\r\n'; ' export var Diagnostics = {\r\n';
var names = Utilities.getObjectKeys(messageTable); var names = Utilities.getObjectKeys(messageTable);
for (var i = 0; i < names.length; i++) { for (var i = 0; i < names.length; i++) {

View file

@ -1,7 +1,7 @@
/// <reference path="parser.ts"/> /// <reference path="parser.ts"/>
/* @internal */ /* @internal */
module ts { namespace ts {
export let bindTime = 0; export let bindTime = 0;
export const enum ModuleInstanceState { export const enum ModuleInstanceState {
@ -90,10 +90,12 @@ module ts {
let lastContainer: Node; let lastContainer: Node;
let symbolCount = 0; let symbolCount = 0;
let Symbol = objectAllocator.getSymbolConstructor(); let Symbol = objectAllocator.getSymbolConstructor();
let classifiableNames: Map<string> = {};
if (!file.locals) { if (!file.locals) {
bind(file); bind(file);
file.symbolCount = symbolCount; file.symbolCount = symbolCount;
file.classifiableNames = classifiableNames;
} }
return; return;
@ -194,6 +196,11 @@ module ts {
symbol = hasProperty(symbolTable, name) symbol = hasProperty(symbolTable, name)
? symbolTable[name] ? symbolTable[name]
: (symbolTable[name] = createSymbol(SymbolFlags.None, name)); : (symbolTable[name] = createSymbol(SymbolFlags.None, name));
if (name && (includes & SymbolFlags.Classifiable)) {
classifiableNames[name] = name;
}
if (symbol.flags & excludes) { if (symbol.flags & excludes) {
if (node.name) { if (node.name) {
node.name.parent = node; node.name.parent = node;

View file

@ -1,7 +1,7 @@
/// <reference path="binder.ts"/> /// <reference path="binder.ts"/>
/* @internal */ /* @internal */
module ts { namespace ts {
let nextSymbolId = 1; let nextSymbolId = 1;
let nextNodeId = 1; let nextNodeId = 1;
let nextMergeId = 1; let nextMergeId = 1;

View file

@ -3,7 +3,7 @@
/// <reference path="core.ts"/> /// <reference path="core.ts"/>
/// <reference path="scanner.ts"/> /// <reference path="scanner.ts"/>
module ts { namespace ts {
/* @internal */ /* @internal */
export var optionDeclarations: CommandLineOption[] = [ export var optionDeclarations: CommandLineOption[] = [
{ {

View file

@ -1,7 +1,7 @@
/// <reference path="types.ts"/> /// <reference path="types.ts"/>
/* @internal */ /* @internal */
module ts { namespace ts {
// Ternary values are defined such that // Ternary values are defined such that
// x & y is False if either x or y is False. // x & y is False if either x or y is False.
// x & y is Maybe if either x or y is Maybe, but neither x or y is False. // x & y is Maybe if either x or y is Maybe, but neither x or y is False.

View file

@ -1,7 +1,7 @@
/// <reference path="checker.ts"/> /// <reference path="checker.ts"/>
/* @internal */ /* @internal */
module ts { namespace ts {
interface ModuleElementDeclarationEmitInfo { interface ModuleElementDeclarationEmitInfo {
node: Node; node: Node;
outputPos: number; outputPos: number;

View file

@ -1,7 +1,7 @@
// <auto-generated /> // <auto-generated />
/// <reference path="types.ts" /> /// <reference path="types.ts" />
/* @internal */ /* @internal */
module ts { namespace ts {
export var Diagnostics = { export var Diagnostics = {
Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." }, Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." },
Identifier_expected: { code: 1003, category: DiagnosticCategory.Error, key: "Identifier expected." }, Identifier_expected: { code: 1003, category: DiagnosticCategory.Error, key: "Identifier expected." },

View file

@ -2,7 +2,7 @@
/// <reference path="declarationEmitter.ts"/> /// <reference path="declarationEmitter.ts"/>
/* @internal */ /* @internal */
module ts { namespace ts {
export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) { export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) {
return isExternalModule(sourceFile) || isDeclarationFile(sourceFile); return isExternalModule(sourceFile) || isDeclarationFile(sourceFile);
} }

View file

@ -1,7 +1,7 @@
/// <reference path="scanner.ts"/> /// <reference path="scanner.ts"/>
/// <reference path="utilities.ts"/> /// <reference path="utilities.ts"/>
module ts { namespace ts {
let nodeConstructors = new Array<new () => Node>(SyntaxKind.Count); let nodeConstructors = new Array<new () => Node>(SyntaxKind.Count);
/* @internal */ export let parseTime = 0; /* @internal */ export let parseTime = 0;

View file

@ -1,7 +1,7 @@
/// <reference path="sys.ts" /> /// <reference path="sys.ts" />
/// <reference path="emitter.ts" /> /// <reference path="emitter.ts" />
module ts { namespace ts {
/* @internal */ export let programTime = 0; /* @internal */ export let programTime = 0;
/* @internal */ export let emitTime = 0; /* @internal */ export let emitTime = 0;
/* @internal */ export let ioReadTime = 0; /* @internal */ export let ioReadTime = 0;
@ -148,6 +148,7 @@ module ts {
let commonSourceDirectory: string; let commonSourceDirectory: string;
let diagnosticsProducingTypeChecker: TypeChecker; let diagnosticsProducingTypeChecker: TypeChecker;
let noDiagnosticsTypeChecker: TypeChecker; let noDiagnosticsTypeChecker: TypeChecker;
let classifiableNames: Map<string>;
let start = new Date().getTime(); let start = new Date().getTime();
@ -172,6 +173,7 @@ module ts {
getDeclarationDiagnostics, getDeclarationDiagnostics,
getCompilerOptionsDiagnostics, getCompilerOptionsDiagnostics,
getTypeChecker, getTypeChecker,
getClassifiableNames,
getDiagnosticsProducingTypeChecker, getDiagnosticsProducingTypeChecker,
getCommonSourceDirectory: () => commonSourceDirectory, getCommonSourceDirectory: () => commonSourceDirectory,
emit, emit,
@ -183,6 +185,20 @@ module ts {
}; };
return program; return program;
function getClassifiableNames() {
if (!classifiableNames) {
// Initialize a checker so that all our files are bound.
getTypeChecker();
classifiableNames = {};
for (let sourceFile of files) {
copyMap(sourceFile.classifiableNames, classifiableNames);
}
}
return classifiableNames;
}
function getEmitHost(writeFileCallback?: WriteFileCallback): EmitHost { function getEmitHost(writeFileCallback?: WriteFileCallback): EmitHost {
return { return {
getCanonicalFileName: fileName => host.getCanonicalFileName(fileName), getCanonicalFileName: fileName => host.getCanonicalFileName(fileName),
@ -335,14 +351,17 @@ module ts {
} }
} }
else { else {
if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { var nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd);
diagnostic = Diagnostics.File_0_not_found; if (!nonTsFile) {
diagnosticArgument = [fileName]; if (options.allowNonTsExtensions) {
} diagnostic = Diagnostics.File_0_not_found;
else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd))) { diagnosticArgument = [fileName];
diagnostic = Diagnostics.File_0_not_found; }
fileName += ".ts"; else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd))) {
diagnosticArgument = [fileName]; diagnostic = Diagnostics.File_0_not_found;
fileName += ".ts";
diagnosticArgument = [fileName];
}
} }
} }

View file

@ -1,7 +1,7 @@
/// <reference path="core.ts"/> /// <reference path="core.ts"/>
/// <reference path="diagnosticInformationMap.generated.ts"/> /// <reference path="diagnosticInformationMap.generated.ts"/>
module ts { namespace ts {
export interface ErrorCallback { export interface ErrorCallback {
(message: DiagnosticMessage, length: number): void; (message: DiagnosticMessage, length: number): void;
} }

View file

@ -1,6 +1,6 @@
/// <reference path="core.ts"/> /// <reference path="core.ts"/>
module ts { namespace ts {
export interface System { export interface System {
args: string[]; args: string[];
newLine: string; newLine: string;

View file

@ -1,7 +1,7 @@
/// <reference path="program.ts"/> /// <reference path="program.ts"/>
/// <reference path="commandLineParser.ts"/> /// <reference path="commandLineParser.ts"/>
module ts { namespace ts {
export interface SourceFile { export interface SourceFile {
fileWatcher: FileWatcher; fileWatcher: FileWatcher;
} }

View file

@ -1,4 +1,4 @@
module ts { namespace ts {
export interface Map<T> { export interface Map<T> {
[index: string]: T; [index: string]: T;
} }
@ -1172,6 +1172,8 @@ module ts {
// Stores a line map for the file. // Stores a line map for the file.
// This field should never be used directly to obtain line map, use getLineMap function instead. // This field should never be used directly to obtain line map, use getLineMap function instead.
/* @internal */ lineMap: number[]; /* @internal */ lineMap: number[];
/* @internal */ classifiableNames?: Map<string>;
} }
export interface ScriptReferenceHost { export interface ScriptReferenceHost {
@ -1223,6 +1225,8 @@ module ts {
// language service). // language service).
/* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker; /* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker;
/* @internal */ getClassifiableNames(): Map<string>;
/* @internal */ getNodeCount(): number; /* @internal */ getNodeCount(): number;
/* @internal */ getIdentifierCount(): number; /* @internal */ getIdentifierCount(): number;
/* @internal */ getSymbolCount(): number; /* @internal */ getSymbolCount(): number;
@ -1519,6 +1523,11 @@ module ts {
PropertyOrAccessor = Property | Accessor, PropertyOrAccessor = Property | Accessor,
Export = ExportNamespace | ExportType | ExportValue, Export = ExportNamespace | ExportType | ExportValue,
/* @internal */
// The set of things we consider semantically classifiable. Used to speed up the LS during
// classification.
Classifiable = Class | Enum | TypeAlias | Interface | TypeParameter | Module,
} }
export interface Symbol { export interface Symbol {

View file

@ -1,7 +1,7 @@
/// <reference path="binder.ts" /> /// <reference path="binder.ts" />
/* @internal */ /* @internal */
module ts { namespace ts {
export interface ReferencePathMatchResult { export interface ReferencePathMatchResult {
fileReference?: FileReference fileReference?: FileReference
diagnosticMessage?: DiagnosticMessage diagnosticMessage?: DiagnosticMessage
@ -2002,7 +2002,7 @@ module ts {
} }
} }
module ts { namespace ts {
export function getDefaultLibFileName(options: CompilerOptions): string { export function getDefaultLibFileName(options: CompilerOptions): string {
return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts"; return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts";
} }

View file

@ -1,6 +1,6 @@
/// <reference path="session.ts" /> /// <reference path="session.ts" />
module ts.server { namespace ts.server {
export interface SessionClientHost extends LanguageServiceHost { export interface SessionClientHost extends LanguageServiceHost {
writeMessage(message: string): void; writeMessage(message: string): void;

View file

@ -4,7 +4,7 @@
/// <reference path="session.ts" /> /// <reference path="session.ts" />
/// <reference path="node.d.ts" /> /// <reference path="node.d.ts" />
module ts.server { namespace ts.server {
export interface Logger { export interface Logger {
close(): void; close(): void;
isVerbose(): boolean; isVerbose(): boolean;

View file

@ -1,7 +1,7 @@
/** /**
* Declaration module describing the TypeScript Server protocol * Declaration module describing the TypeScript Server protocol
*/ */
declare module ts.server.protocol { declare namespace ts.server.protocol {
/** /**
* A TypeScript Server message * A TypeScript Server message
*/ */

View file

@ -1,7 +1,7 @@
/// <reference path="node.d.ts" /> /// <reference path="node.d.ts" />
/// <reference path="session.ts" /> /// <reference path="session.ts" />
module ts.server { namespace ts.server {
var nodeproto: typeof NodeJS._debugger = require('_debugger'); var nodeproto: typeof NodeJS._debugger = require('_debugger');
var readline: NodeJS.ReadLine = require('readline'); var readline: NodeJS.ReadLine = require('readline');
var path: NodeJS.Path = require('path'); var path: NodeJS.Path = require('path');

View file

@ -4,7 +4,7 @@
/// <reference path="protocol.d.ts" /> /// <reference path="protocol.d.ts" />
/// <reference path="editorServices.ts" /> /// <reference path="editorServices.ts" />
module ts.server { namespace ts.server {
var spaceCache:string[] = []; var spaceCache:string[] = [];
interface StackTraceError extends Error { interface StackTraceError extends Error {

View file

@ -4,7 +4,7 @@
/// <reference path='services.ts' /> /// <reference path='services.ts' />
/* @internal */ /* @internal */
module ts.BreakpointResolver { namespace ts.BreakpointResolver {
/** /**
* Get the breakpoint span in given sourceFile * Get the breakpoint span in given sourceFile
*/ */

View file

@ -4,7 +4,7 @@
///<reference path='references.ts' /> ///<reference path='references.ts' />
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export interface TextRangeWithKind extends TextRange { export interface TextRangeWithKind extends TextRange {
kind: SyntaxKind; kind: SyntaxKind;

View file

@ -1,7 +1,7 @@
/// <reference path="references.ts"/> /// <reference path="references.ts"/>
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export class FormattingContext { export class FormattingContext {
public currentTokenSpan: TextRangeWithKind; public currentTokenSpan: TextRangeWithKind;
public nextTokenSpan: TextRangeWithKind; public nextTokenSpan: TextRangeWithKind;

View file

@ -1,7 +1,7 @@
/// <reference path="references.ts"/> /// <reference path="references.ts"/>
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export const enum FormattingRequestKind { export const enum FormattingRequestKind {
FormatDocument, FormatDocument,
FormatSelection, FormatSelection,

View file

@ -2,7 +2,7 @@
/// <reference path="..\..\compiler\scanner.ts"/> /// <reference path="..\..\compiler\scanner.ts"/>
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
let scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false); let scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false);
export interface FormattingScanner { export interface FormattingScanner {
@ -224,7 +224,7 @@ module ts.formatting {
} }
function isOnToken(): boolean { function isOnToken(): boolean {
let current = (lastTokenInfo && lastTokenInfo.token.kind) || scanner.getToken(); let current = (lastTokenInfo && lastTokenInfo.token.kind) || scanner.getToken();
let startPos = (lastTokenInfo && lastTokenInfo.token.pos) || scanner.getStartPos(); let startPos = (lastTokenInfo && lastTokenInfo.token.pos) || scanner.getStartPos();
return startPos < endPos && current !== SyntaxKind.EndOfFileToken && !isTrivia(current); return startPos < endPos && current !== SyntaxKind.EndOfFileToken && !isTrivia(current);
} }

View file

@ -1,7 +1,7 @@
///<reference path='references.ts' /> ///<reference path='references.ts' />
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export class Rule { export class Rule {
constructor( constructor(
public Descriptor: RuleDescriptor, public Descriptor: RuleDescriptor,

View file

@ -1,7 +1,7 @@
///<reference path='references.ts' /> ///<reference path='references.ts' />
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export const enum RuleAction { export const enum RuleAction {
Ignore = 0x00000001, Ignore = 0x00000001,
Space = 0x00000002, Space = 0x00000002,

View file

@ -1,7 +1,7 @@
///<reference path='references.ts' /> ///<reference path='references.ts' />
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export class RuleDescriptor { export class RuleDescriptor {
constructor(public LeftTokenRange: Shared.TokenRange, public RightTokenRange: Shared.TokenRange) { constructor(public LeftTokenRange: Shared.TokenRange, public RightTokenRange: Shared.TokenRange) {
} }

View file

@ -2,7 +2,7 @@
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export const enum RuleFlags { export const enum RuleFlags {
None, None,
CanDeleteNewLines CanDeleteNewLines

View file

@ -1,7 +1,7 @@
///<reference path='references.ts' /> ///<reference path='references.ts' />
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export class RuleOperation { export class RuleOperation {
public Context: RuleOperationContext; public Context: RuleOperationContext;
public Action: RuleAction; public Action: RuleAction;

View file

@ -1,7 +1,7 @@
///<reference path='references.ts' /> ///<reference path='references.ts' />
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export class RuleOperationContext { export class RuleOperationContext {
private customContextChecks: { (context: FormattingContext): boolean; }[]; private customContextChecks: { (context: FormattingContext): boolean; }[];

View file

@ -1,7 +1,7 @@
///<reference path='references.ts' /> ///<reference path='references.ts' />
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export class Rules { export class Rules {
public getRuleName(rule: Rule) { public getRuleName(rule: Rule) {
let o: ts.Map<any> = <any>this; let o: ts.Map<any> = <any>this;
@ -193,7 +193,7 @@ module ts.formatting {
// Insert space after function keyword for anonymous functions // Insert space after function keyword for anonymous functions
public SpaceAfterAnonymousFunctionKeyword: Rule; public SpaceAfterAnonymousFunctionKeyword: Rule;
public NoSpaceAfterAnonymousFunctionKeyword: Rule; public NoSpaceAfterAnonymousFunctionKeyword: Rule;
// Insert space after @ in decorator // Insert space after @ in decorator
public SpaceBeforeAt: Rule; public SpaceBeforeAt: Rule;
public NoSpaceAfterAt: Rule; public NoSpaceAfterAt: Rule;
@ -470,8 +470,9 @@ module ts.formatting {
switch (context.contextNode.kind) { switch (context.contextNode.kind) {
case SyntaxKind.BinaryExpression: case SyntaxKind.BinaryExpression:
case SyntaxKind.ConditionalExpression: case SyntaxKind.ConditionalExpression:
case SyntaxKind.TypePredicate:
return true; return true;
// equals in binding elements: function foo([[x, y] = [1, 2]]) // equals in binding elements: function foo([[x, y] = [1, 2]])
case SyntaxKind.BindingElement: case SyntaxKind.BindingElement:
// equals in type X = ... // equals in type X = ...

View file

@ -1,7 +1,7 @@
///<reference path='references.ts' /> ///<reference path='references.ts' />
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export class RulesMap { export class RulesMap {
public map: RulesBucket[]; public map: RulesBucket[];
public mapRowLength: number; public mapRowLength: number;

View file

@ -1,7 +1,7 @@
/// <reference path="references.ts"/> /// <reference path="references.ts"/>
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export class RulesProvider { export class RulesProvider {
private globalRules: Rules; private globalRules: Rules;
private options: ts.FormatCodeOptions; private options: ts.FormatCodeOptions;

View file

@ -1,7 +1,7 @@
///<reference path='..\services.ts' /> ///<reference path='..\services.ts' />
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export module SmartIndenter { export module SmartIndenter {
const enum Value { const enum Value {

View file

@ -1,7 +1,7 @@
///<reference path='references.ts' /> ///<reference path='references.ts' />
/* @internal */ /* @internal */
module ts.formatting { namespace ts.formatting {
export module Shared { export module Shared {
export interface ITokenAccess { export interface ITokenAccess {
GetTokens(): SyntaxKind[]; GetTokens(): SyntaxKind[];
@ -112,7 +112,7 @@ module ts.formatting {
static AnyIncludingMultilineComments = TokenRange.FromTokens(TokenRange.Any.GetTokens().concat([SyntaxKind.MultiLineCommentTrivia])); static AnyIncludingMultilineComments = TokenRange.FromTokens(TokenRange.Any.GetTokens().concat([SyntaxKind.MultiLineCommentTrivia]));
static Keywords = TokenRange.FromRange(SyntaxKind.FirstKeyword, SyntaxKind.LastKeyword); static Keywords = TokenRange.FromRange(SyntaxKind.FirstKeyword, SyntaxKind.LastKeyword);
static BinaryOperators = TokenRange.FromRange(SyntaxKind.FirstBinaryOperator, SyntaxKind.LastBinaryOperator); static BinaryOperators = TokenRange.FromRange(SyntaxKind.FirstBinaryOperator, SyntaxKind.LastBinaryOperator);
static BinaryKeywordOperators = TokenRange.FromTokens([SyntaxKind.InKeyword, SyntaxKind.InstanceOfKeyword, SyntaxKind.OfKeyword]); static BinaryKeywordOperators = TokenRange.FromTokens([SyntaxKind.InKeyword, SyntaxKind.InstanceOfKeyword, SyntaxKind.OfKeyword, SyntaxKind.IsKeyword]);
static UnaryPrefixOperators = TokenRange.FromTokens([SyntaxKind.PlusPlusToken, SyntaxKind.MinusMinusToken, SyntaxKind.TildeToken, SyntaxKind.ExclamationToken]); static UnaryPrefixOperators = TokenRange.FromTokens([SyntaxKind.PlusPlusToken, SyntaxKind.MinusMinusToken, SyntaxKind.TildeToken, SyntaxKind.ExclamationToken]);
static UnaryPrefixExpressions = TokenRange.FromTokens([SyntaxKind.NumericLiteral, SyntaxKind.Identifier, SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, SyntaxKind.OpenBraceToken, SyntaxKind.ThisKeyword, SyntaxKind.NewKeyword]); static UnaryPrefixExpressions = TokenRange.FromTokens([SyntaxKind.NumericLiteral, SyntaxKind.Identifier, SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, SyntaxKind.OpenBraceToken, SyntaxKind.ThisKeyword, SyntaxKind.NewKeyword]);
static UnaryPreincrementExpressions = TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.OpenParenToken, SyntaxKind.ThisKeyword, SyntaxKind.NewKeyword]); static UnaryPreincrementExpressions = TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.OpenParenToken, SyntaxKind.ThisKeyword, SyntaxKind.NewKeyword]);

View file

@ -1,5 +1,5 @@
/* @internal */ /* @internal */
module ts.NavigateTo { namespace ts.NavigateTo {
type RawNavigateToItem = { name: string; fileName: string; matchKind: PatternMatchKind; isCaseSensitive: boolean; declaration: Declaration }; type RawNavigateToItem = { name: string; fileName: string; matchKind: PatternMatchKind; isCaseSensitive: boolean; declaration: Declaration };
export function getNavigateToItems(program: Program, cancellationToken: CancellationTokenObject, searchValue: string, maxResultCount: number): NavigateToItem[] { export function getNavigateToItems(program: Program, cancellationToken: CancellationTokenObject, searchValue: string, maxResultCount: number): NavigateToItem[] {

View file

@ -1,7 +1,7 @@
/// <reference path='services.ts' /> /// <reference path='services.ts' />
/* @internal */ /* @internal */
module ts.NavigationBar { namespace ts.NavigationBar {
export function getNavigationBarItems(sourceFile: SourceFile): ts.NavigationBarItem[] { export function getNavigationBarItems(sourceFile: SourceFile): ts.NavigationBarItem[] {
// If the source file has any child items, then it included in the tree // If the source file has any child items, then it included in the tree
// and takes lexical ownership of all other top-level items. // and takes lexical ownership of all other top-level items.

View file

@ -1,5 +1,5 @@
/* @internal */ /* @internal */
module ts { namespace ts {
export module OutliningElementsCollector { export module OutliningElementsCollector {
export function collectElements(sourceFile: SourceFile): OutliningSpan[] { export function collectElements(sourceFile: SourceFile): OutliningSpan[] {
let elements: OutliningSpan[] = []; let elements: OutliningSpan[] = [];

View file

@ -1,5 +1,5 @@
/* @internal */ /* @internal */
module ts { namespace ts {
// Note(cyrusn): this enum is ordered from strongest match type to weakest match type. // Note(cyrusn): this enum is ordered from strongest match type to weakest match type.
export enum PatternMatchKind { export enum PatternMatchKind {
exact, exact,

View file

@ -10,7 +10,7 @@
/// <reference path='formatting\formatting.ts' /> /// <reference path='formatting\formatting.ts' />
/// <reference path='formatting\smartIndenter.ts' /> /// <reference path='formatting\smartIndenter.ts' />
module ts { namespace ts {
/** The version of the language service API */ /** The version of the language service API */
export let servicesVersion = "0.4" export let servicesVersion = "0.4"
@ -5992,6 +5992,7 @@ module ts {
let typeChecker = program.getTypeChecker(); let typeChecker = program.getTypeChecker();
let result: number[] = []; let result: number[] = [];
let classifiableNames = program.getClassifiableNames();
processNode(sourceFile); processNode(sourceFile);
return { spans: result, endOfLineState: EndOfLineState.None }; return { spans: result, endOfLineState: EndOfLineState.None };
@ -6004,6 +6005,9 @@ module ts {
function classifySymbol(symbol: Symbol, meaningAtPosition: SemanticMeaning): ClassificationType { function classifySymbol(symbol: Symbol, meaningAtPosition: SemanticMeaning): ClassificationType {
let flags = symbol.getFlags(); let flags = symbol.getFlags();
if ((flags & SymbolFlags.Classifiable) === SymbolFlags.None) {
return;
}
if (flags & SymbolFlags.Class) { if (flags & SymbolFlags.Class) {
return ClassificationType.className; return ClassificationType.className;
@ -6048,11 +6052,18 @@ module ts {
// Only walk into nodes that intersect the requested span. // Only walk into nodes that intersect the requested span.
if (node && textSpanIntersectsWith(span, node.getFullStart(), node.getFullWidth())) { if (node && textSpanIntersectsWith(span, node.getFullStart(), node.getFullWidth())) {
if (node.kind === SyntaxKind.Identifier && !nodeIsMissing(node)) { if (node.kind === SyntaxKind.Identifier && !nodeIsMissing(node)) {
let symbol = typeChecker.getSymbolAtLocation(node); let identifier = <Identifier>node;
if (symbol) {
let type = classifySymbol(symbol, getMeaningFromLocation(node)); // Only bother calling into the typechecker if this is an identifier that
if (type) { // could possibly resolve to a type name. This makes classification run
pushClassification(node.getStart(), node.getWidth(), type); // in a third of the time it would normally take.
if (classifiableNames[identifier.text]) {
let symbol = typeChecker.getSymbolAtLocation(node);
if (symbol) {
let type = classifySymbol(symbol, getMeaningFromLocation(node));
if (type) {
pushClassification(node.getStart(), node.getWidth(), type);
}
} }
} }
} }

View file

@ -19,7 +19,7 @@
var debugObjectHost = (<any>this); var debugObjectHost = (<any>this);
/* @internal */ /* @internal */
module ts { namespace ts {
export interface ScriptSnapshotShim { export interface ScriptSnapshotShim {
/** Gets a portion of the script snapshot specified by [start, end). */ /** Gets a portion of the script snapshot specified by [start, end). */
getText(start: number, end: number): string; getText(start: number, end: number): string;

View file

@ -1,6 +1,6 @@
///<reference path='services.ts' /> ///<reference path='services.ts' />
/* @internal */ /* @internal */
module ts.SignatureHelp { namespace ts.SignatureHelp {
// A partially written generic type expression is not guaranteed to have the correct syntax tree. the expression could be parsed as less than/greater than expression or a comma expression // A partially written generic type expression is not guaranteed to have the correct syntax tree. the expression could be parsed as less than/greater than expression or a comma expression
// or some other combination depending on what the user has typed so far. For the purposes of signature help we need to consider any location after "<" as a possible generic type reference. // or some other combination depending on what the user has typed so far. For the purposes of signature help we need to consider any location after "<" as a possible generic type reference.

View file

@ -1,6 +1,6 @@
// These utilities are common to multiple language service features. // These utilities are common to multiple language service features.
/* @internal */ /* @internal */
module ts { namespace ts {
export interface ListItemInfo { export interface ListItemInfo {
listItemIndex: number; listItemIndex: number;
list: Node; list: Node;
@ -502,7 +502,7 @@ module ts {
// Display-part writer helpers // Display-part writer helpers
/* @internal */ /* @internal */
module ts { namespace ts {
export function isFirstDeclarationOfSymbolParameter(symbol: Symbol) { export function isFirstDeclarationOfSymbolParameter(symbol: Symbol) {
return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === SyntaxKind.Parameter; return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === SyntaxKind.Parameter;
} }

View file

@ -0,0 +1,7 @@
/// <reference path='fourslash.ts' />
//// /**/function bar(a: A): a is B {}
goTo.marker();
format.document();
verify.currentLineContentIs("function bar(a: A): a is B { }");

View file

@ -3,9 +3,9 @@
module ts { module ts {
describe("Transpile", () => { describe("Transpile", () => {
function runTest(input: string, compilerOptions: ts.CompilerOptions = {}, moduleName?: string, expectedOutput?: string, expectedDiagnosticCodes: number[] = []): void { function runTest(input: string, compilerOptions: ts.CompilerOptions = {}, fileName?: string, moduleName?: string, expectedOutput?: string, expectedDiagnosticCodes: number[] = []): void {
let diagnostics: Diagnostic[] = []; let diagnostics: Diagnostic[] = [];
let result = transpile(input, compilerOptions, "file.ts", diagnostics, moduleName); let result = transpile(input, compilerOptions, fileName || "file.ts", diagnostics, moduleName);
for (let i = 0; i < expectedDiagnosticCodes.length; i++) { for (let i = 0; i < expectedDiagnosticCodes.length; i++) {
assert.equal(expectedDiagnosticCodes[i], diagnostics[i] && diagnostics[i].code, `Could not find expeced diagnostic.`); assert.equal(expectedDiagnosticCodes[i], diagnostics[i] && diagnostics[i].code, `Could not find expeced diagnostic.`);
@ -19,41 +19,41 @@ module ts {
it("Generates correct compilerOptions diagnostics", () => { it("Generates correct compilerOptions diagnostics", () => {
// Expecting 5047: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." // Expecting 5047: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher."
runTest(`var x = 0;`, {}, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [5047]); runTest(`var x = 0;`, {}, /*fileName*/ undefined, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [5047]);
}); });
it("Generates no diagnostics with valid inputs", () => { it("Generates no diagnostics with valid inputs", () => {
// No errors // No errors
runTest(`var x = 0;`, { module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); runTest(`var x = 0;`, { module: ModuleKind.CommonJS }, /*fileName*/ undefined, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
}); });
it("Generates no diagnostics for missing file references", () => { it("Generates no diagnostics for missing file references", () => {
runTest(`/// <reference path="file2.ts" /> runTest(`/// <reference path="file2.ts" />
var x = 0;`, var x = 0;`,
{ module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); { module: ModuleKind.CommonJS }, /*fileName*/ undefined, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
}); });
it("Generates no diagnostics for missing module imports", () => { it("Generates no diagnostics for missing module imports", () => {
runTest(`import {a} from "module2";`, runTest(`import {a} from "module2";`,
{ module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); { module: ModuleKind.CommonJS }, /*fileName*/ undefined,/*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
}); });
it("Generates expected syntactic diagnostics", () => { it("Generates expected syntactic diagnostics", () => {
runTest(`a b`, runTest(`a b`,
{ module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [1005]); /// 1005: ';' Expected { module: ModuleKind.CommonJS }, /*fileName*/ undefined, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [1005]); /// 1005: ';' Expected
}); });
it("Does not generate semantic diagnostics", () => { it("Does not generate semantic diagnostics", () => {
runTest(`var x: string = 0;`, runTest(`var x: string = 0;`,
{ module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); { module: ModuleKind.CommonJS }, /*fileName*/ undefined, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
}); });
it("Generates module output", () => { it("Generates module output", () => {
runTest(`var x = 0;`, { module: ModuleKind.AMD }, /*moduleName*/undefined, `define(["require", "exports"], function (require, exports) {\r\n var x = 0;\r\n});\r\n`); runTest(`var x = 0;`, { module: ModuleKind.AMD }, /*fileName*/ undefined, /*moduleName*/undefined, `define(["require", "exports"], function (require, exports) {\r\n var x = 0;\r\n});\r\n`);
}); });
it("Uses correct newLine character", () => { it("Uses correct newLine character", () => {
runTest(`var x = 0;`, { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed }, /*moduleName*/undefined, `var x = 0;\n`, /*expectedDiagnosticCodes*/ []); runTest(`var x = 0;`, { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed }, /*fileName*/ undefined, /*moduleName*/undefined, `var x = 0;\n`, /*expectedDiagnosticCodes*/ []);
}); });
it("Sets module name", () => { it("Sets module name", () => {
@ -66,7 +66,11 @@ var x = 0;`,
` }\n` + ` }\n` +
` }\n` + ` }\n` +
`});\n`; `});\n`;
runTest("var x = 1;", { module: ModuleKind.System, newLine: NewLineKind.LineFeed }, "NamedModule", output) runTest("var x = 1;", { module: ModuleKind.System, newLine: NewLineKind.LineFeed }, /*fileName*/ undefined, "NamedModule", output)
}); });
it("No extra errors for file without extension", () => {
runTest(`var x = 0;`, { module: ModuleKind.CommonJS }, "file", /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/[]);
});
}); });
} }