mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into getRenameInfo
Conflicts: src/services/services.ts
This commit is contained in:
+12
-14
@@ -2968,10 +2968,12 @@ module ts {
|
||||
}
|
||||
|
||||
if (getDeclarationFlagsFromSymbol(sourceProp) & NodeFlags.Private || getDeclarationFlagsFromSymbol(targetProp) & NodeFlags.Private) {
|
||||
if (reportErrors) {
|
||||
reportError(Diagnostics.Private_property_0_cannot_be_reimplemented, symbolToString(targetProp));
|
||||
if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
|
||||
if (reportErrors) {
|
||||
reportError(Diagnostics.Private_property_0_cannot_be_reimplemented, symbolToString(targetProp));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors)) {
|
||||
if (reportErrors) {
|
||||
@@ -5212,8 +5214,7 @@ module ts {
|
||||
var otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
|
||||
var otherAccessor = <AccessorDeclaration>getDeclarationOfKind(node.symbol, otherKind);
|
||||
if (otherAccessor) {
|
||||
var visibilityFlags = NodeFlags.Private | NodeFlags.Public;
|
||||
if (((node.flags & visibilityFlags) !== (otherAccessor.flags & visibilityFlags))) {
|
||||
if (((node.flags & NodeFlags.AccessibilityModifier) !== (otherAccessor.flags & NodeFlags.AccessibilityModifier))) {
|
||||
error(node.name, Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility);
|
||||
}
|
||||
|
||||
@@ -7240,12 +7241,9 @@ module ts {
|
||||
return target !== unknownSymbol && ((target.flags & SymbolFlags.Value) !== 0);
|
||||
}
|
||||
|
||||
function shouldEmitDeclarations() {
|
||||
// If the declaration emit and there are no errors being reported in program or by checker
|
||||
// declarations can be emitted
|
||||
return compilerOptions.declaration &&
|
||||
!program.getDiagnostics().length &&
|
||||
!getDiagnostics().length;
|
||||
function hasSemanticErrors() {
|
||||
// Return true if there is any semantic error in a file or globally
|
||||
return getDiagnostics().length > 0 || getGlobalDiagnostics().length > 0;
|
||||
}
|
||||
|
||||
function isReferencedImportDeclaration(node: ImportDeclaration): boolean {
|
||||
@@ -7306,7 +7304,7 @@ module ts {
|
||||
writeTypeToTextWriter(getReturnTypeOfSignature(signature), enclosingDeclaration, flags , writer);
|
||||
}
|
||||
|
||||
function invokeEmitter() {
|
||||
function invokeEmitter(targetSourceFile?: SourceFile) {
|
||||
var resolver: EmitResolver = {
|
||||
getProgram: () => program,
|
||||
getLocalNameOfContainer: getLocalNameOfContainer,
|
||||
@@ -7317,7 +7315,7 @@ module ts {
|
||||
getNodeCheckFlags: getNodeCheckFlags,
|
||||
getEnumMemberValue: getEnumMemberValue,
|
||||
isTopLevelValueImportedViaEntityName: isTopLevelValueImportedViaEntityName,
|
||||
shouldEmitDeclarations: shouldEmitDeclarations,
|
||||
hasSemanticErrors: hasSemanticErrors,
|
||||
isDeclarationVisible: isDeclarationVisible,
|
||||
isImplementationOfOverload: isImplementationOfOverload,
|
||||
writeTypeAtLocation: writeTypeAtLocation,
|
||||
@@ -7327,7 +7325,7 @@ module ts {
|
||||
isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile
|
||||
};
|
||||
checkProgram();
|
||||
return emitFiles(resolver);
|
||||
return emitFiles(resolver, targetSourceFile);
|
||||
}
|
||||
|
||||
function initializeTypeChecker() {
|
||||
|
||||
@@ -407,7 +407,7 @@ module ts {
|
||||
return normalizedPathComponents(path, rootLength);
|
||||
}
|
||||
|
||||
export function getNormalizedPathFromPathCompoments(pathComponents: string[]) {
|
||||
export function getNormalizedPathFromPathComponents(pathComponents: string[]) {
|
||||
if (pathComponents && pathComponents.length) {
|
||||
return pathComponents[0] + pathComponents.slice(1).join(directorySeparator);
|
||||
}
|
||||
@@ -468,7 +468,7 @@ module ts {
|
||||
var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory);
|
||||
var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory);
|
||||
if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") {
|
||||
// If the directory path given was of type test/cases/ then we really need components of directry to be only till its name
|
||||
// If the directory path given was of type test/cases/ then we really need components of directory to be only till its name
|
||||
// that is ["test", "cases", ""] needs to be actually ["test", "cases"]
|
||||
directoryComponents.length--;
|
||||
}
|
||||
@@ -494,7 +494,7 @@ module ts {
|
||||
}
|
||||
|
||||
// Cant find the relative path, get the absolute path
|
||||
var absolutePath = getNormalizedPathFromPathCompoments(pathComponents);
|
||||
var absolutePath = getNormalizedPathFromPathComponents(pathComponents);
|
||||
if (isAbsolutePathAnUrl && isRootedDiskPath(absolutePath)) {
|
||||
absolutePath = "file:///" + absolutePath;
|
||||
}
|
||||
|
||||
+57
-29
@@ -25,7 +25,22 @@ module ts {
|
||||
return indentStrings[1].length;
|
||||
}
|
||||
|
||||
export function emitFiles(resolver: EmitResolver): EmitResult {
|
||||
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
|
||||
if (!(sourceFile.flags & NodeFlags.DeclarationFile)) {
|
||||
if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.filename, ".js")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) {
|
||||
return isExternalModule(sourceFile) || (sourceFile.flags & NodeFlags.DeclarationFile) !== 0;
|
||||
}
|
||||
|
||||
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature
|
||||
export function emitFiles(resolver: EmitResolver, targetSourceFile?: SourceFile): EmitResult {
|
||||
var program = resolver.getProgram();
|
||||
var compilerHost = program.getCompilerHost();
|
||||
var compilerOptions = program.getCompilerOptions();
|
||||
@@ -34,22 +49,14 @@ module ts {
|
||||
var newLine = program.getCompilerHost().getNewLine();
|
||||
|
||||
function getSourceFilePathInNewDir(newDirPath: string, sourceFile: SourceFile) {
|
||||
var sourceFilePath = getNormalizedPathFromPathCompoments(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory()));
|
||||
var sourceFilePath = getNormalizedPathFromPathComponents(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory()));
|
||||
sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
|
||||
return combinePaths(newDirPath, sourceFilePath);
|
||||
}
|
||||
|
||||
function shouldEmitToOwnFile(sourceFile: SourceFile) {
|
||||
if (!(sourceFile.flags & NodeFlags.DeclarationFile)) {
|
||||
if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.filename, ".js")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getOwnEmitOutputFilePath(sourceFile: SourceFile, extension: string) {
|
||||
if (program.getCompilerOptions().outDir) {
|
||||
var emitOutputFilePathWithoutExtension = getModuleNameFromFilename(getSourceFilePathInNewDir(program.getCompilerOptions().outDir, sourceFile));
|
||||
if (compilerOptions.outDir) {
|
||||
var emitOutputFilePathWithoutExtension = getModuleNameFromFilename(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile));
|
||||
}
|
||||
else {
|
||||
var emitOutputFilePathWithoutExtension = getModuleNameFromFilename(sourceFile.filename);
|
||||
@@ -58,10 +65,6 @@ module ts {
|
||||
return emitOutputFilePathWithoutExtension + extension;
|
||||
}
|
||||
|
||||
function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) {
|
||||
return isExternalModule(sourceFile) || (sourceFile.flags & NodeFlags.DeclarationFile) !== 0;
|
||||
}
|
||||
|
||||
function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration {
|
||||
return forEach(node.members, member => {
|
||||
if (member.kind === SyntaxKind.Constructor && (<ConstructorDeclaration>member).body) {
|
||||
@@ -1431,7 +1434,7 @@ module ts {
|
||||
|
||||
function emitParameterPropertyAssignments(node: ConstructorDeclaration) {
|
||||
forEach(node.parameters, param => {
|
||||
if (param.flags & (NodeFlags.Public | NodeFlags.Private)) {
|
||||
if (param.flags & NodeFlags.AccessibilityModifier) {
|
||||
writeLine();
|
||||
emitStart(param);
|
||||
emitStart(param.name);
|
||||
@@ -2630,7 +2633,7 @@ module ts {
|
||||
function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) {
|
||||
if (constructorDeclaration) {
|
||||
forEach(constructorDeclaration.parameters, param => {
|
||||
if (param.flags & (NodeFlags.Public | NodeFlags.Private)) {
|
||||
if (param.flags & NodeFlags.AccessibilityModifier) {
|
||||
emitPropertyDeclaration(param);
|
||||
}
|
||||
});
|
||||
@@ -3082,7 +3085,7 @@ module ts {
|
||||
function writeReferencePath(referencedFile: SourceFile) {
|
||||
var declFileName = referencedFile.flags & NodeFlags.DeclarationFile
|
||||
? referencedFile.filename // Declaration file, use declaration file name
|
||||
: shouldEmitToOwnFile(referencedFile)
|
||||
: shouldEmitToOwnFile(referencedFile, compilerOptions)
|
||||
? getOwnEmitOutputFilePath(referencedFile, ".d.ts") // Own output file so get the .d.ts file
|
||||
: getModuleNameFromFilename(compilerOptions.out) + ".d.ts";// Global out file
|
||||
|
||||
@@ -3104,7 +3107,7 @@ module ts {
|
||||
|
||||
// All the references that are not going to be part of same file
|
||||
if ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference
|
||||
shouldEmitToOwnFile(referencedFile) || // This is referenced file is emitting its own js file
|
||||
shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file
|
||||
!addedGlobalFileReference) { // Or the global out file corresponding to this reference was not added
|
||||
|
||||
writeReferencePath(referencedFile);
|
||||
@@ -3161,29 +3164,54 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
var shouldEmitDeclarations = resolver.shouldEmitDeclarations();
|
||||
var hasSemanticErrors = resolver.hasSemanticErrors();
|
||||
|
||||
function emitFile(jsFilePath: string, sourceFile?: SourceFile) {
|
||||
emitJavaScript(jsFilePath, sourceFile);
|
||||
if (shouldEmitDeclarations) {
|
||||
if (!hasSemanticErrors && compilerOptions.declaration) {
|
||||
emitDeclarations(jsFilePath, sourceFile);
|
||||
}
|
||||
}
|
||||
|
||||
forEach(program.getSourceFiles(), sourceFile => {
|
||||
if (shouldEmitToOwnFile(sourceFile)) {
|
||||
var jsFilePath = getOwnEmitOutputFilePath(sourceFile, ".js");
|
||||
emitFile(jsFilePath, sourceFile);
|
||||
}
|
||||
});
|
||||
if (targetSourceFile === undefined) {
|
||||
forEach(program.getSourceFiles(), sourceFile => {
|
||||
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
|
||||
var jsFilePath = getOwnEmitOutputFilePath(sourceFile, ".js");
|
||||
emitFile(jsFilePath, sourceFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Emit only one file specified in targetFilename. This is mainly used in compilerOnSave feature
|
||||
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
|
||||
emitFile(jsFilePath, targetSourceFile);
|
||||
}
|
||||
|
||||
if (compilerOptions.out) {
|
||||
emitFile(compilerOptions.out);
|
||||
}
|
||||
|
||||
|
||||
// Sort and make the unique list of diagnostics
|
||||
diagnostics.sort(compareDiagnostics);
|
||||
diagnostics = deduplicateSortedDiagnostics(diagnostics);
|
||||
|
||||
// Update returnCode if there is any EmitterError
|
||||
var hasEmitterError = forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error);
|
||||
|
||||
// Check and update returnCode for syntactic and semantic
|
||||
var returnCode: EmitReturnStatus;
|
||||
if (hasEmitterError) {
|
||||
returnCode = EmitReturnStatus.EmitErrorsEncountered;
|
||||
} else if (hasSemanticErrors && compilerOptions.declaration) {
|
||||
returnCode = EmitReturnStatus.DeclarationGenerationSkipped;
|
||||
} else if (hasSemanticErrors && !compilerOptions.declaration) {
|
||||
returnCode = EmitReturnStatus.JSGeneratedWithSemanticErrors;
|
||||
} else {
|
||||
returnCode = EmitReturnStatus.Succeeded;
|
||||
}
|
||||
|
||||
return {
|
||||
emitResultStatus: returnCode,
|
||||
errors: diagnostics,
|
||||
sourceMaps: sourceMapDataList
|
||||
};
|
||||
|
||||
+48
-26
@@ -1400,14 +1400,25 @@ module ts {
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseSignature(kind: SyntaxKind, returnToken: SyntaxKind): ParsedSignature {
|
||||
function parseSignature(kind: SyntaxKind, returnToken: SyntaxKind, returnTokenRequired: boolean): ParsedSignature {
|
||||
if (kind === SyntaxKind.ConstructSignature) {
|
||||
parseExpected(SyntaxKind.NewKeyword);
|
||||
}
|
||||
var typeParameters = parseTypeParameters();
|
||||
var parameters = parseParameterList(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken);
|
||||
checkParameterList(parameters);
|
||||
var type = parseOptional(returnToken) ? parseType() : undefined;
|
||||
|
||||
var type: TypeNode;
|
||||
|
||||
if (returnTokenRequired) {
|
||||
parseExpected(returnToken);
|
||||
type = parseType();
|
||||
}
|
||||
else if (parseOptional(returnToken))
|
||||
{
|
||||
type = parseType();
|
||||
}
|
||||
|
||||
return {
|
||||
typeParameters: typeParameters,
|
||||
parameters: parameters,
|
||||
@@ -1471,7 +1482,7 @@ module ts {
|
||||
|
||||
function parseSignatureMember(kind: SyntaxKind, returnToken: SyntaxKind): SignatureDeclaration {
|
||||
var node = <SignatureDeclaration>createNode(kind);
|
||||
var sig = parseSignature(kind, returnToken);
|
||||
var sig = parseSignature(kind, returnToken, /* returnTokenRequired */ false);
|
||||
node.typeParameters = sig.typeParameters;
|
||||
node.parameters = sig.parameters;
|
||||
node.type = sig.type;
|
||||
@@ -1544,7 +1555,7 @@ module ts {
|
||||
}
|
||||
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
|
||||
node.kind = SyntaxKind.Method;
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false);
|
||||
(<MethodDeclaration>node).typeParameters = sig.typeParameters;
|
||||
(<MethodDeclaration>node).parameters = sig.parameters;
|
||||
(<MethodDeclaration>node).type = sig.type;
|
||||
@@ -1616,7 +1627,7 @@ module ts {
|
||||
function parseFunctionType(signatureKind: SyntaxKind): TypeLiteralNode {
|
||||
var node = <TypeLiteralNode>createNode(SyntaxKind.TypeLiteral);
|
||||
var member = <SignatureDeclaration>createNode(signatureKind);
|
||||
var sig = parseSignature(signatureKind, SyntaxKind.EqualsGreaterThanToken);
|
||||
var sig = parseSignature(signatureKind, SyntaxKind.EqualsGreaterThanToken, /* returnTokenRequired */ true);
|
||||
member.typeParameters = sig.typeParameters;
|
||||
member.parameters = sig.parameters;
|
||||
member.type = sig.type;
|
||||
@@ -1875,7 +1886,7 @@ module ts {
|
||||
var pos = getNodePos();
|
||||
|
||||
if (triState === Tristate.True) {
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false);
|
||||
|
||||
// If we have an arrow, then try to parse the body.
|
||||
// Even if not, try to parse if we have an opening brace, just in case we're in an error state.
|
||||
@@ -1978,7 +1989,7 @@ module ts {
|
||||
|
||||
function tryParseSignatureIfArrowOrBraceFollows(): ParsedSignature {
|
||||
return tryParse(() => {
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false);
|
||||
|
||||
// Parsing a signature isn't enough.
|
||||
// Parenthesized arrow signatures often look like other valid expressions.
|
||||
@@ -2320,7 +2331,7 @@ module ts {
|
||||
var node = <PropertyDeclaration>createNode(SyntaxKind.PropertyAssignment);
|
||||
node.name = parsePropertyName();
|
||||
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false);
|
||||
var body = parseBody(/* ignoreMissingOpenBrace */ false);
|
||||
// do not propagate property name as name for function expression
|
||||
// for scenarios like
|
||||
@@ -2420,7 +2431,7 @@ module ts {
|
||||
var pos = getNodePos();
|
||||
parseExpected(SyntaxKind.FunctionKeyword);
|
||||
var name = isIdentifier() ? parseIdentifier() : undefined;
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false);
|
||||
var body = parseBody(/* ignoreMissingOpenBrace */ false);
|
||||
if (name && isInStrictMode && isEvalOrArgumentsIdentifier(name)) {
|
||||
// It is a SyntaxError to use within strict mode code the identifiers eval or arguments as the
|
||||
@@ -3035,7 +3046,7 @@ module ts {
|
||||
if (flags) node.flags = flags;
|
||||
parseExpected(SyntaxKind.FunctionKeyword);
|
||||
node.name = parseIdentifier();
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false);
|
||||
node.typeParameters = sig.typeParameters;
|
||||
node.parameters = sig.parameters;
|
||||
node.type = sig.type;
|
||||
@@ -3052,7 +3063,7 @@ module ts {
|
||||
var node = <ConstructorDeclaration>createNode(SyntaxKind.Constructor, pos);
|
||||
node.flags = flags;
|
||||
parseExpected(SyntaxKind.ConstructorKeyword);
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false);
|
||||
node.typeParameters = sig.typeParameters;
|
||||
node.parameters = sig.parameters;
|
||||
node.type = sig.type;
|
||||
@@ -3079,7 +3090,7 @@ module ts {
|
||||
var method = <MethodDeclaration>createNode(SyntaxKind.Method, pos);
|
||||
method.flags = flags;
|
||||
method.name = name;
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false);
|
||||
method.typeParameters = sig.typeParameters;
|
||||
method.parameters = sig.parameters;
|
||||
method.type = sig.type;
|
||||
@@ -3152,7 +3163,7 @@ module ts {
|
||||
var node = <MethodDeclaration>createNode(kind, pos);
|
||||
node.flags = flags;
|
||||
node.name = parsePropertyName();
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false);
|
||||
node.typeParameters = sig.typeParameters;
|
||||
node.parameters = sig.parameters;
|
||||
node.type = sig.type;
|
||||
@@ -3239,7 +3250,7 @@ module ts {
|
||||
|
||||
switch (modifierToken) {
|
||||
case SyntaxKind.PublicKeyword:
|
||||
if (flags & NodeFlags.Private || flags & NodeFlags.Public) {
|
||||
if (flags & NodeFlags.AccessibilityModifier) {
|
||||
grammarErrorAtPos(modifierStart, modifierLength, Diagnostics.Accessibility_modifier_already_seen);
|
||||
}
|
||||
else if (flags & NodeFlags.Static) {
|
||||
@@ -3252,7 +3263,7 @@ module ts {
|
||||
break;
|
||||
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
if (flags & NodeFlags.Private || flags & NodeFlags.Public) {
|
||||
if (flags & NodeFlags.AccessibilityModifier) {
|
||||
grammarErrorAtPos(modifierStart, modifierLength, Diagnostics.Accessibility_modifier_already_seen);
|
||||
}
|
||||
else if (flags & NodeFlags.Static) {
|
||||
@@ -3822,17 +3833,28 @@ module ts {
|
||||
var start = refPos;
|
||||
var length = refEnd - refPos;
|
||||
}
|
||||
var diagnostic: DiagnosticMessage;
|
||||
if (hasExtension(filename)) {
|
||||
if (!fileExtensionIs(filename, ".ts")) {
|
||||
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_must_have_extension_ts_or_d_ts, filename));
|
||||
diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts;
|
||||
}
|
||||
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
|
||||
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_not_found, filename));
|
||||
diagnostic = Diagnostics.File_0_not_found;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) {
|
||||
errors.push(createFileDiagnostic(refFile, start, length, Diagnostics.File_0_not_found, filename + ".ts"));
|
||||
diagnostic = Diagnostics.File_0_not_found;
|
||||
filename += ".ts";
|
||||
}
|
||||
}
|
||||
|
||||
if (diagnostic) {
|
||||
if (refFile) {
|
||||
errors.push(createFileDiagnostic(refFile, start, length, diagnostic, filename));
|
||||
}
|
||||
else {
|
||||
errors.push(createCompilerDiagnostic(diagnostic, filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3965,11 +3987,11 @@ module ts {
|
||||
// Each file contributes into common source file path
|
||||
if (!(sourceFile.flags & NodeFlags.DeclarationFile)
|
||||
&& !fileExtensionIs(sourceFile.filename, ".js")) {
|
||||
var sourcePathCompoments = getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory());
|
||||
sourcePathCompoments.pop(); // FileName is not part of directory
|
||||
var sourcePathComponents = getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory());
|
||||
sourcePathComponents.pop(); // FileName is not part of directory
|
||||
if (commonPathComponents) {
|
||||
for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathCompoments.length); i++) {
|
||||
if (commonPathComponents[i] !== sourcePathCompoments[i]) {
|
||||
for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) {
|
||||
if (commonPathComponents[i] !== sourcePathComponents[i]) {
|
||||
if (i === 0) {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
|
||||
return;
|
||||
@@ -3982,18 +4004,18 @@ module ts {
|
||||
}
|
||||
|
||||
// If the fileComponent path completely matched and less than already found update the length
|
||||
if (sourcePathCompoments.length < commonPathComponents.length) {
|
||||
commonPathComponents.length = sourcePathCompoments.length;
|
||||
if (sourcePathComponents.length < commonPathComponents.length) {
|
||||
commonPathComponents.length = sourcePathComponents.length;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// first file
|
||||
commonPathComponents = sourcePathCompoments;
|
||||
commonPathComponents = sourcePathComponents;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
commonSourceDirectory = getNormalizedPathFromPathCompoments(commonPathComponents);
|
||||
commonSourceDirectory = getNormalizedPathFromPathComponents(commonPathComponents);
|
||||
if (commonSourceDirectory) {
|
||||
// Make sure directory path ends with directory separator so this string can directly
|
||||
// used to replace with "" to get the relative path of the source file and the relative path doesn't
|
||||
|
||||
+15
-4
@@ -239,7 +239,8 @@ module ts {
|
||||
Synthetic = 0x00000100, // Synthetic node (for full fidelity)
|
||||
DeclarationFile = 0x00000200, // Node is a .d.ts file
|
||||
|
||||
Modifier = Export | Ambient | Public | Private | Static
|
||||
Modifier = Export | Ambient | Public | Private | Static,
|
||||
AccessibilityModifier = Public | Private
|
||||
}
|
||||
|
||||
export interface Node extends TextRange {
|
||||
@@ -576,7 +577,7 @@ module ts {
|
||||
export interface SourceMapData {
|
||||
/** Where the sourcemap file is written */
|
||||
sourceMapFilePath: string;
|
||||
/** source map url written in the js file */
|
||||
/** source map URL written in the js file */
|
||||
jsSourceMappingURL: string;
|
||||
/** Source map's file field - js file name*/
|
||||
sourceMapFile: string;
|
||||
@@ -595,7 +596,17 @@ module ts {
|
||||
sourceMapDecodedMappings: SourceMapSpan[];
|
||||
}
|
||||
|
||||
// Return code used by getEmitOutput function to indicate status of the function
|
||||
export enum EmitReturnStatus {
|
||||
Succeeded = 0, // All outputs generated as requested (.js, .map, .d.ts), no errors reported
|
||||
AllOutputGenerationSkipped = 1, // No .js generated because of syntax errors, or compiler options errors, nothing generated
|
||||
JSGeneratedWithSemanticErrors = 2, // .js and .map generated with semantic errors
|
||||
DeclarationGenerationSkipped = 3, // .d.ts generation skipped because of semantic errors or declaration emitter specific errors; Output .js with semantic errors
|
||||
EmitErrorsEncountered = 4 // Emitter errors occurred during emitting process
|
||||
}
|
||||
|
||||
export interface EmitResult {
|
||||
emitResultStatus: EmitReturnStatus;
|
||||
errors: Diagnostic[];
|
||||
sourceMaps: SourceMapData[]; // Array of sourceMapData if compiler emitted sourcemaps
|
||||
}
|
||||
@@ -609,7 +620,7 @@ module ts {
|
||||
getSymbolCount(): number;
|
||||
getTypeCount(): number;
|
||||
checkProgram(): void;
|
||||
emitFiles(): EmitResult;
|
||||
emitFiles(targetSourceFile?: SourceFile): EmitResult;
|
||||
getParentOfSymbol(symbol: Symbol): Symbol;
|
||||
getTypeOfSymbol(symbol: Symbol): Type;
|
||||
getPropertiesOfType(type: Type): Symbol[];
|
||||
@@ -668,7 +679,7 @@ module ts {
|
||||
isTopLevelValueImportedViaEntityName(node: ImportDeclaration): boolean;
|
||||
getNodeCheckFlags(node: Node): NodeCheckFlags;
|
||||
getEnumMemberValue(node: EnumMember): number;
|
||||
shouldEmitDeclarations(): boolean;
|
||||
hasSemanticErrors(): boolean;
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
isImplementationOfOverload(node: FunctionDeclaration): boolean;
|
||||
writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void;
|
||||
|
||||
@@ -156,10 +156,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
return file.writeByteOrderMark ? "\u00EF\u00BB\u00BF" : "";
|
||||
}
|
||||
|
||||
function getErrorBaseline(toBeCompiled: { unitName: string; content: string }[],
|
||||
otherFiles: { unitName: string; content: string }[],
|
||||
result: Harness.Compiler.CompilerResult
|
||||
) {
|
||||
function getErrorBaseline(toBeCompiled: { unitName: string; content: string }[], otherFiles: { unitName: string; content: string }[], result: Harness.Compiler.CompilerResult) {
|
||||
return Harness.Compiler.getErrorBaseline(toBeCompiled.concat(otherFiles), result.errors);
|
||||
}
|
||||
|
||||
@@ -168,7 +165,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
if (this.errors) {
|
||||
Harness.Baseline.runBaseline('Correct errors for ' + fileName, justName.replace(/\.ts$/, '.errors.txt'), (): string => {
|
||||
if (result.errors.length === 0) return null;
|
||||
|
||||
|
||||
return getErrorBaseline(toBeCompiled, otherFiles, result);
|
||||
});
|
||||
}
|
||||
|
||||
+132
-17
@@ -122,9 +122,71 @@ module FourSlash {
|
||||
return s.replace(/[&<>"'\/]/g, ch => entityMap[ch]);
|
||||
}
|
||||
|
||||
// Name of testcase metadata including ts.CompilerOptions properties that will be used by globalOptions
|
||||
// To add additional option, add property into the testOptMetadataNames, refer the property in either globalMetadataNames or fileMetadataNames
|
||||
// Add cases into convertGlobalOptionsToCompilationsSettings function for the compiler to acknowledge such option from meta data
|
||||
var testOptMetadataNames = {
|
||||
baselineFile: 'BaselineFile',
|
||||
declaration: 'declaration',
|
||||
emitThisFile: 'emitThisFile', // This flag is used for testing getEmitOutput feature. It allows test-cases to indicate what file to be output in multiple files project
|
||||
filename: 'Filename',
|
||||
mapRoot: 'mapRoot',
|
||||
module: 'module',
|
||||
out: 'out',
|
||||
outDir: 'outDir',
|
||||
sourceMap: 'sourceMap',
|
||||
sourceRoot: 'sourceRoot',
|
||||
};
|
||||
|
||||
// List of allowed metadata names
|
||||
var fileMetadataNames = ['Filename'];
|
||||
var globalMetadataNames = ['Module', 'Target', 'BaselineFile']; // Note: Only BaselineFile is actually supported at the moment
|
||||
var fileMetadataNames = [testOptMetadataNames.filename, testOptMetadataNames.emitThisFile];
|
||||
var globalMetadataNames = [testOptMetadataNames.baselineFile, testOptMetadataNames.declaration,
|
||||
testOptMetadataNames.mapRoot, testOptMetadataNames.module, testOptMetadataNames.out,
|
||||
testOptMetadataNames.outDir, testOptMetadataNames.sourceMap, testOptMetadataNames.sourceRoot]
|
||||
|
||||
function convertGlobalOptionsToCompilationSettings(globalOptions: { [idx: string]: string }): ts.CompilationSettings {
|
||||
var settings: ts.CompilationSettings = {};
|
||||
// Convert all property in globalOptions into ts.CompilationSettings
|
||||
for (var prop in globalOptions) {
|
||||
if (globalOptions.hasOwnProperty(prop)) {
|
||||
switch (prop) {
|
||||
case testOptMetadataNames.declaration:
|
||||
settings.generateDeclarationFiles = true;
|
||||
break;
|
||||
case testOptMetadataNames.mapRoot:
|
||||
settings.mapRoot = globalOptions[prop];
|
||||
break;
|
||||
case testOptMetadataNames.module:
|
||||
// create appropriate external module target for CompilationSettings
|
||||
switch (globalOptions[prop]) {
|
||||
case "AMD":
|
||||
settings.moduleGenTarget = ts.ModuleGenTarget.Asynchronous;
|
||||
break;
|
||||
case "CommonJS":
|
||||
settings.moduleGenTarget = ts.ModuleGenTarget.Synchronous;
|
||||
break;
|
||||
default:
|
||||
settings.moduleGenTarget = ts.ModuleGenTarget.Unspecified;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case testOptMetadataNames.out:
|
||||
settings.outFileOption = globalOptions[prop];
|
||||
break;
|
||||
case testOptMetadataNames.outDir:
|
||||
settings.outDirOption = globalOptions[prop];
|
||||
break;
|
||||
case testOptMetadataNames.sourceMap:
|
||||
settings.mapSourceFiles = true;
|
||||
break;
|
||||
case testOptMetadataNames.sourceRoot:
|
||||
settings.sourceRoot = globalOptions[prop];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
export var currentTestState: TestState = null;
|
||||
|
||||
@@ -199,11 +261,15 @@ module FourSlash {
|
||||
private scenarioActions: string[] = [];
|
||||
private taoInvalidReason: string = null;
|
||||
|
||||
|
||||
constructor(public testData: FourSlashData) {
|
||||
// Initialize the language service with all the scripts
|
||||
this.cancellationToken = new TestCancellationToken();
|
||||
this.languageServiceShimHost = new Harness.LanguageService.TypeScriptLS(this.cancellationToken);
|
||||
|
||||
var compilationSettings = convertGlobalOptionsToCompilationSettings(this.testData.globalOptions);
|
||||
this.languageServiceShimHost.setCompilationSettings(compilationSettings);
|
||||
|
||||
var inputFiles: { unitName: string; content: string }[] = [];
|
||||
|
||||
testData.files.forEach(file => {
|
||||
@@ -220,9 +286,9 @@ module FourSlash {
|
||||
//if (/require\(/.test(lastFile.content) || /reference\spath/.test(lastFile.content)) {
|
||||
// inputFiles.push({ unitName: lastFile.fileName, content: lastFile.content });
|
||||
//} else {
|
||||
inputFiles = testData.files.map(file => {
|
||||
return { unitName: file.fileName, content: file.content };
|
||||
});
|
||||
inputFiles = testData.files.map(file => {
|
||||
return { unitName: file.fileName, content: file.content };
|
||||
});
|
||||
//}
|
||||
|
||||
|
||||
@@ -914,7 +980,7 @@ module FourSlash {
|
||||
|
||||
Harness.Baseline.runBaseline(
|
||||
"Breakpoint Locations for " + this.activeFile.fileName,
|
||||
this.testData.globalOptions['BaselineFile'],
|
||||
this.testData.globalOptions[testOptMetadataNames.baselineFile],
|
||||
() => {
|
||||
var fileLength = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getLength();
|
||||
var resultString = "";
|
||||
@@ -926,6 +992,48 @@ module FourSlash {
|
||||
true /* run immediately */);
|
||||
}
|
||||
|
||||
public baselineGetEmitOutput() {
|
||||
this.taoInvalidReason = 'baselineGetEmitOutput impossible';
|
||||
// Find file to be emitted
|
||||
var emitFiles: FourSlashFile[] = []; // List of FourSlashFile that has emitThisFile flag on
|
||||
|
||||
var allFourSlashFiles = this.testData.files;
|
||||
for (var idx = 0; idx < allFourSlashFiles.length; ++idx) {
|
||||
var file = allFourSlashFiles[idx];
|
||||
if (file.fileOptions[testOptMetadataNames.emitThisFile]) {
|
||||
// Find a file with the flag emitThisFile turned on
|
||||
emitFiles.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
// If there is not emiThisFile flag specified in the test file, throw an error
|
||||
if (emitFiles.length === 0) {
|
||||
throw new Error("No emitThisFile is specified in the test file");
|
||||
}
|
||||
|
||||
Harness.Baseline.runBaseline(
|
||||
"Generate getEmitOutput baseline : " + emitFiles.join(" "),
|
||||
this.testData.globalOptions[testOptMetadataNames.baselineFile],
|
||||
() => {
|
||||
var resultString = "";
|
||||
// Loop through all the emittedFiles and emit them one by one
|
||||
emitFiles.forEach(emitFile => {
|
||||
var emitOutput = this.languageService.getEmitOutput(emitFile.fileName);
|
||||
var emitOutputStatus = emitOutput.emitOutputStatus;
|
||||
// Print emitOutputStatus in readable format
|
||||
resultString += "EmitOutputStatus : " + ts.EmitReturnStatus[emitOutputStatus];
|
||||
resultString += "\n";
|
||||
emitOutput.outputFiles.forEach((outputFile, idx, array) => {
|
||||
var filename = "Filename : " + outputFile.name + "\n";
|
||||
resultString = resultString + filename + outputFile.text;
|
||||
});
|
||||
resultString += "\n";
|
||||
});
|
||||
return resultString;
|
||||
},
|
||||
true /* run immediately */);
|
||||
}
|
||||
|
||||
public printBreakpointLocation(pos: number) {
|
||||
Harness.IO.log(this.getBreakpointStatementLocation(pos));
|
||||
}
|
||||
@@ -1236,7 +1344,7 @@ module FourSlash {
|
||||
|
||||
private applyEdits(fileName: string, edits: ts.TextChange[], isFormattingEdit = false): number {
|
||||
// We get back a set of edits, but langSvc.editScript only accepts one at a time. Use this to keep track
|
||||
// of the incremental offest from each edit to the next. Assumption is that these edit ranges don't overlap
|
||||
// of the incremental offset from each edit to the next. Assumption is that these edit ranges don't overlap
|
||||
var runningOffset = 0;
|
||||
edits = edits.sort((a, b) => a.span.start() - b.span.start());
|
||||
// Get a snapshot of the content of the file so we can make sure any formatting edits didn't destroy non-whitespace characters
|
||||
@@ -1313,7 +1421,7 @@ module FourSlash {
|
||||
|
||||
var definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition);
|
||||
if (!definitions || !definitions.length) {
|
||||
throw new Error('goToDefinition failed - expected to at least one defintion location but got 0');
|
||||
throw new Error('goToDefinition failed - expected to at least one definition location but got 0');
|
||||
}
|
||||
|
||||
if (definitionIndex >= definitions.length) {
|
||||
@@ -1333,10 +1441,10 @@ module FourSlash {
|
||||
var foundDefinitions = definitions && definitions.length;
|
||||
|
||||
if (foundDefinitions && negative) {
|
||||
throw new Error('goToDefinition - expected to 0 defintion locations but got ' + definitions.length);
|
||||
throw new Error('goToDefinition - expected to 0 definition locations but got ' + definitions.length);
|
||||
}
|
||||
else if (!foundDefinitions && !negative) {
|
||||
throw new Error('goToDefinition - expected to at least one defintion location but got 0');
|
||||
throw new Error('goToDefinition - expected to at least one definition location but got 0');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1450,7 +1558,7 @@ module FourSlash {
|
||||
|
||||
Harness.Baseline.runBaseline(
|
||||
"Name OrDottedNameSpans for " + this.activeFile.fileName,
|
||||
this.testData.globalOptions['BaselineFile'],
|
||||
this.testData.globalOptions[testOptMetadataNames.baselineFile],
|
||||
() => {
|
||||
var fileLength = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getLength();
|
||||
var resultString = "";
|
||||
@@ -2091,12 +2199,12 @@ module FourSlash {
|
||||
// Comment line, check for global/file @options and record them
|
||||
var match = optionRegex.exec(line.substr(2));
|
||||
if (match) {
|
||||
var globalNameIndex = globalMetadataNames.indexOf(match[1]);
|
||||
var fileNameIndex = fileMetadataNames.indexOf(match[1]);
|
||||
if (globalNameIndex === -1) {
|
||||
if (fileNameIndex === -1) {
|
||||
var globalMetadataNamesIndex = globalMetadataNames.indexOf(match[1]);
|
||||
var fileMetadataNamesIndex = fileMetadataNames.indexOf(match[1]);
|
||||
if (globalMetadataNamesIndex === -1) {
|
||||
if (fileMetadataNamesIndex === -1) {
|
||||
throw new Error('Unrecognized metadata name "' + match[1] + '". Available global metadata names are: ' + globalMetadataNames.join(', ') + '; file metadata names are: ' + fileMetadataNames.join(', '));
|
||||
} else {
|
||||
} else if (fileMetadataNamesIndex === fileMetadataNames.indexOf(testOptMetadataNames.filename)) {
|
||||
// Found an @Filename directive, if this is not the first then create a new subfile
|
||||
if (currentFileContent) {
|
||||
var file = parseFileContent(currentFileContent, currentFileName, markerMap, markers, ranges);
|
||||
@@ -2113,8 +2221,15 @@ module FourSlash {
|
||||
|
||||
currentFileName = 'tests/cases/fourslash/' + match[2];
|
||||
currentFileOptions[match[1]] = match[2];
|
||||
} else {
|
||||
// Add other fileMetadata flag
|
||||
currentFileOptions[match[1]] = match[2];
|
||||
}
|
||||
} else {
|
||||
// Check if the match is already existed in the global options
|
||||
if (opts[match[1]] !== undefined) {
|
||||
throw new Error("Global Option : '" + match[1] + "' is already existed");
|
||||
}
|
||||
opts[match[1]] = match[2];
|
||||
}
|
||||
}
|
||||
@@ -2224,7 +2339,7 @@ module FourSlash {
|
||||
/// A list of ranges we've collected so far */
|
||||
var localRanges: Range[] = [];
|
||||
|
||||
/// The latest position of the start of an unflushed plaintext area
|
||||
/// The latest position of the start of an unflushed plain text area
|
||||
var lastNormalCharPosition: number = 0;
|
||||
|
||||
/// The total number of metacharacters removed from the file (so far)
|
||||
|
||||
@@ -807,9 +807,7 @@ module Harness {
|
||||
return errorOutput;
|
||||
}
|
||||
|
||||
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[],
|
||||
diagnostics: HarnessDiagnostic[]
|
||||
) {
|
||||
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: HarnessDiagnostic[]) {
|
||||
|
||||
var outputLines: string[] = [];
|
||||
// Count up all the errors we find so we don't miss any
|
||||
@@ -820,13 +818,13 @@ module Harness {
|
||||
.split('\n')
|
||||
.map(s => s.length > 0 && s.charAt(s.length - 1) === '\r' ? s.substr(0, s.length - 1) : s)
|
||||
.filter(s => s.length > 0)
|
||||
.map(s => '!!! ' + s);
|
||||
.map(s => '!!! ' + error.category + " TS" + error.code + ": " + s);
|
||||
errLines.forEach(e => outputLines.push(e));
|
||||
|
||||
totalErrorsReported++;
|
||||
}
|
||||
|
||||
// Report glovbal errors:
|
||||
// Report global errors
|
||||
var globalErrors = diagnostics.filter(err => !err.filename);
|
||||
globalErrors.forEach(err => outputErrorText(err));
|
||||
|
||||
@@ -896,7 +894,8 @@ module Harness {
|
||||
// Verify we didn't miss any errors in total
|
||||
assert.equal(totalErrorsReported, diagnostics.length, 'total number of errors');
|
||||
|
||||
return outputLines.join('\r\n');
|
||||
return minimalDiagnosticsToString(diagnostics) +
|
||||
sys.newLine + sys.newLine + outputLines.join('\r\n');
|
||||
}
|
||||
|
||||
/* TODO: Delete?
|
||||
@@ -917,7 +916,7 @@ module Harness {
|
||||
export function recreate(options?: { useMinimalDefaultLib: boolean; noImplicitAny: boolean; }) {
|
||||
}
|
||||
|
||||
/** The harness' compiler instance used when tests are actually run. Reseting or changing settings of this compiler instance must be done within a testcase (i.e., describe/it) */
|
||||
/** The harness' compiler instance used when tests are actually run. Reseting or changing settings of this compiler instance must be done within a test case (i.e., describe/it) */
|
||||
var harnessCompiler: HarnessCompiler;
|
||||
|
||||
/** Returns the singleton harness compiler instance for generating and running tests.
|
||||
@@ -1016,7 +1015,7 @@ module Harness {
|
||||
}
|
||||
|
||||
export module TestCaseParser {
|
||||
/** all the necesarry information to set the right compiler settings */
|
||||
/** all the necessary information to set the right compiler settings */
|
||||
export interface CompilerSetting {
|
||||
flag: string;
|
||||
value: string;
|
||||
|
||||
@@ -134,6 +134,7 @@ module Harness.LanguageService {
|
||||
private ls: ts.LanguageServiceShim = null;
|
||||
|
||||
private fileNameToScript: ts.Map<ScriptInfo> = {};
|
||||
private settings: ts.CompilationSettings = {};
|
||||
|
||||
constructor(private cancellationToken: ts.CancellationToken = CancellationToken.None) {
|
||||
}
|
||||
@@ -199,13 +200,21 @@ module Harness.LanguageService {
|
||||
|
||||
/// Returns json for Tools.CompilationSettings
|
||||
public getCompilationSettings(): string {
|
||||
return JSON.stringify({}); // i.e. default settings
|
||||
return JSON.stringify(this.settings);
|
||||
}
|
||||
|
||||
public getCancellationToken(): ts.CancellationToken {
|
||||
return this.cancellationToken;
|
||||
}
|
||||
|
||||
public getCurrentDirectory(): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
public getDefaultLibFilename(): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
public getScriptFileNames(): string {
|
||||
var fileNames: string[] = [];
|
||||
ts.forEachKey(this.fileNameToScript, (fileName) => { fileNames.push(fileName); });
|
||||
@@ -236,6 +245,14 @@ module Harness.LanguageService {
|
||||
return this.ls;
|
||||
}
|
||||
|
||||
public setCompilationSettings(settings: ts.CompilationSettings) {
|
||||
for (var key in settings) {
|
||||
if (settings.hasOwnProperty(key)) {
|
||||
this.settings[key] = settings[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Return a new instance of the classifier service shim */
|
||||
public getClassifier(): ts.ClassifierShim {
|
||||
return new TypeScript.Services.TypeScriptServicesFactory().createClassifierShim(this);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// Test case is json of below type in tests/cases/project/
|
||||
interface ProjectRunnerTestCase {
|
||||
scenario: string;
|
||||
projectRoot: string; // project where it lives - this also is the current dictory when compiling
|
||||
projectRoot: string; // project where it lives - this also is the current directory when compiling
|
||||
inputFiles: string[]; // list of input files to be given to program
|
||||
out?: string; // --out
|
||||
outDir?: string; // --outDir
|
||||
@@ -22,7 +22,7 @@ interface ProjectRunnerTestCase {
|
||||
interface ProjectRunnerTestCaseResolutionInfo extends ProjectRunnerTestCase {
|
||||
// Apart from actual test case the results of the resolution
|
||||
resolvedInputFiles: string[]; // List of files that were asked to read by compiler
|
||||
emittedFiles: string[]; // List of files that wre emitted by the compiler
|
||||
emittedFiles: string[]; // List of files that were emitted by the compiler
|
||||
}
|
||||
|
||||
interface BatchCompileProjectTestCaseEmittedFile extends Harness.Compiler.GeneratedFile {
|
||||
@@ -69,7 +69,7 @@ class ProjectRunner extends RunnerBase {
|
||||
testCase = <ProjectRunnerTestCase>JSON.parse(testFileText);
|
||||
}
|
||||
catch (e) {
|
||||
assert(false, "Testcase: " + testCaseFileName + " doesnt not contain valid json format: " + e.message);
|
||||
assert(false, "Testcase: " + testCaseFileName + " does not contain valid json format: " + e.message);
|
||||
}
|
||||
var testCaseJustName = testCaseFileName.replace(/^.*[\\\/]/, '').replace(/\.json/, "");
|
||||
|
||||
@@ -87,7 +87,7 @@ class ProjectRunner extends RunnerBase {
|
||||
}
|
||||
|
||||
// When test case output goes to tests/baselines/local/projectOutput/testCaseName/moduleKind/
|
||||
// We have these two separate locations because when compairing baselines the baseline verifier will delete the existing file
|
||||
// We have these two separate locations because when comparing baselines the baseline verifier will delete the existing file
|
||||
// so even if it was created by compiler in that location, the file will be deleted by verified before we can read it
|
||||
// so lets keep these two locations separate
|
||||
function getProjectOutputFolder(filename: string, moduleKind: ts.ModuleKind) {
|
||||
@@ -228,7 +228,7 @@ class ProjectRunner extends RunnerBase {
|
||||
|
||||
var diskRelativeName = ts.getRelativePathToDirectoryOrUrl(testCase.projectRoot, diskFileName, getCurrentDirectory(), false);
|
||||
if (ts.isRootedDiskPath(diskRelativeName) || diskRelativeName.substr(0, 3) === "../") {
|
||||
// If the generated output file recides in the parent folder or is rooted path,
|
||||
// If the generated output file resides in the parent folder or is rooted path,
|
||||
// we need to instead create files that can live in the project reference folder
|
||||
// but make sure extension of these files matches with the filename the compiler asked to write
|
||||
diskRelativeName = "diskFile" + nonSubfolderDiskFiles++ +
|
||||
@@ -299,13 +299,11 @@ class ProjectRunner extends RunnerBase {
|
||||
return { unitName: sourceFile.filename, content: sourceFile.text };
|
||||
});
|
||||
var diagnostics = ts.map(compilerResult.errors, error => Harness.Compiler.getMinimalDiagnostic(error));
|
||||
var errors = Harness.Compiler.minimalDiagnosticsToString(diagnostics);
|
||||
errors += sys.newLine + sys.newLine + Harness.Compiler.getErrorBaseline(inputFiles, diagnostics);
|
||||
|
||||
return errors;
|
||||
return Harness.Compiler.getErrorBaseline(inputFiles, diagnostics);
|
||||
}
|
||||
|
||||
describe('Compiling project for ' + testCase.scenario +': testcase ' + testCaseFileName, () => {
|
||||
describe('Compiling project for ' + testCase.scenario + ': testcase ' + testCaseFileName, () => {
|
||||
function verifyCompilerResults(compilerResult: BatchCompileProjectTestCaseResult) {
|
||||
function getCompilerResolutionInfo() {
|
||||
var resolutionInfo: ProjectRunnerTestCaseResolutionInfo = {
|
||||
|
||||
@@ -152,9 +152,7 @@ module RWC {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Harness.Compiler.minimalDiagnosticsToString(compilerResult.errors) +
|
||||
sys.newLine + sys.newLine +
|
||||
Harness.Compiler.getErrorBaseline(inputFiles.concat(otherFiles), compilerResult.errors);
|
||||
return Harness.Compiler.getErrorBaseline(inputFiles.concat(otherFiles), compilerResult.errors);
|
||||
}, false, baselineOpts);
|
||||
});
|
||||
|
||||
|
||||
@@ -798,7 +798,6 @@ module TypeScript.Services.Breakpoints {
|
||||
var container = Syntax.containingNode(varDeclarationNode);
|
||||
var varDeclarationSyntax = <TypeScript.VariableDeclarationSyntax>varDeclarationNode;
|
||||
var varDeclarators = varDeclarationSyntax.variableDeclarators;
|
||||
var varDeclaratorsCount = childCount(varDeclarators); // varDeclarators has to be non null because its checked in canHaveBreakpoint
|
||||
|
||||
if (container && container.kind() == TypeScript.SyntaxKind.VariableStatement) {
|
||||
return this.breakpointSpanOfVariableStatement(container);
|
||||
|
||||
+259
-36
@@ -71,6 +71,7 @@ module ts {
|
||||
getSourceUnit(): TypeScript.SourceUnitSyntax;
|
||||
getSyntaxTree(): TypeScript.SyntaxTree;
|
||||
getScriptSnapshot(): TypeScript.IScriptSnapshot;
|
||||
getNamedDeclarations(): Declaration[];
|
||||
update(scriptSnapshot: TypeScript.IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TypeScript.TextChangeRange): SourceFile;
|
||||
}
|
||||
|
||||
@@ -327,6 +328,7 @@ module ts {
|
||||
|
||||
private syntaxTree: TypeScript.SyntaxTree;
|
||||
private scriptSnapshot: TypeScript.IScriptSnapshot;
|
||||
private namedDeclarations: Declaration[];
|
||||
|
||||
public getSourceUnit(): TypeScript.SourceUnitSyntax {
|
||||
// If we don't have a script, create one from our parse tree.
|
||||
@@ -341,6 +343,59 @@ module ts {
|
||||
return this.getSyntaxTree().lineMap();
|
||||
}
|
||||
|
||||
public getNamedDeclarations() {
|
||||
if (!this.namedDeclarations) {
|
||||
var sourceFile = this;
|
||||
var namedDeclarations: Declaration[] = [];
|
||||
var isExternalModule = ts.isExternalModule(sourceFile);
|
||||
|
||||
forEachChild(sourceFile, function visit(node: Node): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
case SyntaxKind.Method:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.TypeLiteral:
|
||||
if ((<Declaration>node).name) {
|
||||
namedDeclarations.push(<Declaration>node);
|
||||
}
|
||||
forEachChild(node, visit);
|
||||
break;
|
||||
|
||||
case SyntaxKind.VariableStatement:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.FunctionBlock:
|
||||
forEachChild(node, visit);
|
||||
break;
|
||||
|
||||
case SyntaxKind.Parameter:
|
||||
if (!(node.flags & NodeFlags.AccessibilityModifier)) {
|
||||
// Only consider properties defined as constructor parameters
|
||||
break;
|
||||
}
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.Property:
|
||||
namedDeclarations.push(<Declaration>node);
|
||||
break;
|
||||
}
|
||||
|
||||
// do not go any deeper
|
||||
return undefined;
|
||||
});
|
||||
|
||||
this.namedDeclarations = namedDeclarations;
|
||||
}
|
||||
|
||||
return this.namedDeclarations;
|
||||
}
|
||||
|
||||
public getSyntaxTree(): TypeScript.SyntaxTree {
|
||||
if (!this.syntaxTree) {
|
||||
var start = new Date().getTime();
|
||||
@@ -418,6 +473,8 @@ module ts {
|
||||
getScriptSnapshot(fileName: string): TypeScript.IScriptSnapshot;
|
||||
getLocalizedDiagnosticMessages(): any;
|
||||
getCancellationToken(): CancellationToken;
|
||||
getCurrentDirectory(): string;
|
||||
getDefaultLibFilename(): string;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -691,16 +748,9 @@ module ts {
|
||||
docComment: string;
|
||||
}
|
||||
|
||||
export enum EmitOutputResult {
|
||||
Succeeded,
|
||||
FailedBecauseOfSyntaxErrors,
|
||||
FailedBecauseOfCompilerOptionsErrors,
|
||||
FailedToGenerateDeclarationsBecauseOfSemanticErrors
|
||||
}
|
||||
|
||||
export interface EmitOutput {
|
||||
outputFiles: OutputFile[];
|
||||
emitOutputResult: EmitOutputResult;
|
||||
emitOutputStatus: EmitReturnStatus;
|
||||
}
|
||||
|
||||
export enum OutputFileType {
|
||||
@@ -713,8 +763,6 @@ module ts {
|
||||
name: string;
|
||||
writeByteOrderMark: boolean;
|
||||
text: string;
|
||||
fileType: OutputFileType;
|
||||
sourceMapOutput: any;
|
||||
}
|
||||
|
||||
export enum EndOfLineState {
|
||||
@@ -850,11 +898,11 @@ module ts {
|
||||
static staticModifier = "static";
|
||||
}
|
||||
|
||||
export class MatchKind {
|
||||
static none: string = null;
|
||||
static exact = "exact";
|
||||
static subString = "substring";
|
||||
static prefix = "prefix";
|
||||
enum MatchKind {
|
||||
none = 0,
|
||||
exact = 1,
|
||||
substring = 2,
|
||||
prefix = 3
|
||||
}
|
||||
|
||||
interface IncrementalParse {
|
||||
@@ -1423,7 +1471,7 @@ module ts {
|
||||
var program: Program;
|
||||
// this checker is used to answer all LS questions except errors
|
||||
var typeInfoResolver: TypeChecker;
|
||||
// the sole purpose of this check is to return semantic diagnostics
|
||||
// the sole purpose of this checker is to return semantic diagnostics
|
||||
// creation is deferred - use getFullTypeCheckChecker to get instance
|
||||
var fullTypeCheckChecker_doNotAccessDirectly: TypeChecker;
|
||||
var useCaseSensitivefilenames = false;
|
||||
@@ -1431,6 +1479,7 @@ module ts {
|
||||
var documentRegistry = documentRegistry;
|
||||
var cancellationToken = new CancellationTokenObject(host.getCancellationToken());
|
||||
var activeCompletionSession: CompletionSession; // The current active completion session, used to get the completion entry details
|
||||
var writer: (filename: string, data: string, writeByteOrderMark: boolean) => void = undefined;
|
||||
|
||||
// Check if the localized messages json is set, otherwise query the host for it
|
||||
if (!TypeScript.LocalizedDiagnosticMessages) {
|
||||
@@ -1455,15 +1504,14 @@ module ts {
|
||||
getCanonicalFileName: (filename) => useCaseSensitivefilenames ? filename : filename.toLowerCase(),
|
||||
useCaseSensitiveFileNames: () => useCaseSensitivefilenames,
|
||||
getNewLine: () => "\r\n",
|
||||
// Need something that doesn't depend on sys.ts here
|
||||
getDefaultLibFilename: (): string => {
|
||||
throw Error("TOD:: getDefaultLibfilename");
|
||||
return host.getDefaultLibFilename();
|
||||
},
|
||||
writeFile: (filename, data, writeByteOrderMark) => {
|
||||
throw Error("TODO: write file");
|
||||
writer(filename, data, writeByteOrderMark);
|
||||
},
|
||||
getCurrentDirectory: (): string => {
|
||||
throw Error("TODO: getCurrentDirectory");
|
||||
return host.getCurrentDirectory();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -2035,6 +2083,29 @@ module ts {
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
|
||||
function getNodeKind(node: Node): string {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ModuleDeclaration: return ScriptElementKind.moduleElement;
|
||||
case SyntaxKind.ClassDeclaration: return ScriptElementKind.classElement;
|
||||
case SyntaxKind.InterfaceDeclaration: return ScriptElementKind.interfaceElement;
|
||||
case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement;
|
||||
case SyntaxKind.VariableDeclaration: return ScriptElementKind.variableElement;
|
||||
case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement;
|
||||
case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement;
|
||||
case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement;
|
||||
case SyntaxKind.Method: return ScriptElementKind.memberFunctionElement;
|
||||
case SyntaxKind.Property: return ScriptElementKind.memberVariableElement;
|
||||
case SyntaxKind.IndexSignature: return ScriptElementKind.indexSignatureElement;
|
||||
case SyntaxKind.ConstructSignature: return ScriptElementKind.constructSignatureElement;
|
||||
case SyntaxKind.CallSignature: return ScriptElementKind.callSignatureElement;
|
||||
case SyntaxKind.Constructor: return ScriptElementKind.constructorImplementationElement;
|
||||
case SyntaxKind.TypeParameter: return ScriptElementKind.typeParameterElement;
|
||||
case SyntaxKind.EnumMember: return ScriptElementKind.variableElement;
|
||||
case SyntaxKind.Parameter: return (node.flags & NodeFlags.AccessibilityModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement;
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
}
|
||||
|
||||
function getNodeModifiers(node: Node): string {
|
||||
var flags = node.flags;
|
||||
var result: string[] = [];
|
||||
@@ -2186,6 +2257,7 @@ module ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
/// References and Occurances
|
||||
function getOccurrencesAtPosition(filename: string, position: number): ReferenceEntry[] {
|
||||
synchronizeHostData();
|
||||
|
||||
@@ -2527,7 +2599,7 @@ module ts {
|
||||
return getReferencesForNode(node, program.getSourceFiles());
|
||||
}
|
||||
|
||||
function getReferencesForNode(node: Node, sourceFiles : SourceFile[]): ReferenceEntry[] {
|
||||
function getReferencesForNode(node: Node, sourceFiles: SourceFile[]): ReferenceEntry[] {
|
||||
// Labels
|
||||
if (isLabelName(node)) {
|
||||
if (isJumpStatementTarget(node)) {
|
||||
@@ -2570,8 +2642,9 @@ module ts {
|
||||
var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), symbol.getDeclarations());
|
||||
|
||||
// Get the text to search for, we need to normalize it as external module names will have quote
|
||||
var symbolName = getNormalizedSymbolName(symbol);
|
||||
var symbolName = getNormalizedSymbolName(symbol);
|
||||
|
||||
// Get syntactic diagnostics
|
||||
var scope = getSymbolScope(symbol);
|
||||
|
||||
if (scope) {
|
||||
@@ -2601,7 +2674,7 @@ module ts {
|
||||
else {
|
||||
var name = symbol.name;
|
||||
}
|
||||
|
||||
|
||||
var length = name.length;
|
||||
if (length >= 2 && name.charCodeAt(0) === CharacterCodes.doubleQuote && name.charCodeAt(length - 1) === CharacterCodes.doubleQuote) {
|
||||
return name.substring(1, length - 1);
|
||||
@@ -2732,9 +2805,10 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Search within node "container" for references for a search value, where the search value is defined as a
|
||||
/// tuple of(searchSymbol, searchText, searchLocation, and searchMeaning).
|
||||
/// searchLocation: a node where the search value
|
||||
/** Search within node "container" for references for a search value, where the search value is defined as a
|
||||
* tuple of(searchSymbol, searchText, searchLocation, and searchMeaning).
|
||||
* searchLocation: a node where the search value
|
||||
*/
|
||||
function getReferencesInNode(container: Node, searchSymbol: Symbol, searchText: string, searchLocation: Node, searchMeaning: SearchMeaning, result: ReferenceEntry[]): void {
|
||||
var sourceFile = container.getSourceFile();
|
||||
|
||||
@@ -3100,12 +3174,13 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
/// Given an initial searchMeaning, extracted from a location, widen the search scope based on the declarations
|
||||
/// of the corresponding symbol. e.g. if we are searching for "Foo" in value position, but "Foo" references a class
|
||||
/// then we need to widen the search to include type positions as well.
|
||||
/// On the contrary, if we are searching for "Bar" in type position and we trace bar to an interface, and an uninstantiated
|
||||
/// module, we want to keep the search limited to only types, as the two declarations (interface and uninstantiated module)
|
||||
/// do not intersect in any of the three spaces.
|
||||
/** Given an initial searchMeaning, extracted from a location, widen the search scope based on the declarations
|
||||
* of the corresponding symbol. e.g. if we are searching for "Foo" in value position, but "Foo" references a class
|
||||
* then we need to widen the search to include type positions as well.
|
||||
* On the contrary, if we are searching for "Bar" in type position and we trace bar to an interface, and an uninstantiated
|
||||
* module, we want to keep the search limited to only types, as the two declarations (interface and uninstantiated module)
|
||||
* do not intersect in any of the three spaces.
|
||||
*/
|
||||
function getIntersectingMeaningFromDeclarations(meaning: SearchMeaning, declarations: Declaration[]): SearchMeaning {
|
||||
if (declarations) {
|
||||
do {
|
||||
@@ -3138,11 +3213,10 @@ module ts {
|
||||
start += 1;
|
||||
end -= 1;
|
||||
}
|
||||
|
||||
return new ReferenceEntry(node.getSourceFile().filename, TypeScript.TextSpan.fromBounds(start, end), isWriteAccess(node));
|
||||
}
|
||||
|
||||
/// A node is considered a writeAccess iff it is a name of a declaration or a target of an assignment
|
||||
/** A node is considered a writeAccess iff it is a name of a declaration or a target of an assignment */
|
||||
function isWriteAccess(node: Node): boolean {
|
||||
if (node.kind === SyntaxKind.Identifier && isDeclarationOrFunctionExpressionOrCatchVariableName(node)) {
|
||||
return true;
|
||||
@@ -3162,6 +3236,155 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// NavigateTo
|
||||
function getNavigateToItems(searchValue: string): NavigateToItem[] {
|
||||
synchronizeHostData();
|
||||
|
||||
// Split search value in terms array
|
||||
var terms = searchValue.split(" ");
|
||||
|
||||
// default NavigateTo approach: if search term contains only lower-case chars - use case-insensitive search, otherwise switch to case-sensitive version
|
||||
var searchTerms = map(terms, t => ({ caseSensitive: hasAnyUpperCaseCharacter(t), term: t }));
|
||||
|
||||
var items: NavigateToItem[] = [];
|
||||
|
||||
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
|
||||
forEach(program.getSourceFiles(), sourceFile => {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
|
||||
var filename = sourceFile.filename;
|
||||
var declarations = sourceFile.getNamedDeclarations();
|
||||
for (var i = 0, n = declarations.length; i < n; i++) {
|
||||
var declaration = declarations[i];
|
||||
var name = declaration.name.text;
|
||||
var matchKind = getMatchKind(searchTerms, name);
|
||||
if (matchKind !== MatchKind.none) {
|
||||
var container = <Declaration>getContainerNode(declaration);
|
||||
items.push({
|
||||
name: name,
|
||||
kind: getNodeKind(declaration),
|
||||
kindModifiers: getNodeModifiers(declaration),
|
||||
matchKind: MatchKind[matchKind],
|
||||
fileName: filename,
|
||||
textSpan: TypeScript.TextSpan.fromBounds(declaration.getStart(), declaration.getEnd()),
|
||||
containerName: container.name ? container.name.text : "",
|
||||
containerKind: container.name ? getNodeKind(container) : ""
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return items;
|
||||
|
||||
function hasAnyUpperCaseCharacter(s: string): boolean {
|
||||
for (var i = 0, n = s.length; i < n; i++) {
|
||||
var c = s.charCodeAt(i);
|
||||
if ((CharacterCodes.A <= c && c <= CharacterCodes.Z) ||
|
||||
(c >= CharacterCodes.maxAsciiCharacter && s.charAt(i).toLocaleLowerCase() !== s.charAt(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getMatchKind(searchTerms: { caseSensitive: boolean; term: string }[], name: string): MatchKind {
|
||||
var matchKind = MatchKind.none;
|
||||
|
||||
if (name) {
|
||||
for (var j = 0, n = searchTerms.length; j < n; j++) {
|
||||
var searchTerm = searchTerms[j];
|
||||
var nameToSearch = searchTerm.caseSensitive ? name : name.toLocaleLowerCase();
|
||||
// in case of case-insensitive search searchTerm.term will already be lower-cased
|
||||
var index = nameToSearch.indexOf(searchTerm.term);
|
||||
if (index < 0) {
|
||||
// Didn't match.
|
||||
return MatchKind.none;
|
||||
}
|
||||
|
||||
var termKind = MatchKind.substring;
|
||||
if (index === 0) {
|
||||
// here we know that match occur at the beginning of the string.
|
||||
// if search term and declName has the same length - we have an exact match, otherwise declName have longer length and this will be prefix match
|
||||
termKind = name.length === searchTerm.term.length ? MatchKind.exact : MatchKind.prefix;
|
||||
}
|
||||
|
||||
// Update our match kind if we don't have one, or if this match is better.
|
||||
if (matchKind === MatchKind.none || termKind < matchKind) {
|
||||
matchKind = termKind;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return matchKind;
|
||||
}
|
||||
}
|
||||
|
||||
function containErrors(diagnostics: Diagnostic[]): boolean {
|
||||
return forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error);
|
||||
}
|
||||
|
||||
function getEmitOutput(filename: string): EmitOutput {
|
||||
synchronizeHostData();
|
||||
filename = TypeScript.switchToForwardSlashes(filename);
|
||||
var compilerOptions = program.getCompilerOptions();
|
||||
var targetSourceFile = program.getSourceFile(filename); // Current selected file to be output
|
||||
var emitToSingleFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions);
|
||||
var emitDeclaration = compilerOptions.declaration;
|
||||
var emitOutput: EmitOutput = {
|
||||
outputFiles: [],
|
||||
emitOutputStatus: undefined,
|
||||
};
|
||||
|
||||
function getEmitOutputWriter(filename: string, data: string, writeByteOrderMark: boolean) {
|
||||
emitOutput.outputFiles.push({
|
||||
name: filename,
|
||||
writeByteOrderMark: writeByteOrderMark,
|
||||
text: data
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize writer for CompilerHost.writeFile
|
||||
writer = getEmitOutputWriter;
|
||||
|
||||
var syntacticDiagnostics: Diagnostic[] = [];
|
||||
var containSyntacticErrors = false;
|
||||
|
||||
if (emitToSingleFile) {
|
||||
// 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 = emitToSingleFile ? getFullTypeCheckChecker().emitFiles(targetSourceFile) : getFullTypeCheckChecker().emitFiles();
|
||||
emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/// Syntactic features
|
||||
function getSyntaxTree(filename: string): TypeScript.SyntaxTree {
|
||||
filename = TypeScript.switchToForwardSlashes(filename);
|
||||
@@ -3718,7 +3941,7 @@ module ts {
|
||||
getImplementorsAtPosition: (filename, position) => [],
|
||||
getNameOrDottedNameSpan: getNameOrDottedNameSpan,
|
||||
getBreakpointStatementAtPosition: getBreakpointStatementAtPosition,
|
||||
getNavigateToItems: (searchValue) => [],
|
||||
getNavigateToItems: getNavigateToItems,
|
||||
getRenameInfo: getRenameInfo,
|
||||
getNavigationBarItems: getNavigationBarItems,
|
||||
getOutliningSpans: getOutliningSpans,
|
||||
@@ -3728,7 +3951,7 @@ module ts {
|
||||
getFormattingEditsForRange: getFormattingEditsForRange,
|
||||
getFormattingEditsForDocument: getFormattingEditsForDocument,
|
||||
getFormattingEditsAfterKeystroke: getFormattingEditsAfterKeystroke,
|
||||
getEmitOutput: (filename): EmitOutput => null,
|
||||
getEmitOutput: getEmitOutput,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+25
-12
@@ -53,6 +53,8 @@ module ts {
|
||||
getScriptSnapshot(fileName: string): ScriptSnapshotShim;
|
||||
getLocalizedDiagnosticMessages(): string;
|
||||
getCancellationToken(): CancellationToken;
|
||||
getCurrentDirectory(): string;
|
||||
getDefaultLibFilename(): string;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -147,19 +149,19 @@ module ts {
|
||||
getDefaultCompilationSettings(): string;
|
||||
}
|
||||
|
||||
/// TODO: delete this, it is only needed untill the VS interface is updated
|
||||
/// TODO: delete this, it is only needed until the VS interface is updated
|
||||
enum LanguageVersion {
|
||||
EcmaScript3 = 0,
|
||||
EcmaScript5 = 1,
|
||||
}
|
||||
|
||||
enum ModuleGenTarget {
|
||||
export enum ModuleGenTarget {
|
||||
Unspecified = 0,
|
||||
Synchronous = 1,
|
||||
Asynchronous = 2,
|
||||
}
|
||||
|
||||
interface CompilationSettings {
|
||||
export interface CompilationSettings {
|
||||
propagateEnumConstants?: boolean;
|
||||
removeComments?: boolean;
|
||||
watch?: boolean;
|
||||
@@ -179,15 +181,18 @@ module ts {
|
||||
gatherDiagnostics?: boolean;
|
||||
codepage?: number;
|
||||
emitBOM?: boolean;
|
||||
|
||||
// Declare indexer signature
|
||||
[index: string]: any;
|
||||
}
|
||||
|
||||
function languageVersionToScriptTarget(languageVersion: LanguageVersion): ScriptTarget {
|
||||
if (typeof languageVersion === "undefined") return undefined;
|
||||
|
||||
switch (languageVersion) {
|
||||
case LanguageVersion.EcmaScript3: return ScriptTarget.ES3;
|
||||
case LanguageVersion.EcmaScript3: return ScriptTarget.ES3
|
||||
case LanguageVersion.EcmaScript5: return ScriptTarget.ES5;
|
||||
default: throw Error("unsuported LanguageVersion value: " + languageVersion);
|
||||
default: throw Error("unsupported LanguageVersion value: " + languageVersion);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +203,7 @@ module ts {
|
||||
case ModuleGenTarget.Asynchronous: return ModuleKind.AMD;
|
||||
case ModuleGenTarget.Synchronous: return ModuleKind.CommonJS;
|
||||
case ModuleGenTarget.Unspecified: return ModuleKind.None;
|
||||
default: throw Error("unsuported ModuleGenTarget value: " + moduleGenTarget);
|
||||
default: throw Error("unsupported ModuleGenTarget value: " + moduleGenTarget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +213,7 @@ module ts {
|
||||
switch (scriptTarget) {
|
||||
case ScriptTarget.ES3: return LanguageVersion.EcmaScript3;
|
||||
case ScriptTarget.ES5: return LanguageVersion.EcmaScript5;
|
||||
default: throw Error("unsuported ScriptTarget value: " + scriptTarget);
|
||||
default: throw Error("unsupported ScriptTarget value: " + scriptTarget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +224,7 @@ module ts {
|
||||
case ModuleKind.AMD: return ModuleGenTarget.Asynchronous;
|
||||
case ModuleKind.CommonJS: return ModuleGenTarget.Synchronous;
|
||||
case ModuleKind.None: return ModuleGenTarget.Unspecified;
|
||||
default: throw Error("unsuported ModuleKind value: " + moduleKind);
|
||||
default: throw Error("unsupported ModuleKind value: " + moduleKind);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,8 +328,8 @@ module ts {
|
||||
|
||||
/// TODO: this should be pushed into VS.
|
||||
/// We can not ask the LS instance to resolve, as this will lead to asking the host about files it does not know about,
|
||||
/// something it is not desinged to handle. for now make sure we never get a "noresolve == false".
|
||||
/// This value should not matter, as the host runs resolution logic independentlly
|
||||
/// something it is not designed to handle. for now make sure we never get a "noresolve == false".
|
||||
/// This value should not matter, as the host runs resolution logic independently
|
||||
options.noResolve = true;
|
||||
|
||||
return options;
|
||||
@@ -364,6 +369,14 @@ module ts {
|
||||
public getCancellationToken(): CancellationToken {
|
||||
return this.shimHost.getCancellationToken();
|
||||
}
|
||||
|
||||
public getDefaultLibFilename(): string {
|
||||
return this.shimHost.getDefaultLibFilename();
|
||||
}
|
||||
|
||||
public getCurrentDirectory(): string {
|
||||
return this.shimHost.getCurrentDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any): any {
|
||||
@@ -421,7 +434,7 @@ module ts {
|
||||
}
|
||||
|
||||
// DISPOSE
|
||||
// Ensure (almost) determinstic release of internal Javascript resources when
|
||||
// Ensure (almost) deterministic release of internal Javascript resources when
|
||||
// some external native objects holds onto us (e.g. Com/Interop).
|
||||
public dispose(dummy: any): void {
|
||||
this.logger.log("dispose()");
|
||||
@@ -866,7 +879,7 @@ module ts {
|
||||
}
|
||||
|
||||
|
||||
/// TODO: this is used by VS, clean this up on both sides of the interfrace
|
||||
/// TODO: this is used by VS, clean this up on both sides of the interface
|
||||
module TypeScript.Services {
|
||||
export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory;
|
||||
}
|
||||
|
||||
@@ -211,8 +211,6 @@ module TypeScript.Services {
|
||||
signatureGroupInfo.signatureInfo = TypeScript.MemberName.memberNameToString(symbolName, paramIndexInfo);
|
||||
signatureGroupInfo.docComment = symbol.docComments();
|
||||
|
||||
var parameterMarkerIndex = 0;
|
||||
|
||||
var typeSymbol = symbol.type;
|
||||
|
||||
var typeParameters = typeSymbol.getTypeParameters();
|
||||
|
||||
@@ -84,7 +84,6 @@ module TypeScript {
|
||||
private cacheSyntaxTreeInfo(): void {
|
||||
// If we're not keeping around the syntax tree, store the diagnostics and line
|
||||
// map so they don't have to be recomputed.
|
||||
var sourceUnit = this.sourceUnit();
|
||||
var firstToken = firstSyntaxTreeToken(this);
|
||||
var leadingTrivia = firstToken.leadingTrivia(this.text);
|
||||
|
||||
|
||||
@@ -150,7 +150,6 @@ module TypeScript.Syntax {
|
||||
|
||||
// When we run into a newline for the first time, create the string builder and copy
|
||||
// all the values up to this newline into it.
|
||||
var isCarriageReturnLineFeed = false;
|
||||
switch (ch) {
|
||||
case CharacterCodes.carriageReturn:
|
||||
if (i < triviaText.length - 1 && triviaText.charCodeAt(i + 1) === CharacterCodes.lineFeed) {
|
||||
|
||||
Reference in New Issue
Block a user