Merge branch 'master' into LessAggresiveCompletionList

This commit is contained in:
Paul van Brenk
2015-01-21 17:44:07 -08:00
51 changed files with 2258 additions and 364 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ module ts {
export function getModuleInstanceState(node: Node): ModuleInstanceState {
// A module is uninstantiated if it contains only
// 1. interface declarations
if (node.kind === SyntaxKind.InterfaceDeclaration) {
// 1. interface declarations, type alias declarations
if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.TypeAliasDeclaration) {
return ModuleInstanceState.NonInstantiated;
}
// 2. const enum declarations don't make module instantiated
+35 -24
View File
@@ -16,6 +16,8 @@ module ts {
var emptySymbols: SymbolTable = {};
var compilerOptions = host.getCompilerOptions();
var languageVersion = compilerOptions.target || ScriptTarget.ES3;
var emitResolver = createResolver();
var checker: TypeChecker = {
@@ -5618,7 +5620,7 @@ module ts {
}
var isConstEnum = isConstEnumObjectType(objectType);
if (isConstEnum &&
if (isConstEnum &&
(!node.argumentExpression || node.argumentExpression.kind !== SyntaxKind.StringLiteral)) {
error(node.argumentExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal);
return unknownType;
@@ -5650,10 +5652,10 @@ module ts {
}
// Check for compatible indexer types.
if (indexType.flags & (TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike)) {
if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike)) {
// Try to use a number indexer.
if (indexType.flags & (TypeFlags.Any | TypeFlags.NumberLike)) {
if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.NumberLike)) {
var numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number);
if (numberIndexType) {
return numberIndexType;
@@ -6357,7 +6359,7 @@ module ts {
function checkTaggedTemplateExpression(node: TaggedTemplateExpression): Type {
// Grammar checking
if (compilerOptions.target < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
grammarErrorOnFirstToken(node.template, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher);
}
@@ -6554,7 +6556,7 @@ module ts {
}
function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean {
if (!(type.flags & (TypeFlags.Any | TypeFlags.NumberLike))) {
if (!isTypeOfKind(type, TypeFlags.Any | TypeFlags.NumberLike)) {
error(operand, diagnostic);
return false;
}
@@ -6705,12 +6707,21 @@ module ts {
return numberType;
}
// Return true if type an object type, a type parameter, or a union type composed of only those kinds of types
function isStructuredType(type: Type): boolean {
if (type.flags & TypeFlags.Union) {
return !forEach((<UnionType>type).types, t => !isStructuredType(t));
// Return true if type has the given flags, or is a union type composed of types that all have those flags
function isTypeOfKind(type: Type, kind: TypeFlags): boolean {
if (type.flags & kind) {
return true;
}
return (type.flags & (TypeFlags.ObjectType | TypeFlags.TypeParameter)) !== 0;
if (type.flags & TypeFlags.Union) {
var types = (<UnionType>type).types;
for (var i = 0; i < types.length; i++) {
if (!(types[i].flags & kind)) {
return false;
}
}
return true;
}
return false;
}
function isConstEnumObjectType(type: Type): boolean {
@@ -6727,7 +6738,7 @@ module ts {
// and the right operand to be of type Any or a subtype of the 'Function' interface type.
// The result is always of the Boolean primitive type.
// NOTE: do not raise error if leftType is unknown as related error was already reported
if (!(leftType.flags & TypeFlags.Any || isStructuredType(leftType))) {
if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
}
// NOTE: do not raise error if right is unknown as related error was already reported
@@ -6742,10 +6753,10 @@ module ts {
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
// and the right operand to be of type Any, an object type, or a type parameter type.
// The result is always of the Boolean primitive type.
if (leftType !== anyType && leftType !== stringType && leftType !== numberType) {
if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike)) {
error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number);
}
if (!(rightType.flags & TypeFlags.Any || isStructuredType(rightType))) {
if (!isTypeOfKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
}
return booleanType;
@@ -6906,16 +6917,16 @@ module ts {
if (rightType.flags & (TypeFlags.Undefined | TypeFlags.Null)) rightType = leftType;
var resultType: Type;
if (leftType.flags & TypeFlags.NumberLike && rightType.flags & TypeFlags.NumberLike) {
if (isTypeOfKind(leftType, TypeFlags.NumberLike) && isTypeOfKind(rightType, TypeFlags.NumberLike)) {
// Operands of an enum type are treated as having the primitive type Number.
// If both operands are of the Number primitive type, the result is of the Number primitive type.
resultType = numberType;
}
else if (leftType.flags & TypeFlags.StringLike || rightType.flags & TypeFlags.StringLike) {
else if (isTypeOfKind(leftType, TypeFlags.StringLike) || isTypeOfKind(rightType, TypeFlags.StringLike)) {
// If one or both operands are of the String primitive type, the result is of the String primitive type.
resultType = stringType;
}
else if (leftType.flags & TypeFlags.Any || leftType === unknownType || rightType.flags & TypeFlags.Any || rightType === unknownType) {
else if (leftType.flags & TypeFlags.Any || rightType.flags & TypeFlags.Any) {
// Otherwise, the result is of type Any.
// NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we.
resultType = anyType;
@@ -8271,7 +8282,7 @@ module ts {
var exprType = checkExpression(node.expression);
// unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved
// in this case error about missing name is already reported - do not report extra one
if (!(exprType.flags & TypeFlags.Any || isStructuredType(exprType))) {
if (!isTypeOfKind(exprType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter);
}
@@ -10055,7 +10066,7 @@ module ts {
globalRegExpType = getGlobalType("RegExp");
// If we're in ES6 mode, load the TemplateStringsArray.
// Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios.
globalTemplateStringsArrayType = compilerOptions.target >= ScriptTarget.ES6
globalTemplateStringsArrayType = languageVersion >= ScriptTarget.ES6
? getGlobalType("TemplateStringsArray")
: unknownType;
anyArrayType = createArrayType(anyType);
@@ -10427,7 +10438,7 @@ module ts {
return;
var computedPropertyName = <ComputedPropertyName>node;
if (compilerOptions.target < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher);
}
else if (computedPropertyName.expression.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>computedPropertyName.expression).operator === SyntaxKind.CommaToken) {
@@ -10527,7 +10538,7 @@ module ts {
function checkGrammarAccessor(accessor: MethodDeclaration): boolean {
var kind = accessor.kind;
if (compilerOptions.target < ScriptTarget.ES5) {
if (languageVersion < ScriptTarget.ES5) {
return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
}
else if (isInAmbientContext(accessor)) {
@@ -10732,7 +10743,7 @@ module ts {
return grammarErrorAtPos(getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty);
}
if (compilerOptions.target < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
if (isLet(declarationList)) {
return grammarErrorOnFirstToken(declarationList, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
}
@@ -10834,7 +10845,7 @@ module ts {
function grammarErrorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
var sourceFile = getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
var scanner = createScanner(compilerOptions.target, /*skipTrivia*/ true, sourceFile.text);
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
var start = scanToken(scanner, node.pos);
diagnostics.push(createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2));
return true;
@@ -10976,7 +10987,7 @@ module ts {
if (node.parserContextFlags & ParserContextFlags.StrictMode) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
}
else if (compilerOptions.target >= ScriptTarget.ES5) {
else if (languageVersion >= ScriptTarget.ES5) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
}
}
@@ -10985,7 +10996,7 @@ module ts {
function grammarErrorAfterFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
var sourceFile = getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
var scanner = createScanner(compilerOptions.target, /*skipTrivia*/ true, sourceFile.text);
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
scanToken(scanner, node.pos);
diagnostics.push(createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2));
return true;
+104 -16
View File
@@ -33,6 +33,10 @@ module ts {
type: "boolean",
description: Diagnostics.Print_this_message,
},
{
name: "listFiles",
type: "boolean",
},
{
name: "locale",
type: "string",
@@ -40,6 +44,7 @@ module ts {
{
name: "mapRoot",
type: "string",
isFilePath: true,
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
paramType: Diagnostics.LOCATION,
},
@@ -90,6 +95,7 @@ module ts {
{
name: "outDir",
type: "string",
isFilePath: true,
description: Diagnostics.Redirect_output_structure_to_the_directory,
paramType: Diagnostics.DIRECTORY,
},
@@ -98,6 +104,14 @@ module ts {
type: "boolean",
description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
},
{
name: "project",
shortName: "p",
type: "string",
isFilePath: true,
description: Diagnostics.Compile_the_project_in_the_given_directory,
paramType: Diagnostics.DIRECTORY
},
{
name: "removeComments",
type: "boolean",
@@ -111,6 +125,7 @@ module ts {
{
name: "sourceRoot",
type: "string",
isFilePath: true,
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
paramType: Diagnostics.LOCATION,
},
@@ -141,26 +156,19 @@ module ts {
}
];
var shortOptionNames: Map<string> = {};
var optionNameMap: Map<CommandLineOption> = {};
forEach(optionDeclarations, option => {
optionNameMap[option.name.toLowerCase()] = option;
if (option.shortName) {
shortOptionNames[option.shortName] = option.name;
}
});
export function parseCommandLine(commandLine: string[]): ParsedCommandLine {
// Set default compiler option values
var options: CompilerOptions = {
target: ScriptTarget.ES3,
module: ModuleKind.None
};
var options: CompilerOptions = {};
var filenames: string[] = [];
var errors: Diagnostic[] = [];
var shortOptionNames: Map<string> = {};
var optionNameMap: Map<CommandLineOption> = {};
forEach(optionDeclarations, option => {
optionNameMap[option.name.toLowerCase()] = option;
if (option.shortName) {
shortOptionNames[option.shortName] = option.name;
}
});
parseStrings(commandLine);
return {
options,
@@ -256,4 +264,84 @@ module ts {
parseStrings(args);
}
}
export function readConfigFile(filename: string): any {
try {
var text = sys.readFile(filename);
return /\S/.test(text) ? JSON.parse(text) : {};
}
catch (e) {
}
}
export function parseConfigFile(json: any, basePath?: string): ParsedCommandLine {
var errors: Diagnostic[] = [];
return {
options: getCompilerOptions(),
filenames: getFiles(),
errors
};
function getCompilerOptions(): CompilerOptions {
var options: CompilerOptions = {};
var optionNameMap: Map<CommandLineOption> = {};
forEach(optionDeclarations, option => {
optionNameMap[option.name] = option;
});
var jsonOptions = json["compilerOptions"];
if (jsonOptions) {
for (var id in jsonOptions) {
if (hasProperty(optionNameMap, id)) {
var opt = optionNameMap[id];
var optType = opt.type;
var value = jsonOptions[id];
var expectedType = typeof optType === "string" ? optType : "string";
if (typeof value === expectedType) {
if (typeof optType !== "string") {
var key = value.toLowerCase();
if (hasProperty(optType, key)) {
value = optType[key];
}
else {
errors.push(createCompilerDiagnostic(opt.error));
value = 0;
}
}
if (opt.isFilePath) {
value = normalizePath(combinePaths(basePath, value));
}
options[opt.name] = value;
}
else {
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType));
}
}
else {
errors.push(createCompilerDiagnostic(Diagnostics.Unknown_compiler_option_0, id));
}
}
}
return options;
}
function getFiles(): string[] {
var files: string[] = [];
if (hasProperty(json, "files")) {
if (json["files"] instanceof Array) {
var files = map(<string[]>json["files"], s => combinePaths(basePath, s));
}
}
else {
var sysFiles = sys.readDirectory(basePath, ".ts");
for (var i = 0; i < sysFiles.length; i++) {
var name = sysFiles[i];
if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {
files.push(name);
}
}
}
return files;
}
}
}
+14 -1
View File
@@ -178,6 +178,19 @@ module ts {
return <T>result;
}
export function extend<T>(first: Map<T>, second: Map<T>): Map<T> {
var result: Map<T> = {};
for (var id in first) {
result[id] = first[id];
}
for (var id in second) {
if (!hasProperty(result, id)) {
result[id] = second[id];
}
}
return result;
}
export function forEachValue<T, U>(map: Map<T>, callback: (value: T) => U): U {
var result: U;
for (var id in map) {
@@ -568,7 +581,7 @@ module ts {
export function combinePaths(path1: string, path2: string) {
if (!(path1 && path1.length)) return path2;
if (!(path2 && path2.length)) return path1;
if (path2.charAt(0) === directorySeparator) return path2;
if (getRootLength(path2) !== 0) return path2;
if (path1.charAt(path1.length - 1) === directorySeparator) return path1 + path2;
return path1 + directorySeparator + path2;
}
@@ -380,11 +380,13 @@ module ts {
Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
Unsupported_file_encoding: { code: 5013, category: DiagnosticCategory.Error, key: "Unsupported file encoding." },
Unknown_compiler_option_0: { code: 5023, category: DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option mapRoot cannot be specified without specifying sourcemap option." },
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option sourceRoot cannot be specified without specifying sourcemap option." },
Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option noEmit cannot be specified with option out or outDir." },
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option noEmit cannot be specified with option declaration." },
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." },
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." },
Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." },
Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." },
@@ -399,6 +401,7 @@ module ts {
Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" },
Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." },
Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." },
Compile_the_project_in_the_given_directory: { code: 6020, category: DiagnosticCategory.Message, key: "Compile the project in the given directory." },
Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" },
options: { code: 6024, category: DiagnosticCategory.Message, key: "options" },
file: { code: 6025, category: DiagnosticCategory.Message, key: "file" },
@@ -406,7 +409,7 @@ module ts {
Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" },
Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" },
Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." },
File_change_detected_Compiling: { code: 6032, category: DiagnosticCategory.Message, key: "File change detected. Compiling..." },
File_change_detected_Starting_incremental_compilation: { code: 6032, category: DiagnosticCategory.Message, key: "File change detected. Starting incremental compilation..." },
KIND: { code: 6034, category: DiagnosticCategory.Message, key: "KIND" },
FILE: { code: 6035, category: DiagnosticCategory.Message, key: "FILE" },
VERSION: { code: 6036, category: DiagnosticCategory.Message, key: "VERSION" },
+17 -5
View File
@@ -1618,26 +1618,34 @@
"category": "Error",
"code": 5023
},
"Compiler option '{0}' requires a value of type {1}.": {
"category": "Error",
"code": 5024
},
"Could not write file '{0}': {1}": {
"category": "Error",
"code": 5033
},
"Option mapRoot cannot be specified without specifying sourcemap option.": {
"Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.": {
"category": "Error",
"code": 5038
},
"Option sourceRoot cannot be specified without specifying sourcemap option.": {
"Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.": {
"category": "Error",
"code": 5039
},
"Option noEmit cannot be specified with option out or outDir.": {
"Option 'noEmit' cannot be specified with option 'out' or 'outDir'.": {
"category": "Error",
"code": 5040
},
"Option noEmit cannot be specified with option declaration.": {
"Option 'noEmit' cannot be specified with option 'declaration'.": {
"category": "Error",
"code": 5041
},
"Option 'project' cannot be mixed with source files on a command line.": {
"category": "Error",
"code": 5042
},
"Concatenate and emit output to single file.": {
"category": "Message",
"code": 6001
@@ -1694,6 +1702,10 @@
"category": "Message",
"code": 6019
},
"Compile the project in the given directory.": {
"category": "Message",
"code": 6020
},
"Syntax: {0}": {
"category": "Message",
"code": 6023
@@ -1722,7 +1734,7 @@
"category": "Message",
"code": 6030
},
"File change detected. Compiling...": {
"File change detected. Starting incremental compilation...": {
"category": "Message",
"code": 6032
},
+19 -16
View File
@@ -170,9 +170,10 @@ module ts {
function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){
if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) {
var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos);
var lastLine = currentSourceFile.getLineStarts().length;
var firstCommentLineIndent: number;
for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, /*character*/1);
var nextLineStart = currentLine === lastLine ? (comment.end + 1) : currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, /*character*/1);
if (pos !== comment.pos) {
// If we are not emitting first line, we need to write the spaces to adjust the alignment
@@ -339,6 +340,7 @@ module ts {
function emitDeclarations(host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit {
var newLine = host.getNewLine();
var compilerOptions = host.getCompilerOptions();
var languageVersion = compilerOptions.target || ScriptTarget.ES3;
var write: (s: string) => void;
var writeLine: () => void;
@@ -1473,6 +1475,7 @@ module ts {
export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile?: SourceFile): EmitResult {
// var program = resolver.getProgram();
var compilerOptions = host.getCompilerOptions();
var languageVersion = compilerOptions.target || ScriptTarget.ES3;
var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined;
var diagnostics: Diagnostic[] = [];
var newLine = host.getNewLine();
@@ -2021,14 +2024,14 @@ module ts {
}
function emitLiteral(node: LiteralExpression) {
var text = compilerOptions.target < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) :
var text = languageVersion < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) :
node.parent ? getSourceTextOfNodeFromSourceFile(currentSourceFile, node) :
node.text;
if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) {
writer.writeLiteral(text);
}
// For version below ES6, emit binary integer literal and octal integer literal in canonical form
else if (compilerOptions.target < ScriptTarget.ES6 && node.kind === SyntaxKind.NumericLiteral && isBinaryOrOctalIntegerLiteral(text)) {
else if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.NumericLiteral && isBinaryOrOctalIntegerLiteral(text)) {
write(node.text);
}
else {
@@ -2043,7 +2046,7 @@ module ts {
function emitTemplateExpression(node: TemplateExpression): void {
// In ES6 mode and above, we can simply emit each portion of a template in order, but in
// ES3 & ES5 we must convert the template expression into a series of string concatenations.
if (compilerOptions.target >= ScriptTarget.ES6) {
if (languageVersion >= ScriptTarget.ES6) {
forEachChild(node, emit);
return;
}
@@ -2150,7 +2153,7 @@ module ts {
//
// TODO (drosen): Note that we need to account for the upcoming 'yield' and
// spread ('...') unary operators that are anticipated for ES6.
Debug.assert(compilerOptions.target <= ScriptTarget.ES5);
Debug.assert(languageVersion < ScriptTarget.ES6);
switch (expression.kind) {
case SyntaxKind.BinaryExpression:
switch ((<BinaryExpression>expression).operator) {
@@ -2335,7 +2338,7 @@ module ts {
write("[]");
return;
}
if (compilerOptions.target >= ScriptTarget.ES6) {
if (languageVersion >= ScriptTarget.ES6) {
write("[");
emitList(elements, 0, elements.length, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0,
/*trailingComma*/ elements.hasTrailingComma);
@@ -2385,7 +2388,7 @@ module ts {
write(" ");
}
emitList(properties, 0, properties.length, /*multiLine*/ multiLine,
/*trailingComma*/ properties.hasTrailingComma && compilerOptions.target >= ScriptTarget.ES5);
/*trailingComma*/ properties.hasTrailingComma && languageVersion >= ScriptTarget.ES5);
if (!multiLine) {
write(" ");
}
@@ -2405,7 +2408,7 @@ module ts {
}
emitLeadingComments(node);
emit(node.name);
if (compilerOptions.target < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
write(": function ");
}
emitSignatureAndBody(node);
@@ -2431,7 +2434,7 @@ module ts {
// export var obj = { y };
// }
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
if (compilerOptions.target < ScriptTarget.ES6 || resolver.getExpressionNamePrefix(node.name)) {
if (languageVersion < ScriptTarget.ES6 || resolver.getExpressionNamePrefix(node.name)) {
// Emit identifier as an identifier
write(": ");
// Even though this is stored as identifier treat it as an expression
@@ -2513,7 +2516,7 @@ module ts {
}
function emitTaggedTemplateExpression(node: TaggedTemplateExpression): void {
Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Trying to emit a tagged template in pre-ES6 mode.");
Debug.assert(languageVersion >= ScriptTarget.ES6, "Trying to emit a tagged template in pre-ES6 mode.");
emit(node.tag);
write(" ");
emit(node.template);
@@ -2605,7 +2608,7 @@ module ts {
function emitBinaryExpression(node: BinaryExpression) {
if (compilerOptions.target < ScriptTarget.ES6 && node.operator === SyntaxKind.EqualsToken &&
if (languageVersion < ScriptTarget.ES6 && node.operator === SyntaxKind.EqualsToken &&
(node.left.kind === SyntaxKind.ObjectLiteralExpression || node.left.kind === SyntaxKind.ArrayLiteralExpression)) {
emitDestructuring(node);
}
@@ -3101,7 +3104,7 @@ module ts {
function emitVariableDeclaration(node: VariableDeclaration) {
emitLeadingComments(node);
if (isBindingPattern(node.name)) {
if (compilerOptions.target < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
emitDestructuring(node);
}
else {
@@ -3136,7 +3139,7 @@ module ts {
function emitParameter(node: ParameterDeclaration) {
emitLeadingComments(node);
if (compilerOptions.target < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
if (isBindingPattern(node.name)) {
var name = createTempVariable(node);
if (!tempParameters) {
@@ -3160,7 +3163,7 @@ module ts {
}
function emitDefaultValueAssignments(node: FunctionLikeDeclaration) {
if (compilerOptions.target < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
var tempIndex = 0;
forEach(node.parameters, p => {
if (isBindingPattern(p.name)) {
@@ -3190,7 +3193,7 @@ module ts {
}
function emitRestParameter(node: FunctionLikeDeclaration) {
if (compilerOptions.target < ScriptTarget.ES6 && hasRestParameters(node)) {
if (languageVersion < ScriptTarget.ES6 && hasRestParameters(node)) {
var restIndex = node.parameters.length - 1;
var restParam = node.parameters[restIndex];
var tempName = createTempVariable(node, /*forLoopVariable*/ true).text;
@@ -3269,7 +3272,7 @@ module ts {
write("(");
if (node) {
var parameters = node.parameters;
var omitCount = compilerOptions.target < ScriptTarget.ES6 && hasRestParameters(node) ? 1 : 0;
var omitCount = languageVersion < ScriptTarget.ES6 && hasRestParameters(node) ? 1 : 0;
emitList(parameters, 0, parameters.length - omitCount, /*multiLine*/ false, /*trailingComma*/ false);
}
write(")");
+4 -2
View File
@@ -146,7 +146,9 @@ module ts {
function invokeEmitter(targetSourceFile?: SourceFile) {
var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver();
return emitFiles(resolver, getEmitHost(), targetSourceFile);
} function getSourceFile(filename: string) {
}
function getSourceFile(filename: string) {
filename = host.getCanonicalFileName(filename);
return hasProperty(filesByName, filename) ? filesByName[filename] : undefined;
}
@@ -340,7 +342,7 @@ module ts {
}
var firstExternalModule = forEach(files, f => isExternalModule(f) ? f : undefined);
if (firstExternalModule && options.module === ModuleKind.None) {
if (firstExternalModule && !options.module) {
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
var externalModuleErrorSpan = getErrorSpanForNode(firstExternalModule.externalModuleIndicator);
var errorStart = skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos);
+7 -7
View File
@@ -224,15 +224,15 @@ module ts {
}
function isUnicodeIdentifierStart(code: number, languageVersion: ScriptTarget) {
return languageVersion === ScriptTarget.ES3 ?
lookupInUnicodeMap(code, unicodeES3IdentifierStart) :
lookupInUnicodeMap(code, unicodeES5IdentifierStart);
return languageVersion >= ScriptTarget.ES5 ?
lookupInUnicodeMap(code, unicodeES5IdentifierStart) :
lookupInUnicodeMap(code, unicodeES3IdentifierStart);
}
function isUnicodeIdentifierPart(code: number, languageVersion: ScriptTarget) {
return languageVersion === ScriptTarget.ES3 ?
lookupInUnicodeMap(code, unicodeES3IdentifierPart) :
lookupInUnicodeMap(code, unicodeES5IdentifierPart);
return languageVersion >= ScriptTarget.ES5 ?
lookupInUnicodeMap(code, unicodeES5IdentifierPart) :
lookupInUnicodeMap(code, unicodeES3IdentifierPart);
}
function makeReverseMap(source: Map<number>): string[] {
@@ -279,7 +279,7 @@ module ts {
}
export function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number {
Debug.assert(line > 0);
Debug.assert(line > 0 && line <= lineStarts.length );
return lineStarts[line - 1] + character - 1;
}
+64
View File
@@ -1,3 +1,4 @@
/// <reference path="core.ts"/>
module ts {
export interface System {
@@ -14,6 +15,7 @@ module ts {
createDirectory(directoryName: string): void;
getExecutingFilePath(): string;
getCurrentDirectory(): string;
readDirectory(path: string, extension?: string): string[];
getMemoryUsage? (): number;
exit(exitCode?: number): void;
}
@@ -28,6 +30,13 @@ module ts {
declare var global: any;
declare var __filename: string;
declare class Enumerator {
public atEnd(): boolean;
public moveNext(): boolean;
public item(): any;
constructor(o: any);
}
export var sys: System = (function () {
function getWScriptSystem(): System {
@@ -100,6 +109,34 @@ module ts {
}
}
function getNames(collection: any): string[] {
var result: string[] = [];
for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
result.push(e.item().Name);
}
return result.sort();
}
function readDirectory(path: string, extension?: string): string[] {
var result: string[] = [];
visitDirectory(path);
return result;
function visitDirectory(path: string) {
var folder = fso.GetFolder(path || ".");
var files = getNames(folder.files);
for (var i = 0; i < files.length; i++) {
var name = files[i];
if (!extension || fileExtensionIs(name, extension)) {
result.push(combinePaths(path, name));
}
}
var subfolders = getNames(folder.subfolders);
for (var i = 0; i < subfolders.length; i++) {
visitDirectory(combinePaths(path, subfolders[i]));
}
}
}
return {
args,
newLine: "\r\n",
@@ -129,6 +166,7 @@ module ts {
getCurrentDirectory() {
return new ActiveXObject("WScript.Shell").CurrentDirectory;
},
readDirectory,
exit(exitCode?: number): void {
try {
WScript.Quit(exitCode);
@@ -185,6 +223,31 @@ module ts {
_fs.writeFileSync(fileName, data, "utf8");
}
function readDirectory(path: string, extension?: string): string[] {
var result: string[] = [];
visitDirectory(path);
return result;
function visitDirectory(path: string) {
var files = _fs.readdirSync(path || ".").sort();
var directories: string[] = [];
for (var i = 0; i < files.length; i++) {
var name = combinePaths(path, files[i]);
var stat = _fs.lstatSync(name);
if (stat.isFile()) {
if (!extension || fileExtensionIs(name, extension)) {
result.push(name);
}
}
else if (stat.isDirectory()) {
directories.push(name);
}
}
for (var i = 0; i < directories.length; i++) {
visitDirectory(directories[i]);
}
}
}
return {
args: process.argv.slice(2),
newLine: _os.EOL,
@@ -231,6 +294,7 @@ module ts {
getCurrentDirectory() {
return process.cwd();
},
readDirectory,
getMemoryUsage() {
if (global.gc) {
global.gc();
+158 -98
View File
@@ -4,6 +4,10 @@
module ts {
var version = "1.4.0.0";
export interface SourceFile {
fileWatcher: FileWatcher;
}
/**
* Checks to see if the locale is in the appropriate format,
* and if it is, attempts to set the appropriate language.
@@ -126,16 +130,43 @@ module ts {
reportStatisticalValue(name, (time / 1000).toFixed(2) + "s");
}
function isJSONSupported() {
return typeof JSON === "object" && typeof JSON.parse === "function";
}
function findConfigFile(): string {
var searchPath = normalizePath(sys.getCurrentDirectory());
var filename = "tsconfig.json";
while (true) {
if (sys.fileExists(filename)) {
return filename;
}
var parentPath = getDirectoryPath(searchPath);
if (parentPath === searchPath) {
break;
}
searchPath = parentPath;
filename = "../" + filename;
}
return undefined;
}
export function executeCommandLine(args: string[]): void {
var commandLine = parseCommandLine(args);
var compilerOptions = commandLine.options;
var configFilename: string; // Configuration file name (if any)
var configFileWatcher: FileWatcher; // Configuration file watcher
var cachedProgram: Program; // Program cached from last compilation
var rootFilenames: string[]; // Root filenames for compilation
var compilerOptions: CompilerOptions; // Compiler options for compilation
var compilerHost: CompilerHost; // Compiler host
var hostGetSourceFile: typeof compilerHost.getSourceFile; // getSourceFile method from default host
var timerHandle: number; // Handle for 0.25s wait timer
if (compilerOptions.locale) {
if (typeof JSON === "undefined") {
if (commandLine.options.locale) {
if (!isJSONSupported()) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"));
return sys.exit(1);
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
}
validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors);
}
@@ -146,131 +177,153 @@ module ts {
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
}
if (compilerOptions.version) {
if (commandLine.options.version) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version));
return sys.exit(EmitReturnStatus.Succeeded);
}
if (compilerOptions.help) {
if (commandLine.options.help) {
printVersion();
printHelp();
return sys.exit(EmitReturnStatus.Succeeded);
}
if (commandLine.filenames.length === 0) {
if (commandLine.options.project) {
if (!isJSONSupported()) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project"));
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
}
configFilename = normalizePath(combinePaths(commandLine.options.project, "tsconfig.json"));
if (commandLine.filenames.length !== 0) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line));
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
}
}
else if (commandLine.filenames.length === 0 && isJSONSupported()) {
configFilename = findConfigFile();
}
if (commandLine.filenames.length === 0 && !configFilename) {
printVersion();
printHelp();
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
}
var defaultCompilerHost = createCompilerHost(compilerOptions);
if (compilerOptions.watch) {
if (commandLine.options.watch) {
if (!sys.watchFile) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"));
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
}
watchProgram(commandLine, defaultCompilerHost);
}
else {
var result = compile(commandLine, defaultCompilerHost).exitStatus
return sys.exit(result);
}
}
/**
* Compiles the program once, and then watches all given and referenced files for changes.
* Upon detecting a file change, watchProgram will queue up file modification events for the next
* 250ms and then perform a recompilation. The reasoning is that in some cases, an editor can
* save all files at once, and we'd like to just perform a single recompilation.
*/
function watchProgram(commandLine: ParsedCommandLine, compilerHost: CompilerHost): void {
var watchers: Map<FileWatcher> = {};
var updatedFiles: Map<boolean> = {};
// Compile the program the first time and watch all given/referenced files.
var program = compile(commandLine, compilerHost).program;
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes));
addWatchers(program);
return;
function addWatchers(program: Program) {
forEach(program.getSourceFiles(), f => {
var filename = getCanonicalName(f.filename);
watchers[filename] = sys.watchFile(filename, fileUpdated);
});
}
function removeWatchers(program: Program) {
forEach(program.getSourceFiles(), f => {
var filename = getCanonicalName(f.filename);
if (hasProperty(watchers, filename)) {
watchers[filename].close();
}
});
watchers = {};
}
// Fired off whenever a file is changed.
function fileUpdated(filename: string) {
var firstNotification = isEmpty(updatedFiles);
updatedFiles[getCanonicalName(filename)] = true;
// Only start this off when the first file change comes in,
// so that we can batch up all further changes.
if (firstNotification) {
setTimeout(() => {
var changedFiles = updatedFiles;
updatedFiles = {};
recompile(changedFiles);
}, 250);
if (configFilename) {
configFileWatcher = sys.watchFile(configFilename, configFileChanged);
}
}
function recompile(changedFiles: Map<boolean>) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Compiling));
// Remove all the watchers, as we may not be watching every file
// specified since the last compilation cycle.
removeWatchers(program);
performCompilation();
// Reuse source files from the last compilation so long as they weren't changed.
var oldSourceFiles = arrayToMap(
filter(program.getSourceFiles(), file => !hasProperty(changedFiles, getCanonicalName(file.filename))),
file => getCanonicalName(file.filename));
// Invoked to perform initial compilation or re-compilation in watch mode
function performCompilation() {
// We create a new compiler host for this compilation cycle.
// This new host is effectively the same except that 'getSourceFile'
// will try to reuse the SourceFiles from the last compilation cycle
// so long as they were not modified.
var newCompilerHost = clone(compilerHost);
newCompilerHost.getSourceFile = (fileName, languageVersion, onError) => {
fileName = getCanonicalName(fileName);
var sourceFile = lookUp(oldSourceFiles, fileName);
if (sourceFile) {
return sourceFile;
if (!cachedProgram) {
if (configFilename) {
var configObject = readConfigFile(configFilename);
if (!configObject) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFilename));
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
}
var configParseResult = parseConfigFile(configObject, getDirectoryPath(configFilename));
if (configParseResult.errors.length > 0) {
reportDiagnostics(configParseResult.errors);
return sys.exit(EmitReturnStatus.CompilerOptionsErrors);
}
rootFilenames = configParseResult.filenames;
compilerOptions = extend(commandLine.options, configParseResult.options);
}
else {
rootFilenames = commandLine.filenames;
compilerOptions = commandLine.options;
}
compilerHost = createCompilerHost(compilerOptions);
hostGetSourceFile = compilerHost.getSourceFile;
compilerHost.getSourceFile = getSourceFile;
}
return compilerHost.getSourceFile(fileName, languageVersion, onError);
};
var compileResult = compile(rootFilenames, compilerOptions, compilerHost);
program = compile(commandLine, newCompilerHost).program;
if (!commandLine.options.watch) {
return sys.exit(compileResult.exitStatus);
}
setCachedProgram(compileResult.program);
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes));
addWatchers(program);
}
function getCanonicalName(fileName: string) {
return compilerHost.getCanonicalFileName(fileName);
function getSourceFile(filename: string, languageVersion: ScriptTarget, onError ?: (message: string) => void) {
// Return existing SourceFile object if one is available
if (cachedProgram) {
var sourceFile = cachedProgram.getSourceFile(filename);
// A modified source file has no watcher and should not be reused
if (sourceFile && sourceFile.fileWatcher) {
return sourceFile;
}
}
// Use default host function
var sourceFile = hostGetSourceFile(filename, languageVersion, onError);
if (sourceFile && commandLine.options.watch) {
// Attach a file watcher
sourceFile.fileWatcher = sys.watchFile(sourceFile.filename, () => sourceFileChanged(sourceFile));
}
return sourceFile;
}
// Change cached program to the given program
function setCachedProgram(program: Program) {
if (cachedProgram) {
var newSourceFiles = program ? program.getSourceFiles() : undefined;
forEach(cachedProgram.getSourceFiles(), sourceFile => {
if (!(newSourceFiles && contains(newSourceFiles, sourceFile))) {
if (sourceFile.fileWatcher) {
sourceFile.fileWatcher.close();
sourceFile.fileWatcher = undefined;
}
}
});
}
cachedProgram = program;
}
// If a source file changes, mark it as unwatched and start the recompilation timer
function sourceFileChanged(sourceFile: SourceFile) {
sourceFile.fileWatcher = undefined;
startTimer();
}
// If the configuration file changes, forget cached program and start the recompilation timer
function configFileChanged() {
setCachedProgram(undefined);
startTimer();
}
// Upon detecting a file change, wait for 250ms and then perform a recompilation. This gives batch
// operations (such as saving all modified files in an editor) a chance to complete before we kick
// off a new compilation.
function startTimer() {
if (timerHandle) {
clearTimeout(timerHandle);
}
timerHandle = setTimeout(recompile, 250);
}
function recompile() {
timerHandle = undefined;
reportDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation));
performCompilation();
}
}
function compile(commandLine: ParsedCommandLine, compilerHost: CompilerHost) {
function compile(filenames: string[], compilerOptions: CompilerOptions, compilerHost: CompilerHost) {
var parseStart = new Date().getTime();
var compilerOptions = commandLine.options;
var program = createProgram(commandLine.filenames, compilerOptions, compilerHost);
var program = createProgram(filenames, compilerOptions, compilerHost);
var bindStart = new Date().getTime();
var errors: Diagnostic[] = program.getDiagnostics();
@@ -303,7 +356,14 @@ module ts {
}
reportDiagnostics(errors);
if (commandLine.options.diagnostics) {
if (compilerOptions.listFiles) {
forEach(program.getSourceFiles(), file => {
sys.write(file.filename + sys.newLine);
});
}
if (compilerOptions.diagnostics) {
var memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1;
reportCountStatistic("Files", program.getSourceFiles().length);
reportCountStatistic("Lines", countLines(program));
+25
View File
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"out": "../../built/local/tsc.js",
"sourceMap": true
},
"files": [
"core.ts",
"sys.ts",
"types.ts",
"scanner.ts",
"parser.ts",
"utilities.ts",
"binder.ts",
"checker.ts",
"emitter.ts",
"program.ts",
"commandLineParser.ts",
"tsc.ts",
"diagnosticInformationMap.generated.ts"
]
}
+6 -3
View File
@@ -1448,6 +1448,7 @@ module ts {
diagnostics?: boolean;
emitBOM?: boolean;
help?: boolean;
listFiles?: boolean;
locale?: string;
mapRoot?: string;
module?: ModuleKind;
@@ -1461,6 +1462,7 @@ module ts {
out?: string;
outDir?: string;
preserveConstEnums?: boolean;
project?: string;
removeComments?: boolean;
sourceMap?: boolean;
sourceRoot?: string;
@@ -1501,10 +1503,11 @@ module ts {
export interface CommandLineOption {
name: string;
type: string | Map<number>; // "string", "number", "boolean", or an object literal mapping named values to actual values
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'.
isFilePath?: boolean; // True if option value is a path or filename
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'
description?: DiagnosticMessage; // The message describing what the command line switch does
paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter.
error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'.
paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter
error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'
}
export const enum CharacterCodes {
+9 -3
View File
@@ -22,6 +22,7 @@
declare var require: any;
declare var process: any;
var Buffer = require('buffer').Buffer;
// this will work in the browser via browserify
var _chai: typeof chai = require('chai');
@@ -1207,7 +1208,6 @@ module Harness {
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: HarnessDiagnostic[]) {
diagnostics.sort(compareDiagnostics);
var outputLines: string[] = [];
// Count up all the errors we find so we don't miss any
var totalErrorsReported = 0;
@@ -1298,8 +1298,13 @@ module Harness {
return diagnostic.filename && isLibraryFile(diagnostic.filename);
});
var numTest262HarnessDiagnostics = ts.countWhere(diagnostics, diagnostic => {
// Count an error generated from tests262-harness folder.This should only apply for test262
return diagnostic.filename && diagnostic.filename.indexOf("test262-harness") >= 0;
});
// Verify we didn't miss any errors in total
assert.equal(totalErrorsReported + numLibraryDiagnostics, diagnostics.length, 'total number of errors');
assert.equal(totalErrorsReported + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length, 'total number of errors');
return minimalDiagnosticsToString(diagnostics) +
ts.sys.newLine + ts.sys.newLine + outputLines.join('\r\n');
@@ -1642,7 +1647,8 @@ module Harness {
}
function writeComparison(expected: string, actual: string, relativeFilename: string, actualFilename: string, descriptionForDescribe: string) {
if (expected != actual) {
var encoded_actual = (new Buffer(actual)).toString('utf8')
if (expected != encoded_actual) {
// Overwrite & issue error
var errMsg = 'The baseline file ' + relativeFilename + ' has changed';
throw new Error(errMsg);
+12 -2
View File
@@ -243,8 +243,18 @@ module ts.formatting {
}
var precedingToken = findPrecedingToken(originalRange.pos, sourceFile);
// no preceding token found - start from the beginning of enclosing node
return precedingToken ? precedingToken.end : enclosingNode.pos;
if (!precedingToken) {
// no preceding token found - start from the beginning of enclosing node
return enclosingNode.pos;
}
// preceding token ends after the start of original range (i.e when originaRange.pos falls in the middle of literal)
// start from the beginning of enclosingNode to handle the entire 'originalRange'
if (precedingToken.end >= originalRange.pos) {
return enclosingNode.pos;
}
return precedingToken.end;
}
/*
@@ -187,6 +187,9 @@ module ts.formatting {
}
// consume trailing trivia
if (trailingTrivia) {
trailingTrivia = undefined;
}
while(scanner.getStartPos() < endPos) {
currentToken = scanner.scan();
if (!isTrivia(currentToken)) {
+9 -4
View File
@@ -12,10 +12,15 @@ module ts.formatting {
return 0;
}
// no indentation in string \regex literals
if ((precedingToken.kind === SyntaxKind.StringLiteral || precedingToken.kind === SyntaxKind.RegularExpressionLiteral) &&
precedingToken.getStart(sourceFile) <= position &&
precedingToken.end > position) {
// no indentation in string \regex\template literals
var precedingTokenIsLiteral =
precedingToken.kind === SyntaxKind.StringLiteral ||
precedingToken.kind === SyntaxKind.RegularExpressionLiteral ||
precedingToken.kind === SyntaxKind.NoSubstitutionTemplateLiteral ||
precedingToken.kind === SyntaxKind.TemplateHead ||
precedingToken.kind === SyntaxKind.TemplateMiddle ||
precedingToken.kind === SyntaxKind.TemplateTail;
if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) {
return 0;
}
+47
View File
@@ -0,0 +1,47 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"out": "../../built/local/typescriptServices.js",
"sourceMap": true
},
"files": [
"../compiler/core.ts",
"../compiler/sys.ts",
"../compiler/types.ts",
"../compiler/scanner.ts",
"../compiler/parser.ts",
"../compiler/utilities.ts",
"../compiler/binder.ts",
"../compiler/checker.ts",
"../compiler/emitter.ts",
"../compiler/program.ts",
"../compiler/commandLineParser.ts",
"../compiler/diagnosticInformationMap.generated.ts",
"breakpoints.ts",
"navigationBar.ts",
"outliningElementsCollector.ts",
"services.ts",
"shims.ts",
"signatureHelp.ts",
"utilities.ts",
"formatting/formatting.ts",
"formatting/formattingContext.ts",
"formatting/formattingRequestKind.ts",
"formatting/formattingScanner.ts",
"formatting/references.ts",
"formatting/rule.ts",
"formatting/ruleAction.ts",
"formatting/ruleDescriptor.ts",
"formatting/ruleFlag.ts",
"formatting/ruleOperation.ts",
"formatting/ruleOperationContext.ts",
"formatting/rules.ts",
"formatting/rulesMap.ts",
"formatting/rulesProvider.ts",
"formatting/smartIndenter.ts",
"formatting/tokenRange.ts"
]
}
@@ -1,8 +1,10 @@
//// [additionOperatorWithNumberAndEnum.ts]
enum E { a, b }
enum F { c, d }
var a: number;
var b: E;
var c: E | F;
var r1 = a + a;
var r2 = a + b;
@@ -12,7 +14,15 @@ var r4 = b + b;
var r5 = 0 + a;
var r6 = E.a + 0;
var r7 = E.a + E.b;
var r8 = E['a'] + E['b'];
var r8 = E['a'] + E['b'];
var r9 = E['a'] + F['c'];
var r10 = a + c;
var r11 = c + a;
var r12 = b + c;
var r13 = c + b;
var r14 = c + c;
//// [additionOperatorWithNumberAndEnum.js]
var E;
@@ -20,8 +30,14 @@ var E;
E[E["a"] = 0] = "a";
E[E["b"] = 1] = "b";
})(E || (E = {}));
var F;
(function (F) {
F[F["c"] = 0] = "c";
F[F["d"] = 1] = "d";
})(F || (F = {}));
var a;
var b;
var c;
var r1 = a + a;
var r2 = a + b;
var r3 = b + a;
@@ -30,3 +46,9 @@ var r5 = 0 + a;
var r6 = 0 /* a */ + 0;
var r7 = 0 /* a */ + 1 /* b */;
var r8 = 0 /* 'a' */ + 1 /* 'b' */;
var r9 = 0 /* 'a' */ + 0 /* 'c' */;
var r10 = a + c;
var r11 = c + a;
var r12 = b + c;
var r13 = c + b;
var r14 = c + c;
@@ -4,6 +4,11 @@ enum E { a, b }
>a : E
>b : E
enum F { c, d }
>F : F
>c : F
>d : F
var a: number;
>a : number
@@ -11,6 +16,11 @@ var b: E;
>b : E
>E : E
var c: E | F;
>c : E | F
>E : E
>F : F
var r1 = a + a;
>r1 : number
>a + a : number
@@ -65,3 +75,41 @@ var r8 = E['a'] + E['b'];
>E['b'] : E
>E : typeof E
var r9 = E['a'] + F['c'];
>r9 : number
>E['a'] + F['c'] : number
>E['a'] : E
>E : typeof E
>F['c'] : F
>F : typeof F
var r10 = a + c;
>r10 : number
>a + c : number
>a : number
>c : E | F
var r11 = c + a;
>r11 : number
>c + a : number
>c : E | F
>a : number
var r12 = b + c;
>r12 : number
>b + c : number
>b : E
>c : E | F
var r13 = c + b;
>r13 : number
>c + b : number
>c : E | F
>b : E
var r14 = c + c;
>r14 : number
>c + c : number
>c : E | F
>c : E | F
@@ -0,0 +1,301 @@
//// [arithmeticOperatorWithEnumUnion.ts]
// operands of an enum type are treated as having the primitive type Number.
enum E {
a,
b
}
enum F {
c,
d
}
var a: any;
var b: number;
var c: E | F;
// operator *
var ra1 = c * a;
var ra2 = c * b;
var ra3 = c * c;
var ra4 = a * c;
var ra5 = b * c;
var ra6 = E.a * a;
var ra7 = E.a * b;
var ra8 = E.a * E.b;
var ra9 = E.a * 1;
var ra10 = a * E.b;
var ra11 = b * E.b;
var ra12 = 1 * E.b;
// operator /
var rb1 = c / a;
var rb2 = c / b;
var rb3 = c / c;
var rb4 = a / c;
var rb5 = b / c;
var rb6 = E.a / a;
var rb7 = E.a / b;
var rb8 = E.a / E.b;
var rb9 = E.a / 1;
var rb10 = a / E.b;
var rb11 = b / E.b;
var rb12 = 1 / E.b;
// operator %
var rc1 = c % a;
var rc2 = c % b;
var rc3 = c % c;
var rc4 = a % c;
var rc5 = b % c;
var rc6 = E.a % a;
var rc7 = E.a % b;
var rc8 = E.a % E.b;
var rc9 = E.a % 1;
var rc10 = a % E.b;
var rc11 = b % E.b;
var rc12 = 1 % E.b;
// operator -
var rd1 = c - a;
var rd2 = c - b;
var rd3 = c - c;
var rd4 = a - c;
var rd5 = b - c;
var rd6 = E.a - a;
var rd7 = E.a - b;
var rd8 = E.a - E.b;
var rd9 = E.a - 1;
var rd10 = a - E.b;
var rd11 = b - E.b;
var rd12 = 1 - E.b;
// operator <<
var re1 = c << a;
var re2 = c << b;
var re3 = c << c;
var re4 = a << c;
var re5 = b << c;
var re6 = E.a << a;
var re7 = E.a << b;
var re8 = E.a << E.b;
var re9 = E.a << 1;
var re10 = a << E.b;
var re11 = b << E.b;
var re12 = 1 << E.b;
// operator >>
var rf1 = c >> a;
var rf2 = c >> b;
var rf3 = c >> c;
var rf4 = a >> c;
var rf5 = b >> c;
var rf6 = E.a >> a;
var rf7 = E.a >> b;
var rf8 = E.a >> E.b;
var rf9 = E.a >> 1;
var rf10 = a >> E.b;
var rf11 = b >> E.b;
var rf12 = 1 >> E.b;
// operator >>>
var rg1 = c >>> a;
var rg2 = c >>> b;
var rg3 = c >>> c;
var rg4 = a >>> c;
var rg5 = b >>> c;
var rg6 = E.a >>> a;
var rg7 = E.a >>> b;
var rg8 = E.a >>> E.b;
var rg9 = E.a >>> 1;
var rg10 = a >>> E.b;
var rg11 = b >>> E.b;
var rg12 = 1 >>> E.b;
// operator &
var rh1 = c & a;
var rh2 = c & b;
var rh3 = c & c;
var rh4 = a & c;
var rh5 = b & c;
var rh6 = E.a & a;
var rh7 = E.a & b;
var rh8 = E.a & E.b;
var rh9 = E.a & 1;
var rh10 = a & E.b;
var rh11 = b & E.b;
var rh12 = 1 & E.b;
// operator ^
var ri1 = c ^ a;
var ri2 = c ^ b;
var ri3 = c ^ c;
var ri4 = a ^ c;
var ri5 = b ^ c;
var ri6 = E.a ^ a;
var ri7 = E.a ^ b;
var ri8 = E.a ^ E.b;
var ri9 = E.a ^ 1;
var ri10 = a ^ E.b;
var ri11 = b ^ E.b;
var ri12 = 1 ^ E.b;
// operator |
var rj1 = c | a;
var rj2 = c | b;
var rj3 = c | c;
var rj4 = a | c;
var rj5 = b | c;
var rj6 = E.a | a;
var rj7 = E.a | b;
var rj8 = E.a | E.b;
var rj9 = E.a | 1;
var rj10 = a | E.b;
var rj11 = b | E.b;
var rj12 = 1 | E.b;
//// [arithmeticOperatorWithEnumUnion.js]
// operands of an enum type are treated as having the primitive type Number.
var E;
(function (E) {
E[E["a"] = 0] = "a";
E[E["b"] = 1] = "b";
})(E || (E = {}));
var F;
(function (F) {
F[F["c"] = 0] = "c";
F[F["d"] = 1] = "d";
})(F || (F = {}));
var a;
var b;
var c;
// operator *
var ra1 = c * a;
var ra2 = c * b;
var ra3 = c * c;
var ra4 = a * c;
var ra5 = b * c;
var ra6 = 0 /* a */ * a;
var ra7 = 0 /* a */ * b;
var ra8 = 0 /* a */ * 1 /* b */;
var ra9 = 0 /* a */ * 1;
var ra10 = a * 1 /* b */;
var ra11 = b * 1 /* b */;
var ra12 = 1 * 1 /* b */;
// operator /
var rb1 = c / a;
var rb2 = c / b;
var rb3 = c / c;
var rb4 = a / c;
var rb5 = b / c;
var rb6 = 0 /* a */ / a;
var rb7 = 0 /* a */ / b;
var rb8 = 0 /* a */ / 1 /* b */;
var rb9 = 0 /* a */ / 1;
var rb10 = a / 1 /* b */;
var rb11 = b / 1 /* b */;
var rb12 = 1 / 1 /* b */;
// operator %
var rc1 = c % a;
var rc2 = c % b;
var rc3 = c % c;
var rc4 = a % c;
var rc5 = b % c;
var rc6 = 0 /* a */ % a;
var rc7 = 0 /* a */ % b;
var rc8 = 0 /* a */ % 1 /* b */;
var rc9 = 0 /* a */ % 1;
var rc10 = a % 1 /* b */;
var rc11 = b % 1 /* b */;
var rc12 = 1 % 1 /* b */;
// operator -
var rd1 = c - a;
var rd2 = c - b;
var rd3 = c - c;
var rd4 = a - c;
var rd5 = b - c;
var rd6 = 0 /* a */ - a;
var rd7 = 0 /* a */ - b;
var rd8 = 0 /* a */ - 1 /* b */;
var rd9 = 0 /* a */ - 1;
var rd10 = a - 1 /* b */;
var rd11 = b - 1 /* b */;
var rd12 = 1 - 1 /* b */;
// operator <<
var re1 = c << a;
var re2 = c << b;
var re3 = c << c;
var re4 = a << c;
var re5 = b << c;
var re6 = 0 /* a */ << a;
var re7 = 0 /* a */ << b;
var re8 = 0 /* a */ << 1 /* b */;
var re9 = 0 /* a */ << 1;
var re10 = a << 1 /* b */;
var re11 = b << 1 /* b */;
var re12 = 1 << 1 /* b */;
// operator >>
var rf1 = c >> a;
var rf2 = c >> b;
var rf3 = c >> c;
var rf4 = a >> c;
var rf5 = b >> c;
var rf6 = 0 /* a */ >> a;
var rf7 = 0 /* a */ >> b;
var rf8 = 0 /* a */ >> 1 /* b */;
var rf9 = 0 /* a */ >> 1;
var rf10 = a >> 1 /* b */;
var rf11 = b >> 1 /* b */;
var rf12 = 1 >> 1 /* b */;
// operator >>>
var rg1 = c >>> a;
var rg2 = c >>> b;
var rg3 = c >>> c;
var rg4 = a >>> c;
var rg5 = b >>> c;
var rg6 = 0 /* a */ >>> a;
var rg7 = 0 /* a */ >>> b;
var rg8 = 0 /* a */ >>> 1 /* b */;
var rg9 = 0 /* a */ >>> 1;
var rg10 = a >>> 1 /* b */;
var rg11 = b >>> 1 /* b */;
var rg12 = 1 >>> 1 /* b */;
// operator &
var rh1 = c & a;
var rh2 = c & b;
var rh3 = c & c;
var rh4 = a & c;
var rh5 = b & c;
var rh6 = 0 /* a */ & a;
var rh7 = 0 /* a */ & b;
var rh8 = 0 /* a */ & 1 /* b */;
var rh9 = 0 /* a */ & 1;
var rh10 = a & 1 /* b */;
var rh11 = b & 1 /* b */;
var rh12 = 1 & 1 /* b */;
// operator ^
var ri1 = c ^ a;
var ri2 = c ^ b;
var ri3 = c ^ c;
var ri4 = a ^ c;
var ri5 = b ^ c;
var ri6 = 0 /* a */ ^ a;
var ri7 = 0 /* a */ ^ b;
var ri8 = 0 /* a */ ^ 1 /* b */;
var ri9 = 0 /* a */ ^ 1;
var ri10 = a ^ 1 /* b */;
var ri11 = b ^ 1 /* b */;
var ri12 = 1 ^ 1 /* b */;
// operator |
var rj1 = c | a;
var rj2 = c | b;
var rj3 = c | c;
var rj4 = a | c;
var rj5 = b | c;
var rj6 = 0 /* a */ | a;
var rj7 = 0 /* a */ | b;
var rj8 = 0 /* a */ | 1 /* b */;
var rj9 = 0 /* a */ | 1;
var rj10 = a | 1 /* b */;
var rj11 = b | 1 /* b */;
var rj12 = 1 | 1 /* b */;
@@ -0,0 +1,903 @@
=== tests/cases/conformance/expressions/binaryOperators/arithmeticOperator/arithmeticOperatorWithEnumUnion.ts ===
// operands of an enum type are treated as having the primitive type Number.
enum E {
>E : E
a,
>a : E
b
>b : E
}
enum F {
>F : F
c,
>c : F
d
>d : F
}
var a: any;
>a : any
var b: number;
>b : number
var c: E | F;
>c : E | F
>E : E
>F : F
// operator *
var ra1 = c * a;
>ra1 : number
>c * a : number
>c : E | F
>a : any
var ra2 = c * b;
>ra2 : number
>c * b : number
>c : E | F
>b : number
var ra3 = c * c;
>ra3 : number
>c * c : number
>c : E | F
>c : E | F
var ra4 = a * c;
>ra4 : number
>a * c : number
>a : any
>c : E | F
var ra5 = b * c;
>ra5 : number
>b * c : number
>b : number
>c : E | F
var ra6 = E.a * a;
>ra6 : number
>E.a * a : number
>E.a : E
>E : typeof E
>a : E
>a : any
var ra7 = E.a * b;
>ra7 : number
>E.a * b : number
>E.a : E
>E : typeof E
>a : E
>b : number
var ra8 = E.a * E.b;
>ra8 : number
>E.a * E.b : number
>E.a : E
>E : typeof E
>a : E
>E.b : E
>E : typeof E
>b : E
var ra9 = E.a * 1;
>ra9 : number
>E.a * 1 : number
>E.a : E
>E : typeof E
>a : E
var ra10 = a * E.b;
>ra10 : number
>a * E.b : number
>a : any
>E.b : E
>E : typeof E
>b : E
var ra11 = b * E.b;
>ra11 : number
>b * E.b : number
>b : number
>E.b : E
>E : typeof E
>b : E
var ra12 = 1 * E.b;
>ra12 : number
>1 * E.b : number
>E.b : E
>E : typeof E
>b : E
// operator /
var rb1 = c / a;
>rb1 : number
>c / a : number
>c : E | F
>a : any
var rb2 = c / b;
>rb2 : number
>c / b : number
>c : E | F
>b : number
var rb3 = c / c;
>rb3 : number
>c / c : number
>c : E | F
>c : E | F
var rb4 = a / c;
>rb4 : number
>a / c : number
>a : any
>c : E | F
var rb5 = b / c;
>rb5 : number
>b / c : number
>b : number
>c : E | F
var rb6 = E.a / a;
>rb6 : number
>E.a / a : number
>E.a : E
>E : typeof E
>a : E
>a : any
var rb7 = E.a / b;
>rb7 : number
>E.a / b : number
>E.a : E
>E : typeof E
>a : E
>b : number
var rb8 = E.a / E.b;
>rb8 : number
>E.a / E.b : number
>E.a : E
>E : typeof E
>a : E
>E.b : E
>E : typeof E
>b : E
var rb9 = E.a / 1;
>rb9 : number
>E.a / 1 : number
>E.a : E
>E : typeof E
>a : E
var rb10 = a / E.b;
>rb10 : number
>a / E.b : number
>a : any
>E.b : E
>E : typeof E
>b : E
var rb11 = b / E.b;
>rb11 : number
>b / E.b : number
>b : number
>E.b : E
>E : typeof E
>b : E
var rb12 = 1 / E.b;
>rb12 : number
>1 / E.b : number
>E.b : E
>E : typeof E
>b : E
// operator %
var rc1 = c % a;
>rc1 : number
>c % a : number
>c : E | F
>a : any
var rc2 = c % b;
>rc2 : number
>c % b : number
>c : E | F
>b : number
var rc3 = c % c;
>rc3 : number
>c % c : number
>c : E | F
>c : E | F
var rc4 = a % c;
>rc4 : number
>a % c : number
>a : any
>c : E | F
var rc5 = b % c;
>rc5 : number
>b % c : number
>b : number
>c : E | F
var rc6 = E.a % a;
>rc6 : number
>E.a % a : number
>E.a : E
>E : typeof E
>a : E
>a : any
var rc7 = E.a % b;
>rc7 : number
>E.a % b : number
>E.a : E
>E : typeof E
>a : E
>b : number
var rc8 = E.a % E.b;
>rc8 : number
>E.a % E.b : number
>E.a : E
>E : typeof E
>a : E
>E.b : E
>E : typeof E
>b : E
var rc9 = E.a % 1;
>rc9 : number
>E.a % 1 : number
>E.a : E
>E : typeof E
>a : E
var rc10 = a % E.b;
>rc10 : number
>a % E.b : number
>a : any
>E.b : E
>E : typeof E
>b : E
var rc11 = b % E.b;
>rc11 : number
>b % E.b : number
>b : number
>E.b : E
>E : typeof E
>b : E
var rc12 = 1 % E.b;
>rc12 : number
>1 % E.b : number
>E.b : E
>E : typeof E
>b : E
// operator -
var rd1 = c - a;
>rd1 : number
>c - a : number
>c : E | F
>a : any
var rd2 = c - b;
>rd2 : number
>c - b : number
>c : E | F
>b : number
var rd3 = c - c;
>rd3 : number
>c - c : number
>c : E | F
>c : E | F
var rd4 = a - c;
>rd4 : number
>a - c : number
>a : any
>c : E | F
var rd5 = b - c;
>rd5 : number
>b - c : number
>b : number
>c : E | F
var rd6 = E.a - a;
>rd6 : number
>E.a - a : number
>E.a : E
>E : typeof E
>a : E
>a : any
var rd7 = E.a - b;
>rd7 : number
>E.a - b : number
>E.a : E
>E : typeof E
>a : E
>b : number
var rd8 = E.a - E.b;
>rd8 : number
>E.a - E.b : number
>E.a : E
>E : typeof E
>a : E
>E.b : E
>E : typeof E
>b : E
var rd9 = E.a - 1;
>rd9 : number
>E.a - 1 : number
>E.a : E
>E : typeof E
>a : E
var rd10 = a - E.b;
>rd10 : number
>a - E.b : number
>a : any
>E.b : E
>E : typeof E
>b : E
var rd11 = b - E.b;
>rd11 : number
>b - E.b : number
>b : number
>E.b : E
>E : typeof E
>b : E
var rd12 = 1 - E.b;
>rd12 : number
>1 - E.b : number
>E.b : E
>E : typeof E
>b : E
// operator <<
var re1 = c << a;
>re1 : number
>c << a : number
>c : E | F
>a : any
var re2 = c << b;
>re2 : number
>c << b : number
>c : E | F
>b : number
var re3 = c << c;
>re3 : number
>c << c : number
>c : E | F
>c : E | F
var re4 = a << c;
>re4 : number
>a << c : number
>a : any
>c : E | F
var re5 = b << c;
>re5 : number
>b << c : number
>b : number
>c : E | F
var re6 = E.a << a;
>re6 : number
>E.a << a : number
>E.a : E
>E : typeof E
>a : E
>a : any
var re7 = E.a << b;
>re7 : number
>E.a << b : number
>E.a : E
>E : typeof E
>a : E
>b : number
var re8 = E.a << E.b;
>re8 : number
>E.a << E.b : number
>E.a : E
>E : typeof E
>a : E
>E.b : E
>E : typeof E
>b : E
var re9 = E.a << 1;
>re9 : number
>E.a << 1 : number
>E.a : E
>E : typeof E
>a : E
var re10 = a << E.b;
>re10 : number
>a << E.b : number
>a : any
>E.b : E
>E : typeof E
>b : E
var re11 = b << E.b;
>re11 : number
>b << E.b : number
>b : number
>E.b : E
>E : typeof E
>b : E
var re12 = 1 << E.b;
>re12 : number
>1 << E.b : number
>E.b : E
>E : typeof E
>b : E
// operator >>
var rf1 = c >> a;
>rf1 : number
>c >> a : number
>c : E | F
>a : any
var rf2 = c >> b;
>rf2 : number
>c >> b : number
>c : E | F
>b : number
var rf3 = c >> c;
>rf3 : number
>c >> c : number
>c : E | F
>c : E | F
var rf4 = a >> c;
>rf4 : number
>a >> c : number
>a : any
>c : E | F
var rf5 = b >> c;
>rf5 : number
>b >> c : number
>b : number
>c : E | F
var rf6 = E.a >> a;
>rf6 : number
>E.a >> a : number
>E.a : E
>E : typeof E
>a : E
>a : any
var rf7 = E.a >> b;
>rf7 : number
>E.a >> b : number
>E.a : E
>E : typeof E
>a : E
>b : number
var rf8 = E.a >> E.b;
>rf8 : number
>E.a >> E.b : number
>E.a : E
>E : typeof E
>a : E
>E.b : E
>E : typeof E
>b : E
var rf9 = E.a >> 1;
>rf9 : number
>E.a >> 1 : number
>E.a : E
>E : typeof E
>a : E
var rf10 = a >> E.b;
>rf10 : number
>a >> E.b : number
>a : any
>E.b : E
>E : typeof E
>b : E
var rf11 = b >> E.b;
>rf11 : number
>b >> E.b : number
>b : number
>E.b : E
>E : typeof E
>b : E
var rf12 = 1 >> E.b;
>rf12 : number
>1 >> E.b : number
>E.b : E
>E : typeof E
>b : E
// operator >>>
var rg1 = c >>> a;
>rg1 : number
>c >>> a : number
>c : E | F
>a : any
var rg2 = c >>> b;
>rg2 : number
>c >>> b : number
>c : E | F
>b : number
var rg3 = c >>> c;
>rg3 : number
>c >>> c : number
>c : E | F
>c : E | F
var rg4 = a >>> c;
>rg4 : number
>a >>> c : number
>a : any
>c : E | F
var rg5 = b >>> c;
>rg5 : number
>b >>> c : number
>b : number
>c : E | F
var rg6 = E.a >>> a;
>rg6 : number
>E.a >>> a : number
>E.a : E
>E : typeof E
>a : E
>a : any
var rg7 = E.a >>> b;
>rg7 : number
>E.a >>> b : number
>E.a : E
>E : typeof E
>a : E
>b : number
var rg8 = E.a >>> E.b;
>rg8 : number
>E.a >>> E.b : number
>E.a : E
>E : typeof E
>a : E
>E.b : E
>E : typeof E
>b : E
var rg9 = E.a >>> 1;
>rg9 : number
>E.a >>> 1 : number
>E.a : E
>E : typeof E
>a : E
var rg10 = a >>> E.b;
>rg10 : number
>a >>> E.b : number
>a : any
>E.b : E
>E : typeof E
>b : E
var rg11 = b >>> E.b;
>rg11 : number
>b >>> E.b : number
>b : number
>E.b : E
>E : typeof E
>b : E
var rg12 = 1 >>> E.b;
>rg12 : number
>1 >>> E.b : number
>E.b : E
>E : typeof E
>b : E
// operator &
var rh1 = c & a;
>rh1 : number
>c & a : number
>c : E | F
>a : any
var rh2 = c & b;
>rh2 : number
>c & b : number
>c : E | F
>b : number
var rh3 = c & c;
>rh3 : number
>c & c : number
>c : E | F
>c : E | F
var rh4 = a & c;
>rh4 : number
>a & c : number
>a : any
>c : E | F
var rh5 = b & c;
>rh5 : number
>b & c : number
>b : number
>c : E | F
var rh6 = E.a & a;
>rh6 : number
>E.a & a : number
>E.a : E
>E : typeof E
>a : E
>a : any
var rh7 = E.a & b;
>rh7 : number
>E.a & b : number
>E.a : E
>E : typeof E
>a : E
>b : number
var rh8 = E.a & E.b;
>rh8 : number
>E.a & E.b : number
>E.a : E
>E : typeof E
>a : E
>E.b : E
>E : typeof E
>b : E
var rh9 = E.a & 1;
>rh9 : number
>E.a & 1 : number
>E.a : E
>E : typeof E
>a : E
var rh10 = a & E.b;
>rh10 : number
>a & E.b : number
>a : any
>E.b : E
>E : typeof E
>b : E
var rh11 = b & E.b;
>rh11 : number
>b & E.b : number
>b : number
>E.b : E
>E : typeof E
>b : E
var rh12 = 1 & E.b;
>rh12 : number
>1 & E.b : number
>E.b : E
>E : typeof E
>b : E
// operator ^
var ri1 = c ^ a;
>ri1 : number
>c ^ a : number
>c : E | F
>a : any
var ri2 = c ^ b;
>ri2 : number
>c ^ b : number
>c : E | F
>b : number
var ri3 = c ^ c;
>ri3 : number
>c ^ c : number
>c : E | F
>c : E | F
var ri4 = a ^ c;
>ri4 : number
>a ^ c : number
>a : any
>c : E | F
var ri5 = b ^ c;
>ri5 : number
>b ^ c : number
>b : number
>c : E | F
var ri6 = E.a ^ a;
>ri6 : number
>E.a ^ a : number
>E.a : E
>E : typeof E
>a : E
>a : any
var ri7 = E.a ^ b;
>ri7 : number
>E.a ^ b : number
>E.a : E
>E : typeof E
>a : E
>b : number
var ri8 = E.a ^ E.b;
>ri8 : number
>E.a ^ E.b : number
>E.a : E
>E : typeof E
>a : E
>E.b : E
>E : typeof E
>b : E
var ri9 = E.a ^ 1;
>ri9 : number
>E.a ^ 1 : number
>E.a : E
>E : typeof E
>a : E
var ri10 = a ^ E.b;
>ri10 : number
>a ^ E.b : number
>a : any
>E.b : E
>E : typeof E
>b : E
var ri11 = b ^ E.b;
>ri11 : number
>b ^ E.b : number
>b : number
>E.b : E
>E : typeof E
>b : E
var ri12 = 1 ^ E.b;
>ri12 : number
>1 ^ E.b : number
>E.b : E
>E : typeof E
>b : E
// operator |
var rj1 = c | a;
>rj1 : number
>c | a : number
>c : E | F
>a : any
var rj2 = c | b;
>rj2 : number
>c | b : number
>c : E | F
>b : number
var rj3 = c | c;
>rj3 : number
>c | c : number
>c : E | F
>c : E | F
var rj4 = a | c;
>rj4 : number
>a | c : number
>a : any
>c : E | F
var rj5 = b | c;
>rj5 : number
>b | c : number
>b : number
>c : E | F
var rj6 = E.a | a;
>rj6 : number
>E.a | a : number
>E.a : E
>E : typeof E
>a : E
>a : any
var rj7 = E.a | b;
>rj7 : number
>E.a | b : number
>E.a : E
>E : typeof E
>a : E
>b : number
var rj8 = E.a | E.b;
>rj8 : number
>E.a | E.b : number
>E.a : E
>E : typeof E
>a : E
>E.b : E
>E : typeof E
>b : E
var rj9 = E.a | 1;
>rj9 : number
>E.a | 1 : number
>E.a : E
>E : typeof E
>a : E
var rj10 = a | E.b;
>rj10 : number
>a | E.b : number
>a : any
>E.b : E
>E : typeof E
>b : E
var rj11 = b | E.b;
>rj11 : number
>b | E.b : number
>b : number
>E.b : E
>E : typeof E
>b : E
var rj12 = 1 | E.b;
>rj12 : number
>1 | E.b : number
>E.b : E
>E : typeof E
>b : E
@@ -55,27 +55,4 @@ interface B<TBase extends Base> extends A {
}
var b: B<Derived> = null;
var z: Derived = b.foo();
class Base { private a: string; }
class Derived extends Base { private b: string; }
// Note - commmenting "extends Foo" prevents the error
interface Foo {
[i: number]: Base;
}
interface FooOf<TBase extends Base> extends Foo {
[i: number]: TBase;
}
var x: FooOf<Derived> = null;
var y: Derived = x[0];
/*
// Note - the equivalent for normal interface methods works fine:
interface A {
foo(): Base;
}
interface B<TBase extends Base> extends A {
foo(): TBase;
}
var b: B<Derived> = null;
var z: Derived = b.foo();
*/
@@ -0,0 +1,11 @@
//// [commentEmitWithCommentOnLastLine.ts]
var x: any;
/*
var bar;
*/
//// [commentEmitWithCommentOnLastLine.js]
var x;
/*
var bar;
*/
@@ -0,0 +1,7 @@
=== tests/cases/compiler/commentEmitWithCommentOnLastLine.ts ===
var x: any;
>x : any
/*
var bar;
*/
+1 -31
View File
@@ -57,34 +57,4 @@ var c: C<number>;
var cc: C<C<number>>;
c = c.m(cc);
var n1: number[];
/*
interface Array<T> {
concat(...items: T[][]): T[]; // Note: This overload needs to be picked for arrays of arrays, even though both are applicable
concat(...items: T[]): T[];
}
*/
var fa: number[];
fa = fa.concat([0]);
fa = fa.concat(0);
/*
declare class C<T> {
public m(p1: C<C<T>>): C<T>;
//public p: T;
}
var c: C<number>;
var cc: C<C<number>>;
c = c.m(cc);
*/
@@ -1,10 +1,8 @@
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(12,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(13,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(14,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(15,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(16,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(17,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(18,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(19,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(20,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(30,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter
@@ -21,7 +19,7 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(43,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter
==== tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts (21 errors) ====
==== tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts (19 errors) ====
enum E { a }
var x: any;
@@ -43,8 +41,6 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv
~~
!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
var ra4 = a4 in x;
~~
!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
var ra5 = null in x;
~~~~
!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
@@ -52,8 +48,6 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv
~~~~~~~~~
!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
var ra7 = E.a in x;
~~~
!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
var ra8 = false in x;
~~~~~
!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.
@@ -1,9 +1,9 @@
error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.
error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.
!!! error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
!!! error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.
!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.
==== m1.ts (0 errors) ====
var m1_a1 = 10;
class m1_c1 {
@@ -1,9 +1,9 @@
error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.
error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.
!!! error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
!!! error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.
!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.
==== m1.ts (0 errors) ====
var m1_a1 = 10;
class m1_c1 {
@@ -1,7 +1,7 @@
error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.
!!! error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.
==== m1.ts (0 errors) ====
var m1_a1 = 10;
class m1_c1 {
@@ -1,7 +1,7 @@
error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.
!!! error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.
==== m1.ts (0 errors) ====
var m1_a1 = 10;
class m1_c1 {
@@ -1,7 +1,7 @@
error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.
!!! error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.
==== m1.ts (0 errors) ====
var m1_a1 = 10;
class m1_c1 {
@@ -1,7 +1,7 @@
error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.
!!! error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.
==== m1.ts (0 errors) ====
var m1_a1 = 10;
class m1_c1 {
@@ -1,16 +1,16 @@
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(9,22): error TS2304: Cannot find name 'HTMLElement'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(10,22): error TS2304: Cannot find name 'HTMLDivElement'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(37,14): error TS2339: Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(72,19): error TS2304: Cannot find name 'window'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(109,18): error TS2304: Cannot find name 'window'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(117,9): error TS2304: Cannot find name 'HTMLDivElement'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(121,9): error TS2304: Cannot find name 'HTMLDivElement'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(125,9): error TS2304: Cannot find name 'HTMLElement'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(129,9): error TS2304: Cannot find name 'HTMLElement'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(132,22): error TS2304: Cannot find name 'window'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(45,14): error TS2339: Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(80,10): error TS2342: An index expression argument must be of type 'string', 'number', or 'any'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(117,10): error TS2342: An index expression argument must be of type 'string', 'number', or 'any'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): error TS2342: An index expression argument must be of type 'string', 'number', or 'any'.
==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (10 errors) ====
==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (4 errors) ====
class A {
a: number;
}
class B extends A {
b: number;
}
enum Compass {
North, South, East, West
}
@@ -19,12 +19,8 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(132,22): er
var strIndex: { [n: string]: Compass } = { 'N': Compass.North, 'E': Compass.East };
var bothIndex:
{
[n: string]: HTMLElement;
~~~~~~~~~~~
!!! error TS2304: Cannot find name 'HTMLElement'.
[m: number]: HTMLDivElement;
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'HTMLDivElement'.
[n: string]: A;
[m: number]: B;
};
function noIndex() { }
@@ -37,6 +33,8 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(132,22): er
'literal property': 100
};
var anyVar: any = {};
var stringOrNumber: string | number;
var someObject: { name: string };
// Assign to a property access
obj.y = 4;
@@ -88,9 +86,9 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(132,22): er
var kk: any;
// Bracket notation property access using value of other type on type with numeric index signature and no string index signature
var ll = numIndex[window]; // Error
~~~~~~
!!! error TS2304: Cannot find name 'window'.
var ll = numIndex[someObject]; // Error
~~~~~~~~~~~~~~~~~~~~
!!! error TS2342: An index expression argument must be of type 'string', 'number', or 'any'.
// Bracket notation property access using string value on type with string index signature and no numeric index signature
var mm = strIndex['N'];
@@ -127,9 +125,9 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(132,22): er
var tt: any;
// Bracket notation property access using values of other types on type with no index signatures
var uu = noIndex[window]; // Error
~~~~~~
!!! error TS2304: Cannot find name 'window'.
var uu = noIndex[someObject]; // Error
~~~~~~~~~~~~~~~~~~~
!!! error TS2342: An index expression argument must be of type 'string', 'number', or 'any'.
// Bracket notation property access using numeric value on type with numeric index signature and string index signature
var vv = noIndex[32];
@@ -137,29 +135,31 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(132,22): er
// Bracket notation property access using enum value on type with numeric index signature and string index signature
var ww = bothIndex[Compass.East];
var ww: HTMLDivElement;
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'HTMLDivElement'.
var ww: B;
// Bracket notation property access using value of type 'any' on type with numeric index signature and string index signature
var xx = bothIndex[<any>null];
var xx: HTMLDivElement;
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'HTMLDivElement'.
var xx: B;
// Bracket notation property access using string value on type with numeric index signature and string index signature
var yy = bothIndex['foo'];
var yy: HTMLElement;
~~~~~~~~~~~
!!! error TS2304: Cannot find name 'HTMLElement'.
var yy: A;
// Bracket notation property access using numeric string value on type with numeric index signature and string index signature
var zz = bothIndex['1.0'];
var zz: HTMLElement;
~~~~~~~~~~~
!!! error TS2304: Cannot find name 'HTMLElement'.
var zz: A;
// Bracket notation property access using value of other type on type with numeric index signature and no string index signature and string index signature
var zzzz = bothIndex[window]; // Error
~~~~~~
!!! error TS2304: Cannot find name 'window'.
var zzzz = bothIndex[someObject]; // Error
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2342: An index expression argument must be of type 'string', 'number', or 'any'.
var x1 = numIndex[stringOrNumber];
var x1: any;
var x2 = strIndex[stringOrNumber];
var x2: Compass;
var x3 = bothIndex[stringOrNumber];
var x3: A;
+56 -12
View File
@@ -1,4 +1,10 @@
//// [propertyAccess.ts]
class A {
a: number;
}
class B extends A {
b: number;
}
enum Compass {
North, South, East, West
}
@@ -7,8 +13,8 @@ var numIndex: { [n: number]: string } = { 3: 'three', 'three': 'three' };
var strIndex: { [n: string]: Compass } = { 'N': Compass.North, 'E': Compass.East };
var bothIndex:
{
[n: string]: HTMLElement;
[m: number]: HTMLDivElement;
[n: string]: A;
[m: number]: B;
};
function noIndex() { }
@@ -21,6 +27,8 @@ var obj = {
'literal property': 100
};
var anyVar: any = {};
var stringOrNumber: string | number;
var someObject: { name: string };
// Assign to a property access
obj.y = 4;
@@ -70,7 +78,7 @@ var kk = numIndex['what'];
var kk: any;
// Bracket notation property access using value of other type on type with numeric index signature and no string index signature
var ll = numIndex[window]; // Error
var ll = numIndex[someObject]; // Error
// Bracket notation property access using string value on type with string index signature and no numeric index signature
var mm = strIndex['N'];
@@ -107,7 +115,7 @@ var tt = noIndex[<any>null];
var tt: any;
// Bracket notation property access using values of other types on type with no index signatures
var uu = noIndex[window]; // Error
var uu = noIndex[someObject]; // Error
// Bracket notation property access using numeric value on type with numeric index signature and string index signature
var vv = noIndex[32];
@@ -115,24 +123,52 @@ var vv: any;
// Bracket notation property access using enum value on type with numeric index signature and string index signature
var ww = bothIndex[Compass.East];
var ww: HTMLDivElement;
var ww: B;
// Bracket notation property access using value of type 'any' on type with numeric index signature and string index signature
var xx = bothIndex[<any>null];
var xx: HTMLDivElement;
var xx: B;
// Bracket notation property access using string value on type with numeric index signature and string index signature
var yy = bothIndex['foo'];
var yy: HTMLElement;
var yy: A;
// Bracket notation property access using numeric string value on type with numeric index signature and string index signature
var zz = bothIndex['1.0'];
var zz: HTMLElement;
var zz: A;
// Bracket notation property access using value of other type on type with numeric index signature and no string index signature and string index signature
var zzzz = bothIndex[window]; // Error
var zzzz = bothIndex[someObject]; // Error
var x1 = numIndex[stringOrNumber];
var x1: any;
var x2 = strIndex[stringOrNumber];
var x2: Compass;
var x3 = bothIndex[stringOrNumber];
var x3: A;
//// [propertyAccess.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var A = (function () {
function A() {
}
return A;
})();
var B = (function (_super) {
__extends(B, _super);
function B() {
_super.apply(this, arguments);
}
return B;
})(A);
var Compass;
(function (Compass) {
Compass[Compass["North"] = 0] = "North";
@@ -153,6 +189,8 @@ var obj = {
'literal property': 100
};
var anyVar = {};
var stringOrNumber;
var someObject;
// Assign to a property access
obj.y = 4;
// Property access on value of type 'any'
@@ -188,7 +226,7 @@ var jj;
var kk = numIndex['what'];
var kk;
// Bracket notation property access using value of other type on type with numeric index signature and no string index signature
var ll = numIndex[window]; // Error
var ll = numIndex[someObject]; // Error
// Bracket notation property access using string value on type with string index signature and no numeric index signature
var mm = strIndex['N'];
var mm;
@@ -216,7 +254,7 @@ var ss;
var tt = noIndex[null];
var tt;
// Bracket notation property access using values of other types on type with no index signatures
var uu = noIndex[window]; // Error
var uu = noIndex[someObject]; // Error
// Bracket notation property access using numeric value on type with numeric index signature and string index signature
var vv = noIndex[32];
var vv;
@@ -233,4 +271,10 @@ var yy;
var zz = bothIndex['1.0'];
var zz;
// Bracket notation property access using value of other type on type with numeric index signature and no string index signature and string index signature
var zzzz = bothIndex[window]; // Error
var zzzz = bothIndex[someObject]; // Error
var x1 = numIndex[stringOrNumber];
var x1;
var x2 = strIndex[stringOrNumber];
var x2;
var x3 = bothIndex[stringOrNumber];
var x3;
@@ -74,32 +74,4 @@ declare module MsPortal.Controls.Base.ItemList {
class ViewModel<TValue> extends ItemValue<TValue> {
}
}
module MsPortal.Controls.Base.ItemList {
export interface Interface<TValue> {
// Removing this line fixes the constructor of ItemValue
options: ViewModel<TValue>;
}
export class ItemValue<T> {
constructor(value: T) {
}
}
export class ViewModel<TValue> extends ItemValue<TValue> {
}
}
// Generates:
/*
declare module MsPortal.Controls.Base.ItemList {
interface Interface<TValue> {
options: ViewModel<TValue>;
}
class ItemValue<T> {
constructor(value: T);
}
class ViewModel<TValue> extends ItemValue<TValue> {
}
}
*/
@@ -0,0 +1,13 @@
//// [typeAliasDoesntMakeModuleInstantiated.ts]
declare module m {
// type alias declaration here shouldnt make the module declaration instantiated
type Selector = string| string[] |Function;
export interface IStatic {
(selector: any /* Selector */): IInstance;
}
export interface IInstance { }
}
declare var m: m.IStatic; // Should be ok to have var 'm' as module is non instantiated
//// [typeAliasDoesntMakeModuleInstantiated.js]
@@ -0,0 +1,24 @@
=== tests/cases/compiler/typeAliasDoesntMakeModuleInstantiated.ts ===
declare module m {
>m : IStatic
// type alias declaration here shouldnt make the module declaration instantiated
type Selector = string| string[] |Function;
>Selector : string | Function | string[]
>Function : Function
export interface IStatic {
>IStatic : IStatic
(selector: any /* Selector */): IInstance;
>selector : any
>IInstance : IInstance
}
export interface IInstance { }
>IInstance : IInstance
}
declare var m: m.IStatic; // Should be ok to have var 'm' as module is non instantiated
>m : m.IStatic
>m : unknown
>IStatic : m.IStatic
@@ -0,0 +1,4 @@
var x: any;
/*
var bar;
*/
@@ -0,0 +1,10 @@
declare module m {
// type alias declaration here shouldnt make the module declaration instantiated
type Selector = string| string[] |Function;
export interface IStatic {
(selector: any /* Selector */): IInstance;
}
export interface IInstance { }
}
declare var m: m.IStatic; // Should be ok to have var 'm' as module is non instantiated
@@ -1,7 +1,9 @@
enum E { a, b }
enum F { c, d }
var a: number;
var b: E;
var c: E | F;
var r1 = a + a;
var r2 = a + b;
@@ -11,4 +13,11 @@ var r4 = b + b;
var r5 = 0 + a;
var r6 = E.a + 0;
var r7 = E.a + E.b;
var r8 = E['a'] + E['b'];
var r8 = E['a'] + E['b'];
var r9 = E['a'] + F['c'];
var r10 = a + c;
var r11 = c + a;
var r12 = b + c;
var r13 = c + b;
var r14 = c + c;
@@ -0,0 +1,154 @@
// operands of an enum type are treated as having the primitive type Number.
enum E {
a,
b
}
enum F {
c,
d
}
var a: any;
var b: number;
var c: E | F;
// operator *
var ra1 = c * a;
var ra2 = c * b;
var ra3 = c * c;
var ra4 = a * c;
var ra5 = b * c;
var ra6 = E.a * a;
var ra7 = E.a * b;
var ra8 = E.a * E.b;
var ra9 = E.a * 1;
var ra10 = a * E.b;
var ra11 = b * E.b;
var ra12 = 1 * E.b;
// operator /
var rb1 = c / a;
var rb2 = c / b;
var rb3 = c / c;
var rb4 = a / c;
var rb5 = b / c;
var rb6 = E.a / a;
var rb7 = E.a / b;
var rb8 = E.a / E.b;
var rb9 = E.a / 1;
var rb10 = a / E.b;
var rb11 = b / E.b;
var rb12 = 1 / E.b;
// operator %
var rc1 = c % a;
var rc2 = c % b;
var rc3 = c % c;
var rc4 = a % c;
var rc5 = b % c;
var rc6 = E.a % a;
var rc7 = E.a % b;
var rc8 = E.a % E.b;
var rc9 = E.a % 1;
var rc10 = a % E.b;
var rc11 = b % E.b;
var rc12 = 1 % E.b;
// operator -
var rd1 = c - a;
var rd2 = c - b;
var rd3 = c - c;
var rd4 = a - c;
var rd5 = b - c;
var rd6 = E.a - a;
var rd7 = E.a - b;
var rd8 = E.a - E.b;
var rd9 = E.a - 1;
var rd10 = a - E.b;
var rd11 = b - E.b;
var rd12 = 1 - E.b;
// operator <<
var re1 = c << a;
var re2 = c << b;
var re3 = c << c;
var re4 = a << c;
var re5 = b << c;
var re6 = E.a << a;
var re7 = E.a << b;
var re8 = E.a << E.b;
var re9 = E.a << 1;
var re10 = a << E.b;
var re11 = b << E.b;
var re12 = 1 << E.b;
// operator >>
var rf1 = c >> a;
var rf2 = c >> b;
var rf3 = c >> c;
var rf4 = a >> c;
var rf5 = b >> c;
var rf6 = E.a >> a;
var rf7 = E.a >> b;
var rf8 = E.a >> E.b;
var rf9 = E.a >> 1;
var rf10 = a >> E.b;
var rf11 = b >> E.b;
var rf12 = 1 >> E.b;
// operator >>>
var rg1 = c >>> a;
var rg2 = c >>> b;
var rg3 = c >>> c;
var rg4 = a >>> c;
var rg5 = b >>> c;
var rg6 = E.a >>> a;
var rg7 = E.a >>> b;
var rg8 = E.a >>> E.b;
var rg9 = E.a >>> 1;
var rg10 = a >>> E.b;
var rg11 = b >>> E.b;
var rg12 = 1 >>> E.b;
// operator &
var rh1 = c & a;
var rh2 = c & b;
var rh3 = c & c;
var rh4 = a & c;
var rh5 = b & c;
var rh6 = E.a & a;
var rh7 = E.a & b;
var rh8 = E.a & E.b;
var rh9 = E.a & 1;
var rh10 = a & E.b;
var rh11 = b & E.b;
var rh12 = 1 & E.b;
// operator ^
var ri1 = c ^ a;
var ri2 = c ^ b;
var ri3 = c ^ c;
var ri4 = a ^ c;
var ri5 = b ^ c;
var ri6 = E.a ^ a;
var ri7 = E.a ^ b;
var ri8 = E.a ^ E.b;
var ri9 = E.a ^ 1;
var ri10 = a ^ E.b;
var ri11 = b ^ E.b;
var ri12 = 1 ^ E.b;
// operator |
var rj1 = c | a;
var rj2 = c | b;
var rj3 = c | c;
var rj4 = a | c;
var rj5 = b | c;
var rj6 = E.a | a;
var rj7 = E.a | b;
var rj8 = E.a | E.b;
var rj9 = E.a | 1;
var rj10 = a | E.b;
var rj11 = b | E.b;
var rj12 = 1 | E.b;
@@ -1,3 +1,9 @@
class A {
a: number;
}
class B extends A {
b: number;
}
enum Compass {
North, South, East, West
}
@@ -6,8 +12,8 @@ var numIndex: { [n: number]: string } = { 3: 'three', 'three': 'three' };
var strIndex: { [n: string]: Compass } = { 'N': Compass.North, 'E': Compass.East };
var bothIndex:
{
[n: string]: HTMLElement;
[m: number]: HTMLDivElement;
[n: string]: A;
[m: number]: B;
};
function noIndex() { }
@@ -20,6 +26,8 @@ var obj = {
'literal property': 100
};
var anyVar: any = {};
var stringOrNumber: string | number;
var someObject: { name: string };
// Assign to a property access
obj.y = 4;
@@ -69,7 +77,7 @@ var kk = numIndex['what'];
var kk: any;
// Bracket notation property access using value of other type on type with numeric index signature and no string index signature
var ll = numIndex[window]; // Error
var ll = numIndex[someObject]; // Error
// Bracket notation property access using string value on type with string index signature and no numeric index signature
var mm = strIndex['N'];
@@ -106,7 +114,7 @@ var tt = noIndex[<any>null];
var tt: any;
// Bracket notation property access using values of other types on type with no index signatures
var uu = noIndex[window]; // Error
var uu = noIndex[someObject]; // Error
// Bracket notation property access using numeric value on type with numeric index signature and string index signature
var vv = noIndex[32];
@@ -114,19 +122,28 @@ var vv: any;
// Bracket notation property access using enum value on type with numeric index signature and string index signature
var ww = bothIndex[Compass.East];
var ww: HTMLDivElement;
var ww: B;
// Bracket notation property access using value of type 'any' on type with numeric index signature and string index signature
var xx = bothIndex[<any>null];
var xx: HTMLDivElement;
var xx: B;
// Bracket notation property access using string value on type with numeric index signature and string index signature
var yy = bothIndex['foo'];
var yy: HTMLElement;
var yy: A;
// Bracket notation property access using numeric string value on type with numeric index signature and string index signature
var zz = bothIndex['1.0'];
var zz: HTMLElement;
var zz: A;
// Bracket notation property access using value of other type on type with numeric index signature and no string index signature and string index signature
var zzzz = bothIndex[window]; // Error
var zzzz = bothIndex[someObject]; // Error
var x1 = numIndex[stringOrNumber];
var x1: any;
var x2 = strIndex[stringOrNumber];
var x2: Compass;
var x3 = bothIndex[stringOrNumber];
var x3: A;
@@ -0,0 +1,13 @@
/// <reference path="fourslash.ts"/>
////var x = `sadasdasdasdasfegsfd
/////*1*/rasdesgeryt35t35y35 e4 ergt er 35t 3535 `;
////var y = `1${2}/*2*/3`;
goTo.marker("1");
edit.insert("\r\n"); // edit will trigger formatting - should succeeed
goTo.marker("2");
edit.insert("\r\n");
verify.indentationIs(0);
verify.currentLineContentIs("3`;")
@@ -1,6 +1,7 @@
/// <reference path="fourslash.ts" />
// @BaselineFile: getEmitOutputSingleFile2.baseline
// @module: CommonJS
// @declaration: true
// @out: declSingleFile.js
// @outDir: tests/cases/fourslash/
@@ -1,6 +1,7 @@
/// <reference path="fourslash.ts" />
// @BaselineFile: getEmitOutputWithDeclarationFile2.baseline
// @module: CommonJS
// @Filename: decl.d.ts
// @emitThisFile: true
@@ -1,5 +1,6 @@
/// <reference path="fourslash.ts" />
// @module: CommonJS
// @declaration: true
//// interface privateInterface {}
//// export class Bar implements /*1*/privateInterface/*2*/{ }
@@ -1,5 +1,7 @@
/// <reference path="fourslash.ts" />
// @module: CommonJS
//// interface privateInterface {}
//// export class Bar implements /*1*/privateInterface/*2*/{ }
@@ -0,0 +1,17 @@
/// <reference path="fourslash.ts"/>
////var x0 = `sadasdasdasdas/*1*/fegsfdrasdesgeryt35t35y35 e4 ergt er 35t 3535 `;
////var x1 = `sadasdasdasdas/*2*/fegsfdr${0}asdesgeryt35t35y35 e4 ergt er 35t 3535 `;
////var x2 = `sadasdasdasdasfegsfdra${0}sdesge/*3*/ryt35t35y35 e4 ergt er 35t 3535 `;
////var x3 = `sadasdasdasdasfegsfdra${0}sdesge/*4*/ryt35${1}t35y35 e4 ergt er 35t 3535 `;
////var x2 = `sadasdasdasdasfegsfdra${0}sdesge${1}sf/*5*/ryt35t35y35 e4 ergt er 35t 3535 `;
function verifyIndentation(marker: string): void {
goTo.marker(marker);
edit.insert("\r\n");
verify.indentationIs(0);
}
verifyIndentation("1");
verifyIndentation("2");
verifyIndentation("3");
verifyIndentation("4");
verifyIndentation("5");
@@ -1,4 +1,6 @@
/// <reference path="fourslash.ts" />
// @module: CommonJS
//// interface Dictionary<T> {
//// [x: string]: T;
+30 -8
View File
@@ -4,8 +4,12 @@ module TypeScript.WebTsc {
declare var RealActiveXObject: { new (s: string): any };
function getWScriptSystem(): System {
function getWScriptSystem() {
var fso = new RealActiveXObject("Scripting.FileSystemObject");
var fileStream = new ActiveXObject("ADODB.Stream");
fileStream.Type = 2 /*text*/;
var args: string[] = [];
for (var i = 0; i < WScript.Arguments.length; i++) {
args[i] = WScript.Arguments.Item(i);
@@ -19,17 +23,35 @@ module TypeScript.WebTsc {
writeErr(s: string): void {
WScript.StdErr.Write(s);
},
readFile(fileName: string): string {
readFile(fileName: string, encoding?: string): string {
if (!fso.FileExists(fileName)) {
return undefined;
}
fileStream.Open();
try {
var f = fso.OpenTextFile(fileName, 1);
var s: string = f.ReadAll();
// TODO: Properly handle byte order marks
if (s.length >= 3 && s.charCodeAt(0) === 0xEF && s.charCodeAt(1) === 0xBB && s.charCodeAt(2) === 0xBF) s = s.slice(3);
f.Close();
if (encoding) {
fileStream.Charset = encoding;
fileStream.LoadFromFile(fileName);
}
else {
// Load file and read the first two bytes into a string with no interpretation
fileStream.Charset = "x-ansi";
fileStream.LoadFromFile(fileName);
var bom = fileStream.ReadText(2) || "";
// Position must be at 0 before encoding can be changed
fileStream.Position = 0;
// [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8
fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8";
}
// ReadText method always strips byte order mark from resulting string
return fileStream.ReadText();
}
catch (e) {
throw e;
}
finally {
fileStream.Close();
}
return s;
},
writeFile(fileName: string, data: string): boolean {
var f = fso.CreateTextFile(fileName, true);