Merge branch 'master' into test262RunnerUpdates

This commit is contained in:
Mohamed Hegazy
2014-12-02 18:01:46 -08:00
66 changed files with 1025 additions and 182 deletions
+26 -11
View File
@@ -1,6 +1,7 @@
// This file contains the build logic for the public repo
var fs = require("fs");
var os = require("os");
var path = require("path");
var child_process = require("child_process");
@@ -148,7 +149,7 @@ var compilerFilename = "tsc.js";
* @param useBuiltCompiler: true to use the built compiler, false to use the LKG
* @param noOutFile: true to compile without using --out
*/
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations) {
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, callback) {
file(outFile, prereqs, function() {
var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory;
var options = "-removeComments --module commonjs -noImplicitAny ";
@@ -180,6 +181,11 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
prependFile(prefixes[i], outFile);
}
}
if (callback) {
callback();
}
complete();
});
ex.addListener("error", function() {
@@ -224,7 +230,7 @@ compileFile(processDiagnosticMessagesJs,
[processDiagnosticMessagesTs],
[processDiagnosticMessagesTs],
[],
false);
/*useBuiltCompiler*/ false);
// The generated diagnostics map; built for the compiler and for the 'generate-diagnostics' task
file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], function () {
@@ -244,7 +250,6 @@ file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson],
ex.run();
}, {async: true})
desc("Generates a diagnostic file in TypeScript based on an input JSON file");
task("generate-diagnostics", [diagnosticInfoMapTs])
@@ -255,13 +260,24 @@ compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(co
var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js");
var servicesDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts");
compileFile(servicesFile, servicesSources, [builtLocalDirectory, copyright].concat(servicesSources), [copyright], /*useBuiltCompiler:*/ true, /*noOutFile:*/ false, /*generateDeclarations:*/ true);
compileFile(servicesFile,
servicesSources,
[builtLocalDirectory, copyright].concat(servicesSources),
[copyright],
/*useBuiltCompiler*/ true,
/*noOutFile*/ false,
/*generateDeclarations*/ true,
/*callback*/ fixDeclarationFile);
function fixDeclarationFile() {
fs.appendFileSync(servicesDefinitionsFile, os.EOL + "export = ts;")
}
// Local target to build the compiler and services
desc("Builds the full compiler and services");
task("local", ["generate-diagnostics", "lib", tscFile, servicesFile]);
// Local target to build the compiler and services
desc("Sets release mode flag");
task("release", function() {
@@ -278,7 +294,6 @@ task("clean", function() {
jake.rmRf(builtDirectory);
});
// Generate Markdown spec
var word2mdJs = path.join(scriptsDirectory, "word2md.js");
var word2mdTs = path.join(scriptsDirectory, "word2md.ts");
@@ -292,7 +307,7 @@ compileFile(word2mdJs,
[word2mdTs],
[word2mdTs],
[],
false);
/*useBuiltCompiler*/ false);
// The generated spec.md; built for the 'generate-spec' task
file(specMd, [word2mdJs, specWord], function () {
@@ -444,7 +459,7 @@ task("generate-code-coverage", ["tests", builtLocalDirectory], function () {
// Browser tests
var nodeServerOutFile = 'tests/webTestServer.js'
var nodeServerInFile = 'tests/webTestServer.ts'
compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile], [], true, true);
compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile], [], /*useBuiltCompiler:*/ true, /*noOutFile*/ true);
desc("Runs browserify on run.js to produce a file suitable for running tests in the browser");
task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() {
@@ -525,7 +540,7 @@ task("baseline-accept-test262", function() {
// Webhost
var webhostPath = "tests/webhost/webtsc.ts";
var webhostJsPath = "tests/webhost/webtsc.js";
compileFile(webhostJsPath, [webhostPath], [tscFile, webhostPath].concat(libraryTargets), [], true);
compileFile(webhostJsPath, [webhostPath], [tscFile, webhostPath].concat(libraryTargets), [], /*useBuiltCompiler*/true);
desc("Builds the tsc web host");
task("webhost", [webhostJsPath], function() {
@@ -535,7 +550,7 @@ task("webhost", [webhostJsPath], function() {
// Perf compiler
var perftscPath = "tests/perftsc.ts";
var perftscJsPath = "built/local/perftsc.js";
compileFile(perftscJsPath, [perftscPath], [tscFile, perftscPath, "tests/perfsys.ts"].concat(libraryTargets), [], true);
compileFile(perftscJsPath, [perftscPath], [tscFile, perftscPath, "tests/perfsys.ts"].concat(libraryTargets), [], /*useBuiltCompiler*/ true);
desc("Builds augmented version of the compiler for perf tests");
task("perftsc", [perftscJsPath]);
@@ -559,7 +574,7 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() {
var instrumenterPath = harnessDirectory + 'instrumenter.ts';
var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js';
compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath], [], true);
compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath], [], /*useBuiltCompiler*/ true);
desc("Builds an instrumented tsc.js");
task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function() {
+14 -17
View File
@@ -85,7 +85,6 @@ module ts {
getDiagnostics,
getDeclarationDiagnostics,
getGlobalDiagnostics,
checkProgram,
getParentOfSymbol,
getNarrowedTypeOfSymbol,
getDeclaredTypeOfSymbol,
@@ -546,14 +545,18 @@ module ts {
return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\";
}
function resolveExternalModuleName(location: Node, moduleExpression: Expression): Symbol {
if (moduleExpression.kind !== SyntaxKind.StringLiteral) {
function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression): Symbol {
if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral) {
return;
}
var moduleLiteral = <LiteralExpression>moduleExpression;
var moduleReferenceLiteral = <LiteralExpression>moduleReferenceExpression;
var searchPath = getDirectoryPath(getSourceFile(location).filename);
var moduleName = moduleLiteral.text;
// Module names are escaped in our symbol table. However, string literal values aren't.
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
var moduleName = escapeIdentifier(moduleReferenceLiteral.text);
if (!moduleName) return;
var isRelative = isExternalModuleNameRelative(moduleName);
if (!isRelative) {
@@ -574,10 +577,10 @@ module ts {
if (sourceFile.symbol) {
return getResolvedExportSymbol(sourceFile.symbol);
}
error(moduleLiteral, Diagnostics.File_0_is_not_an_external_module, sourceFile.filename);
error(moduleReferenceLiteral, Diagnostics.File_0_is_not_an_external_module, sourceFile.filename);
return;
}
error(moduleLiteral, Diagnostics.Cannot_find_external_module_0, moduleName);
error(moduleReferenceLiteral, Diagnostics.Cannot_find_external_module_0, moduleName);
}
function getResolvedExportSymbol(moduleSymbol: Symbol): Symbol {
@@ -8653,10 +8656,6 @@ module ts {
}
}
function checkProgram() {
forEach(program.getSourceFiles(), checkSourceFile);
}
function getSortedDiagnostics(): Diagnostic[]{
Debug.assert(fullTypeCheck, "diagnostics are available only in the full typecheck mode");
@@ -8669,12 +8668,11 @@ module ts {
}
function getDiagnostics(sourceFile?: SourceFile): Diagnostic[]{
if (sourceFile) {
checkSourceFile(sourceFile);
return filter(getSortedDiagnostics(), d => d.file === sourceFile);
}
checkProgram();
forEach(program.getSourceFiles(), checkSourceFile);
return getSortedDiagnostics();
}
@@ -9024,7 +9022,7 @@ module ts {
// This is necessary as an identifier in short-hand property assignment can contains two meaning:
// property name and property value.
if (location && location.kind === SyntaxKind.ShorthandPropertyAssignment) {
return resolveEntityName(location, (<ShortHandPropertyDeclaration>location).name, SymbolFlags.Value);
return resolveEntityName(location, (<ShorthandPropertyDeclaration>location).name, SymbolFlags.Value);
}
return undefined;
}
@@ -9192,9 +9190,9 @@ module ts {
return isImportResolvedToValue(getSymbolOfNode(node));
}
function hasSemanticErrors() {
function hasSemanticErrors(sourceFile?: SourceFile) {
// Return true if there is any semantic error in a file or globally
return getDiagnostics().length > 0 || getGlobalDiagnostics().length > 0;
return getDiagnostics(sourceFile).length > 0 || getGlobalDiagnostics().length > 0;
}
function isEmitBlocked(sourceFile?: SourceFile): boolean {
@@ -9312,7 +9310,6 @@ module ts {
function invokeEmitter(targetSourceFile?: SourceFile) {
var resolver = createResolver();
checkProgram();
return emitFiles(resolver, targetSourceFile);
}
+72 -38
View File
@@ -2236,33 +2236,35 @@ module ts {
emitTrailingComments(node);
}
function emitShortHandPropertyAssignment(node: ShortHandPropertyDeclaration) {
function emitAsNormalPropertyAssignment() {
emitLeadingComments(node);
// Emit identifier as an identifier
emit(node.name);
write(": ");
// Even though this is stored as identified because it is in short-hand property assignment,
// treated it as expression
emitExpressionIdentifier(node.name);
emitTrailingComments(node);
}
function emitDownlevelShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) {
emitLeadingComments(node);
// Emit identifier as an identifier
emit(node.name);
write(": ");
// Even though this is stored as identifier treat it as an expression
// Short-hand, { x }, is equivalent of normal form { x: x }
emitExpressionIdentifier(node.name);
emitTrailingComments(node);
}
if (compilerOptions.target < ScriptTarget.ES6) {
emitAsNormalPropertyAssignment();
function emitShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) {
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
// module m {
// export var y;
// }
// module m {
// export var obj = { y };
// }
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
var prefix = resolver.getExpressionNamePrefix(node.name);
if (prefix) {
emitDownlevelShorthandPropertyAssignment(node);
}
else if (compilerOptions.target >= ScriptTarget.ES6) {
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment
var prefix = resolver.getExpressionNamePrefix(node.name);
if (prefix) {
emitAsNormalPropertyAssignment();
}
// If short-hand property has no prefix, emit it as short-hand.
else {
emitLeadingComments(node);
emit(node.name);
emitTrailingComments(node);
}
// If short-hand property has no prefix, emit it as short-hand.
else {
emitLeadingComments(node);
emit(node.name);
emitTrailingComments(node);
}
}
@@ -3441,6 +3443,7 @@ module ts {
// Start new file on new line
writeLine();
emitDetachedComments(node);
// emit prologue directives prior to __extends
var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
if (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends) {
@@ -3472,6 +3475,8 @@ module ts {
emitCaptureThisForNodeIfNecessary(node);
emitLinesStartingAt(node.statements, startIndex);
}
emitLeadingComments(node.endOfFileToken);
}
function emitNode(node: Node): void {
@@ -3483,6 +3488,7 @@ module ts {
return emitPinnedOrTripleSlashComments(node);
}
// Check if the node can be emitted regardless of the ScriptTarget
switch (node.kind) {
case SyntaxKind.Identifier:
return emitIdentifier(<Identifier>node);
@@ -3521,8 +3527,6 @@ module ts {
return emitObjectLiteral(<ObjectLiteralExpression>node);
case SyntaxKind.PropertyAssignment:
return emitPropertyAssignment(<PropertyDeclaration>node);
case SyntaxKind.ShorthandPropertyAssignment:
return emitShortHandPropertyAssignment(<ShortHandPropertyDeclaration>node);
case SyntaxKind.ComputedPropertyName:
return emitComputedPropertyName(<ComputedPropertyName>node);
case SyntaxKind.PropertyAccessExpression:
@@ -3618,6 +3622,23 @@ module ts {
case SyntaxKind.SourceFile:
return emitSourceFile(<SourceFile>node);
}
// Emit node which needs to be emitted differently depended on ScriptTarget
if (compilerOptions.target < ScriptTarget.ES6) {
// Emit node down-level
switch (node.kind) {
case SyntaxKind.ShorthandPropertyAssignment:
return emitDownlevelShorthandPropertyAssignment(<ShorthandPropertyDeclaration>node);
}
}
else {
// Emit node natively
Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Invalid ScriptTarget. We should emit as ES6 or above");
switch (node.kind) {
case SyntaxKind.ShorthandPropertyAssignment:
return emitShorthandPropertyAssignment(<ShorthandPropertyDeclaration>node);
}
}
}
function hasDetachedComments(pos: number) {
@@ -3791,20 +3812,14 @@ module ts {
}
}
var hasSemanticErrors = resolver.hasSemanticErrors();
var isEmitBlocked = resolver.isEmitBlocked(targetSourceFile);
function emitFile(jsFilePath: string, sourceFile?: SourceFile) {
if (!isEmitBlocked) {
emitJavaScript(jsFilePath, sourceFile);
if (!hasSemanticErrors && compilerOptions.declaration) {
writeDeclarationFile(jsFilePath, sourceFile);
}
}
}
var hasSemanticErrors: boolean = false;
var isEmitBlocked: boolean = false;
if (targetSourceFile === undefined) {
// No targetSourceFile is specified (e.g. calling emitter from batch compiler)
hasSemanticErrors = resolver.hasSemanticErrors();
isEmitBlocked = resolver.isEmitBlocked();
forEach(program.getSourceFiles(), sourceFile => {
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
var jsFilePath = getOwnEmitOutputFilePath(sourceFile, program, ".js");
@@ -3820,16 +3835,35 @@ module ts {
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
// If shouldEmitToOwnFile returns true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
hasSemanticErrors = resolver.hasSemanticErrors(targetSourceFile);
isEmitBlocked = resolver.isEmitBlocked(targetSourceFile);
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js");
emitFile(jsFilePath, targetSourceFile);
}
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
// Otherwise, if --out is specified and targetSourceFile is not a declaration file,
// Emit all, non-external-module file, into one single output file
forEach(program.getSourceFiles(), sourceFile => {
if (!shouldEmitToOwnFile(sourceFile, compilerOptions)) {
hasSemanticErrors = hasSemanticErrors || resolver.hasSemanticErrors(sourceFile);
isEmitBlocked = isEmitBlocked || resolver.isEmitBlocked(sourceFile);
}
});
emitFile(compilerOptions.out);
}
}
function emitFile(jsFilePath: string, sourceFile?: SourceFile) {
if (!isEmitBlocked) {
emitJavaScript(jsFilePath, sourceFile);
if (!hasSemanticErrors && compilerOptions.declaration) {
writeDeclarationFile(jsFilePath, sourceFile);
}
}
}
// Sort and make the unique list of diagnostics
diagnostics.sort(compareDiagnostics);
diagnostics = deduplicateSortedDiagnostics(diagnostics);
+69 -54
View File
@@ -313,8 +313,10 @@ module ts {
case SyntaxKind.FinallyBlock:
case SyntaxKind.FunctionBlock:
case SyntaxKind.ModuleBlock:
case SyntaxKind.SourceFile:
return children((<Block>node).statements);
case SyntaxKind.SourceFile:
return children((<SourceFile>node).statements) ||
child((<SourceFile>node).endOfFileToken);
case SyntaxKind.VariableStatement:
return children(node.modifiers) ||
children((<VariableStatement>node).declarations);
@@ -943,7 +945,6 @@ module ts {
}
export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, version: string, isOpen: boolean = false): SourceFile {
var file: SourceFile;
var scanner: Scanner;
var token: SyntaxKind;
var parsingContext: ParsingContext;
@@ -1101,22 +1102,22 @@ module ts {
return getPositionFromLineAndCharacter(getLineStarts(), line, character);
}
function error(message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
var start = scanner.getTokenPos();
var length = scanner.getTextPos() - start;
errorAtPosition(start, length, message, arg0, arg1, arg2);
parseErrorAtPosition(start, length, message, arg0, arg1, arg2);
}
function errorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
var lastErrorPosition = file.parseDiagnostics.length
? file.parseDiagnostics[file.parseDiagnostics.length - 1].start
function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
var lastErrorPosition = sourceFile.parseDiagnostics.length
? sourceFile.parseDiagnostics[sourceFile.parseDiagnostics.length - 1].start
: -1;
// Don't report another error if it would just be at the same position as the last error.
if (start !== lastErrorPosition) {
var diagnostic = createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);
file.parseDiagnostics.push(diagnostic);
var diagnostic = createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2);
sourceFile.parseDiagnostics.push(diagnostic);
}
if (lookAheadMode === LookAheadMode.NoErrorYet) {
@@ -1126,7 +1127,7 @@ module ts {
function scanError(message: DiagnosticMessage) {
var pos = scanner.getTextPos();
errorAtPosition(pos, 0, message);
parseErrorAtPosition(pos, 0, message);
}
function onComment(pos: number, end: number) {
@@ -1165,7 +1166,7 @@ module ts {
// Keep track of the state we'll need to rollback to if lookahead fails (or if the
// caller asked us to always reset our state).
var saveToken = token;
var saveSyntacticErrorsLength = file.parseDiagnostics.length;
var saveSyntacticErrorsLength = sourceFile.parseDiagnostics.length;
// Keep track of the current look ahead mode (this matters if we have nested
// speculative parsing).
@@ -1187,7 +1188,7 @@ module ts {
lookAheadMode = saveLookAheadMode;
if (!result || alwaysResetState) {
token = saveToken;
file.parseDiagnostics.length = saveSyntacticErrorsLength;
sourceFile.parseDiagnostics.length = saveSyntacticErrorsLength;
}
return result;
@@ -1236,10 +1237,10 @@ module ts {
// Report specific message if provided with one. Otherwise, report generic fallback message.
if (diagnosticMessage) {
error(diagnosticMessage, arg0);
parseErrorAtCurrentToken(diagnosticMessage, arg0);
}
else {
error(Diagnostics._0_expected, tokenToString(kind));
parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(kind));
}
return false;
}
@@ -1307,10 +1308,10 @@ module ts {
function createMissingNode(kind: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node {
if (reportAtCurrentPosition) {
errorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0);
parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0);
}
else {
error(diagnosticMessage, arg0);
parseErrorAtCurrentToken(diagnosticMessage, arg0);
}
return createMissingNodeWithoutError(kind);
@@ -1395,10 +1396,12 @@ module ts {
}
function parseContextualModifier(t: SyntaxKind): boolean {
return token === t && tryParse(() => {
nextToken();
return canFollowModifier();
});
return token === t && tryParse(nextTokenCanFollowModifier);
}
function nextTokenCanFollowModifier() {
nextToken();
return canFollowModifier();
}
function parseAnyContextualModifier(): boolean {
@@ -1599,7 +1602,7 @@ module ts {
// Returns true if we should abort parsing.
function abortParsingListOrMoveToNextToken(kind: ParsingContext) {
error(parsingContextErrors(kind));
parseErrorAtCurrentToken(parsingContextErrors(kind));
if (isInSomeParsingContext()) {
return true;
}
@@ -3188,7 +3191,7 @@ module ts {
// Parse to check if it is short-hand property assignment or normal property assignment
if ((token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBraceToken) && tokenIsIdentifier) {
var shorthandDeclaration = <ShortHandPropertyDeclaration>createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos);
var shorthandDeclaration = <ShorthandPropertyDeclaration>createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos);
shorthandDeclaration.name = <Identifier>propertyName;
shorthandDeclaration.questionToken = questionToken;
return finishNode(shorthandDeclaration);
@@ -4066,9 +4069,13 @@ module ts {
// literals. We check to ensure that it is only a string literal later in the grammar
// walker.
node.expression = parseExpression();
// Ensure the string being required is in our 'identifier' table. This will ensure
// that features like 'find refs' will look inside this file when search for its name.
if (node.expression.kind === SyntaxKind.StringLiteral) {
internIdentifier((<LiteralExpression>node.expression).text);
}
parseExpected(SyntaxKind.CloseParenToken);
return finishNode(node);
}
@@ -4200,13 +4207,13 @@ module ts {
var referencePathMatchResult = getFileReferenceFromReferencePath(comment, range);
if (referencePathMatchResult) {
var fileReference = referencePathMatchResult.fileReference;
file.hasNoDefaultLib = referencePathMatchResult.isNoDefaultLib;
sourceFile.hasNoDefaultLib = referencePathMatchResult.isNoDefaultLib;
var diagnosticMessage = referencePathMatchResult.diagnosticMessage;
if (fileReference) {
referencedFiles.push(fileReference);
}
if (diagnosticMessage) {
file.parseDiagnostics.push(createFileDiagnostic(file, range.pos, range.end - range.pos, diagnosticMessage));
sourceFile.referenceDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
}
}
else {
@@ -4214,7 +4221,7 @@ module ts {
var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment);
if(amdModuleNameMatchResult) {
if(amdModuleName) {
file.parseDiagnostics.push(createFileDiagnostic(file, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
sourceFile.referenceDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
}
amdModuleName = amdModuleNameMatchResult[2];
}
@@ -4235,7 +4242,7 @@ module ts {
}
function getExternalModuleIndicator() {
return forEach(file.statements, node =>
return forEach(sourceFile.statements, node =>
node.flags & NodeFlags.Export
|| node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference
|| node.kind === SyntaxKind.ExportAssignment
@@ -4246,15 +4253,15 @@ module ts {
var syntacticDiagnostics: Diagnostic[];
function getSyntacticDiagnostics() {
if (syntacticDiagnostics === undefined) {
if (file.parseDiagnostics.length > 0) {
if (sourceFile.parseDiagnostics.length > 0) {
// Don't bother doing any grammar checks if there are already parser errors.
// Otherwise we may end up with too many cascading errors.
syntacticDiagnostics = file.parseDiagnostics;
syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics);
}
else {
// No parser errors were reported. Perform our stricter grammar checks.
syntacticDiagnostics = file.grammarDiagnostics;
checkGrammar(sourceText, languageVersion, file);
checkGrammar(sourceText, languageVersion, sourceFile);
syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.grammarDiagnostics);
}
}
@@ -4267,32 +4274,40 @@ module ts {
if (fileExtensionIs(filename, ".d.ts")) {
rootNodeFlags = NodeFlags.DeclarationFile;
}
file = <SourceFile>createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags);
file.filename = normalizePath(filename);
file.text = sourceText;
file.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition;
file.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter;
file.getLineStarts = getLineStarts;
file.getSyntacticDiagnostics = getSyntacticDiagnostics;
file.parseDiagnostics = [];
file.grammarDiagnostics = [];
file.semanticDiagnostics = [];
var sourceFile = <SourceFile>createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags);
sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition;
sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter;
sourceFile.getLineStarts = getLineStarts;
sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics;
sourceFile.filename = normalizePath(filename);
sourceFile.text = sourceText;
sourceFile.referenceDiagnostics = [];
sourceFile.parseDiagnostics = [];
sourceFile.grammarDiagnostics = [];
sourceFile.semanticDiagnostics = [];
var referenceComments = processReferenceComments();
file.referencedFiles = referenceComments.referencedFiles;
file.amdDependencies = referenceComments.amdDependencies;
file.amdModuleName = referenceComments.amdModuleName;
sourceFile.referencedFiles = referenceComments.referencedFiles;
sourceFile.amdDependencies = referenceComments.amdDependencies;
sourceFile.amdModuleName = referenceComments.amdModuleName;
file.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement);
file.externalModuleIndicator = getExternalModuleIndicator();
sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement);
Debug.assert(token === SyntaxKind.EndOfFileToken);
sourceFile.endOfFileToken = parseTokenNode();
file.nodeCount = nodeCount;
file.identifierCount = identifierCount;
file.version = version;
file.isOpen = isOpen;
file.languageVersion = languageVersion;
file.identifiers = identifiers;
return file;
sourceFile.externalModuleIndicator = getExternalModuleIndicator();
sourceFile.nodeCount = nodeCount;
sourceFile.identifierCount = identifierCount;
sourceFile.version = version;
sourceFile.isOpen = isOpen;
sourceFile.languageVersion = languageVersion;
sourceFile.identifiers = identifiers;
return sourceFile;
}
function isLeftHandSideExpression(expr: Expression): boolean {
@@ -4432,7 +4447,7 @@ module ts {
case SyntaxKind.ReturnStatement: return checkReturnStatement(<ReturnStatement>node);
case SyntaxKind.SetAccessor: return checkSetAccessor(<MethodDeclaration>node);
case SyntaxKind.SourceFile: return checkSourceFile(<SourceFile>node);
case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(<ShortHandPropertyDeclaration>node);
case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(<ShorthandPropertyDeclaration>node);
case SyntaxKind.SwitchStatement: return checkSwitchStatement(<SwitchStatement>node);
case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(<TaggedTemplateExpression>node);
case SyntaxKind.ThrowStatement: return checkThrowStatement(<ThrowStatement>node);
@@ -5449,7 +5464,7 @@ module ts {
return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
}
function checkShorthandPropertyAssignment(node: ShortHandPropertyDeclaration): boolean {
function checkShorthandPropertyAssignment(node: ShorthandPropertyDeclaration): boolean {
return checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
}
+16 -9
View File
@@ -257,7 +257,7 @@ module ts {
LastTypeNode = ParenthesizedType,
FirstPunctuation = OpenBraceToken,
LastPunctuation = CaretEqualsToken,
FirstToken = EndOfFileToken,
FirstToken = Unknown,
LastToken = TypeKeyword,
FirstTriviaToken = SingleLineCommentTrivia,
LastTriviaToken = WhitespaceTrivia,
@@ -386,7 +386,7 @@ module ts {
export type VariableOrParameterDeclaration = VariableDeclaration | ParameterDeclaration;
export type VariableOrParameterOrPropertyDeclaration = VariableOrParameterDeclaration | PropertyDeclaration;
export interface ShortHandPropertyDeclaration extends Declaration {
export interface ShorthandPropertyDeclaration extends Declaration {
name: Identifier;
questionToken?: Node;
}
@@ -786,6 +786,7 @@ module ts {
// Source files are declarations when they are external modules.
export interface SourceFile extends Declaration {
statements: NodeArray<ModuleElement>;
endOfFileToken: Node;
filename: string;
text: string;
@@ -795,17 +796,24 @@ module ts {
amdDependencies: string[];
amdModuleName: string;
referencedFiles: FileReference[];
semanticDiagnostics: Diagnostic[];
// Diagnostics reported about the "///<reference" comments in the file.
referenceDiagnostics: Diagnostic[];
// Parse errors refer specifically to things the parser could not understand at all (like
// missing tokens, or tokens it didn't know how to deal with). Grammar errors are for
// things the parser understood, but either the ES6 or TS grammars do not allow (like
// putting an 'public' modifier on a 'class declaration').
// missing tokens, or tokens it didn't know how to deal with).
parseDiagnostics: Diagnostic[];
// Grammar errors are for things the parser understood, but either the ES6 or TS grammars
// do not allow (like putting an 'public' modifier on a 'class declaration').
grammarDiagnostics: Diagnostic[];
// Returns all
// Returns all syntactic diagnostics (i.e. the reference, parser and grammar diagnostics).
getSyntacticDiagnostics(): Diagnostic[];
// File level diagnostics reported by the binder.
semanticDiagnostics: Diagnostic[];
hasNoDefaultLib: boolean;
externalModuleIndicator: Node; // The first node that causes this file to be an external module
nodeCount: number;
@@ -874,7 +882,6 @@ module ts {
getIdentifierCount(): number;
getSymbolCount(): number;
getTypeCount(): number;
checkProgram(): void;
emitFiles(targetSourceFile?: SourceFile): EmitResult;
getParentOfSymbol(symbol: Symbol): Symbol;
getNarrowedTypeOfSymbol(symbol: Symbol, node: Node): Type;
@@ -986,7 +993,7 @@ module ts {
isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean;
getNodeCheckFlags(node: Node): NodeCheckFlags;
getEnumMemberValue(node: EnumMember): number;
hasSemanticErrors(): boolean;
hasSemanticErrors(sourceFile?: SourceFile): boolean;
isDeclarationVisible(node: Declaration): boolean;
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableOrParameterDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
+3 -4
View File
@@ -2217,11 +2217,10 @@ module FourSlash {
// TODO (drosen): We need to enforce checking on these tests.
var program = ts.createProgram([Harness.Compiler.fourslashFilename, fileName], { out: "fourslashTestOutput.js", noResolve: true }, host);
var checker = ts.createTypeChecker(program, /*fullTypeCheckMode*/ true);
checker.checkProgram();
var errs = program.getDiagnostics().concat(checker.getDiagnostics());
if (errs.length > 0) {
throw new Error('Error compiling ' + fileName + ': ' + errs.map(e => e.messageText).join('\r\n'));
var errors = program.getDiagnostics().concat(checker.getDiagnostics());
if (errors.length > 0) {
throw new Error('Error compiling ' + fileName + ': ' + errors.map(e => e.messageText).join('\r\n'));
}
checker.emitFiles();
result = result || ''; // Might have an empty fourslash file
-1
View File
@@ -801,7 +801,6 @@ module Harness {
useCaseSensitiveFileNames));
var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true);
checker.checkProgram();
var isEmitBlocked = checker.isEmitBlocked();
+17 -42
View File
@@ -722,6 +722,9 @@ module ts {
public filename: string;
public text: string;
public statements: NodeArray<Statement>;
public endOfFileToken: Node;
// These methods will have their implementation provided by the implementation the
// compiler actually exports off of SourceFile.
public getLineAndCharacterFromPosition: (position: number) => LineAndCharacter;
@@ -732,15 +735,17 @@ module ts {
public amdDependencies: string[];
public amdModuleName: string;
public referencedFiles: FileReference[];
public referenceDiagnostics: Diagnostic[];
public parseDiagnostics: Diagnostic[];
public grammarDiagnostics: Diagnostic[];
public semanticDiagnostics: Diagnostic[];
public hasNoDefaultLib: boolean;
public externalModuleIndicator: Node; // The first node that causes this file to be an external module
public nodeCount: number;
public identifierCount: number;
public symbolCount: number;
public statements: NodeArray<Statement>;
public version: string;
public isOpen: boolean;
public languageVersion: ScriptTarget;
@@ -4665,18 +4670,14 @@ module ts {
function getEmitOutput(filename: string): EmitOutput {
synchronizeHostData();
filename = normalizeSlashes(filename);
var compilerOptions = program.getCompilerOptions();
var targetSourceFile = program.getSourceFile(filename); // Current selected file to be output
// If --out flag is not specified, shouldEmitToOwnFile is true. Otherwise shouldEmitToOwnFile is false.
var shouldEmitToOwnFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions);
var emitOutput: EmitOutput = {
outputFiles: [],
emitOutputStatus: undefined,
};
var sourceFile = getSourceFile(filename);
var outputFiles: OutputFile[] = [];
function getEmitOutputWriter(filename: string, data: string, writeByteOrderMark: boolean) {
emitOutput.outputFiles.push({
outputFiles.push({
name: filename,
writeByteOrderMark: writeByteOrderMark,
text: data
@@ -4686,41 +4687,15 @@ module ts {
// Initialize writer for CompilerHost.writeFile
writer = getEmitOutputWriter;
var containSyntacticErrors = false;
if (shouldEmitToOwnFile) {
// Check only the file we want to emit
containSyntacticErrors = containErrors(program.getDiagnostics(targetSourceFile));
} else {
// Check the syntactic of only sourceFiles that will get emitted into single output
// Terminate the process immediately if we encounter a syntax error from one of the sourceFiles
containSyntacticErrors = forEach(program.getSourceFiles(), sourceFile => {
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
// If emit to a single file then we will check all files that do not have external module
return containErrors(program.getDiagnostics(sourceFile));
}
return false;
});
}
if (containSyntacticErrors) {
// If there is a syntax error, terminate the process and report outputStatus
emitOutput.emitOutputStatus = EmitReturnStatus.AllOutputGenerationSkipped;
// Reset writer back to undefined to make sure that we produce an error message
// if CompilerHost.writeFile is called when we are not in getEmitOutput
writer = undefined;
return emitOutput;
}
// Perform semantic and force a type check before emit to ensure that all symbols are updated
// EmitFiles will report if there is an error from TypeChecker and Emitter
// Depend whether we will have to emit into a single file or not either emit only selected file in the project, emit all files into a single file
var emitFilesResult = getFullTypeCheckChecker().emitFiles(targetSourceFile);
emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus;
var emitOutput = getFullTypeCheckChecker().emitFiles(sourceFile);
// Reset writer back to undefined to make sure that we produce an error message if CompilerHost.writeFile method is called when we are not in getEmitOutput
writer = undefined;
return emitOutput;
return {
outputFiles,
emitOutputStatus: emitOutput.emitResultStatus
};
}
function getMeaningFromDeclaration(node: Node): SemanticMeaning {
+7 -1
View File
@@ -912,6 +912,13 @@ module ts {
throw new Error("Invalid operation");
}
}
// Here we expose the TypeScript services as an external module
// so that it may be consumed easily like a node module.
declare var module: any;
if (typeof module !== "undefined" && module.exports) {
module.exports = ts;
}
}
@@ -919,4 +926,3 @@ module ts {
module TypeScript.Services {
export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory;
}
-4
View File
@@ -280,10 +280,6 @@ module ts {
}
function nodeHasTokens(n: Node): boolean {
if (n.kind === SyntaxKind.Unknown) {
return false;
}
// If we have a token or node that has a non-zero width, it must have tokens.
// Note, that getWidth() does not take trivia into account.
return n.getWidth() !== 0;
@@ -83,3 +83,8 @@ function foo(x, y, z) {
y = a;
z = a;
}
//function foo<T, U extends T, V extends Date>(x: T, y: U, z: V) {
// x = a;
// y = a;
// z = a;
//}
@@ -52,3 +52,4 @@ var c5c = (function () {
};
return c5c;
})();
//import c5c = require('');
@@ -105,3 +105,6 @@ var e6b;
(function (e6b) {
e6b.y = 2;
})(e6b || (e6b = {})); // should be error
// enum then import, messes with error reporting
//enum e7 { One }
//import e7 = require(''); // should be error
@@ -40,3 +40,5 @@ var e2 = (function () {
};
return e2;
})();
//enum then enum - covered
//enum then import - covered
@@ -93,3 +93,6 @@ var y5b;
})(y5b || (y5b = {})); // should be an error
function y5c() {
}
// function then import, messes with other errors
//function y6() { }
//import y6 = require('');
@@ -48,3 +48,4 @@ var i3;
i3[i3["One"] = 0] = "One";
})(i3 || (i3 = {}));
;
//import i4 = require(''); // error
@@ -268,3 +268,4 @@ var m6;
(function (m6) {
m6.y = 2;
})(m6 || (m6 = {}));
//import m6 = require('');
@@ -80,3 +80,6 @@ var x6b;
(function (x6b) {
x6b.y = 2;
})(x6b || (x6b = {})); // error
// var then import, messes with other error reporting
//var x7 = 1;
//import x7 = require('');
@@ -45,3 +45,37 @@ var Derived = (function (_super) {
})(Base);
var x = null;
var y = 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();
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,22 @@
//// [commentEmitAtEndOfFile1.ts]
// test
var f = ''
// test #2
module foo {
function bar() { }
}
// test #3
module empty {
}
// test #4
//// [commentEmitAtEndOfFile1.js]
// test
var f = '';
// test #2
var foo;
(function (foo) {
function bar() {
}
})(foo || (foo = {}));
// test #4
@@ -0,0 +1,17 @@
=== tests/cases/compiler/commentEmitAtEndOfFile1.ts ===
// test
var f = ''
>f : string
// test #2
module foo {
>foo : typeof foo
function bar() { }
>bar : () => void
}
// test #3
module empty {
>empty : unknown
}
// test #4
@@ -6,3 +6,4 @@ Input:
//// [commentsAtEndOfFile1.js]
Input: ;
//Testing two
@@ -501,3 +501,4 @@ var r8b8 = b8 !== a8;
var r8b9 = b9 !== a9;
var r8b10 = b10 !== a10;
var r8b11 = b11 !== a11;
//var r8b12 = b12 !== a12;
@@ -427,3 +427,4 @@ var r8b6 = b6 !== a6;
var r8b7 = b7 !== a7;
var r8b8 = b8 !== a8;
var r8b9 = b9 !== a9;
//var r8b10 = b10 !== a10;
@@ -316,3 +316,4 @@ var r8b3 = b3 !== a3;
var r8b4 = b4 !== a4;
var r8b5 = b5 !== a5;
var r8b6 = b6 !== a6;
//var r8b7 = b7 !== a7;
@@ -316,3 +316,4 @@ var r8b3 = b3 !== a3;
var r8b4 = b4 !== a4;
var r8b5 = b5 !== a5;
var r8b6 = b6 !== a6;
//var r8b7 = b7 !== a7;
+45
View File
@@ -43,3 +43,48 @@ interface Array<T> {
var fa;
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);
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);
@@ -25,3 +25,13 @@
//// [conformanceFunctionOverloads.js]
// Function overloads do not emit code
// Function overload signature with optional parameter
// Function overload signature with optional parameter
// Function overloads with generic and non-generic overloads
// Function overloads whose only difference is returning different unconstrained generic parameters
// Function overloads whose only difference is returning different constrained generic parameters
// Function overloads that differ only by type parameter constraints
// Function overloads with matching accessibility
// Function overloads with matching export
// Function overloads with more params than implementation signature
// Function overloads where return types are same infinitely recursive type reference
@@ -29,3 +29,29 @@
//// [emitCommentsOnlyFile.js]
/**
* @name Foo
* @class
*/
/**#@+
* @memberOf Foo#
* @field
*/
/**
* @name bar
* @type Object[]
*/
/**#@-*/
/**
* @name Foo2
* @class
*/
/**#@+
* @memberOf Foo2#
* @field
*/
/**
* @name bar
* @type Object[]
*/
/**#@-*/
@@ -31,3 +31,29 @@ var y = 10;
//// [emitPostComments.js]
var y = 10;
/**
* @name Foo
* @class
*/
/**#@+
* @memberOf Foo#
* @field
*/
/**
* @name bar
* @type Object[]
*/
/**#@-*/
/**
* @name Foo2
* @class
*/
/**#@+
* @memberOf Foo2#
* @field
*/
/**
* @name bar
* @type Object[]
*/
/**#@-*/
@@ -33,3 +33,29 @@ var y = 10;
//// [emitPreComments.js]
// This is pre comment
var y = 10;
/**
* @name Foo
* @class
*/
/**#@+
* @memberOf Foo#
* @field
*/
/**
* @name bar
* @type Object[]
*/
/**#@-*/
/**
* @name Foo2
* @class
*/
/**#@+
* @memberOf Foo2#
* @field
*/
/**
* @name bar
* @type Object[]
*/
/**#@-*/
@@ -20,3 +20,4 @@ var Foo = (function () {
var baz = Foo.b;
// Foo.b won't bind.
baz.concat("y");
// So we don't want an error on 'concat'.
@@ -113,3 +113,8 @@ function foo(x, y, z) {
a = y;
a = z;
}
//function foo<T, U extends T, V extends Date>(x: T, y: U, z: V) {
// a = x;
// a = y;
// a = z;
//}
@@ -0,0 +1,19 @@
//// [externalModuleReferenceDoubleUnderscore1.ts]
declare module 'timezonecomplete' {
import basics = require("__timezonecomplete/basics");
export import TimeUnit = basics.TimeUnit;
}
declare module '__timezonecomplete/basics' {
export enum TimeUnit {
Second = 0,
Minute = 1,
Hour = 2,
Day = 3,
Week = 4,
Month = 5,
Year = 6,
}
}
//// [externalModuleReferenceDoubleUnderscore1.js]
@@ -0,0 +1,37 @@
=== tests/cases/compiler/externalModuleReferenceDoubleUnderscore1.ts ===
declare module 'timezonecomplete' {
import basics = require("__timezonecomplete/basics");
>basics : typeof basics
export import TimeUnit = basics.TimeUnit;
>TimeUnit : typeof basics.TimeUnit
>basics : typeof basics
>TimeUnit : basics.TimeUnit
}
declare module '__timezonecomplete/basics' {
export enum TimeUnit {
>TimeUnit : TimeUnit
Second = 0,
>Second : TimeUnit
Minute = 1,
>Minute : TimeUnit
Hour = 2,
>Hour : TimeUnit
Day = 3,
>Day : TimeUnit
Week = 4,
>Week : TimeUnit
Month = 5,
>Month : TimeUnit
Year = 6,
>Year : TimeUnit
}
}
@@ -113,3 +113,7 @@ function foo2(x, y) {
foo(x);
foo(y);
}
//function foo2<T extends { (): void }, U extends T>(x: T, y: U) {
// foo(x);
// foo(y);
//}
@@ -57,3 +57,10 @@ function other3(arg) {
// BUG 821629
//var u: U = r2[1]; // ok
}
//function other3<T extends U, U extends Date>(arg: T) {
// var b: { [x: number]: T };
// var r2 = foo(b);
// var d = r2[1];
// // BUG 821629
// //var u: U = r2[1]; // ok
//}
@@ -58,3 +58,10 @@ function other3(arg) {
// BUG 821629
//var u: U = r2['hm']; // ok
}
//function other3<T extends U, U extends Date>(arg: T) {
// var b: { [x: string]: T };
// var r2 = foo(b);
// var d: Date = r2['hm']; // ok
// // BUG 821629
// //var u: U = r2['hm']; // ok
//}
@@ -0,0 +1,2 @@
EmitOutputStatus : AllOutputGenerationSkipped
@@ -0,0 +1,8 @@
EmitOutputStatus : Succeeded
Filename : tests/cases/fourslash/inputFile1.js
// File to emit, does not contain semantic errors
// expected to be emitted correctelly regardless of the semantic errors in the other file
var noErrors = true;
Filename : tests/cases/fourslash/inputFile1.d.ts
declare var noErrors: boolean;
@@ -0,0 +1,8 @@
EmitOutputStatus : DeclarationGenerationSkipped
Filename : out.js
// File to emit, does not contain semantic errors, but --out is passed
// expected to not generate declarations because of the semantic errors in the other file
var noErrors = true;
// File not emitted, and contains semantic errors
var semanticError = "string";
@@ -0,0 +1,6 @@
EmitOutputStatus : Succeeded
Filename : tests/cases/fourslash/inputFile1.js
// File to emit, does not contain syntactic errors
// expected to be emitted correctelly regardless of the syntactic errors in the other file
var noErrors = true;
@@ -0,0 +1,2 @@
EmitOutputStatus : AllOutputGenerationSkipped
@@ -241,3 +241,28 @@ function foo4(t, u) {
var j = [u, derived]; // Derived[]
var k = [t, u];
}
//function foo3<T extends U, U extends Derived>(t: T, u: U) {
// var a = [t, t]; // T[]
// var b = [t, null]; // T[]
// var c = [t, u]; // {}[]
// var d = [t, 1]; // {}[]
// var e = [() => t, () => u]; // {}[]
// var f = [() => t, () => u, () => null]; // { (): any }[]
// var g = [t, base]; // Base[]
// var h = [t, derived]; // Derived[]
// var i = [u, base]; // Base[]
// var j = [u, derived]; // Derived[]
//}
//function foo4<T extends U, U extends Base>(t: T, u: U) {
// var a = [t, t]; // T[]
// var b = [t, null]; // T[]
// var c = [t, u]; // BUG 821629
// var d = [t, 1]; // {}[]
// var e = [() => t, () => u]; // {}[]
// var f = [() => t, () => u, () => null]; // { (): any }[]
// var g = [t, base]; // Base[]
// var h = [t, derived]; // Derived[]
// var i = [u, base]; // Base[]
// var j = [u, derived]; // Derived[]
// var k: Base[] = [t, u];
//}
@@ -47,3 +47,11 @@ function f2() {
var x;
x.getDate();
}
//function f2<T extends Date, U extends T>() {
// function g<T extends Number, U extends T>() {
// var x: U;
// x.toFixed();
// }
// var x: U;
// x.getDate();
//}
@@ -66,3 +66,13 @@ var C2 = (function () {
};
return C2;
})();
//class C2<T extends Date, U extends T> {
// g<T extends Number, U extends T>() {
// var x: U;
// x.toFixed();
// }
// h() {
// var x: U;
// x.getDate();
// }
//}
@@ -18,3 +18,5 @@ var M;
//var p: M.P;
//var m: M = M;
var x1 = M.a;
//var x2 = m.a;
//var q: m.P;
@@ -80,3 +80,8 @@ function foo(x, y, z) {
y = null;
z = null;
}
//function foo<T, U extends T, V extends Date>(x: T, y: U, z: V) {
// x = null;
// y = null;
// z = null;
//}
@@ -17,3 +17,11 @@
//// [parserS7.6.1.1_A1.10.js]
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* The "for" token can not be used as identifier
*
* @path ch07/7.6/7.6.1/7.6.1.1/S7.6.1.1_A1.10.js
* @description Checking if execution of "for=1" fails
* @negative
*/
//for = 1;
@@ -289,3 +289,220 @@
// [index: number]: string;
// }
//}
//import fs = module("fs");
//module TypeScriptAllInOne {
// export class Program {
// static Main(...args: string[]) {
// try {
// var bfs = new BasicFeatures();
// var retValue: number = 0;
// retValue = bfs.VARIABLES();
// if (retValue != 0) {
// return 1;
// }
// retValue = bfs.STATEMENTS(4);
// if (retValue != 0) {
// return 1;
// }
// retValue = bfs.TYPES();
// if (retValue != 0) {
// return 1;
// }
// retValue = bfs.OPERATOR();
// if (retValue != 0) {
// return 1;
// }
// }
// catch (e) {
// console.log(e);
// }
// finally {
// }
// console.log('Done');
// return 0;
// }
// }
// class BasicFeatures {
// /// <summary>
// /// Test various of variables. Including nullable,key world as variable,special format
// /// </summary>
// /// <returns></returns>
// public VARIABLES(): number {
// var local = Number.MAX_VALUE;
// var min = Number.MIN_VALUE;
// var inf = Number.NEGATIVE_INFINITY;
// var nan = Number.NaN;
// var undef = undefined;
// var п = local;
// var м = local;
// var local5 = <fs.File>null;
// var local6 = local5 instanceof fs.File;
// var hex = 0xBADC0DE, Hex = 0XDEADBEEF;
// var float = 6.02e23, float2 = 6.02E-23
// var char = 'c', \u0066 = '\u0066', hexchar = '\x42';
// var quoted = '"', quoted2 = "'";
// var reg = /\w*/;
// var objLit = { "var": number = 42, equals: function (x) { return x["var"] === 42; }, toString: () => 'objLit{42}' };
// var weekday = Weekdays.Monday;
// var con = char + f + hexchar + float.toString() + float2.toString() + reg.toString() + objLit + weekday;
// //
// var any = 0;
// var boolean = 0;
// var declare = 0;
// var constructor = 0;
// var get = 0;
// var implements = 0;
// var interface = 0;
// var let = 0;
// var module = 0;
// var number = 0;
// var package = 0;
// var private = 0;
// var protected = 0;
// var public = 0;
// var set = 0;
// var static = 0;
// var string = 0;
// var yield = 0;
// var sum3 = any + boolean + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield;
// return 0;
// }
// /// <summary>
// /// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally
// /// </summary>
// /// <param name="i"></param>
// /// <returns></returns>
// STATEMENTS(i: number): number {
// var retVal = 0;
// if (i == 1)
// retVal = 1;
// else
// retVal = 0;
// switch (i) {
// case 2:
// retVal = 1;
// break;
// case 3:
// retVal = 1;
// break;
// default:
// break;
// }
// for (var x in { x: 0, y: 1 }) {
// }
// try {
// throw null;
// }
// catch (Exception) {
// }
// finally {
// try { }
// catch (Exception) { }
// }
// return retVal;
// }
// /// <summary>
// /// Test types in ts language. Including class,struct,interface,delegate,anonymous type
// /// </summary>
// /// <returns></returns>
// public TYPES(): number {
// var retVal = 0;
// var c = new CLASS();
// var xx: IF = c;
// retVal += c.Property;
// retVal += c.Member();
// retVal += xx ^= Foo() ? 0 : 1;
// //anonymous type
// var anony = { a: new CLASS() };
// retVal += anony.a.d();
// return retVal;
// }
// ///// <summary>
// ///// Test different operators
// ///// </summary>
// ///// <returns></returns>
// public OPERATOR(): number {
// var a: number[] = [1, 2, 3, 4, implements , ];/*[] bug*/ // YES []
// var i = a[1];/*[]*/
// i = i + i - i * i / i % i & i | i ^ i;/*+ - * / % & | ^*/
// var b = true && false || true ^ false;/*& | ^*/
// b = !b;/*!*/
// i = ~i;/*~i*/
// b = i < (i - continue ) && (i + 1) > i;/*< && >*/
// var f = true ? 1 : 0;/*? :*/ // YES :
// i++;/*++*/
// i--;/*--*/
// b = true && false || true;/*&& ||*/
// i = i << 5;/*<<*/
// i = i >> 5;/*>>*/
// var j = i;
// b = i == j && i != j && i <= j && i >= j;/*= == && != <= >=*/
// i += <number>5.0;/*+=*/
// i -= i;/*-=*/
// i *= i;/**=*/
// if (i == 0)
// i++;
// i /= i;/*/=*/
// i %= i;/*%=*/
// i &= i;/*&=*/
// i |= i;/*|=*/
// i ^= i;/*^=*/
// i <<= i;/*<<=*/
// i >>= i;/*>>=*/
// if (i == 0 && !b && f == 1)
// return 0;
// else return 1;
// }
// }
// interface IF {
// Foo <!-- ): boolean;
// }
// class CLASS implements IF {
// public d = () => ' return 0; };
// public get Property() { return 0; }
// public Member() {
// return 0;
// }
// public Foo(): boolean {
// var myEvent = () => { return 1; };
// if (myEvent() == 1)
// return true;
// else
// return false;
// }
// }
// // todo: use these
// class A {
// public method1(val:number) {
// return val;
// }
// public method2() {
// return 2 * this.method1(2);
// }
// }
// class B extends A {
// public method2() {
// return this.method1(2);
// }
// }
// class Overloading {
// private otherValue = 42;
// constructor(private value: number, public name: string) { }
// public Overloads(value: string);
// public Overloads(value: string, ...rest: string[]) { }
// public DefaultValue(value?: string = "Hello") { }
// }
//}
//enum Weekdays {
// Monday,
// Tuesday,
// Weekend,
//}
//enum Fruit {
// Apple,
// Pear
//}
//interface IDisposable {
// Dispose(): void;
//}
//TypeScriptAllInOne.Program.Main();
@@ -62,3 +62,44 @@ var MsPortal;
})(Base = Controls.Base || (Controls.Base = {}));
})(Controls = MsPortal.Controls || (MsPortal.Controls = {}));
})(MsPortal || (MsPortal = {}));
// 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> {
}
}
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> {
}
}
@@ -2,4 +2,5 @@
// Comment
//// [sourceMap-Comment1.js]
// Comment
//# sourceMappingURL=sourceMap-Comment1.js.map
@@ -1,2 +1,2 @@
//// [sourceMap-Comment1.js.map]
{"version":3,"file":"sourceMap-Comment1.js","sourceRoot":"","sources":["sourceMap-Comment1.ts"],"names":[],"mappings":""}
{"version":3,"file":"sourceMap-Comment1.js","sourceRoot":"","sources":["sourceMap-Comment1.ts"],"names":[],"mappings":"AAAA,UAAU"}
@@ -4,4 +4,17 @@ mapUrl: sourceMap-Comment1.js.map
sourceRoot:
sources: sourceMap-Comment1.ts
===================================================================
-------------------------------------------------------------------
emittedFile:tests/cases/compiler/sourceMap-Comment1.js
sourceFile:sourceMap-Comment1.ts
-------------------------------------------------------------------
>>>// Comment
1 >
2 >^^^^^^^^^^
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
2 >// Comment
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 11) Source(1, 11) + SourceIndex(0)
---
>>>//# sourceMappingURL=sourceMap-Comment1.js.map
@@ -39,3 +39,13 @@ var C = (function () {
}
return C;
})();
//function foo<T, U extends T>(x: T, y: U) {
// foo<U, U>(y, y);
// return new C<U, T>();
//}
//class C<T extends U, U> {
// x: T;
//}
//interface I<T, U extends T> {
// x: C<U, T>;
//}
@@ -53,3 +53,15 @@ interface I2<V, T, U> {
//// [typeParameterUsedAsTypeParameterConstraint3.js]
// Type parameters are in scope in their own and other type parameter lists
// Object types
//interface I < T, U extends T, V extends U > {
// x: T;
// y: U;
// z: V;
// foo<W extends V>(x: W): T;
//}
//interface I2<V extends U, T, U extends T> {
// x: T;
// y: U;
// z: V;
// foo<W extends V>(x: W): T;
//}
@@ -79,3 +79,8 @@ function foo(x, y, z) {
y = undefined;
z = undefined;
}
//function foo<T, U extends T, V extends Date>(x: T, y: U, z: V) {
// x = undefined;
// y = undefined;
// z = undefined;
//}
+1
View File
@@ -269,3 +269,4 @@ var C3 = (function () {
})();
var qq = C3.q;
var qq;
// Parentheses - tested a bunch above
@@ -0,0 +1,10 @@
// test
var f = ''
// test #2
module foo {
function bar() { }
}
// test #3
module empty {
}
// test #4
@@ -0,0 +1,16 @@
declare module 'timezonecomplete' {
import basics = require("__timezonecomplete/basics");
export import TimeUnit = basics.TimeUnit;
}
declare module '__timezonecomplete/basics' {
export enum TimeUnit {
Second = 0,
Minute = 1,
Hour = 2,
Day = 3,
Week = 4,
Month = 5,
Year = 6,
}
}
@@ -0,0 +1,10 @@
/// <reference path="fourslash.ts" />
// @BaselineFile: getEmitOutputWithEarlySyntacticErrors.baseline
// @Filename: inputFile1.ts
// @emitThisFile: true
//// // File contains early errors. All outputs should be skipped.
//// const uninitialized_const_error;
verify.baselineGetEmitOutput();
@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// @BaselineFile: getEmitOutputWithSemanticErrorsForMultipleFiles.baseline
// @declaration: true
// @Filename: inputFile1.ts
// @emitThisFile: true
//// // File to emit, does not contain semantic errors
//// // expected to be emitted correctelly regardless of the semantic errors in the other file
//// var noErrors = true;
// @Filename: inputFile2.ts
//// // File not emitted, and contains semantic errors
//// var semanticError: boolean = "string";
verify.baselineGetEmitOutput();
@@ -0,0 +1,17 @@
/// <reference path="fourslash.ts" />
// @BaselineFile: getEmitOutputWithSemanticErrorsForMultipleFiles2.baseline
// @declaration: true
// @out: out.js
// @Filename: inputFile1.ts
// @emitThisFile: true
//// // File to emit, does not contain semantic errors, but --out is passed
//// // expected to not generate declarations because of the semantic errors in the other file
//// var noErrors = true;
// @Filename: inputFile2.ts
//// // File not emitted, and contains semantic errors
//// var semanticError: boolean = "string";
verify.baselineGetEmitOutput();
@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
// @BaselineFile: getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline
// @Filename: inputFile1.ts
// @emitThisFile: true
//// // File to emit, does not contain syntactic errors
//// // expected to be emitted correctelly regardless of the syntactic errors in the other file
//// var noErrors = true;
// @Filename: inputFile2.ts
//// // File not emitted, and contains syntactic errors
//// var syntactic Error;
verify.baselineGetEmitOutput();
@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// @BaselineFile: getEmitOutputWithSyntacticErrorsForMultipleFiles2.baseline
// @out: out.js
// @Filename: inputFile1.ts
// @emitThisFile: true
//// // File to emit, does not contain syntactic errors, but --out is passed
//// // expected to not generate outputs because of the syntactic errors in the other file.
//// var noErrors = true;
// @Filename: inputFile2.ts
//// // File not emitted, and contains syntactic errors
//// var syntactic Error;
verify.baselineGetEmitOutput();
@@ -0,0 +1,6 @@
/// <reference path='fourslash.ts'/>
////eval(\/*1*/
goTo.marker("1");
verify.signatureHelpCountIs(1);