diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 51b232712e6..2e2c28590c2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,17 +1,21 @@ ## Contributing bug fixes + TypeScript is currently accepting contributions in the form of bug fixes. A bug must have an issue tracking it in the issue tracker that has been approved ("Milestone == Community") by the TypeScript team. Your pull request should include a link to the bug that you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort. ## Contributing features + Features (things that add new or improved functionality to TypeScript) may be accepted, but will need to first be approved (marked as "Milestone == Community" by a TypeScript coordinator with the message "Approved") in the suggestion issue. Features with language design impact, or that are adequately satisfied with external tools, will not be accepted. Design changes will not be accepted at this time. If you have a design change proposal, please log a suggestion issue. ## Legal + You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright. Please submit a Contributor License Agreement (CLA) before submitting a pull request. You may visit https://cla.microsoft.com to sign digitally. Alternatively, download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to . Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. ## Housekeeping + Your pull request should: * Include a description of what your change intends to do @@ -29,7 +33,8 @@ Your pull request should: * To avoid line ending issues, set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration ## Running the Tests -To run all tests, invoke the runtests target using jake: + +To run all tests, invoke the `runtests` target using jake: ```Shell jake runtests @@ -55,7 +60,7 @@ jake runtests tests=2dArrays ## Debugging the tests -To debug the tests, invoke the runtests-browser using jake. +To debug the tests, invoke the `runtests-browser` task from jake. You will probably only want to debug one test at a time: ```Shell @@ -75,16 +80,14 @@ jake runtests tests=2dArrays debug=true ``` ## Adding a Test -To add a new testcase, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making. -These files support metadata tags in the format `// @metaDataName: value`. The supported names and values are: +To add a new test case, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making. -* `comments`, `sourcemap`, `noimplicitany`, `declaration`: true or false (corresponds to the compiler command-line options of the same name) -* `target`: ES3 or ES5 (same as compiler) -* `out`, outDir: path (same as compiler) -* `module`: local, commonjs, or amd (local corresponds to not passing any compiler --module flag) -* `fileName`: path - * These tags delimit sections of a file to be used as separate compilation units. They are useful for tests relating to modules. See below for examples. +These files support metadata tags in the format `// @metaDataName: value`. +The supported names and values are the same as those supported in the compiler itself, with the addition of the `fileName` flag. +`fileName` tags delimit sections of a file to be used as separate compilation units. +They are useful for tests relating to modules. +See below for examples. **Note** that if you have a test corresponding to a specific spec compliance item, you can place it in `tests\cases\conformance` in an appropriately-named subfolder. **Note** that filenames here must be distinct from all other compiler testcase names, so you may have to work a bit to find a unique name if it's something common. @@ -107,6 +110,7 @@ var x = g(); One can also write a project test, but it is slightly more involved. ## Managing the Baselines + Compiler testcases generate baselines that track the emitted `.js`, the errors produced by the compiler, and the type of each expression in the file. Additionally, some testcases opt in to baselining the source map output. When a change in the baselines is detected, the test will fail. To inspect changes vs the expected baselines, use @@ -123,4 +127,4 @@ jake baseline-accept to establish the new baselines as the desired behavior. This will change the files in `tests\baselines\reference`, which should be included as part of your commit. It's important to carefully validate changes in the baselines. -**Note** that baseline-accept should only be run after a full test run! Accepting baselines after running a subset of tests will delete baseline files for the tests that didn't run. +**Note** that `baseline-accept` should only be run after a full test run! Accepting baselines after running a subset of tests will delete baseline files for the tests that didn't run. diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c407ca0c183..46e98239c54 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4922,7 +4922,7 @@ namespace ts { if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Intersection) && target.flags & TypeFlags.ObjectType) { // Report structural errors only if we haven't reported any errors yet let reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo; - if (result = objectTypeRelatedTo(apparentType, target, reportStructuralErrors)) { + if (result = objectTypeRelatedTo(apparentType, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } @@ -4944,7 +4944,7 @@ namespace ts { return result; } } - return objectTypeRelatedTo(source, target, /*reportErrors*/ false); + return objectTypeRelatedTo(source, source, target, /*reportErrors*/ false); } if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { return typeParameterIdenticalTo(source, target); @@ -4971,34 +4971,34 @@ namespace ts { resolved.stringIndexType || resolved.numberIndexType || getPropertyOfType(type, name)) { return true; } - return false; } - if (type.flags & TypeFlags.UnionOrIntersection) { + else if (type.flags & TypeFlags.UnionOrIntersection) { for (let t of (type).types) { if (isKnownProperty(t, name)) { return true; } } - return false; } - return true; + return false; } function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean { - for (let prop of getPropertiesOfObjectType(source)) { - if (!isKnownProperty(target, prop.name)) { - if (reportErrors) { - // We know *exactly* where things went wrong when comparing the types. - // Use this property as the error node as this will be more helpful in - // reasoning about what went wrong. - errorNode = prop.valueDeclaration; - reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, - symbolToString(prop), - typeToString(target)); + if (someConstituentTypeHasKind(target, TypeFlags.ObjectType)) { + for (let prop of getPropertiesOfObjectType(source)) { + if (!isKnownProperty(target, prop.name)) { + if (reportErrors) { + // We know *exactly* where things went wrong when comparing the types. + // Use this property as the error node as this will be more helpful in + // reasoning about what went wrong. + errorNode = prop.valueDeclaration; + reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, + symbolToString(prop), typeToString(target)); + } + return true; } - return true; } } + return false; } function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary { @@ -5098,11 +5098,11 @@ namespace ts { // Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are // equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion // and issue an error. Otherwise, actually compare the structure of the two types. - function objectTypeRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary { + function objectTypeRelatedTo(apparentSource: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { if (overflow) { return Ternary.False; } - let id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; + let id = relation !== identityRelation || apparentSource.id < target.id ? apparentSource.id + "," + target.id : target.id + "," + apparentSource.id; let related = relation[id]; if (related !== undefined) { // If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate @@ -5129,28 +5129,28 @@ namespace ts { maybeStack = []; expandingFlags = 0; } - sourceStack[depth] = source; + sourceStack[depth] = apparentSource; targetStack[depth] = target; maybeStack[depth] = {}; maybeStack[depth][id] = RelationComparisonResult.Succeeded; depth++; let saveExpandingFlags = expandingFlags; - if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack, depth)) expandingFlags |= 1; + if (!(expandingFlags & 1) && isDeeplyNestedGeneric(apparentSource, sourceStack, depth)) expandingFlags |= 1; if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack, depth)) expandingFlags |= 2; let result: Ternary; if (expandingFlags === 3) { result = Ternary.Maybe; } else { - result = propertiesRelatedTo(source, target, reportErrors); + result = propertiesRelatedTo(apparentSource, target, reportErrors); if (result) { - result &= signaturesRelatedTo(source, target, SignatureKind.Call, reportErrors); + result &= signaturesRelatedTo(apparentSource, target, SignatureKind.Call, reportErrors); if (result) { - result &= signaturesRelatedTo(source, target, SignatureKind.Construct, reportErrors); + result &= signaturesRelatedTo(apparentSource, target, SignatureKind.Construct, reportErrors); if (result) { - result &= stringIndexTypesRelatedTo(source, target, reportErrors); + result &= stringIndexTypesRelatedTo(apparentSource, originalSource, target, reportErrors); if (result) { - result &= numberIndexTypesRelatedTo(source, target, reportErrors); + result &= numberIndexTypesRelatedTo(apparentSource, originalSource, target, reportErrors); } } } @@ -5481,12 +5481,17 @@ namespace ts { return result; } - function stringIndexTypesRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary { + function stringIndexTypesRelatedTo(source: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { if (relation === identityRelation) { return indexTypesIdenticalTo(IndexKind.String, source, target); } let targetType = getIndexTypeOfType(target, IndexKind.String); - if (targetType && !(targetType.flags & TypeFlags.Any)) { + if (targetType) { + if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { + // non-primitive assignment to any is always allowed, eg + // `var x: { [index: string]: any } = { property: 12 };` + return Ternary.True; + } let sourceType = getIndexTypeOfType(source, IndexKind.String); if (!sourceType) { if (reportErrors) { @@ -5506,12 +5511,17 @@ namespace ts { return Ternary.True; } - function numberIndexTypesRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary { + function numberIndexTypesRelatedTo(source: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { if (relation === identityRelation) { return indexTypesIdenticalTo(IndexKind.Number, source, target); } let targetType = getIndexTypeOfType(target, IndexKind.Number); - if (targetType && !(targetType.flags & TypeFlags.Any)) { + if (targetType) { + if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { + // non-primitive assignment to any is always allowed, eg + // `var x: { [index: number]: any } = { property: 12 };` + return Ternary.True; + } let sourceStringType = getIndexTypeOfType(source, IndexKind.String); let sourceNumberType = getIndexTypeOfType(source, IndexKind.Number); if (!(sourceStringType || sourceNumberType)) { @@ -7537,9 +7547,6 @@ namespace ts { case SyntaxKind.JsxSelfClosingElement: checkJsxSelfClosingElement(child); break; - default: - // No checks for JSX Text - Debug.assert(child.kind === SyntaxKind.JsxText); } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index acf0474b7bf..0c561ab06d8 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -410,63 +410,19 @@ namespace ts { /** * Parse the contents of a config file (tsconfig.json). * @param json The contents of the config file to parse + * @param host Instance of ParseConfigHost used to enumerate files in folder. * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine { - let errors: Diagnostic[] = []; + let { options, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath); return { - options: getCompilerOptions(), + options, fileNames: getFileNames(), errors }; - function getCompilerOptions(): CompilerOptions { - let options: CompilerOptions = {}; - let optionNameMap: Map = {}; - forEach(optionDeclarations, option => { - optionNameMap[option.name] = option; - }); - let jsonOptions = json["compilerOptions"]; - if (jsonOptions) { - for (let id in jsonOptions) { - if (hasProperty(optionNameMap, id)) { - let opt = optionNameMap[id]; - let optType = opt.type; - let value = jsonOptions[id]; - let expectedType = typeof optType === "string" ? optType : "string"; - if (typeof value === expectedType) { - if (typeof optType !== "string") { - let key = value.toLowerCase(); - if (hasProperty(optType, key)) { - value = optType[key]; - } - else { - errors.push(createCompilerDiagnostic((opt).error)); - value = 0; - } - } - if (opt.isFilePath) { - value = normalizePath(combinePaths(basePath, value)); - if (value === "") { - value = "."; - } - } - options[opt.name] = value; - } - else { - errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType)); - } - } - else { - errors.push(createCompilerDiagnostic(Diagnostics.Unknown_compiler_option_0, id)); - } - } - } - return options; - } - function getFileNames(): string[] { let fileNames: string[] = []; if (hasProperty(json, "files")) { @@ -501,4 +457,51 @@ namespace ts { return fileNames; } } + + export function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string): { options: CompilerOptions, errors: Diagnostic[] } { + let options: CompilerOptions = {}; + let errors: Diagnostic[] = []; + + if (!jsonOptions) { + return { options, errors }; + } + + let optionNameMap = arrayToMap(optionDeclarations, opt => opt.name); + + for (let id in jsonOptions) { + if (hasProperty(optionNameMap, id)) { + let opt = optionNameMap[id]; + let optType = opt.type; + let value = jsonOptions[id]; + let expectedType = typeof optType === "string" ? optType : "string"; + if (typeof value === expectedType) { + if (typeof optType !== "string") { + let key = value.toLowerCase(); + if (hasProperty(optType, key)) { + value = optType[key]; + } + else { + errors.push(createCompilerDiagnostic((opt).error)); + value = 0; + } + } + if (opt.isFilePath) { + value = normalizePath(combinePaths(basePath, value)); + if (value === "") { + value = "."; + } + } + options[opt.name] = value; + } + else { + errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType)); + } + } + else { + errors.push(createCompilerDiagnostic(Diagnostics.Unknown_compiler_option_0, id)); + } + } + + return { options, errors }; + } } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 9a2fb26df0f..e7609c1aca4 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -770,7 +770,7 @@ namespace ts { }; export interface ObjectAllocator { - getNodeConstructor(kind: SyntaxKind): new () => Node; + getNodeConstructor(kind: SyntaxKind): new (pos?: number, end?: number) => Node; getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol; getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type; getSignatureConstructor(): new (checker: TypeChecker) => Signature; @@ -791,15 +791,13 @@ namespace ts { export let objectAllocator: ObjectAllocator = { getNodeConstructor: kind => { - function Node() { + function Node(pos: number, end: number) { + this.pos = pos; + this.end = end; + this.flags = NodeFlags.None; + this.parent = undefined; } - Node.prototype = { - kind: kind, - pos: -1, - end: -1, - flags: 0, - parent: undefined, - }; + Node.prototype = { kind }; return Node; }, getSymbolConstructor: () => Symbol, @@ -839,9 +837,9 @@ namespace ts { export function copyListRemovingItem(item: T, list: T[]) { let copiedList: T[] = []; - for (var i = 0, len = list.length; i < len; i++) { - if (list[i] !== item) { - copiedList.push(list[i]); + for (let e of list) { + if (e !== item) { + copiedList.push(e); } } return copiedList; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b2c1e6f0d5e..188cf23f76c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1720,6 +1720,10 @@ "category": "Error", "code": 2656 }, + "JSX expressions must have one parent element": { + "category": "Error", + "code": 2657 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f2468e7244d..70ab3606c6c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1769,34 +1769,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write("."); } } - else if (modulekind !== ModuleKind.ES6) { - let declaration = resolver.getReferencedImportDeclaration(node); - if (declaration) { - if (declaration.kind === SyntaxKind.ImportClause) { - // Identifier references default import - write(getGeneratedNameForNode(declaration.parent)); - write(languageVersion === ScriptTarget.ES3 ? "[\"default\"]" : ".default"); - return; - } - else if (declaration.kind === SyntaxKind.ImportSpecifier) { - // Identifier references named import - write(getGeneratedNameForNode(declaration.parent.parent.parent)); - let name = (declaration).propertyName || (declaration).name; - let identifier = getSourceTextOfNodeFromSourceFile(currentSourceFile, name); - if (languageVersion === ScriptTarget.ES3 && identifier === "default") { - write(`["default"]`); + else { + if (modulekind !== ModuleKind.ES6) { + let declaration = resolver.getReferencedImportDeclaration(node); + if (declaration) { + if (declaration.kind === SyntaxKind.ImportClause) { + // Identifier references default import + write(getGeneratedNameForNode(declaration.parent)); + write(languageVersion === ScriptTarget.ES3 ? "[\"default\"]" : ".default"); + return; } - else { - write("."); - write(identifier); + else if (declaration.kind === SyntaxKind.ImportSpecifier) { + // Identifier references named import + write(getGeneratedNameForNode(declaration.parent.parent.parent)); + let name = (declaration).propertyName || (declaration).name; + let identifier = getSourceTextOfNodeFromSourceFile(currentSourceFile, name); + if (languageVersion === ScriptTarget.ES3 && identifier === "default") { + write(`["default"]`); + } + else { + write("."); + write(identifier); + } + return; } - return; } } - declaration = resolver.getReferencedNestedRedeclaration(node); - if (declaration) { - write(getGeneratedNameForNode(declaration.name)); - return; + + if (languageVersion !== ScriptTarget.ES6) { + let declaration = resolver.getReferencedNestedRedeclaration(node); + if (declaration) { + write(getGeneratedNameForNode(declaration.name)); + return; + } } } @@ -2785,7 +2790,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi /** * Emit ES7 exponentiation operator downlevel using Math.pow - * @param node a binary expression node containing exponentiationOperator (**, **=) + * @param node a binary expression node containing exponentiationOperator (**, **=) */ function emitExponentiationOperator(node: BinaryExpression) { let leftHandSideExpression = node.left; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f81d4d5f86b..c84439e356c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2,15 +2,15 @@ /// namespace ts { - let nodeConstructors = new Array Node>(SyntaxKind.Count); + let nodeConstructors = new Array Node>(SyntaxKind.Count); /* @internal */ export let parseTime = 0; - export function getNodeConstructor(kind: SyntaxKind): new () => Node { + export function getNodeConstructor(kind: SyntaxKind): new (pos?: number, end?: number) => Node { return nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind)); } - export function createNode(kind: SyntaxKind): Node { - return new (getNodeConstructor(kind))(); + export function createNode(kind: SyntaxKind, pos?: number, end?: number): Node { + return new (getNodeConstructor(kind))(pos, end); } function visitNode(cbNode: (node: Node) => T, node: Node): T { @@ -998,14 +998,10 @@ namespace ts { function createNode(kind: SyntaxKind, pos?: number): Node { nodeCount++; - let node = new (nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind)))(); if (!(pos >= 0)) { pos = scanner.getStartPos(); } - - node.pos = pos; - node.end = pos; - return node; + return new (nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind)))(pos, pos); } function finishNode(node: T, end?: number): T { @@ -3459,19 +3455,43 @@ namespace ts { function parseJsxElementOrSelfClosingElement(inExpressionContext: boolean): JsxElement | JsxSelfClosingElement { let opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext); + let result: JsxElement | JsxSelfClosingElement; if (opening.kind === SyntaxKind.JsxOpeningElement) { let node = createNode(SyntaxKind.JsxElement, opening.pos); node.openingElement = opening; node.children = parseJsxChildren(node.openingElement.tagName); node.closingElement = parseJsxClosingElement(inExpressionContext); - return finishNode(node); + result = finishNode(node); } else { Debug.assert(opening.kind === SyntaxKind.JsxSelfClosingElement); // Nothing else to do for self-closing elements - return opening; + result = opening; } + + // If the user writes the invalid code '
' in an expression context (i.e. not wrapped in + // an enclosing tag), we'll naively try to parse ^ this as a 'less than' operator and the remainder of the tag + // as garbage, which will cause the formatter to badly mangle the JSX. Perform a speculative parse of a JSX + // element if we see a < token so that we can wrap it in a synthetic binary expression so the formatter + // does less damage and we can report a better error. + // Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios + // of one sort or another. + if (inExpressionContext && token === SyntaxKind.LessThanToken) { + let invalidElement = tryParse(() => parseJsxElementOrSelfClosingElement(/*inExpressionContext*/true)); + if (invalidElement) { + parseErrorAtCurrentToken(Diagnostics.JSX_expressions_must_have_one_parent_element); + let badNode = createNode(SyntaxKind.BinaryExpression, result.pos); + badNode.end = invalidElement.end; + badNode.left = result; + badNode.right = invalidElement; + badNode.operatorToken = createMissingNode(SyntaxKind.CommaToken, /*reportAtCurrentPosition*/ false, /*diagnosticMessage*/ undefined); + badNode.operatorToken.pos = badNode.operatorToken.end = badNode.right.pos; + return badNode; + } + } + + return result; } function parseJsxText(): JsxText { diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 0872a2e5ba5..3eeb126c065 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -407,7 +407,7 @@ namespace ts { // (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643) return _fs.watch( path, - { persisten: true, recursive: !!recursive }, + { persistent: true, recursive: !!recursive }, (eventName: string, relativeFileName: string) => { // In watchDirectory we only care about adding and removing files (when event name is // "rename"); changes made within files are handled by corresponding fileWatchers (when diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 9d79d435a04..e51fda074c5 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -360,7 +360,8 @@ namespace ts { let newFileNames = ts.map(parsedCommandLine.fileNames, compilerHost.getCanonicalFileName); let canonicalRootFileNames = ts.map(rootFileNames, compilerHost.getCanonicalFileName); - if (!arrayStructurallyIsEqualTo(newFileNames, canonicalRootFileNames)) { + // We check if the project file list has changed. If so, we just throw away the old program and start fresh. + if (!arrayIsEqualTo(newFileNames && newFileNames.sort(), canonicalRootFileNames && canonicalRootFileNames.sort())) { setCachedProgram(undefined); startTimerForRecompilation(); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5e8de9a3fb4..16aa377fdc0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -361,6 +361,7 @@ namespace ts { } export const enum NodeFlags { + None = 0, Export = 0x00000001, // Declarations Ambient = 0x00000002, // Declarations Public = 0x00000010, // Property/Method @@ -1308,7 +1309,7 @@ namespace ts { getCurrentDirectory(): string; } - export interface ParseConfigHost extends ModuleResolutionHost { + export interface ParseConfigHost { readDirectory(rootDir: string, extension: string, exclude: string[]): string[]; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 67f16cbfd0f..6057da15a02 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -82,17 +82,17 @@ namespace ts { return node.end - node.pos; } - export function arrayIsEqualTo(arr1: T[], arr2: T[], comparer?: (a: T, b: T) => boolean): boolean { - if (!arr1 || !arr2) { - return arr1 === arr2; + export function arrayIsEqualTo(array1: T[], array2: T[], equaler?: (a: T, b: T) => boolean): boolean { + if (!array1 || !array2) { + return array1 === array2; } - if (arr1.length !== arr2.length) { + if (array1.length !== array2.length) { return false; } - for (let i = 0; i < arr1.length; ++i) { - let equals = comparer ? comparer(arr1[i], arr2[i]) : arr1[i] === arr2[i]; + for (let i = 0; i < array1.length; ++i) { + let equals = equaler ? equaler(array1[i], array2[i]) : array1[i] === array2[i]; if (!equals) { return false; } @@ -1560,7 +1560,7 @@ namespace ts { } export function createSynthesizedNode(kind: SyntaxKind, startsOnNewLine?: boolean): Node { - let node = createNode(kind); + let node = createNode(kind, /* pos */ -1, /* end */ -1); node.startsOnNewLine = startsOnNewLine; return node; } @@ -2469,16 +2469,4 @@ namespace ts { } } } - - export function arrayStructurallyIsEqualTo(array1: Array, array2: Array): boolean { - if (!array1 || !array2) { - return false; - } - - if (array1.length !== array2.length) { - return false; - } - - return arrayIsEqualTo(array1.sort(), array2.sort()); - } } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index a37b647a124..806f89be04d 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -274,7 +274,9 @@ namespace Utils { case "flags": // Print out flags with their enum names. - o[propertyName] = getNodeFlagName(n.flags); + if (n.flags) { + o[propertyName] = getNodeFlagName(n.flags); + } break; case "parserContextFlags": diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 056443415c8..18e8dd2e703 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -581,7 +581,8 @@ namespace ts.server { let newRootFiles = projectOptions.files.map((f => this.getCanonicalFileName(f))); let currentRootFiles = project.getRootFiles().map((f => this.getCanonicalFileName(f))); - if (!arrayStructurallyIsEqualTo(currentRootFiles, newRootFiles)) { + // We check if the project file list has changed. If so, we update the project. + if (!arrayIsEqualTo(currentRootFiles && currentRootFiles.sort(), newRootFiles && newRootFiles.sort())) { // For configured projects, the change is made outside the tsconfig file, and // it is not likely to affect the project for other files opened by the client. We can // just update the current project. diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 4a7033c6f3e..651105e9d5c 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -695,8 +695,8 @@ namespace ts.formatting { let tokenStart = sourceFile.getLineAndCharacterOfPosition(currentTokenInfo.token.pos); if (isTokenInRange) { let rangeHasError = rangeContainsError(currentTokenInfo.token); - // save prevStartLine since processRange will overwrite this value with current ones - let prevStartLine = previousRangeStartLine; + // save previousRange since processRange will overwrite this value with current one + let savePreviousRange = previousRange; lineAdded = processRange(currentTokenInfo.token, tokenStart, parent, childContextNode, dynamicIndentation); if (rangeHasError) { // do not indent comments\token if token range overlaps with some error @@ -707,7 +707,9 @@ namespace ts.formatting { indentToken = lineAdded; } else { - indentToken = lastTriviaWasNewLine && tokenStart.line !== prevStartLine; + // indent token only if end line of previous range does not match start line of the token + const prevEndLine = savePreviousRange && sourceFile.getLineAndCharacterOfPosition(savePreviousRange.end).line; + indentToken = lastTriviaWasNewLine && tokenStart.line !== prevEndLine; } } } diff --git a/src/services/services.ts b/src/services/services.ts index 30d993cb6b6..c10a03f644b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -174,9 +174,7 @@ namespace ts { let jsDocCompletionEntries: CompletionEntry[]; function createNode(kind: SyntaxKind, pos: number, end: number, flags: NodeFlags, parent?: Node): NodeObject { - let node = new (getNodeConstructor(kind))(); - node.pos = pos; - node.end = end; + let node = new (getNodeConstructor(kind))(pos, end); node.flags = flags; node.parent = parent; return node; @@ -8055,14 +8053,14 @@ namespace ts { function initializeServices() { objectAllocator = { getNodeConstructor: kind => { - function Node() { + function Node(pos: number, end: number) { + this.pos = pos; + this.end = end; + this.flags = NodeFlags.None; + this.parent = undefined; } let proto = kind === SyntaxKind.SourceFile ? new SourceFileObject() : new NodeObject(); proto.kind = kind; - proto.pos = -1; - proto.end = -1; - proto.flags = 0; - proto.parent = undefined; Node.prototype = proto; return Node; }, diff --git a/tests/baselines/reference/assignmentCompat1.errors.txt b/tests/baselines/reference/assignmentCompat1.errors.txt index edb8d28eecc..7539af92887 100644 --- a/tests/baselines/reference/assignmentCompat1.errors.txt +++ b/tests/baselines/reference/assignmentCompat1.errors.txt @@ -2,9 +2,13 @@ tests/cases/compiler/assignmentCompat1.ts(4,1): error TS2322: Type '{ [index: st Property 'one' is missing in type '{ [index: string]: any; }'. tests/cases/compiler/assignmentCompat1.ts(6,1): error TS2322: Type '{ [index: number]: any; }' is not assignable to type '{ one: number; }'. Property 'one' is missing in type '{ [index: number]: any; }'. +tests/cases/compiler/assignmentCompat1.ts(8,1): error TS2322: Type 'string' is not assignable to type '{ [index: string]: any; }'. + Index signature is missing in type 'String'. +tests/cases/compiler/assignmentCompat1.ts(10,1): error TS2322: Type 'boolean' is not assignable to type '{ [index: number]: any; }'. + Index signature is missing in type 'Boolean'. -==== tests/cases/compiler/assignmentCompat1.ts (2 errors) ==== +==== tests/cases/compiler/assignmentCompat1.ts (4 errors) ==== var x = { one: 1 }; var y: { [index: string]: any }; var z: { [index: number]: any }; @@ -18,4 +22,14 @@ tests/cases/compiler/assignmentCompat1.ts(6,1): error TS2322: Type '{ [index: nu !!! error TS2322: Type '{ [index: number]: any; }' is not assignable to type '{ one: number; }'. !!! error TS2322: Property 'one' is missing in type '{ [index: number]: any; }'. z = x; // Ok because index signature type is any + y = "foo"; // Error + ~ +!!! error TS2322: Type 'string' is not assignable to type '{ [index: string]: any; }'. +!!! error TS2322: Index signature is missing in type 'String'. + z = "foo"; // OK, string has numeric indexer + z = false; // Error + ~ +!!! error TS2322: Type 'boolean' is not assignable to type '{ [index: number]: any; }'. +!!! error TS2322: Index signature is missing in type 'Boolean'. + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompat1.js b/tests/baselines/reference/assignmentCompat1.js index 740a44cced4..7451d342fa1 100644 --- a/tests/baselines/reference/assignmentCompat1.js +++ b/tests/baselines/reference/assignmentCompat1.js @@ -6,6 +6,10 @@ x = y; // Error y = x; // Ok because index signature type is any x = z; // Error z = x; // Ok because index signature type is any +y = "foo"; // Error +z = "foo"; // OK, string has numeric indexer +z = false; // Error + //// [assignmentCompat1.js] @@ -16,3 +20,6 @@ x = y; // Error y = x; // Ok because index signature type is any x = z; // Error z = x; // Ok because index signature type is any +y = "foo"; // Error +z = "foo"; // OK, string has numeric indexer +z = false; // Error diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 2ea5a2f413a..06b844f8321 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -1,13 +1,14 @@ tests/cases/compiler/indexTypeCheck.ts(2,2): error TS1021: An index signature must have a type annotation. tests/cases/compiler/indexTypeCheck.ts(3,2): error TS1021: An index signature must have a type annotation. tests/cases/compiler/indexTypeCheck.ts(17,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. +tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'. tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. tests/cases/compiler/indexTypeCheck.ts(32,3): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string' or 'number'. tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. -==== tests/cases/compiler/indexTypeCheck.ts (7 errors) ==== +==== tests/cases/compiler/indexTypeCheck.ts (8 errors) ==== interface Red { [n:number]; // ok ~~~~~~~~~~~ @@ -36,6 +37,8 @@ tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression interface Green { [n:number]: Orange; // error + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'. [s:string]: Yellow; // ok } diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 7f1cc88e2a2..e48d1b1dc73 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -30,6 +30,8 @@ tests/cases/compiler/intTypeCheck.ts(134,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(134,22): error TS2304: Cannot find name 'i3'. tests/cases/compiler/intTypeCheck.ts(135,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(142,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(148,5): error TS2322: Type 'boolean' is not assignable to type 'i4'. + Index signature is missing in type 'Boolean'. tests/cases/compiler/intTypeCheck.ts(148,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(148,22): error TS2304: Cannot find name 'i4'. tests/cases/compiler/intTypeCheck.ts(149,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -66,12 +68,14 @@ tests/cases/compiler/intTypeCheck.ts(190,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(190,22): error TS2304: Cannot find name 'i7'. tests/cases/compiler/intTypeCheck.ts(191,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(198,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(204,5): error TS2322: Type 'boolean' is not assignable to type 'i8'. + Index signature is missing in type 'Boolean'. tests/cases/compiler/intTypeCheck.ts(204,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(204,22): error TS2304: Cannot find name 'i8'. tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -==== tests/cases/compiler/intTypeCheck.ts (61 errors) ==== +==== tests/cases/compiler/intTypeCheck.ts (63 errors) ==== interface i1 { //Property Signatures p; @@ -280,6 +284,9 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit //var obj40: i4 = function foo() { }; var obj41: i4 = anyVar; var obj42: i4 = new anyVar; + ~~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'i4'. +!!! error TS2322: Index signature is missing in type 'Boolean'. ~ !!! error TS1109: Expression expected. ~~ @@ -402,6 +409,9 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit //var obj84: i8 = function foo() { }; var obj85: i8 = anyVar; var obj86: i8 = new anyVar; + ~~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'i8'. +!!! error TS2322: Index signature is missing in type 'Boolean'. ~ !!! error TS1109: Expression expected. ~~ diff --git a/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt b/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt index 5758db36960..3a6059d8d07 100644 --- a/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt +++ b/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt @@ -4,11 +4,10 @@ tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,29): error TS1005: '{' tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,57): error TS1109: Expression expected. tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,58): error TS1109: Expression expected. tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(41,1): error TS1003: Identifier expected. -tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(41,6): error TS1109: Expression expected. -tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(41,12): error TS1109: Expression expected. +tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(41,12): error TS2657: JSX expressions must have one parent element -==== tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx (8 errors) ==== +==== tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx (7 errors) ==== declare var React: any; declare var 日本語; declare var AbC_def; @@ -62,10 +61,8 @@ tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(41,12): error TS1109: Expr ; ~ !!! error TS1003: Identifier expected. - ~~ -!!! error TS1109: Expression expected. ~ -!!! error TS1109: Expression expected. +!!! error TS2657: JSX expressions must have one parent element ; diff --git a/tests/baselines/reference/jsxEsprimaFbTestSuite.js b/tests/baselines/reference/jsxEsprimaFbTestSuite.js index 1e22826f440..465d265efb2 100644 --- a/tests/baselines/reference/jsxEsprimaFbTestSuite.js +++ b/tests/baselines/reference/jsxEsprimaFbTestSuite.js @@ -72,8 +72,8 @@ baz
@test content
;

