mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 01:34:55 -06:00
Merge branch 'master' into DtsExports_all
This commit is contained in:
commit
e9ea336771
2
Jakefile
2
Jakefile
@ -252,6 +252,8 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
|
||||
options += " --stripInternal"
|
||||
}
|
||||
|
||||
options += " --cacheDownlevelForOfLength --preserveNewLines";
|
||||
|
||||
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
|
||||
cmd = cmd + sources.join(" ");
|
||||
console.log(cmd + "\n");
|
||||
|
||||
1431
bin/tsc.js
1431
bin/tsc.js
File diff suppressed because it is too large
Load Diff
10997
bin/tsserver.js
10997
bin/tsserver.js
File diff suppressed because one or more lines are too long
8
bin/typescript.d.ts
vendored
8
bin/typescript.d.ts
vendored
@ -1200,8 +1200,6 @@ declare module "typescript" {
|
||||
target?: ScriptTarget;
|
||||
version?: boolean;
|
||||
watch?: boolean;
|
||||
stripInternal?: boolean;
|
||||
preserveNewLines?: boolean;
|
||||
[option: string]: string | number | boolean;
|
||||
}
|
||||
const enum ModuleKind {
|
||||
@ -1443,7 +1441,7 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
/** The version of the TypeScript compiler release */
|
||||
var version: string;
|
||||
let version: string;
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
@ -1451,7 +1449,7 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
/** The version of the language service API */
|
||||
var servicesVersion: string;
|
||||
let servicesVersion: string;
|
||||
interface Node {
|
||||
getSourceFile(): SourceFile;
|
||||
getChildCount(sourceFile?: SourceFile): number;
|
||||
@ -1938,7 +1936,7 @@ declare module "typescript" {
|
||||
throwIfCancellationRequested(): void;
|
||||
}
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
var disableIncrementalParsing: boolean;
|
||||
let disableIncrementalParsing: boolean;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo;
|
||||
|
||||
10584
bin/typescript.js
10584
bin/typescript.js
File diff suppressed because one or more lines are too long
8
bin/typescriptServices.d.ts
vendored
8
bin/typescriptServices.d.ts
vendored
@ -1200,8 +1200,6 @@ declare module ts {
|
||||
target?: ScriptTarget;
|
||||
version?: boolean;
|
||||
watch?: boolean;
|
||||
stripInternal?: boolean;
|
||||
preserveNewLines?: boolean;
|
||||
[option: string]: string | number | boolean;
|
||||
}
|
||||
const enum ModuleKind {
|
||||
@ -1443,7 +1441,7 @@ declare module ts {
|
||||
}
|
||||
declare module ts {
|
||||
/** The version of the TypeScript compiler release */
|
||||
var version: string;
|
||||
let version: string;
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
@ -1451,7 +1449,7 @@ declare module ts {
|
||||
}
|
||||
declare module ts {
|
||||
/** The version of the language service API */
|
||||
var servicesVersion: string;
|
||||
let servicesVersion: string;
|
||||
interface Node {
|
||||
getSourceFile(): SourceFile;
|
||||
getChildCount(sourceFile?: SourceFile): number;
|
||||
@ -1938,7 +1936,7 @@ declare module ts {
|
||||
throwIfCancellationRequested(): void;
|
||||
}
|
||||
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
|
||||
var disableIncrementalParsing: boolean;
|
||||
let disableIncrementalParsing: boolean;
|
||||
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
function createDocumentRegistry(): DocumentRegistry;
|
||||
function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo;
|
||||
|
||||
File diff suppressed because one or more lines are too long
10
bin/typescriptServices_internal.d.ts
vendored
10
bin/typescriptServices_internal.d.ts
vendored
@ -62,7 +62,7 @@ declare module ts {
|
||||
* index in the array will be the one associated with the produced key.
|
||||
*/
|
||||
function arrayToMap<T>(array: T[], makeKey: (value: T) => string): Map<T>;
|
||||
var localizedDiagnosticMessages: Map<string>;
|
||||
let localizedDiagnosticMessages: Map<string>;
|
||||
function getLocaleSpecificMessage(message: string): string;
|
||||
function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic;
|
||||
function createCompilerDiagnostic(message: DiagnosticMessage, ...args: any[]): Diagnostic;
|
||||
@ -74,7 +74,7 @@ declare module ts {
|
||||
function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[];
|
||||
function normalizeSlashes(path: string): string;
|
||||
function getRootLength(path: string): number;
|
||||
var directorySeparator: string;
|
||||
let directorySeparator: string;
|
||||
function normalizePath(path: string): string;
|
||||
function getDirectoryPath(path: string): string;
|
||||
function isUrl(path: string): boolean;
|
||||
@ -94,7 +94,7 @@ declare module ts {
|
||||
getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type;
|
||||
getSignatureConstructor(): new (checker: TypeChecker) => Signature;
|
||||
}
|
||||
var objectAllocator: ObjectAllocator;
|
||||
let objectAllocator: ObjectAllocator;
|
||||
const enum AssertionLevel {
|
||||
None = 0,
|
||||
Normal = 1,
|
||||
@ -186,7 +186,7 @@ declare module ts {
|
||||
function isPrologueDirective(node: Node): boolean;
|
||||
function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode?: SourceFile): CommentRange[];
|
||||
function getJsDocComments(node: Node, sourceFileOfNode: SourceFile): CommentRange[];
|
||||
var fullTripleSlashReferencePathRegEx: RegExp;
|
||||
let fullTripleSlashReferencePathRegEx: RegExp;
|
||||
function forEachReturnStatement<T>(body: Block, visitor: (stmt: ReturnStatement) => T): T;
|
||||
function isFunctionLike(node: Node): boolean;
|
||||
function isFunctionBlock(node: Node): boolean;
|
||||
@ -257,7 +257,7 @@ declare module ts {
|
||||
function textChangeRangeNewSpan(range: TextChangeRange): TextSpan;
|
||||
function textChangeRangeIsUnchanged(range: TextChangeRange): boolean;
|
||||
function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange;
|
||||
var unchangedTextChangeRange: TextChangeRange;
|
||||
let unchangedTextChangeRange: TextChangeRange;
|
||||
/**
|
||||
* Called to merge all the changes that occurred across several versions of a script snapshot
|
||||
* into a single change. i.e. if a user keeps making successive edits to a script we will
|
||||
|
||||
10
bin/typescript_internal.d.ts
vendored
10
bin/typescript_internal.d.ts
vendored
@ -62,7 +62,7 @@ declare module "typescript" {
|
||||
* index in the array will be the one associated with the produced key.
|
||||
*/
|
||||
function arrayToMap<T>(array: T[], makeKey: (value: T) => string): Map<T>;
|
||||
var localizedDiagnosticMessages: Map<string>;
|
||||
let localizedDiagnosticMessages: Map<string>;
|
||||
function getLocaleSpecificMessage(message: string): string;
|
||||
function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic;
|
||||
function createCompilerDiagnostic(message: DiagnosticMessage, ...args: any[]): Diagnostic;
|
||||
@ -74,7 +74,7 @@ declare module "typescript" {
|
||||
function deduplicateSortedDiagnostics(diagnostics: Diagnostic[]): Diagnostic[];
|
||||
function normalizeSlashes(path: string): string;
|
||||
function getRootLength(path: string): number;
|
||||
var directorySeparator: string;
|
||||
let directorySeparator: string;
|
||||
function normalizePath(path: string): string;
|
||||
function getDirectoryPath(path: string): string;
|
||||
function isUrl(path: string): boolean;
|
||||
@ -94,7 +94,7 @@ declare module "typescript" {
|
||||
getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type;
|
||||
getSignatureConstructor(): new (checker: TypeChecker) => Signature;
|
||||
}
|
||||
var objectAllocator: ObjectAllocator;
|
||||
let objectAllocator: ObjectAllocator;
|
||||
const enum AssertionLevel {
|
||||
None = 0,
|
||||
Normal = 1,
|
||||
@ -186,7 +186,7 @@ declare module "typescript" {
|
||||
function isPrologueDirective(node: Node): boolean;
|
||||
function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode?: SourceFile): CommentRange[];
|
||||
function getJsDocComments(node: Node, sourceFileOfNode: SourceFile): CommentRange[];
|
||||
var fullTripleSlashReferencePathRegEx: RegExp;
|
||||
let fullTripleSlashReferencePathRegEx: RegExp;
|
||||
function forEachReturnStatement<T>(body: Block, visitor: (stmt: ReturnStatement) => T): T;
|
||||
function isFunctionLike(node: Node): boolean;
|
||||
function isFunctionBlock(node: Node): boolean;
|
||||
@ -257,7 +257,7 @@ declare module "typescript" {
|
||||
function textChangeRangeNewSpan(range: TextChangeRange): TextSpan;
|
||||
function textChangeRangeIsUnchanged(range: TextChangeRange): boolean;
|
||||
function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange;
|
||||
var unchangedTextChangeRange: TextChangeRange;
|
||||
let unchangedTextChangeRange: TextChangeRange;
|
||||
/**
|
||||
* Called to merge all the changes that occurred across several versions of a script snapshot
|
||||
* into a single change. i.e. if a user keeps making successive edits to a script we will
|
||||
|
||||
@ -58,7 +58,7 @@ module ts {
|
||||
}
|
||||
|
||||
function bindSourceFileWorker(file: SourceFile): void {
|
||||
var parent: Node;
|
||||
let parent: Node;
|
||||
let container: Node;
|
||||
let blockScopeContainer: Node;
|
||||
let lastContainer: Node;
|
||||
@ -505,7 +505,7 @@ module ts {
|
||||
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.ExportAssignment:
|
||||
if ((<ExportAssignment>node).expression.kind === SyntaxKind.Identifier) {
|
||||
if ((<ExportAssignment>node).expression && (<ExportAssignment>node).expression.kind === SyntaxKind.Identifier) {
|
||||
// An export default clause with an identifier exports all meanings of that identifier
|
||||
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
|
||||
}
|
||||
|
||||
@ -22,6 +22,9 @@ module ts {
|
||||
|
||||
let emitResolver = createResolver();
|
||||
|
||||
let undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
|
||||
let argumentsSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "arguments");
|
||||
|
||||
let checker: TypeChecker = {
|
||||
getNodeCount: () => sum(host.getSourceFiles(), "nodeCount"),
|
||||
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
|
||||
@ -59,8 +62,6 @@ module ts {
|
||||
getExportsOfExternalModule,
|
||||
};
|
||||
|
||||
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
|
||||
var argumentsSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "arguments");
|
||||
let unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown");
|
||||
let resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__");
|
||||
|
||||
@ -447,7 +448,7 @@ module ts {
|
||||
let declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) ? d : undefined);
|
||||
|
||||
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
|
||||
|
||||
|
||||
// first check if usage is lexically located after the declaration
|
||||
let isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation);
|
||||
if (!isUsedBeforeDeclaration) {
|
||||
@ -464,7 +465,7 @@ module ts {
|
||||
|
||||
if (variableDeclaration.parent.parent.kind === SyntaxKind.VariableStatement ||
|
||||
variableDeclaration.parent.parent.kind === SyntaxKind.ForStatement) {
|
||||
// variable statement/for statement case,
|
||||
// variable statement/for statement case,
|
||||
// use site should not be inside variable declaration (initializer of declaration or binding element)
|
||||
isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container);
|
||||
}
|
||||
@ -579,7 +580,7 @@ module ts {
|
||||
}
|
||||
|
||||
function getTargetOfExportAssignment(node: ExportAssignment): Symbol {
|
||||
return resolveEntityName(<Identifier>node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
|
||||
return node.expression && resolveEntityName(<Identifier>node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
|
||||
}
|
||||
|
||||
function getTargetOfImportDeclaration(node: Declaration): Symbol {
|
||||
@ -635,7 +636,7 @@ module ts {
|
||||
if (!links.referenced) {
|
||||
links.referenced = true;
|
||||
let node = getDeclarationOfAliasSymbol(symbol);
|
||||
if (node.kind === SyntaxKind.ExportAssignment) {
|
||||
if (node.kind === SyntaxKind.ExportAssignment && (<ExportAssignment>node).expression) {
|
||||
// export default <symbol>
|
||||
checkExpressionCached((<ExportAssignment>node).expression);
|
||||
}
|
||||
@ -686,8 +687,10 @@ module ts {
|
||||
if (getFullWidth(name) === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let symbol: Symbol;
|
||||
if (name.kind === SyntaxKind.Identifier) {
|
||||
var symbol = resolveName(name, (<Identifier>name).text, meaning, Diagnostics.Cannot_find_name_0, <Identifier>name);
|
||||
symbol = resolveName(name, (<Identifier>name).text, meaning, Diagnostics.Cannot_find_name_0, <Identifier>name);
|
||||
if (!symbol) {
|
||||
return undefined;
|
||||
}
|
||||
@ -698,7 +701,7 @@ module ts {
|
||||
return undefined;
|
||||
}
|
||||
let right = (<QualifiedName>name).right;
|
||||
var symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning);
|
||||
symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning);
|
||||
if (!symbol) {
|
||||
error(right, Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), declarationNameToString(right));
|
||||
return undefined;
|
||||
@ -734,12 +737,20 @@ module ts {
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
|
||||
let sourceFile: SourceFile;
|
||||
while (true) {
|
||||
let fileName = normalizePath(combinePaths(searchPath, moduleName));
|
||||
var sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts");
|
||||
if (sourceFile || isRelative) break;
|
||||
sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts");
|
||||
if (sourceFile || isRelative) {
|
||||
break;
|
||||
}
|
||||
|
||||
let parentPath = getDirectoryPath(searchPath);
|
||||
if (parentPath === searchPath) break;
|
||||
if (parentPath === searchPath) {
|
||||
break;
|
||||
}
|
||||
|
||||
searchPath = parentPath;
|
||||
}
|
||||
if (sourceFile) {
|
||||
@ -1726,11 +1737,12 @@ module ts {
|
||||
function isUsedInExportAssignment(node: Node) {
|
||||
// Get source File and see if it is external module and has export assigned symbol
|
||||
let externalModule = getContainingExternalModule(node);
|
||||
let exportAssignmentSymbol: Symbol;
|
||||
let resolvedExportSymbol: Symbol;
|
||||
if (externalModule) {
|
||||
// This is export assigned symbol node
|
||||
let externalModuleSymbol = getSymbolOfNode(externalModule);
|
||||
var exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
|
||||
var resolvedExportSymbol: Symbol;
|
||||
exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
|
||||
let symbolOfNode = getSymbolOfNode(node);
|
||||
if (isSymbolUsedInExportAssignment(symbolOfNode)) {
|
||||
return true;
|
||||
@ -1931,12 +1943,14 @@ module ts {
|
||||
}
|
||||
return parentType;
|
||||
}
|
||||
|
||||
let type: Type;
|
||||
if (pattern.kind === SyntaxKind.ObjectBindingPattern) {
|
||||
// Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form)
|
||||
let name = declaration.propertyName || <Identifier>declaration.name;
|
||||
// Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature,
|
||||
// or otherwise the type of the string index signature.
|
||||
var type = getTypeOfPropertyOfType(parentType, name.text) ||
|
||||
type = getTypeOfPropertyOfType(parentType, name.text) ||
|
||||
isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, IndexKind.Number) ||
|
||||
getIndexTypeOfType(parentType, IndexKind.String);
|
||||
if (!type) {
|
||||
@ -1953,7 +1967,7 @@ module ts {
|
||||
if (!declaration.dotDotDotToken) {
|
||||
// Use specific property type when parent is a tuple or numeric index type when parent is an array
|
||||
let propName = "" + indexOf(pattern.elements, declaration);
|
||||
var type = isTupleLikeType(parentType) ? getTypeOfPropertyOfType(parentType, propName) : getIndexTypeOfType(parentType, IndexKind.Number);
|
||||
type = isTupleLikeType(parentType) ? getTypeOfPropertyOfType(parentType, propName) : getIndexTypeOfType(parentType, IndexKind.Number);
|
||||
if (!type) {
|
||||
if (isTupleType(parentType)) {
|
||||
error(declaration, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(parentType), (<TupleType>parentType).elementTypes.length, pattern.elements.length);
|
||||
@ -1966,7 +1980,7 @@ module ts {
|
||||
}
|
||||
else {
|
||||
// Rest element has an array type with the same element type as the parent type
|
||||
var type = createArrayType(getIndexTypeOfType(parentType, IndexKind.Number));
|
||||
type = createArrayType(getIndexTypeOfType(parentType, IndexKind.Number));
|
||||
}
|
||||
}
|
||||
return type;
|
||||
@ -2122,7 +2136,16 @@ module ts {
|
||||
}
|
||||
// Handle export default expressions
|
||||
if (declaration.kind === SyntaxKind.ExportAssignment) {
|
||||
return links.type = checkExpression((<ExportAssignment>declaration).expression);
|
||||
var exportAssignment = <ExportAssignment>declaration;
|
||||
if (exportAssignment.expression) {
|
||||
return links.type = checkExpression(exportAssignment.expression);
|
||||
}
|
||||
else if (exportAssignment.type) {
|
||||
return links.type = getTypeFromTypeNode(exportAssignment.type);
|
||||
}
|
||||
else {
|
||||
return links.type = anyType;
|
||||
}
|
||||
}
|
||||
// Handle variable, parameter or property
|
||||
links.type = resolvingType;
|
||||
@ -2643,18 +2666,24 @@ module ts {
|
||||
|
||||
function resolveAnonymousTypeMembers(type: ObjectType) {
|
||||
let symbol = type.symbol;
|
||||
let members: SymbolTable;
|
||||
let callSignatures: Signature[];
|
||||
let constructSignatures: Signature[];
|
||||
let stringIndexType: Type;
|
||||
let numberIndexType: Type;
|
||||
|
||||
if (symbol.flags & SymbolFlags.TypeLiteral) {
|
||||
var members = symbol.members;
|
||||
var callSignatures = getSignaturesOfSymbol(members["__call"]);
|
||||
var constructSignatures = getSignaturesOfSymbol(members["__new"]);
|
||||
var stringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String);
|
||||
var numberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number);
|
||||
members = symbol.members;
|
||||
callSignatures = getSignaturesOfSymbol(members["__call"]);
|
||||
constructSignatures = getSignaturesOfSymbol(members["__new"]);
|
||||
stringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String);
|
||||
numberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number);
|
||||
}
|
||||
else {
|
||||
// Combinations of function, class, enum and module
|
||||
var members = emptySymbols;
|
||||
var callSignatures: Signature[] = emptyArray;
|
||||
var constructSignatures: Signature[] = emptyArray;
|
||||
members = emptySymbols;
|
||||
callSignatures = emptyArray;
|
||||
constructSignatures = emptyArray;
|
||||
if (symbol.flags & SymbolFlags.HasExports) {
|
||||
members = getExportsOfSymbol(symbol);
|
||||
}
|
||||
@ -2672,8 +2701,8 @@ module ts {
|
||||
addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(classType.baseTypes[0].symbol)));
|
||||
}
|
||||
}
|
||||
var stringIndexType: Type = undefined;
|
||||
var numberIndexType: Type = (symbol.flags & SymbolFlags.Enum) ? stringType : undefined;
|
||||
stringIndexType = undefined;
|
||||
numberIndexType = (symbol.flags & SymbolFlags.Enum) ? stringType : undefined;
|
||||
}
|
||||
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
|
||||
}
|
||||
@ -2980,14 +3009,15 @@ module ts {
|
||||
function getReturnTypeOfSignature(signature: Signature): Type {
|
||||
if (!signature.resolvedReturnType) {
|
||||
signature.resolvedReturnType = resolvingType;
|
||||
let type: Type;
|
||||
if (signature.target) {
|
||||
var type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper);
|
||||
type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper);
|
||||
}
|
||||
else if (signature.unionSignatures) {
|
||||
var type = getUnionType(map(signature.unionSignatures, getReturnTypeOfSignature));
|
||||
type = getUnionType(map(signature.unionSignatures, getReturnTypeOfSignature));
|
||||
}
|
||||
else {
|
||||
var type = getReturnTypeFromBody(<FunctionLikeDeclaration>signature.declaration);
|
||||
type = getReturnTypeFromBody(<FunctionLikeDeclaration>signature.declaration);
|
||||
}
|
||||
if (signature.resolvedReturnType === resolvingType) {
|
||||
signature.resolvedReturnType = type;
|
||||
@ -3191,8 +3221,8 @@ module ts {
|
||||
let links = getNodeLinks(node);
|
||||
if (!links.resolvedType) {
|
||||
let symbol = resolveEntityName(node.typeName, SymbolFlags.Type);
|
||||
let type: Type;
|
||||
if (symbol) {
|
||||
var type: Type;
|
||||
if ((symbol.flags & SymbolFlags.TypeParameter) && isTypeParameterReferenceIllegalInConstraint(node, symbol)) {
|
||||
// TypeScript 1.0 spec (April 2014): 3.4.1
|
||||
// Type parameters declared in a particular type parameter list
|
||||
@ -3576,8 +3606,9 @@ module ts {
|
||||
}
|
||||
|
||||
function instantiateSignature(signature: Signature, mapper: TypeMapper, eraseTypeParameters?: boolean): Signature {
|
||||
let freshTypeParameters: TypeParameter[];
|
||||
if (signature.typeParameters && !eraseTypeParameters) {
|
||||
var freshTypeParameters = instantiateList(signature.typeParameters, mapper, instantiateTypeParameter);
|
||||
freshTypeParameters = instantiateList(signature.typeParameters, mapper, instantiateTypeParameter);
|
||||
mapper = combineTypeMappers(createTypeMapper(signature.typeParameters, freshTypeParameters), mapper);
|
||||
}
|
||||
let result = createSignature(signature.declaration, freshTypeParameters,
|
||||
@ -4287,12 +4318,13 @@ module ts {
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
let related: Ternary;
|
||||
if (sourceStringType && sourceNumberType) {
|
||||
// If we know for sure we're testing both string and numeric index types then only report errors from the second one
|
||||
var related = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors);
|
||||
related = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors);
|
||||
}
|
||||
else {
|
||||
var related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors);
|
||||
related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors);
|
||||
}
|
||||
if (!related) {
|
||||
if (reportErrors) {
|
||||
@ -4452,7 +4484,7 @@ module ts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Type was written as a tuple type literal.
|
||||
* Check if a Type was written as a tuple type literal.
|
||||
* Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
|
||||
*/
|
||||
function isTupleType(type: Type) : boolean {
|
||||
@ -4532,13 +4564,14 @@ module ts {
|
||||
|
||||
function reportImplicitAnyError(declaration: Declaration, type: Type) {
|
||||
let typeAsString = typeToString(getWidenedType(type));
|
||||
let diagnostic: DiagnosticMessage;
|
||||
switch (declaration.kind) {
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
var diagnostic = Diagnostics.Member_0_implicitly_has_an_1_type;
|
||||
diagnostic = Diagnostics.Member_0_implicitly_has_an_1_type;
|
||||
break;
|
||||
case SyntaxKind.Parameter:
|
||||
var diagnostic = (<ParameterDeclaration>declaration).dotDotDotToken ?
|
||||
diagnostic = (<ParameterDeclaration>declaration).dotDotDotToken ?
|
||||
Diagnostics.Rest_parameter_0_implicitly_has_an_any_type :
|
||||
Diagnostics.Parameter_0_implicitly_has_an_1_type;
|
||||
break;
|
||||
@ -4553,10 +4586,10 @@ module ts {
|
||||
error(declaration, Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString);
|
||||
return;
|
||||
}
|
||||
var diagnostic = Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type;
|
||||
diagnostic = Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type;
|
||||
break;
|
||||
default:
|
||||
var diagnostic = Diagnostics.Variable_0_implicitly_has_an_1_type;
|
||||
diagnostic = Diagnostics.Variable_0_implicitly_has_an_1_type;
|
||||
}
|
||||
error(declaration, diagnostic, declarationNameToString(declaration.name), typeAsString);
|
||||
}
|
||||
@ -5319,6 +5352,7 @@ module ts {
|
||||
|
||||
if (container) {
|
||||
let canUseSuperExpression = false;
|
||||
let needToCaptureLexicalThis: boolean;
|
||||
if (isCallExpression) {
|
||||
// TS 1.0 SPEC (April 2014): 4.8.1
|
||||
// Super calls are only permitted in constructors of derived classes
|
||||
@ -5331,7 +5365,7 @@ module ts {
|
||||
// - In a static member function or static member accessor
|
||||
|
||||
// super property access might appear in arrow functions with arbitrary deep nesting
|
||||
var needToCaptureLexicalThis = false;
|
||||
needToCaptureLexicalThis = false;
|
||||
while (container && container.kind === SyntaxKind.ArrowFunction) {
|
||||
container = getSuperContainer(container, /*includeFunctions*/ true);
|
||||
needToCaptureLexicalThis = true;
|
||||
@ -5857,15 +5891,16 @@ module ts {
|
||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment ||
|
||||
memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment ||
|
||||
isObjectLiteralMethod(memberDecl)) {
|
||||
let type: Type;
|
||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment) {
|
||||
var type = checkPropertyAssignment(<PropertyAssignment>memberDecl, contextualMapper);
|
||||
type = checkPropertyAssignment(<PropertyAssignment>memberDecl, contextualMapper);
|
||||
}
|
||||
else if (memberDecl.kind === SyntaxKind.MethodDeclaration) {
|
||||
var type = checkObjectLiteralMethod(<MethodDeclaration>memberDecl, contextualMapper);
|
||||
type = checkObjectLiteralMethod(<MethodDeclaration>memberDecl, contextualMapper);
|
||||
}
|
||||
else {
|
||||
Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment);
|
||||
var type = memberDecl.name.kind === SyntaxKind.ComputedPropertyName
|
||||
type = memberDecl.name.kind === SyntaxKind.ComputedPropertyName
|
||||
? unknownType
|
||||
: checkExpression(<Identifier>memberDecl.name, contextualMapper);
|
||||
}
|
||||
@ -6382,14 +6417,15 @@ module ts {
|
||||
let arg = args[i];
|
||||
if (arg.kind !== SyntaxKind.OmittedExpression) {
|
||||
let paramType = getTypeAtPosition(signature, arg.kind === SyntaxKind.SpreadElementExpression ? -1 : i);
|
||||
let argType: Type;
|
||||
if (i === 0 && args[i].parent.kind === SyntaxKind.TaggedTemplateExpression) {
|
||||
var argType = globalTemplateStringsArrayType;
|
||||
argType = globalTemplateStringsArrayType;
|
||||
}
|
||||
else {
|
||||
// For context sensitive arguments we pass the identityMapper, which is a signal to treat all
|
||||
// context sensitive function expressions as wildcards
|
||||
let mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper;
|
||||
var argType = checkExpressionWithContextualType(arg, paramType, mapper);
|
||||
argType = checkExpressionWithContextualType(arg, paramType, mapper);
|
||||
}
|
||||
inferTypes(context, argType, paramType);
|
||||
}
|
||||
@ -6661,12 +6697,12 @@ module ts {
|
||||
|
||||
let originalCandidate = current;
|
||||
let inferenceResult: InferenceContext;
|
||||
|
||||
let candidate: Signature;
|
||||
let typeArgumentsAreValid: boolean;
|
||||
while (true) {
|
||||
var candidate = originalCandidate;
|
||||
candidate = originalCandidate;
|
||||
if (candidate.typeParameters) {
|
||||
let typeArgumentTypes: Type[];
|
||||
var typeArgumentsAreValid: boolean;
|
||||
if (typeArguments) {
|
||||
typeArgumentTypes = new Array<Type>(candidate.typeParameters.length);
|
||||
typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false)
|
||||
@ -6948,9 +6984,9 @@ module ts {
|
||||
if (!func.body) {
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
let type: Type;
|
||||
if (func.body.kind !== SyntaxKind.Block) {
|
||||
var type = checkExpressionCached(<Expression>func.body, contextualMapper);
|
||||
type = checkExpressionCached(<Expression>func.body, contextualMapper);
|
||||
}
|
||||
else {
|
||||
// Aggregate the types of expressions within all the return statements.
|
||||
@ -6960,7 +6996,7 @@ module ts {
|
||||
}
|
||||
// When return statements are contextually typed we allow the return type to be a union type. Otherwise we require the
|
||||
// return expressions to have a best common supertype.
|
||||
var type = contextualSignature ? getUnionType(types) : getCommonSupertype(types);
|
||||
type = contextualSignature ? getUnionType(types) : getCommonSupertype(types);
|
||||
if (!type) {
|
||||
error(func, Diagnostics.No_best_common_type_exists_among_return_expressions);
|
||||
return unknownType;
|
||||
@ -7129,18 +7165,20 @@ module ts {
|
||||
// and property accesses(section 4.10).
|
||||
// All other expression constructs described in this chapter are classified as values.
|
||||
switch (n.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
var symbol = findSymbol(n);
|
||||
case SyntaxKind.Identifier: {
|
||||
let symbol = findSymbol(n);
|
||||
// TypeScript 1.0 spec (April 2014): 4.3
|
||||
// An identifier expression that references a variable or parameter is classified as a reference.
|
||||
// An identifier expression that references any other kind of entity is classified as a value(and therefore cannot be the target of an assignment).
|
||||
return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & SymbolFlags.Variable) !== 0;
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
var symbol = findSymbol(n);
|
||||
}
|
||||
case SyntaxKind.PropertyAccessExpression: {
|
||||
let symbol = findSymbol(n);
|
||||
// TypeScript 1.0 spec (April 2014): 4.10
|
||||
// A property access expression is always classified as a reference.
|
||||
// NOTE (not in spec): assignment to enum members should not be allowed
|
||||
return !symbol || symbol === unknownSymbol || (symbol.flags & ~SymbolFlags.EnumMember) !== 0;
|
||||
}
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
// old compiler doesn't check indexed assess
|
||||
return true;
|
||||
@ -7154,12 +7192,13 @@ module ts {
|
||||
function isConstVariableReference(n: Node): boolean {
|
||||
switch (n.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
var symbol = findSymbol(n);
|
||||
case SyntaxKind.PropertyAccessExpression: {
|
||||
let symbol = findSymbol(n);
|
||||
return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0;
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
}
|
||||
case SyntaxKind.ElementAccessExpression: {
|
||||
let index = (<ElementAccessExpression>n).argumentExpression;
|
||||
var symbol = findSymbol((<ElementAccessExpression>n).expression);
|
||||
let symbol = findSymbol((<ElementAccessExpression>n).expression);
|
||||
|
||||
if (symbol && index && index.kind === SyntaxKind.StringLiteral) {
|
||||
let name = (<LiteralExpression>index).text;
|
||||
@ -7167,6 +7206,7 @@ module ts {
|
||||
return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return isConstVariableReference((<ParenthesizedExpression>n).expression);
|
||||
default:
|
||||
@ -8395,13 +8435,11 @@ module ts {
|
||||
return;
|
||||
}
|
||||
|
||||
var symbol: Symbol;
|
||||
|
||||
// Exports should be checked only if enclosing module contains both exported and non exported declarations.
|
||||
// In case if all declarations are non-exported check is unnecessary.
|
||||
|
||||
// if localSymbol is defined on node then node itself is exported - check is required
|
||||
var symbol = node.localSymbol;
|
||||
let symbol = node.localSymbol;
|
||||
if (!symbol) {
|
||||
// local symbol is undefined => this declaration is non-exported.
|
||||
// however symbol might contain other declarations that are exported
|
||||
@ -8668,36 +8706,48 @@ module ts {
|
||||
// const x = 0; // localDeclarationSymbol obtained after name resolution will correspond to this declaration
|
||||
// let x = 0; // symbol for this declaration will be 'symbol'
|
||||
// }
|
||||
if (node.initializer && (getCombinedNodeFlags(node) & NodeFlags.BlockScoped) === 0) {
|
||||
let symbol = getSymbolOfNode(node);
|
||||
if (symbol.flags & SymbolFlags.FunctionScopedVariable) {
|
||||
let localDeclarationSymbol = resolveName(node, (<Identifier>node.name).text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
|
||||
if (localDeclarationSymbol &&
|
||||
localDeclarationSymbol !== symbol &&
|
||||
localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) {
|
||||
if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.BlockScoped) {
|
||||
|
||||
let varDeclList = getAncestor(localDeclarationSymbol.valueDeclaration, SyntaxKind.VariableDeclarationList);
|
||||
let container =
|
||||
varDeclList.parent.kind === SyntaxKind.VariableStatement &&
|
||||
varDeclList.parent.parent;
|
||||
// skip block-scoped variables and parameters
|
||||
if ((getCombinedNodeFlags(node) & NodeFlags.BlockScoped) !== 0 || isParameterDeclaration(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// names of block-scoped and function scoped variables can collide only
|
||||
// if block scoped variable is defined in the function\module\source file scope (because of variable hoisting)
|
||||
let namesShareScope =
|
||||
container &&
|
||||
(container.kind === SyntaxKind.Block && isFunctionLike(container.parent) ||
|
||||
(container.kind === SyntaxKind.ModuleBlock && container.kind === SyntaxKind.ModuleDeclaration) ||
|
||||
container.kind === SyntaxKind.SourceFile);
|
||||
// skip variable declarations that don't have initializers
|
||||
// NOTE: in ES6 spec initializer is required in variable declarations where name is binding pattern
|
||||
// so we'll always treat binding elements as initialized
|
||||
if (node.kind === SyntaxKind.VariableDeclaration && !node.initializer) {
|
||||
return;
|
||||
}
|
||||
|
||||
// here we know that function scoped variable is shadowed by block scoped one
|
||||
// if they are defined in the same scope - binder has already reported redeclaration error
|
||||
// otherwise if variable has an initializer - show error that initialization will fail
|
||||
// since LHS will be block scoped name instead of function scoped
|
||||
if (!namesShareScope) {
|
||||
let name = symbolToString(localDeclarationSymbol);
|
||||
error(node, Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name);
|
||||
}
|
||||
var symbol = getSymbolOfNode(node);
|
||||
if (symbol.flags & SymbolFlags.FunctionScopedVariable) {
|
||||
let localDeclarationSymbol = resolveName(node, (<Identifier>node.name).text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
|
||||
if (localDeclarationSymbol &&
|
||||
localDeclarationSymbol !== symbol &&
|
||||
localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) {
|
||||
if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.BlockScoped) {
|
||||
let varDeclList = getAncestor(localDeclarationSymbol.valueDeclaration, SyntaxKind.VariableDeclarationList);
|
||||
let container =
|
||||
varDeclList.parent.kind === SyntaxKind.VariableStatement && varDeclList.parent.parent
|
||||
? varDeclList.parent.parent
|
||||
: undefined;
|
||||
|
||||
// names of block-scoped and function scoped variables can collide only
|
||||
// if block scoped variable is defined in the function\module\source file scope (because of variable hoisting)
|
||||
let namesShareScope =
|
||||
container &&
|
||||
(container.kind === SyntaxKind.Block && isFunctionLike(container.parent) ||
|
||||
container.kind === SyntaxKind.ModuleBlock ||
|
||||
container.kind === SyntaxKind.ModuleDeclaration ||
|
||||
container.kind === SyntaxKind.SourceFile);
|
||||
|
||||
// here we know that function scoped variable is shadowed by block scoped one
|
||||
// if they are defined in the same scope - binder has already reported redeclaration error
|
||||
// otherwise if variable has an initializer - show error that initialization will fail
|
||||
// since LHS will be block scoped name instead of function scoped
|
||||
if (!namesShareScope) {
|
||||
let name = symbolToString(localDeclarationSymbol);
|
||||
error(node, Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8713,10 +8763,13 @@ module ts {
|
||||
|
||||
// Check that a parameter initializer contains no references to parameters declared to the right of itself
|
||||
function checkParameterInitializer(node: VariableLikeDeclaration): void {
|
||||
if (getRootDeclaration(node).kind === SyntaxKind.Parameter) {
|
||||
var func = getContainingFunction(node);
|
||||
visit(node.initializer);
|
||||
if (getRootDeclaration(node).kind !== SyntaxKind.Parameter) {
|
||||
return;
|
||||
}
|
||||
|
||||
let func = getContainingFunction(node);
|
||||
visit(node.initializer);
|
||||
|
||||
function visit(n: Node) {
|
||||
if (n.kind === SyntaxKind.Identifier) {
|
||||
let referencedSymbol = getNodeLinks(n).resolvedSymbol;
|
||||
@ -9111,7 +9164,7 @@ module ts {
|
||||
*/
|
||||
function checkElementTypeOfArrayOrString(arrayOrStringType: Type, expressionForError: Expression): Type {
|
||||
Debug.assert(languageVersion < ScriptTarget.ES6);
|
||||
|
||||
|
||||
// After we remove all types that are StringLike, we will know if there was a string constituent
|
||||
// based on whether the remaining type is the same as the initial type.
|
||||
let arrayType = removeTypesFromUnionType(arrayOrStringType, TypeFlags.StringLike, /*isTypeOfKind*/ true, /*allowEmptyUnionResult*/ true);
|
||||
@ -10094,12 +10147,21 @@ module ts {
|
||||
if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers);
|
||||
}
|
||||
if (node.expression.kind === SyntaxKind.Identifier) {
|
||||
markExportAsReferenced(node);
|
||||
if (node.expression) {
|
||||
if (node.expression.kind === SyntaxKind.Identifier) {
|
||||
markExportAsReferenced(node);
|
||||
}
|
||||
else {
|
||||
checkExpressionCached(node.expression);
|
||||
}
|
||||
}
|
||||
else {
|
||||
checkExpressionCached(node.expression);
|
||||
if (node.type) {
|
||||
checkSourceElement(node.type);
|
||||
if (!isInAmbientContext(node)) {
|
||||
grammarErrorOnFirstToken(node.type, Diagnostics.A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration);
|
||||
}
|
||||
}
|
||||
|
||||
checkExternalModuleExports(container);
|
||||
}
|
||||
|
||||
@ -10792,7 +10854,7 @@ module ts {
|
||||
// Return the list of properties of the given type, augmented with properties from Function
|
||||
// if the type has call or construct signatures
|
||||
function getAugmentedPropertiesOfType(type: Type): Symbol[] {
|
||||
var type = getApparentType(type);
|
||||
type = getApparentType(type);
|
||||
let propsByName = createSymbolTable(getPropertiesOfType(type));
|
||||
if (getSignaturesOfType(type, SignatureKind.Call).length || getSignaturesOfType(type, SignatureKind.Construct).length) {
|
||||
forEach(getPropertiesOfType(globalFunctionType), p => {
|
||||
@ -10933,7 +10995,7 @@ module ts {
|
||||
}
|
||||
|
||||
function generateNameForExportAssignment(node: ExportAssignment) {
|
||||
if (node.expression.kind !== SyntaxKind.Identifier) {
|
||||
if (node.expression && node.expression.kind !== SyntaxKind.Identifier) {
|
||||
assignGeneratedName(node, makeUniqueName("default"));
|
||||
}
|
||||
}
|
||||
@ -11104,26 +11166,11 @@ module ts {
|
||||
function getBlockScopedVariableId(n: Identifier): number {
|
||||
Debug.assert(!nodeIsSynthesized(n));
|
||||
|
||||
// ignore name parts of property access expressions
|
||||
if (n.parent.kind === SyntaxKind.PropertyAccessExpression &&
|
||||
(<PropertyAccessExpression>n.parent).name === n) {
|
||||
return undefined;
|
||||
}
|
||||
let isVariableDeclarationOrBindingElement =
|
||||
n.parent.kind === SyntaxKind.BindingElement || (n.parent.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>n.parent).name === n);
|
||||
|
||||
// ignore property names in object binding patterns
|
||||
if (n.parent.kind === SyntaxKind.BindingElement &&
|
||||
(<BindingElement>n.parent).propertyName === n) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// for names in variable declarations and binding elements try to short circuit and fetch symbol from the node
|
||||
let declarationSymbol: Symbol =
|
||||
(n.parent.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>n.parent).name === n) ||
|
||||
n.parent.kind === SyntaxKind.BindingElement
|
||||
? getSymbolOfNode(n.parent)
|
||||
: undefined;
|
||||
|
||||
let symbol = declarationSymbol ||
|
||||
let symbol =
|
||||
(isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) ||
|
||||
getNodeLinks(n).resolvedSymbol ||
|
||||
resolveName(n, n.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined);
|
||||
|
||||
@ -11356,16 +11403,15 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray<TypeParameterDeclaration>): boolean {
|
||||
function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray<TypeParameterDeclaration>, file: SourceFile): boolean {
|
||||
if (checkGrammarForDisallowedTrailingComma(typeParameters)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (typeParameters && typeParameters.length === 0) {
|
||||
let start = typeParameters.pos - "<".length;
|
||||
let sourceFile = getSourceFileOfNode(node);
|
||||
let end = skipTrivia(sourceFile.text, typeParameters.end) + ">".length;
|
||||
return grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty);
|
||||
let end = skipTrivia(file.text, typeParameters.end) + ">".length;
|
||||
return grammarErrorAtPos(file, start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty);
|
||||
}
|
||||
}
|
||||
|
||||
@ -11409,7 +11455,21 @@ module ts {
|
||||
|
||||
function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean {
|
||||
// Prevent cascading error by short-circuit
|
||||
return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters) || checkGrammarParameterList(node.parameters);
|
||||
let file = getSourceFileOfNode(node);
|
||||
return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) ||
|
||||
checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
|
||||
}
|
||||
|
||||
function checkGrammarArrowFunction(node: FunctionLikeDeclaration, file: SourceFile): boolean {
|
||||
if (node.kind === SyntaxKind.ArrowFunction) {
|
||||
let arrowFunction = <ArrowFunction>node;
|
||||
let startLine = getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line;
|
||||
let endLine = getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line;
|
||||
if (startLine !== endLine) {
|
||||
return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkGrammarIndexSignatureParameters(node: SignatureDeclaration): boolean {
|
||||
|
||||
@ -146,6 +146,12 @@ module ts {
|
||||
description: Diagnostics.Preserve_new_lines_when_emitting_code,
|
||||
experimental: true
|
||||
},
|
||||
{
|
||||
name: "cacheDownlevelForOfLength",
|
||||
type: "boolean",
|
||||
description: "Cache length access when downlevel emitting for-of statements",
|
||||
experimental: true,
|
||||
},
|
||||
{
|
||||
name: "target",
|
||||
shortName: "t",
|
||||
|
||||
@ -157,6 +157,8 @@ module ts {
|
||||
Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." },
|
||||
An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." },
|
||||
Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." },
|
||||
Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
|
||||
A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration: { code: 1201, category: DiagnosticCategory.Error, key: "A type annotation on an export statement is only allowed in an ambient external module declaration." },
|
||||
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
|
||||
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
|
||||
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
|
||||
|
||||
@ -617,8 +617,17 @@
|
||||
},
|
||||
"Unterminated Unicode escape sequence.": {
|
||||
"category": "Error",
|
||||
"code": 1199
|
||||
"code": 1199
|
||||
},
|
||||
"Line terminator not permitted before arrow.": {
|
||||
"category": "Error",
|
||||
"code": 1200
|
||||
},
|
||||
"A type annotation on an export statement is only allowed in an ambient external module declaration.": {
|
||||
"category": "Error",
|
||||
"code": 1201
|
||||
},
|
||||
|
||||
"Duplicate identifier '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2300
|
||||
|
||||
@ -2289,19 +2289,19 @@ module ts {
|
||||
sourceMapDir = getDirectoryPath(normalizePath(jsFilePath));
|
||||
}
|
||||
|
||||
function emitNodeWithSourceMap(node: Node) {
|
||||
function emitNodeWithSourceMap(node: Node, allowGeneratedIdentifiers?: boolean) {
|
||||
if (node) {
|
||||
if (nodeIsSynthesized(node)) {
|
||||
return emitNodeWithoutSourceMap(node);
|
||||
return emitNodeWithoutSourceMap(node, /*allowGeneratedIdentifiers*/ false);
|
||||
}
|
||||
if (node.kind != SyntaxKind.SourceFile) {
|
||||
recordEmitNodeStartSpan(node);
|
||||
emitNodeWithoutSourceMap(node);
|
||||
emitNodeWithoutSourceMap(node, allowGeneratedIdentifiers);
|
||||
recordEmitNodeEndSpan(node);
|
||||
}
|
||||
else {
|
||||
recordNewSourceFileStart(<SourceFile>node);
|
||||
emitNodeWithoutSourceMap(node);
|
||||
emitNodeWithoutSourceMap(node, /*allowGeneratedIdentifiers*/ false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2331,16 +2331,22 @@ module ts {
|
||||
|
||||
// Create a temporary variable with a unique unused name. The forLoopVariable parameter signals that the
|
||||
// name should be one that is appropriate for a for loop variable.
|
||||
function createTempVariable(location: Node, forLoopVariable?: boolean): Identifier {
|
||||
let name = forLoopVariable ? "_i" : undefined;
|
||||
while (true) {
|
||||
if (name && !isExistingName(location, name)) {
|
||||
break;
|
||||
}
|
||||
function createTempVariable(location: Node, preferredName?: string): Identifier {
|
||||
for (var name = preferredName; !name || isExistingName(location, name); tempCount++) {
|
||||
// _a .. _h, _j ... _z, _0, _1, ...
|
||||
// Note that _i is skipped
|
||||
name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + CharacterCodes.a) : tempCount - 25);
|
||||
tempCount++;
|
||||
|
||||
// Note: we avoid generating _i and _n as those are common names we want in other places.
|
||||
var char = CharacterCodes.a + tempCount;
|
||||
if (char === CharacterCodes.i || char === CharacterCodes.n) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tempCount < 26) {
|
||||
name = "_" + String.fromCharCode(char);
|
||||
}
|
||||
else {
|
||||
name = "_" + (tempCount - 26);
|
||||
}
|
||||
}
|
||||
|
||||
// This is necessary so that a name generated via renameNonTopLevelLetAndConst will see the name
|
||||
@ -2359,8 +2365,8 @@ module ts {
|
||||
tempVariables.push(name);
|
||||
}
|
||||
|
||||
function createAndRecordTempVariable(location: Node): Identifier {
|
||||
let temp = createTempVariable(location, /*forLoopVariable*/ false);
|
||||
function createAndRecordTempVariable(location: Node, preferredName?: string): Identifier {
|
||||
let temp = createTempVariable(location, preferredName);
|
||||
recordTempDeclaration(temp);
|
||||
|
||||
return temp;
|
||||
@ -2832,17 +2838,24 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getBlockScopedVariableId(node: Identifier): number {
|
||||
// return undefined for synthesized nodes
|
||||
return !nodeIsSynthesized(node) && resolver.getBlockScopedVariableId(node);
|
||||
function getGeneratedNameForIdentifier(node: Identifier): string {
|
||||
if (nodeIsSynthesized(node) || !generatedBlockScopeNames) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var variableId = resolver.getBlockScopedVariableId(node)
|
||||
if (variableId === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return generatedBlockScopeNames[variableId];
|
||||
}
|
||||
|
||||
function emitIdentifier(node: Identifier) {
|
||||
let variableId = getBlockScopedVariableId(node);
|
||||
if (variableId !== undefined && generatedBlockScopeNames) {
|
||||
let text = generatedBlockScopeNames[variableId];
|
||||
if (text) {
|
||||
write(text);
|
||||
function emitIdentifier(node: Identifier, allowGeneratedIdentifiers: boolean) {
|
||||
if (allowGeneratedIdentifiers) {
|
||||
let generatedName = getGeneratedNameForIdentifier(node);
|
||||
if (generatedName) {
|
||||
write(generatedName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -2895,7 +2908,7 @@ module ts {
|
||||
|
||||
function emitBindingElement(node: BindingElement) {
|
||||
if (node.propertyName) {
|
||||
emit(node.propertyName);
|
||||
emit(node.propertyName, /*allowGeneratedIdentifiers*/ false);
|
||||
write(": ");
|
||||
}
|
||||
if (node.dotDotDotToken) {
|
||||
@ -3068,7 +3081,7 @@ module ts {
|
||||
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
var { firstAccessor, getAccessor, setAccessor } = getAllAccessorDeclarations(objectLiteral.properties, <AccessorDeclaration>property);
|
||||
let { firstAccessor, getAccessor, setAccessor } = getAllAccessorDeclarations(objectLiteral.properties, <AccessorDeclaration>property);
|
||||
|
||||
// Only emit the first accessor.
|
||||
if (firstAccessor !== property) {
|
||||
@ -3239,7 +3252,7 @@ module ts {
|
||||
}
|
||||
|
||||
function emitMethod(node: MethodDeclaration) {
|
||||
emit(node.name);
|
||||
emit(node.name, /*allowGeneratedIdentifiers*/ false);
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
write(": function ");
|
||||
}
|
||||
@ -3247,13 +3260,13 @@ module ts {
|
||||
}
|
||||
|
||||
function emitPropertyAssignment(node: PropertyDeclaration) {
|
||||
emit(node.name);
|
||||
emit(node.name, /*allowGeneratedIdentifiers*/ false);
|
||||
write(": ");
|
||||
emit(node.initializer);
|
||||
}
|
||||
|
||||
function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) {
|
||||
emit(node.name);
|
||||
emit(node.name, /*allowGeneratedIdentifiers*/ false);
|
||||
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
|
||||
// module m {
|
||||
// export let y;
|
||||
@ -3262,7 +3275,20 @@ module ts {
|
||||
// export let obj = { y };
|
||||
// }
|
||||
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
|
||||
if (languageVersion < ScriptTarget.ES6 || resolver.getExpressionNameSubstitution(node.name)) {
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
// Emit identifier as an identifier
|
||||
write(": ");
|
||||
var generatedName = getGeneratedNameForIdentifier(node.name);
|
||||
if (generatedName) {
|
||||
write(generatedName);
|
||||
}
|
||||
else {
|
||||
// Even though this is stored as identifier treat it as an expression
|
||||
// Short-hand, { x }, is equivalent of normal form { x: x }
|
||||
emitExpressionIdentifier(node.name);
|
||||
}
|
||||
}
|
||||
else if (resolver.getExpressionNameSubstitution(node.name)) {
|
||||
// Emit identifier as an identifier
|
||||
write(": ");
|
||||
// Even though this is stored as identifier treat it as an expression
|
||||
@ -3315,7 +3341,7 @@ module ts {
|
||||
let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken);
|
||||
write(".");
|
||||
let indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name);
|
||||
emit(node.name);
|
||||
emit(node.name, /*allowGeneratedIdentifiers*/ false);
|
||||
decreaseIndentIf(indentedBeforeDot, indentedAfterDot);
|
||||
}
|
||||
|
||||
@ -3795,8 +3821,10 @@ module ts {
|
||||
//
|
||||
// we don't want to emit a temporary variable for the RHS, just use it directly.
|
||||
let rhsIsIdentifier = node.expression.kind === SyntaxKind.Identifier;
|
||||
let counter = createTempVariable(node, /*forLoopVariable*/ true);
|
||||
let rhsReference = rhsIsIdentifier ? <Identifier>node.expression : createTempVariable(node, /*forLoopVariable*/ false);
|
||||
let counter = createTempVariable(node, /*preferredName*/ "_i");
|
||||
let rhsReference = rhsIsIdentifier ? <Identifier>node.expression : createTempVariable(node);
|
||||
|
||||
var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, /*preferredName:*/ "_n") : undefined;
|
||||
|
||||
// This is the let keyword for the counter and rhsReference. The let keyword for
|
||||
// the LHS will be emitted inside the body.
|
||||
@ -3817,14 +3845,30 @@ module ts {
|
||||
emitNodeWithoutSourceMap(node.expression);
|
||||
emitEnd(node.expression);
|
||||
}
|
||||
|
||||
if (cachedLength) {
|
||||
write(", ");
|
||||
emitNodeWithoutSourceMap(cachedLength);
|
||||
write(" = ");
|
||||
emitNodeWithoutSourceMap(rhsReference);
|
||||
write(".length");
|
||||
}
|
||||
|
||||
write("; ");
|
||||
|
||||
// _i < _a.length;
|
||||
emitStart(node.initializer);
|
||||
emitNodeWithoutSourceMap(counter);
|
||||
write(" < ");
|
||||
emitNodeWithoutSourceMap(rhsReference);
|
||||
write(".length");
|
||||
|
||||
if (cachedLength) {
|
||||
emitNodeWithoutSourceMap(cachedLength);
|
||||
}
|
||||
else {
|
||||
emitNodeWithoutSourceMap(rhsReference);
|
||||
write(".length");
|
||||
}
|
||||
|
||||
emitEnd(node.initializer);
|
||||
write("; ");
|
||||
|
||||
@ -3865,7 +3909,7 @@ module ts {
|
||||
else {
|
||||
// It's an empty declaration list. This can only happen in an error case, if the user wrote
|
||||
// for (let of []) {}
|
||||
emitNodeWithoutSourceMap(createTempVariable(node, /*forLoopVariable*/ false));
|
||||
emitNodeWithoutSourceMap(createTempVariable(node));
|
||||
write(" = ");
|
||||
emitNodeWithoutSourceMap(rhsIterationValue);
|
||||
}
|
||||
@ -4451,7 +4495,7 @@ module ts {
|
||||
if (languageVersion < ScriptTarget.ES6 && hasRestParameters(node)) {
|
||||
let restIndex = node.parameters.length - 1;
|
||||
let restParam = node.parameters[restIndex];
|
||||
let tempName = createTempVariable(node, /*forLoopVariable*/ true).text;
|
||||
let tempName = createTempVariable(node, /*preferredName:*/ "_i").text;
|
||||
writeLine();
|
||||
emitLeadingComments(restParam);
|
||||
emitStart(restParam);
|
||||
@ -4488,7 +4532,7 @@ module ts {
|
||||
|
||||
function emitAccessor(node: AccessorDeclaration) {
|
||||
write(node.kind === SyntaxKind.GetAccessor ? "get " : "set ");
|
||||
emit(node.name);
|
||||
emit(node.name, /*allowGeneratedIdentifiers*/ false);
|
||||
emitSignatureAndBody(node);
|
||||
}
|
||||
|
||||
@ -5534,7 +5578,7 @@ module ts {
|
||||
emitLeadingComments(node.endOfFileToken);
|
||||
}
|
||||
|
||||
function emitNodeWithoutSourceMapWithComments(node: Node): void {
|
||||
function emitNodeWithoutSourceMapWithComments(node: Node, allowGeneratedIdentifiers?: boolean): void {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
@ -5548,14 +5592,14 @@ module ts {
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
|
||||
emitJavaScriptWorker(node);
|
||||
emitJavaScriptWorker(node, allowGeneratedIdentifiers);
|
||||
|
||||
if (emitComments) {
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
}
|
||||
|
||||
function emitNodeWithoutSourceMapWithoutComments(node: Node): void {
|
||||
function emitNodeWithoutSourceMapWithoutComments(node: Node, allowGeneratedIdentifiers?: boolean): void {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
@ -5564,7 +5608,7 @@ module ts {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
|
||||
emitJavaScriptWorker(node);
|
||||
emitJavaScriptWorker(node, allowGeneratedIdentifiers);
|
||||
}
|
||||
|
||||
function shouldEmitLeadingAndTrailingComments(node: Node) {
|
||||
@ -5594,11 +5638,11 @@ module ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
function emitJavaScriptWorker(node: Node) {
|
||||
function emitJavaScriptWorker(node: Node, allowGeneratedIdentifiers: boolean = true) {
|
||||
// Check if the node can be emitted regardless of the ScriptTarget
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
return emitIdentifier(<Identifier>node);
|
||||
return emitIdentifier(<Identifier>node, allowGeneratedIdentifiers);
|
||||
case SyntaxKind.Parameter:
|
||||
return emitParameter(<ParameterDeclaration>node);
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -2,15 +2,15 @@
|
||||
/// <reference path="emitter.ts" />
|
||||
|
||||
module ts {
|
||||
/* @internal */ export var emitTime = 0;
|
||||
/* @internal */ export var ioReadTime = 0;
|
||||
/* @internal */ export let emitTime = 0;
|
||||
/* @internal */ export let ioReadTime = 0;
|
||||
|
||||
/** The version of the TypeScript compiler release */
|
||||
export var version = "1.5.0.0";
|
||||
export let version = "1.5.0.0";
|
||||
|
||||
export function createCompilerHost(options: CompilerOptions): CompilerHost {
|
||||
var currentDirectory: string;
|
||||
var existingDirectories: Map<boolean> = {};
|
||||
let currentDirectory: string;
|
||||
let existingDirectories: Map<boolean> = {};
|
||||
|
||||
function getCanonicalFileName(fileName: string): string {
|
||||
// if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form.
|
||||
@ -19,12 +19,13 @@ module ts {
|
||||
}
|
||||
|
||||
// returned by CScript sys environment
|
||||
var unsupportedFileEncodingErrorCode = -2147024809;
|
||||
let unsupportedFileEncodingErrorCode = -2147024809;
|
||||
|
||||
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile {
|
||||
let text: string;
|
||||
try {
|
||||
var start = new Date().getTime();
|
||||
var text = sys.readFile(fileName, options.charset);
|
||||
let start = new Date().getTime();
|
||||
text = sys.readFile(fileName, options.charset);
|
||||
ioReadTime += new Date().getTime() - start;
|
||||
}
|
||||
catch (e) {
|
||||
@ -53,7 +54,7 @@ module ts {
|
||||
|
||||
function ensureDirectoriesExist(directoryPath: string) {
|
||||
if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) {
|
||||
var parentDirectory = getDirectoryPath(directoryPath);
|
||||
let parentDirectory = getDirectoryPath(directoryPath);
|
||||
ensureDirectoriesExist(parentDirectory);
|
||||
sys.createDirectory(directoryPath);
|
||||
}
|
||||
@ -82,7 +83,7 @@ module ts {
|
||||
}
|
||||
|
||||
export function getPreEmitDiagnostics(program: Program): Diagnostic[] {
|
||||
var diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics());
|
||||
let diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics());
|
||||
return sortAndDeduplicateDiagnostics(diagnostics);
|
||||
}
|
||||
|
||||
@ -91,15 +92,15 @@ module ts {
|
||||
return messageText;
|
||||
}
|
||||
else {
|
||||
var diagnosticChain = messageText;
|
||||
var result = "";
|
||||
let diagnosticChain = messageText;
|
||||
let result = "";
|
||||
|
||||
var indent = 0;
|
||||
let indent = 0;
|
||||
while (diagnosticChain) {
|
||||
if (indent) {
|
||||
result += newLine;
|
||||
|
||||
for (var i = 0; i < indent; i++) {
|
||||
for (let i = 0; i < indent; i++) {
|
||||
result += " ";
|
||||
}
|
||||
}
|
||||
@ -113,12 +114,12 @@ module ts {
|
||||
}
|
||||
|
||||
export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program {
|
||||
var program: Program;
|
||||
var files: SourceFile[] = [];
|
||||
var filesByName: Map<SourceFile> = {};
|
||||
var diagnostics = createDiagnosticCollection();
|
||||
var seenNoDefaultLib = options.noLib;
|
||||
var commonSourceDirectory: string;
|
||||
let program: Program;
|
||||
let files: SourceFile[] = [];
|
||||
let filesByName: Map<SourceFile> = {};
|
||||
let diagnostics = createDiagnosticCollection();
|
||||
let seenNoDefaultLib = options.noLib;
|
||||
let commonSourceDirectory: string;
|
||||
host = host || createCompilerHost(options);
|
||||
|
||||
forEach(rootNames, name => processRootFile(name, false));
|
||||
@ -127,8 +128,8 @@ module ts {
|
||||
}
|
||||
verifyCompilerOptions();
|
||||
|
||||
var diagnosticsProducingTypeChecker: TypeChecker;
|
||||
var noDiagnosticsTypeChecker: TypeChecker;
|
||||
let diagnosticsProducingTypeChecker: TypeChecker;
|
||||
let noDiagnosticsTypeChecker: TypeChecker;
|
||||
|
||||
program = {
|
||||
getSourceFile: getSourceFile,
|
||||
@ -172,7 +173,7 @@ module ts {
|
||||
}
|
||||
|
||||
function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[] {
|
||||
var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(targetSourceFile);
|
||||
let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(targetSourceFile);
|
||||
return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile);
|
||||
}
|
||||
|
||||
@ -186,11 +187,11 @@ module ts {
|
||||
// Create the emit resolver outside of the "emitTime" tracking code below. That way
|
||||
// any cost associated with it (like type checking) are appropriate associated with
|
||||
// the type-checking counter.
|
||||
var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile);
|
||||
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile);
|
||||
|
||||
var start = new Date().getTime();
|
||||
let start = new Date().getTime();
|
||||
|
||||
var emitResult = emitFiles(
|
||||
let emitResult = emitFiles(
|
||||
emitResolver,
|
||||
getEmitHost(writeFileCallback),
|
||||
sourceFile);
|
||||
@ -209,7 +210,7 @@ module ts {
|
||||
return getDiagnostics(sourceFile);
|
||||
}
|
||||
|
||||
var allDiagnostics: Diagnostic[] = [];
|
||||
let allDiagnostics: Diagnostic[] = [];
|
||||
forEach(program.getSourceFiles(), sourceFile => {
|
||||
addRange(allDiagnostics, getDiagnostics(sourceFile));
|
||||
});
|
||||
@ -230,20 +231,20 @@ module ts {
|
||||
}
|
||||
|
||||
function getSemanticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] {
|
||||
var typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
let typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
|
||||
Debug.assert(!!sourceFile.bindDiagnostics);
|
||||
var bindDiagnostics = sourceFile.bindDiagnostics;
|
||||
var checkDiagnostics = typeChecker.getDiagnostics(sourceFile);
|
||||
var programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName);
|
||||
let bindDiagnostics = sourceFile.bindDiagnostics;
|
||||
let checkDiagnostics = typeChecker.getDiagnostics(sourceFile);
|
||||
let programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName);
|
||||
|
||||
return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics);
|
||||
}
|
||||
|
||||
function getGlobalDiagnostics(): Diagnostic[] {
|
||||
var typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
let typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
|
||||
var allDiagnostics: Diagnostic[] = [];
|
||||
let allDiagnostics: Diagnostic[] = [];
|
||||
addRange(allDiagnostics, typeChecker.getGlobalDiagnostics());
|
||||
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
|
||||
|
||||
@ -259,11 +260,13 @@ module ts {
|
||||
}
|
||||
|
||||
function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
|
||||
let start: number;
|
||||
let length: number;
|
||||
if (refEnd !== undefined && refPos !== undefined) {
|
||||
var start = refPos;
|
||||
var length = refEnd - refPos;
|
||||
start = refPos;
|
||||
length = refEnd - refPos;
|
||||
}
|
||||
var diagnostic: DiagnosticMessage;
|
||||
let diagnostic: DiagnosticMessage;
|
||||
if (hasExtension(fileName)) {
|
||||
if (!options.allowNonTsExtensions && !fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) {
|
||||
diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts;
|
||||
@ -297,20 +300,20 @@ module ts {
|
||||
|
||||
// Get source file from normalized fileName
|
||||
function findSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refStart?: number, refLength?: number): SourceFile {
|
||||
var canonicalName = host.getCanonicalFileName(fileName);
|
||||
let canonicalName = host.getCanonicalFileName(fileName);
|
||||
if (hasProperty(filesByName, canonicalName)) {
|
||||
// We've already looked for this file, use cached result
|
||||
return getSourceFileFromCache(fileName, canonicalName, /*useAbsolutePath*/ false);
|
||||
}
|
||||
else {
|
||||
var normalizedAbsolutePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
|
||||
var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath);
|
||||
let normalizedAbsolutePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
|
||||
let canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath);
|
||||
if (hasProperty(filesByName, canonicalAbsolutePath)) {
|
||||
return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, /*useAbsolutePath*/ true);
|
||||
}
|
||||
|
||||
// We haven't looked for this file, do so now and cache result
|
||||
var file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, hostErrorMessage => {
|
||||
let file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, hostErrorMessage => {
|
||||
if (refFile) {
|
||||
diagnostics.add(createFileDiagnostic(refFile, refStart, refLength,
|
||||
Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
|
||||
@ -326,7 +329,7 @@ module ts {
|
||||
filesByName[canonicalAbsolutePath] = file;
|
||||
|
||||
if (!options.noResolve) {
|
||||
var basePath = getDirectoryPath(fileName);
|
||||
let basePath = getDirectoryPath(fileName);
|
||||
processReferencedFiles(file, basePath);
|
||||
processImportedModules(file, basePath);
|
||||
}
|
||||
@ -337,13 +340,14 @@ module ts {
|
||||
files.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
return file;
|
||||
|
||||
function getSourceFileFromCache(fileName: string, canonicalName: string, useAbsolutePath: boolean): SourceFile {
|
||||
var file = filesByName[canonicalName];
|
||||
let file = filesByName[canonicalName];
|
||||
if (file && host.useCaseSensitiveFileNames()) {
|
||||
var sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName;
|
||||
let sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName;
|
||||
if (canonicalName !== sourceFileName) {
|
||||
diagnostics.add(createFileDiagnostic(refFile, refStart, refLength,
|
||||
Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
|
||||
@ -355,7 +359,7 @@ module ts {
|
||||
|
||||
function processReferencedFiles(file: SourceFile, basePath: string) {
|
||||
forEach(file.referencedFiles, ref => {
|
||||
var referencedFileName = isRootedDiskPath(ref.fileName) ? ref.fileName : combinePaths(basePath, ref.fileName);
|
||||
let referencedFileName = isRootedDiskPath(ref.fileName) ? ref.fileName : combinePaths(basePath, ref.fileName);
|
||||
processSourceFile(normalizePath(referencedFileName), /* isDefaultLib */ false, file, ref.pos, ref.end);
|
||||
});
|
||||
}
|
||||
@ -363,17 +367,17 @@ module ts {
|
||||
function processImportedModules(file: SourceFile, basePath: string) {
|
||||
forEach(file.statements, node => {
|
||||
if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ExportDeclaration) {
|
||||
var moduleNameExpr = getExternalModuleName(node);
|
||||
let moduleNameExpr = getExternalModuleName(node);
|
||||
if (moduleNameExpr && moduleNameExpr.kind === SyntaxKind.StringLiteral) {
|
||||
var moduleNameText = (<LiteralExpression>moduleNameExpr).text;
|
||||
let moduleNameText = (<LiteralExpression>moduleNameExpr).text;
|
||||
if (moduleNameText) {
|
||||
var searchPath = basePath;
|
||||
let searchPath = basePath;
|
||||
while (true) {
|
||||
var searchName = normalizePath(combinePaths(searchPath, moduleNameText));
|
||||
let searchName = normalizePath(combinePaths(searchPath, moduleNameText));
|
||||
if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) {
|
||||
break;
|
||||
}
|
||||
var parentPath = getDirectoryPath(searchPath);
|
||||
let parentPath = getDirectoryPath(searchPath);
|
||||
if (parentPath === searchPath) {
|
||||
break;
|
||||
}
|
||||
@ -392,14 +396,14 @@ module ts {
|
||||
if (isExternalModuleImportEqualsDeclaration(node) &&
|
||||
getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
|
||||
|
||||
var nameLiteral = <LiteralExpression>getExternalModuleImportEqualsDeclarationExpression(node);
|
||||
var moduleName = nameLiteral.text;
|
||||
let nameLiteral = <LiteralExpression>getExternalModuleImportEqualsDeclarationExpression(node);
|
||||
let moduleName = nameLiteral.text;
|
||||
if (moduleName) {
|
||||
// TypeScript 1.0 spec (April 2014): 12.1.6
|
||||
// An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
|
||||
// only through top - level external module names. Relative external module names are not permitted.
|
||||
var searchName = normalizePath(combinePaths(basePath, moduleName));
|
||||
var tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral);
|
||||
let searchName = normalizePath(combinePaths(basePath, moduleName));
|
||||
let tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral);
|
||||
if (!tsFile) {
|
||||
findModuleSourceFile(searchName + ".d.ts", nameLiteral);
|
||||
}
|
||||
@ -426,10 +430,10 @@ module ts {
|
||||
return;
|
||||
}
|
||||
|
||||
var firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
|
||||
let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
|
||||
if (firstExternalModuleSourceFile && !options.module) {
|
||||
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
|
||||
var span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
|
||||
let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
|
||||
diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
|
||||
}
|
||||
|
||||
@ -440,15 +444,15 @@ module ts {
|
||||
(options.mapRoot && // there is --mapRoot Specified and there would be multiple js files generated
|
||||
(!options.out || firstExternalModuleSourceFile !== undefined))) {
|
||||
|
||||
var commonPathComponents: string[];
|
||||
let commonPathComponents: string[];
|
||||
forEach(files, sourceFile => {
|
||||
// Each file contributes into common source file path
|
||||
if (!(sourceFile.flags & NodeFlags.DeclarationFile)
|
||||
&& !fileExtensionIs(sourceFile.fileName, ".js")) {
|
||||
var sourcePathComponents = getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory());
|
||||
let sourcePathComponents = getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory());
|
||||
sourcePathComponents.pop(); // FileName is not part of directory
|
||||
if (commonPathComponents) {
|
||||
for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) {
|
||||
for (let i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) {
|
||||
if (commonPathComponents[i] !== sourcePathComponents[i]) {
|
||||
if (i === 0) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
|
||||
|
||||
@ -959,7 +959,7 @@ module ts {
|
||||
if (pos >= len) {
|
||||
return token = SyntaxKind.EndOfFileToken;
|
||||
}
|
||||
var ch = text.charCodeAt(pos);
|
||||
let ch = text.charCodeAt(pos);
|
||||
switch (ch) {
|
||||
case CharacterCodes.lineFeed:
|
||||
case CharacterCodes.carriageReturn:
|
||||
@ -1248,10 +1248,10 @@ module ts {
|
||||
case CharacterCodes.tilde:
|
||||
return pos++, token = SyntaxKind.TildeToken;
|
||||
case CharacterCodes.backslash:
|
||||
var ch = peekUnicodeEscape();
|
||||
if (ch >= 0 && isIdentifierStart(ch)) {
|
||||
let cookedChar = peekUnicodeEscape();
|
||||
if (cookedChar >= 0 && isIdentifierStart(cookedChar)) {
|
||||
pos += 6;
|
||||
tokenValue = String.fromCharCode(ch) + scanIdentifierParts();
|
||||
tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
|
||||
return token = getIdentifierToken();
|
||||
}
|
||||
error(Diagnostics.Invalid_character);
|
||||
|
||||
@ -329,7 +329,7 @@ module ts {
|
||||
|
||||
// If the parser encountered an error when parsing the code that created this node. Note
|
||||
// the parser only sets this directly on the node it creates right after encountering the
|
||||
// error.
|
||||
// error.
|
||||
ThisNodeHasError = 1 << 4,
|
||||
|
||||
// Context flags set directly by the parser.
|
||||
@ -337,7 +337,7 @@ module ts {
|
||||
|
||||
// Context flags computed by aggregating child flags upwards.
|
||||
|
||||
// Used during incremental parsing to determine if this node or any of its children had an
|
||||
// Used during incremental parsing to determine if this node or any of its children had an
|
||||
// error. Computed only once and then cached.
|
||||
ThisNodeOrAnySubNodesHasError = 1 << 5,
|
||||
|
||||
@ -354,7 +354,7 @@ module ts {
|
||||
export interface Node extends TextRange {
|
||||
kind: SyntaxKind;
|
||||
flags: NodeFlags;
|
||||
// Specific context the parser was in when this node was created. Normally undefined.
|
||||
// Specific context the parser was in when this node was created. Normally undefined.
|
||||
// Only set when the parser was in some interesting context (like async/yield).
|
||||
parserContextFlags?: ParserContextFlags;
|
||||
modifiers?: ModifiersArray; // Array of modifiers
|
||||
@ -524,7 +524,7 @@ module ts {
|
||||
body?: Block;
|
||||
}
|
||||
|
||||
// See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a
|
||||
// See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a
|
||||
// ClassElement and an ObjectLiteralElement.
|
||||
export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
|
||||
_accessorDeclarationBrand: any;
|
||||
@ -575,12 +575,12 @@ module ts {
|
||||
|
||||
export interface StringLiteralTypeNode extends LiteralExpression, TypeNode { }
|
||||
|
||||
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
|
||||
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
|
||||
// Consider 'Expression'. Without the brand, 'Expression' is actually no different
|
||||
// (structurally) than 'Node'. Because of this you can pass any Node to a function that
|
||||
// takes an Expression without any error. By using the 'brands' we ensure that the type
|
||||
// checker actually thinks you have something of the right type. Note: the brands are
|
||||
// never actually given values. At runtime they have zero cost.
|
||||
// checker actually thinks you have something of the right type. Note: the brands are
|
||||
// never actually given values. At runtime they have zero cost.
|
||||
|
||||
export interface Expression extends Node {
|
||||
_expressionBrand: any;
|
||||
@ -653,6 +653,10 @@ module ts {
|
||||
body: Block | Expression; // Required, whereas the member inherited from FunctionDeclaration is optional
|
||||
}
|
||||
|
||||
export interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
equalsGreaterThanToken: Node;
|
||||
}
|
||||
|
||||
// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral,
|
||||
// or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters.
|
||||
// For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1".
|
||||
@ -735,7 +739,7 @@ module ts {
|
||||
}
|
||||
|
||||
export interface VariableStatement extends Statement {
|
||||
declarationList: VariableDeclarationList;
|
||||
declarationList: VariableDeclarationList;
|
||||
}
|
||||
|
||||
export interface ExpressionStatement extends Statement {
|
||||
@ -903,7 +907,7 @@ module ts {
|
||||
moduleSpecifier: Expression;
|
||||
}
|
||||
|
||||
// In case of:
|
||||
// In case of:
|
||||
// import d from "mod" => name = d, namedBinding = undefined
|
||||
// import * as ns from "mod" => name = undefined, namedBinding: NamespaceImport = { name: ns }
|
||||
// import d, * as ns from "mod" => name = d, namedBinding: NamespaceImport = { name: ns }
|
||||
@ -940,7 +944,8 @@ module ts {
|
||||
|
||||
export interface ExportAssignment extends Declaration, ModuleElement {
|
||||
isExportEquals?: boolean;
|
||||
expression: Expression;
|
||||
expression?: Expression;
|
||||
type?: TypeNode;
|
||||
}
|
||||
|
||||
export interface FileReference extends TextRange {
|
||||
@ -969,7 +974,7 @@ module ts {
|
||||
externalModuleIndicator: Node;
|
||||
languageVersion: ScriptTarget;
|
||||
identifiers: Map<string>;
|
||||
|
||||
|
||||
/* @internal */ nodeCount: number;
|
||||
/* @internal */ identifierCount: number;
|
||||
/* @internal */ symbolCount: number;
|
||||
@ -977,10 +982,10 @@ module ts {
|
||||
// File level diagnostics reported by the parser (includes diagnostics about /// references
|
||||
// as well as code diagnostics).
|
||||
/* @internal */ parseDiagnostics: Diagnostic[];
|
||||
|
||||
|
||||
// File level diagnostics reported by the binder.
|
||||
/* @internal */ bindDiagnostics: Diagnostic[];
|
||||
|
||||
|
||||
// Stores a line map for the file.
|
||||
// This field should never be used directly to obtain line map, use getLineMap function instead.
|
||||
/* @internal */ lineMap: number[];
|
||||
@ -1000,10 +1005,10 @@ module ts {
|
||||
getSourceFiles(): SourceFile[];
|
||||
|
||||
/**
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
|
||||
* the javascript and declaration files will be produced for all the files in this program.
|
||||
* If targetSourceFile is specified, then only the javascript and declaration for that
|
||||
* specific file will be generated.
|
||||
* specific file will be generated.
|
||||
*
|
||||
* If writeFile is not specified then the writeFile callback from the compiler host will be
|
||||
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
|
||||
@ -1021,7 +1026,7 @@ module ts {
|
||||
|
||||
getCommonSourceDirectory(): string;
|
||||
|
||||
// For testing purposes only. Should not be used by any other consumers (including the
|
||||
// For testing purposes only. Should not be used by any other consumers (including the
|
||||
// language service).
|
||||
/* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker;
|
||||
|
||||
@ -1058,7 +1063,7 @@ module ts {
|
||||
// when -version or -help was provided, or this was a normal compilation, no diagnostics
|
||||
// were produced, and all outputs were generated successfully.
|
||||
Success = 0,
|
||||
|
||||
|
||||
// Diagnostics were produced and because of them no code was generated.
|
||||
DiagnosticsPresent_OutputsSkipped = 1,
|
||||
|
||||
@ -1168,12 +1173,12 @@ module ts {
|
||||
|
||||
// Write symbols's type argument if it is instantiated symbol
|
||||
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
|
||||
// var a: C<number>;
|
||||
// var a: C<number>;
|
||||
// var p = a.p; <--- Here p is property of C<number> so show it as C<number>.p instead of just C.p
|
||||
WriteTypeParametersOrArguments = 0x00000001,
|
||||
WriteTypeParametersOrArguments = 0x00000001,
|
||||
|
||||
// Use only external alias information to get the symbol name in the given context
|
||||
// eg. module m { export class c { } } import x = m.c;
|
||||
// eg. module m { export class c { } } import x = m.c;
|
||||
// When this flag is specified m.c will be used to refer to the class instead of alias symbol x
|
||||
UseOnlyExternalAliasing = 0x00000002,
|
||||
}
|
||||
@ -1561,8 +1566,9 @@ module ts {
|
||||
target?: ScriptTarget;
|
||||
version?: boolean;
|
||||
watch?: boolean;
|
||||
stripInternal?: boolean;
|
||||
preserveNewLines?: boolean;
|
||||
/* @internal */ stripInternal?: boolean;
|
||||
/* @internal */ preserveNewLines?: boolean;
|
||||
/* @internal */ cacheDownlevelForOfLength?: boolean;
|
||||
[option: string]: string | number | boolean;
|
||||
}
|
||||
|
||||
@ -1780,7 +1786,7 @@ module ts {
|
||||
// Gets a count of how many times this collection has been modified. This value changes
|
||||
// each time 'add' is called (regardless of whether or not an equivalent diagnostic was
|
||||
// already in the collection). As such, it can be used as a simple way to tell if any
|
||||
// operation caused diagnostics to be returned by storing and comparing the return value
|
||||
// operation caused diagnostics to be returned by storing and comparing the return value
|
||||
// of this method before/after the operation is performed.
|
||||
getModificationCount(): number;
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ module ts {
|
||||
}
|
||||
|
||||
export function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration {
|
||||
var declarations = symbol.declarations;
|
||||
let declarations = symbol.declarations;
|
||||
for (let declaration of declarations) {
|
||||
if (declaration.kind === kind) {
|
||||
return declaration;
|
||||
@ -39,12 +39,12 @@ module ts {
|
||||
}
|
||||
|
||||
// Pool writers to avoid needing to allocate them for every symbol we write.
|
||||
var stringWriters: StringSymbolWriter[] = [];
|
||||
let stringWriters: StringSymbolWriter[] = [];
|
||||
export function getSingleLineStringWriter(): StringSymbolWriter {
|
||||
if (stringWriters.length == 0) {
|
||||
var str = "";
|
||||
let str = "";
|
||||
|
||||
var writeText: (text: string) => void = text => str += text;
|
||||
let writeText: (text: string) => void = text => str += text;
|
||||
return {
|
||||
string: () => str,
|
||||
writeKeyword: writeText,
|
||||
@ -88,7 +88,7 @@ module ts {
|
||||
// A node is considered to contain a parse error if:
|
||||
// a) the parser explicitly marked that it had an error
|
||||
// b) any of it's children reported that it had an error.
|
||||
var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & ParserContextFlags.ThisNodeHasError) !== 0) ||
|
||||
let thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & ParserContextFlags.ThisNodeHasError) !== 0) ||
|
||||
forEachChild(node, containsParseError);
|
||||
|
||||
// If so, mark ourselves accordingly.
|
||||
@ -117,8 +117,8 @@ module ts {
|
||||
|
||||
// This is a useful function for debugging purposes.
|
||||
export function nodePosToString(node: Node): string {
|
||||
var file = getSourceFileOfNode(node);
|
||||
var loc = getLineAndCharacterOfPosition(file, node.pos);
|
||||
let file = getSourceFileOfNode(node);
|
||||
let loc = getLineAndCharacterOfPosition(file, node.pos);
|
||||
return `${ file.fileName }(${ loc.line + 1 },${ loc.character + 1 })`;
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ module ts {
|
||||
// missing. This happens whenever the parser knows it needs to parse something, but can't
|
||||
// get anything in the source code that it expects at that location. For example:
|
||||
//
|
||||
// var a: ;
|
||||
// let a: ;
|
||||
//
|
||||
// Here, the Type in the Type-Annotation is not-optional (as there is a colon in the source
|
||||
// code). So the parser will attempt to parse out a type, and will create an actual node.
|
||||
@ -165,7 +165,7 @@ module ts {
|
||||
return "";
|
||||
}
|
||||
|
||||
var text = sourceFile.text;
|
||||
let text = sourceFile.text;
|
||||
return text.substring(skipTrivia(text, node.pos), node.end);
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ module ts {
|
||||
}
|
||||
|
||||
export function getEnclosingBlockScopeContainer(node: Node): Node {
|
||||
var current = node;
|
||||
let current = node;
|
||||
while (current) {
|
||||
if (isFunctionLike(current)) {
|
||||
return current;
|
||||
@ -244,14 +244,14 @@ module ts {
|
||||
}
|
||||
|
||||
export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic {
|
||||
var sourceFile = getSourceFileOfNode(node);
|
||||
var span = getErrorSpanForNode(sourceFile, node);
|
||||
let sourceFile = getSourceFileOfNode(node);
|
||||
let span = getErrorSpanForNode(sourceFile, node);
|
||||
return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
export function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): Diagnostic {
|
||||
var sourceFile = getSourceFileOfNode(node);
|
||||
var span = getErrorSpanForNode(sourceFile, node);
|
||||
let sourceFile = getSourceFileOfNode(node);
|
||||
let span = getErrorSpanForNode(sourceFile, node);
|
||||
return {
|
||||
file: sourceFile,
|
||||
start: span.start,
|
||||
@ -264,15 +264,15 @@ module ts {
|
||||
|
||||
/* @internal */
|
||||
export function getSpanOfTokenAtPosition(sourceFile: SourceFile, pos: number): TextSpan {
|
||||
var scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.text);
|
||||
let scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.text);
|
||||
scanner.setTextPos(pos);
|
||||
scanner.scan();
|
||||
var start = scanner.getTokenPos();
|
||||
let start = scanner.getTokenPos();
|
||||
return createTextSpanFromBounds(start, scanner.getTextPos());
|
||||
}
|
||||
|
||||
export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan {
|
||||
var errorNode = node;
|
||||
let errorNode = node;
|
||||
switch (node.kind) {
|
||||
// This list is a work in progress. Add missing node kinds to improve their error
|
||||
// spans.
|
||||
@ -295,7 +295,7 @@ module ts {
|
||||
return getSpanOfTokenAtPosition(sourceFile, node.pos);
|
||||
}
|
||||
|
||||
var pos = nodeIsMissing(errorNode)
|
||||
let pos = nodeIsMissing(errorNode)
|
||||
? errorNode.pos
|
||||
: skipTrivia(sourceFile.text, errorNode.pos);
|
||||
|
||||
@ -332,7 +332,7 @@ module ts {
|
||||
export function getCombinedNodeFlags(node: Node): NodeFlags {
|
||||
node = walkUpBindingElementsAndPatterns(node);
|
||||
|
||||
var flags = node.flags;
|
||||
let flags = node.flags;
|
||||
if (node.kind === SyntaxKind.VariableDeclaration) {
|
||||
node = node.parent;
|
||||
}
|
||||
@ -389,7 +389,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
export var fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/
|
||||
export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/
|
||||
|
||||
|
||||
// Warning: This has the same semantics as the forEach family of functions,
|
||||
@ -619,7 +619,7 @@ module ts {
|
||||
// fall through
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.StringLiteral:
|
||||
var parent = node.parent;
|
||||
let parent = node.parent;
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
@ -641,13 +641,13 @@ module ts {
|
||||
case SyntaxKind.SwitchStatement:
|
||||
return (<ExpressionStatement>parent).expression === node;
|
||||
case SyntaxKind.ForStatement:
|
||||
var forStatement = <ForStatement>parent;
|
||||
let forStatement = <ForStatement>parent;
|
||||
return (forStatement.initializer === node && forStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) ||
|
||||
forStatement.condition === node ||
|
||||
forStatement.iterator === node;
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.ForOfStatement:
|
||||
var forInStatement = <ForInStatement | ForOfStatement>parent;
|
||||
let forInStatement = <ForInStatement | ForOfStatement>parent;
|
||||
return (forInStatement.initializer === node && forInStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) ||
|
||||
forInStatement.expression === node;
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
@ -666,7 +666,7 @@ module ts {
|
||||
}
|
||||
|
||||
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) {
|
||||
var moduleState = getModuleInstanceState(node)
|
||||
let moduleState = getModuleInstanceState(node)
|
||||
return moduleState === ModuleInstanceState.Instantiated ||
|
||||
(preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly);
|
||||
}
|
||||
@ -689,7 +689,7 @@ module ts {
|
||||
return (<ImportDeclaration>node).moduleSpecifier;
|
||||
}
|
||||
if (node.kind === SyntaxKind.ImportEqualsDeclaration) {
|
||||
var reference = (<ImportEqualsDeclaration>node).moduleReference;
|
||||
let reference = (<ImportEqualsDeclaration>node).moduleReference;
|
||||
if (reference.kind === SyntaxKind.ExternalModuleReference) {
|
||||
return (<ExternalModuleReference>reference).expression;
|
||||
}
|
||||
@ -820,7 +820,7 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
var parent = name.parent;
|
||||
let parent = name.parent;
|
||||
if (parent.kind === SyntaxKind.ImportSpecifier || parent.kind === SyntaxKind.ExportSpecifier) {
|
||||
if ((<ImportOrExportSpecifier>parent).propertyName) {
|
||||
return true;
|
||||
@ -835,17 +835,17 @@ module ts {
|
||||
}
|
||||
|
||||
export function getClassBaseTypeNode(node: ClassDeclaration) {
|
||||
var heritageClause = getHeritageClause(node.heritageClauses, SyntaxKind.ExtendsKeyword);
|
||||
let heritageClause = getHeritageClause(node.heritageClauses, SyntaxKind.ExtendsKeyword);
|
||||
return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined;
|
||||
}
|
||||
|
||||
export function getClassImplementedTypeNodes(node: ClassDeclaration) {
|
||||
var heritageClause = getHeritageClause(node.heritageClauses, SyntaxKind.ImplementsKeyword);
|
||||
let heritageClause = getHeritageClause(node.heritageClauses, SyntaxKind.ImplementsKeyword);
|
||||
return heritageClause ? heritageClause.types : undefined;
|
||||
}
|
||||
|
||||
export function getInterfaceBaseTypeNodes(node: InterfaceDeclaration) {
|
||||
var heritageClause = getHeritageClause(node.heritageClauses, SyntaxKind.ExtendsKeyword);
|
||||
let heritageClause = getHeritageClause(node.heritageClauses, SyntaxKind.ExtendsKeyword);
|
||||
return heritageClause ? heritageClause.types : undefined;
|
||||
}
|
||||
|
||||
@ -863,7 +863,7 @@ module ts {
|
||||
|
||||
export function tryResolveScriptReference(host: ScriptReferenceHost, sourceFile: SourceFile, reference: FileReference) {
|
||||
if (!host.getCompilerOptions().noResolve) {
|
||||
var referenceFileName = isRootedDiskPath(reference.fileName) ? reference.fileName : combinePaths(getDirectoryPath(sourceFile.fileName), reference.fileName);
|
||||
let referenceFileName = isRootedDiskPath(reference.fileName) ? reference.fileName : combinePaths(getDirectoryPath(sourceFile.fileName), reference.fileName);
|
||||
referenceFileName = getNormalizedAbsolutePath(referenceFileName, host.getCurrentDirectory());
|
||||
return host.getSourceFile(referenceFileName);
|
||||
}
|
||||
@ -880,8 +880,8 @@ module ts {
|
||||
}
|
||||
|
||||
export function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult {
|
||||
var simpleReferenceRegEx = /^\/\/\/\s*<reference\s+/gim;
|
||||
var isNoDefaultLibRegEx = /^(\/\/\/\s*<reference\s+no-default-lib\s*=\s*)('|")(.+?)\2\s*\/>/gim;
|
||||
let simpleReferenceRegEx = /^\/\/\/\s*<reference\s+/gim;
|
||||
let isNoDefaultLibRegEx = /^(\/\/\/\s*<reference\s+no-default-lib\s*=\s*)('|")(.+?)\2\s*\/>/gim;
|
||||
if (simpleReferenceRegEx.exec(comment)) {
|
||||
if (isNoDefaultLibRegEx.exec(comment)) {
|
||||
return {
|
||||
@ -889,10 +889,10 @@ module ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
var matchResult = fullTripleSlashReferencePathRegEx.exec(comment);
|
||||
let matchResult = fullTripleSlashReferencePathRegEx.exec(comment);
|
||||
if (matchResult) {
|
||||
var start = commentRange.pos;
|
||||
var end = commentRange.end;
|
||||
let start = commentRange.pos;
|
||||
let end = commentRange.end;
|
||||
return {
|
||||
fileReference: {
|
||||
pos: start,
|
||||
@ -949,9 +949,9 @@ module ts {
|
||||
return (<Identifier | LiteralExpression>name).text;
|
||||
}
|
||||
if (name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
var nameExpression = (<ComputedPropertyName>name).expression;
|
||||
let nameExpression = (<ComputedPropertyName>name).expression;
|
||||
if (isWellKnownSymbolSyntactically(nameExpression)) {
|
||||
var rightHandSideName = (<PropertyAccessExpression>nameExpression).name.text;
|
||||
let rightHandSideName = (<PropertyAccessExpression>nameExpression).name.text;
|
||||
return getPropertyNameForKnownSymbolName(rightHandSideName);
|
||||
}
|
||||
}
|
||||
@ -1003,14 +1003,14 @@ module ts {
|
||||
}
|
||||
|
||||
export function textSpanOverlapsWith(span: TextSpan, other: TextSpan) {
|
||||
var overlapStart = Math.max(span.start, other.start);
|
||||
var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other));
|
||||
let overlapStart = Math.max(span.start, other.start);
|
||||
let overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other));
|
||||
return overlapStart < overlapEnd;
|
||||
}
|
||||
|
||||
export function textSpanOverlap(span1: TextSpan, span2: TextSpan) {
|
||||
var overlapStart = Math.max(span1.start, span2.start);
|
||||
var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
|
||||
let overlapStart = Math.max(span1.start, span2.start);
|
||||
let overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
|
||||
if (overlapStart < overlapEnd) {
|
||||
return createTextSpanFromBounds(overlapStart, overlapEnd);
|
||||
}
|
||||
@ -1022,7 +1022,7 @@ module ts {
|
||||
}
|
||||
|
||||
export function textSpanIntersectsWith(span: TextSpan, start: number, length: number) {
|
||||
var end = start + length;
|
||||
let end = start + length;
|
||||
return start <= textSpanEnd(span) && end >= span.start;
|
||||
}
|
||||
|
||||
@ -1031,8 +1031,8 @@ module ts {
|
||||
}
|
||||
|
||||
export function textSpanIntersection(span1: TextSpan, span2: TextSpan) {
|
||||
var intersectStart = Math.max(span1.start, span2.start);
|
||||
var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
|
||||
let intersectStart = Math.max(span1.start, span2.start);
|
||||
let intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
|
||||
if (intersectStart <= intersectEnd) {
|
||||
return createTextSpanFromBounds(intersectStart, intersectEnd);
|
||||
}
|
||||
@ -1070,7 +1070,7 @@ module ts {
|
||||
return { span, newLength };
|
||||
}
|
||||
|
||||
export var unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0);
|
||||
export let unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0);
|
||||
|
||||
/**
|
||||
* Called to merge all the changes that occurred across several versions of a script snapshot
|
||||
@ -1091,14 +1091,14 @@ module ts {
|
||||
|
||||
// We change from talking about { { oldStart, oldLength }, newLength } to { oldStart, oldEnd, newEnd }
|
||||
// as it makes things much easier to reason about.
|
||||
var change0 = changes[0];
|
||||
let change0 = changes[0];
|
||||
|
||||
var oldStartN = change0.span.start;
|
||||
var oldEndN = textSpanEnd(change0.span);
|
||||
var newEndN = oldStartN + change0.newLength;
|
||||
let oldStartN = change0.span.start;
|
||||
let oldEndN = textSpanEnd(change0.span);
|
||||
let newEndN = oldStartN + change0.newLength;
|
||||
|
||||
for (var i = 1; i < changes.length; i++) {
|
||||
var nextChange = changes[i];
|
||||
for (let i = 1; i < changes.length; i++) {
|
||||
let nextChange = changes[i];
|
||||
|
||||
// Consider the following case:
|
||||
// i.e. two edits. The first represents the text change range { { 10, 50 }, 30 }. i.e. The span starting
|
||||
@ -1180,13 +1180,13 @@ module ts {
|
||||
// newEnd3 : Max(newEnd2, newEnd2 + (newEnd1 - oldEnd2))
|
||||
// }
|
||||
|
||||
var oldStart1 = oldStartN;
|
||||
var oldEnd1 = oldEndN;
|
||||
var newEnd1 = newEndN;
|
||||
let oldStart1 = oldStartN;
|
||||
let oldEnd1 = oldEndN;
|
||||
let newEnd1 = newEndN;
|
||||
|
||||
var oldStart2 = nextChange.span.start;
|
||||
var oldEnd2 = textSpanEnd(nextChange.span);
|
||||
var newEnd2 = oldStart2 + nextChange.newLength;
|
||||
let oldStart2 = nextChange.span.start;
|
||||
let oldEnd2 = textSpanEnd(nextChange.span);
|
||||
let newEnd2 = oldStart2 + nextChange.newLength;
|
||||
|
||||
oldStartN = Math.min(oldStart1, oldStart2);
|
||||
oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1));
|
||||
@ -1205,7 +1205,7 @@ module ts {
|
||||
}
|
||||
|
||||
export function createSynthesizedNode(kind: SyntaxKind, startsOnNewLine?: boolean): Node {
|
||||
var node = <SynthesizedNode>createNode(kind);
|
||||
let node = <SynthesizedNode>createNode(kind);
|
||||
node.pos = -1;
|
||||
node.end = -1;
|
||||
node.startsOnNewLine = startsOnNewLine;
|
||||
@ -1215,7 +1215,7 @@ module ts {
|
||||
export function generateUniqueName(baseName: string, isExistingName: (name: string) => boolean): string {
|
||||
// First try '_name'
|
||||
if (baseName.charCodeAt(0) !== CharacterCodes._) {
|
||||
var baseName = "_" + baseName;
|
||||
baseName = "_" + baseName;
|
||||
if (!isExistingName(baseName)) {
|
||||
return baseName;
|
||||
}
|
||||
@ -1224,9 +1224,9 @@ module ts {
|
||||
if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) {
|
||||
baseName += "_";
|
||||
}
|
||||
var i = 1;
|
||||
let i = 1;
|
||||
while (true) {
|
||||
var name = baseName + i;
|
||||
let name = baseName + i;
|
||||
if (!isExistingName(name)) {
|
||||
return name;
|
||||
}
|
||||
@ -1236,11 +1236,11 @@ module ts {
|
||||
|
||||
// @internal
|
||||
export function createDiagnosticCollection(): DiagnosticCollection {
|
||||
var nonFileDiagnostics: Diagnostic[] = [];
|
||||
var fileDiagnostics: Map<Diagnostic[]> = {};
|
||||
let nonFileDiagnostics: Diagnostic[] = [];
|
||||
let fileDiagnostics: Map<Diagnostic[]> = {};
|
||||
|
||||
var diagnosticsModified = false;
|
||||
var modificationCount = 0;
|
||||
let diagnosticsModified = false;
|
||||
let modificationCount = 0;
|
||||
|
||||
return {
|
||||
add,
|
||||
@ -1254,7 +1254,7 @@ module ts {
|
||||
}
|
||||
|
||||
function add(diagnostic: Diagnostic): void {
|
||||
var diagnostics: Diagnostic[];
|
||||
let diagnostics: Diagnostic[];
|
||||
if (diagnostic.file) {
|
||||
diagnostics = fileDiagnostics[diagnostic.file.fileName];
|
||||
if (!diagnostics) {
|
||||
@ -1282,14 +1282,14 @@ module ts {
|
||||
return fileDiagnostics[fileName] || [];
|
||||
}
|
||||
|
||||
var allDiagnostics: Diagnostic[] = [];
|
||||
let allDiagnostics: Diagnostic[] = [];
|
||||
function pushDiagnostic(d: Diagnostic) {
|
||||
allDiagnostics.push(d);
|
||||
}
|
||||
|
||||
forEach(nonFileDiagnostics, pushDiagnostic);
|
||||
|
||||
for (var key in fileDiagnostics) {
|
||||
for (let key in fileDiagnostics) {
|
||||
if (hasProperty(fileDiagnostics, key)) {
|
||||
forEach(fileDiagnostics[key], pushDiagnostic);
|
||||
}
|
||||
@ -1306,7 +1306,7 @@ module ts {
|
||||
diagnosticsModified = false;
|
||||
nonFileDiagnostics = sortAndDeduplicateDiagnostics(nonFileDiagnostics);
|
||||
|
||||
for (var key in fileDiagnostics) {
|
||||
for (let key in fileDiagnostics) {
|
||||
if (hasProperty(fileDiagnostics, key)) {
|
||||
fileDiagnostics[key] = sortAndDeduplicateDiagnostics(fileDiagnostics[key]);
|
||||
}
|
||||
@ -1319,8 +1319,8 @@ module ts {
|
||||
// the language service. These characters should be escaped when printing, and if any characters are added,
|
||||
// the map below must be updated. Note that this regexp *does not* include the 'delete' character.
|
||||
// There is no reason for this other than that JSON.stringify does not handle it either.
|
||||
var escapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
|
||||
var escapedCharsMap: Map<string> = {
|
||||
let escapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
|
||||
let escapedCharsMap: Map<string> = {
|
||||
"\0": "\\0",
|
||||
"\t": "\\t",
|
||||
"\v": "\\v",
|
||||
@ -1351,12 +1351,12 @@ module ts {
|
||||
}
|
||||
|
||||
function get16BitUnicodeEscapeSequence(charCode: number): string {
|
||||
var hexCharCode = charCode.toString(16).toUpperCase();
|
||||
var paddedHexCode = ("0000" + hexCharCode).slice(-4);
|
||||
let hexCharCode = charCode.toString(16).toUpperCase();
|
||||
let paddedHexCode = ("0000" + hexCharCode).slice(-4);
|
||||
return "\\u" + paddedHexCode;
|
||||
}
|
||||
|
||||
var nonAsciiCharacters = /[^\u0000-\u007F]/g;
|
||||
let nonAsciiCharacters = /[^\u0000-\u007F]/g;
|
||||
export function escapeNonAsciiCharacters(s: string): string {
|
||||
// Replace non-ASCII characters with '\uNNNN' escapes if any exist.
|
||||
// Otherwise just return the original string.
|
||||
|
||||
@ -173,6 +173,10 @@ module ts.BreakpointResolver {
|
||||
return textSpan(node, (<ThrowStatement>node).expression);
|
||||
|
||||
case SyntaxKind.ExportAssignment:
|
||||
if (!(<ExportAssignment>node).expression) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// span on export = id
|
||||
return textSpan(node, (<ExportAssignment>node).expression);
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ module ts.formatting {
|
||||
* Indentation for the scope that can be dynamically recomputed.
|
||||
* i.e
|
||||
* while(true)
|
||||
* { var x;
|
||||
* { let x;
|
||||
* }
|
||||
* Normally indentation is applied only to the first token in line so at glance 'var' should not be touched.
|
||||
* However if some format rule adds new line between '}' and 'var' 'var' will become
|
||||
@ -67,12 +67,12 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
export function formatOnEnter(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeOptions): TextChange[] {
|
||||
var line = sourceFile.getLineAndCharacterOfPosition(position).line;
|
||||
let line = sourceFile.getLineAndCharacterOfPosition(position).line;
|
||||
if (line === 0) {
|
||||
return [];
|
||||
}
|
||||
// get the span for the previous\current line
|
||||
var span = {
|
||||
let span = {
|
||||
// get start position for the previous line
|
||||
pos: getStartPositionOfLine(line - 1, sourceFile),
|
||||
// get end position for the current line (end value is exclusive so add 1 to the result)
|
||||
@ -90,7 +90,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
export function formatDocument(sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeOptions): TextChange[] {
|
||||
var span = {
|
||||
let span = {
|
||||
pos: 0,
|
||||
end: sourceFile.text.length
|
||||
};
|
||||
@ -99,7 +99,7 @@ module ts.formatting {
|
||||
|
||||
export function formatSelection(start: number, end: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeOptions): TextChange[] {
|
||||
// format from the beginning of the line
|
||||
var span = {
|
||||
let span = {
|
||||
pos: getLineStartPositionForPosition(start, sourceFile),
|
||||
end: end
|
||||
};
|
||||
@ -107,11 +107,11 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
function formatOutermostParent(position: number, expectedLastToken: SyntaxKind, sourceFile: SourceFile, options: FormatCodeOptions, rulesProvider: RulesProvider, requestKind: FormattingRequestKind): TextChange[] {
|
||||
var parent = findOutermostParent(position, expectedLastToken, sourceFile);
|
||||
let parent = findOutermostParent(position, expectedLastToken, sourceFile);
|
||||
if (!parent) {
|
||||
return [];
|
||||
}
|
||||
var span = {
|
||||
let span = {
|
||||
pos: getLineStartPositionForPosition(parent.getStart(sourceFile), sourceFile),
|
||||
end: parent.end
|
||||
};
|
||||
@ -119,7 +119,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
function findOutermostParent(position: number, expectedTokenKind: SyntaxKind, sourceFile: SourceFile): Node {
|
||||
var precedingToken = findPrecedingToken(position, sourceFile);
|
||||
let precedingToken = findPrecedingToken(position, sourceFile);
|
||||
|
||||
// when it is claimed that trigger character was typed at given position
|
||||
// we verify that there is a token with a matching kind whose end is equal to position (because the character was just typed).
|
||||
@ -134,13 +134,13 @@ module ts.formatting {
|
||||
// walk up and search for the parent node that ends at the same position with precedingToken.
|
||||
// for cases like this
|
||||
//
|
||||
// var x = 1;
|
||||
// let x = 1;
|
||||
// while (true) {
|
||||
// }
|
||||
// after typing close curly in while statement we want to reformat just the while statement.
|
||||
// However if we just walk upwards searching for the parent that has the same end value -
|
||||
// we'll end up with the whole source file. isListElement allows to stop on the list element level
|
||||
var current = precedingToken;
|
||||
let current = precedingToken;
|
||||
while (current &&
|
||||
current.parent &&
|
||||
current.parent.end === precedingToken.end &&
|
||||
@ -159,7 +159,7 @@ module ts.formatting {
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
return rangeContainsRange((<InterfaceDeclaration>parent).members, node);
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
var body = (<ModuleDeclaration>parent).body;
|
||||
let body = (<ModuleDeclaration>parent).body;
|
||||
return body && body.kind === SyntaxKind.Block && rangeContainsRange((<Block>body).statements, node);
|
||||
case SyntaxKind.SourceFile:
|
||||
case SyntaxKind.Block:
|
||||
@ -177,9 +177,9 @@ module ts.formatting {
|
||||
return find(sourceFile);
|
||||
|
||||
function find(n: Node): Node {
|
||||
var candidate = forEachChild(n, c => startEndContainsRange(c.getStart(sourceFile), c.end, range) && c);
|
||||
let candidate = forEachChild(n, c => startEndContainsRange(c.getStart(sourceFile), c.end, range) && c);
|
||||
if (candidate) {
|
||||
var result = find(candidate);
|
||||
let result = find(candidate);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
@ -199,7 +199,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
// pick only errors that fall in range
|
||||
var sorted = errors
|
||||
let sorted = errors
|
||||
.filter(d => rangeOverlapsWithStartEnd(originalRange, d.start, d.start + d.length))
|
||||
.sort((e1, e2) => e1.start - e2.start);
|
||||
|
||||
@ -207,7 +207,7 @@ module ts.formatting {
|
||||
return rangeHasNoErrors;
|
||||
}
|
||||
|
||||
var index = 0;
|
||||
let index = 0;
|
||||
|
||||
return r => {
|
||||
// in current implementation sequence of arguments [r1, r2...] is monotonically increasing.
|
||||
@ -218,7 +218,7 @@ module ts.formatting {
|
||||
return false;
|
||||
}
|
||||
|
||||
var error = sorted[index];
|
||||
let error = sorted[index];
|
||||
if (r.end <= error.start) {
|
||||
// specified range ends before the error refered by 'index' - no error in range
|
||||
return false;
|
||||
@ -244,12 +244,12 @@ module ts.formatting {
|
||||
* and return its end as start position for the scanner.
|
||||
*/
|
||||
function getScanStartPosition(enclosingNode: Node, originalRange: TextRange, sourceFile: SourceFile): number {
|
||||
var start = enclosingNode.getStart(sourceFile);
|
||||
let start = enclosingNode.getStart(sourceFile);
|
||||
if (start === originalRange.pos && enclosingNode.end === originalRange.end) {
|
||||
return start;
|
||||
}
|
||||
|
||||
var precedingToken = findPrecedingToken(originalRange.pos, sourceFile);
|
||||
let precedingToken = findPrecedingToken(originalRange.pos, sourceFile);
|
||||
if (!precedingToken) {
|
||||
// no preceding token found - start from the beginning of enclosing node
|
||||
return enclosingNode.pos;
|
||||
@ -280,10 +280,10 @@ module ts.formatting {
|
||||
* to the initial indentation.
|
||||
*/
|
||||
function getOwnOrInheritedDelta(n: Node, options: FormatCodeOptions, sourceFile: SourceFile): number {
|
||||
var previousLine = Constants.Unknown;
|
||||
var childKind = SyntaxKind.Unknown;
|
||||
let previousLine = Constants.Unknown;
|
||||
let childKind = SyntaxKind.Unknown;
|
||||
while (n) {
|
||||
var line = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)).line;
|
||||
let line = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)).line;
|
||||
if (previousLine !== Constants.Unknown && line !== previousLine) {
|
||||
break;
|
||||
}
|
||||
@ -305,30 +305,30 @@ module ts.formatting {
|
||||
rulesProvider: RulesProvider,
|
||||
requestKind: FormattingRequestKind): TextChange[] {
|
||||
|
||||
var rangeContainsError = prepareRangeContainsErrorFunction(sourceFile.parseDiagnostics, originalRange);
|
||||
let rangeContainsError = prepareRangeContainsErrorFunction(sourceFile.parseDiagnostics, originalRange);
|
||||
|
||||
// formatting context is used by rules provider
|
||||
var formattingContext = new FormattingContext(sourceFile, requestKind);
|
||||
let formattingContext = new FormattingContext(sourceFile, requestKind);
|
||||
|
||||
// find the smallest node that fully wraps the range and compute the initial indentation for the node
|
||||
var enclosingNode = findEnclosingNode(originalRange, sourceFile);
|
||||
let enclosingNode = findEnclosingNode(originalRange, sourceFile);
|
||||
|
||||
var formattingScanner = getFormattingScanner(sourceFile, getScanStartPosition(enclosingNode, originalRange, sourceFile), originalRange.end);
|
||||
let formattingScanner = getFormattingScanner(sourceFile, getScanStartPosition(enclosingNode, originalRange, sourceFile), originalRange.end);
|
||||
|
||||
var initialIndentation = SmartIndenter.getIndentationForNode(enclosingNode, originalRange, sourceFile, options);
|
||||
let initialIndentation = SmartIndenter.getIndentationForNode(enclosingNode, originalRange, sourceFile, options);
|
||||
|
||||
var previousRangeHasError: boolean;
|
||||
var previousRange: TextRangeWithKind;
|
||||
var previousParent: Node;
|
||||
var previousRangeStartLine: number;
|
||||
let previousRangeHasError: boolean;
|
||||
let previousRange: TextRangeWithKind;
|
||||
let previousParent: Node;
|
||||
let previousRangeStartLine: number;
|
||||
|
||||
var edits: TextChange[] = [];
|
||||
let edits: TextChange[] = [];
|
||||
|
||||
formattingScanner.advance();
|
||||
|
||||
if (formattingScanner.isOnToken()) {
|
||||
var startLine = sourceFile.getLineAndCharacterOfPosition(enclosingNode.getStart(sourceFile)).line;
|
||||
var delta = getOwnOrInheritedDelta(enclosingNode, options, sourceFile);
|
||||
let startLine = sourceFile.getLineAndCharacterOfPosition(enclosingNode.getStart(sourceFile)).line;
|
||||
let delta = getOwnOrInheritedDelta(enclosingNode, options, sourceFile);
|
||||
processNode(enclosingNode, enclosingNode, startLine, initialIndentation, delta);
|
||||
}
|
||||
|
||||
@ -357,9 +357,9 @@ module ts.formatting {
|
||||
}
|
||||
}
|
||||
else {
|
||||
var startLine = sourceFile.getLineAndCharacterOfPosition(startPos).line;
|
||||
var startLinePosition = getLineStartPositionForPosition(startPos, sourceFile);
|
||||
var column = SmartIndenter.findFirstNonWhitespaceColumn(startLinePosition, startPos, sourceFile, options);
|
||||
let startLine = sourceFile.getLineAndCharacterOfPosition(startPos).line;
|
||||
let startLinePosition = getLineStartPositionForPosition(startPos, sourceFile);
|
||||
let column = SmartIndenter.findFirstNonWhitespaceColumn(startLinePosition, startPos, sourceFile, options);
|
||||
if (startLine !== parentStartLine || startPos === column) {
|
||||
return column
|
||||
}
|
||||
@ -376,7 +376,7 @@ module ts.formatting {
|
||||
parentDynamicIndentation: DynamicIndentation,
|
||||
effectiveParentStartLine: number): Indentation {
|
||||
|
||||
var indentation = inheritedIndentation;
|
||||
let indentation = inheritedIndentation;
|
||||
if (indentation === Constants.Unknown) {
|
||||
if (isSomeBlock(node.kind)) {
|
||||
// blocks should be indented in
|
||||
@ -475,7 +475,7 @@ module ts.formatting {
|
||||
return;
|
||||
}
|
||||
|
||||
var nodeDynamicIndentation = getDynamicIndentation(node, nodeStartLine, indentation, delta);
|
||||
let nodeDynamicIndentation = getDynamicIndentation(node, nodeStartLine, indentation, delta);
|
||||
|
||||
// a useful observations when tracking context node
|
||||
// /
|
||||
@ -489,7 +489,7 @@ module ts.formatting {
|
||||
// context node is set to parent node value after processing every child node
|
||||
// context node is set to parent of the token after processing every token
|
||||
|
||||
var childContextNode = contextNode;
|
||||
let childContextNode = contextNode;
|
||||
|
||||
// if there are any tokens that logically belong to node and interleave child nodes
|
||||
// such tokens will be consumed in processChildNode for for the child that follows them
|
||||
@ -504,7 +504,7 @@ module ts.formatting {
|
||||
|
||||
// proceed any tokens in the node that are located after child nodes
|
||||
while (formattingScanner.isOnToken()) {
|
||||
var tokenInfo = formattingScanner.readTokenInfo(node);
|
||||
let tokenInfo = formattingScanner.readTokenInfo(node);
|
||||
if (tokenInfo.token.end > node.end) {
|
||||
break;
|
||||
}
|
||||
@ -519,12 +519,12 @@ module ts.formatting {
|
||||
parentStartLine: number,
|
||||
isListItem: boolean): number {
|
||||
|
||||
var childStartPos = child.getStart(sourceFile);
|
||||
let childStartPos = child.getStart(sourceFile);
|
||||
|
||||
var childStart = sourceFile.getLineAndCharacterOfPosition(childStartPos);
|
||||
let childStart = sourceFile.getLineAndCharacterOfPosition(childStartPos);
|
||||
|
||||
// if child is a list item - try to get its indentation
|
||||
var childIndentationAmount = Constants.Unknown;
|
||||
let childIndentationAmount = Constants.Unknown;
|
||||
if (isListItem) {
|
||||
childIndentationAmount = tryComputeIndentationForListItem(childStartPos, child.end, parentStartLine, originalRange, inheritedIndentation);
|
||||
if (childIndentationAmount !== Constants.Unknown) {
|
||||
@ -543,7 +543,7 @@ module ts.formatting {
|
||||
|
||||
while (formattingScanner.isOnToken()) {
|
||||
// proceed any parent tokens that are located prior to child.getStart()
|
||||
var tokenInfo = formattingScanner.readTokenInfo(node);
|
||||
let tokenInfo = formattingScanner.readTokenInfo(node);
|
||||
if (tokenInfo.token.end > childStartPos) {
|
||||
// stop when formatting scanner advances past the beginning of the child
|
||||
break;
|
||||
@ -558,13 +558,13 @@ module ts.formatting {
|
||||
|
||||
if (isToken(child)) {
|
||||
// if child node is a token, it does not impact indentation, proceed it using parent indentation scope rules
|
||||
var tokenInfo = formattingScanner.readTokenInfo(child);
|
||||
let tokenInfo = formattingScanner.readTokenInfo(child);
|
||||
Debug.assert(tokenInfo.token.end === child.end);
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation);
|
||||
return inheritedIndentation;
|
||||
}
|
||||
|
||||
var childIndentation = computeIndentation(child, childStart.line, childIndentationAmount, node, parentDynamicIndentation, parentStartLine);
|
||||
let childIndentation = computeIndentation(child, childStart.line, childIndentationAmount, node, parentDynamicIndentation, parentStartLine);
|
||||
|
||||
processNode(child, childContextNode, childStart.line, childIndentation.indentation, childIndentation.delta);
|
||||
|
||||
@ -578,16 +578,16 @@ module ts.formatting {
|
||||
parentStartLine: number,
|
||||
parentDynamicIndentation: DynamicIndentation): void {
|
||||
|
||||
var listStartToken = getOpenTokenForList(parent, nodes);
|
||||
var listEndToken = getCloseTokenForOpenToken(listStartToken);
|
||||
let listStartToken = getOpenTokenForList(parent, nodes);
|
||||
let listEndToken = getCloseTokenForOpenToken(listStartToken);
|
||||
|
||||
var listDynamicIndentation = parentDynamicIndentation;
|
||||
var startLine = parentStartLine;
|
||||
let listDynamicIndentation = parentDynamicIndentation;
|
||||
let startLine = parentStartLine;
|
||||
|
||||
if (listStartToken !== SyntaxKind.Unknown) {
|
||||
// introduce a new indentation scope for lists (including list start and end tokens)
|
||||
while (formattingScanner.isOnToken()) {
|
||||
var tokenInfo = formattingScanner.readTokenInfo(parent);
|
||||
let tokenInfo = formattingScanner.readTokenInfo(parent);
|
||||
if (tokenInfo.token.end > nodes.pos) {
|
||||
// stop when formatting scanner moves past the beginning of node list
|
||||
break;
|
||||
@ -595,7 +595,7 @@ module ts.formatting {
|
||||
else if (tokenInfo.token.kind === listStartToken) {
|
||||
// consume list start token
|
||||
startLine = sourceFile.getLineAndCharacterOfPosition(tokenInfo.token.pos).line;
|
||||
var indentation =
|
||||
let indentation =
|
||||
computeIndentation(tokenInfo.token, startLine, Constants.Unknown, parent, parentDynamicIndentation, startLine);
|
||||
|
||||
listDynamicIndentation = getDynamicIndentation(parent, parentStartLine, indentation.indentation, indentation.delta);
|
||||
@ -608,14 +608,14 @@ module ts.formatting {
|
||||
}
|
||||
}
|
||||
|
||||
var inheritedIndentation = Constants.Unknown;
|
||||
let inheritedIndentation = Constants.Unknown;
|
||||
for (let child of nodes) {
|
||||
inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, /*isListElement*/ true)
|
||||
}
|
||||
|
||||
if (listEndToken !== SyntaxKind.Unknown) {
|
||||
if (formattingScanner.isOnToken()) {
|
||||
var tokenInfo = formattingScanner.readTokenInfo(parent);
|
||||
let tokenInfo = formattingScanner.readTokenInfo(parent);
|
||||
// consume the list end token only if it is still belong to the parent
|
||||
// there might be the case when current token matches end token but does not considered as one
|
||||
// function (x: function) <--
|
||||
@ -631,21 +631,21 @@ module ts.formatting {
|
||||
function consumeTokenAndAdvanceScanner(currentTokenInfo: TokenInfo, parent: Node, dynamicIndentation: DynamicIndentation): void {
|
||||
Debug.assert(rangeContainsRange(parent, currentTokenInfo.token));
|
||||
|
||||
var lastTriviaWasNewLine = formattingScanner.lastTrailingTriviaWasNewLine();
|
||||
var indentToken = false;
|
||||
let lastTriviaWasNewLine = formattingScanner.lastTrailingTriviaWasNewLine();
|
||||
let indentToken = false;
|
||||
|
||||
if (currentTokenInfo.leadingTrivia) {
|
||||
processTrivia(currentTokenInfo.leadingTrivia, parent, childContextNode, dynamicIndentation);
|
||||
}
|
||||
|
||||
var lineAdded: boolean;
|
||||
var isTokenInRange = rangeContainsRange(originalRange, currentTokenInfo.token);
|
||||
let lineAdded: boolean;
|
||||
let isTokenInRange = rangeContainsRange(originalRange, currentTokenInfo.token);
|
||||
|
||||
var tokenStart = sourceFile.getLineAndCharacterOfPosition(currentTokenInfo.token.pos);
|
||||
let tokenStart = sourceFile.getLineAndCharacterOfPosition(currentTokenInfo.token.pos);
|
||||
if (isTokenInRange) {
|
||||
var rangeHasError = rangeContainsError(currentTokenInfo.token);
|
||||
let rangeHasError = rangeContainsError(currentTokenInfo.token);
|
||||
// save prevStartLine since processRange will overwrite this value with current ones
|
||||
var prevStartLine = previousRangeStartLine;
|
||||
let prevStartLine = previousRangeStartLine;
|
||||
lineAdded = processRange(currentTokenInfo.token, tokenStart, parent, childContextNode, dynamicIndentation);
|
||||
if (rangeHasError) {
|
||||
// do not indent comments\token if token range overlaps with some error
|
||||
@ -666,23 +666,23 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
if (indentToken) {
|
||||
var indentNextTokenOrTrivia = true;
|
||||
let indentNextTokenOrTrivia = true;
|
||||
if (currentTokenInfo.leadingTrivia) {
|
||||
for (let triviaItem of currentTokenInfo.leadingTrivia) {
|
||||
if (!rangeContainsRange(originalRange, triviaItem)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var triviaStartLine = sourceFile.getLineAndCharacterOfPosition(triviaItem.pos).line;
|
||||
let triviaStartLine = sourceFile.getLineAndCharacterOfPosition(triviaItem.pos).line;
|
||||
switch (triviaItem.kind) {
|
||||
case SyntaxKind.MultiLineCommentTrivia:
|
||||
var commentIndentation = dynamicIndentation.getIndentationForComment(currentTokenInfo.token.kind);
|
||||
let commentIndentation = dynamicIndentation.getIndentationForComment(currentTokenInfo.token.kind);
|
||||
indentMultilineComment(triviaItem, commentIndentation, /*firstLineIsIndented*/ !indentNextTokenOrTrivia);
|
||||
indentNextTokenOrTrivia = false;
|
||||
break;
|
||||
case SyntaxKind.SingleLineCommentTrivia:
|
||||
if (indentNextTokenOrTrivia) {
|
||||
var commentIndentation = dynamicIndentation.getIndentationForComment(currentTokenInfo.token.kind);
|
||||
let commentIndentation = dynamicIndentation.getIndentationForComment(currentTokenInfo.token.kind);
|
||||
insertIndentation(triviaItem.pos, commentIndentation, /*lineAdded*/ false);
|
||||
indentNextTokenOrTrivia = false;
|
||||
}
|
||||
@ -696,7 +696,7 @@ module ts.formatting {
|
||||
|
||||
// indent token only if is it is in target range and does not overlap with any error ranges
|
||||
if (isTokenInRange && !rangeContainsError(currentTokenInfo.token)) {
|
||||
var tokenIndentation = dynamicIndentation.getIndentationForToken(tokenStart.line, currentTokenInfo.token.kind);
|
||||
let tokenIndentation = dynamicIndentation.getIndentationForToken(tokenStart.line, currentTokenInfo.token.kind);
|
||||
insertIndentation(currentTokenInfo.token.pos, tokenIndentation, lineAdded);
|
||||
}
|
||||
}
|
||||
@ -710,7 +710,7 @@ module ts.formatting {
|
||||
function processTrivia(trivia: TextRangeWithKind[], parent: Node, contextNode: Node, dynamicIndentation: DynamicIndentation): void {
|
||||
for (let triviaItem of trivia) {
|
||||
if (isComment(triviaItem.kind) && rangeContainsRange(originalRange, triviaItem)) {
|
||||
var triviaItemStart = sourceFile.getLineAndCharacterOfPosition(triviaItem.pos);
|
||||
let triviaItemStart = sourceFile.getLineAndCharacterOfPosition(triviaItem.pos);
|
||||
processRange(triviaItem, triviaItemStart, parent, contextNode, dynamicIndentation);
|
||||
}
|
||||
}
|
||||
@ -722,12 +722,12 @@ module ts.formatting {
|
||||
contextNode: Node,
|
||||
dynamicIndentation: DynamicIndentation): boolean {
|
||||
|
||||
var rangeHasError = rangeContainsError(range);
|
||||
var lineAdded: boolean;
|
||||
let rangeHasError = rangeContainsError(range);
|
||||
let lineAdded: boolean;
|
||||
if (!rangeHasError && !previousRangeHasError) {
|
||||
if (!previousRange) {
|
||||
// trim whitespaces starting from the beginning of the span up to the current line
|
||||
var originalStart = sourceFile.getLineAndCharacterOfPosition(originalRange.pos);
|
||||
let originalStart = sourceFile.getLineAndCharacterOfPosition(originalRange.pos);
|
||||
trimTrailingWhitespacesForLines(originalStart.line, rangeStart.line);
|
||||
}
|
||||
else {
|
||||
@ -755,10 +755,10 @@ module ts.formatting {
|
||||
|
||||
formattingContext.updateContext(previousItem, previousParent, currentItem, currentParent, contextNode);
|
||||
|
||||
var rule = rulesProvider.getRulesMap().GetRule(formattingContext);
|
||||
let rule = rulesProvider.getRulesMap().GetRule(formattingContext);
|
||||
|
||||
var trimTrailingWhitespaces: boolean;
|
||||
var lineAdded: boolean;
|
||||
let trimTrailingWhitespaces: boolean;
|
||||
let lineAdded: boolean;
|
||||
if (rule) {
|
||||
applyRuleEdits(rule, previousItem, previousStartLine, currentItem, currentStartLine);
|
||||
|
||||
@ -798,16 +798,16 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
function insertIndentation(pos: number, indentation: number, lineAdded: boolean): void {
|
||||
var indentationString = getIndentationString(indentation, options);
|
||||
let indentationString = getIndentationString(indentation, options);
|
||||
if (lineAdded) {
|
||||
// new line is added before the token by the formatting rules
|
||||
// insert indentation string at the very beginning of the token
|
||||
recordReplace(pos, 0, indentationString);
|
||||
}
|
||||
else {
|
||||
var tokenStart = sourceFile.getLineAndCharacterOfPosition(pos);
|
||||
let tokenStart = sourceFile.getLineAndCharacterOfPosition(pos);
|
||||
if (indentation !== tokenStart.character) {
|
||||
var startLinePosition = getStartPositionOfLine(tokenStart.line, sourceFile);
|
||||
let startLinePosition = getStartPositionOfLine(tokenStart.line, sourceFile);
|
||||
recordReplace(startLinePosition, tokenStart.character, indentationString);
|
||||
}
|
||||
}
|
||||
@ -815,9 +815,9 @@ module ts.formatting {
|
||||
|
||||
function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean) {
|
||||
// split comment in lines
|
||||
var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
|
||||
var endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line;
|
||||
|
||||
let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
|
||||
let endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line;
|
||||
let parts: TextRange[];
|
||||
if (startLine === endLine) {
|
||||
if (!firstLineIsIndented) {
|
||||
// treat as single line comment
|
||||
@ -826,10 +826,10 @@ module ts.formatting {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
var parts: TextRange[] = [];
|
||||
var startPos = commentRange.pos;
|
||||
for (var line = startLine; line < endLine; ++line) {
|
||||
var endOfLine = getEndLinePosition(line, sourceFile);
|
||||
parts = [];
|
||||
let startPos = commentRange.pos;
|
||||
for (let line = startLine; line < endLine; ++line) {
|
||||
let endOfLine = getEndLinePosition(line, sourceFile);
|
||||
parts.push({ pos: startPos, end: endOfLine });
|
||||
startPos = getStartPositionOfLine(line + 1, sourceFile);
|
||||
}
|
||||
@ -837,33 +837,33 @@ module ts.formatting {
|
||||
parts.push({ pos: startPos, end: commentRange.end });
|
||||
}
|
||||
|
||||
var startLinePos = getStartPositionOfLine(startLine, sourceFile);
|
||||
let startLinePos = getStartPositionOfLine(startLine, sourceFile);
|
||||
|
||||
var nonWhitespaceColumnInFirstPart =
|
||||
let nonWhitespaceColumnInFirstPart =
|
||||
SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options);
|
||||
|
||||
if (indentation === nonWhitespaceColumnInFirstPart.column) {
|
||||
return;
|
||||
}
|
||||
|
||||
var startIndex = 0;
|
||||
let startIndex = 0;
|
||||
if (firstLineIsIndented) {
|
||||
startIndex = 1;
|
||||
startLine++;
|
||||
}
|
||||
|
||||
// shift all parts on the delta size
|
||||
var delta = indentation - nonWhitespaceColumnInFirstPart.column;
|
||||
for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) {
|
||||
var startLinePos = getStartPositionOfLine(startLine, sourceFile);
|
||||
var nonWhitespaceCharacterAndColumn =
|
||||
let delta = indentation - nonWhitespaceColumnInFirstPart.column;
|
||||
for (let i = startIndex, len = parts.length; i < len; ++i, ++startLine) {
|
||||
let startLinePos = getStartPositionOfLine(startLine, sourceFile);
|
||||
let nonWhitespaceCharacterAndColumn =
|
||||
i === 0
|
||||
? nonWhitespaceColumnInFirstPart
|
||||
: SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options);
|
||||
|
||||
var newIndentation = nonWhitespaceCharacterAndColumn.column + delta;
|
||||
let newIndentation = nonWhitespaceCharacterAndColumn.column + delta;
|
||||
if (newIndentation > 0) {
|
||||
var indentationString = getIndentationString(newIndentation, options);
|
||||
let indentationString = getIndentationString(newIndentation, options);
|
||||
recordReplace(startLinePos, nonWhitespaceCharacterAndColumn.character, indentationString);
|
||||
}
|
||||
else {
|
||||
@ -873,16 +873,16 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
function trimTrailingWhitespacesForLines(line1: number, line2: number, range?: TextRangeWithKind) {
|
||||
for (var line = line1; line < line2; ++line) {
|
||||
var lineStartPosition = getStartPositionOfLine(line, sourceFile);
|
||||
var lineEndPosition = getEndLinePosition(line, sourceFile);
|
||||
for (let line = line1; line < line2; ++line) {
|
||||
let lineStartPosition = getStartPositionOfLine(line, sourceFile);
|
||||
let lineEndPosition = getEndLinePosition(line, sourceFile);
|
||||
|
||||
// do not trim whitespaces in comments
|
||||
if (range && isComment(range.kind) && range.pos <= lineEndPosition && range.end > lineEndPosition) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var pos = lineEndPosition;
|
||||
let pos = lineEndPosition;
|
||||
while (pos >= lineStartPosition && isWhiteSpace(sourceFile.text.charCodeAt(pos))) {
|
||||
pos--;
|
||||
}
|
||||
@ -915,7 +915,7 @@ module ts.formatting {
|
||||
currentRange: TextRangeWithKind,
|
||||
currentStartLine: number): void {
|
||||
|
||||
var between: TextRange;
|
||||
let between: TextRange;
|
||||
switch (rule.Operation.Action) {
|
||||
case RuleAction.Ignore:
|
||||
// no action required
|
||||
@ -935,7 +935,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
// edit should not be applied only if we have one line feed between elements
|
||||
var lineDelta = currentStartLine - previousStartLine;
|
||||
let lineDelta = currentStartLine - previousStartLine;
|
||||
if (lineDelta !== 1) {
|
||||
recordReplace(previousRange.end, currentRange.pos - previousRange.end, options.NewLineCharacter);
|
||||
}
|
||||
@ -946,7 +946,7 @@ module ts.formatting {
|
||||
return;
|
||||
}
|
||||
|
||||
var posDelta = currentRange.pos - previousRange.end;
|
||||
let posDelta = currentRange.pos - previousRange.end;
|
||||
if (posDelta !== 1 || sourceFile.text.charCodeAt(previousRange.end) !== CharacterCodes.space) {
|
||||
recordReplace(previousRange.end, currentRange.pos - previousRange.end, " ");
|
||||
}
|
||||
@ -1008,15 +1008,15 @@ module ts.formatting {
|
||||
return SyntaxKind.Unknown;
|
||||
}
|
||||
|
||||
var internedTabsIndentation: string[];
|
||||
var internedSpacesIndentation: string[];
|
||||
let internedTabsIndentation: string[];
|
||||
let internedSpacesIndentation: string[];
|
||||
|
||||
export function getIndentationString(indentation: number, options: FormatCodeOptions): string {
|
||||
if (!options.ConvertTabsToSpaces) {
|
||||
var tabs = Math.floor(indentation / options.TabSize);
|
||||
var spaces = indentation - tabs * options.TabSize;
|
||||
let tabs = Math.floor(indentation / options.TabSize);
|
||||
let spaces = indentation - tabs * options.TabSize;
|
||||
|
||||
var tabString: string;
|
||||
let tabString: string;
|
||||
if (!internedTabsIndentation) {
|
||||
internedTabsIndentation = [];
|
||||
}
|
||||
@ -1031,9 +1031,9 @@ module ts.formatting {
|
||||
return spaces ? tabString + repeat(" ", spaces) : tabString;
|
||||
}
|
||||
else {
|
||||
var spacesString: string;
|
||||
var quotient = Math.floor(indentation / options.IndentSize);
|
||||
var remainder = indentation % options.IndentSize;
|
||||
let spacesString: string;
|
||||
let quotient = Math.floor(indentation / options.IndentSize);
|
||||
let remainder = indentation % options.IndentSize;
|
||||
if (!internedSpacesIndentation) {
|
||||
internedSpacesIndentation = [];
|
||||
}
|
||||
@ -1046,13 +1046,12 @@ module ts.formatting {
|
||||
spacesString = internedSpacesIndentation[quotient];
|
||||
}
|
||||
|
||||
|
||||
return remainder ? spacesString + repeat(" ", remainder) : spacesString;
|
||||
}
|
||||
|
||||
function repeat(value: string, count: number): string {
|
||||
var s = "";
|
||||
for (var i = 0; i < count; ++i) {
|
||||
let s = "";
|
||||
for (let i = 0; i < count; ++i) {
|
||||
s += value;
|
||||
}
|
||||
|
||||
|
||||
@ -71,8 +71,8 @@ module ts.formatting {
|
||||
|
||||
public TokensAreOnSameLine(): boolean {
|
||||
if (this.tokensAreOnSameLine === undefined) {
|
||||
var startLine = this.sourceFile.getLineAndCharacterOfPosition(this.currentTokenSpan.pos).line;
|
||||
var endLine = this.sourceFile.getLineAndCharacterOfPosition(this.nextTokenSpan.pos).line;
|
||||
let startLine = this.sourceFile.getLineAndCharacterOfPosition(this.currentTokenSpan.pos).line;
|
||||
let endLine = this.sourceFile.getLineAndCharacterOfPosition(this.nextTokenSpan.pos).line;
|
||||
this.tokensAreOnSameLine = (startLine == endLine);
|
||||
}
|
||||
|
||||
@ -96,17 +96,17 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
private NodeIsOnOneLine(node: Node): boolean {
|
||||
var startLine = this.sourceFile.getLineAndCharacterOfPosition(node.getStart(this.sourceFile)).line;
|
||||
var endLine = this.sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line;
|
||||
let startLine = this.sourceFile.getLineAndCharacterOfPosition(node.getStart(this.sourceFile)).line;
|
||||
let endLine = this.sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line;
|
||||
return startLine == endLine;
|
||||
}
|
||||
|
||||
private BlockIsOnOneLine(node: Node): boolean {
|
||||
var openBrace = findChildOfKind(node, SyntaxKind.OpenBraceToken, this.sourceFile);
|
||||
var closeBrace = findChildOfKind(node, SyntaxKind.CloseBraceToken, this.sourceFile);
|
||||
let openBrace = findChildOfKind(node, SyntaxKind.OpenBraceToken, this.sourceFile);
|
||||
let closeBrace = findChildOfKind(node, SyntaxKind.CloseBraceToken, this.sourceFile);
|
||||
if (openBrace && closeBrace) {
|
||||
var startLine = this.sourceFile.getLineAndCharacterOfPosition(openBrace.getEnd()).line;
|
||||
var endLine = this.sourceFile.getLineAndCharacterOfPosition(closeBrace.getStart(this.sourceFile)).line;
|
||||
let startLine = this.sourceFile.getLineAndCharacterOfPosition(openBrace.getEnd()).line;
|
||||
let endLine = this.sourceFile.getLineAndCharacterOfPosition(closeBrace.getStart(this.sourceFile)).line;
|
||||
return startLine === endLine;
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
/// <reference path="..\..\compiler\scanner.ts"/>
|
||||
|
||||
module ts.formatting {
|
||||
var scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false);
|
||||
let scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false);
|
||||
|
||||
export interface FormattingScanner {
|
||||
advance(): void;
|
||||
@ -24,13 +24,13 @@ module ts.formatting {
|
||||
scanner.setText(sourceFile.text);
|
||||
scanner.setTextPos(startPos);
|
||||
|
||||
var wasNewLine: boolean = true;
|
||||
var leadingTrivia: TextRangeWithKind[];
|
||||
var trailingTrivia: TextRangeWithKind[];
|
||||
let wasNewLine: boolean = true;
|
||||
let leadingTrivia: TextRangeWithKind[];
|
||||
let trailingTrivia: TextRangeWithKind[];
|
||||
|
||||
var savedPos: number;
|
||||
var lastScanAction: ScanAction;
|
||||
var lastTokenInfo: TokenInfo;
|
||||
let savedPos: number;
|
||||
let lastScanAction: ScanAction;
|
||||
let lastTokenInfo: TokenInfo;
|
||||
|
||||
return {
|
||||
advance: advance,
|
||||
@ -45,7 +45,7 @@ module ts.formatting {
|
||||
|
||||
function advance(): void {
|
||||
lastTokenInfo = undefined;
|
||||
var isStarted = scanner.getStartPos() !== startPos;
|
||||
let isStarted = scanner.getStartPos() !== startPos;
|
||||
|
||||
if (isStarted) {
|
||||
if (trailingTrivia) {
|
||||
@ -64,19 +64,19 @@ module ts.formatting {
|
||||
scanner.scan();
|
||||
}
|
||||
|
||||
var t: SyntaxKind;
|
||||
var pos = scanner.getStartPos();
|
||||
let t: SyntaxKind;
|
||||
let pos = scanner.getStartPos();
|
||||
|
||||
// Read leading trivia and token
|
||||
while (pos < endPos) {
|
||||
var t = scanner.getToken();
|
||||
let t = scanner.getToken();
|
||||
if (!isTrivia(t)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// consume leading trivia
|
||||
scanner.scan();
|
||||
var item = {
|
||||
let item = {
|
||||
pos: pos,
|
||||
end: scanner.getStartPos(),
|
||||
kind: t
|
||||
@ -133,7 +133,7 @@ module ts.formatting {
|
||||
|
||||
// normally scanner returns the smallest available token
|
||||
// check the kind of context node to determine if scanner should have more greedy behavior and consume more text.
|
||||
var expectedScanAction =
|
||||
let expectedScanAction =
|
||||
shouldRescanGreaterThanToken(n)
|
||||
? ScanAction.RescanGreaterThanToken
|
||||
: shouldRescanSlashToken(n)
|
||||
@ -159,7 +159,7 @@ module ts.formatting {
|
||||
scanner.scan();
|
||||
}
|
||||
|
||||
var currentToken = scanner.getToken();
|
||||
let currentToken = scanner.getToken();
|
||||
|
||||
if (expectedScanAction === ScanAction.RescanGreaterThanToken && currentToken === SyntaxKind.GreaterThanToken) {
|
||||
currentToken = scanner.reScanGreaterToken();
|
||||
@ -179,7 +179,7 @@ module ts.formatting {
|
||||
lastScanAction = ScanAction.Scan;
|
||||
}
|
||||
|
||||
var token: TextRangeWithKind = {
|
||||
let token: TextRangeWithKind = {
|
||||
pos: scanner.getStartPos(),
|
||||
end: scanner.getTextPos(),
|
||||
kind: currentToken
|
||||
@ -194,7 +194,7 @@ module ts.formatting {
|
||||
if (!isTrivia(currentToken)) {
|
||||
break;
|
||||
}
|
||||
var trivia = {
|
||||
let trivia = {
|
||||
pos: scanner.getStartPos(),
|
||||
end: scanner.getTextPos(),
|
||||
kind: currentToken
|
||||
@ -223,8 +223,8 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
function isOnToken(): boolean {
|
||||
var current = (lastTokenInfo && lastTokenInfo.token.kind) || scanner.getToken();
|
||||
var startPos = (lastTokenInfo && lastTokenInfo.token.pos) || scanner.getStartPos();
|
||||
let current = (lastTokenInfo && lastTokenInfo.token.kind) || scanner.getToken();
|
||||
let startPos = (lastTokenInfo && lastTokenInfo.token.pos) || scanner.getStartPos();
|
||||
return startPos < endPos && current !== SyntaxKind.EndOfFileToken && !isTrivia(current);
|
||||
}
|
||||
|
||||
|
||||
@ -33,8 +33,7 @@ module ts.formatting {
|
||||
return RuleDescriptor.create4(left, Shared.TokenRange.FromToken(right));
|
||||
}
|
||||
|
||||
static create3(left: SyntaxKind, right: Shared.TokenRange): RuleDescriptor
|
||||
{
|
||||
static create3(left: SyntaxKind, right: Shared.TokenRange): RuleDescriptor {
|
||||
return RuleDescriptor.create4(Shared.TokenRange.FromToken(left), right);
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
static create2(context: RuleOperationContext, action: RuleAction) {
|
||||
var result = new RuleOperation();
|
||||
let result = new RuleOperation();
|
||||
result.Context = context;
|
||||
result.Action = action;
|
||||
return result;
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
module ts.formatting {
|
||||
export class Rules {
|
||||
public getRuleName(rule: Rule) {
|
||||
var o: ts.Map<any> = <any>this;
|
||||
for (var name in o) {
|
||||
let o: ts.Map<any> = <any>this;
|
||||
for (let name in o) {
|
||||
if (o[name] === rule) {
|
||||
return name;
|
||||
}
|
||||
@ -139,7 +139,7 @@ module ts.formatting {
|
||||
// Lambda expressions
|
||||
public SpaceAfterArrow: Rule;
|
||||
|
||||
// Optional parameters and var args
|
||||
// Optional parameters and let args
|
||||
public NoSpaceAfterEllipsis: Rule;
|
||||
public NoSpaceAfterOptionalParameters: Rule;
|
||||
|
||||
@ -330,7 +330,7 @@ module ts.formatting {
|
||||
// Lambda expressions
|
||||
this.SpaceAfterArrow = new Rule(RuleDescriptor.create3(SyntaxKind.EqualsGreaterThanToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||
|
||||
// Optional parameters and var args
|
||||
// Optional parameters and let args
|
||||
this.NoSpaceAfterEllipsis = new Rule(RuleDescriptor.create1(SyntaxKind.DotDotDotToken, SyntaxKind.Identifier), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterOptionalParameters = new Rule(RuleDescriptor.create3(SyntaxKind.QuestionToken, Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.CommaToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), RuleAction.Delete));
|
||||
|
||||
@ -462,7 +462,7 @@ module ts.formatting {
|
||||
|
||||
// equal in import a = module('a');
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
// equal in var a = 0;
|
||||
// equal in let a = 0;
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
// equal in p = 0;
|
||||
case SyntaxKind.Parameter:
|
||||
@ -470,7 +470,7 @@ module ts.formatting {
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken;
|
||||
// "in" keyword in for (var x in []) { }
|
||||
// "in" keyword in for (let x in []) { }
|
||||
case SyntaxKind.ForInStatement:
|
||||
return context.currentTokenSpan.kind === SyntaxKind.InKeyword || context.nextTokenSpan.kind === SyntaxKind.InKeyword;
|
||||
// Technically, "of" is not a binary operator, but format it the same way as "in"
|
||||
|
||||
@ -26,7 +26,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
static create(rules: Rule[]): RulesMap {
|
||||
var result = new RulesMap();
|
||||
let result = new RulesMap();
|
||||
result.Initialize(rules);
|
||||
return result;
|
||||
}
|
||||
@ -36,7 +36,7 @@ module ts.formatting {
|
||||
this.map = <any> new Array(this.mapRowLength * this.mapRowLength);//new Array<RulesBucket>(this.mapRowLength * this.mapRowLength);
|
||||
|
||||
// This array is used only during construction of the rulesbucket in the map
|
||||
var rulesBucketConstructionStateList: RulesBucketConstructionState[] = <any> new Array(this.map.length);//new Array<RulesBucketConstructionState>(this.map.length);
|
||||
let rulesBucketConstructionStateList: RulesBucketConstructionState[] = <any> new Array(this.map.length);//new Array<RulesBucketConstructionState>(this.map.length);
|
||||
|
||||
this.FillRules(rules, rulesBucketConstructionStateList);
|
||||
return this.map;
|
||||
@ -49,20 +49,20 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
private GetRuleBucketIndex(row: number, column: number): number {
|
||||
var rulesBucketIndex = (row * this.mapRowLength) + column;
|
||||
let rulesBucketIndex = (row * this.mapRowLength) + column;
|
||||
//Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array.");
|
||||
return rulesBucketIndex;
|
||||
}
|
||||
|
||||
private FillRule(rule: Rule, rulesBucketConstructionStateList: RulesBucketConstructionState[]): void {
|
||||
var specificRule = rule.Descriptor.LeftTokenRange != Shared.TokenRange.Any &&
|
||||
let specificRule = rule.Descriptor.LeftTokenRange != Shared.TokenRange.Any &&
|
||||
rule.Descriptor.RightTokenRange != Shared.TokenRange.Any;
|
||||
|
||||
rule.Descriptor.LeftTokenRange.GetTokens().forEach((left) => {
|
||||
rule.Descriptor.RightTokenRange.GetTokens().forEach((right) => {
|
||||
var rulesBucketIndex = this.GetRuleBucketIndex(left, right);
|
||||
let rulesBucketIndex = this.GetRuleBucketIndex(left, right);
|
||||
|
||||
var rulesBucket = this.map[rulesBucketIndex];
|
||||
let rulesBucket = this.map[rulesBucketIndex];
|
||||
if (rulesBucket == undefined) {
|
||||
rulesBucket = this.map[rulesBucketIndex] = new RulesBucket();
|
||||
}
|
||||
@ -73,8 +73,8 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
public GetRule(context: FormattingContext): Rule {
|
||||
var bucketIndex = this.GetRuleBucketIndex(context.currentTokenSpan.kind, context.nextTokenSpan.kind);
|
||||
var bucket = this.map[bucketIndex];
|
||||
let bucketIndex = this.GetRuleBucketIndex(context.currentTokenSpan.kind, context.nextTokenSpan.kind);
|
||||
let bucket = this.map[bucketIndex];
|
||||
if (bucket != null) {
|
||||
for (let rule of bucket.Rules()) {
|
||||
if (rule.Operation.Context.InContext(context)) {
|
||||
@ -86,8 +86,8 @@ module ts.formatting {
|
||||
}
|
||||
}
|
||||
|
||||
var MaskBitSize = 5;
|
||||
var Mask = 0x1f;
|
||||
let MaskBitSize = 5;
|
||||
let Mask = 0x1f;
|
||||
|
||||
export enum RulesPosition {
|
||||
IgnoreRulesSpecific = 0,
|
||||
@ -121,10 +121,10 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
public GetInsertionIndex(maskPosition: RulesPosition): number {
|
||||
var index = 0;
|
||||
let index = 0;
|
||||
|
||||
var pos = 0;
|
||||
var indexBitmap = this.rulesInsertionIndexBitmap;
|
||||
let pos = 0;
|
||||
let indexBitmap = this.rulesInsertionIndexBitmap;
|
||||
|
||||
while (pos <= maskPosition) {
|
||||
index += (indexBitmap & Mask);
|
||||
@ -136,11 +136,11 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
public IncreaseInsertionIndex(maskPosition: RulesPosition): void {
|
||||
var value = (this.rulesInsertionIndexBitmap >> maskPosition) & Mask;
|
||||
let value = (this.rulesInsertionIndexBitmap >> maskPosition) & Mask;
|
||||
value++;
|
||||
Debug.assert((value & Mask) == value, "Adding more rules into the sub-bucket than allowed. Maximum allowed is 32 rules.");
|
||||
|
||||
var temp = this.rulesInsertionIndexBitmap & ~(Mask << maskPosition);
|
||||
let temp = this.rulesInsertionIndexBitmap & ~(Mask << maskPosition);
|
||||
temp |= value << maskPosition;
|
||||
|
||||
this.rulesInsertionIndexBitmap = temp;
|
||||
@ -159,7 +159,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
public AddRule(rule: Rule, specificTokens: boolean, constructionState: RulesBucketConstructionState[], rulesBucketIndex: number): void {
|
||||
var position: RulesPosition;
|
||||
let position: RulesPosition;
|
||||
|
||||
if (rule.Operation.Action == RuleAction.Ignore) {
|
||||
position = specificTokens ?
|
||||
@ -177,11 +177,11 @@ module ts.formatting {
|
||||
RulesPosition.NoContextRulesAny;
|
||||
}
|
||||
|
||||
var state = constructionState[rulesBucketIndex];
|
||||
let state = constructionState[rulesBucketIndex];
|
||||
if (state === undefined) {
|
||||
state = constructionState[rulesBucketIndex] = new RulesBucketConstructionState();
|
||||
}
|
||||
var index = state.GetInsertionIndex(position);
|
||||
let index = state.GetInsertionIndex(position);
|
||||
this.rules.splice(index, 0, rule);
|
||||
state.IncreaseInsertionIndex(position);
|
||||
}
|
||||
|
||||
@ -40,8 +40,8 @@ module ts.formatting {
|
||||
|
||||
public ensureUpToDate(options: ts.FormatCodeOptions) {
|
||||
if (this.options == null || !ts.compareDataObjects(this.options, options)) {
|
||||
var activeRules = this.createActiveRules(options);
|
||||
var rulesMap = RulesMap.create(activeRules);
|
||||
let activeRules = this.createActiveRules(options);
|
||||
let rulesMap = RulesMap.create(activeRules);
|
||||
|
||||
this.activeRules = activeRules;
|
||||
this.rulesMap = rulesMap;
|
||||
@ -50,7 +50,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
private createActiveRules(options: ts.FormatCodeOptions): Rule[] {
|
||||
var rules = this.globalRules.HighPriorityCommonRules.slice(0);
|
||||
let rules = this.globalRules.HighPriorityCommonRules.slice(0);
|
||||
|
||||
if (options.InsertSpaceAfterCommaDelimiter) {
|
||||
rules.push(this.globalRules.SpaceAfterComma);
|
||||
|
||||
@ -12,13 +12,13 @@ module ts.formatting {
|
||||
return 0; // past EOF
|
||||
}
|
||||
|
||||
var precedingToken = findPrecedingToken(position, sourceFile);
|
||||
let precedingToken = findPrecedingToken(position, sourceFile);
|
||||
if (!precedingToken) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// no indentation in string \regex\template literals
|
||||
var precedingTokenIsLiteral =
|
||||
let precedingTokenIsLiteral =
|
||||
precedingToken.kind === SyntaxKind.StringLiteral ||
|
||||
precedingToken.kind === SyntaxKind.RegularExpressionLiteral ||
|
||||
precedingToken.kind === SyntaxKind.NoSubstitutionTemplateLiteral ||
|
||||
@ -29,11 +29,11 @@ module ts.formatting {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var lineAtPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
|
||||
let lineAtPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
|
||||
|
||||
if (precedingToken.kind === SyntaxKind.CommaToken && precedingToken.parent.kind !== SyntaxKind.BinaryExpression) {
|
||||
// previous token is comma that separates items in list - find the previous item and try to derive indentation from it
|
||||
var actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options);
|
||||
let actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options);
|
||||
if (actualIndentation !== Value.Unknown) {
|
||||
return actualIndentation;
|
||||
}
|
||||
@ -41,10 +41,10 @@ module ts.formatting {
|
||||
|
||||
// try to find node that can contribute to indentation and includes 'position' starting from 'precedingToken'
|
||||
// if such node is found - compute initial indentation for 'position' inside this node
|
||||
var previous: Node;
|
||||
var current = precedingToken;
|
||||
var currentStart: LineAndCharacter;
|
||||
var indentationDelta: number;
|
||||
let previous: Node;
|
||||
let current = precedingToken;
|
||||
let currentStart: LineAndCharacter;
|
||||
let indentationDelta: number;
|
||||
|
||||
while (current) {
|
||||
if (positionBelongsToNode(current, position, sourceFile) && shouldIndentChildNode(current.kind, previous ? previous.kind : SyntaxKind.Unknown)) {
|
||||
@ -61,7 +61,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
// check if current node is a list item - if yes, take indentation from it
|
||||
var actualIndentation = getActualIndentationForListItem(current, sourceFile, options);
|
||||
let actualIndentation = getActualIndentationForListItem(current, sourceFile, options);
|
||||
if (actualIndentation !== Value.Unknown) {
|
||||
return actualIndentation;
|
||||
}
|
||||
@ -79,7 +79,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
export function getIndentationForNode(n: Node, ignoreActualIndentationRange: TextRange, sourceFile: SourceFile, options: FormatCodeOptions): number {
|
||||
var start = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile));
|
||||
let start = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile));
|
||||
return getIndentationForNodeWorker(n, start, ignoreActualIndentationRange, /*indentationDelta*/ 0, sourceFile, options);
|
||||
}
|
||||
|
||||
@ -91,33 +91,33 @@ module ts.formatting {
|
||||
sourceFile: SourceFile,
|
||||
options: EditorOptions): number {
|
||||
|
||||
var parent: Node = current.parent;
|
||||
var parentStart: LineAndCharacter;
|
||||
let parent: Node = current.parent;
|
||||
let parentStart: LineAndCharacter;
|
||||
|
||||
// walk upwards and collect indentations for pairs of parent-child nodes
|
||||
// indentation is not added if parent and child nodes start on the same line or if parent is IfStatement and child starts on the same line with 'else clause'
|
||||
while (parent) {
|
||||
var useActualIndentation = true;
|
||||
let useActualIndentation = true;
|
||||
if (ignoreActualIndentationRange) {
|
||||
var start = current.getStart(sourceFile);
|
||||
let start = current.getStart(sourceFile);
|
||||
useActualIndentation = start < ignoreActualIndentationRange.pos || start > ignoreActualIndentationRange.end;
|
||||
}
|
||||
|
||||
if (useActualIndentation) {
|
||||
// check if current node is a list item - if yes, take indentation from it
|
||||
var actualIndentation = getActualIndentationForListItem(current, sourceFile, options);
|
||||
let actualIndentation = getActualIndentationForListItem(current, sourceFile, options);
|
||||
if (actualIndentation !== Value.Unknown) {
|
||||
return actualIndentation + indentationDelta;
|
||||
}
|
||||
}
|
||||
parentStart = getParentStart(parent, current, sourceFile);
|
||||
var parentAndChildShareLine =
|
||||
let parentAndChildShareLine =
|
||||
parentStart.line === currentStart.line ||
|
||||
childStartsOnTheSameLineWithElseInIfStatement(parent, current, currentStart.line, sourceFile);
|
||||
|
||||
if (useActualIndentation) {
|
||||
// try to fetch actual indentation for current node from source text
|
||||
var actualIndentation = getActualIndentationForNode(current, parent, currentStart, parentAndChildShareLine, sourceFile, options);
|
||||
let actualIndentation = getActualIndentationForNode(current, parent, currentStart, parentAndChildShareLine, sourceFile, options);
|
||||
if (actualIndentation !== Value.Unknown) {
|
||||
return actualIndentation + indentationDelta;
|
||||
}
|
||||
@ -138,7 +138,7 @@ module ts.formatting {
|
||||
|
||||
|
||||
function getParentStart(parent: Node, child: Node, sourceFile: SourceFile): LineAndCharacter {
|
||||
var containingList = getContainingList(child, sourceFile);
|
||||
let containingList = getContainingList(child, sourceFile);
|
||||
if (containingList) {
|
||||
return sourceFile.getLineAndCharacterOfPosition(containingList.pos);
|
||||
}
|
||||
@ -151,7 +151,7 @@ module ts.formatting {
|
||||
*/
|
||||
function getActualIndentationForListItemBeforeComma(commaToken: Node, sourceFile: SourceFile, options: EditorOptions): number {
|
||||
// previous token is comma that separates items in list - find the previous item and try to derive indentation from it
|
||||
var commaItemInfo = findListItemInfo(commaToken);
|
||||
let commaItemInfo = findListItemInfo(commaToken);
|
||||
if (commaItemInfo && commaItemInfo.listItemIndex > 0) {
|
||||
return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options);
|
||||
}
|
||||
@ -174,7 +174,7 @@ module ts.formatting {
|
||||
// actual indentation is used for statements\declarations if one of cases below is true:
|
||||
// - parent is SourceFile - by default immediate children of SourceFile are not indented except when user indents them manually
|
||||
// - parent and child are not on the same line
|
||||
var useActualIndentation =
|
||||
let useActualIndentation =
|
||||
(isDeclaration(current) || isStatement(current)) &&
|
||||
(parent.kind === SyntaxKind.SourceFile || !parentAndChildShareLine);
|
||||
|
||||
@ -186,7 +186,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
function nextTokenIsCurlyBraceOnSameLineAsCursor(precedingToken: Node, current: Node, lineAtPosition: number, sourceFile: SourceFile): boolean {
|
||||
var nextToken = findNextToken(precedingToken, current);
|
||||
let nextToken = findNextToken(precedingToken, current);
|
||||
if (!nextToken) {
|
||||
return false;
|
||||
}
|
||||
@ -205,7 +205,7 @@ module ts.formatting {
|
||||
// class A {
|
||||
// $}
|
||||
|
||||
var nextTokenStartLine = getStartLineAndCharacterForNode(nextToken, sourceFile).line;
|
||||
let nextTokenStartLine = getStartLineAndCharacterForNode(nextToken, sourceFile).line;
|
||||
return lineAtPosition === nextTokenStartLine;
|
||||
}
|
||||
|
||||
@ -222,10 +222,10 @@ module ts.formatting {
|
||||
|
||||
export function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFile): boolean {
|
||||
if (parent.kind === SyntaxKind.IfStatement && (<IfStatement>parent).elseStatement === child) {
|
||||
var elseKeyword = findChildOfKind(parent, SyntaxKind.ElseKeyword, sourceFile);
|
||||
let elseKeyword = findChildOfKind(parent, SyntaxKind.ElseKeyword, sourceFile);
|
||||
Debug.assert(elseKeyword !== undefined);
|
||||
|
||||
var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line;
|
||||
let elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line;
|
||||
return elseKeywordStartLine === childStartLine;
|
||||
}
|
||||
|
||||
@ -251,8 +251,8 @@ module ts.formatting {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
var start = node.getStart(sourceFile);
|
||||
case SyntaxKind.ConstructSignature: {
|
||||
let start = node.getStart(sourceFile);
|
||||
if ((<SignatureDeclaration>node.parent).typeParameters &&
|
||||
rangeContainsStartEnd((<SignatureDeclaration>node.parent).typeParameters, start, node.getEnd())) {
|
||||
return (<SignatureDeclaration>node.parent).typeParameters;
|
||||
@ -261,9 +261,10 @@ module ts.formatting {
|
||||
return (<SignatureDeclaration>node.parent).parameters;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.CallExpression:
|
||||
var start = node.getStart(sourceFile);
|
||||
case SyntaxKind.CallExpression: {
|
||||
let start = node.getStart(sourceFile);
|
||||
if ((<CallExpression>node.parent).typeArguments &&
|
||||
rangeContainsStartEnd((<CallExpression>node.parent).typeArguments, start, node.getEnd())) {
|
||||
return (<CallExpression>node.parent).typeArguments;
|
||||
@ -273,34 +274,35 @@ module ts.formatting {
|
||||
return (<CallExpression>node.parent).arguments;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getActualIndentationForListItem(node: Node, sourceFile: SourceFile, options: EditorOptions): number {
|
||||
var containingList = getContainingList(node, sourceFile);
|
||||
let containingList = getContainingList(node, sourceFile);
|
||||
return containingList ? getActualIndentationFromList(containingList) : Value.Unknown;
|
||||
|
||||
function getActualIndentationFromList(list: Node[]): number {
|
||||
var index = indexOf(list, node);
|
||||
let index = indexOf(list, node);
|
||||
return index !== -1 ? deriveActualIndentationFromList(list, index, sourceFile, options) : Value.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
function deriveActualIndentationFromList(list: Node[], index: number, sourceFile: SourceFile, options: EditorOptions): number {
|
||||
Debug.assert(index >= 0 && index < list.length);
|
||||
var node = list[index];
|
||||
let node = list[index];
|
||||
|
||||
// walk toward the start of the list starting from current node and check if the line is the same for all items.
|
||||
// if end line for item [i - 1] differs from the start line for item [i] - find column of the first non-whitespace character on the line of item [i]
|
||||
var lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile);
|
||||
for (var i = index - 1; i >= 0; --i) {
|
||||
let lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile);
|
||||
for (let i = index - 1; i >= 0; --i) {
|
||||
if (list[i].kind === SyntaxKind.CommaToken) {
|
||||
continue;
|
||||
}
|
||||
// skip list items that ends on the same line with the current list element
|
||||
var prevEndLine = sourceFile.getLineAndCharacterOfPosition(list[i].end).line;
|
||||
let prevEndLine = sourceFile.getLineAndCharacterOfPosition(list[i].end).line;
|
||||
if (prevEndLine !== lineAndCharacter.line) {
|
||||
return findColumnForFirstNonWhitespaceCharacterInLine(lineAndCharacter, sourceFile, options);
|
||||
}
|
||||
@ -311,7 +313,7 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
function findColumnForFirstNonWhitespaceCharacterInLine(lineAndCharacter: LineAndCharacter, sourceFile: SourceFile, options: EditorOptions): number {
|
||||
var lineStart = sourceFile.getPositionOfLineAndCharacter(lineAndCharacter.line, 0);
|
||||
let lineStart = sourceFile.getPositionOfLineAndCharacter(lineAndCharacter.line, 0);
|
||||
return findFirstNonWhitespaceColumn(lineStart, lineStart + lineAndCharacter.character, sourceFile, options);
|
||||
}
|
||||
|
||||
@ -323,10 +325,10 @@ module ts.formatting {
|
||||
value of 'column' for '$' is 6 (assuming that tab size is 4)
|
||||
*/
|
||||
export function findFirstNonWhitespaceCharacterAndColumn(startPos: number, endPos: number, sourceFile: SourceFile, options: EditorOptions) {
|
||||
var character = 0;
|
||||
var column = 0;
|
||||
for (var pos = startPos; pos < endPos; ++pos) {
|
||||
var ch = sourceFile.text.charCodeAt(pos);
|
||||
let character = 0;
|
||||
let column = 0;
|
||||
for (let pos = startPos; pos < endPos; ++pos) {
|
||||
let ch = sourceFile.text.charCodeAt(pos);
|
||||
if (!isWhiteSpace(ch)) {
|
||||
break;
|
||||
}
|
||||
@ -403,9 +405,9 @@ module ts.formatting {
|
||||
* If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'.
|
||||
*/
|
||||
function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean {
|
||||
var children = n.getChildren(sourceFile);
|
||||
let children = n.getChildren(sourceFile);
|
||||
if (children.length) {
|
||||
var last = children[children.length - 1];
|
||||
let last = children[children.length - 1];
|
||||
if (last.kind === expectedLastToken) {
|
||||
return true;
|
||||
}
|
||||
@ -471,7 +473,7 @@ module ts.formatting {
|
||||
return isCompletedNode((<WhileStatement>n).statement, sourceFile);
|
||||
case SyntaxKind.DoStatement:
|
||||
// rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')';
|
||||
var hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile);
|
||||
let hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile);
|
||||
if (hasWhileKeyword) {
|
||||
return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile);
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ module ts.formatting {
|
||||
|
||||
constructor(from: SyntaxKind, to: SyntaxKind, except: SyntaxKind[]) {
|
||||
this.tokens = [];
|
||||
for (var token = from; token <= to; token++) {
|
||||
for (let token = from; token <= to; token++) {
|
||||
if (except.indexOf(token) < 0) {
|
||||
this.tokens.push(token);
|
||||
}
|
||||
@ -74,8 +74,8 @@ module ts.formatting {
|
||||
|
||||
export class TokenAllAccess implements ITokenAccess {
|
||||
public GetTokens(): SyntaxKind[] {
|
||||
var result: SyntaxKind[] = [];
|
||||
for (var token = SyntaxKind.FirstToken; token <= SyntaxKind.LastToken; token++) {
|
||||
let result: SyntaxKind[] = [];
|
||||
for (let token = SyntaxKind.FirstToken; token <= SyntaxKind.LastToken; token++) {
|
||||
result.push(token);
|
||||
}
|
||||
return result;
|
||||
|
||||
@ -418,10 +418,10 @@ module ts.NavigationBar {
|
||||
}
|
||||
|
||||
function createFunctionItem(node: FunctionDeclaration) {
|
||||
if (node.name && node.body && node.body.kind === SyntaxKind.Block) {
|
||||
if ((node.name || node.flags & NodeFlags.Default) && node.body && node.body.kind === SyntaxKind.Block) {
|
||||
let childItems = getItemsWorker(sortNodes((<Block>node.body).statements), createChildItem);
|
||||
|
||||
return getNavigationBarItem(node.name.text,
|
||||
return getNavigationBarItem((!node.name && node.flags & NodeFlags.Default) ? "default": node.name.text ,
|
||||
ts.ScriptElementKind.functionElement,
|
||||
getNodeModifiers(node),
|
||||
[getNodeSpan(node)],
|
||||
@ -452,11 +452,6 @@ module ts.NavigationBar {
|
||||
}
|
||||
|
||||
function createClassItem(node: ClassDeclaration): ts.NavigationBarItem {
|
||||
if (!node.name) {
|
||||
// An export default class may be nameless
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let childItems: NavigationBarItem[];
|
||||
|
||||
if (node.members) {
|
||||
@ -475,8 +470,10 @@ module ts.NavigationBar {
|
||||
childItems = getItemsWorker(sortNodes(nodes), createChildItem);
|
||||
}
|
||||
|
||||
var nodeName = !node.name && (node.flags & NodeFlags.Default) ? "default" : node.name.text;
|
||||
|
||||
return getNavigationBarItem(
|
||||
node.name.text,
|
||||
nodeName,
|
||||
ts.ScriptElementKind.classElement,
|
||||
getNodeModifiers(node),
|
||||
[getNodeSpan(node)],
|
||||
|
||||
@ -553,6 +553,9 @@ declare module "typescript" {
|
||||
name?: Identifier;
|
||||
body: Block | Expression;
|
||||
}
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
equalsGreaterThanToken: Node;
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
text: string;
|
||||
isUnterminated?: boolean;
|
||||
@ -762,7 +765,8 @@ declare module "typescript" {
|
||||
type ExportSpecifier = ImportOrExportSpecifier;
|
||||
interface ExportAssignment extends Declaration, ModuleElement {
|
||||
isExportEquals?: boolean;
|
||||
expression: Expression;
|
||||
expression?: Expression;
|
||||
type?: TypeNode;
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
fileName: string;
|
||||
@ -1239,8 +1243,6 @@ declare module "typescript" {
|
||||
target?: ScriptTarget;
|
||||
version?: boolean;
|
||||
watch?: boolean;
|
||||
stripInternal?: boolean;
|
||||
preserveNewLines?: boolean;
|
||||
[option: string]: string | number | boolean;
|
||||
}
|
||||
const enum ModuleKind {
|
||||
@ -1482,7 +1484,7 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
/** The version of the TypeScript compiler release */
|
||||
var version: string;
|
||||
let version: string;
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
|
||||
@ -1668,6 +1668,15 @@ declare module "typescript" {
|
||||
>body : Expression | Block
|
||||
>Block : Block
|
||||
>Expression : Expression
|
||||
}
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
>ArrowFunction : ArrowFunction
|
||||
>Expression : Expression
|
||||
>FunctionLikeDeclaration : FunctionLikeDeclaration
|
||||
|
||||
equalsGreaterThanToken: Node;
|
||||
>equalsGreaterThanToken : Node
|
||||
>Node : Node
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
>LiteralExpression : LiteralExpression
|
||||
@ -2324,9 +2333,13 @@ declare module "typescript" {
|
||||
isExportEquals?: boolean;
|
||||
>isExportEquals : boolean
|
||||
|
||||
expression: Expression;
|
||||
expression?: Expression;
|
||||
>expression : Expression
|
||||
>Expression : Expression
|
||||
|
||||
type?: TypeNode;
|
||||
>type : TypeNode
|
||||
>TypeNode : TypeNode
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
>FileReference : FileReference
|
||||
@ -3958,12 +3971,6 @@ declare module "typescript" {
|
||||
watch?: boolean;
|
||||
>watch : boolean
|
||||
|
||||
stripInternal?: boolean;
|
||||
>stripInternal : boolean
|
||||
|
||||
preserveNewLines?: boolean;
|
||||
>preserveNewLines : boolean
|
||||
|
||||
[option: string]: string | number | boolean;
|
||||
>option : string
|
||||
}
|
||||
@ -4747,7 +4754,7 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
/** The version of the TypeScript compiler release */
|
||||
var version: string;
|
||||
let version: string;
|
||||
>version : string
|
||||
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
|
||||
@ -584,6 +584,9 @@ declare module "typescript" {
|
||||
name?: Identifier;
|
||||
body: Block | Expression;
|
||||
}
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
equalsGreaterThanToken: Node;
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
text: string;
|
||||
isUnterminated?: boolean;
|
||||
@ -793,7 +796,8 @@ declare module "typescript" {
|
||||
type ExportSpecifier = ImportOrExportSpecifier;
|
||||
interface ExportAssignment extends Declaration, ModuleElement {
|
||||
isExportEquals?: boolean;
|
||||
expression: Expression;
|
||||
expression?: Expression;
|
||||
type?: TypeNode;
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
fileName: string;
|
||||
@ -1270,8 +1274,6 @@ declare module "typescript" {
|
||||
target?: ScriptTarget;
|
||||
version?: boolean;
|
||||
watch?: boolean;
|
||||
stripInternal?: boolean;
|
||||
preserveNewLines?: boolean;
|
||||
[option: string]: string | number | boolean;
|
||||
}
|
||||
const enum ModuleKind {
|
||||
@ -1513,7 +1515,7 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
/** The version of the TypeScript compiler release */
|
||||
var version: string;
|
||||
let version: string;
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
|
||||
@ -1814,6 +1814,15 @@ declare module "typescript" {
|
||||
>body : Expression | Block
|
||||
>Block : Block
|
||||
>Expression : Expression
|
||||
}
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
>ArrowFunction : ArrowFunction
|
||||
>Expression : Expression
|
||||
>FunctionLikeDeclaration : FunctionLikeDeclaration
|
||||
|
||||
equalsGreaterThanToken: Node;
|
||||
>equalsGreaterThanToken : Node
|
||||
>Node : Node
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
>LiteralExpression : LiteralExpression
|
||||
@ -2470,9 +2479,13 @@ declare module "typescript" {
|
||||
isExportEquals?: boolean;
|
||||
>isExportEquals : boolean
|
||||
|
||||
expression: Expression;
|
||||
expression?: Expression;
|
||||
>expression : Expression
|
||||
>Expression : Expression
|
||||
|
||||
type?: TypeNode;
|
||||
>type : TypeNode
|
||||
>TypeNode : TypeNode
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
>FileReference : FileReference
|
||||
@ -4104,12 +4117,6 @@ declare module "typescript" {
|
||||
watch?: boolean;
|
||||
>watch : boolean
|
||||
|
||||
stripInternal?: boolean;
|
||||
>stripInternal : boolean
|
||||
|
||||
preserveNewLines?: boolean;
|
||||
>preserveNewLines : boolean
|
||||
|
||||
[option: string]: string | number | boolean;
|
||||
>option : string
|
||||
}
|
||||
@ -4893,7 +4900,7 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
/** The version of the TypeScript compiler release */
|
||||
var version: string;
|
||||
let version: string;
|
||||
>version : string
|
||||
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
|
||||
@ -585,6 +585,9 @@ declare module "typescript" {
|
||||
name?: Identifier;
|
||||
body: Block | Expression;
|
||||
}
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
equalsGreaterThanToken: Node;
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
text: string;
|
||||
isUnterminated?: boolean;
|
||||
@ -794,7 +797,8 @@ declare module "typescript" {
|
||||
type ExportSpecifier = ImportOrExportSpecifier;
|
||||
interface ExportAssignment extends Declaration, ModuleElement {
|
||||
isExportEquals?: boolean;
|
||||
expression: Expression;
|
||||
expression?: Expression;
|
||||
type?: TypeNode;
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
fileName: string;
|
||||
@ -1271,8 +1275,6 @@ declare module "typescript" {
|
||||
target?: ScriptTarget;
|
||||
version?: boolean;
|
||||
watch?: boolean;
|
||||
stripInternal?: boolean;
|
||||
preserveNewLines?: boolean;
|
||||
[option: string]: string | number | boolean;
|
||||
}
|
||||
const enum ModuleKind {
|
||||
@ -1514,7 +1516,7 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
/** The version of the TypeScript compiler release */
|
||||
var version: string;
|
||||
let version: string;
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
|
||||
@ -1764,6 +1764,15 @@ declare module "typescript" {
|
||||
>body : Expression | Block
|
||||
>Block : Block
|
||||
>Expression : Expression
|
||||
}
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
>ArrowFunction : ArrowFunction
|
||||
>Expression : Expression
|
||||
>FunctionLikeDeclaration : FunctionLikeDeclaration
|
||||
|
||||
equalsGreaterThanToken: Node;
|
||||
>equalsGreaterThanToken : Node
|
||||
>Node : Node
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
>LiteralExpression : LiteralExpression
|
||||
@ -2420,9 +2429,13 @@ declare module "typescript" {
|
||||
isExportEquals?: boolean;
|
||||
>isExportEquals : boolean
|
||||
|
||||
expression: Expression;
|
||||
expression?: Expression;
|
||||
>expression : Expression
|
||||
>Expression : Expression
|
||||
|
||||
type?: TypeNode;
|
||||
>type : TypeNode
|
||||
>TypeNode : TypeNode
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
>FileReference : FileReference
|
||||
@ -4054,12 +4067,6 @@ declare module "typescript" {
|
||||
watch?: boolean;
|
||||
>watch : boolean
|
||||
|
||||
stripInternal?: boolean;
|
||||
>stripInternal : boolean
|
||||
|
||||
preserveNewLines?: boolean;
|
||||
>preserveNewLines : boolean
|
||||
|
||||
[option: string]: string | number | boolean;
|
||||
>option : string
|
||||
}
|
||||
@ -4843,7 +4850,7 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
/** The version of the TypeScript compiler release */
|
||||
var version: string;
|
||||
let version: string;
|
||||
>version : string
|
||||
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
|
||||
@ -622,6 +622,9 @@ declare module "typescript" {
|
||||
name?: Identifier;
|
||||
body: Block | Expression;
|
||||
}
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
equalsGreaterThanToken: Node;
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
text: string;
|
||||
isUnterminated?: boolean;
|
||||
@ -831,7 +834,8 @@ declare module "typescript" {
|
||||
type ExportSpecifier = ImportOrExportSpecifier;
|
||||
interface ExportAssignment extends Declaration, ModuleElement {
|
||||
isExportEquals?: boolean;
|
||||
expression: Expression;
|
||||
expression?: Expression;
|
||||
type?: TypeNode;
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
fileName: string;
|
||||
@ -1308,8 +1312,6 @@ declare module "typescript" {
|
||||
target?: ScriptTarget;
|
||||
version?: boolean;
|
||||
watch?: boolean;
|
||||
stripInternal?: boolean;
|
||||
preserveNewLines?: boolean;
|
||||
[option: string]: string | number | boolean;
|
||||
}
|
||||
const enum ModuleKind {
|
||||
@ -1551,7 +1553,7 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
/** The version of the TypeScript compiler release */
|
||||
var version: string;
|
||||
let version: string;
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
function getPreEmitDiagnostics(program: Program): Diagnostic[];
|
||||
function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string;
|
||||
|
||||
@ -1937,6 +1937,15 @@ declare module "typescript" {
|
||||
>body : Expression | Block
|
||||
>Block : Block
|
||||
>Expression : Expression
|
||||
}
|
||||
interface ArrowFunction extends Expression, FunctionLikeDeclaration {
|
||||
>ArrowFunction : ArrowFunction
|
||||
>Expression : Expression
|
||||
>FunctionLikeDeclaration : FunctionLikeDeclaration
|
||||
|
||||
equalsGreaterThanToken: Node;
|
||||
>equalsGreaterThanToken : Node
|
||||
>Node : Node
|
||||
}
|
||||
interface LiteralExpression extends PrimaryExpression {
|
||||
>LiteralExpression : LiteralExpression
|
||||
@ -2593,9 +2602,13 @@ declare module "typescript" {
|
||||
isExportEquals?: boolean;
|
||||
>isExportEquals : boolean
|
||||
|
||||
expression: Expression;
|
||||
expression?: Expression;
|
||||
>expression : Expression
|
||||
>Expression : Expression
|
||||
|
||||
type?: TypeNode;
|
||||
>type : TypeNode
|
||||
>TypeNode : TypeNode
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
>FileReference : FileReference
|
||||
@ -4227,12 +4240,6 @@ declare module "typescript" {
|
||||
watch?: boolean;
|
||||
>watch : boolean
|
||||
|
||||
stripInternal?: boolean;
|
||||
>stripInternal : boolean
|
||||
|
||||
preserveNewLines?: boolean;
|
||||
>preserveNewLines : boolean
|
||||
|
||||
[option: string]: string | number | boolean;
|
||||
>option : string
|
||||
}
|
||||
@ -5016,7 +5023,7 @@ declare module "typescript" {
|
||||
}
|
||||
declare module "typescript" {
|
||||
/** The version of the TypeScript compiler release */
|
||||
var version: string;
|
||||
let version: string;
|
||||
>version : string
|
||||
|
||||
function createCompilerHost(options: CompilerOptions): CompilerHost;
|
||||
|
||||
@ -0,0 +1,131 @@
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(2,5): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(4,7): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(6,5): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(8,7): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(10,5): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(12,7): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(14,5): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(16,7): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(18,5): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(21,5): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(23,8): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(26,8): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(52,5): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(54,5): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(59,13): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(63,13): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(68,13): error TS1200: Line terminator not permitted before arrow.
|
||||
tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(72,9): error TS1200: Line terminator not permitted before arrow.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (18 errors) ====
|
||||
var f1 = ()
|
||||
=> { }
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f2 = (x: string, y: string) /*
|
||||
*/ => { }
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f3 = (x: string, y: number, ...rest)
|
||||
=> { }
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f4 = (x: string, y: number, ...rest) /*
|
||||
*/ => { }
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f5 = (...rest)
|
||||
=> { }
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f6 = (...rest) /*
|
||||
*/ => { }
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f7 = (x: string, y: number, z = 10)
|
||||
=> { }
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f8 = (x: string, y: number, z = 10) /*
|
||||
*/ => { }
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f9 = (a: number): number
|
||||
=> a;
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f10 = (a: number) :
|
||||
number
|
||||
=> a
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f11 = (a: number): number /*
|
||||
*/ => a;
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
var f12 = (a: number) :
|
||||
number /*
|
||||
*/ => a
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
|
||||
// Should be valid.
|
||||
var f11 = (a: number
|
||||
) => a;
|
||||
|
||||
// Should be valid.
|
||||
var f12 = (a: number)
|
||||
: number => a;
|
||||
|
||||
// Should be valid.
|
||||
var f13 = (a: number):
|
||||
number => a;
|
||||
|
||||
// Should be valid.
|
||||
var f14 = () /* */ => {}
|
||||
|
||||
// Should be valid.
|
||||
var f15 = (a: number): number /* */ => a
|
||||
|
||||
// Should be valid.
|
||||
var f16 = (a: number, b = 10):
|
||||
number /* */ => a + b;
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
foo(()
|
||||
=> true);
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
foo(()
|
||||
=> { return false; });
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
|
||||
module m {
|
||||
class City {
|
||||
constructor(x: number, thing = ()
|
||||
=> 100) {
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
}
|
||||
|
||||
public m = ()
|
||||
=> 2 * 2 * 2
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
}
|
||||
|
||||
export enum Enum {
|
||||
claw = (()
|
||||
=> 10)()
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
}
|
||||
|
||||
export var v = x
|
||||
=> new City(Enum.claw);
|
||||
~~
|
||||
!!! error TS1200: Line terminator not permitted before arrow.
|
||||
}
|
||||
|
||||
178
tests/baselines/reference/disallowLineTerminatorBeforeArrow.js
Normal file
178
tests/baselines/reference/disallowLineTerminatorBeforeArrow.js
Normal file
@ -0,0 +1,178 @@
|
||||
//// [disallowLineTerminatorBeforeArrow.ts]
|
||||
var f1 = ()
|
||||
=> { }
|
||||
var f2 = (x: string, y: string) /*
|
||||
*/ => { }
|
||||
var f3 = (x: string, y: number, ...rest)
|
||||
=> { }
|
||||
var f4 = (x: string, y: number, ...rest) /*
|
||||
*/ => { }
|
||||
var f5 = (...rest)
|
||||
=> { }
|
||||
var f6 = (...rest) /*
|
||||
*/ => { }
|
||||
var f7 = (x: string, y: number, z = 10)
|
||||
=> { }
|
||||
var f8 = (x: string, y: number, z = 10) /*
|
||||
*/ => { }
|
||||
var f9 = (a: number): number
|
||||
=> a;
|
||||
var f10 = (a: number) :
|
||||
number
|
||||
=> a
|
||||
var f11 = (a: number): number /*
|
||||
*/ => a;
|
||||
var f12 = (a: number) :
|
||||
number /*
|
||||
*/ => a
|
||||
|
||||
// Should be valid.
|
||||
var f11 = (a: number
|
||||
) => a;
|
||||
|
||||
// Should be valid.
|
||||
var f12 = (a: number)
|
||||
: number => a;
|
||||
|
||||
// Should be valid.
|
||||
var f13 = (a: number):
|
||||
number => a;
|
||||
|
||||
// Should be valid.
|
||||
var f14 = () /* */ => {}
|
||||
|
||||
// Should be valid.
|
||||
var f15 = (a: number): number /* */ => a
|
||||
|
||||
// Should be valid.
|
||||
var f16 = (a: number, b = 10):
|
||||
number /* */ => a + b;
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
foo(()
|
||||
=> true);
|
||||
foo(()
|
||||
=> { return false; });
|
||||
|
||||
module m {
|
||||
class City {
|
||||
constructor(x: number, thing = ()
|
||||
=> 100) {
|
||||
}
|
||||
|
||||
public m = ()
|
||||
=> 2 * 2 * 2
|
||||
}
|
||||
|
||||
export enum Enum {
|
||||
claw = (()
|
||||
=> 10)()
|
||||
}
|
||||
|
||||
export var v = x
|
||||
=> new City(Enum.claw);
|
||||
}
|
||||
|
||||
|
||||
//// [disallowLineTerminatorBeforeArrow.js]
|
||||
var f1 = function () {
|
||||
};
|
||||
var f2 = function (x, y) {
|
||||
};
|
||||
var f3 = function (x, y) {
|
||||
var rest = [];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
rest[_i - 2] = arguments[_i];
|
||||
}
|
||||
};
|
||||
var f4 = function (x, y) {
|
||||
var rest = [];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
rest[_i - 2] = arguments[_i];
|
||||
}
|
||||
};
|
||||
var f5 = function () {
|
||||
var rest = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
rest[_i - 0] = arguments[_i];
|
||||
}
|
||||
};
|
||||
var f6 = function () {
|
||||
var rest = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
rest[_i - 0] = arguments[_i];
|
||||
}
|
||||
};
|
||||
var f7 = function (x, y, z) {
|
||||
if (z === void 0) { z = 10; }
|
||||
};
|
||||
var f8 = function (x, y, z) {
|
||||
if (z === void 0) { z = 10; }
|
||||
};
|
||||
var f9 = function (a) {
|
||||
return a;
|
||||
};
|
||||
var f10 = function (a) {
|
||||
return a;
|
||||
};
|
||||
var f11 = function (a) {
|
||||
return a;
|
||||
};
|
||||
var f12 = function (a) {
|
||||
return a;
|
||||
};
|
||||
// Should be valid.
|
||||
var f11 = function (a) {
|
||||
return a;
|
||||
};
|
||||
// Should be valid.
|
||||
var f12 = function (a) {
|
||||
return a;
|
||||
};
|
||||
// Should be valid.
|
||||
var f13 = function (a) {
|
||||
return a;
|
||||
};
|
||||
// Should be valid.
|
||||
var f14 = function () {
|
||||
};
|
||||
// Should be valid.
|
||||
var f15 = function (a) {
|
||||
return a;
|
||||
};
|
||||
// Should be valid.
|
||||
var f16 = function (a, b) {
|
||||
if (b === void 0) { b = 10; }
|
||||
return a + b;
|
||||
};
|
||||
function foo(func) {
|
||||
}
|
||||
foo(function () {
|
||||
return true;
|
||||
});
|
||||
foo(function () {
|
||||
return false;
|
||||
});
|
||||
var m;
|
||||
(function (m) {
|
||||
var City = (function () {
|
||||
function City(x, thing) {
|
||||
if (thing === void 0) { thing = function () {
|
||||
return 100;
|
||||
}; }
|
||||
this.m = function () {
|
||||
return 2 * 2 * 2;
|
||||
};
|
||||
}
|
||||
return City;
|
||||
})();
|
||||
(function (Enum) {
|
||||
Enum[Enum["claw"] = (function () {
|
||||
return 10;
|
||||
})()] = "claw";
|
||||
})(m.Enum || (m.Enum = {}));
|
||||
var Enum = m.Enum;
|
||||
m.v = function (x) {
|
||||
return new City(Enum.claw);
|
||||
};
|
||||
})(m || (m = {}));
|
||||
@ -0,0 +1,8 @@
|
||||
tests/cases/compiler/exportDefaultTypeAnnoation.ts(2,18): error TS1201: A type annotation on an export statement is only allowed in an ambient external module declaration.
|
||||
|
||||
|
||||
==== tests/cases/compiler/exportDefaultTypeAnnoation.ts (1 errors) ====
|
||||
|
||||
export default : number;
|
||||
~~~~~~
|
||||
!!! error TS1201: A type annotation on an export statement is only allowed in an ambient external module declaration.
|
||||
6
tests/baselines/reference/exportDefaultTypeAnnoation.js
Normal file
6
tests/baselines/reference/exportDefaultTypeAnnoation.js
Normal file
@ -0,0 +1,6 @@
|
||||
//// [exportDefaultTypeAnnoation.ts]
|
||||
|
||||
export default : number;
|
||||
|
||||
//// [exportDefaultTypeAnnoation.js]
|
||||
module.exports = ;
|
||||
7
tests/baselines/reference/exportDefaultTypeAnnoation2.js
Normal file
7
tests/baselines/reference/exportDefaultTypeAnnoation2.js
Normal file
@ -0,0 +1,7 @@
|
||||
//// [exportDefaultTypeAnnoation2.ts]
|
||||
|
||||
declare module "mod" {
|
||||
export default : number;
|
||||
}
|
||||
|
||||
//// [exportDefaultTypeAnnoation2.js]
|
||||
@ -0,0 +1,6 @@
|
||||
=== tests/cases/compiler/exportDefaultTypeAnnoation2.ts ===
|
||||
|
||||
No type information for this code.declare module "mod" {
|
||||
No type information for this code. export default : number;
|
||||
No type information for this code.}
|
||||
No type information for this code.
|
||||
@ -0,0 +1,21 @@
|
||||
tests/cases/compiler/reference1.ts(2,5): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/compiler/reference2.ts(2,5): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/mod.d.ts (0 errors) ====
|
||||
|
||||
declare module "mod" {
|
||||
export default : number;
|
||||
}
|
||||
|
||||
==== tests/cases/compiler/reference1.ts (1 errors) ====
|
||||
import d from "mod";
|
||||
var s: string = d; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
|
||||
==== tests/cases/compiler/reference2.ts (1 errors) ====
|
||||
import { default as d } from "mod";
|
||||
var s: string = d; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
22
tests/baselines/reference/exportDefaultTypeAnnoation3.js
Normal file
22
tests/baselines/reference/exportDefaultTypeAnnoation3.js
Normal file
@ -0,0 +1,22 @@
|
||||
//// [tests/cases/compiler/exportDefaultTypeAnnoation3.ts] ////
|
||||
|
||||
//// [mod.d.ts]
|
||||
|
||||
declare module "mod" {
|
||||
export default : number;
|
||||
}
|
||||
|
||||
//// [reference1.ts]
|
||||
import d from "mod";
|
||||
var s: string = d; // Error
|
||||
|
||||
//// [reference2.ts]
|
||||
import { default as d } from "mod";
|
||||
var s: string = d; // Error
|
||||
|
||||
//// [reference1.js]
|
||||
var d = require("mod");
|
||||
var s = d; // Error
|
||||
//// [reference2.js]
|
||||
var _mod = require("mod");
|
||||
var s = _mod.default; // Error
|
||||
@ -0,0 +1,46 @@
|
||||
//// [initializePropertiesWithRenamedLet.ts]
|
||||
|
||||
var x0;
|
||||
if (true) {
|
||||
let x0;
|
||||
var obj1 = { x0: x0 };
|
||||
var obj2 = { x0 };
|
||||
}
|
||||
|
||||
var x, y, z;
|
||||
if (true) {
|
||||
let { x: x } = { x: 0 };
|
||||
let { y } = { y: 0 };
|
||||
let z;
|
||||
({ z: z } = { z: 0 });
|
||||
({ z } = { z: 0 });
|
||||
}
|
||||
|
||||
//// [initializePropertiesWithRenamedLet.js]
|
||||
var x0;
|
||||
if (true) {
|
||||
var _x0;
|
||||
var obj1 = {
|
||||
x0: _x0
|
||||
};
|
||||
var obj2 = {
|
||||
x0: _x0
|
||||
};
|
||||
}
|
||||
var x, y, z;
|
||||
if (true) {
|
||||
var _x = ({
|
||||
x: 0
|
||||
}).x;
|
||||
var _y = ({
|
||||
y: 0
|
||||
}).y;
|
||||
var _z;
|
||||
(_a = {
|
||||
z: 0
|
||||
}, _z = _a.z, _a);
|
||||
(_b = {
|
||||
z: 0
|
||||
}, _z = _b.z, _b);
|
||||
}
|
||||
var _a, _b;
|
||||
@ -0,0 +1,58 @@
|
||||
=== tests/cases/compiler/initializePropertiesWithRenamedLet.ts ===
|
||||
|
||||
var x0;
|
||||
>x0 : any
|
||||
|
||||
if (true) {
|
||||
let x0;
|
||||
>x0 : any
|
||||
|
||||
var obj1 = { x0: x0 };
|
||||
>obj1 : { x0: any; }
|
||||
>{ x0: x0 } : { x0: any; }
|
||||
>x0 : any
|
||||
>x0 : any
|
||||
|
||||
var obj2 = { x0 };
|
||||
>obj2 : { x0: any; }
|
||||
>{ x0 } : { x0: any; }
|
||||
>x0 : any
|
||||
}
|
||||
|
||||
var x, y, z;
|
||||
>x : any
|
||||
>y : any
|
||||
>z : any
|
||||
|
||||
if (true) {
|
||||
let { x: x } = { x: 0 };
|
||||
>x : unknown
|
||||
>x : number
|
||||
>{ x: 0 } : { x: number; }
|
||||
>x : number
|
||||
|
||||
let { y } = { y: 0 };
|
||||
>y : number
|
||||
>{ y: 0 } : { y: number; }
|
||||
>y : number
|
||||
|
||||
let z;
|
||||
>z : any
|
||||
|
||||
({ z: z } = { z: 0 });
|
||||
>({ z: z } = { z: 0 }) : { z: number; }
|
||||
>{ z: z } = { z: 0 } : { z: number; }
|
||||
>{ z: z } : { z: any; }
|
||||
>z : any
|
||||
>z : any
|
||||
>{ z: 0 } : { z: number; }
|
||||
>z : number
|
||||
|
||||
({ z } = { z: 0 });
|
||||
>({ z } = { z: 0 }) : { z: number; }
|
||||
>{ z } = { z: 0 } : { z: number; }
|
||||
>{ z } : { z: any; }
|
||||
>z : any
|
||||
>{ z: 0 } : { z: number; }
|
||||
>z : number
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(4,13): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(5,15): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(6,18): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(7,15): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(8,18): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts (5 errors) ====
|
||||
if (true) {
|
||||
let x;
|
||||
if (true) {
|
||||
var x = 0; // Error
|
||||
~
|
||||
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
var { x = 0 } = { x: 0 }; // Error
|
||||
~
|
||||
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
var { x: x = 0 } = { x: 0 }; // Error
|
||||
~
|
||||
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
var { x } = { x: 0 }; // Error
|
||||
~
|
||||
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
var { x: x } = { x: 0 }; // Error
|
||||
~
|
||||
!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'.
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
//// [shadowingViaLocalValueOrBindingElement.ts]
|
||||
if (true) {
|
||||
let x;
|
||||
if (true) {
|
||||
var x = 0; // Error
|
||||
var { x = 0 } = { x: 0 }; // Error
|
||||
var { x: x = 0 } = { x: 0 }; // Error
|
||||
var { x } = { x: 0 }; // Error
|
||||
var { x: x } = { x: 0 }; // Error
|
||||
}
|
||||
}
|
||||
|
||||
//// [shadowingViaLocalValueOrBindingElement.js]
|
||||
if (true) {
|
||||
var _x;
|
||||
if (true) {
|
||||
var x = 0; // Error
|
||||
var _a = ({
|
||||
x: 0
|
||||
}).x, x = _a === void 0 ? 0 : _a; // Error
|
||||
var _b = ({
|
||||
x: 0
|
||||
}).x, x = _b === void 0 ? 0 : _b; // Error
|
||||
var x = ({
|
||||
x: 0
|
||||
}).x; // Error
|
||||
var x = ({
|
||||
x: 0
|
||||
}).x; // Error
|
||||
}
|
||||
}
|
||||
@ -145,23 +145,16 @@ function someGenerics4(strs, n, f) {
|
||||
// 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type
|
||||
function someGenerics5(strs, n, f) {
|
||||
}
|
||||
(_n = ["", " ", ""], _n.raw = ["", " ", ""], someGenerics5(_n, 4, function () {
|
||||
(_o = ["", " ", ""], _o.raw = ["", " ", ""], someGenerics5(_o, 4, function () {
|
||||
return null;
|
||||
}));
|
||||
(_o = ["", "", ""], _o.raw = ["", "", ""], someGenerics5(_o, '', function () {
|
||||
(_p = ["", "", ""], _p.raw = ["", "", ""], someGenerics5(_p, '', function () {
|
||||
return 3;
|
||||
}));
|
||||
(_p = ["", "", ""], _p.raw = ["", "", ""], someGenerics5(_p, null, null));
|
||||
(_q = ["", "", ""], _q.raw = ["", "", ""], someGenerics5(_q, null, null));
|
||||
// Generic tag with multiple arguments of function types that each have parameters of the same generic type
|
||||
function someGenerics6(strs, a, b, c) {
|
||||
}
|
||||
(_q = ["", "", "", ""], _q.raw = ["", "", "", ""], someGenerics6(_q, function (n) {
|
||||
return n;
|
||||
}, function (n) {
|
||||
return n;
|
||||
}, function (n) {
|
||||
return n;
|
||||
}));
|
||||
(_r = ["", "", "", ""], _r.raw = ["", "", "", ""], someGenerics6(_r, function (n) {
|
||||
return n;
|
||||
}, function (n) {
|
||||
@ -176,16 +169,16 @@ function someGenerics6(strs, a, b, c) {
|
||||
}, function (n) {
|
||||
return n;
|
||||
}));
|
||||
// Generic tag with multiple arguments of function types that each have parameters of different generic type
|
||||
function someGenerics7(strs, a, b, c) {
|
||||
}
|
||||
(_t = ["", "", "", ""], _t.raw = ["", "", "", ""], someGenerics7(_t, function (n) {
|
||||
(_t = ["", "", "", ""], _t.raw = ["", "", "", ""], someGenerics6(_t, function (n) {
|
||||
return n;
|
||||
}, function (n) {
|
||||
return n;
|
||||
}, function (n) {
|
||||
return n;
|
||||
}));
|
||||
// Generic tag with multiple arguments of function types that each have parameters of different generic type
|
||||
function someGenerics7(strs, a, b, c) {
|
||||
}
|
||||
(_u = ["", "", "", ""], _u.raw = ["", "", "", ""], someGenerics7(_u, function (n) {
|
||||
return n;
|
||||
}, function (n) {
|
||||
@ -200,19 +193,26 @@ function someGenerics7(strs, a, b, c) {
|
||||
}, function (n) {
|
||||
return n;
|
||||
}));
|
||||
(_w = ["", "", "", ""], _w.raw = ["", "", "", ""], someGenerics7(_w, function (n) {
|
||||
return n;
|
||||
}, function (n) {
|
||||
return n;
|
||||
}, function (n) {
|
||||
return n;
|
||||
}));
|
||||
// Generic tag with argument of generic function type
|
||||
function someGenerics8(strs, n) {
|
||||
return n;
|
||||
}
|
||||
var x = (_w = ["", ""], _w.raw = ["", ""], someGenerics8(_w, someGenerics7));
|
||||
(_x = ["", "", "", ""], _x.raw = ["", "", "", ""], x(_x, null, null, null));
|
||||
var x = (_x = ["", ""], _x.raw = ["", ""], someGenerics8(_x, someGenerics7));
|
||||
(_y = ["", "", "", ""], _y.raw = ["", "", "", ""], x(_y, null, null, null));
|
||||
// Generic tag with multiple parameters of generic type passed arguments with no best common type
|
||||
function someGenerics9(strs, a, b, c) {
|
||||
return null;
|
||||
}
|
||||
var a9a = (_y = ["", "", "", ""], _y.raw = ["", "", "", ""], someGenerics9(_y, '', 0, []));
|
||||
var a9a = (_z = ["", "", "", ""], _z.raw = ["", "", "", ""], someGenerics9(_z, '', 0, []));
|
||||
var a9a;
|
||||
var a9e = (_z = ["", "", "", ""], _z.raw = ["", "", "", ""], someGenerics9(_z, undefined, {
|
||||
var a9e = (_0 = ["", "", "", ""], _0.raw = ["", "", "", ""], someGenerics9(_0, undefined, {
|
||||
x: 6,
|
||||
z: new Date()
|
||||
}, {
|
||||
@ -221,7 +221,7 @@ var a9e = (_z = ["", "", "", ""], _z.raw = ["", "", "", ""], someGenerics9(_z, u
|
||||
}));
|
||||
var a9e;
|
||||
// Generic tag with multiple parameters of generic type passed arguments with a single best common type
|
||||
var a9d = (_0 = ["", "", "", ""], _0.raw = ["", "", "", ""], someGenerics9(_0, {
|
||||
var a9d = (_1 = ["", "", "", ""], _1.raw = ["", "", "", ""], someGenerics9(_1, {
|
||||
x: 3
|
||||
}, {
|
||||
x: 6
|
||||
@ -231,9 +231,9 @@ var a9d = (_0 = ["", "", "", ""], _0.raw = ["", "", "", ""], someGenerics9(_0, {
|
||||
var a9d;
|
||||
// Generic tag with multiple parameters of generic type where one argument is of type 'any'
|
||||
var anyVar;
|
||||
var a = (_1 = ["", "", "", ""], _1.raw = ["", "", "", ""], someGenerics9(_1, 7, anyVar, 4));
|
||||
var a = (_2 = ["", "", "", ""], _2.raw = ["", "", "", ""], someGenerics9(_2, 7, anyVar, 4));
|
||||
var a;
|
||||
// Generic tag with multiple parameters of generic type where one argument is [] and the other is not 'any'
|
||||
var arr = (_2 = ["", "", "", ""], _2.raw = ["", "", "", ""], someGenerics9(_2, [], null, undefined));
|
||||
var arr = (_3 = ["", "", "", ""], _3.raw = ["", "", "", ""], someGenerics9(_3, [], null, undefined));
|
||||
var arr;
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
|
||||
|
||||
@ -103,26 +103,26 @@ var s = (_k = ["", ""], _k.raw = ["", ""], fn3(_k, 4));
|
||||
var s = (_l = ["", "", "", ""], _l.raw = ["", "", "", ""], fn3(_l, '', '', ''));
|
||||
var n = (_m = ["", "", "", ""], _m.raw = ["", "", "", ""], fn3(_m, '', '', 3));
|
||||
// Generic overloads with differing arity tagging with argument count that doesn't match any overload
|
||||
(_n = [""], _n.raw = [""], fn3(_n)); // Error
|
||||
(_o = [""], _o.raw = [""], fn3(_o)); // Error
|
||||
function fn4() {
|
||||
}
|
||||
// Generic overloads with constraints tagged with types that satisfy the constraints
|
||||
(_o = ["", "", ""], _o.raw = ["", "", ""], fn4(_o, '', 3));
|
||||
(_p = ["", "", ""], _p.raw = ["", "", ""], fn4(_p, 3, ''));
|
||||
(_q = ["", "", ""], _q.raw = ["", "", ""], fn4(_q, 3, undefined));
|
||||
(_r = ["", "", ""], _r.raw = ["", "", ""], fn4(_r, '', null));
|
||||
(_p = ["", "", ""], _p.raw = ["", "", ""], fn4(_p, '', 3));
|
||||
(_q = ["", "", ""], _q.raw = ["", "", ""], fn4(_q, 3, ''));
|
||||
(_r = ["", "", ""], _r.raw = ["", "", ""], fn4(_r, 3, undefined));
|
||||
(_s = ["", "", ""], _s.raw = ["", "", ""], fn4(_s, '', null));
|
||||
// Generic overloads with constraints called with type arguments that do not satisfy the constraints
|
||||
(_s = ["", "", ""], _s.raw = ["", "", ""], fn4(_s, null, null)); // Error
|
||||
(_t = ["", "", ""], _t.raw = ["", "", ""], fn4(_t, null, null)); // Error
|
||||
// Generic overloads with constraints called without type arguments but with types that do not satisfy the constraints
|
||||
(_t = ["", "", ""], _t.raw = ["", "", ""], fn4(_t, true, null));
|
||||
(_u = ["", "", ""], _u.raw = ["", "", ""], fn4(_u, null, true));
|
||||
(_u = ["", "", ""], _u.raw = ["", "", ""], fn4(_u, true, null));
|
||||
(_v = ["", "", ""], _v.raw = ["", "", ""], fn4(_v, null, true));
|
||||
function fn5() {
|
||||
return undefined;
|
||||
}
|
||||
(_v = ["", ""], _v.raw = ["", ""], fn5(_v, function (n) {
|
||||
(_w = ["", ""], _w.raw = ["", ""], fn5(_w, function (n) {
|
||||
return n.toFixed();
|
||||
})); // will error; 'n' should have type 'string'.
|
||||
(_w = ["", ""], _w.raw = ["", ""], fn5(_w, function (n) {
|
||||
(_x = ["", ""], _x.raw = ["", ""], fn5(_x, function (n) {
|
||||
return n.substr(0);
|
||||
}));
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
||||
|
||||
4
tests/cases/compiler/exportDefaultTypeAnnoation.ts
Normal file
4
tests/cases/compiler/exportDefaultTypeAnnoation.ts
Normal file
@ -0,0 +1,4 @@
|
||||
// @target: es5
|
||||
// @module: commonjs
|
||||
|
||||
export default : number;
|
||||
6
tests/cases/compiler/exportDefaultTypeAnnoation2.ts
Normal file
6
tests/cases/compiler/exportDefaultTypeAnnoation2.ts
Normal file
@ -0,0 +1,6 @@
|
||||
// @target: es5
|
||||
// @module: commonjs
|
||||
|
||||
declare module "mod" {
|
||||
export default : number;
|
||||
}
|
||||
15
tests/cases/compiler/exportDefaultTypeAnnoation3.ts
Normal file
15
tests/cases/compiler/exportDefaultTypeAnnoation3.ts
Normal file
@ -0,0 +1,15 @@
|
||||
// @target: es5
|
||||
// @module: commonjs
|
||||
|
||||
// @fileName: mod.d.ts
|
||||
declare module "mod" {
|
||||
export default : number;
|
||||
}
|
||||
|
||||
// @fileName: reference1.ts
|
||||
import d from "mod";
|
||||
var s: string = d; // Error
|
||||
|
||||
// @fileName: reference2.ts
|
||||
import { default as d } from "mod";
|
||||
var s: string = d; // Error
|
||||
17
tests/cases/compiler/initializePropertiesWithRenamedLet.ts
Normal file
17
tests/cases/compiler/initializePropertiesWithRenamedLet.ts
Normal file
@ -0,0 +1,17 @@
|
||||
// @target: es5
|
||||
|
||||
var x0;
|
||||
if (true) {
|
||||
let x0;
|
||||
var obj1 = { x0: x0 };
|
||||
var obj2 = { x0 };
|
||||
}
|
||||
|
||||
var x, y, z;
|
||||
if (true) {
|
||||
let { x: x } = { x: 0 };
|
||||
let { y } = { y: 0 };
|
||||
let z;
|
||||
({ z: z } = { z: 0 });
|
||||
({ z } = { z: 0 });
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
if (true) {
|
||||
let x;
|
||||
if (true) {
|
||||
var x = 0; // Error
|
||||
var { x = 0 } = { x: 0 }; // Error
|
||||
var { x: x = 0 } = { x: 0 }; // Error
|
||||
var { x } = { x: 0 }; // Error
|
||||
var { x: x } = { x: 0 }; // Error
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
var f1 = ()
|
||||
=> { }
|
||||
var f2 = (x: string, y: string) /*
|
||||
*/ => { }
|
||||
var f3 = (x: string, y: number, ...rest)
|
||||
=> { }
|
||||
var f4 = (x: string, y: number, ...rest) /*
|
||||
*/ => { }
|
||||
var f5 = (...rest)
|
||||
=> { }
|
||||
var f6 = (...rest) /*
|
||||
*/ => { }
|
||||
var f7 = (x: string, y: number, z = 10)
|
||||
=> { }
|
||||
var f8 = (x: string, y: number, z = 10) /*
|
||||
*/ => { }
|
||||
var f9 = (a: number): number
|
||||
=> a;
|
||||
var f10 = (a: number) :
|
||||
number
|
||||
=> a
|
||||
var f11 = (a: number): number /*
|
||||
*/ => a;
|
||||
var f12 = (a: number) :
|
||||
number /*
|
||||
*/ => a
|
||||
|
||||
// Should be valid.
|
||||
var f11 = (a: number
|
||||
) => a;
|
||||
|
||||
// Should be valid.
|
||||
var f12 = (a: number)
|
||||
: number => a;
|
||||
|
||||
// Should be valid.
|
||||
var f13 = (a: number):
|
||||
number => a;
|
||||
|
||||
// Should be valid.
|
||||
var f14 = () /* */ => {}
|
||||
|
||||
// Should be valid.
|
||||
var f15 = (a: number): number /* */ => a
|
||||
|
||||
// Should be valid.
|
||||
var f16 = (a: number, b = 10):
|
||||
number /* */ => a + b;
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
foo(()
|
||||
=> true);
|
||||
foo(()
|
||||
=> { return false; });
|
||||
|
||||
module m {
|
||||
class City {
|
||||
constructor(x: number, thing = ()
|
||||
=> 100) {
|
||||
}
|
||||
|
||||
public m = ()
|
||||
=> 2 * 2 * 2
|
||||
}
|
||||
|
||||
export enum Enum {
|
||||
claw = (()
|
||||
=> 10)()
|
||||
}
|
||||
|
||||
export var v = x
|
||||
=> new City(Enum.claw);
|
||||
}
|
||||
24
tests/cases/fourslash/navbar_exportDefault.ts
Normal file
24
tests/cases/fourslash/navbar_exportDefault.ts
Normal file
@ -0,0 +1,24 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @Filename: a.ts
|
||||
//// {| "itemName": "default", "kind": "class", "parentName": "" |}export default class { }
|
||||
|
||||
// @Filename: b.ts
|
||||
//// {| "itemName": "C", "kind": "class", "parentName": "" |}export default class C { }
|
||||
|
||||
// @Filename: c.ts
|
||||
//// {| "itemName": "default", "kind": "function", "parentName": "" |}export default function { }
|
||||
|
||||
// @Filename: d.ts
|
||||
//// {| "itemName": "Func", "kind": "function", "parentName": "" |}export default function Func { }
|
||||
|
||||
test.markers().forEach(marker => {
|
||||
goTo.file(marker.fileName);
|
||||
verify.getScriptLexicalStructureListContains(
|
||||
marker.data.itemName,
|
||||
marker.data.kind,
|
||||
marker.fileName,
|
||||
marker.data.parentName,
|
||||
marker.data.isAdditionalRange,
|
||||
marker.position);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user