diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a209db4e73b..9204bfbaa10 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2,6 +2,8 @@ /* @internal */ namespace ts { + const ambientModuleSymbolRegex = /^".+"$/; + let nextSymbolId = 1; let nextNodeId = 1; let nextMergeId = 1; @@ -100,6 +102,7 @@ namespace ts { getAliasedSymbol: resolveAlias, getEmitResolver, getExportsOfModule: getExportsOfModuleAsArray, + getAmbientModules, getJsxElementAttributesType, getJsxIntrinsicTagNames, @@ -329,6 +332,7 @@ namespace ts { const assignableRelation = createMap(); const comparableRelation = createMap(); const identityRelation = createMap(); + const enumRelation = createMap(); // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. let _displayBuilder: SymbolDisplayBuilder; @@ -3347,7 +3351,13 @@ namespace ts { // Otherwise, fall back to 'any'. else { if (compilerOptions.noImplicitAny) { - error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbolToString(symbol)); + if (setter) { + error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol)); + } + else { + Debug.assert(!!getter, "there must existed getter as we are current checking either setter or getter in this function"); + error(getter, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol)); + } } type = anyType; } @@ -6186,8 +6196,14 @@ namespace ts { if (source === target) { return true; } - if (source.symbol.name !== target.symbol.name || !(source.symbol.flags & SymbolFlags.RegularEnum) || !(target.symbol.flags & SymbolFlags.RegularEnum)) { - return false; + const id = source.id + "," + target.id; + if (enumRelation[id] !== undefined) { + return enumRelation[id]; + } + if (source.symbol.name !== target.symbol.name || + !(source.symbol.flags & SymbolFlags.RegularEnum) || !(target.symbol.flags & SymbolFlags.RegularEnum) || + (source.flags & TypeFlags.Union) !== (target.flags & TypeFlags.Union)) { + return enumRelation[id] = false; } const targetEnumType = getTypeOfSymbol(target.symbol); for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) { @@ -6198,11 +6214,11 @@ namespace ts { errorReporter(Diagnostics.Property_0_is_missing_in_type_1, property.name, typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); } - return false; + return enumRelation[id] = false; } } } - return true; + return enumRelation[id] = true; } function isSimpleTypeRelatedTo(source: Type, target: Type, relation: Map, errorReporter?: ErrorReporter) { @@ -6217,8 +6233,18 @@ namespace ts { if (source.flags & TypeFlags.Null && (!strictNullChecks || target.flags & TypeFlags.Null)) return true; if (relation === assignableRelation || relation === comparableRelation) { if (source.flags & TypeFlags.Any) return true; - if (source.flags & (TypeFlags.Number | TypeFlags.NumberLiteral) && target.flags & TypeFlags.Enum) return true; - if (source.flags & TypeFlags.NumberLiteral && target.flags & TypeFlags.EnumLiteral && (source).text === (target).text) return true; + if ((source.flags & TypeFlags.Number | source.flags & TypeFlags.NumberLiteral) && target.flags & TypeFlags.EnumLike) return true; + if (source.flags & TypeFlags.EnumLiteral && + target.flags & TypeFlags.EnumLiteral && + (source).text === (target).text && + isEnumTypeRelatedTo((source).baseType, (target).baseType, errorReporter)) { + return true; + } + if (source.flags & TypeFlags.EnumLiteral && + target.flags & TypeFlags.Enum && + isEnumTypeRelatedTo(target, (source).baseType, errorReporter)) { + return true; + } } return false; } @@ -11961,18 +11987,12 @@ namespace ts { // Function interface, since they have none by default. This is a bit of a leap of faith // that the user will not add any. const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call); - const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct); - // TS 1.0 spec: 4.12 - // If FuncExpr is of type Any, or of an object type that has no call or construct signatures - // but is a subtype of the Function interface, the call is an untyped function call. In an - // untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual + + // TS 1.0 Spec: 4.12 + // In an untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual // types are provided for the argument expressions, and the result is always of type Any. - // We exclude union types because we may have a union of function types that happen to have - // no common signatures. - if (isTypeAny(funcType) || - (isTypeAny(apparentType) && funcType.flags & TypeFlags.TypeParameter) || - (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { + if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) { // The unknownType indicates that an error already occurred (and was reported). No // need to report another error in this case. if (funcType !== unknownType && node.typeArguments) { @@ -11995,6 +12015,29 @@ namespace ts { return resolveCall(node, callSignatures, candidatesOutArray); } + /** + * TS 1.0 spec: 4.12 + * If FuncExpr is of type Any, or of an object type that has no call or construct signatures + * but is a subtype of the Function interface, the call is an untyped function call. + */ + function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number) { + if (isTypeAny(funcType)) { + return true; + } + if (isTypeAny(apparentFuncType) && funcType.flags & TypeFlags.TypeParameter) { + return true; + } + if (!numCallSignatures && !numConstructSignatures) { + // We exclude union types because we may have a union of function types that happen to have + // no common signatures. + if (funcType.flags & TypeFlags.Union) { + return false; + } + return isTypeAssignableTo(funcType, globalFunctionType); + } + return false; + } + function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature { if (node.arguments && languageVersion < ScriptTarget.ES5) { const spreadIndex = getSpreadArgumentIndex(node.arguments); @@ -12120,8 +12163,9 @@ namespace ts { } const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call); + const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct); - if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isUntypedFunctionCall(tagType, apparentType, callSignatures.length, constructSignatures.length)) { return resolveUntypedCall(node); } @@ -12166,7 +12210,8 @@ namespace ts { } const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call); - if (funcType === anyType || (!callSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { + const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct); + if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) { return resolveUntypedCall(node); } @@ -18767,7 +18812,13 @@ namespace ts { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } if (file.symbol && file.symbol.globalExports) { - mergeSymbolTable(globals, file.symbol.globalExports); + // Merge in UMD exports with first-in-wins semantics (see #9771) + const source = file.symbol.globalExports; + for (const id in source) { + if (!(id in globals)) { + globals[id] = source[id]; + } + } } }); @@ -19992,5 +20043,15 @@ namespace ts { return true; } } + + function getAmbientModules(): Symbol[] { + const result: Symbol[] = []; + for (const sym in globals) { + if (ambientModuleSymbolRegex.test(sym)) { + result.push(globals[sym]); + } + } + return result; + } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fefe1f982ac..167985e184f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2875,11 +2875,7 @@ "Element implicitly has an 'any' type because index expression is not of type 'number'.": { "category": "Error", "code": 7015 - }, - "Property '{0}' implicitly has type 'any', because its 'set' accessor lacks a type annotation.": { - "category": "Error", - "code": 7016 - }, + }, "Index signature of object type implicitly has an 'any' type.": { "category": "Error", "code": 7017 @@ -2936,6 +2932,14 @@ "category": "Error", "code": 7031 }, + "Property '{0}' implicitly has type 'any', because its set accessor lacks a parameter type annotation.": { + "category": "Error", + "code": 7032 + }, + "Property '{0}' implicitly has type 'any', because its get accessor lacks a return type annotation.": { + "category": "Error", + "code": 7033 + }, "You cannot rename this element.": { "category": "Error", "code": 8000 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 40c806198ab..3c200aca931 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6587,7 +6587,7 @@ const _super = (function (geti, seti) { // import { x, y } from "foo" // import d, * as x from "foo" // import d, { x, y } from "foo" - const isNakedImport = SyntaxKind.ImportDeclaration && !(node).importClause; + const isNakedImport = node.kind === SyntaxKind.ImportDeclaration && !(node).importClause; if (!isNakedImport) { write(varOrConst); write(getGeneratedNameForNode(node)); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index fd6403cf14b..3628ac304a9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2340,6 +2340,7 @@ namespace ts { token() === SyntaxKind.LessThanToken || token() === SyntaxKind.QuestionToken || token() === SyntaxKind.ColonToken || + token() === SyntaxKind.CommaToken || canParseSemicolon(); } return false; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 9086220cdc5..69a6727c961 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -11,9 +11,9 @@ namespace ts { const defaultTypeRoots = ["node_modules/@types"]; - export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean): string { + export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string { while (true) { - const fileName = combinePaths(searchPath, "tsconfig.json"); + const fileName = combinePaths(searchPath, configName); if (fileExists(fileName)) { return fileName; } @@ -79,22 +79,19 @@ namespace ts { const typeReferenceExtensions = [".d.ts"]; - function getEffectiveTypeRoots(options: CompilerOptions, host: ModuleResolutionHost) { + export function getEffectiveTypeRoots(options: CompilerOptions, currentDirectory: string) { if (options.typeRoots) { return options.typeRoots; } - let currentDirectory: string; if (options.configFilePath) { currentDirectory = getDirectoryPath(options.configFilePath); } - else if (host.getCurrentDirectory) { - currentDirectory = host.getCurrentDirectory(); - } if (!currentDirectory) { return undefined; } + return map(defaultTypeRoots, d => combinePaths(currentDirectory, d)); } @@ -112,7 +109,7 @@ namespace ts { traceEnabled }; - const typeRoots = getEffectiveTypeRoots(options, host); + const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory && host.getCurrentDirectory()); if (traceEnabled) { if (containingFile === undefined) { if (typeRoots === undefined) { @@ -427,7 +424,7 @@ namespace ts { // Walk the primary type lookup locations const result: string[] = []; if (host.directoryExists && host.getDirectories) { - const typeRoots = getEffectiveTypeRoots(options, host); + const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory && host.getCurrentDirectory()); if (typeRoots) { for (const root of typeRoots) { if (host.directoryExists(root)) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9d3f419cbb2..d346671ff78 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1891,6 +1891,7 @@ namespace ts { getJsxElementAttributesType(elementNode: JsxOpeningLikeElement): Type; getJsxIntrinsicTagNames(): Symbol[]; isOptionalParameter(node: ParameterDeclaration): boolean; + getAmbientModules(): Symbol[]; // Should not be called directly. Should only be accessed through the Program instance. /* @internal */ getDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 91b641f6218..f898709442c 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -206,6 +206,24 @@ namespace FourSlash { private inputFiles = ts.createMap(); // Map between inputFile's fileName and its content for easily looking up when resolving references + private static getDisplayPartsJson(displayParts: ts.SymbolDisplayPart[]) { + let result = ""; + ts.forEach(displayParts, part => { + if (result) { + result += ",\n "; + } + else { + result = "[\n "; + } + result += JSON.stringify(part); + }); + if (result) { + result += "\n]"; + } + + return result; + } + // Add input file which has matched file name with the given reference-file path. // This is necessary when resolveReference flag is specified private addMatchedInputFile(referenceFilePath: string, extensions: string[]) { @@ -245,22 +263,31 @@ namespace FourSlash { constructor(private basePath: string, private testType: FourSlashTestType, public testData: FourSlashData) { // Create a new Services Adapter this.cancellationToken = new TestCancellationToken(); - const compilationOptions = convertGlobalOptionsToCompilerOptions(this.testData.globalOptions); - if (compilationOptions.typeRoots) { - compilationOptions.typeRoots = compilationOptions.typeRoots.map(p => ts.getNormalizedAbsolutePath(p, this.basePath)); - } + let compilationOptions = convertGlobalOptionsToCompilerOptions(this.testData.globalOptions); compilationOptions.skipDefaultLibCheck = true; - const languageServiceAdapter = this.getLanguageServiceAdapter(testType, this.cancellationToken, compilationOptions); - this.languageServiceAdapterHost = languageServiceAdapter.getHost(); - this.languageService = languageServiceAdapter.getLanguageService(); - // Initialize the language service with all the scripts let startResolveFileRef: FourSlashFile; ts.forEach(testData.files, file => { // Create map between fileName and its content for easily looking up when resolveReference flag is specified this.inputFiles[file.fileName] = file.content; + + if (ts.getBaseFileName(file.fileName).toLowerCase() === "tsconfig.json") { + const configJson = ts.parseConfigFileTextToJson(file.fileName, file.content); + assert.isTrue(configJson.config !== undefined); + + // Extend our existing compiler options so that we can also support tsconfig only options + if (configJson.config.compilerOptions) { + const baseDirectory = ts.normalizePath(ts.getDirectoryPath(file.fileName)); + const tsConfig = ts.convertCompilerOptionsFromJson(configJson.config.compilerOptions, baseDirectory, file.fileName); + + if (!tsConfig.errors || !tsConfig.errors.length) { + compilationOptions = ts.extend(compilationOptions, tsConfig.options); + } + } + } + if (!startResolveFileRef && file.fileOptions[metadataOptionNames.resolveReference] === "true") { startResolveFileRef = file; } @@ -270,6 +297,15 @@ namespace FourSlash { } }); + + if (compilationOptions.typeRoots) { + compilationOptions.typeRoots = compilationOptions.typeRoots.map(p => ts.getNormalizedAbsolutePath(p, this.basePath)); + } + + const languageServiceAdapter = this.getLanguageServiceAdapter(testType, this.cancellationToken, compilationOptions); + this.languageServiceAdapterHost = languageServiceAdapter.getHost(); + this.languageService = languageServiceAdapter.getLanguageService(); + if (startResolveFileRef) { // Add the entry-point file itself into the languageServiceShimHost this.languageServiceAdapterHost.addScript(startResolveFileRef.fileName, startResolveFileRef.content, /*isRootFile*/ true); @@ -651,10 +687,10 @@ namespace FourSlash { } } - public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string) { + public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string, spanIndex?: number) { const completions = this.getCompletionListAtCaret(); if (completions) { - this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind); + this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind, spanIndex); } else { this.raiseError(`No completions at position '${this.currentCaretPosition}' when looking for '${symbol}'.`); @@ -670,25 +706,32 @@ namespace FourSlash { * @param expectedText the text associated with the symbol * @param expectedDocumentation the documentation text associated with the symbol * @param expectedKind the kind of symbol (see ScriptElementKind) + * @param spanIndex the index of the range that the completion item's replacement text span should match */ - public verifyCompletionListDoesNotContain(symbol: string, expectedText?: string, expectedDocumentation?: string, expectedKind?: string) { + public verifyCompletionListDoesNotContain(symbol: string, expectedText?: string, expectedDocumentation?: string, expectedKind?: string, spanIndex?: number) { const that = this; + let replacementSpan: ts.TextSpan; + if (spanIndex !== undefined) { + replacementSpan = this.getTextSpanForRangeAtIndex(spanIndex); + } + function filterByTextOrDocumentation(entry: ts.CompletionEntry) { const details = that.getCompletionEntryDetails(entry.name); const documentation = ts.displayPartsToString(details.documentation); const text = ts.displayPartsToString(details.displayParts); - if (expectedText && expectedDocumentation) { - return (documentation === expectedDocumentation && text === expectedText) ? true : false; + + // If any of the expected values are undefined, assume that users don't + // care about them. + if (replacementSpan && !TestState.textSpansEqual(replacementSpan, entry.replacementSpan)) { + return false; } - else if (expectedText && !expectedDocumentation) { - return text === expectedText ? true : false; + else if (expectedText && text !== expectedText) { + return false; } - else if (expectedDocumentation && !expectedText) { - return documentation === expectedDocumentation ? true : false; + else if (expectedDocumentation && documentation !== expectedDocumentation) { + return false; } - // Because expectedText and expectedDocumentation are undefined, we assume that - // users don"t care to compare them so we will treat that entry as if the entry has matching text and documentation - // and keep it in the list of filtered entry. + return true; } @@ -712,6 +755,10 @@ namespace FourSlash { if (expectedKind) { error += "Expected kind: " + expectedKind + " to equal: " + filterCompletions[0].kind + "."; } + if (replacementSpan) { + const spanText = filterCompletions[0].replacementSpan ? stringify(filterCompletions[0].replacementSpan) : undefined; + error += "Expected replacement span: " + stringify(replacementSpan) + " to equal: " + spanText + "."; + } this.raiseError(error); } } @@ -777,6 +824,20 @@ namespace FourSlash { ts.forEachProperty(this.rangesByText(), ranges => this.verifyRangesReferenceEachOther(ranges)); } + public verifyDisplayPartsOfReferencedSymbol(expected: ts.SymbolDisplayPart[]) { + const referencedSymbols = this.findReferencesAtCaret(); + + if (referencedSymbols.length === 0) { + this.raiseError("No referenced symbols found at current caret position"); + } + else if (referencedSymbols.length > 1) { + this.raiseError("More than one referenced symbol found"); + } + + assert.equal(TestState.getDisplayPartsJson(referencedSymbols[0].definition.displayParts), + TestState.getDisplayPartsJson(expected), this.messageAtLastKnownMarker("referenced symbol definition display parts")); + } + private verifyReferencesWorker(references: ts.ReferenceEntry[], fileName: string, start: number, end: number, isWriteAccess?: boolean, isDefinition?: boolean) { for (let i = 0; i < references.length; i++) { const reference = references[i]; @@ -811,6 +872,10 @@ namespace FourSlash { return this.languageService.getReferencesAtPosition(this.activeFile.fileName, this.currentCaretPosition); } + private findReferencesAtCaret() { + return this.languageService.findReferences(this.activeFile.fileName, this.currentCaretPosition); + } + public getSyntacticDiagnostics(expected: string) { const diagnostics = this.languageService.getSyntacticDiagnostics(this.activeFile.fileName); this.testDiagnostics(expected, diagnostics); @@ -856,30 +921,12 @@ namespace FourSlash { displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[]) { - function getDisplayPartsJson(displayParts: ts.SymbolDisplayPart[]) { - let result = ""; - ts.forEach(displayParts, part => { - if (result) { - result += ",\n "; - } - else { - result = "[\n "; - } - result += JSON.stringify(part); - }); - if (result) { - result += "\n]"; - } - - return result; - } - const actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition); assert.equal(actualQuickInfo.kind, kind, this.messageAtLastKnownMarker("QuickInfo kind")); assert.equal(actualQuickInfo.kindModifiers, kindModifiers, this.messageAtLastKnownMarker("QuickInfo kindModifiers")); assert.equal(JSON.stringify(actualQuickInfo.textSpan), JSON.stringify(textSpan), this.messageAtLastKnownMarker("QuickInfo textSpan")); - assert.equal(getDisplayPartsJson(actualQuickInfo.displayParts), getDisplayPartsJson(displayParts), this.messageAtLastKnownMarker("QuickInfo displayParts")); - assert.equal(getDisplayPartsJson(actualQuickInfo.documentation), getDisplayPartsJson(documentation), this.messageAtLastKnownMarker("QuickInfo documentation")); + assert.equal(TestState.getDisplayPartsJson(actualQuickInfo.displayParts), TestState.getDisplayPartsJson(displayParts), this.messageAtLastKnownMarker("QuickInfo displayParts")); + assert.equal(TestState.getDisplayPartsJson(actualQuickInfo.documentation), TestState.getDisplayPartsJson(documentation), this.messageAtLastKnownMarker("QuickInfo documentation")); } public verifyRenameLocations(findInStrings: boolean, findInComments: boolean, ranges?: Range[]) { @@ -2147,7 +2194,7 @@ namespace FourSlash { return text.substring(startPos, endPos); } - private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, text?: string, documentation?: string, kind?: string) { + private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, text?: string, documentation?: string, kind?: string, spanIndex?: number) { for (let i = 0; i < items.length; i++) { const item = items[i]; if (item.name === name) { @@ -2166,6 +2213,11 @@ namespace FourSlash { assert.equal(item.kind, kind, this.assertionMessageAtLastKnownMarker("completion item kind for " + name)); } + if (spanIndex !== undefined) { + const span = this.getTextSpanForRangeAtIndex(spanIndex); + assert.isTrue(TestState.textSpansEqual(span, item.replacementSpan), this.assertionMessageAtLastKnownMarker(stringify(span) + " does not equal " + stringify(item.replacementSpan) + " replacement span for " + name)); + } + return; } } @@ -2222,6 +2274,17 @@ namespace FourSlash { return `line ${(pos.line + 1)}, col ${pos.character}`; } + private getTextSpanForRangeAtIndex(index: number): ts.TextSpan { + const ranges = this.getRanges(); + if (ranges && ranges.length > index) { + const range = ranges[index]; + return { start: range.start, length: range.end - range.start }; + } + else { + this.raiseError("Supplied span index: " + index + " does not exist in range list of size: " + (ranges ? 0 : ranges.length)); + } + } + public getMarkerByName(markerName: string) { const markerPos = this.testData.markerPositions[markerName]; if (markerPos === undefined) { @@ -2245,6 +2308,10 @@ namespace FourSlash { public resetCancelled(): void { this.cancellationToken.resetCancelled(); } + + private static textSpansEqual(a: ts.TextSpan, b: ts.TextSpan) { + return a && b && a.start === b.start && a.length === b.length; + } } export function runFourSlashTest(basePath: string, testType: FourSlashTestType, fileName: string) { @@ -2253,12 +2320,16 @@ namespace FourSlash { } export function runFourSlashTestContent(basePath: string, testType: FourSlashTestType, content: string, fileName: string): void { + // Give file paths an absolute path for the virtual file system + const absoluteBasePath = ts.combinePaths(Harness.virtualFileSystemRoot, basePath); + const absoluteFileName = ts.combinePaths(Harness.virtualFileSystemRoot, fileName); + // Parse out the files and their metadata - const testData = parseTestData(basePath, content, fileName); - const state = new TestState(basePath, testType, testData); + const testData = parseTestData(absoluteBasePath, content, absoluteFileName); + const state = new TestState(absoluteBasePath, testType, testData); const output = ts.transpileModule(content, { reportDiagnostics: true }); if (output.diagnostics.length > 0) { - throw new Error(`Syntax error in ${basePath}: ${output.diagnostics[0].messageText}`); + throw new Error(`Syntax error in ${absoluteBasePath}: ${output.diagnostics[0].messageText}`); } runCode(output.outputText, state); } @@ -2811,12 +2882,12 @@ namespace FourSlashInterface { // Verifies the completion list contains the specified symbol. The // completion list is brought up if necessary - public completionListContains(symbol: string, text?: string, documentation?: string, kind?: string) { + public completionListContains(symbol: string, text?: string, documentation?: string, kind?: string, spanIndex?: number) { if (this.negative) { - this.state.verifyCompletionListDoesNotContain(symbol, text, documentation, kind); + this.state.verifyCompletionListDoesNotContain(symbol, text, documentation, kind, spanIndex); } else { - this.state.verifyCompletionListContains(symbol, text, documentation, kind); + this.state.verifyCompletionListContains(symbol, text, documentation, kind, spanIndex); } } @@ -2945,6 +3016,10 @@ namespace FourSlashInterface { this.state.verifyRangesReferenceEachOther(ranges); } + public findReferencesDefinitionDisplayPartsAtCaretAre(expected: ts.SymbolDisplayPart[]) { + this.state.verifyDisplayPartsOfReferencedSymbol(expected); + } + public rangesWithSameTextReferenceEachOther() { this.state.verifyRangesWithSameTextReferenceEachOther(); } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index e93d3d45189..429a1aab805 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -458,6 +458,9 @@ namespace Harness { // harness always uses one kind of new line const harnessNewLine = "\r\n"; + // Root for file paths that are stored in a virtual file system + export const virtualFileSystemRoot = "/"; + namespace IOImpl { declare class Enumerator { public atEnd(): boolean; @@ -1370,23 +1373,31 @@ namespace Harness { // Produce baselines. The first gives the types for all expressions. // The second gives symbols for all identifiers. - let e1: Error, e2: Error; + let typesError: Error, symbolsError: Error; try { checkBaseLines(/*isSymbolBaseLine*/ false); } catch (e) { - e1 = e; + typesError = e; } try { checkBaseLines(/*isSymbolBaseLine*/ true); } catch (e) { - e2 = e; + symbolsError = e; } - if (e1 || e2) { - throw e1 || e2; + if (typesError && symbolsError) { + throw new Error(typesError.message + ts.sys.newLine + symbolsError.message); + } + + if (typesError) { + throw typesError; + } + + if (symbolsError) { + throw symbolsError; } return; @@ -1396,7 +1407,12 @@ namespace Harness { const fullExtension = isSymbolBaseLine ? ".symbols" : ".types"; - Harness.Baseline.runBaseline(baselinePath.replace(/\.tsx?/, fullExtension), () => fullBaseLine, opts); + // When calling this function from rwc-runner, the baselinePath will have no extension. + // As rwc test- file is stored in json which ".json" will get stripped off. + // When calling this function from compiler-runner, the baselinePath will then has either ".ts" or ".tsx" extension + const outputFileName = ts.endsWith(baselinePath, ".ts") || ts.endsWith(baselinePath, ".tsx") ? + baselinePath.replace(/\.tsx?/, fullExtension) : baselinePath.concat(fullExtension); + Harness.Baseline.runBaseline(outputFileName, () => fullBaseLine, opts); } function generateBaseLine(typeWriterResults: ts.Map, isSymbolBaseline: boolean): string { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 2282f08bc07..d73f1b60624 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -123,7 +123,7 @@ namespace Harness.LanguageService { } export class LanguageServiceAdapterHost { - protected fileNameToScript = ts.createMap(); + protected virtualFileSystem: Utils.VirtualFileSystem = new Utils.VirtualFileSystem(virtualFileSystemRoot, /*useCaseSensitiveFilenames*/false); constructor(protected cancellationToken = DefaultHostCancellationToken.Instance, protected settings = ts.getDefaultCompilerOptions()) { @@ -135,22 +135,24 @@ namespace Harness.LanguageService { public getFilenames(): string[] { const fileNames: string[] = []; - ts.forEachProperty(this.fileNameToScript, (scriptInfo) => { + for (const virtualEntry of this.virtualFileSystem.getAllFileEntries()){ + const scriptInfo = virtualEntry.content; if (scriptInfo.isRootFile) { // only include root files here // usually it means that we won't include lib.d.ts in the list of root files so it won't mess the computation of compilation root dir. fileNames.push(scriptInfo.fileName); } - }); + } return fileNames; } public getScriptInfo(fileName: string): ScriptInfo { - return this.fileNameToScript[fileName]; + const fileEntry = this.virtualFileSystem.traversePath(fileName); + return fileEntry && fileEntry.isFile() ? (fileEntry).content : undefined; } public addScript(fileName: string, content: string, isRootFile: boolean): void { - this.fileNameToScript[fileName] = new ScriptInfo(fileName, content, isRootFile); + this.virtualFileSystem.addFile(fileName, new ScriptInfo(fileName, content, isRootFile)); } public editScript(fileName: string, start: number, end: number, newText: string) { @@ -171,7 +173,7 @@ namespace Harness.LanguageService { * @param col 0 based index */ public positionToLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter { - const script: ScriptInfo = this.fileNameToScript[fileName]; + const script: ScriptInfo = this.getScriptInfo(fileName); assert.isOk(script); return ts.computeLineAndCharacterOfPosition(script.getLineMap(), position); @@ -182,8 +184,14 @@ namespace Harness.LanguageService { class NativeLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceHost { getCompilationSettings() { return this.settings; } getCancellationToken() { return this.cancellationToken; } - getDirectories(path: string): string[] { return []; } - getCurrentDirectory(): string { return ""; } + getDirectories(path: string): string[] { + const dir = this.virtualFileSystem.traversePath(path); + if (dir && dir.isDirectory()) { + return ts.map((dir).getDirectories(), (d) => ts.combinePaths(path, d.name)); + } + return []; + } + getCurrentDirectory(): string { return virtualFileSystemRoot; } getDefaultLibFileName(): string { return Harness.Compiler.defaultLibFileName; } getScriptFileNames(): string[] { return this.getFilenames(); } getScriptSnapshot(fileName: string): ts.IScriptSnapshot { @@ -196,6 +204,22 @@ namespace Harness.LanguageService { return script ? script.version.toString() : undefined; } + fileExists(fileName: string): boolean { + const script = this.getScriptSnapshot(fileName); + return script !== undefined; + } + readDirectory(path: string, extensions?: string[], exclude?: string[], include?: string[]): string[] { + return ts.matchFiles(path, extensions, exclude, include, + /*useCaseSensitiveFileNames*/false, + this.getCurrentDirectory(), + (p) => this.virtualFileSystem.getAccessibleFileSystemEntries(p)); + } + readFile(path: string, encoding?: string): string { + const snapshot = this.getScriptSnapshot(path); + return snapshot.getText(0, snapshot.getLength()); + } + + log(s: string): void { } trace(s: string): void { } error(s: string): void { } diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index ba1ab71ec19..fff0d6bfb49 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -223,7 +223,8 @@ namespace RWC { }); it("has the expected types", () => { - Harness.Compiler.doTypeAndSymbolBaseline(`${baseName}.types`, compilerResult, inputFiles + // We don't need to pass the extension here because "doTypeAndSymbolBaseline" will append appropriate extension of ".types" or ".symbols" + Harness.Compiler.doTypeAndSymbolBaseline(baseName, compilerResult, inputFiles .concat(otherFiles) .filter(file => !!compilerResult.program.getSourceFile(file.unitName)) .filter(e => !Harness.isDefaultLibraryFile(e.unitName)), baselineOpts); diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/classes.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/classes.ts deleted file mode 100644 index e779f69810f..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/classes.ts +++ /dev/null @@ -1,79 +0,0 @@ - class a { - constructor ( n : number ) ; - constructor ( s : string ) ; - constructor ( ns : any ) { - - } - - public pgF ( ) { } ; - - public pv ; - public get d ( ) { - return 30 ; - } - public set d ( ) { - } - - public static get p2 ( ) { - return { x : 30 , y : 40 } ; - } - - private static d2 ( ) { - } - private static get p3 ( ) { - return "string" ; - } - private pv3 ; - - private foo ( n : number ) : string ; - private foo ( s : string ) : string ; - private foo ( ns : any ) { - return ns.toString ( ) ; - } -} - - class b extends a { -} - - class m1b { - -} - - interface m1ib { - - } - class c extends m1b { -} - - class ib2 implements m1ib { -} - - declare class aAmbient { - constructor ( n : number ) ; - constructor ( s : string ) ; - public pgF ( ) : void ; - public pv ; - public d : number ; - static p2 : { x : number ; y : number ; } ; - static d2 ( ) ; - static p3 ; - private pv3 ; - private foo ( s ) ; -} - - class d { - private foo ( n : number ) : string ; - private foo ( ns : any ) { - return ns.toString ( ) ; - } - private foo ( s : string ) : string ; -} - - class e { - private foo ( ns : any ) { - return ns.toString ( ) ; - } - private foo ( s : string ) : string ; - private foo ( n : number ) : string ; -} - diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/classesBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/classesBaseline.ts deleted file mode 100644 index e7e69b44125..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/classesBaseline.ts +++ /dev/null @@ -1,79 +0,0 @@ -class a { - constructor(n: number); - constructor(s: string); - constructor(ns: any) { - - } - - public pgF() { }; - - public pv; - public get d() { - return 30; - } - public set d() { - } - - public static get p2() { - return { x: 30, y: 40 }; - } - - private static d2() { - } - private static get p3() { - return "string"; - } - private pv3; - - private foo(n: number): string; - private foo(s: string): string; - private foo(ns: any) { - return ns.toString(); - } -} - -class b extends a { -} - -class m1b { - -} - -interface m1ib { - -} -class c extends m1b { -} - -class ib2 implements m1ib { -} - -declare class aAmbient { - constructor(n: number); - constructor(s: string); - public pgF(): void; - public pv; - public d: number; - static p2: { x: number; y: number; }; - static d2(); - static p3; - private pv3; - private foo(s); -} - -class d { - private foo(n: number): string; - private foo(ns: any) { - return ns.toString(); - } - private foo(s: string): string; -} - -class e { - private foo(ns: any) { - return ns.toString(); - } - private foo(s: string): string; - private foo(n: number): string; -} - diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/colonAndQMark.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/colonAndQMark.ts deleted file mode 100644 index 5562e142046..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/colonAndQMark.ts +++ /dev/null @@ -1,4 +0,0 @@ -class foo { - constructor (n?: number, m? = 5, o?: string = "") { } - x:number = 1?2:3; -} diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/colonAndQMarkBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/colonAndQMarkBaseline.ts deleted file mode 100644 index 52bbe56251d..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/colonAndQMarkBaseline.ts +++ /dev/null @@ -1,4 +0,0 @@ -class foo { - constructor(n?: number, m? = 5, o?: string = "") { } - x: number = 1 ? 2 : 3; -} diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/documentReadyFunction.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/documentReadyFunction.ts deleted file mode 100644 index 35daa4d895c..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/documentReadyFunction.ts +++ /dev/null @@ -1,3 +0,0 @@ -$ ( document ) . ready ( function ( ) { - alert ( 'i am ready' ) ; - } ); \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/documentReadyFunctionBaseLine.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/documentReadyFunctionBaseLine.ts deleted file mode 100644 index 838ef682207..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/documentReadyFunctionBaseLine.ts +++ /dev/null @@ -1,3 +0,0 @@ -$(document).ready(function() { - alert('i am ready'); -}); \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyBlock.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyBlock.ts deleted file mode 100644 index 9e26dfeeb6e..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyBlock.ts +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyBlockBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyBlockBaseline.ts deleted file mode 100644 index 6f31cf5a2e6..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyBlockBaseline.ts +++ /dev/null @@ -1 +0,0 @@ -{ } \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyInterfaceLiteral.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyInterfaceLiteral.ts deleted file mode 100644 index 1feec453d03..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyInterfaceLiteral.ts +++ /dev/null @@ -1,10 +0,0 @@ - function foo ( x : { } ) { } - -foo ( { } ) ; - - - - interface bar { - x : { } ; - y : ( ) => { } ; - } \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyInterfaceLiteralBaseLine.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyInterfaceLiteralBaseLine.ts deleted file mode 100644 index 04f3c0bc9b9..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/emptyInterfaceLiteralBaseLine.ts +++ /dev/null @@ -1,10 +0,0 @@ -function foo(x: {}) { } - -foo({}); - - - -interface bar { - x: {}; - y: () => {}; -} \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/fatArrowFunctions.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/fatArrowFunctions.ts deleted file mode 100644 index ebbf54557fa..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/fatArrowFunctions.ts +++ /dev/null @@ -1,112 +0,0 @@ -// valid - ( ) => 1 ; - ( arg ) => 2 ; - arg => 2 ; - ( arg = 1 ) => 3 ; - ( arg ? ) => 4 ; - ( arg : number ) => 5 ; - ( arg : number = 0 ) => 6 ; - ( arg ? : number ) => 7 ; - ( ... arg : number [ ] ) => 8 ; - ( arg1 , arg2 ) => 12 ; - ( arg1 = 1 , arg2 =3 ) => 13 ; - ( arg1 ? , arg2 ? ) => 14 ; - ( arg1 : number , arg2 : number ) => 15 ; - ( arg1 : number = 0 , arg2 : number = 1 ) => 16 ; - ( arg1 ? : number , arg2 ? : number ) => 17 ; - ( arg1 , ... arg2 : number [ ] ) => 18 ; - ( arg1 , arg2 ? : number ) => 19 ; - -// in paren - ( ( ) => 21 ) ; - ( ( arg ) => 22 ) ; - ( ( arg = 1 ) => 23 ) ; - ( ( arg ? ) => 24 ) ; - ( ( arg : number ) => 25 ) ; - ( ( arg : number = 0 ) => 26 ) ; - ( ( arg ? : number ) => 27 ) ; - ( ( ... arg : number [ ] ) => 28 ) ; - -// in multiple paren - ( ( ( ( ( arg ) => { return 32 ; } ) ) ) ) ; - -// in ternary exression - false ? ( ) => 41 : null ; - false ? ( arg ) => 42 : null ; - false ? ( arg = 1 ) => 43 : null ; - false ? ( arg ? ) => 44 : null ; - false ? ( arg : number ) => 45 : null ; - false ? ( arg ? : number ) => 46 : null ; - false ? ( arg ? : number = 0 ) => 47 : null ; - false ? ( ... arg : number [ ] ) => 48 : null ; - -// in ternary exression within paren - false ? ( ( ) => 51 ) : null ; - false ? ( ( arg ) => 52 ) : null ; - false ? ( ( arg = 1 ) => 53 ) : null ; - false ? ( ( arg ? ) => 54 ) : null ; - false ? ( ( arg : number ) => 55 ) : null ; - false ? ( ( arg ? : number ) => 56 ) : null ; - false ? ( ( arg ? : number = 0 ) => 57 ) : null ; - false ? ( ( ... arg : number [ ] ) => 58 ) : null ; - -// ternary exression's else clause - false ? null : ( ) => 61 ; - false ? null : ( arg ) => 62 ; - false ? null : ( arg = 1 ) => 63 ; - false ? null : ( arg ? ) => 64 ; - false ? null : ( arg : number ) => 65 ; - false ? null : ( arg ? : number ) => 66 ; - false ? null : ( arg ? : number = 0 ) => 67 ; - false ? null : ( ... arg : number [ ] ) => 68 ; - - -// nested ternary expressions - ( a ? ) => { return a ; } ? ( b ? ) => { return b ; } : ( c ? ) => { return c ; } ; - -//multiple levels - ( a ? ) => { return a ; } ? ( b ) => ( c ) => 81 : ( c ) => ( d ) => 82 ; - - -// In Expressions - ( ( arg ) => 90 ) instanceof Function ; - ( ( arg = 1 ) => 91 ) instanceof Function ; - ( ( arg ? ) => 92 ) instanceof Function ; - ( ( arg : number ) => 93 ) instanceof Function ; - ( ( arg : number = 1 ) => 94 ) instanceof Function ; - ( ( arg ? : number ) => 95 ) instanceof Function ; - ( ( ... arg : number [ ] ) => 96 ) instanceof Function ; - -'' + ( arg ) => 100 ; - ( ( arg ) => 0 ) + '' + ( arg ) => 101 ; - ( ( arg = 1 ) => 0 ) + '' + ( arg = 2 ) => 102 ; - ( ( arg ? ) => 0 ) + '' + ( arg ? ) => 103 ; - ( ( arg : number ) => 0 ) + '' + ( arg : number ) => 104 ; - ( ( arg : number = 1 ) => 0 ) + '' + ( arg : number = 2 ) => 105 ; - ( ( arg ? : number = 1 ) => 0 ) + '' + ( arg ? : number = 2 ) => 106 ; - ( ( ... arg : number [ ] ) => 0 ) + '' + ( ... arg : number [ ] ) => 107 ; - ( ( arg1 , arg2 ? ) => 0 ) + '' + ( arg1 , arg2 ? ) => 108 ; - ( ( arg1 , ... arg2 : number [ ] ) => 0 ) + '' + ( arg1 , ... arg2 : number [ ] ) => 108 ; - - -// Function Parameters -function foo ( ... arg : any [ ] ) { } - -foo ( - ( a ) => 110 , - ( ( a ) => 111 ) , - ( a ) => { - return 112 ; - } , - ( a ? ) => 113 , - ( a , b ? ) => 114 , - ( a : number ) => 115 , - ( a : number = 0 ) => 116 , - ( a = 0 ) => 117 , - ( a ? : number = 0 ) => 118 , - ( a ? , b ? : number = 0 ) => 118 , - ( ... a : number [ ] ) => 119 , - ( a , b ? = 0 , ... c : number [ ] ) => 120 , - ( a ) => ( b ) => ( c ) => 121 , - false ? ( a ) => 0 : ( b ) => 122 - ) ; \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/fatArrowFunctionsBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/fatArrowFunctionsBaseline.ts deleted file mode 100644 index 7a1ef86f5af..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/fatArrowFunctionsBaseline.ts +++ /dev/null @@ -1,112 +0,0 @@ -// valid -() => 1; -(arg) => 2; -arg => 2; -(arg = 1) => 3; -(arg?) => 4; -(arg: number) => 5; -(arg: number = 0) => 6; -(arg?: number) => 7; -(...arg: number[]) => 8; -(arg1, arg2) => 12; -(arg1 = 1, arg2 = 3) => 13; -(arg1?, arg2?) => 14; -(arg1: number, arg2: number) => 15; -(arg1: number = 0, arg2: number = 1) => 16; -(arg1?: number, arg2?: number) => 17; -(arg1, ...arg2: number[]) => 18; -(arg1, arg2?: number) => 19; - -// in paren -(() => 21); -((arg) => 22); -((arg = 1) => 23); -((arg?) => 24); -((arg: number) => 25); -((arg: number = 0) => 26); -((arg?: number) => 27); -((...arg: number[]) => 28); - -// in multiple paren -(((((arg) => { return 32; })))); - -// in ternary exression -false ? () => 41 : null; -false ? (arg) => 42 : null; -false ? (arg = 1) => 43 : null; -false ? (arg?) => 44 : null; -false ? (arg: number) => 45 : null; -false ? (arg?: number) => 46 : null; -false ? (arg?: number = 0) => 47 : null; -false ? (...arg: number[]) => 48 : null; - -// in ternary exression within paren -false ? (() => 51) : null; -false ? ((arg) => 52) : null; -false ? ((arg = 1) => 53) : null; -false ? ((arg?) => 54) : null; -false ? ((arg: number) => 55) : null; -false ? ((arg?: number) => 56) : null; -false ? ((arg?: number = 0) => 57) : null; -false ? ((...arg: number[]) => 58) : null; - -// ternary exression's else clause -false ? null : () => 61; -false ? null : (arg) => 62; -false ? null : (arg = 1) => 63; -false ? null : (arg?) => 64; -false ? null : (arg: number) => 65; -false ? null : (arg?: number) => 66; -false ? null : (arg?: number = 0) => 67; -false ? null : (...arg: number[]) => 68; - - -// nested ternary expressions -(a?) => { return a; } ? (b?) => { return b; } : (c?) => { return c; }; - -//multiple levels -(a?) => { return a; } ? (b) => (c) => 81 : (c) => (d) => 82; - - -// In Expressions -((arg) => 90) instanceof Function; -((arg = 1) => 91) instanceof Function; -((arg?) => 92) instanceof Function; -((arg: number) => 93) instanceof Function; -((arg: number = 1) => 94) instanceof Function; -((arg?: number) => 95) instanceof Function; -((...arg: number[]) => 96) instanceof Function; - -'' + (arg) => 100; -((arg) => 0) + '' + (arg) => 101; -((arg = 1) => 0) + '' + (arg = 2) => 102; -((arg?) => 0) + '' + (arg?) => 103; -((arg: number) => 0) + '' + (arg: number) => 104; -((arg: number = 1) => 0) + '' + (arg: number = 2) => 105; -((arg?: number = 1) => 0) + '' + (arg?: number = 2) => 106; -((...arg: number[]) => 0) + '' + (...arg: number[]) => 107; -((arg1, arg2?) => 0) + '' + (arg1, arg2?) => 108; -((arg1, ...arg2: number[]) => 0) + '' + (arg1, ...arg2: number[]) => 108; - - -// Function Parameters -function foo(...arg: any[]) { } - -foo( - (a) => 110, - ((a) => 111), - (a) => { - return 112; - }, - (a?) => 113, - (a, b?) => 114, - (a: number) => 115, - (a: number = 0) => 116, - (a = 0) => 117, - (a?: number = 0) => 118, - (a?, b?: number = 0) => 118, - (...a: number[]) => 119, - (a, b? = 0, ...c: number[]) => 120, - (a) => (b) => (c) => 121, - false ? (a) => 0 : (b) => 122 - ); \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatDebuggerStatement.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatDebuggerStatement.ts deleted file mode 100644 index 314cd416a81..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatDebuggerStatement.ts +++ /dev/null @@ -1,2 +0,0 @@ -if(false){debugger;} - if ( false ) { debugger ; } \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatDebuggerStatementBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatDebuggerStatementBaseline.ts deleted file mode 100644 index c03acf91ecf..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatDebuggerStatementBaseline.ts +++ /dev/null @@ -1,2 +0,0 @@ -if (false) { debugger; } -if (false) { debugger; } \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatvariableDeclarationList.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatvariableDeclarationList.ts deleted file mode 100644 index 956309d2c4d..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatvariableDeclarationList.ts +++ /dev/null @@ -1,13 +0,0 @@ -var fun1 = function ( ) { - var x = 'foo' , - z = 'bar' ; - return x ; -}, - -fun2 = ( function ( f ) { - var fun = function ( ) { - console . log ( f ( ) ) ; - }, - x = 'Foo' ; - return fun ; -} ( fun1 ) ) ; diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatvariableDeclarationListBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatvariableDeclarationListBaseline.ts deleted file mode 100644 index f1d32283fd7..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/formatvariableDeclarationListBaseline.ts +++ /dev/null @@ -1,13 +0,0 @@ -var fun1 = function() { - var x = 'foo', - z = 'bar'; - return x; -}, - -fun2 = (function(f) { - var fun = function() { - console.log(f()); - }, - x = 'Foo'; - return fun; -} (fun1)); diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/implicitModule.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/implicitModule.ts deleted file mode 100644 index 352a252593b..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/implicitModule.ts +++ /dev/null @@ -1,3 +0,0 @@ - export class A { - - } diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/implicitModuleBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/implicitModuleBaseline.ts deleted file mode 100644 index df93540466f..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/implicitModuleBaseline.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class A { - -} diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/importDeclaration.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/importDeclaration.ts deleted file mode 100644 index afd010fe8b7..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/importDeclaration.ts +++ /dev/null @@ -1,6 +0,0 @@ -module Foo { -} - -import bar = Foo; - -import bar2=Foo; diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/importDeclarationBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/importDeclarationBaseline.ts deleted file mode 100644 index d0a4e190d95..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/importDeclarationBaseline.ts +++ /dev/null @@ -1,6 +0,0 @@ -module Foo { -} - -import bar = Foo; - -import bar2 = Foo; diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/main.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/main.ts deleted file mode 100644 index 7640013af8b..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/main.ts +++ /dev/null @@ -1,95 +0,0 @@ - -var a;var c , b;var $d -var $e -var f -a++;b++; - -function f ( ) { - for (i = 0; i < 10; i++) { - k = abc + 123 ^ d; - a = XYZ[m (a[b[c][d]])]; - break; - - switch ( variable){ - case 1: abc += 425; -break; -case 404 : a [x--/2]%=3 ; - break ; - case vari : v[--x ] *=++y*( m + n / k[z]); - for (a in b){ - for (a = 0; a < 10; ++a) { - a++;--a; - if (a == b) { - a++;b--; - } -else -if (a == c){ -++a; -(--c)+=d; -$c = $a + --$b; -} -if (a == b) -if (a != b) { - if (a !== b) - if (a === b) - --a; - else - --a; - else { - a--;++b; -a++ - } - } - } - for (x in y) { -m-=m; -k=1+2+3+4; -} -} - break; - - } - } - var a ={b:function(){}}; - return {a:1,b:2} -} - -var z = 1; - for (i = 0; i < 10; i++) - for (j = 0; j < 10; j++) -for (k = 0; k < 10; ++k) { -z++; -} - -for (k = 0; k < 10; k += 2) { -z++; -} - - $(document).ready (); - - - function pageLoad() { - $('#TextBox1' ) . unbind ( ) ; -$('#TextBox1' ) . datepicker ( ) ; -} - - function pageLoad ( ) { - var webclass=[ - { 'student' : - { 'id': '1', 'name': 'Linda Jones', 'legacySkill': 'Access, VB 5.0' } - } , -{ 'student': -{'id':'2','name':'Adam Davidson','legacySkill':'Cobol,MainFrame'} -} , - { 'student': -{ 'id':'3','name':'Charles Boyer' ,'legacySkill':'HTML, XML'} -} - ]; - -$create(Sys.UI.DataView,{data:webclass},null,null,$get('SList')); - -} - -$( document ).ready(function(){ -alert('hello'); - } ) ; diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/mainBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/mainBaseline.ts deleted file mode 100644 index 30756f547ca..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/mainBaseline.ts +++ /dev/null @@ -1,98 +0,0 @@ - -var a; var c, b; var $d -var $e -var f -a++; b++; - -function f() { - for (i = 0; i < 10; i++) { - k = abc + 123 ^ d; - a = XYZ[m(a[b[c][d]])]; - break; - - switch (variable) { - case 1: abc += 425; - break; - case 404: a[x-- / 2] %= 3; - break; - case vari: v[--x] *= ++y * (m + n / k[z]); - for (a in b) { - for (a = 0; a < 10; ++a) { - a++; --a; - if (a == b) { - a++; b--; - } - else - if (a == c) { - ++a; - (--c) += d; - $c = $a + --$b; - } - if (a == b) - if (a != b) { - if (a !== b) - if (a === b) - --a; - else - --a; - else { - a--; ++b; - a++ - } - } - } - for (x in y) { - m -= m; - k = 1 + 2 + 3 + 4; - } - } - break; - - } - } - var a = { b: function() { } }; - return { a: 1, b: 2 } -} - -var z = 1; -for (i = 0; i < 10; i++) - for (j = 0; j < 10; j++) - for (k = 0; k < 10; ++k) { - z++; - } - -for (k = 0; k < 10; k += 2) { - z++; -} - -$(document).ready(); - - -function pageLoad() { - $('#TextBox1').unbind(); - $('#TextBox1').datepicker(); -} - -function pageLoad() { - var webclass = [ - { - 'student': - { 'id': '1', 'name': 'Linda Jones', 'legacySkill': 'Access, VB 5.0' } - }, -{ - 'student': - { 'id': '2', 'name': 'Adam Davidson', 'legacySkill': 'Cobol,MainFrame' } -}, - { - 'student': - { 'id': '3', 'name': 'Charles Boyer', 'legacySkill': 'HTML, XML' } - } - ]; - - $create(Sys.UI.DataView, { data: webclass }, null, null, $get('SList')); - -} - -$(document).ready(function() { - alert('hello'); -}); diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/moduleIndentation.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/moduleIndentation.ts deleted file mode 100644 index 3030a36630a..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/moduleIndentation.ts +++ /dev/null @@ -1,3 +0,0 @@ - module Foo { - export module A . B . C { } - } \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/moduleIndentationBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/moduleIndentationBaseline.ts deleted file mode 100644 index 0013b367dcf..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/moduleIndentationBaseline.ts +++ /dev/null @@ -1,3 +0,0 @@ -module Foo { - export module A.B.C { } -} \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/modules.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/modules.ts deleted file mode 100644 index 5ce0d19b632..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/modules.ts +++ /dev/null @@ -1,76 +0,0 @@ - module mod1 { - export class b { - } - class d { - } - - - export interface ib { - } -} - - module m2 { - - export module m3 { - export class c extends mod1.b { - } - export class ib2 implements mod1.ib { - } - } -} - - class c extends mod1.b { -} - - class ib2 implements mod1.ib { -} - - declare export module "m4" { - export class d { - } ; - var x : d ; - export function foo ( ) : d ; -} - - import m4 = module ( "m4" ) ; - export var x4 = m4.x ; - export var d4 = m4.d ; - export var f4 = m4.foo ( ) ; - - export module m1 { - declare export module "m2" { - export class d { - } ; - var x: d ; - export function foo ( ) : d ; - } - import m2 = module ( "m2" ) ; - import m3 = module ( "m4" ) ; - - export var x2 = m2.x ; - export var d2 = m2.d ; - export var f2 = m2.foo ( ) ; - - export var x3 = m3.x ; - export var d3 = m3.d ; - export var f3 = m3.foo ( ) ; -} - - export var x2 = m1.m2.x ; - export var d2 = m1.m2.d ; - export var f2 = m1.m2.foo ( ) ; - - export var x3 = m1.m3.x ; - export var d3 = m1.m3.d ; - export var f3 = m1.m3.foo ( ) ; - - export module m5 { - export var x2 = m1.m2.x ; - export var d2 = m1.m2.d ; - export var f2 = m1.m2.foo ( ) ; - - export var x3 = m1.m3.x ; - export var d3 = m1.m3.d ; - export var f3 = m1.m3.foo ( ) ; -} - diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/modulesBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/modulesBaseline.ts deleted file mode 100644 index e6f62024fe6..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/modulesBaseline.ts +++ /dev/null @@ -1,76 +0,0 @@ -module mod1 { - export class b { - } - class d { - } - - - export interface ib { - } -} - -module m2 { - - export module m3 { - export class c extends mod1.b { - } - export class ib2 implements mod1.ib { - } - } -} - -class c extends mod1.b { -} - -class ib2 implements mod1.ib { -} - -declare export module "m4" { - export class d { - }; - var x: d; - export function foo(): d; -} - -import m4 = module("m4"); -export var x4 = m4.x; -export var d4 = m4.d; -export var f4 = m4.foo(); - -export module m1 { - declare export module "m2" { - export class d { - }; - var x: d; - export function foo(): d; - } - import m2 = module("m2"); - import m3 = module("m4"); - - export var x2 = m2.x; - export var d2 = m2.d; - export var f2 = m2.foo(); - - export var x3 = m3.x; - export var d3 = m3.d; - export var f3 = m3.foo(); -} - -export var x2 = m1.m2.x; -export var d2 = m1.m2.d; -export var f2 = m1.m2.foo(); - -export var x3 = m1.m3.x; -export var d3 = m1.m3.d; -export var f3 = m1.m3.foo(); - -export module m5 { - export var x2 = m1.m2.x; - export var d2 = m1.m2.d; - export var f2 = m1.m2.foo(); - - export var x3 = m1.m3.x; - export var d3 = m1.m3.d; - export var f3 = m1.m3.foo(); -} - diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/objectLiteral.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/objectLiteral.ts deleted file mode 100644 index dbecc4d4fec..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/objectLiteral.ts +++ /dev/null @@ -1,27 +0,0 @@ -var x = {foo: 1, -bar: "tt", -boo: 1 + 5}; - -var x2 = {foo: 1, -bar: "tt",boo:1+5}; - -function Foo() { -var typeICalc = { -clear: { -"()": [1, 2, 3] -} -} -} - -// Rule for object literal members for the "value" of the memebr to follow the indent -// of the member, i.e. the relative position of the value is maintained when the member -// is indented. -var x2 = { - foo: -3, - 'bar': - { a: 1, b : 2} -}; - -var x={ }; -var y = {}; \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/objectLiteralBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/objectLiteralBaseline.ts deleted file mode 100644 index 3a7fa63d927..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/objectLiteralBaseline.ts +++ /dev/null @@ -1,31 +0,0 @@ -var x = { - foo: 1, - bar: "tt", - boo: 1 + 5 -}; - -var x2 = { - foo: 1, - bar: "tt", boo: 1 + 5 -}; - -function Foo() { - var typeICalc = { - clear: { - "()": [1, 2, 3] - } - } -} - -// Rule for object literal members for the "value" of the memebr to follow the indent -// of the member, i.e. the relative position of the value is maintained when the member -// is indented. -var x2 = { - foo: - 3, - 'bar': - { a: 1, b: 2 } -}; - -var x = {}; -var y = {}; \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/onClosingBracket.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/onClosingBracket.ts deleted file mode 100644 index 0161f04308d..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/onClosingBracket.ts +++ /dev/null @@ -1,32 +0,0 @@ -function f( ) { -var x = 3; - var z = 2 ; - a = z ++ - 2 * x ; - for ( ; ; ) { - a+=(g +g)*a%t; - b -- ; -} - - switch ( a ) - { - case 1 : { - a ++ ; - b--; - if(a===a) - return; - else - { - for(a in b) - if(a!=a) - { - for(a in b) - { -a++; - } - } - } - } - default: - break; - } -} diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/onClosingBracketBaseLine.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/onClosingBracketBaseLine.ts deleted file mode 100644 index 051a4ebd13a..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/onClosingBracketBaseLine.ts +++ /dev/null @@ -1,28 +0,0 @@ -function f() { - var x = 3; - var z = 2; - a = z++ - 2 * x; - for (; ;) { - a += (g + g) * a % t; - b--; - } - - switch (a) { - case 1: { - a++; - b--; - if (a === a) - return; - else { - for (a in b) - if (a != a) { - for (a in b) { - a++; - } - } - } - } - default: - break; - } -} diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/onSemiColon.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/onSemiColon.ts deleted file mode 100644 index 3b5b5456a6f..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/onSemiColon.ts +++ /dev/null @@ -1 +0,0 @@ -var a=b+c^d-e*++f; \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/onSemiColonBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/onSemiColonBaseline.ts deleted file mode 100644 index 2ba96e4f88a..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/onSemiColonBaseline.ts +++ /dev/null @@ -1 +0,0 @@ -var a = b + c ^ d - e * ++f; \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/spaceAfterConstructor.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/spaceAfterConstructor.ts deleted file mode 100644 index 7d98d5a8f43..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/spaceAfterConstructor.ts +++ /dev/null @@ -1 +0,0 @@ -class test { constructor () { } } \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/spaceAfterConstructorBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/spaceAfterConstructorBaseline.ts deleted file mode 100644 index bc124d41baf..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/spaceAfterConstructorBaseline.ts +++ /dev/null @@ -1 +0,0 @@ -class test { constructor() { } } \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/tabAfterCloseCurly.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/tabAfterCloseCurly.ts deleted file mode 100644 index ec093e0e376..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/tabAfterCloseCurly.ts +++ /dev/null @@ -1,10 +0,0 @@ -module Tools { - export enum NodeType { - Error, - Comment, - } - export enum foob - { - Blah=1, Bleah=2 - } -} \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/tabAfterCloseCurlyBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/tabAfterCloseCurlyBaseline.ts deleted file mode 100644 index d0a3db2d51a..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/tabAfterCloseCurlyBaseline.ts +++ /dev/null @@ -1,9 +0,0 @@ -module Tools { - export enum NodeType { - Error, - Comment, - } - export enum foob { - Blah = 1, Bleah = 2 - } -} \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/typescriptConstructs.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/typescriptConstructs.ts deleted file mode 100644 index 43ef3710ef1..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/typescriptConstructs.ts +++ /dev/null @@ -1,65 +0,0 @@ - module MyModule - { - module A.B.C { -module F { -} - } -interface Blah -{ -boo: string; -} - - class Foo - { - -} - -class Foo2 { -public foo():number { -return 5 * 6; -} -public foo2() { -if (1 === 2) - - -{ -var y : number= 76; -return y; -} - - while (2 == 3) { - if ( y == null ) { - -} - } -} - -public foo3() { -if (1 === 2) - -//comment preventing line merging -{ -var y = 76; -return y; -} - -} - } - } - -function foo(a:number, b:number):number -{ -return 0; -} - -function bar(a:number, b:number) :number[] { -return []; -} - -module BugFix3 { -declare var f: { - (): any; - (x: number): string; - foo: number; -}; -} diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/typescriptConstructsBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/typescriptConstructsBaseline.ts deleted file mode 100644 index 929334e4730..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/typescriptConstructsBaseline.ts +++ /dev/null @@ -1,58 +0,0 @@ -module MyModule { - module A.B.C { - module F { - } - } - interface Blah { - boo: string; - } - - class Foo { - - } - - class Foo2 { - public foo(): number { - return 5 * 6; - } - public foo2() { - if (1 === 2) { - var y: number = 76; - return y; - } - - while (2 == 3) { - if (y == null) { - - } - } - } - - public foo3() { - if (1 === 2) - - //comment preventing line merging - { - var y = 76; - return y; - } - - } - } -} - -function foo(a: number, b: number): number { - return 0; -} - -function bar(a: number, b: number): number[] { - return []; -} - -module BugFix3 { - declare var f: { - (): any; - (x: number): string; - foo: number; - }; -} diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/various.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/various.ts deleted file mode 100644 index bd814c2348e..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/various.ts +++ /dev/null @@ -1,17 +0,0 @@ -function f(a,b,c,d){ -for(var i=0;i<10;i++){ -var a=0; -var b=a+a+a*a%a/2-1; -b+=a; -++b; -f(a,b,c,d); -if(1===1){ -var m=function(e,f){ -return e^f; -} -} -} -} - -for (var i = 0 ; i < this.foo(); i++) { -} \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/variousBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/variousBaseline.ts deleted file mode 100644 index a4b5ceeb1c2..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/variousBaseline.ts +++ /dev/null @@ -1,17 +0,0 @@ -function f(a, b, c, d) { - for (var i = 0; i < 10; i++) { - var a = 0; - var b = a + a + a * a % a / 2 - 1; - b += a; - ++b; - f(a, b, c, d); - if (1 === 1) { - var m = function(e, f) { - return e ^ f; - } - } - } -} - -for (var i = 0 ; i < this.foo(); i++) { -} \ No newline at end of file diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/withStatement.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/withStatement.ts deleted file mode 100644 index 66ec4bf546f..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/withStatement.ts +++ /dev/null @@ -1,9 +0,0 @@ -with (foo.bar) - - { - - } - -with (bar.blah) -{ -} diff --git a/src/harness/unittests/services/formatting/testCode/testCode/formatting/withStatementBaseline.ts b/src/harness/unittests/services/formatting/testCode/testCode/formatting/withStatementBaseline.ts deleted file mode 100644 index f81378d7f82..00000000000 --- a/src/harness/unittests/services/formatting/testCode/testCode/formatting/withStatementBaseline.ts +++ /dev/null @@ -1,6 +0,0 @@ -with (foo.bar) { - -} - -with (bar.blah) { -} diff --git a/src/harness/virtualFileSystem.ts b/src/harness/virtualFileSystem.ts index 30192b8b8ec..b6d234acd59 100644 --- a/src/harness/virtualFileSystem.ts +++ b/src/harness/virtualFileSystem.ts @@ -16,7 +16,7 @@ namespace Utils { } export class VirtualFile extends VirtualFileSystemEntry { - content: string; + content?: Harness.LanguageService.ScriptInfo; isFile() { return true; } } @@ -73,7 +73,7 @@ namespace Utils { } } - addFile(name: string, content?: string): VirtualFile { + addFile(name: string, content?: Harness.LanguageService.ScriptInfo): VirtualFile { const entry = this.getFileSystemEntry(name); if (entry === undefined) { const file = new VirtualFile(this.fileSystem, name); @@ -111,6 +111,7 @@ namespace Utils { getFileSystemEntries() { return this.root.getFileSystemEntries(); } addDirectory(path: string) { + path = ts.normalizePath(path); const components = ts.getNormalizedPathComponents(path, this.currentDirectory); let directory: VirtualDirectory = this.root; for (const component of components) { @@ -123,8 +124,8 @@ namespace Utils { return directory; } - addFile(path: string, content?: string) { - const absolutePath = ts.getNormalizedAbsolutePath(path, this.currentDirectory); + addFile(path: string, content?: Harness.LanguageService.ScriptInfo) { + const absolutePath = ts.normalizePath(ts.getNormalizedAbsolutePath(path, this.currentDirectory)); const fileName = ts.getBaseFileName(path); const directoryPath = ts.getDirectoryPath(absolutePath); const directory = this.addDirectory(directoryPath); @@ -141,6 +142,7 @@ namespace Utils { } traversePath(path: string) { + path = ts.normalizePath(path); let directory: VirtualDirectory = this.root; for (const component of ts.getNormalizedPathComponents(path, this.currentDirectory)) { const entry = directory.getFileSystemEntry(component); @@ -157,6 +159,40 @@ namespace Utils { return directory; } + + /** + * Reads the directory at the given path and retrieves a list of file names and a list + * of directory names within it. Suitable for use with ts.matchFiles() + * @param path The path to the directory to be read + */ + getAccessibleFileSystemEntries(path: string) { + const entry = this.traversePath(path); + if (entry && entry.isDirectory()) { + const directory = entry; + return { + files: ts.map(directory.getFiles(), f => f.name), + directories: ts.map(directory.getDirectories(), d => d.name) + }; + } + return { files: [], directories: [] }; + } + + getAllFileEntries() { + const fileEntries: VirtualFile[] = []; + getFilesRecursive(this.root, fileEntries); + return fileEntries; + + function getFilesRecursive(dir: VirtualDirectory, result: VirtualFile[]) { + const files = dir.getFiles(); + const dirs = dir.getDirectories(); + for (const file of files) { + result.push(file); + } + for (const subDir of dirs) { + getFilesRecursive(subDir, result); + } + } + } } export class MockParseConfigHost extends VirtualFileSystem implements ts.ParseConfigHost { @@ -170,17 +206,5 @@ namespace Utils { readDirectory(path: string, extensions: string[], excludes: string[], includes: string[]) { return ts.matchFiles(path, extensions, excludes, includes, this.useCaseSensitiveFileNames, this.currentDirectory, (path: string) => this.getAccessibleFileSystemEntries(path)); } - - getAccessibleFileSystemEntries(path: string) { - const entry = this.traversePath(path); - if (entry && entry.isDirectory()) { - const directory = entry; - return { - files: ts.map(directory.getFiles(), f => f.name), - directories: ts.map(directory.getDirectories(), d => d.name) - }; - } - return { files: [], directories: [] }; - } } } \ No newline at end of file diff --git a/src/server/client.ts b/src/server/client.ts index 88177e91fad..ca2d517701f 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -216,7 +216,18 @@ namespace ts.server { return { isMemberCompletion: false, isNewIdentifierLocation: false, - entries: response.body + entries: response.body.map(entry => { + + if (entry.replacementSpan !== undefined) { + const { name, kind, kindModifiers, sortText, replacementSpan} = entry; + + const convertedSpan = createTextSpanFromBounds(this.lineOffsetToPosition(fileName, replacementSpan.start), + this.lineOffsetToPosition(fileName, replacementSpan.end)); + return { name, kind, kindModifiers, sortText, replacementSpan: convertedSpan }; + } + + return entry as { name: string, kind: string, kindModifiers: string, sortText: string }; + }) }; } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index a840a73b73e..5cc3bf47f8c 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -341,6 +341,7 @@ namespace ts.server { // capture list of projects since detachAllProjects will wipe out original list const containingProjects = info.containingProjects.slice(); + info.detachAllProjects(); // update projects to make sure that set of referenced files is correct diff --git a/src/server/lsHost.ts b/src/server/lsHost.ts index bf460d404b3..fd933bace10 100644 --- a/src/server/lsHost.ts +++ b/src/server/lsHost.ts @@ -146,7 +146,7 @@ namespace ts.server { } getCurrentDirectory(): string { - return ""; + return this.host.getCurrentDirectory(); } resolvePath(path: string): string { diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index 79fd49d747c..8d88c761bac 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -965,6 +965,11 @@ declare namespace ts.server.protocol { * is often the same as the name but may be different in certain circumstances. */ sortText: string; + /** + * An optional span that indicates the text to be replaced by this completion item. If present, + * this span should be used instead of the default one. + */ + replacementSpan?: TextSpan; } /** diff --git a/src/server/session.ts b/src/server/session.ts index fc6b4669b13..7b086f014fe 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -923,7 +923,17 @@ namespace ts.server { if (simplifiedResult) { return completions.entries.reduce((result: protocol.CompletionEntry[], entry: ts.CompletionEntry) => { if (completions.isMemberCompletion || (entry.name.toLowerCase().indexOf(prefix.toLowerCase()) === 0)) { - result.push(entry); + const { name, kind, kindModifiers, sortText, replacementSpan } = entry; + + let convertedSpan: protocol.TextSpan = undefined; + if (replacementSpan) { + convertedSpan = { + start: scriptInfo.positionToLineOffset(replacementSpan.start), + end: scriptInfo.positionToLineOffset(replacementSpan.start + replacementSpan.length) + }; + } + + result.push({ name, kind, kindModifiers, sortText, replacementSpan: convertedSpan }); } return result; }, []).sort((a, b) => a.name.localeCompare(b.name)); diff --git a/src/services/services.ts b/src/services/services.ts index fa7fd760c5a..b0d20599a69 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1177,6 +1177,14 @@ namespace ts { error?(s: string): void; useCaseSensitiveFileNames?(): boolean; + /* + * LS host can optionally implement these methods to support completions for module specifiers. + * Without these methods, only completions for ambient modules will be provided. + */ + readDirectory?(path: string, extensions?: string[], exclude?: string[], include?: string[]): string[]; + readFile?(path: string, encoding?: string): string; + fileExists?(path: string): boolean; + /* * LS host can optionally implement this method if it wants to be completely in charge of module name resolution. * if implementation is omitted then language service will use built-in module resolution logic and get answers to @@ -1185,6 +1193,11 @@ namespace ts { resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[]; directoryExists?(directoryName: string): boolean; + + /* + * getDirectories is also required for full import and type reference completions. Without it defined, certain + * completions will not be provided + */ getDirectories?(directoryName: string): string[]; } @@ -1442,8 +1455,12 @@ namespace ts { containerName: string; } + export interface ReferencedSymbolDefinitionInfo extends DefinitionInfo { + displayParts: SymbolDisplayPart[]; + } + export interface ReferencedSymbol { - definition: DefinitionInfo; + definition: ReferencedSymbolDefinitionInfo; references: ReferenceEntry[]; } @@ -1540,6 +1557,12 @@ namespace ts { kind: string; // see ScriptElementKind kindModifiers: string; // see ScriptElementKindModifier, comma separated sortText: string; + /** + * An optional span that indicates the text to be replaced by this completion item. It will be + * set if the required span differs from the one generated by the default replacement behavior and should + * be used in that case + */ + replacementSpan?: TextSpan; } export interface CompletionEntryDetails { @@ -1822,6 +1845,10 @@ namespace ts { export const constElement = "const"; export const letElement = "let"; + + export const directory = "directory"; + + export const externalModuleName = "external module name"; } export namespace ScriptElementKindModifier { @@ -1910,6 +1937,11 @@ namespace ts { owners: string[]; } + interface VisibleModuleInfo { + moduleName: string; + moduleDir: string; + } + export interface DisplayPartsSymbolWriter extends SymbolWriter { displayParts(): SymbolDisplayPart[]; } @@ -2062,7 +2094,15 @@ namespace ts { sourceMapText?: string; } + /** + * Matches a triple slash reference directive with an incomplete string literal for its path. Used + * to determine if the caret is currently within the string literal and capture the literal fragment + * for completions. + * For example, this matches /// node); + } else { const argumentInfo = SignatureHelp.getContainingArgumentInfo(node, position, sourceFile); if (argumentInfo) { @@ -4552,6 +4607,486 @@ namespace ts { } } } + + function getStringLiteralCompletionEntriesFromModuleNames(node: StringLiteral): CompletionInfo { + const literalValue = normalizeSlashes(node.text); + + const scriptPath = node.getSourceFile().path; + const scriptDirectory = getDirectoryPath(scriptPath); + + const span = getDirectoryFragmentTextSpan((node).text, node.getStart() + 1); + let entries: CompletionEntry[]; + if (isPathRelativeToScript(literalValue) || isRootedDiskPath(literalValue)) { + const compilerOptions = program.getCompilerOptions(); + if (compilerOptions.rootDirs) { + entries = getCompletionEntriesForDirectoryFragmentWithRootDirs( + compilerOptions.rootDirs, literalValue, scriptDirectory, getSupportedExtensions(program.getCompilerOptions()), /*includeExtensions*/false, span, scriptPath); + } + else { + entries = getCompletionEntriesForDirectoryFragment( + literalValue, scriptDirectory, getSupportedExtensions(program.getCompilerOptions()), /*includeExtensions*/false, span, scriptPath); + } + } + else { + // Check for node modules + entries = getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, span); + } + return { + isMemberCompletion: false, + isNewIdentifierLocation: true, + entries + }; + } + + /** + * Takes a script path and returns paths for all potential folders that could be merged with its + * containing folder via the "rootDirs" compiler option + */ + function getBaseDirectoriesFromRootDirs(rootDirs: string[], basePath: string, scriptPath: string, ignoreCase: boolean): string[] { + // Make all paths absolute/normalized if they are not already + rootDirs = map(rootDirs, rootDirectory => normalizePath(isRootedDiskPath(rootDirectory) ? rootDirectory : combinePaths(basePath, rootDirectory))); + + // Determine the path to the directory containing the script relative to the root directory it is contained within + let relativeDirectory: string; + for (const rootDirectory of rootDirs) { + if (containsPath(rootDirectory, scriptPath, basePath, ignoreCase)) { + relativeDirectory = scriptPath.substr(rootDirectory.length); + break; + } + } + + // Now find a path for each potential directory that is to be merged with the one containing the script + return deduplicate(map(rootDirs, rootDirectory => combinePaths(rootDirectory, relativeDirectory))); + } + + function getCompletionEntriesForDirectoryFragmentWithRootDirs(rootDirs: string[], fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string): CompletionEntry[] { + const basePath = program.getCompilerOptions().project || host.getCurrentDirectory(); + const ignoreCase = !(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames()); + const baseDirectories = getBaseDirectoriesFromRootDirs(rootDirs, basePath, scriptPath, ignoreCase); + + const result: CompletionEntry[] = []; + + for (const baseDirectory of baseDirectories) { + getCompletionEntriesForDirectoryFragment(fragment, baseDirectory, extensions, includeExtensions, span, exclude, result); + } + + return result; + } + + function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] { + fragment = getDirectoryPath(fragment); + if (!fragment) { + fragment = "./"; + } + else { + fragment = ensureTrailingDirectorySeparator(fragment); + } + + const absolutePath = normalizeAndPreserveTrailingSlash(isRootedDiskPath(fragment) ? fragment : combinePaths(scriptPath, fragment)); + const baseDirectory = getDirectoryPath(absolutePath); + const ignoreCase = !(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames()); + + if (tryDirectoryExists(host, baseDirectory)) { + // Enumerate the available files if possible + const files = tryReadDirectory(host, baseDirectory, extensions, /*exclude*/undefined, /*include*/["./*"]); + + if (files) { + const foundFiles = createMap(); + for (let filePath of files) { + filePath = normalizePath(filePath); + if (exclude && comparePaths(filePath, exclude, scriptPath, ignoreCase) === Comparison.EqualTo) { + continue; + } + + const foundFileName = includeExtensions ? getBaseFileName(filePath) : removeFileExtension(getBaseFileName(filePath)); + + if (!foundFiles[foundFileName]) { + foundFiles[foundFileName] = true; + } + } + + for (const foundFile in foundFiles) { + result.push(createCompletionEntryForModule(foundFile, ScriptElementKind.scriptElement, span)); + } + } + + // If possible, get folder completion as well + const directories = tryGetDirectories(host, baseDirectory); + + if (directories) { + for (const directory of directories) { + const directoryName = getBaseFileName(normalizePath(directory)); + + result.push(createCompletionEntryForModule(directoryName, ScriptElementKind.directory, span)); + } + } + } + + return result; + } + + /** + * Check all of the declared modules and those in node modules. Possible sources of modules: + * Modules that are found by the type checker + * Modules found relative to "baseUrl" compliler options (including patterns from "paths" compiler option) + * Modules from node_modules (i.e. those listed in package.json) + * This includes all files that are found in node_modules/moduleName/ with acceptable file extensions + */ + function getCompletionEntriesForNonRelativeModules(fragment: string, scriptPath: string, span: TextSpan): CompletionEntry[] { + const options = program.getCompilerOptions(); + const { baseUrl, paths } = options; + + let result: CompletionEntry[]; + + if (baseUrl) { + const fileExtensions = getSupportedExtensions(options); + const projectDir = options.project || host.getCurrentDirectory(); + const absolute = isRootedDiskPath(baseUrl) ? baseUrl : combinePaths(projectDir, baseUrl); + result = getCompletionEntriesForDirectoryFragment(fragment, normalizePath(absolute), fileExtensions, /*includeExtensions*/false, span); + + if (paths) { + for (const path in paths) { + if (paths.hasOwnProperty(path)) { + if (path === "*") { + if (paths[path]) { + for (const pattern of paths[path]) { + for (const match of getModulesForPathsPattern(fragment, baseUrl, pattern, fileExtensions)) { + result.push(createCompletionEntryForModule(match, ScriptElementKind.externalModuleName, span)); + } + } + } + } + else if (startsWith(path, fragment)) { + const entry = paths[path] && paths[path].length === 1 && paths[path][0]; + if (entry) { + result.push(createCompletionEntryForModule(path, ScriptElementKind.externalModuleName, span)); + } + } + } + } + } + } + else { + result = []; + } + + getCompletionEntriesFromTypings(host, options, scriptPath, span, result); + + for (const moduleName of enumeratePotentialNonRelativeModules(fragment, scriptPath, options)) { + result.push(createCompletionEntryForModule(moduleName, ScriptElementKind.externalModuleName, span)); + } + + return result; + } + + function getModulesForPathsPattern(fragment: string, baseUrl: string, pattern: string, fileExtensions: string[]): string[] { + if (host.readDirectory) { + const parsed = hasZeroOrOneAsteriskCharacter(pattern) ? tryParsePattern(pattern) : undefined; + if (parsed) { + // The prefix has two effective parts: the directory path and the base component after the filepath that is not a + // full directory component. For example: directory/path/of/prefix/base* + const normalizedPrefix = normalizeAndPreserveTrailingSlash(parsed.prefix); + const normalizedPrefixDirectory = getDirectoryPath(normalizedPrefix); + const normalizedPrefixBase = getBaseFileName(normalizedPrefix); + + const fragmentHasPath = fragment.indexOf(directorySeparator) !== -1; + + // Try and expand the prefix to include any path from the fragment so that we can limit the readDirectory call + const expandedPrefixDirectory = fragmentHasPath ? combinePaths(normalizedPrefixDirectory, normalizedPrefixBase + getDirectoryPath(fragment)) : normalizedPrefixDirectory; + + const normalizedSuffix = normalizePath(parsed.suffix); + const baseDirectory = combinePaths(baseUrl, expandedPrefixDirectory); + const completePrefix = fragmentHasPath ? baseDirectory : ensureTrailingDirectorySeparator(baseDirectory) + normalizedPrefixBase; + + // If we have a suffix, then we need to read the directory all the way down. We could create a glob + // that encodes the suffix, but we would have to escape the character "?" which readDirectory + // doesn't support. For now, this is safer but slower + const includeGlob = normalizedSuffix ? "**/*" : "./*"; + + const matches = tryReadDirectory(host, baseDirectory, fileExtensions, undefined, [includeGlob]); + if (matches) { + const result: string[] = []; + + // Trim away prefix and suffix + for (const match of matches) { + const normalizedMatch = normalizePath(match); + if (!endsWith(normalizedMatch, normalizedSuffix) || !startsWith(normalizedMatch, completePrefix)) { + continue; + } + + const start = completePrefix.length; + const length = normalizedMatch.length - start - normalizedSuffix.length; + + result.push(removeFileExtension(normalizedMatch.substr(start, length))); + } + return result; + } + } + } + + return undefined; + } + + function enumeratePotentialNonRelativeModules(fragment: string, scriptPath: string, options: CompilerOptions): string[] { + // Check If this is a nested module + const isNestedModule = fragment.indexOf(directorySeparator) !== -1; + const moduleNameFragment = isNestedModule ? fragment.substr(0, fragment.lastIndexOf(directorySeparator)) : undefined; + + // Get modules that the type checker picked up + const ambientModules = map(program.getTypeChecker().getAmbientModules(), sym => stripQuotes(sym.name)); + let nonRelativeModules = filter(ambientModules, moduleName => startsWith(moduleName, fragment)); + + // Nested modules of the form "module-name/sub" need to be adjusted to only return the string + // after the last '/' that appears in the fragment because that's where the replacement span + // starts + if (isNestedModule) { + const moduleNameWithSeperator = ensureTrailingDirectorySeparator(moduleNameFragment); + nonRelativeModules = map(nonRelativeModules, moduleName => { + if (startsWith(fragment, moduleNameWithSeperator)) { + return moduleName.substr(moduleNameWithSeperator.length); + } + return moduleName; + }); + } + + + if (!options.moduleResolution || options.moduleResolution === ModuleResolutionKind.NodeJs) { + for (const visibleModule of enumerateNodeModulesVisibleToScript(host, scriptPath)) { + if (!isNestedModule) { + nonRelativeModules.push(visibleModule.moduleName); + } + else if (startsWith(visibleModule.moduleName, moduleNameFragment)) { + const nestedFiles = tryReadDirectory(host, visibleModule.moduleDir, supportedTypeScriptExtensions, /*exclude*/undefined, /*include*/["./*"]); + if (nestedFiles) { + for (let f of nestedFiles) { + f = normalizePath(f); + const nestedModule = removeFileExtension(getBaseFileName(f)); + nonRelativeModules.push(nestedModule); + } + } + } + } + } + + return deduplicate(nonRelativeModules); + } + + function getTripleSlashReferenceCompletion(sourceFile: SourceFile, position: number): CompletionInfo { + const token = getTokenAtPosition(sourceFile, position); + if (!token) { + return undefined; + } + const commentRanges: CommentRange[] = getLeadingCommentRanges(sourceFile.text, token.pos); + + if (!commentRanges || !commentRanges.length) { + return undefined; + } + + const range = forEach(commentRanges, commentRange => position >= commentRange.pos && position <= commentRange.end && commentRange); + + if (!range) { + return undefined; + } + + const text = sourceFile.text.substr(range.pos, position - range.pos); + + const match = tripleSlashDirectiveFragmentRegex.exec(text); + if (match) { + const prefix = match[1]; + const kind = match[2]; + const toComplete = match[3]; + + const scriptPath = getDirectoryPath(sourceFile.path); + let entries: CompletionEntry[]; + if (kind === "path") { + // Give completions for a relative path + const span: TextSpan = getDirectoryFragmentTextSpan(toComplete, range.pos + prefix.length); + entries = getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getSupportedExtensions(program.getCompilerOptions()), /*includeExtensions*/true, span, sourceFile.path); + } + else { + // Give completions based on the typings available + const span: TextSpan = { start: range.pos + prefix.length, length: match[0].length - prefix.length }; + entries = getCompletionEntriesFromTypings(host, program.getCompilerOptions(), scriptPath, span); + } + + return { + isMemberCompletion: false, + isNewIdentifierLocation: true, + entries + }; + } + + return undefined; + } + + function getCompletionEntriesFromTypings(host: LanguageServiceHost, options: CompilerOptions, scriptPath: string, span: TextSpan, result: CompletionEntry[] = []): CompletionEntry[] { + // Check for typings specified in compiler options + if (options.types) { + for (const moduleName of options.types) { + result.push(createCompletionEntryForModule(moduleName, ScriptElementKind.externalModuleName, span)); + } + } + else if (host.getDirectories) { + const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory()); + for (const root of typeRoots) { + getCompletionEntriesFromDirectories(host, options, root, span, result); + } + } + + if (host.getDirectories) { + // Also get all @types typings installed in visible node_modules directories + for (const package of findPackageJsons(scriptPath)) { + const typesDir = combinePaths(getDirectoryPath(package), "node_modules/@types"); + getCompletionEntriesFromDirectories(host, options, typesDir, span, result); + } + } + + return result; + } + + function getCompletionEntriesFromDirectories(host: LanguageServiceHost, options: CompilerOptions, directory: string, span: TextSpan, result: CompletionEntry[]) { + if (host.getDirectories && tryDirectoryExists(host, directory)) { + const directories = tryGetDirectories(host, directory); + if (directories) { + for (let typeDirectory of directories) { + typeDirectory = normalizePath(typeDirectory); + result.push(createCompletionEntryForModule(getBaseFileName(typeDirectory), ScriptElementKind.externalModuleName, span)); + } + } + } + } + + function findPackageJsons(currentDir: string): string[] { + const paths: string[] = []; + let currentConfigPath: string; + while (true) { + currentConfigPath = findConfigFile(currentDir, (f) => tryFileExists(host, f), "package.json"); + if (currentConfigPath) { + paths.push(currentConfigPath); + + currentDir = getDirectoryPath(currentConfigPath); + const parent = getDirectoryPath(currentDir); + if (currentDir === parent) { + break; + } + currentDir = parent; + } + else { + break; + } + } + + return paths; + } + + + function enumerateNodeModulesVisibleToScript(host: LanguageServiceHost, scriptPath: string) { + const result: VisibleModuleInfo[] = []; + + if (host.readFile && host.fileExists) { + for (const packageJson of findPackageJsons(scriptPath)) { + const package = tryReadingPackageJson(packageJson); + if (!package) { + return; + } + + const nodeModulesDir = combinePaths(getDirectoryPath(packageJson), "node_modules"); + const foundModuleNames: string[] = []; + + // Provide completions for all non @types dependencies + for (const key of nodeModulesDependencyKeys) { + addPotentialPackageNames(package[key], foundModuleNames); + } + + for (const moduleName of foundModuleNames) { + const moduleDir = combinePaths(nodeModulesDir, moduleName); + result.push({ + moduleName, + moduleDir + }); + } + } + } + + return result; + + function tryReadingPackageJson(filePath: string) { + try { + const fileText = tryReadFile(host, filePath); + return fileText ? JSON.parse(fileText) : undefined; + } + catch (e) { + return undefined; + } + } + + function addPotentialPackageNames(dependencies: any, result: string[]) { + if (dependencies) { + for (const dep in dependencies) { + if (dependencies.hasOwnProperty(dep) && !startsWith(dep, "@types/")) { + result.push(dep); + } + } + } + } + } + + function createCompletionEntryForModule(name: string, kind: string, replacementSpan: TextSpan): CompletionEntry { + return { name, kind, kindModifiers: ScriptElementKindModifier.none, sortText: name, replacementSpan }; + } + + // Replace everything after the last directory seperator that appears + function getDirectoryFragmentTextSpan(text: string, textStart: number): TextSpan { + const index = text.lastIndexOf(directorySeparator); + const offset = index !== -1 ? index + 1 : 0; + return { start: textStart + offset, length: text.length - offset }; + } + + // Returns true if the path is explicitly relative to the script (i.e. relative to . or ..) + function isPathRelativeToScript(path: string) { + if (path && path.length >= 2 && path.charCodeAt(0) === CharacterCodes.dot) { + const slashIndex = path.length >= 3 && path.charCodeAt(1) === CharacterCodes.dot ? 2 : 1; + const slashCharCode = path.charCodeAt(slashIndex); + return slashCharCode === CharacterCodes.slash || slashCharCode === CharacterCodes.backslash; + } + return false; + } + + function normalizeAndPreserveTrailingSlash(path: string) { + return hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(normalizePath(path)) : normalizePath(path); + } + + function tryGetDirectories(host: LanguageServiceHost, directoryName: string): string[] { + return tryIOAndConsumeErrors(host, host.getDirectories, directoryName); + } + + function tryReadDirectory(host: LanguageServiceHost, path: string, extensions?: string[], exclude?: string[], include?: string[]): string[] { + return tryIOAndConsumeErrors(host, host.readDirectory, path, extensions, exclude, include); + } + + function tryReadFile(host: LanguageServiceHost, path: string): string { + return tryIOAndConsumeErrors(host, host.readFile, path); + } + + function tryFileExists(host: LanguageServiceHost, path: string): boolean { + return tryIOAndConsumeErrors(host, host.fileExists, path); + } + + function tryDirectoryExists(host: LanguageServiceHost, path: string): boolean { + try { + return directoryProbablyExists(path, host); + } + catch (e) {} + return undefined; + } + + function tryIOAndConsumeErrors(host: LanguageServiceHost, toApply: (...a: any[]) => T, ...args: any[]) { + try { + return toApply && toApply.apply(host, args); + } + catch (e) {} + return undefined; + } } function getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails { @@ -6194,7 +6729,7 @@ namespace ts { return result; - function getDefinition(symbol: Symbol): DefinitionInfo { + function getDefinition(symbol: Symbol): ReferencedSymbolDefinitionInfo { const info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), node); const name = map(info.displayParts, p => p.text).join(""); const declarations = symbol.declarations; @@ -6208,7 +6743,8 @@ namespace ts { name, kind: info.symbolKind, fileName: declarations[0].getSourceFile().fileName, - textSpan: createTextSpan(declarations[0].getStart(), 0) + textSpan: createTextSpan(declarations[0].getStart(), 0), + displayParts: info.displayParts }; } @@ -6403,13 +6939,14 @@ namespace ts { } }); - const definition: DefinitionInfo = { + const definition: ReferencedSymbolDefinitionInfo = { containerKind: "", containerName: "", fileName: targetLabel.getSourceFile().fileName, kind: ScriptElementKind.label, name: labelName, - textSpan: createTextSpanFromBounds(targetLabel.getStart(), targetLabel.getEnd()) + textSpan: createTextSpanFromBounds(targetLabel.getStart(), targetLabel.getEnd()), + displayParts: [displayPart(labelName, SymbolDisplayPartKind.text)] }; return [{ definition, references }]; @@ -6456,7 +6993,6 @@ namespace ts { symbolToIndex: number[]): void { const sourceFile = container.getSourceFile(); - const tripleSlashDirectivePrefixRegex = /^\/\/\/\s*= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var CtorDtor = (function () { + function CtorDtor() { + } + return CtorDtor; +}()); +var C = (function () { + function C() { + } + C = __decorate([ + CtorDtor + ], C); + return C; +}()); diff --git a/tests/baselines/reference/constructableDecoratorOnClass01.symbols b/tests/baselines/reference/constructableDecoratorOnClass01.symbols new file mode 100644 index 00000000000..46de420b826 --- /dev/null +++ b/tests/baselines/reference/constructableDecoratorOnClass01.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/decorators/class/constructableDecoratorOnClass01.ts === + +class CtorDtor {} +>CtorDtor : Symbol(CtorDtor, Decl(constructableDecoratorOnClass01.ts, 0, 0)) + +@CtorDtor +>CtorDtor : Symbol(CtorDtor, Decl(constructableDecoratorOnClass01.ts, 0, 0)) + +class C { +>C : Symbol(C, Decl(constructableDecoratorOnClass01.ts, 1, 17)) + +} + diff --git a/tests/baselines/reference/constructableDecoratorOnClass01.types b/tests/baselines/reference/constructableDecoratorOnClass01.types new file mode 100644 index 00000000000..d66778a27e6 --- /dev/null +++ b/tests/baselines/reference/constructableDecoratorOnClass01.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/decorators/class/constructableDecoratorOnClass01.ts === + +class CtorDtor {} +>CtorDtor : CtorDtor + +@CtorDtor +>CtorDtor : typeof CtorDtor + +class C { +>C : C + +} + diff --git a/tests/baselines/reference/enumAssignmentCompat3.errors.txt b/tests/baselines/reference/enumAssignmentCompat3.errors.txt index 02cb4314777..558540c32c8 100644 --- a/tests/baselines/reference/enumAssignmentCompat3.errors.txt +++ b/tests/baselines/reference/enumAssignmentCompat3.errors.txt @@ -1,20 +1,18 @@ -tests/cases/compiler/enumAssignmentCompat3.ts(68,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. - Property 'd' is missing in type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(68,1): error TS2324: Property 'd' is missing in type 'First.E'. tests/cases/compiler/enumAssignmentCompat3.ts(70,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. Property 'd' is missing in type 'First.E'. tests/cases/compiler/enumAssignmentCompat3.ts(71,1): error TS2322: Type 'Nope' is not assignable to type 'E'. -tests/cases/compiler/enumAssignmentCompat3.ts(75,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. - Property 'c' is missing in type 'Ab.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(72,1): error TS2322: Type 'Decl.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(75,1): error TS2324: Property 'c' is missing in type 'Ab.E'. tests/cases/compiler/enumAssignmentCompat3.ts(76,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. - Property 'a' is missing in type 'Cd.E'. tests/cases/compiler/enumAssignmentCompat3.ts(77,1): error TS2322: Type 'E' is not assignable to type 'Nope'. +tests/cases/compiler/enumAssignmentCompat3.ts(78,1): error TS2322: Type 'First.E' is not assignable to type 'Decl.E'. tests/cases/compiler/enumAssignmentCompat3.ts(82,1): error TS2322: Type 'Const.E' is not assignable to type 'First.E'. tests/cases/compiler/enumAssignmentCompat3.ts(83,1): error TS2322: Type 'First.E' is not assignable to type 'Const.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(86,1): error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. - Property 'd' is missing in type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(86,1): error TS2324: Property 'd' is missing in type 'First.E'. -==== tests/cases/compiler/enumAssignmentCompat3.ts (9 errors) ==== +==== tests/cases/compiler/enumAssignmentCompat3.ts (11 errors) ==== namespace First { export enum E { a, b, c, @@ -84,8 +82,7 @@ tests/cases/compiler/enumAssignmentCompat3.ts(86,1): error TS2322: Type 'Merged. abc = secondAbc; // ok abc = secondAbcd; // missing 'd' ~~~ -!!! error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. -!!! error TS2322: Property 'd' is missing in type 'First.E'. +!!! error TS2324: Property 'd' is missing in type 'First.E'. abc = secondAb; // ok abc = secondCd; // missing 'd' ~~~ @@ -95,20 +92,22 @@ tests/cases/compiler/enumAssignmentCompat3.ts(86,1): error TS2322: Type 'Merged. ~~~ !!! error TS2322: Type 'Nope' is not assignable to type 'E'. abc = decl; // ok + ~~~ +!!! error TS2322: Type 'Decl.E' is not assignable to type 'First.E'. secondAbc = abc; // ok secondAbcd = abc; // ok secondAb = abc; // missing 'c' ~~~~~~~~ -!!! error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. -!!! error TS2322: Property 'c' is missing in type 'Ab.E'. +!!! error TS2324: Property 'c' is missing in type 'Ab.E'. secondCd = abc; // missing 'a' and 'b' ~~~~~~~~ !!! error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. -!!! error TS2322: Property 'a' is missing in type 'Cd.E'. nope = abc; // nope! ~~~~ !!! error TS2322: Type 'E' is not assignable to type 'Nope'. decl = abc; // ok + ~~~~ +!!! error TS2322: Type 'First.E' is not assignable to type 'Decl.E'. // const is only assignable to itself k = k; @@ -122,8 +121,7 @@ tests/cases/compiler/enumAssignmentCompat3.ts(86,1): error TS2322: Type 'Merged. // merged enums compare all their members abc = merged; // missing 'd' ~~~ -!!! error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. -!!! error TS2322: Property 'd' is missing in type 'First.E'. +!!! error TS2324: Property 'd' is missing in type 'First.E'. merged = abc; // ok abc = merged2; // ok merged2 = abc; // ok \ No newline at end of file diff --git a/tests/baselines/reference/enumAssignmentCompat5.errors.txt b/tests/baselines/reference/enumAssignmentCompat5.errors.txt new file mode 100644 index 00000000000..ef703a2ad62 --- /dev/null +++ b/tests/baselines/reference/enumAssignmentCompat5.errors.txt @@ -0,0 +1,30 @@ +tests/cases/compiler/enumAssignmentCompat5.ts(20,9): error TS2535: Enum type 'Computed' has members with initializers that are not literals. + + +==== tests/cases/compiler/enumAssignmentCompat5.ts (1 errors) ==== + enum E { + A, B, C + } + enum Computed { + A = 1 << 1, + B = 1 << 2, + C = 1 << 3, + } + let n: number; + let e: E = n; // ok because it's too inconvenient otherwise + e = 0; // ok, in range + e = 4; // ok, out of range, but allowed computed enums don't have all members + let a: E.A = 0; // ok, A === 0 + a = 2; // error, 2 !== 0 + a = n; // ok + + let c: Computed = n; // ok + c = n; // ok + c = 4; // ok + let ca: Computed.A = 1; // error, Computed.A isn't a literal type because Computed has no enum literals + ~~~~~~~~~~ +!!! error TS2535: Enum type 'Computed' has members with initializers that are not literals. + + + + \ No newline at end of file diff --git a/tests/baselines/reference/enumAssignmentCompat5.js b/tests/baselines/reference/enumAssignmentCompat5.js new file mode 100644 index 00000000000..a7c96929f08 --- /dev/null +++ b/tests/baselines/reference/enumAssignmentCompat5.js @@ -0,0 +1,50 @@ +//// [enumAssignmentCompat5.ts] +enum E { + A, B, C +} +enum Computed { + A = 1 << 1, + B = 1 << 2, + C = 1 << 3, +} +let n: number; +let e: E = n; // ok because it's too inconvenient otherwise +e = 0; // ok, in range +e = 4; // ok, out of range, but allowed computed enums don't have all members +let a: E.A = 0; // ok, A === 0 +a = 2; // error, 2 !== 0 +a = n; // ok + +let c: Computed = n; // ok +c = n; // ok +c = 4; // ok +let ca: Computed.A = 1; // error, Computed.A isn't a literal type because Computed has no enum literals + + + + + +//// [enumAssignmentCompat5.js] +var E; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; +})(E || (E = {})); +var Computed; +(function (Computed) { + Computed[Computed["A"] = 2] = "A"; + Computed[Computed["B"] = 4] = "B"; + Computed[Computed["C"] = 8] = "C"; +})(Computed || (Computed = {})); +var n; +var e = n; // ok because it's too inconvenient otherwise +e = 0; // ok, in range +e = 4; // ok, out of range, but allowed computed enums don't have all members +var a = 0; // ok, A === 0 +a = 2; // error, 2 !== 0 +a = n; // ok +var c = n; // ok +c = n; // ok +c = 4; // ok +var ca = 1; // error, Computed.A isn't a literal type because Computed has no enum literals diff --git a/tests/baselines/reference/enumLiteralAssignableToEnumInsideUnion.errors.txt b/tests/baselines/reference/enumLiteralAssignableToEnumInsideUnion.errors.txt new file mode 100644 index 00000000000..660e1094ae9 --- /dev/null +++ b/tests/baselines/reference/enumLiteralAssignableToEnumInsideUnion.errors.txt @@ -0,0 +1,44 @@ +tests/cases/compiler/enumLiteralAssignableToEnumInsideUnion.ts(24,7): error TS2322: Type 'Foo' is not assignable to type 'boolean | Foo'. +tests/cases/compiler/enumLiteralAssignableToEnumInsideUnion.ts(25,7): error TS2322: Type 'Foo' is not assignable to type 'boolean | Foo'. +tests/cases/compiler/enumLiteralAssignableToEnumInsideUnion.ts(26,7): error TS2322: Type 'Foo' is not assignable to type 'boolean | Foo.B'. +tests/cases/compiler/enumLiteralAssignableToEnumInsideUnion.ts(27,7): error TS2322: Type 'Foo' is not assignable to type 'boolean | Foo.A'. + + +==== tests/cases/compiler/enumLiteralAssignableToEnumInsideUnion.ts (4 errors) ==== + module X { + export enum Foo { + A, B + } + } + module Y { + export enum Foo { + A, B + } + } + module Z { + export enum Foo { + A = 1 << 1, + B = 1 << 2, + } + } + module Ka { + export enum Foo { + A = 1 << 10, + B = 1 << 11, + } + } + const e0: X.Foo | boolean = Y.Foo.A; // ok + const e1: X.Foo | boolean = Z.Foo.A; // not legal, Z is computed + ~~ +!!! error TS2322: Type 'Foo' is not assignable to type 'boolean | Foo'. + const e2: X.Foo.A | X.Foo.B | boolean = Z.Foo.A; // still not legal + ~~ +!!! error TS2322: Type 'Foo' is not assignable to type 'boolean | Foo'. + const e3: X.Foo.B | boolean = Z.Foo.A; // not legal + ~~ +!!! error TS2322: Type 'Foo' is not assignable to type 'boolean | Foo.B'. + const e4: X.Foo.A | boolean = Z.Foo.A; // not legal either because Z.Foo is computed and Z.Foo.A is not necessarily assignable to X.Foo.A + ~~ +!!! error TS2322: Type 'Foo' is not assignable to type 'boolean | Foo.A'. + const e5: Ka.Foo | boolean = Z.Foo.A; // ok + \ No newline at end of file diff --git a/tests/baselines/reference/enumLiteralAssignableToEnumInsideUnion.js b/tests/baselines/reference/enumLiteralAssignableToEnumInsideUnion.js new file mode 100644 index 00000000000..8786745a504 --- /dev/null +++ b/tests/baselines/reference/enumLiteralAssignableToEnumInsideUnion.js @@ -0,0 +1,70 @@ +//// [enumLiteralAssignableToEnumInsideUnion.ts] +module X { + export enum Foo { + A, B + } +} +module Y { + export enum Foo { + A, B + } +} +module Z { + export enum Foo { + A = 1 << 1, + B = 1 << 2, + } +} +module Ka { + export enum Foo { + A = 1 << 10, + B = 1 << 11, + } +} +const e0: X.Foo | boolean = Y.Foo.A; // ok +const e1: X.Foo | boolean = Z.Foo.A; // not legal, Z is computed +const e2: X.Foo.A | X.Foo.B | boolean = Z.Foo.A; // still not legal +const e3: X.Foo.B | boolean = Z.Foo.A; // not legal +const e4: X.Foo.A | boolean = Z.Foo.A; // not legal either because Z.Foo is computed and Z.Foo.A is not necessarily assignable to X.Foo.A +const e5: Ka.Foo | boolean = Z.Foo.A; // ok + + +//// [enumLiteralAssignableToEnumInsideUnion.js] +var X; +(function (X) { + (function (Foo) { + Foo[Foo["A"] = 0] = "A"; + Foo[Foo["B"] = 1] = "B"; + })(X.Foo || (X.Foo = {})); + var Foo = X.Foo; +})(X || (X = {})); +var Y; +(function (Y) { + (function (Foo) { + Foo[Foo["A"] = 0] = "A"; + Foo[Foo["B"] = 1] = "B"; + })(Y.Foo || (Y.Foo = {})); + var Foo = Y.Foo; +})(Y || (Y = {})); +var Z; +(function (Z) { + (function (Foo) { + Foo[Foo["A"] = 2] = "A"; + Foo[Foo["B"] = 4] = "B"; + })(Z.Foo || (Z.Foo = {})); + var Foo = Z.Foo; +})(Z || (Z = {})); +var Ka; +(function (Ka) { + (function (Foo) { + Foo[Foo["A"] = 1024] = "A"; + Foo[Foo["B"] = 2048] = "B"; + })(Ka.Foo || (Ka.Foo = {})); + var Foo = Ka.Foo; +})(Ka || (Ka = {})); +var e0 = Y.Foo.A; // ok +var e1 = Z.Foo.A; // not legal, Z is computed +var e2 = Z.Foo.A; // still not legal +var e3 = Z.Foo.A; // not legal +var e4 = Z.Foo.A; // not legal either because Z.Foo is computed and Z.Foo.A is not necessarily assignable to X.Foo.A +var e5 = Z.Foo.A; // ok diff --git a/tests/baselines/reference/getEmitOutput-pp.baseline b/tests/baselines/reference/getEmitOutput-pp.baseline index d6952e4537d..683b454a275 100644 --- a/tests/baselines/reference/getEmitOutput-pp.baseline +++ b/tests/baselines/reference/getEmitOutput-pp.baseline @@ -1,12 +1,12 @@ EmitSkipped: false -FileName : tests/cases/fourslash/shims-pp/inputFile1.js +FileName : /tests/cases/fourslash/shims-pp/inputFile1.js var x = 5; var Bar = (function () { function Bar() { } return Bar; }()); -FileName : tests/cases/fourslash/shims-pp/inputFile1.d.ts +FileName : /tests/cases/fourslash/shims-pp/inputFile1.d.ts declare var x: number; declare class Bar { x: string; @@ -14,14 +14,14 @@ declare class Bar { } EmitSkipped: false -FileName : tests/cases/fourslash/shims-pp/inputFile2.js +FileName : /tests/cases/fourslash/shims-pp/inputFile2.js var x1 = "hello world"; var Foo = (function () { function Foo() { } return Foo; }()); -FileName : tests/cases/fourslash/shims-pp/inputFile2.d.ts +FileName : /tests/cases/fourslash/shims-pp/inputFile2.d.ts declare var x1: string; declare class Foo { x: string; diff --git a/tests/baselines/reference/getEmitOutput.baseline b/tests/baselines/reference/getEmitOutput.baseline index 52c7d8a7aae..8251850e1bb 100644 --- a/tests/baselines/reference/getEmitOutput.baseline +++ b/tests/baselines/reference/getEmitOutput.baseline @@ -1,12 +1,12 @@ EmitSkipped: false -FileName : tests/cases/fourslash/shims/inputFile1.js +FileName : /tests/cases/fourslash/shims/inputFile1.js var x = 5; var Bar = (function () { function Bar() { } return Bar; }()); -FileName : tests/cases/fourslash/shims/inputFile1.d.ts +FileName : /tests/cases/fourslash/shims/inputFile1.d.ts declare var x: number; declare class Bar { x: string; @@ -14,14 +14,14 @@ declare class Bar { } EmitSkipped: false -FileName : tests/cases/fourslash/shims/inputFile2.js +FileName : /tests/cases/fourslash/shims/inputFile2.js var x1 = "hello world"; var Foo = (function () { function Foo() { } return Foo; }()); -FileName : tests/cases/fourslash/shims/inputFile2.d.ts +FileName : /tests/cases/fourslash/shims/inputFile2.d.ts declare var x1: string; declare class Foo { x: string; diff --git a/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline b/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline index 5a6fb434b1f..56eb932fb5d 100644 --- a/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline +++ b/tests/baselines/reference/getEmitOutputDeclarationMultiFiles.baseline @@ -1,12 +1,12 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile1.js +FileName : /tests/cases/fourslash/inputFile1.js var x = 5; var Bar = (function () { function Bar() { } return Bar; }()); -FileName : tests/cases/fourslash/inputFile1.d.ts +FileName : /tests/cases/fourslash/inputFile1.d.ts declare var x: number; declare class Bar { x: string; @@ -14,14 +14,14 @@ declare class Bar { } EmitSkipped: false -FileName : tests/cases/fourslash/inputFile2.js +FileName : /tests/cases/fourslash/inputFile2.js var x1 = "hello world"; var Foo = (function () { function Foo() { } return Foo; }()); -FileName : tests/cases/fourslash/inputFile2.d.ts +FileName : /tests/cases/fourslash/inputFile2.d.ts declare var x1: string; declare class Foo { x: string; diff --git a/tests/baselines/reference/getEmitOutputNoErrors.baseline b/tests/baselines/reference/getEmitOutputNoErrors.baseline index 461cba4ea05..6469ab3d1a7 100644 --- a/tests/baselines/reference/getEmitOutputNoErrors.baseline +++ b/tests/baselines/reference/getEmitOutputNoErrors.baseline @@ -1,5 +1,5 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile.js +FileName : /tests/cases/fourslash/inputFile.js var x; var M = (function () { function M() { diff --git a/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline b/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline index 4d1c88e45b4..dbcfe28afaa 100644 --- a/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline +++ b/tests/baselines/reference/getEmitOutputOnlyOneFile.baseline @@ -1,5 +1,5 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile2.js +FileName : /tests/cases/fourslash/inputFile2.js var x; var Foo = (function () { function Foo() { diff --git a/tests/baselines/reference/getEmitOutputSourceMap.baseline b/tests/baselines/reference/getEmitOutputSourceMap.baseline index 65257d63607..25667b8b701 100644 --- a/tests/baselines/reference/getEmitOutputSourceMap.baseline +++ b/tests/baselines/reference/getEmitOutputSourceMap.baseline @@ -1,6 +1,6 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile.js.map -{"version":3,"file":"inputFile.js","sourceRoot":"","sources":["inputFile.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB;IAAA;IAGA,CAAC;IAAD,QAAC;AAAD,CAAC,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile.js +FileName : /tests/cases/fourslash/inputFile.js.map +{"version":3,"file":"inputFile.js","sourceRoot":"","sources":["inputFile.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB;IAAA;IAGA,CAAC;IAAD,QAAC;AAAD,CAAC,AAHD,IAGC"}FileName : /tests/cases/fourslash/inputFile.js var x = 109; var foo = "hello world"; var M = (function () { diff --git a/tests/baselines/reference/getEmitOutputSourceRoot.baseline b/tests/baselines/reference/getEmitOutputSourceRoot.baseline index d38078a08e3..5881a61f22a 100644 --- a/tests/baselines/reference/getEmitOutputSourceRoot.baseline +++ b/tests/baselines/reference/getEmitOutputSourceRoot.baseline @@ -1,6 +1,6 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile.js.map -{"version":3,"file":"inputFile.js","sourceRoot":"sourceRootDir/","sources":["inputFile.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB;IAAA;IAGA,CAAC;IAAD,QAAC;AAAD,CAAC,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile.js +FileName : /tests/cases/fourslash/inputFile.js.map +{"version":3,"file":"inputFile.js","sourceRoot":"sourceRootDir/","sources":["inputFile.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB;IAAA;IAGA,CAAC;IAAD,QAAC;AAAD,CAAC,AAHD,IAGC"}FileName : /tests/cases/fourslash/inputFile.js var x = 109; var foo = "hello world"; var M = (function () { diff --git a/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline b/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline index 50a6ad68605..62e3f2eb7e5 100644 --- a/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline +++ b/tests/baselines/reference/getEmitOutputSourceRootMultiFiles.baseline @@ -1,6 +1,6 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile1.js.map -{"version":3,"file":"inputFile1.js","sourceRoot":"sourceRootDir/","sources":["inputFile1.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB;IAAA;IAGA,CAAC;IAAD,QAAC;AAAD,CAAC,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile1.js +FileName : /tests/cases/fourslash/inputFile1.js.map +{"version":3,"file":"inputFile1.js","sourceRoot":"sourceRootDir/","sources":["inputFile1.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,GAAG,CAAC;AACZ,IAAI,GAAG,GAAG,aAAa,CAAC;AACxB;IAAA;IAGA,CAAC;IAAD,QAAC;AAAD,CAAC,AAHD,IAGC"}FileName : /tests/cases/fourslash/inputFile1.js var x = 109; var foo = "hello world"; var M = (function () { @@ -10,8 +10,8 @@ var M = (function () { }()); //# sourceMappingURL=inputFile1.js.map EmitSkipped: false -FileName : tests/cases/fourslash/inputFile2.js.map -{"version":3,"file":"inputFile2.js","sourceRoot":"sourceRootDir/","sources":["inputFile2.ts"],"names":[],"mappings":"AAAA,IAAI,GAAG,GAAG,wBAAwB,CAAC;AACnC;IAAA;IAGA,CAAC;IAAD,QAAC;AAAD,CAAC,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile2.js +FileName : /tests/cases/fourslash/inputFile2.js.map +{"version":3,"file":"inputFile2.js","sourceRoot":"sourceRootDir/","sources":["inputFile2.ts"],"names":[],"mappings":"AAAA,IAAI,GAAG,GAAG,wBAAwB,CAAC;AACnC;IAAA;IAGA,CAAC;IAAD,QAAC;AAAD,CAAC,AAHD,IAGC"}FileName : /tests/cases/fourslash/inputFile2.js var bar = "hello world Typescript"; var C = (function () { function C() { diff --git a/tests/baselines/reference/getEmitOutputTsxFile_Preserve.baseline b/tests/baselines/reference/getEmitOutputTsxFile_Preserve.baseline index bebd1ff1dd1..015ddba07d9 100644 --- a/tests/baselines/reference/getEmitOutputTsxFile_Preserve.baseline +++ b/tests/baselines/reference/getEmitOutputTsxFile_Preserve.baseline @@ -1,6 +1,6 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile1.js.map -{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["inputFile1.ts"],"names":[],"mappings":"AAAA,kBAAkB;AACjB,IAAI,CAAC,GAAW,CAAC,CAAC;AAClB;IAAA;IAGA,CAAC;IAAD,UAAC;AAAD,CAAC,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile1.js +FileName : /tests/cases/fourslash/inputFile1.js.map +{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["inputFile1.ts"],"names":[],"mappings":"AAAA,kBAAkB;AACjB,IAAI,CAAC,GAAW,CAAC,CAAC;AAClB;IAAA;IAGA,CAAC;IAAD,UAAC;AAAD,CAAC,AAHD,IAGC"}FileName : /tests/cases/fourslash/inputFile1.js // regular ts file var t = 5; var Bar = (function () { @@ -8,7 +8,7 @@ var Bar = (function () { } return Bar; }()); -//# sourceMappingURL=inputFile1.js.mapFileName : tests/cases/fourslash/inputFile1.d.ts +//# sourceMappingURL=inputFile1.js.mapFileName : /tests/cases/fourslash/inputFile1.d.ts declare var t: number; declare class Bar { x: string; @@ -16,11 +16,11 @@ declare class Bar { } EmitSkipped: false -FileName : tests/cases/fourslash/inputFile2.jsx.map -{"version":3,"file":"inputFile2.jsx","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC,EAAG,CAAA"}FileName : tests/cases/fourslash/inputFile2.jsx +FileName : /tests/cases/fourslash/inputFile2.jsx.map +{"version":3,"file":"inputFile2.jsx","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC,EAAG,CAAA"}FileName : /tests/cases/fourslash/inputFile2.jsx var y = "my div"; var x =
; -//# sourceMappingURL=inputFile2.jsx.mapFileName : tests/cases/fourslash/inputFile2.d.ts +//# sourceMappingURL=inputFile2.jsx.mapFileName : /tests/cases/fourslash/inputFile2.d.ts declare var y: string; declare var x: any; diff --git a/tests/baselines/reference/getEmitOutputTsxFile_React.baseline b/tests/baselines/reference/getEmitOutputTsxFile_React.baseline index 5b668fd65e8..b78cbecf6c3 100644 --- a/tests/baselines/reference/getEmitOutputTsxFile_React.baseline +++ b/tests/baselines/reference/getEmitOutputTsxFile_React.baseline @@ -1,6 +1,6 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile1.js.map -{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["inputFile1.ts"],"names":[],"mappings":"AAAA,kBAAkB;AACjB,IAAI,CAAC,GAAW,CAAC,CAAC;AAClB;IAAA;IAGA,CAAC;IAAD,UAAC;AAAD,CAAC,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile1.js +FileName : /tests/cases/fourslash/inputFile1.js.map +{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["inputFile1.ts"],"names":[],"mappings":"AAAA,kBAAkB;AACjB,IAAI,CAAC,GAAW,CAAC,CAAC;AAClB;IAAA;IAGA,CAAC;IAAD,UAAC;AAAD,CAAC,AAHD,IAGC"}FileName : /tests/cases/fourslash/inputFile1.js // regular ts file var t = 5; var Bar = (function () { @@ -8,7 +8,7 @@ var Bar = (function () { } return Bar; }()); -//# sourceMappingURL=inputFile1.js.mapFileName : tests/cases/fourslash/inputFile1.d.ts +//# sourceMappingURL=inputFile1.js.mapFileName : /tests/cases/fourslash/inputFile1.d.ts declare var t: number; declare class Bar { x: string; @@ -16,11 +16,11 @@ declare class Bar { } EmitSkipped: false -FileName : tests/cases/fourslash/inputFile2.js.map -{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AACA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,qBAAC,GAAG,IAAC,IAAI,EAAG,CAAE,EAAG,CAAA"}FileName : tests/cases/fourslash/inputFile2.js +FileName : /tests/cases/fourslash/inputFile2.js.map +{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AACA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,qBAAC,GAAG,IAAC,IAAI,EAAG,CAAE,EAAG,CAAA"}FileName : /tests/cases/fourslash/inputFile2.js var y = "my div"; var x = React.createElement("div", {name: y}); -//# sourceMappingURL=inputFile2.js.mapFileName : tests/cases/fourslash/inputFile2.d.ts +//# sourceMappingURL=inputFile2.js.mapFileName : /tests/cases/fourslash/inputFile2.d.ts declare var React: any; declare var y: string; declare var x: any; diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline index af4ccd10580..a10ef5967b0 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline @@ -1,7 +1,7 @@ EmitSkipped: false EmitSkipped: false -FileName : tests/cases/fourslash/inputFile2.js +FileName : /tests/cases/fourslash/inputFile2.js var x1 = "hello world"; var Foo = (function () { function Foo() { diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline index 8e43219e005..5c865321691 100644 --- a/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline @@ -1,7 +1,7 @@ EmitSkipped: false EmitSkipped: false -FileName : tests/cases/fourslash/inputFile2.js +FileName : /tests/cases/fourslash/inputFile2.js "use strict"; var Foo = (function () { function Foo() { @@ -11,6 +11,6 @@ var Foo = (function () { exports.Foo = Foo; EmitSkipped: false -FileName : tests/cases/fourslash/inputFile3.js +FileName : /tests/cases/fourslash/inputFile3.js var x = "hello"; diff --git a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline index 9e2e9978f46..6609554a299 100644 --- a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline @@ -1,5 +1,5 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile1.js +FileName : /tests/cases/fourslash/inputFile1.js // File contains early errors. All outputs should be skipped. var uninitialized_const_error; diff --git a/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline b/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline index 8ba493e04b7..326d547ae1b 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline @@ -1,7 +1,7 @@ EmitSkipped: true Diagnostics: Exported variable 'foo' has or is using private name 'C'. -FileName : tests/cases/fourslash/inputFile.js +FileName : /tests/cases/fourslash/inputFile.js var M; (function (M) { var C = (function () { diff --git a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline index bf12bd35548..a181526eb27 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline @@ -1,7 +1,7 @@ EmitSkipped: true Diagnostics: Exported variable 'foo' has or is using private name 'C'. -FileName : tests/cases/fourslash/inputFile.js +FileName : /tests/cases/fourslash/inputFile.js define(["require", "exports"], function (require, exports) { "use strict"; var C = (function () { diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline index b6249822131..55a58ea041f 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors.baseline @@ -1,4 +1,4 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile.js +FileName : /tests/cases/fourslash/inputFile.js var x = "hello world"; diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline index 396e220bdb6..b5848da3457 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrors2.baseline @@ -1,6 +1,6 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile.js +FileName : /tests/cases/fourslash/inputFile.js var x = "hello world"; -FileName : tests/cases/fourslash/inputFile.d.ts +FileName : /tests/cases/fourslash/inputFile.d.ts declare var x: number; diff --git a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline index 7f012b6a546..4c22a7e3f93 100644 --- a/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline +++ b/tests/baselines/reference/getEmitOutputWithSemanticErrorsForMultipleFiles.baseline @@ -1,8 +1,8 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile1.js +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 +FileName : /tests/cases/fourslash/inputFile1.d.ts declare var noErrors: boolean; diff --git a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline index 701b275eb31..f51782cc75d 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntacticErrorsForMultipleFiles.baseline @@ -1,5 +1,5 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile1.js +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; diff --git a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline index 2c341821fb0..8aa81ba60ce 100644 --- a/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithSyntaxErrors.baseline @@ -1,4 +1,4 @@ EmitSkipped: false -FileName : tests/cases/fourslash/inputFile.js +FileName : /tests/cases/fourslash/inputFile.js var x; diff --git a/tests/baselines/reference/implicitAnyGetAndSetAccessorWithAnyReturnType.errors.txt b/tests/baselines/reference/implicitAnyGetAndSetAccessorWithAnyReturnType.errors.txt index 460ff97b10e..1e2de97aae0 100644 --- a/tests/baselines/reference/implicitAnyGetAndSetAccessorWithAnyReturnType.errors.txt +++ b/tests/baselines/reference/implicitAnyGetAndSetAccessorWithAnyReturnType.errors.txt @@ -2,7 +2,7 @@ tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts(3,5): erro tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts(4,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts(9,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts(15,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts(15,16): error TS7016: Property 'haveOnlySet' implicitly has type 'any', because its 'set' accessor lacks a type annotation. +tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts(15,16): error TS7032: Property 'haveOnlySet' implicitly has type 'any', because its set accessor lacks a parameter type annotation. tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts(15,28): error TS7006: Parameter 'newXValue' implicitly has an 'any' type. tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts(20,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts(20,16): error TS7010: 'haveOnlyGet', which lacks return-type annotation, implicitly has an 'any' return type. @@ -33,7 +33,7 @@ tests/cases/compiler/implicitAnyGetAndSetAccessorWithAnyReturnType.ts(20,16): er ~~~~~~~~~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~~~~~~~~~ -!!! error TS7016: Property 'haveOnlySet' implicitly has type 'any', because its 'set' accessor lacks a type annotation. +!!! error TS7032: Property 'haveOnlySet' implicitly has type 'any', because its set accessor lacks a parameter type annotation. ~~~~~~~~~ !!! error TS7006: Parameter 'newXValue' implicitly has an 'any' type. } diff --git a/tests/baselines/reference/noImplicitAnyMissingGetAccessor.errors.txt b/tests/baselines/reference/noImplicitAnyMissingGetAccessor.errors.txt new file mode 100644 index 00000000000..ef2a273711f --- /dev/null +++ b/tests/baselines/reference/noImplicitAnyMissingGetAccessor.errors.txt @@ -0,0 +1,27 @@ +tests/cases/compiler/noImplicitAnyMissingGetAccessor.ts(4,25): error TS7032: Property 'message' implicitly has type 'any', because its set accessor lacks a parameter type annotation. +tests/cases/compiler/noImplicitAnyMissingGetAccessor.ts(4,33): error TS7006: Parameter 'str' implicitly has an 'any' type. +tests/cases/compiler/noImplicitAnyMissingGetAccessor.ts(9,16): error TS7032: Property 'message' implicitly has type 'any', because its set accessor lacks a parameter type annotation. +tests/cases/compiler/noImplicitAnyMissingGetAccessor.ts(9,24): error TS7006: Parameter 'str' implicitly has an 'any' type. + + +==== tests/cases/compiler/noImplicitAnyMissingGetAccessor.ts (4 errors) ==== + + abstract class Parent + { + public abstract set message(str); + ~~~~~~~ +!!! error TS7032: Property 'message' implicitly has type 'any', because its set accessor lacks a parameter type annotation. + ~~~ +!!! error TS7006: Parameter 'str' implicitly has an 'any' type. + } + + class Child extends Parent { + _x: any; + public set message(str) { + ~~~~~~~ +!!! error TS7032: Property 'message' implicitly has type 'any', because its set accessor lacks a parameter type annotation. + ~~~ +!!! error TS7006: Parameter 'str' implicitly has an 'any' type. + this._x = str; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitAnyMissingGetAccessor.js b/tests/baselines/reference/noImplicitAnyMissingGetAccessor.js new file mode 100644 index 00000000000..38a2a731af4 --- /dev/null +++ b/tests/baselines/reference/noImplicitAnyMissingGetAccessor.js @@ -0,0 +1,44 @@ +//// [noImplicitAnyMissingGetAccessor.ts] + +abstract class Parent +{ + public abstract set message(str); +} + +class Child extends Parent { + _x: any; + public set message(str) { + this._x = str; + } +} + +//// [noImplicitAnyMissingGetAccessor.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Parent = (function () { + function Parent() { + } + Object.defineProperty(Parent.prototype, "message", { + set: function (str) { }, + enumerable: true, + configurable: true + }); + return Parent; +}()); +var Child = (function (_super) { + __extends(Child, _super); + function Child() { + _super.apply(this, arguments); + } + Object.defineProperty(Child.prototype, "message", { + set: function (str) { + this._x = str; + }, + enumerable: true, + configurable: true + }); + return Child; +}(Parent)); diff --git a/tests/baselines/reference/noImplicitAnyMissingSetAccessor.errors.txt b/tests/baselines/reference/noImplicitAnyMissingSetAccessor.errors.txt new file mode 100644 index 00000000000..ba104209189 --- /dev/null +++ b/tests/baselines/reference/noImplicitAnyMissingSetAccessor.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/noImplicitAnyMissingSetAccessor.ts(4,25): error TS7033: Property 'message' implicitly has type 'any', because its get accessor lacks a return type annotation. + + +==== tests/cases/compiler/noImplicitAnyMissingSetAccessor.ts (1 errors) ==== + + abstract class Parent + { + public abstract get message(); + ~~~~~~~ +!!! error TS7033: Property 'message' implicitly has type 'any', because its get accessor lacks a return type annotation. + } + + class Child extends Parent { + public get message() { + return ""; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitAnyMissingSetAccessor.js b/tests/baselines/reference/noImplicitAnyMissingSetAccessor.js new file mode 100644 index 00000000000..d4e0d17186d --- /dev/null +++ b/tests/baselines/reference/noImplicitAnyMissingSetAccessor.js @@ -0,0 +1,43 @@ +//// [noImplicitAnyMissingSetAccessor.ts] + +abstract class Parent +{ + public abstract get message(); +} + +class Child extends Parent { + public get message() { + return ""; + } +} + +//// [noImplicitAnyMissingSetAccessor.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Parent = (function () { + function Parent() { + } + Object.defineProperty(Parent.prototype, "message", { + get: function () { }, + enumerable: true, + configurable: true + }); + return Parent; +}()); +var Child = (function (_super) { + __extends(Child, _super); + function Child() { + _super.apply(this, arguments); + } + Object.defineProperty(Child.prototype, "message", { + get: function () { + return ""; + }, + enumerable: true, + configurable: true + }); + return Child; +}(Parent)); diff --git a/tests/baselines/reference/numberAssignableToEnumInsideUnion.js b/tests/baselines/reference/numberAssignableToEnumInsideUnion.js new file mode 100644 index 00000000000..584b395212d --- /dev/null +++ b/tests/baselines/reference/numberAssignableToEnumInsideUnion.js @@ -0,0 +1,14 @@ +//// [numberAssignableToEnumInsideUnion.ts] +enum E { A, B } +let n: number; +let z: E | boolean = n; + + +//// [numberAssignableToEnumInsideUnion.js] +var E; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; +})(E || (E = {})); +var n; +var z = n; diff --git a/tests/baselines/reference/numberAssignableToEnumInsideUnion.symbols b/tests/baselines/reference/numberAssignableToEnumInsideUnion.symbols new file mode 100644 index 00000000000..4d815a99690 --- /dev/null +++ b/tests/baselines/reference/numberAssignableToEnumInsideUnion.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/numberAssignableToEnumInsideUnion.ts === +enum E { A, B } +>E : Symbol(E, Decl(numberAssignableToEnumInsideUnion.ts, 0, 0)) +>A : Symbol(E.A, Decl(numberAssignableToEnumInsideUnion.ts, 0, 8)) +>B : Symbol(E.B, Decl(numberAssignableToEnumInsideUnion.ts, 0, 11)) + +let n: number; +>n : Symbol(n, Decl(numberAssignableToEnumInsideUnion.ts, 1, 3)) + +let z: E | boolean = n; +>z : Symbol(z, Decl(numberAssignableToEnumInsideUnion.ts, 2, 3)) +>E : Symbol(E, Decl(numberAssignableToEnumInsideUnion.ts, 0, 0)) +>n : Symbol(n, Decl(numberAssignableToEnumInsideUnion.ts, 1, 3)) + diff --git a/tests/baselines/reference/numberAssignableToEnumInsideUnion.types b/tests/baselines/reference/numberAssignableToEnumInsideUnion.types new file mode 100644 index 00000000000..fd45ff17622 --- /dev/null +++ b/tests/baselines/reference/numberAssignableToEnumInsideUnion.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/numberAssignableToEnumInsideUnion.ts === +enum E { A, B } +>E : E +>A : E +>B : E + +let n: number; +>n : number + +let z: E | boolean = n; +>z : boolean | E +>E : E +>n : number + diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt index 50839d5e56b..6f405facceb 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt @@ -1,8 +1,5 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(4,43): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'. Object literal may only specify known properties, and 'name' does not exist in type '{ b: string; id: number; }'. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,16): error TS1131: Property or signature expected. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,25): error TS1128: Declaration or statement expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(6,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ id: string; name: number; }'. Types of property 'id' are incompatible. Type 'number' is not assignable to type 'string'. @@ -11,7 +8,7 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr Type 'number' is not assignable to type 'boolean'. -==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts (6 errors) ==== +==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts (3 errors) ==== var id: number = 10000; var name: string = "my name"; @@ -19,13 +16,7 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr ~~~~ !!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'. !!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ b: string; id: number; }'. - var person1: { name, id }; // error: can't use short-hand property assignment in type position - ~~~~ -!!! error TS1131: Property or signature expected. - ~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'. - ~ -!!! error TS1128: Declaration or statement expected. + var person1: { name, id }; // ok function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error ~~~~~~~~~~~~ !!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ id: string; name: number; }'. diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.js b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.js index 8e2d7f80356..4d01f799348 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.js +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.js @@ -3,7 +3,7 @@ var id: number = 10000; var name: string = "my name"; var person: { b: string; id: number } = { name, id }; // error -var person1: { name, id }; // error: can't use short-hand property assignment in type position +var person1: { name, id }; // ok function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error function bar(obj: { name: string; id: boolean }) { } bar({ name, id }); // error @@ -14,8 +14,7 @@ bar({ name, id }); // error var id = 10000; var name = "my name"; var person = { name: name, id: id }; // error -var person1 = name, id; -; // error: can't use short-hand property assignment in type position +var person1; // ok function foo(name, id) { return { name: name, id: id }; } // error function bar(obj) { } bar({ name: name, id: id }); // error diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt index b4f695c835d..92750fd29a0 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt @@ -3,15 +3,12 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(5,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ name: number; id: string; }'. Types of property 'name' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,16): error TS1131: Property or signature expected. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,25): error TS1128: Declaration or statement expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(8,5): error TS2322: Type '{ name: number; id: string; }' is not assignable to type '{ name: string; id: number; }'. Types of property 'name' are incompatible. Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts (6 errors) ==== +==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts (3 errors) ==== var id: number = 10000; var name: string = "my name"; @@ -25,15 +22,10 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr !!! error TS2322: Types of property 'name' are incompatible. !!! error TS2322: Type 'string' is not assignable to type 'number'. function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error - var person1: { name, id }; // error : Can't use shorthand in the type position - ~~~~ -!!! error TS1131: Property or signature expected. - ~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'. - ~ -!!! error TS1128: Declaration or statement expected. + var person1: { name, id }; // ok var person2: { name: string, id: number } = bar("hello", 5); ~~~~~~~ !!! error TS2322: Type '{ name: number; id: string; }' is not assignable to type '{ name: string; id: number; }'. !!! error TS2322: Types of property 'name' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file +!!! error TS2322: Type 'number' is not assignable to type 'string'. + \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.js b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.js index 71449746add..7800cbff53e 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.js +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.js @@ -5,8 +5,9 @@ var name: string = "my name"; var person: { b: string; id: number } = { name, id }; // error function bar(name: string, id: number): { name: number, id: string } { return { name, id }; } // error function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error -var person1: { name, id }; // error : Can't use shorthand in the type position -var person2: { name: string, id: number } = bar("hello", 5); +var person1: { name, id }; // ok +var person2: { name: string, id: number } = bar("hello", 5); + //// [objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.js] var id = 10000; @@ -14,6 +15,5 @@ var name = "my name"; var person = { name: name, id: id }; // error function bar(name, id) { return { name: name, id: id }; } // error function foo(name, id) { return { name: name, id: id }; } // error -var person1 = name, id; -; // error : Can't use shorthand in the type position +var person1; // ok var person2 = bar("hello", 5); diff --git a/tests/baselines/reference/parseObjectLiteralsWithoutTypes.js b/tests/baselines/reference/parseObjectLiteralsWithoutTypes.js new file mode 100644 index 00000000000..4872cb8773b --- /dev/null +++ b/tests/baselines/reference/parseObjectLiteralsWithoutTypes.js @@ -0,0 +1,10 @@ +//// [parseObjectLiteralsWithoutTypes.ts] +let x: { foo, bar } +let y: { foo: number, bar } +let z: { foo, bar: number } + + +//// [parseObjectLiteralsWithoutTypes.js] +var x; +var y; +var z; diff --git a/tests/baselines/reference/parseObjectLiteralsWithoutTypes.symbols b/tests/baselines/reference/parseObjectLiteralsWithoutTypes.symbols new file mode 100644 index 00000000000..1e0bd775d10 --- /dev/null +++ b/tests/baselines/reference/parseObjectLiteralsWithoutTypes.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/parseObjectLiteralsWithoutTypes.ts === +let x: { foo, bar } +>x : Symbol(x, Decl(parseObjectLiteralsWithoutTypes.ts, 0, 3)) +>foo : Symbol(foo, Decl(parseObjectLiteralsWithoutTypes.ts, 0, 8)) +>bar : Symbol(bar, Decl(parseObjectLiteralsWithoutTypes.ts, 0, 13)) + +let y: { foo: number, bar } +>y : Symbol(y, Decl(parseObjectLiteralsWithoutTypes.ts, 1, 3)) +>foo : Symbol(foo, Decl(parseObjectLiteralsWithoutTypes.ts, 1, 8)) +>bar : Symbol(bar, Decl(parseObjectLiteralsWithoutTypes.ts, 1, 21)) + +let z: { foo, bar: number } +>z : Symbol(z, Decl(parseObjectLiteralsWithoutTypes.ts, 2, 3)) +>foo : Symbol(foo, Decl(parseObjectLiteralsWithoutTypes.ts, 2, 8)) +>bar : Symbol(bar, Decl(parseObjectLiteralsWithoutTypes.ts, 2, 13)) + diff --git a/tests/baselines/reference/parseObjectLiteralsWithoutTypes.types b/tests/baselines/reference/parseObjectLiteralsWithoutTypes.types new file mode 100644 index 00000000000..dcd9cb79d19 --- /dev/null +++ b/tests/baselines/reference/parseObjectLiteralsWithoutTypes.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/parseObjectLiteralsWithoutTypes.ts === +let x: { foo, bar } +>x : { foo: any; bar: any; } +>foo : any +>bar : any + +let y: { foo: number, bar } +>y : { foo: number; bar: any; } +>foo : number +>bar : any + +let z: { foo, bar: number } +>z : { foo: any; bar: number; } +>foo : any +>bar : number + diff --git a/tests/baselines/reference/taggedTemplateUntypedTagCall01.js b/tests/baselines/reference/taggedTemplateUntypedTagCall01.js new file mode 100644 index 00000000000..e0d16eec39d --- /dev/null +++ b/tests/baselines/reference/taggedTemplateUntypedTagCall01.js @@ -0,0 +1,8 @@ +//// [taggedTemplateUntypedTagCall01.ts] +var tag: Function; +tag `Hello world!`; + +//// [taggedTemplateUntypedTagCall01.js] +var tag; +(_a = ["Hello world!"], _a.raw = ["Hello world!"], tag(_a)); +var _a; diff --git a/tests/baselines/reference/taggedTemplateUntypedTagCall01.symbols b/tests/baselines/reference/taggedTemplateUntypedTagCall01.symbols new file mode 100644 index 00000000000..07af0a996e5 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateUntypedTagCall01.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateUntypedTagCall01.ts === +var tag: Function; +>tag : Symbol(tag, Decl(taggedTemplateUntypedTagCall01.ts, 0, 3)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +tag `Hello world!`; +>tag : Symbol(tag, Decl(taggedTemplateUntypedTagCall01.ts, 0, 3)) + diff --git a/tests/baselines/reference/taggedTemplateUntypedTagCall01.types b/tests/baselines/reference/taggedTemplateUntypedTagCall01.types new file mode 100644 index 00000000000..3949869550c --- /dev/null +++ b/tests/baselines/reference/taggedTemplateUntypedTagCall01.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateUntypedTagCall01.ts === +var tag: Function; +>tag : Function +>Function : Function + +tag `Hello world!`; +>tag `Hello world!` : any +>tag : Function +>`Hello world!` : string + diff --git a/tests/baselines/reference/taggedTemplateWithConstructableTag01.errors.txt b/tests/baselines/reference/taggedTemplateWithConstructableTag01.errors.txt new file mode 100644 index 00000000000..b114acc5277 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithConstructableTag01.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag01.ts(3,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. + + +==== tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag01.ts (1 errors) ==== + class CtorTag { } + + CtorTag `Hello world!`; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateWithConstructableTag01.js b/tests/baselines/reference/taggedTemplateWithConstructableTag01.js new file mode 100644 index 00000000000..dbcb70edf00 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithConstructableTag01.js @@ -0,0 +1,13 @@ +//// [taggedTemplateWithConstructableTag01.ts] +class CtorTag { } + +CtorTag `Hello world!`; + +//// [taggedTemplateWithConstructableTag01.js] +var CtorTag = (function () { + function CtorTag() { + } + return CtorTag; +}()); +(_a = ["Hello world!"], _a.raw = ["Hello world!"], CtorTag(_a)); +var _a; diff --git a/tests/baselines/reference/taggedTemplateWithConstructableTag01.symbols b/tests/baselines/reference/taggedTemplateWithConstructableTag01.symbols new file mode 100644 index 00000000000..340d5887808 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithConstructableTag01.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag01.ts === +class CtorTag { } +>CtorTag : Symbol(CtorTag, Decl(taggedTemplateWithConstructableTag01.ts, 0, 0)) + +CtorTag `Hello world!`; +>CtorTag : Symbol(CtorTag, Decl(taggedTemplateWithConstructableTag01.ts, 0, 0)) + diff --git a/tests/baselines/reference/taggedTemplateWithConstructableTag01.types b/tests/baselines/reference/taggedTemplateWithConstructableTag01.types new file mode 100644 index 00000000000..05e5aba7cde --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithConstructableTag01.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag01.ts === +class CtorTag { } +>CtorTag : CtorTag + +CtorTag `Hello world!`; +>CtorTag `Hello world!` : any +>CtorTag : typeof CtorTag +>`Hello world!` : string + diff --git a/tests/baselines/reference/taggedTemplateWithConstructableTag02.errors.txt b/tests/baselines/reference/taggedTemplateWithConstructableTag02.errors.txt new file mode 100644 index 00000000000..9bc4414b24f --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithConstructableTag02.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag02.ts(6,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. + + +==== tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag02.ts (1 errors) ==== + interface I { + new (...args: any[]): string; + new (): number; + } + var tag: I; + tag `Hello world!`; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateWithConstructableTag02.js b/tests/baselines/reference/taggedTemplateWithConstructableTag02.js new file mode 100644 index 00000000000..6c38d508bd2 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithConstructableTag02.js @@ -0,0 +1,12 @@ +//// [taggedTemplateWithConstructableTag02.ts] +interface I { + new (...args: any[]): string; + new (): number; +} +var tag: I; +tag `Hello world!`; + +//// [taggedTemplateWithConstructableTag02.js] +var tag; +(_a = ["Hello world!"], _a.raw = ["Hello world!"], tag(_a)); +var _a; diff --git a/tests/baselines/reference/taggedTemplateWithConstructableTag02.symbols b/tests/baselines/reference/taggedTemplateWithConstructableTag02.symbols new file mode 100644 index 00000000000..2b2ccdbcbcf --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithConstructableTag02.symbols @@ -0,0 +1,16 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag02.ts === +interface I { +>I : Symbol(I, Decl(taggedTemplateWithConstructableTag02.ts, 0, 0)) + + new (...args: any[]): string; +>args : Symbol(args, Decl(taggedTemplateWithConstructableTag02.ts, 1, 9)) + + new (): number; +} +var tag: I; +>tag : Symbol(tag, Decl(taggedTemplateWithConstructableTag02.ts, 4, 3)) +>I : Symbol(I, Decl(taggedTemplateWithConstructableTag02.ts, 0, 0)) + +tag `Hello world!`; +>tag : Symbol(tag, Decl(taggedTemplateWithConstructableTag02.ts, 4, 3)) + diff --git a/tests/baselines/reference/taggedTemplateWithConstructableTag02.types b/tests/baselines/reference/taggedTemplateWithConstructableTag02.types new file mode 100644 index 00000000000..1b96c3324dd --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithConstructableTag02.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag02.ts === +interface I { +>I : I + + new (...args: any[]): string; +>args : any[] + + new (): number; +} +var tag: I; +>tag : I +>I : I + +tag `Hello world!`; +>tag `Hello world!` : any +>tag : I +>`Hello world!` : string + diff --git a/tests/baselines/reference/umdGlobalConflict.js b/tests/baselines/reference/umdGlobalConflict.js new file mode 100644 index 00000000000..e8a820e2333 --- /dev/null +++ b/tests/baselines/reference/umdGlobalConflict.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/umdGlobalConflict.ts] //// + +//// [index.d.ts] +export as namespace Alpha; +export var x: string; + +//// [index.d.ts] +export as namespace Alpha; +export var y: number; + +//// [consumer.ts] +import * as v1 from './v1'; +import * as v2 from './v2'; + +//// [global.ts] +// Should be OK, first in wins +const p: string = Alpha.x; + +//// [consumer.js] +"use strict"; +//// [global.js] +// Should be OK, first in wins +var p = Alpha.x; diff --git a/tests/baselines/reference/umdGlobalConflict.symbols b/tests/baselines/reference/umdGlobalConflict.symbols new file mode 100644 index 00000000000..b13fb0f25b1 --- /dev/null +++ b/tests/baselines/reference/umdGlobalConflict.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/v1/index.d.ts === +export as namespace Alpha; +>Alpha : Symbol(Alpha, Decl(index.d.ts, 0, 0)) + +export var x: string; +>x : Symbol(x, Decl(index.d.ts, 1, 10)) + +=== tests/cases/compiler/v2/index.d.ts === +export as namespace Alpha; +>Alpha : Symbol(Alpha, Decl(index.d.ts, 0, 0)) + +export var y: number; +>y : Symbol(y, Decl(index.d.ts, 1, 10)) + +=== tests/cases/compiler/consumer.ts === +import * as v1 from './v1'; +>v1 : Symbol(v1, Decl(consumer.ts, 0, 6)) + +import * as v2 from './v2'; +>v2 : Symbol(v2, Decl(consumer.ts, 1, 6)) + +=== tests/cases/compiler/global.ts === +// Should be OK, first in wins +const p: string = Alpha.x; +>p : Symbol(p, Decl(global.ts, 1, 5)) +>Alpha.x : Symbol(Alpha.x, Decl(index.d.ts, 1, 10)) +>Alpha : Symbol(Alpha, Decl(index.d.ts, 0, 0)) +>x : Symbol(Alpha.x, Decl(index.d.ts, 1, 10)) + diff --git a/tests/baselines/reference/umdGlobalConflict.types b/tests/baselines/reference/umdGlobalConflict.types new file mode 100644 index 00000000000..fa74e26874f --- /dev/null +++ b/tests/baselines/reference/umdGlobalConflict.types @@ -0,0 +1,29 @@ +=== tests/cases/compiler/v1/index.d.ts === +export as namespace Alpha; +>Alpha : typeof Alpha + +export var x: string; +>x : string + +=== tests/cases/compiler/v2/index.d.ts === +export as namespace Alpha; +>Alpha : typeof + +export var y: number; +>y : number + +=== tests/cases/compiler/consumer.ts === +import * as v1 from './v1'; +>v1 : typeof v1 + +import * as v2 from './v2'; +>v2 : typeof v2 + +=== tests/cases/compiler/global.ts === +// Should be OK, first in wins +const p: string = Alpha.x; +>p : string +>Alpha.x : string +>Alpha : typeof Alpha +>x : string + diff --git a/tests/cases/compiler/enumAssignmentCompat5.ts b/tests/cases/compiler/enumAssignmentCompat5.ts new file mode 100644 index 00000000000..c56db8b04f5 --- /dev/null +++ b/tests/cases/compiler/enumAssignmentCompat5.ts @@ -0,0 +1,23 @@ +enum E { + A, B, C +} +enum Computed { + A = 1 << 1, + B = 1 << 2, + C = 1 << 3, +} +let n: number; +let e: E = n; // ok because it's too inconvenient otherwise +e = 0; // ok, in range +e = 4; // ok, out of range, but allowed computed enums don't have all members +let a: E.A = 0; // ok, A === 0 +a = 2; // error, 2 !== 0 +a = n; // ok + +let c: Computed = n; // ok +c = n; // ok +c = 4; // ok +let ca: Computed.A = 1; // error, Computed.A isn't a literal type because Computed has no enum literals + + + diff --git a/tests/cases/compiler/enumLiteralAssignableToEnumInsideUnion.ts b/tests/cases/compiler/enumLiteralAssignableToEnumInsideUnion.ts new file mode 100644 index 00000000000..19cd98fd5e8 --- /dev/null +++ b/tests/cases/compiler/enumLiteralAssignableToEnumInsideUnion.ts @@ -0,0 +1,28 @@ +module X { + export enum Foo { + A, B + } +} +module Y { + export enum Foo { + A, B + } +} +module Z { + export enum Foo { + A = 1 << 1, + B = 1 << 2, + } +} +module Ka { + export enum Foo { + A = 1 << 10, + B = 1 << 11, + } +} +const e0: X.Foo | boolean = Y.Foo.A; // ok +const e1: X.Foo | boolean = Z.Foo.A; // not legal, Z is computed +const e2: X.Foo.A | X.Foo.B | boolean = Z.Foo.A; // still not legal +const e3: X.Foo.B | boolean = Z.Foo.A; // not legal +const e4: X.Foo.A | boolean = Z.Foo.A; // not legal either because Z.Foo is computed and Z.Foo.A is not necessarily assignable to X.Foo.A +const e5: Ka.Foo | boolean = Z.Foo.A; // ok diff --git a/tests/cases/compiler/noImplicitAnyMissingGetAccessor.ts b/tests/cases/compiler/noImplicitAnyMissingGetAccessor.ts new file mode 100644 index 00000000000..d6c7b012cf9 --- /dev/null +++ b/tests/cases/compiler/noImplicitAnyMissingGetAccessor.ts @@ -0,0 +1,14 @@ +// @noImplicitAny : true +// @target: es5 + +abstract class Parent +{ + public abstract set message(str); +} + +class Child extends Parent { + _x: any; + public set message(str) { + this._x = str; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/noImplicitAnyMissingSetAccessor.ts b/tests/cases/compiler/noImplicitAnyMissingSetAccessor.ts new file mode 100644 index 00000000000..ae18faf1f6f --- /dev/null +++ b/tests/cases/compiler/noImplicitAnyMissingSetAccessor.ts @@ -0,0 +1,13 @@ +// @noImplicitAny: true +// @target: es5 + +abstract class Parent +{ + public abstract get message(); +} + +class Child extends Parent { + public get message() { + return ""; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/numberAssignableToEnumInsideUnion.ts b/tests/cases/compiler/numberAssignableToEnumInsideUnion.ts new file mode 100644 index 00000000000..fbefb5ac802 --- /dev/null +++ b/tests/cases/compiler/numberAssignableToEnumInsideUnion.ts @@ -0,0 +1,3 @@ +enum E { A, B } +let n: number; +let z: E | boolean = n; diff --git a/tests/cases/compiler/parseObjectLiteralsWithoutTypes.ts b/tests/cases/compiler/parseObjectLiteralsWithoutTypes.ts new file mode 100644 index 00000000000..7f00e4b15e7 --- /dev/null +++ b/tests/cases/compiler/parseObjectLiteralsWithoutTypes.ts @@ -0,0 +1,3 @@ +let x: { foo, bar } +let y: { foo: number, bar } +let z: { foo, bar: number } diff --git a/tests/cases/compiler/umdGlobalConflict.ts b/tests/cases/compiler/umdGlobalConflict.ts new file mode 100644 index 00000000000..58b4ea6be02 --- /dev/null +++ b/tests/cases/compiler/umdGlobalConflict.ts @@ -0,0 +1,15 @@ +//@filename: v1/index.d.ts +export as namespace Alpha; +export var x: string; + +//@filename: v2/index.d.ts +export as namespace Alpha; +export var y: number; + +//@filename: consumer.ts +import * as v1 from './v1'; +import * as v2 from './v2'; + +//@filename: global.ts +// Should be OK, first in wins +const p: string = Alpha.x; \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/constructableDecoratorOnClass01.ts b/tests/cases/conformance/decorators/class/constructableDecoratorOnClass01.ts new file mode 100644 index 00000000000..a9f9fa1699d --- /dev/null +++ b/tests/cases/conformance/decorators/class/constructableDecoratorOnClass01.ts @@ -0,0 +1,8 @@ +// @experimentalDecorators: true + +class CtorDtor {} + +@CtorDtor +class C { + +} diff --git a/tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts b/tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts index b745b93b3ca..55f10aec932 100644 --- a/tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts +++ b/tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts @@ -2,7 +2,7 @@ var name: string = "my name"; var person: { b: string; id: number } = { name, id }; // error -var person1: { name, id }; // error: can't use short-hand property assignment in type position +var person1: { name, id }; // ok function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error function bar(obj: { name: string; id: boolean }) { } bar({ name, id }); // error diff --git a/tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts b/tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts index 6b0943a8d77..104be41a839 100644 --- a/tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts +++ b/tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts @@ -4,5 +4,5 @@ var name: string = "my name"; var person: { b: string; id: number } = { name, id }; // error function bar(name: string, id: number): { name: number, id: string } { return { name, id }; } // error function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error -var person1: { name, id }; // error : Can't use shorthand in the type position -var person2: { name: string, id: number } = bar("hello", 5); \ No newline at end of file +var person1: { name, id }; // ok +var person2: { name: string, id: number } = bar("hello", 5); diff --git a/tests/cases/conformance/es6/templates/taggedTemplateUntypedTagCall01.ts b/tests/cases/conformance/es6/templates/taggedTemplateUntypedTagCall01.ts new file mode 100644 index 00000000000..b77e04b3095 --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateUntypedTagCall01.ts @@ -0,0 +1,2 @@ +var tag: Function; +tag `Hello world!`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag01.ts b/tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag01.ts new file mode 100644 index 00000000000..996f5b80298 --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag01.ts @@ -0,0 +1,3 @@ +class CtorTag { } + +CtorTag `Hello world!`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag02.ts b/tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag02.ts new file mode 100644 index 00000000000..7c6f009bf23 --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateWithConstructableTag02.ts @@ -0,0 +1,6 @@ +interface I { + new (...args: any[]): string; + new (): number; +} +var tag: I; +tag `Hello world!`; \ No newline at end of file diff --git a/tests/cases/fourslash/cloduleAsBaseClass.ts b/tests/cases/fourslash/cloduleAsBaseClass.ts index 19bd3bb53e3..89f7b8ce8a7 100644 --- a/tests/cases/fourslash/cloduleAsBaseClass.ts +++ b/tests/cases/fourslash/cloduleAsBaseClass.ts @@ -23,9 +23,6 @@ ////d./*1*/ ////D./*2*/ -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('1'); verify.completionListContains('foo'); verify.completionListContains('foo2'); diff --git a/tests/cases/fourslash/cloduleAsBaseClass2.ts b/tests/cases/fourslash/cloduleAsBaseClass2.ts index 310ae72d664..995348fc7d1 100644 --- a/tests/cases/fourslash/cloduleAsBaseClass2.ts +++ b/tests/cases/fourslash/cloduleAsBaseClass2.ts @@ -28,9 +28,6 @@ ////d./*1*/ ////D./*2*/ -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('1'); verify.completionListContains('foo'); verify.completionListContains('foo2'); diff --git a/tests/cases/fourslash/cloduleTypeOf1.ts b/tests/cases/fourslash/cloduleTypeOf1.ts index f34bb04c075..16f49a6ddb3 100644 --- a/tests/cases/fourslash/cloduleTypeOf1.ts +++ b/tests/cases/fourslash/cloduleTypeOf1.ts @@ -14,10 +14,6 @@ //// } ////} -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - - goTo.marker('1'); verify.completionListContains('f'); verify.completionListContains('foo'); diff --git a/tests/cases/fourslash/cloduleWithRecursiveReference.ts b/tests/cases/fourslash/cloduleWithRecursiveReference.ts index 069049907ff..0a22bf7af42 100644 --- a/tests/cases/fourslash/cloduleWithRecursiveReference.ts +++ b/tests/cases/fourslash/cloduleWithRecursiveReference.ts @@ -9,9 +9,6 @@ //// } ////} -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker(); verify.quickInfoIs('var M.C.C: typeof M.C'); verify.numberOfErrorsInCurrentFile(0); \ No newline at end of file diff --git a/tests/cases/fourslash/commentsClass.ts b/tests/cases/fourslash/commentsClass.ts index b9a446efe6e..fb42c01f4c9 100644 --- a/tests/cases/fourslash/commentsClass.ts +++ b/tests/cases/fourslash/commentsClass.ts @@ -58,9 +58,6 @@ ////} ////var myVar = new m.m2.c/*33*/1(); -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('1'); verify.quickInfoIs("class c2", "This is class c2 without constuctor"); diff --git a/tests/cases/fourslash/commentsExternalModules.ts b/tests/cases/fourslash/commentsExternalModules.ts index c4bba7c444f..c7212fbea61 100644 --- a/tests/cases/fourslash/commentsExternalModules.ts +++ b/tests/cases/fourslash/commentsExternalModules.ts @@ -31,9 +31,6 @@ /////*10*/extMod./*11*/m1./*12*/fooExp/*13q*/ort(/*13*/); ////var new/*14*/Var = new extMod.m1.m2./*15*/c(); -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.file("commentsExternalModules_file0.ts"); goTo.marker('1'); verify.quickInfoIs("namespace m1", "Namespace comment"); diff --git a/tests/cases/fourslash/commentsMultiModuleMultiFile.ts b/tests/cases/fourslash/commentsMultiModuleMultiFile.ts index 9516ddc9abb..2a9e01e42d9 100644 --- a/tests/cases/fourslash/commentsMultiModuleMultiFile.ts +++ b/tests/cases/fourslash/commentsMultiModuleMultiFile.ts @@ -26,8 +26,6 @@ ////} ////new /*7*/mu/*8*/ltiM.d(); -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); goTo.marker('1'); verify.completionListContains("multiM", "namespace multiM", "this is multi declare namespace\nthi is multi namespace 2\nthis is multi namespace 3 comment"); diff --git a/tests/cases/fourslash/commentsMultiModuleSingleFile.ts b/tests/cases/fourslash/commentsMultiModuleSingleFile.ts index c2bd677ce9a..0393338b26c 100644 --- a/tests/cases/fourslash/commentsMultiModuleSingleFile.ts +++ b/tests/cases/fourslash/commentsMultiModuleSingleFile.ts @@ -16,9 +16,6 @@ ////new /*1*/mu/*4*/ltiM.b(); ////new mu/*5*/ltiM.c(); -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('1'); verify.completionListContains("multiM", "namespace multiM", "this is multi declare namespace\nthi is multi namespace 2"); diff --git a/tests/cases/fourslash/completionForStringLiteralImport1.ts b/tests/cases/fourslash/completionForStringLiteralImport1.ts new file mode 100644 index 00000000000..4cdee889538 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralImport1.ts @@ -0,0 +1,33 @@ +/// + +// Should define spans for replacement that appear after the last directory seperator in import statements + +// @typeRoots: my_typings + +// @Filename: test.ts +//// import * as foo0 from "./[|some|]/*0*/ +//// import * as foo1 from "./sub/[|some|]/*1*/ +//// import * as foo2 from "[|some-|]/*2*/" +//// import * as foo3 from "../[||]/*3*/"; + + +// @Filename: someFile1.ts +//// /*someFile1*/ + +// @Filename: sub/someFile2.ts +//// /*someFile2*/ + +// @Filename: my_typings/some-module/index.d.ts +//// export var x = 9; + +goTo.marker("0"); +verify.completionListContains("someFile1", undefined, undefined, undefined, 0); + +goTo.marker("1"); +verify.completionListContains("someFile2", undefined, undefined, undefined, 1); + +goTo.marker("2"); +verify.completionListContains("some-module", undefined, undefined, undefined, 2); + +goTo.marker("3"); +verify.completionListContains("fourslash", undefined, undefined, undefined, 3); \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralImport2.ts b/tests/cases/fourslash/completionForStringLiteralImport2.ts new file mode 100644 index 00000000000..25de3d2240a --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralImport2.ts @@ -0,0 +1,33 @@ +/// + +// Should define spans for replacement that appear after the last directory seperator in triple slash references + +// @typeRoots: my_typings + +// @Filename: test.ts +//// /// +//// /// + +// @Filename: someFile.ts +//// /*someFile*/ + +// @Filename: sub/someOtherFile.ts +//// /*someOtherFile*/ + +// @Filename: my_typings/some-module/index.d.ts +//// export var x = 9; + +goTo.marker("0"); +verify.completionListContains("someFile.ts", undefined, undefined, undefined, 0); + +goTo.marker("1"); +verify.completionListContains("some-module", undefined, undefined, undefined, 1); + +goTo.marker("2"); +verify.completionListContains("someOtherFile.ts", undefined, undefined, undefined, 2); + +goTo.marker("3"); +verify.completionListContains("some-module", undefined, undefined, undefined, 3); \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport1.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport1.ts new file mode 100644 index 00000000000..c0e5ebbcd90 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport1.ts @@ -0,0 +1,63 @@ +/// + +// Should give completions for node modules and files within those modules with ts file extensions + +// @Filename: tests/test0.ts +//// import * as foo1 from "f/*import_as0*/ +//// import * as foo2 from "fake-module//*import_as1*/ +//// import * as foo3 from "fake-module/*import_as2*/ + +//// import foo4 = require("f/*import_equals0*/ +//// import foo5 = require("fake-module//*import_equals1*/ +//// import foo6 = require("fake-module/*import_equals2*/ + +//// var foo7 = require("f/*require0*/ +//// var foo8 = require("fake-module//*require1*/ +//// var foo9 = require("fake-module/*require2*/ + +// @Filename: package.json +//// { "dependencies": { "fake-module": "latest" }, "devDependencies": { "fake-module-dev": "latest" } } + +// @Filename: node_modules/fake-module/index.js +//// /*fake-module*/ +// @Filename: node_modules/fake-module/index.d.ts +//// /*fakemodule-d-ts*/ +// @Filename: node_modules/fake-module/ts.ts +//// /*ts*/ +// @Filename: node_modules/fake-module/dts.d.ts +//// /*dts*/ +// @Filename: node_modules/fake-module/tsx.tsx +//// /*tsx*/ +// @Filename: node_modules/fake-module/js.js +//// /*js*/ +// @Filename: node_modules/fake-module/jsx.jsx +//// /*jsx*/ + +// @Filename: node_modules/fake-module-dev/index.js +//// /*fakemodule-dev*/ +// @Filename: node_modules/fake-module-dev/index.d.ts +//// /*fakemodule-dev-d-ts*/ + +// @Filename: node_modules/unlisted-module/index.ts +//// /*unlisted-module*/ + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListContains("fake-module"); + verify.completionListContains("fake-module-dev"); + verify.not.completionListItemsCountIsGreaterThan(2); + + goTo.marker(kind + "1"); + verify.completionListContains("index"); + verify.completionListContains("ts"); + verify.completionListContains("dts"); + verify.completionListContains("tsx"); + verify.not.completionListItemsCountIsGreaterThan(4); + + goTo.marker(kind + "2"); + verify.completionListContains("fake-module"); + verify.completionListContains("fake-module-dev"); + verify.not.completionListItemsCountIsGreaterThan(2); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport10.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport10.ts new file mode 100644 index 00000000000..24a323bc6e5 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport10.ts @@ -0,0 +1,35 @@ +/// + +// Should not give node module completions if classic module resolution is enabled + +// @moduleResolution: classic + +// @Filename: dir1/dir2/dir3/dir4/test0.ts +//// import * as foo1 from "f/*import_as0*/ +//// import * as foo3 from "fake-module/*import_as1*/ + +//// import foo4 = require("f/*import_equals0*/ +//// import foo6 = require("fake-module/*import_equals1*/ + +//// var foo7 = require("f/*require0*/ +//// var foo9 = require("fake-module/*require1*/ + +// @Filename: package.json +//// { "dependencies": { "fake-module": "latest" } } +// @Filename: node_modules/fake-module/ts.ts +//// /*module1*/ + +// @Filename: dir1/dir2/dir3/package.json +//// { "dependencies": { "fake-module3": "latest" } } +// @Filename: dir1/dir2/dir3/node_modules/fake-module3/ts.ts +//// /*module3*/ + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListIsEmpty(); + + goTo.marker(kind + "1"); + verify.completionListIsEmpty(); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport11.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport11.ts new file mode 100644 index 00000000000..7b81c4da106 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport11.ts @@ -0,0 +1,38 @@ +/// + +// Should handle nested files in folders discovered via the baseUrl compiler option + +// @baseUrl: tests/cases/fourslash/modules + +// @Filename: tests/test0.ts +//// import * as foo1 from "subfolder//*import_as0*/ +//// import foo2 = require("subfolder//*import_equals0*/ +//// var foo3 = require("subfolder//*require0*/ + +//// import * as foo1 from "module-from-node//*import_as1*/ +//// import foo2 = require("module-from-node//*import_equals1*/ +//// var foo3 = require("module-from-node//*require1*/ + +// @Filename: modules/subfolder/module.ts +//// export var x = 5; + +// @Filename: package.json +//// { "dependencies": { "module-from-node": "latest" } } +// @Filename: node_modules/module-from-node/index.ts +//// /*module1*/ + + + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + + verify.completionListContains("module"); + verify.not.completionListItemsCountIsGreaterThan(1); + + goTo.marker(kind + "1"); + + verify.completionListContains("index"); + verify.not.completionListItemsCountIsGreaterThan(1); +} diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport12.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport12.ts new file mode 100644 index 00000000000..ed202d68ec1 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport12.ts @@ -0,0 +1,28 @@ +/// + +// Should give completions for all dependencies in package.json + +// @Filename: tests/test0.ts +//// import * as foo1 from "m/*import_as0*/ +//// import foo2 = require("m/*import_equals0*/ +//// var foo3 = require("m/*require0*/ + +// @Filename: package.json +//// { +//// "dependencies": { "module": "latest" }, +//// "devDependencies": { "dev-module": "latest" }, +//// "optionalDependencies": { "optional-module": "latest" }, +//// "peerDependencies": { "peer-module": "latest" } +//// } + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + + verify.completionListContains("module"); + verify.completionListContains("dev-module"); + verify.completionListContains("optional-module"); + verify.completionListContains("peer-module"); + verify.not.completionListItemsCountIsGreaterThan(4); +} diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport2.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport2.ts new file mode 100644 index 00000000000..bac5c54ff23 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport2.ts @@ -0,0 +1,37 @@ +/// + +// Should not give duplicate entries for similarly named files with different extensions + +// @Filename: tests/test0.ts +//// import * as foo1 from "fake-module//*import_as0*/ +//// import foo2 = require("fake-module//*import_equals0*/ +//// var foo3 = require("fake-module//*require0*/ + +// @Filename: package.json +//// { "dependencies": { "fake-module": "latest" }, "devDependencies": { "fake-module-dev": "latest" } } + +// @Filename: node_modules/fake-module/repeated.ts +//// /*repeatedts*/ +// @Filename: node_modules/fake-module/repeated.tsx +//// /*repeatedtsx*/ +// @Filename: node_modules/fake-module/repeated.d.ts +//// /*repeateddts*/ +// @Filename: node_modules/fake-module/other.js +//// /*other*/ +// @Filename: node_modules/fake-module/other2.js +//// /*other2*/ + +// @Filename: node_modules/unlisted-module/index.js +//// /*unlisted-module*/ + +// @Filename: ambient.ts +//// declare module "fake-module/other" + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListContains("repeated"); + verify.completionListContains("other"); + verify.not.completionListItemsCountIsGreaterThan(2); +} diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport3.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport3.ts new file mode 100644 index 00000000000..d2103f6f10c --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport3.ts @@ -0,0 +1,38 @@ +/// + +// Should give completions for js files in node modules when allowJs is set to true + +// @allowJs: true + +// @Filename: tests/test0.ts +//// import * as foo1 from "fake-module//*import_as0*/ +//// import foo2 = require("fake-module//*import_equals0*/ +//// var foo3 = require("fake-module//*require0*/ + +// @Filename: package.json +//// { "dependencies": { "fake-module": "latest" } } + +// @Filename: node_modules/fake-module/ts.ts +//// /*ts*/ +// @Filename: node_modules/fake-module/tsx.tsx +//// /*tsx*/ +// @Filename: node_modules/fake-module/dts.d.ts +//// /*dts*/ +// @Filename: node_modules/fake-module/js.js +//// /*js*/ +// @Filename: node_modules/fake-module/jsx.jsx +//// /*jsx*/ +// @Filename: node_modules/fake-module/repeated.js +//// /*repeatedjs*/ +// @Filename: node_modules/fake-module/repeated.jsx +//// /*repeatedjsx*/ + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListContains("ts"); + verify.completionListContains("tsx"); + verify.completionListContains("dts"); + verify.not.completionListItemsCountIsGreaterThan(3); +} diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport4.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport4.ts new file mode 100644 index 00000000000..b95fd96f380 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport4.ts @@ -0,0 +1,34 @@ +/// + +// Should give completions for all node modules visible to the script + +// @Filename: dir1/dir2/dir3/dir4/test0.ts +//// import * as foo1 from "f/*import_as0*/ +//// import foo4 = require("f/*import_equals0*/ +//// var foo7 = require("f/*require0*/ + +// @Filename: package.json +//// { "dependencies": { "fake-module": "latest" } } +// @Filename: node_modules/fake-module/ts.ts +//// /*module1*/ + +// @Filename: dir1/package.json +//// { "dependencies": { "fake-module2": "latest" } } +// @Filename: dir1/node_modules/fake-module2/index.ts +//// /*module2*/ + +// @Filename: dir1/dir2/dir3/package.json +//// { "dependencies": { "fake-module3": "latest" } } +// @Filename: dir1/dir2/dir3/node_modules/fake-module3/ts.ts +//// /*module3*/ + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + + verify.completionListContains("fake-module"); + verify.completionListContains("fake-module2"); + verify.completionListContains("fake-module3"); + verify.not.completionListItemsCountIsGreaterThan(3); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport5.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport5.ts new file mode 100644 index 00000000000..c8c9a18ff85 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport5.ts @@ -0,0 +1,39 @@ +/// + +// Should give completions for ambiently declared modules + +// @Filename: test0.ts +//// /// +//// /// +//// import * as foo1 from "/*import_as0*/ +//// import * as foo2 from "a/*import_as1*/ + +//// import foo3 = require("/*import_equals0*/ +//// import foo4 = require("a/*import_equals1*/ + +//// var foo5 = require("/*require0*/ +//// var foo6 = require("a/*require1*/ + +// @Filename: ambientModules.d.ts +//// declare module "ambientModule" {} +//// declare module "otherAmbientModule" {} /*dummy0*/ + +// @Filename: ambientModules2.d.ts +//// declare module "otherOtherAmbientModule" {} /*dummy1*/ + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + + verify.completionListContains("ambientModule"); + verify.completionListContains("otherAmbientModule"); + verify.completionListContains("otherOtherAmbientModule"); + verify.not.completionListItemsCountIsGreaterThan(3); + + goTo.marker(kind + "1"); + + verify.completionListContains("ambientModule"); + verify.not.completionListItemsCountIsGreaterThan(1); +} + diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport7.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport7.ts new file mode 100644 index 00000000000..57ba6e440cf --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport7.ts @@ -0,0 +1,30 @@ +/// + +// Should give completions for files that are discovered via the baseUrl compiler option + +// @baseUrl: tests/cases/fourslash/modules + +// @Filename: tests/test0.ts +//// import * as foo1 from "mod/*import_as0*/ +//// import foo2 = require("mod/*import_equals0*/ +//// var foo3 = require("mod/*require0*/ + +// @Filename: modules/module.ts +//// export var x = 5; + +// @Filename: package.json +//// { "dependencies": { "module-from-node": "latest" } } +// @Filename: node_modules/module-from-node/index.ts +//// /*module1*/ + + + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + + verify.completionListContains("module"); + verify.completionListContains("module-from-node"); + verify.not.completionListItemsCountIsGreaterThan(2); +} diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport8.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport8.ts new file mode 100644 index 00000000000..603e8d1104d --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport8.ts @@ -0,0 +1,55 @@ +/// + +// Should give completions for modules referenced via baseUrl and paths compiler options with wildcards + +// @Filename: tsconfig.json +//// { +//// "compilerOptions": { +//// "baseUrl": "./modules", +//// "paths": { +//// "*": [ +//// "prefix/0*/suffix.ts", +//// "prefix-only/*", +//// "*/suffix-only.ts" +//// ] +//// } +//// } +//// } + + +// @Filename: tests/test0.ts +//// import * as foo1 from "0/*import_as0*/ +//// import foo2 = require("0/*import_equals0*/ +//// var foo3 = require("0/*require0*/ + +//// import * as foo1 from "1/*import_as1*/ +//// import foo2 = require("1/*import_equals1*/ +//// var foo3 = require("1/*require1*/ + +//// import * as foo1 from "2/*import_as2*/ +//// import foo2 = require("2/*import_equals2*/ +//// var foo3 = require("2/*require2*/ + + +// @Filename: modules/prefix/00test/suffix.ts +//// export var x = 5; + +// @Filename: modules/prefix-only/1test.ts +//// export var y = 5; + +// @Filename: modules/2test/suffix-only.ts +//// export var z = 5; + + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListContains("0test"); + + goTo.marker(kind + "1"); + verify.completionListContains("1test"); + + goTo.marker(kind + "2"); + verify.completionListContains("2test"); +} diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport9.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport9.ts new file mode 100644 index 00000000000..8703c608462 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport9.ts @@ -0,0 +1,36 @@ +/// + +// Should give completions for modules referenced via baseUrl and paths compiler options with explicit name mappings + +// @Filename: tsconfig.json +//// { +//// "compilerOptions": { +//// "baseUrl": "./modules", +//// "paths": { +//// "module1": ["some/path/whatever.ts"], +//// "module2": ["some/other/path.ts"] +//// } +//// } +//// } + + +// @Filename: tests/test0.ts +//// import * as foo1 from "m/*import_as0*/ +//// import foo2 = require("m/*import_equals0*/ +//// var foo3 = require("m/*require0*/ + +// @Filename: some/path/whatever.ts +//// export var x = 9; + +// @Filename: some/other/path.ts +//// export var y = 10; + + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListContains("module1"); + verify.completionListContains("module2"); + verify.not.completionListItemsCountIsGreaterThan(2); +} diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImportTypings1.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImportTypings1.ts new file mode 100644 index 00000000000..687103629e2 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImportTypings1.ts @@ -0,0 +1,35 @@ +/// + +// Should give completions for typings discovered via the typeRoots compiler option + +// @typeRoots: my_typings,my_other_typings + + +// @Filename: tests/test0.ts +//// /// +//// import * as foo1 from "m/*import_as0*/ +//// import foo2 = require("m/*import_equals0*/ +//// var foo3 = require("m/*require0*/ + +// @Filename: my_typings/module-x/index.d.ts +//// export var x = 9; + +// @Filename: my_typings/module-x/whatever.d.ts +//// export var w = 9; + +// @Filename: my_typings/module-y/index.d.ts +//// export var y = 9; + +// @Filename: my_other_typings/module-z/index.d.ts +//// export var z = 9; + + +const kinds = ["types_ref", "import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListContains("module-x"); + verify.completionListContains("module-y"); + verify.completionListContains("module-z"); + verify.not.completionListItemsCountIsGreaterThan(3); +} diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImportTypings2.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImportTypings2.ts new file mode 100644 index 00000000000..12a4fcf243f --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImportTypings2.ts @@ -0,0 +1,32 @@ +/// + +// Should respect the types compiler option when giving completions + +// @typeRoots: my_typings,my_other_typings +// @types: module-x,module-z + + +// @Filename: tests/test0.ts +//// /// +//// import * as foo1 from "m/*import_as0*/ +//// import foo2 = require("m/*import_equals0*/ +//// var foo3 = require("m/*require0*/ + +// @Filename: my_typings/module-x/index.d.ts +//// export var x = 9; + +// @Filename: my_typings/module-y/index.d.ts +//// export var y = 9; + +// @Filename: my_other_typings/module-z/index.d.ts +//// export var z = 9; + + +const kinds = ["types_ref", "import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListContains("module-x"); + verify.completionListContains("module-z"); + verify.not.completionListItemsCountIsGreaterThan(2); +} diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImportTypings3.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImportTypings3.ts new file mode 100644 index 00000000000..14cf71ad0dc --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImportTypings3.ts @@ -0,0 +1,28 @@ +/// + +// Should give completions for typings discovered in all visible @types directories + +// @Filename: subdirectory/test0.ts +//// /// +//// import * as foo1 from "m/*import_as0*/ +//// import foo2 = require("m/*import_equals0*/ +//// var foo3 = require("m/*require0*/ + +// @Filename: subdirectory/node_modules/@types/module-x/index.d.ts +//// export var x = 9; +// @Filename: subdirectory/package.json +//// { "dependencies": { "@types/module-x": "latest" } } + +// @Filename: node_modules/@types/module-y/index.d.ts +//// export var y = 9; +// @Filename: package.json +//// { "dependencies": { "@types/module-y": "latest" } } + +const kinds = ["types_ref", "import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListContains("module-x"); + verify.completionListContains("module-y"); + verify.not.completionListItemsCountIsGreaterThan(2); +} diff --git a/tests/cases/fourslash/completionForStringLiteralRelativeImport1.ts b/tests/cases/fourslash/completionForStringLiteralRelativeImport1.ts new file mode 100644 index 00000000000..3ba82fb0acf --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralRelativeImport1.ts @@ -0,0 +1,70 @@ +/// + +// Should give completions for ts files when allowJs is false + +// @Filename: test0.ts +//// import * as foo1 from "./*import_as0*/ +//// import * as foo2 from ".//*import_as1*/ +//// import * as foo4 from "./folder//*import_as2*/ + +//// import foo6 = require("./*import_equals0*/ +//// import foo7 = require(".//*import_equals1*/ +//// import foo9 = require("./folder//*import_equals2*/ + +//// var foo11 = require("./*require0*/ +//// var foo12 = require(".//*require1*/ +//// var foo14 = require("./folder//*require2*/ + +// @Filename: parentTest/sub/test5.ts +//// import * as foo16 from "../g/*import_as3*/ +//// import foo17 = require("../g/*import_equals3*/ +//// var foo18 = require("../g/*require3*/ + + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f1.js +//// /*f1j*/ +// @Filename: f1.d.ts +//// /*f1d*/ +// @Filename: f2.tsx +//// /f2*/ +// @Filename: f3.js +//// /*f3*/ +// @Filename: f4.jsx +//// /*f4*/ +// @Filename: e1.ts +//// /*e1*/ +// @Filename: folder/f3.ts +//// /*subf1*/ +// @Filename: folder/h1.ts +//// /*subh1*/ +// @Filename: parentTest/f4.ts +//// /*parentf1*/ +// @Filename: parentTest/g1.ts +//// /*parentg1*/ +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListIsEmpty(); + + goTo.marker(kind + "1"); + verify.completionListContains("f1"); + verify.completionListContains("f2"); + verify.completionListContains("e1"); + verify.completionListContains("folder"); + verify.completionListContains("parentTest"); + verify.not.completionListItemsCountIsGreaterThan(5); + + goTo.marker(kind + "2"); + verify.completionListContains("f3"); + verify.completionListContains("h1"); + verify.not.completionListItemsCountIsGreaterThan(2); + + goTo.marker(kind + "3"); + verify.completionListContains("f4"); + verify.completionListContains("g1"); + verify.completionListContains("sub"); + verify.not.completionListItemsCountIsGreaterThan(3); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralRelativeImport2.ts b/tests/cases/fourslash/completionForStringLiteralRelativeImport2.ts new file mode 100644 index 00000000000..18a80ab3481 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralRelativeImport2.ts @@ -0,0 +1,53 @@ +/// + +// Should give completions for ts and js files when allowJs is true + +// @allowJs: true + +// @Filename: test0.ts +//// import * as foo1 from ".//*import_as0*/ +//// import * as foo2 from "./f/*import_as1*/ + +//// import foo3 = require(".//*import_equals0*/ +//// import foo4 = require("./f/*import_equals1*/ + +//// var foo5 = require(".//*require0*/ +//// var foo6 = require("./f/*require1*/ + +// @Filename: f1.ts +//// /f1*/ +// @Filename: f1.js +//// /*f1j*/ +// @Filename: f1.d.ts +//// /*f1d*/ +// @Filename: f2.tsx +//// /*f2*/ +// @Filename: f3.js +//// /*f3*/ +// @Filename: f4.jsx +//// /*f4*/ +// @Filename: e1.ts +//// /*e1*/ +// @Filename: e2.js +//// /*e2*/ +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListContains("f1"); + verify.completionListContains("f2"); + verify.completionListContains("f3"); + verify.completionListContains("f4"); + verify.completionListContains("e1"); + verify.completionListContains("e2"); + verify.not.completionListItemsCountIsGreaterThan(6); + + goTo.marker(kind + "1"); + verify.completionListContains("f1"); + verify.completionListContains("f2"); + verify.completionListContains("f3"); + verify.completionListContains("f4"); + verify.completionListContains("e1"); + verify.completionListContains("e2"); + verify.not.completionListItemsCountIsGreaterThan(6); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralRelativeImport3.ts b/tests/cases/fourslash/completionForStringLiteralRelativeImport3.ts new file mode 100644 index 00000000000..915cebdf6e7 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralRelativeImport3.ts @@ -0,0 +1,51 @@ +/// + +// Should give completions for absolute paths + +// @Filename: tests/test0.ts +//// import * as foo1 from "/tests/cases/f/*import_as0*/ +//// import * as foo2 from "/tests/cases/fourslash/*import_as1*/ +//// import * as foo3 from "/tests/cases/fourslash//*import_as2*/ + +//// import foo4 = require("/tests/cases/f/*import_equals0*/ +//// import foo5 = require("/tests/cases/fourslash/*import_equals1*/ +//// import foo6 = require("/tests/cases/fourslash//*import_equals2*/ + +//// var foo7 = require("/tests/cases/f/*require0*/ +//// var foo8 = require("/tests/cases/fourslash/*require1*/ +//// var foo9 = require("/tests/cases/fourslash//*require2*/ + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f2.tsx +//// /*f2*/ +// @Filename: folder/f1.ts +//// /*subf1*/ +// @Filename: f3.js +//// /*f3*/ +// @Filename: f4.jsx +//// /*f4*/ +// @Filename: e1.ts +//// /*e1*/ +// @Filename: e2.js +//// /*e2*/ + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListContains("fourslash"); + verify.not.completionListItemsCountIsGreaterThan(1); + + goTo.marker(kind + "1"); + verify.completionListContains("fourslash"); + verify.not.completionListItemsCountIsGreaterThan(1); + + goTo.marker(kind + "2"); + verify.completionListContains("f1"); + verify.completionListContains("f2"); + verify.completionListContains("e1"); + verify.completionListContains("folder"); + verify.completionListContains("tests"); + verify.not.completionListItemsCountIsGreaterThan(5); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralRelativeImport4.ts b/tests/cases/fourslash/completionForStringLiteralRelativeImport4.ts new file mode 100644 index 00000000000..b9750de9c17 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralRelativeImport4.ts @@ -0,0 +1,52 @@ +/// + +// Should give completions for directories that are merged via the rootDirs compiler option + +// @rootDirs: tests/cases/fourslash/sub/src1,tests/cases/fourslash/src2 + +// @Filename: src2/test0.ts +//// import * as foo1 from "./mo/*import_as0*/ +//// import foo2 = require("./mo/*import_equals0*/ +//// var foo3 = require("./mo/*require0*/ + +// @Filename: src2/module0.ts +//// export var w = 0; + +// @Filename: sub/src1/module1.ts +//// export var x = 0; + +// @Filename: sub/src1/module2.ts +//// export var y = 0; + +// @Filename: sub/src1/more/module3.ts +//// export var z = 0; + + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f2.tsx +//// /*f2*/ +// @Filename: folder/f1.ts +//// /*subf1*/ +// @Filename: f3.js +//// /*f3*/ +// @Filename: f4.jsx +//// /*f4*/ +// @Filename: e1.ts +//// /*e1*/ +// @Filename: e2.js +//// /*e2*/ + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + + verify.completionListContains("module0"); + verify.completionListContains("module1"); + verify.completionListContains("module2"); + verify.completionListContains("more"); + + // Should not contain itself + verify.not.completionListItemsCountIsGreaterThan(4); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionForTripleSlashReference1.ts b/tests/cases/fourslash/completionForTripleSlashReference1.ts new file mode 100644 index 00000000000..2ce4de2e72e --- /dev/null +++ b/tests/cases/fourslash/completionForTripleSlashReference1.ts @@ -0,0 +1,51 @@ +/// + +// Should give completions for relative references to ts files when allowJs is false + +// @Filename: test0.ts +//// /// +//// /// + +// Should give completions for relative references to js and ts files when allowJs is true + +// @allowJs: true + +// @Filename: test0.ts +//// /// + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f1.js +//// /*f1j*/ +// @Filename: f1.d.ts +//// /*f1d*/ +// @Filename: f2.tsx +//// /f2*/ +// @Filename: f4.jsx +//// /*f4*/ + +for (let i = 0; i < 5; i++) { + goTo.marker("" + i); + verify.completionListContains("f1.ts"); + verify.completionListContains("f1.js"); + verify.completionListContains("f1.d.ts"); + verify.completionListContains("f2.tsx"); + verify.completionListContains("f4.jsx"); + verify.not.completionListItemsCountIsGreaterThan(5); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionForTripleSlashReference3.ts b/tests/cases/fourslash/completionForTripleSlashReference3.ts new file mode 100644 index 00000000000..798e556be58 --- /dev/null +++ b/tests/cases/fourslash/completionForTripleSlashReference3.ts @@ -0,0 +1,43 @@ +/// + +// Should give completions for absolute paths + +// @Filename: tests/test0.ts +//// /// + +// Should NOT give completions for directories that are merged via the rootDirs compiler option + +// @rootDirs: sub/src1,src2 + +// @Filename: src2/test0.ts +//// /// number"); goTo.marker('2'); diff --git a/tests/cases/fourslash/extendInterfaceOverloadedMethod.ts b/tests/cases/fourslash/extendInterfaceOverloadedMethod.ts index 43a476303f6..332f4e0e5c7 100644 --- a/tests/cases/fourslash/extendInterfaceOverloadedMethod.ts +++ b/tests/cases/fourslash/extendInterfaceOverloadedMethod.ts @@ -11,9 +11,6 @@ ////var b: B; ////var /**/x = b.foo2().foo(5).foo(); // 'x' is of type 'void' -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker(); verify.quickInfoIs('var x: void'); verify.numberOfErrorsInCurrentFile(0); diff --git a/tests/cases/fourslash/findReferencesDefinitionDisplayParts.ts b/tests/cases/fourslash/findReferencesDefinitionDisplayParts.ts new file mode 100644 index 00000000000..d424bd0c500 --- /dev/null +++ b/tests/cases/fourslash/findReferencesDefinitionDisplayParts.ts @@ -0,0 +1,23 @@ +/// + +//// class Gre/*1*/eter { +//// someFunction() { th/*2*/is; } +//// } +//// +//// type Options = "opt/*3*/ion 1" | "option 2"; +//// let myOption: Options = "option 1"; +//// +//// some/*4*/Label: +//// break someLabel; + +goTo.marker("1"); +verify.findReferencesDefinitionDisplayPartsAtCaretAre([{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "Greeter", kind: "className" }]); + +goTo.marker("2"); +verify.findReferencesDefinitionDisplayPartsAtCaretAre([{ text: "this", kind: "keyword" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "this", kind: "keyword" }]); + +goTo.marker("3"); +verify.findReferencesDefinitionDisplayPartsAtCaretAre([{ text: "\"option 1\"", kind: "stringLiteral" }]); + +goTo.marker("4"); +verify.findReferencesDefinitionDisplayPartsAtCaretAre([{ text: "someLabel", kind: "text" }]); \ No newline at end of file diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 9ce3197a46f..825b943e7a8 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -121,7 +121,7 @@ declare namespace FourSlashInterface { constructor(negative?: boolean); memberListContains(symbol: string, text?: string, documenation?: string, kind?: string): void; memberListCount(expectedCount: number): void; - completionListContains(symbol: string, text?: string, documentation?: string, kind?: string): void; + completionListContains(symbol: string, text?: string, documentation?: string, kind?: string, spanIndex?: number): void; completionListItemsCountIsGreaterThan(count: number): void; completionListIsEmpty(): void; completionListAllowsNewIdentifier(): void; @@ -171,6 +171,7 @@ declare namespace FourSlashInterface { * If `ranges` is omitted, this is `test.ranges()`. */ rangesReferenceEachOther(ranges?: Range[]): void; + findReferencesDefinitionDisplayPartsAtCaretAre(expected: ts.SymbolDisplayPart[]): void; rangesWithSameTextReferenceEachOther(): void; currentParameterHelpArgumentNameIs(name: string): void; currentParameterSpanIs(parameter: string): void; diff --git a/tests/cases/fourslash/funduleWithRecursiveReference.ts b/tests/cases/fourslash/funduleWithRecursiveReference.ts index c93d2cc0e1a..5af02f60dd4 100644 --- a/tests/cases/fourslash/funduleWithRecursiveReference.ts +++ b/tests/cases/fourslash/funduleWithRecursiveReference.ts @@ -7,9 +7,6 @@ //// } ////} -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker(); verify.quickInfoIs('var M.C.C: typeof M.C'); verify.numberOfErrorsInCurrentFile(0); \ No newline at end of file diff --git a/tests/cases/fourslash/genericCombinators1.ts b/tests/cases/fourslash/genericCombinators1.ts index 40f524c9dba..04f64cdcd8c 100644 --- a/tests/cases/fourslash/genericCombinators1.ts +++ b/tests/cases/fourslash/genericCombinators1.ts @@ -50,9 +50,6 @@ ////var /*23*/r8a = _.map(c5, (/*8*/x) => { return x.foo() }); -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('1'); verify.quickInfoIs('(parameter) x: number'); goTo.marker('2'); diff --git a/tests/cases/fourslash/genericCombinators2.ts b/tests/cases/fourslash/genericCombinators2.ts index bcd96dcd1c6..af7f621bc12 100644 --- a/tests/cases/fourslash/genericCombinators2.ts +++ b/tests/cases/fourslash/genericCombinators2.ts @@ -56,9 +56,6 @@ //// ////var /*23*/r8a = _.map(c5, (/*8a*/x,/*8b*/y) => { return y.foo() }); -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('2a'); verify.quickInfoIs('(parameter) x: Collection'); goTo.marker('2b'); diff --git a/tests/cases/fourslash/getEmitOutputSingleFile2.ts b/tests/cases/fourslash/getEmitOutputSingleFile2.ts index 5dd0276a936..5d616b19e13 100644 --- a/tests/cases/fourslash/getEmitOutputSingleFile2.ts +++ b/tests/cases/fourslash/getEmitOutputSingleFile2.ts @@ -4,7 +4,7 @@ // @module: CommonJS // @declaration: true // @out: declSingleFile.js -// @outDir: tests/cases/fourslash/ +// @outDir: /tests/cases/fourslash/ // @Filename: inputFile1.ts //// var x: number = 5; diff --git a/tests/cases/fourslash/goToDefinitionFunctionOverloadsInClass.ts b/tests/cases/fourslash/goToDefinitionFunctionOverloadsInClass.ts index f368120922d..d5f5a374c39 100644 --- a/tests/cases/fourslash/goToDefinitionFunctionOverloadsInClass.ts +++ b/tests/cases/fourslash/goToDefinitionFunctionOverloadsInClass.ts @@ -11,9 +11,6 @@ //// constructor() { } ////} -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('staticFunctionOverload'); goTo.definition(); verify.caretAtMarker('staticFunctionOverloadDefinition'); diff --git a/tests/cases/fourslash/goToDefinitionPartialImplementation.ts b/tests/cases/fourslash/goToDefinitionPartialImplementation.ts index eaf75f9a90b..81e417b6c0f 100644 --- a/tests/cases/fourslash/goToDefinitionPartialImplementation.ts +++ b/tests/cases/fourslash/goToDefinitionPartialImplementation.ts @@ -16,9 +16,6 @@ //// var x: /*Part2Use*/IA; ////} -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('Part2Use'); goTo.definition(); verify.caretAtMarker('Part1Definition'); diff --git a/tests/cases/fourslash/mergedDeclarationsWithExportAssignment1.ts b/tests/cases/fourslash/mergedDeclarationsWithExportAssignment1.ts index 791f519aa28..b3d80b5b588 100644 --- a/tests/cases/fourslash/mergedDeclarationsWithExportAssignment1.ts +++ b/tests/cases/fourslash/mergedDeclarationsWithExportAssignment1.ts @@ -15,9 +15,6 @@ ////var /*3*/z = new /*2*/Foo(); ////var /*5*/r2 = Foo./*4*/x; -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('1'); verify.quickInfoIs("import Foo = require('./mergedDeclarationsWithExportAssignment1_file0')"); diff --git a/tests/cases/fourslash/quickInfoInFunctionTypeReference.ts b/tests/cases/fourslash/quickInfoInFunctionTypeReference.ts index e8430d3fabe..180590ef4d0 100644 --- a/tests/cases/fourslash/quickInfoInFunctionTypeReference.ts +++ b/tests/cases/fourslash/quickInfoInFunctionTypeReference.ts @@ -4,9 +4,6 @@ ////} ////var x = <{ (fn: (va/*2*/riable2: string) => void, a: string): void; }> () => { }; -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker("1"); verify.quickInfoIs("(parameter) variable1: string", undefined); diff --git a/tests/cases/fourslash/quickInfoOnConstructorWithGenericParameter.ts b/tests/cases/fourslash/quickInfoOnConstructorWithGenericParameter.ts index d2ec8ca4f14..2adc8cf336f 100644 --- a/tests/cases/fourslash/quickInfoOnConstructorWithGenericParameter.ts +++ b/tests/cases/fourslash/quickInfoOnConstructorWithGenericParameter.ts @@ -16,9 +16,6 @@ ////} ////var x = new /*2*/B(/*1*/ -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker("1"); verify.currentSignatureHelpIs("B(a: Foo, b: number): B"); edit.insert("null,"); diff --git a/tests/cases/fourslash/renameForDefaultExport04.ts b/tests/cases/fourslash/renameForDefaultExport04.ts index ba40374e262..b225c47b2b2 100644 --- a/tests/cases/fourslash/renameForDefaultExport04.ts +++ b/tests/cases/fourslash/renameForDefaultExport04.ts @@ -12,4 +12,4 @@ ////var y = new DefaultExportedClass; goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedClass", '"tests/cases/fourslash/foo".DefaultExportedClass'); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedClass", '"/tests/cases/fourslash/foo".DefaultExportedClass'); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport05.ts b/tests/cases/fourslash/renameForDefaultExport05.ts index 099f878bda1..2e5fcd847d8 100644 --- a/tests/cases/fourslash/renameForDefaultExport05.ts +++ b/tests/cases/fourslash/renameForDefaultExport05.ts @@ -12,4 +12,4 @@ ////var y = new DefaultExportedClass; goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedClass", '"tests/cases/fourslash/foo".DefaultExportedClass'); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedClass", '"/tests/cases/fourslash/foo".DefaultExportedClass'); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport06.ts b/tests/cases/fourslash/renameForDefaultExport06.ts index 3ec067b7029..ba7f8cac7d7 100644 --- a/tests/cases/fourslash/renameForDefaultExport06.ts +++ b/tests/cases/fourslash/renameForDefaultExport06.ts @@ -12,4 +12,4 @@ ////var y = new /**/[|DefaultExportedClass|]; goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedClass", '"tests/cases/fourslash/foo".DefaultExportedClass'); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedClass", '"/tests/cases/fourslash/foo".DefaultExportedClass'); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport07.ts b/tests/cases/fourslash/renameForDefaultExport07.ts index b65f348f2a0..9e3b4741b55 100644 --- a/tests/cases/fourslash/renameForDefaultExport07.ts +++ b/tests/cases/fourslash/renameForDefaultExport07.ts @@ -13,4 +13,4 @@ ////var y = DefaultExportedFunction(); goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedFunction", '"tests/cases/fourslash/foo".DefaultExportedFunction'); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedFunction", '"/tests/cases/fourslash/foo".DefaultExportedFunction'); \ No newline at end of file diff --git a/tests/cases/fourslash/renameForDefaultExport08.ts b/tests/cases/fourslash/renameForDefaultExport08.ts index 9b3f23db2c1..ad8a2b8242f 100644 --- a/tests/cases/fourslash/renameForDefaultExport08.ts +++ b/tests/cases/fourslash/renameForDefaultExport08.ts @@ -13,4 +13,4 @@ ////var y = DefaultExportedFunction(); goTo.marker(); -verify.renameInfoSucceeded("DefaultExportedFunction", '"tests/cases/fourslash/foo".DefaultExportedFunction'); \ No newline at end of file +verify.renameInfoSucceeded("DefaultExportedFunction", '"/tests/cases/fourslash/foo".DefaultExportedFunction'); \ No newline at end of file diff --git a/tests/cases/fourslash/signatureHelpForSuperCalls1.ts b/tests/cases/fourslash/signatureHelpForSuperCalls1.ts index 58e083ea2ed..6857cf76ead 100644 --- a/tests/cases/fourslash/signatureHelpForSuperCalls1.ts +++ b/tests/cases/fourslash/signatureHelpForSuperCalls1.ts @@ -17,9 +17,6 @@ //// } ////} -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('1'); verify.signatureHelpPresent(); verify.currentSignatureHelpIs('B(): B'); diff --git a/tests/cases/fourslash/signatureHelpSimpleSuperCall.ts b/tests/cases/fourslash/signatureHelpSimpleSuperCall.ts index ff8913a6b04..01d140f29ea 100644 --- a/tests/cases/fourslash/signatureHelpSimpleSuperCall.ts +++ b/tests/cases/fourslash/signatureHelpSimpleSuperCall.ts @@ -10,9 +10,6 @@ //// } ////} -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker('superCall'); verify.signatureHelpCountIs(1); verify.currentSignatureHelpIs("SuperCallBase(b: boolean): SuperCallBase");