7x invalid-js-identifier
; } right={monkeys /> gorillas / > }/> - < a.b > ; -a.b > ; + , + ; ; (
) < x;
; diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt index 02bc56e823e..578159dc651 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt @@ -12,17 +12,11 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(6,6): error TS2304: C tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(6,9): error TS1109: Expression expected. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(6,10): error TS1109: Expression expected. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(7,1): error TS1003: Identifier expected. -tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(7,2): error TS2304: Cannot find name 'a'. -tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(7,4): error TS1109: Expression expected. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(8,4): error TS17002: Expected corresponding JSX closing tag for 'a'. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(9,13): error TS1002: Unterminated string literal. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(10,1): error TS1003: Identifier expected. -tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(10,2): error TS2304: Cannot find name 'a'. -tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(10,3): error TS1005: ';' expected. -tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(10,4): error TS2304: Cannot find name 'b'. -tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(10,6): error TS1109: Expression expected. -tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(10,8): error TS2304: Cannot find name 'b'. -tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(10,10): error TS1109: Expression expected. +tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(10,6): error TS17002: Expected corresponding JSX closing tag for 'a'. +tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(10,10): error TS2657: JSX expressions must have one parent element tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(11,3): error TS1003: Identifier expected. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(11,5): error TS1003: Identifier expected. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(11,11): error TS1005: '>' expected. @@ -71,7 +65,7 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,4): error TS1003: tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,21): error TS17002: Expected corresponding JSX closing tag for 'a'. -==== tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx (71 errors) ==== +==== tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx (65 errors) ==== declare var React: any; ; @@ -107,10 +101,6 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,21): error TS17002 ; ~ !!! error TS1003: Identifier expected. - ~ -!!! error TS2304: Cannot find name 'a'. - ~ -!!! error TS1109: Expression expected. ; ~~~~ !!! error TS17002: Expected corresponding JSX closing tag for 'a'. @@ -120,18 +110,10 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,21): error TS17002 ; ~ !!! error TS1003: Identifier expected. - ~ -!!! error TS2304: Cannot find name 'a'. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS2304: Cannot find name 'b'. - ~~ -!!! error TS1109: Expression expected. - ~ -!!! error TS2304: Cannot find name 'b'. + ~~~~ +!!! error TS17002: Expected corresponding JSX closing tag for 'a'. ~ -!!! error TS1109: Expression expected. +!!! error TS2657: JSX expressions must have one parent element ; ~ !!! error TS1003: Identifier expected. diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js index d623e127be7..7f01666bd78 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js @@ -41,12 +41,10 @@ var x =
one
/* intervening comment */
two
;; < ; a / > ;
}/> - < a > ; -; -a:b>; ; b.c > ; ; diff --git a/tests/baselines/reference/nestedRedeclarationInES6AMD.js b/tests/baselines/reference/nestedRedeclarationInES6AMD.js new file mode 100644 index 00000000000..bb90759dc8b --- /dev/null +++ b/tests/baselines/reference/nestedRedeclarationInES6AMD.js @@ -0,0 +1,15 @@ +//// [nestedRedeclarationInES6AMD.ts] +function a() { + { + let status = 1; + status = 2; + } +} + +//// [nestedRedeclarationInES6AMD.js] +function a() { + { + let status = 1; + status = 2; + } +} diff --git a/tests/baselines/reference/nestedRedeclarationInES6AMD.symbols b/tests/baselines/reference/nestedRedeclarationInES6AMD.symbols new file mode 100644 index 00000000000..65f310a7ed2 --- /dev/null +++ b/tests/baselines/reference/nestedRedeclarationInES6AMD.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/nestedRedeclarationInES6AMD.ts === +function a() { +>a : Symbol(a, Decl(nestedRedeclarationInES6AMD.ts, 0, 0)) + { + let status = 1; +>status : Symbol(status, Decl(nestedRedeclarationInES6AMD.ts, 2, 11)) + + status = 2; +>status : Symbol(status, Decl(nestedRedeclarationInES6AMD.ts, 2, 11)) + } +} diff --git a/tests/baselines/reference/nestedRedeclarationInES6AMD.types b/tests/baselines/reference/nestedRedeclarationInES6AMD.types new file mode 100644 index 00000000000..2b8d971e3c1 --- /dev/null +++ b/tests/baselines/reference/nestedRedeclarationInES6AMD.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/nestedRedeclarationInES6AMD.ts === +function a() { +>a : () => void + { + let status = 1; +>status : number +>1 : number + + status = 2; +>status = 2 : number +>status : number +>2 : number + } +} diff --git a/tests/baselines/reference/objectLiteralExcessProperties.errors.txt b/tests/baselines/reference/objectLiteralExcessProperties.errors.txt new file mode 100644 index 00000000000..84f635bf947 --- /dev/null +++ b/tests/baselines/reference/objectLiteralExcessProperties.errors.txt @@ -0,0 +1,66 @@ +tests/cases/compiler/objectLiteralExcessProperties.ts(9,18): error TS2322: Type '{ forword: string; }' is not assignable to type 'Book'. + Object literal may only specify known properties, and 'forword' does not exist in type 'Book'. +tests/cases/compiler/objectLiteralExcessProperties.ts(11,27): error TS2322: Type '{ foreward: string; }' is not assignable to type 'Book | string'. + Object literal may only specify known properties, and 'foreward' does not exist in type 'Book | string'. +tests/cases/compiler/objectLiteralExcessProperties.ts(13,53): error TS2322: Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book | Book[]'. + Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book[]'. + Type '{ foreword: string; } | { forwards: string; }' is not assignable to type 'Book'. + Type '{ forwards: string; }' is not assignable to type 'Book'. + Object literal may only specify known properties, and 'forwards' does not exist in type 'Book'. +tests/cases/compiler/objectLiteralExcessProperties.ts(15,42): error TS2322: Type '{ foreword: string; colour: string; }' is not assignable to type 'Book & Cover'. + Object literal may only specify known properties, and 'colour' does not exist in type 'Book & Cover'. +tests/cases/compiler/objectLiteralExcessProperties.ts(17,26): error TS2322: Type '{ foreward: string; color: string; }' is not assignable to type 'Book & Cover'. + Object literal may only specify known properties, and 'foreward' does not exist in type 'Book & Cover'. +tests/cases/compiler/objectLiteralExcessProperties.ts(19,57): error TS2322: Type '{ foreword: string; color: string; price: number; }' is not assignable to type 'Book & Cover'. + Object literal may only specify known properties, and 'price' does not exist in type 'Book & Cover'. +tests/cases/compiler/objectLiteralExcessProperties.ts(21,43): error TS2322: Type '{ foreword: string; price: number; }' is not assignable to type 'Book & number'. + Object literal may only specify known properties, and 'price' does not exist in type 'Book & number'. + + +==== tests/cases/compiler/objectLiteralExcessProperties.ts (7 errors) ==== + interface Book { + foreword: string; + } + + interface Cover { + color?: string; + } + + var b1: Book = { forword: "oops" }; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ forword: string; }' is not assignable to type 'Book'. +!!! error TS2322: Object literal may only specify known properties, and 'forword' does not exist in type 'Book'. + + var b2: Book | string = { foreward: "nope" }; + ~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ foreward: string; }' is not assignable to type 'Book | string'. +!!! error TS2322: Object literal may only specify known properties, and 'foreward' does not exist in type 'Book | string'. + + var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }]; + ~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book | Book[]'. +!!! error TS2322: Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book[]'. +!!! error TS2322: Type '{ foreword: string; } | { forwards: string; }' is not assignable to type 'Book'. +!!! error TS2322: Type '{ forwards: string; }' is not assignable to type 'Book'. +!!! error TS2322: Object literal may only specify known properties, and 'forwards' does not exist in type 'Book'. + + var b4: Book & Cover = { foreword: "hi", colour: "blue" }; + ~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ foreword: string; colour: string; }' is not assignable to type 'Book & Cover'. +!!! error TS2322: Object literal may only specify known properties, and 'colour' does not exist in type 'Book & Cover'. + + var b5: Book & Cover = { foreward: "hi", color: "blue" }; + ~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ foreward: string; color: string; }' is not assignable to type 'Book & Cover'. +!!! error TS2322: Object literal may only specify known properties, and 'foreward' does not exist in type 'Book & Cover'. + + var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 }; + ~~~~~~~~~~~~ +!!! error TS2322: Type '{ foreword: string; color: string; price: number; }' is not assignable to type 'Book & Cover'. +!!! error TS2322: Object literal may only specify known properties, and 'price' does not exist in type 'Book & Cover'. + + var b7: Book & number = { foreword: "hi", price: 10.99 }; + ~~~~~~~~~~~~ +!!! error TS2322: Type '{ foreword: string; price: number; }' is not assignable to type 'Book & number'. +!!! error TS2322: Object literal may only specify known properties, and 'price' does not exist in type 'Book & number'. + \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralExcessProperties.js b/tests/baselines/reference/objectLiteralExcessProperties.js new file mode 100644 index 00000000000..747928ccb20 --- /dev/null +++ b/tests/baselines/reference/objectLiteralExcessProperties.js @@ -0,0 +1,32 @@ +//// [objectLiteralExcessProperties.ts] +interface Book { + foreword: string; +} + +interface Cover { + color?: string; +} + +var b1: Book = { forword: "oops" }; + +var b2: Book | string = { foreward: "nope" }; + +var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }]; + +var b4: Book & Cover = { foreword: "hi", colour: "blue" }; + +var b5: Book & Cover = { foreward: "hi", color: "blue" }; + +var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 }; + +var b7: Book & number = { foreword: "hi", price: 10.99 }; + + +//// [objectLiteralExcessProperties.js] +var b1 = { forword: "oops" }; +var b2 = { foreward: "nope" }; +var b3 = [{ foreword: "hello" }, { forwards: "back" }]; +var b4 = { foreword: "hi", colour: "blue" }; +var b5 = { foreward: "hi", color: "blue" }; +var b6 = { foreword: "hi", color: "blue", price: 10.99 }; +var b7 = { foreword: "hi", price: 10.99 }; diff --git a/tests/baselines/reference/tsxErrorRecovery2.errors.txt b/tests/baselines/reference/tsxErrorRecovery2.errors.txt new file mode 100644 index 00000000000..9a0b5790b2c --- /dev/null +++ b/tests/baselines/reference/tsxErrorRecovery2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/jsx/file1.tsx(6,1): error TS2657: JSX expressions must have one parent element +tests/cases/conformance/jsx/file2.tsx(2,1): error TS2657: JSX expressions must have one parent element + + +==== tests/cases/conformance/jsx/file1.tsx (1 errors) ==== + + declare namespace JSX { interface Element { } } + +
+
+ + +!!! error TS2657: JSX expressions must have one parent element +==== tests/cases/conformance/jsx/file2.tsx (1 errors) ==== + var x =
+ + +!!! error TS2657: JSX expressions must have one parent element \ No newline at end of file diff --git a/tests/baselines/reference/tsxErrorRecovery2.js b/tests/baselines/reference/tsxErrorRecovery2.js new file mode 100644 index 00000000000..be5b6c73424 --- /dev/null +++ b/tests/baselines/reference/tsxErrorRecovery2.js @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/jsx/tsxErrorRecovery2.tsx] //// + +//// [file1.tsx] + +declare namespace JSX { interface Element { } } + +
+
+ +//// [file2.tsx] +var x =
+ + +//// [file1.jsx] +
+ , +
; +//// [file2.jsx] +var x =
,
; diff --git a/tests/baselines/reference/tsxErrorRecovery3.errors.txt b/tests/baselines/reference/tsxErrorRecovery3.errors.txt new file mode 100644 index 00000000000..f7e4bc170a9 --- /dev/null +++ b/tests/baselines/reference/tsxErrorRecovery3.errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/jsx/file1.tsx(4,2): error TS2304: Cannot find name 'React'. +tests/cases/conformance/jsx/file1.tsx(5,2): error TS2304: Cannot find name 'React'. +tests/cases/conformance/jsx/file1.tsx(6,1): error TS2657: JSX expressions must have one parent element +tests/cases/conformance/jsx/file2.tsx(1,10): error TS2304: Cannot find name 'React'. +tests/cases/conformance/jsx/file2.tsx(1,21): error TS2304: Cannot find name 'React'. +tests/cases/conformance/jsx/file2.tsx(2,1): error TS2657: JSX expressions must have one parent element + + +==== tests/cases/conformance/jsx/file1.tsx (3 errors) ==== + + declare namespace JSX { interface Element { } } + +
+ ~~~ +!!! error TS2304: Cannot find name 'React'. +
+ ~~~ +!!! error TS2304: Cannot find name 'React'. + + +!!! error TS2657: JSX expressions must have one parent element +==== tests/cases/conformance/jsx/file2.tsx (3 errors) ==== + var x =
+ ~~~ +!!! error TS2304: Cannot find name 'React'. + ~~~ +!!! error TS2304: Cannot find name 'React'. + + +!!! error TS2657: JSX expressions must have one parent element \ No newline at end of file diff --git a/tests/baselines/reference/tsxErrorRecovery3.js b/tests/baselines/reference/tsxErrorRecovery3.js new file mode 100644 index 00000000000..93b34a14c19 --- /dev/null +++ b/tests/baselines/reference/tsxErrorRecovery3.js @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/jsx/tsxErrorRecovery3.tsx] //// + +//// [file1.tsx] + +declare namespace JSX { interface Element { } } + +
+
+ +//// [file2.tsx] +var x =
+ + +//// [file1.js] +React.createElement("div", null) + , + React.createElement("div", null); +//// [file2.js] +var x = React.createElement("div", null), React.createElement("div", null); diff --git a/tests/cases/compiler/assignmentCompat1.ts b/tests/cases/compiler/assignmentCompat1.ts index b37a11b20d9..e93da76d95e 100644 --- a/tests/cases/compiler/assignmentCompat1.ts +++ b/tests/cases/compiler/assignmentCompat1.ts @@ -5,3 +5,7 @@ x = y; // Error y = x; // Ok because index signature type is any x = z; // Error z = x; // Ok because index signature type is any +y = "foo"; // Error +z = "foo"; // OK, string has numeric indexer +z = false; // Error + diff --git a/tests/cases/compiler/nestedRedeclarationInES6AMD.ts b/tests/cases/compiler/nestedRedeclarationInES6AMD.ts new file mode 100644 index 00000000000..e518e354cd0 --- /dev/null +++ b/tests/cases/compiler/nestedRedeclarationInES6AMD.ts @@ -0,0 +1,8 @@ +// @target: ES6 +// @module: AMD +function a() { + { + let status = 1; + status = 2; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/objectLiteralExcessProperties.ts b/tests/cases/compiler/objectLiteralExcessProperties.ts new file mode 100644 index 00000000000..0aa81703c33 --- /dev/null +++ b/tests/cases/compiler/objectLiteralExcessProperties.ts @@ -0,0 +1,21 @@ +interface Book { + foreword: string; +} + +interface Cover { + color?: string; +} + +var b1: Book = { forword: "oops" }; + +var b2: Book | string = { foreward: "nope" }; + +var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }]; + +var b4: Book & Cover = { foreword: "hi", colour: "blue" }; + +var b5: Book & Cover = { foreward: "hi", color: "blue" }; + +var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 }; + +var b7: Book & number = { foreword: "hi", price: 10.99 }; diff --git a/tests/cases/conformance/jsx/tsxErrorRecovery2.tsx b/tests/cases/conformance/jsx/tsxErrorRecovery2.tsx new file mode 100644 index 00000000000..e189e0e7791 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxErrorRecovery2.tsx @@ -0,0 +1,10 @@ +//@jsx: preserve + +//@filename: file1.tsx +declare namespace JSX { interface Element { } } + +
+
+ +//@filename: file2.tsx +var x =
diff --git a/tests/cases/conformance/jsx/tsxErrorRecovery3.tsx b/tests/cases/conformance/jsx/tsxErrorRecovery3.tsx new file mode 100644 index 00000000000..9d444b07cb2 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxErrorRecovery3.tsx @@ -0,0 +1,10 @@ +//@jsx: react + +//@filename: file1.tsx +declare namespace JSX { interface Element { } } + +
+
+ +//@filename: file2.tsx +var x =
diff --git a/tests/cases/fourslash/formatAfterMultilineComment.ts b/tests/cases/fourslash/formatAfterMultilineComment.ts new file mode 100644 index 00000000000..b795ab5c8c9 --- /dev/null +++ b/tests/cases/fourslash/formatAfterMultilineComment.ts @@ -0,0 +1,7 @@ +/// +/////*foo +////*/"123123"; + +format.document(); +verify.currentFileContentIs(`/*foo +*/"123123";`) diff --git a/tests/webTestServer.ts b/tests/webTestServer.ts index 75d90dbeefe..b857e332c15 100644 --- a/tests/webTestServer.ts +++ b/tests/webTestServer.ts @@ -264,6 +264,7 @@ http.createServer(function (req: http.ServerRequest, res: http.ServerResponse) { var browserPath: string; if ((browser && browser === 'chrome')) { +<<<<<<< HEAD const platform = os.platform(); let defaultChromePath: string; switch(platform) { @@ -277,6 +278,22 @@ if ((browser && browser === 'chrome')) { console.log(`Default Chrome location for platform ${platform} is unknown`); break; } +======= + let defaultChromePath = ""; + switch (os.platform()) { + case "win32": + case "win64": + defaultChromePath = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"; + break; + case "linux": + defaultChromePath = "/opt/google/chrome/chrome" + break; + default: + console.log(`default Chrome location is unknown for platform '${os.platform()}'`); + break; + } + +>>>>>>> master if (fs.existsSync(defaultChromePath)) { browserPath = defaultChromePath; } else {