From fd52e9ae157e0136ed8a66e08a1c24227fcfb85a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 15 Dec 2015 15:49:00 -0800 Subject: [PATCH 01/23] Simplify abstract constructor type assignability checking --- src/compiler/checker.ts | 82 ++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 55 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1fdac127c50..5da30b18192 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5528,32 +5528,24 @@ namespace ts { if (target === anyFunctionType || source === anyFunctionType) { return Ternary.True; } + const sourceSignatures = getSignaturesOfType(source, kind); const targetSignatures = getSignaturesOfType(target, kind); + if (kind === SignatureKind.Construct && sourceSignatures.length && targetSignatures.length && + isAbstractConstructorType(source) && !isAbstractConstructorType(target)) { + // An abstract constructor type is not assignable to a non-abstract constructor type + // as it would otherwise be possible to new an abstract class. Note that the assignablity + // check we perform for an extends clause excludes construct signatures from the target, + // so this check never proceeds. + if (reportErrors) { + reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); + } + return Ternary.False; + } + let result = Ternary.True; const saveErrorInfo = errorInfo; - - - if (kind === SignatureKind.Construct) { - // Only want to compare the construct signatures for abstractness guarantees. - - // Because the "abstractness" of a class is the same across all construct signatures - // (internally we are checking the corresponding declaration), it is enough to perform - // the check and report an error once over all pairs of source and target construct signatures. - // - // sourceSig and targetSig are (possibly) undefined. - // - // Note that in an extends-clause, targetSignatures is stripped, so the check never proceeds. - const sourceSig = sourceSignatures[0]; - const targetSig = targetSignatures[0]; - - result &= abstractSignatureRelatedTo(source, sourceSig, target, targetSig); - if (result !== Ternary.True) { - return result; - } - } - outer: for (const t of targetSignatures) { if (!t.hasStringLiterals || target.flags & TypeFlags.FromSignature) { // Only elaborate errors from the first failure @@ -5580,40 +5572,6 @@ namespace ts { } } return result; - - function abstractSignatureRelatedTo(source: Type, sourceSig: Signature, target: Type, targetSig: Signature) { - if (sourceSig && targetSig) { - - const sourceDecl = source.symbol && getClassLikeDeclarationOfSymbol(source.symbol); - const targetDecl = target.symbol && getClassLikeDeclarationOfSymbol(target.symbol); - - if (!sourceDecl) { - // If the source object isn't itself a class declaration, it can be freely assigned, regardless - // of whether the constructed object is abstract or not. - return Ternary.True; - } - - const sourceErasedSignature = getErasedSignature(sourceSig); - const targetErasedSignature = getErasedSignature(targetSig); - - const sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature); - const targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature); - - const sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getClassLikeDeclarationOfSymbol(sourceReturnType.symbol); - const targetReturnDecl = targetReturnType && targetReturnType.symbol && getClassLikeDeclarationOfSymbol(targetReturnType.symbol); - const sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & NodeFlags.Abstract; - const targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & NodeFlags.Abstract; - - if (sourceIsAbstract && !(targetIsAbstract && targetDecl)) { - // if target isn't a class-declaration type, then it can be new'd, so we forbid the assignment. - if (reportErrors) { - reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); - } - return Ternary.False; - } - } - return Ternary.True; - } } function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): Ternary { @@ -5782,6 +5740,20 @@ namespace ts { } } + // Return true if the given type is the constructor type for an abstract class + function isAbstractConstructorType(type: Type) { + if (type.flags & TypeFlags.Anonymous) { + const symbol = type.symbol; + if (symbol && symbol.flags & SymbolFlags.Class) { + const declaration = getClassLikeDeclarationOfSymbol(symbol); + if (declaration && declaration.flags & NodeFlags.Abstract) { + return true; + } + } + } + return false; + } + // Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case // when structural type comparisons have been started for 10 or more instantiations of the same generic type. It is possible, // though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely expanding. From c21193a0b871de5368fdd73327adb5d659dd8b0b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 15 Dec 2015 17:33:51 -0800 Subject: [PATCH 02/23] Removing unused function --- src/compiler/checker.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5da30b18192..1a1a01d6dd0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15368,20 +15368,6 @@ namespace ts { return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration; } - function instantiateSingleCallFunctionType(functionType: Type, typeArguments: Type[]): Type { - if (functionType === unknownType) { - return unknownType; - } - - const signature = getSingleCallSignature(functionType); - if (!signature) { - return unknownType; - } - - const instantiatedSignature = getSignatureInstantiation(signature, typeArguments); - return getOrCreateTypeFromSignature(instantiatedSignature); - } - function createResolver(): EmitResolver { return { getReferencedExportContainer, From cf621399a49745d693b6874eab9b792d1055d6ab Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 14:32:02 -0800 Subject: [PATCH 03/23] Add 'no-unused-variable' to 'tslint.json'. --- tslint.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tslint.json b/tslint.json index 9b010d9a896..71efb21ad7b 100644 --- a/tslint.json +++ b/tslint.json @@ -38,6 +38,7 @@ "no-trailing-whitespace": true, "no-inferrable-types": true, "no-null": true, + "no-unused-variable": true, "boolean-trivia": true, "type-operator-spacing": true, "prefer-const": true, From 0a470add811a0c8edcb69fe977daad6451c9836b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 14:33:55 -0800 Subject: [PATCH 04/23] Removed unused declarations from 'sys.ts'. --- src/compiler/sys.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 836b2daeab2..c99c28bc0dd 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -218,7 +218,6 @@ namespace ts { const _fs = require("fs"); const _path = require("path"); const _os = require("os"); - const _tty = require("tty"); // average async stat takes about 30 microseconds // set chunk size to do 30 files in < 1 millisecond @@ -313,10 +312,6 @@ namespace ts { // time dynamically to match the large reference set? const watchedFileSet = createWatchedFileSet(); - function isNode4OrLater(): Boolean { - return parseInt(process.version.charAt(1)) >= 4; - } - const platform: string = _os.platform(); // win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive const useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin"; From 0843c82543da7552de929c5ef576ae6989f1d6fe Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 14:37:54 -0800 Subject: [PATCH 05/23] Removed unused declarations from 'core.ts'. --- src/compiler/core.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index cae7bd82103..ad434d4cfad 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -794,23 +794,6 @@ namespace ts { return path; } - const backslashOrDoubleQuote = /[\"\\]/g; - const escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; - const escapedCharsMap: Map = { - "\0": "\\0", - "\t": "\\t", - "\v": "\\v", - "\f": "\\f", - "\b": "\\b", - "\r": "\\r", - "\n": "\\n", - "\\": "\\\\", - "\"": "\\\"", - "\u2028": "\\u2028", // lineSeparator - "\u2029": "\\u2029", // paragraphSeparator - "\u0085": "\\u0085" // nextLine - }; - export interface ObjectAllocator { getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node; getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile; From 80c7f3a529baffdfb2eee060a497a879a711d6bd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 14:39:15 -0800 Subject: [PATCH 06/23] Removed unused declarations from 'declarationEmitter.ts'. --- src/compiler/declarationEmitter.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 3348b51dff7..d0c5cbff48b 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1534,14 +1534,6 @@ namespace ts { } function emitBindingElement(bindingElement: BindingElement) { - function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - const diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); - return diagnosticMessage !== undefined ? { - diagnosticMessage, - errorNode: bindingElement, - typeName: bindingElement.name - } : undefined; - } if (bindingElement.kind === SyntaxKind.OmittedExpression) { // If bindingElement is an omittedExpression (i.e. containing elision), From b1ccf69d34c9fa20f96321793400048ffdde1fc1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 14:50:27 -0800 Subject: [PATCH 07/23] Removed unused declarations in 'checker.ts'. --- src/compiler/checker.ts | 180 ++++------------------------------------ 1 file changed, 16 insertions(+), 164 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1fdac127c50..96852d25efb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -819,15 +819,6 @@ namespace ts { return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier); } - function getMemberOfModuleVariable(moduleSymbol: Symbol, name: string): Symbol { - if (moduleSymbol.flags & SymbolFlags.Variable) { - const typeAnnotation = (moduleSymbol.valueDeclaration).type; - if (typeAnnotation) { - return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name); - } - } - } - // This function creates a synthetic symbol that combines the value side of one symbol with the // type/namespace side of another symbol. Consider this example: // @@ -1063,7 +1054,6 @@ namespace ts { } const moduleReferenceLiteral = moduleReferenceExpression; - const searchPath = getDirectoryPath(getSourceFile(location).fileName); // Module names are escaped in our symbol table. However, string literal values aren't. // Escape the name in the "require(...)" clause to ensure we find the right symbol. @@ -2183,65 +2173,15 @@ namespace ts { } function isDeclarationVisible(node: Declaration): boolean { - function getContainingExternalModule(node: Node) { - for (; node; node = node.parent) { - if (node.kind === SyntaxKind.ModuleDeclaration) { - if ((node).name.kind === SyntaxKind.StringLiteral) { - return node; - } - } - else if (node.kind === SyntaxKind.SourceFile) { - return isExternalOrCommonJsModule(node) ? node : undefined; - } + if (node) { + const links = getNodeLinks(node); + if (links.isVisible === undefined) { + links.isVisible = !!determineIfDeclarationIsVisible(); } - Debug.fail("getContainingModule cant reach here"); + return links.isVisible; } - function isUsedInExportAssignment(node: Node) { - // Get source File and see if it is external module and has export assigned symbol - const externalModule = getContainingExternalModule(node); - let exportAssignmentSymbol: Symbol; - let resolvedExportSymbol: Symbol; - if (externalModule) { - // This is export assigned symbol node - const externalModuleSymbol = getSymbolOfNode(externalModule); - exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol); - const symbolOfNode = getSymbolOfNode(node); - if (isSymbolUsedInExportAssignment(symbolOfNode)) { - return true; - } - - // if symbolOfNode is alias declaration, resolve the symbol declaration and check - if (symbolOfNode.flags & SymbolFlags.Alias) { - return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode)); - } - } - - // Check if the symbol is used in export assignment - function isSymbolUsedInExportAssignment(symbol: Symbol) { - if (exportAssignmentSymbol === symbol) { - return true; - } - - if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & SymbolFlags.Alias)) { - // if export assigned symbol is alias declaration, resolve the alias - resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol); - if (resolvedExportSymbol === symbol) { - return true; - } - - // Container of resolvedExportSymbol is visible - return forEach(resolvedExportSymbol.declarations, (current: Node) => { - while (current) { - if (current === node) { - return true; - } - current = current.parent; - } - }); - } - } - } + return false; function determineIfDeclarationIsVisible() { switch (node.kind) { @@ -2320,14 +2260,6 @@ namespace ts { Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind); } } - - if (node) { - const links = getNodeLinks(node); - if (links.isVisible === undefined) { - links.isVisible = !!determineIfDeclarationIsVisible(); - } - return links.isVisible; - } } function collectLinkedAliases(node: Identifier): Node[] { @@ -3373,14 +3305,6 @@ namespace ts { } } - function addInheritedSignatures(signatures: Signature[], baseSignatures: Signature[]) { - if (baseSignatures) { - for (const signature of baseSignatures) { - signatures.push(signature); - } - } - } - function resolveDeclaredMembers(type: InterfaceType): InterfaceTypeWithDeclaredMembers { if (!(type).declaredProperties) { const symbol = type.symbol; @@ -3861,25 +3785,6 @@ namespace ts { function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] { return getSignaturesOfStructuredType(getApparentType(type), kind); } - - function typeHasConstructSignatures(type: Type): boolean { - const apparentType = getApparentType(type); - if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Union)) { - const resolved = resolveStructuredTypeMembers(type); - return resolved.constructSignatures.length > 0; - } - return false; - } - - function typeHasCallOrConstructSignatures(type: Type): boolean { - const apparentType = getApparentType(type); - if (apparentType.flags & TypeFlags.StructuredType) { - const resolved = resolveStructuredTypeMembers(type); - return resolved.callSignatures.length > 0 || resolved.constructSignatures.length > 0; - } - return false; - } - function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type { if (type.flags & TypeFlags.StructuredType) { const resolved = resolveStructuredTypeMembers(type); @@ -4381,10 +4286,6 @@ namespace ts { return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity); } - function tryGetGlobalType(name: string, arity = 0): ObjectType { - return getTypeOfGlobalSymbol(getGlobalSymbol(name, SymbolFlags.Type, /*diagnostic*/ undefined), arity); - } - /** * Returns a type that is inside a namespace at the global scope, e.g. * getExportedTypeFromNamespace('JSX', 'Element') returns the JSX.Element type @@ -6148,12 +6049,8 @@ namespace ts { } function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext { - const inferences: TypeInferences[] = []; - for (const unused of typeParameters) { - inferences.push({ - primary: undefined, secondary: undefined, isFixed: false - }); - } + const inferences = map(typeParameters, createTypeInferencesObject); + return { typeParameters, inferUnionTypes, @@ -6162,6 +6059,14 @@ namespace ts { }; } + function createTypeInferencesObject(): TypeInferences { + return { + primary: undefined, + secondary: undefined, + isFixed: false, + }; + } + function inferTypes(context: InferenceContext, source: Type, target: Type) { let sourceStack: Type[]; let targetStack: Type[]; @@ -6432,10 +6337,6 @@ namespace ts { return context.inferredTypes; } - function hasAncestor(node: Node, kind: SyntaxKind): boolean { - return getAncestor(node, kind) !== undefined; - } - // EXPRESSION TYPE CHECKING function getResolvedSymbol(node: Identifier): Symbol { @@ -8035,7 +7936,6 @@ namespace ts { /// type or factory function. /// Otherwise, returns unknownSymbol. function getJsxElementTagSymbol(node: JsxOpeningLikeElement | JsxClosingElement): Symbol { - const flags: JsxFlags = JsxFlags.UnknownElement; const links = getNodeLinks(node); if (!links.resolvedSymbol) { if (isJsxIntrinsicIdentifier(node.tagName)) { @@ -14308,16 +14208,6 @@ namespace ts { } } - function getModuleStatements(node: Declaration): Statement[] { - if (node.kind === SyntaxKind.SourceFile) { - return (node).statements; - } - if (node.kind === SyntaxKind.ModuleDeclaration && (node).body.kind === SyntaxKind.ModuleBlock) { - return ((node).body).statements; - } - return emptyArray; - } - function hasExportedMembers(moduleSymbol: Symbol) { for (var id in moduleSymbol.exports) { if (id !== "export=") { @@ -15396,20 +15286,6 @@ namespace ts { return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration; } - function instantiateSingleCallFunctionType(functionType: Type, typeArguments: Type[]): Type { - if (functionType === unknownType) { - return unknownType; - } - - const signature = getSingleCallSignature(functionType); - if (!signature) { - return unknownType; - } - - const instantiatedSignature = getSignatureInstantiation(signature, typeArguments); - return getOrCreateTypeFromSignature(instantiatedSignature); - } - function createResolver(): EmitResolver { return { getReferencedExportContainer, @@ -16458,25 +16334,6 @@ namespace ts { } } - function isIntegerLiteral(expression: Expression): boolean { - if (expression.kind === SyntaxKind.PrefixUnaryExpression) { - const unaryExpression = expression; - if (unaryExpression.operator === SyntaxKind.PlusToken || unaryExpression.operator === SyntaxKind.MinusToken) { - expression = unaryExpression.operand; - } - } - if (expression.kind === SyntaxKind.NumericLiteral) { - // Allows for scientific notation since literalExpression.text was formed by - // coercing a number to a string. Sometimes this coercion can yield a string - // in scientific notation. - // We also don't need special logic for hex because a hex integer is converted - // to decimal when it is coerced. - return /^[0-9]+([eE]\+?[0-9]+)?$/.test((expression).text); - } - - return false; - } - function hasParseDiagnostics(sourceFile: SourceFile): boolean { return sourceFile.parseDiagnostics.length > 0; } @@ -16505,11 +16362,6 @@ namespace ts { } } - function isEvalOrArgumentsIdentifier(node: Node): boolean { - return node.kind === SyntaxKind.Identifier && - ((node).text === "eval" || (node).text === "arguments"); - } - function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) { if (node.typeParameters) { return grammarErrorAtPos(getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration); From d7c5e18cb3439c3d5a07b721239615536429f1f5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 14:53:46 -0800 Subject: [PATCH 08/23] Removed unused declarations in 'parser.ts'. --- src/compiler/parser.ts | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 62d98337102..7f5d052a7e7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -771,10 +771,6 @@ namespace ts { return doInsideOfContext(ParserContextFlags.Yield, func); } - function doOutsideOfYieldContext(func: () => T): T { - return doOutsideOfContext(ParserContextFlags.Yield, func); - } - function doInDecoratorContext(func: () => T): T { return doInsideOfContext(ParserContextFlags.Decorator, func); } @@ -791,10 +787,6 @@ namespace ts { return doInsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func); } - function doOutsideOfYieldAndAwaitContext(func: () => T): T { - return doOutsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func); - } - function inContext(flags: ParserContextFlags) { return (contextFlags & flags) !== 0; } @@ -851,10 +843,6 @@ namespace ts { return token = scanner.scan(); } - function getTokenPos(pos: number): number { - return skipTrivia(sourceText, pos); - } - function reScanGreaterToken(): SyntaxKind { return token = scanner.reScanGreaterToken(); } @@ -2644,10 +2632,6 @@ namespace ts { isStartOfExpression(); } - function allowInAndParseExpression(): Expression { - return allowInAnd(parseExpression); - } - function parseExpression(): Expression { // Expression[in]: // AssignmentExpression[in] @@ -3962,7 +3946,6 @@ namespace ts { const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); const tokenIsIdentifier = isIdentifier(); - const nameToken = token; const propertyName = parsePropertyName(); // Disallowing of optional property assignments happens in the grammar checker. @@ -5104,10 +5087,6 @@ namespace ts { return undefined; } - function parseHeritageClausesWorker() { - return parseList(ParsingContext.HeritageClauses, parseHeritageClause); - } - function parseHeritageClause() { if (token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword) { const node = createNode(SyntaxKind.HeritageClause); @@ -5253,12 +5232,6 @@ namespace ts { return nextToken() === SyntaxKind.SlashToken; } - function nextTokenIsCommaOrFromKeyword() { - nextToken(); - return token === SyntaxKind.CommaToken || - token === SyntaxKind.FromKeyword; - } - function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration { parseExpected(SyntaxKind.ImportKeyword); const afterImportPos = scanner.getStartPos(); @@ -5751,13 +5724,6 @@ namespace ts { return finishNode(parameter); } - function parseJSDocOptionalType(type: JSDocType): JSDocOptionalType { - const result = createNode(SyntaxKind.JSDocOptionalType, type.pos); - nextToken(); - result.type = type; - return finishNode(result); - } - function parseJSDocTypeReference(): JSDocTypeReference { const result = createNode(SyntaxKind.JSDocTypeReference); result.name = parseSimplePropertyName(); From 11acb7bf16b123841dc256002c9bbb6848f1139c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 14:54:19 -0800 Subject: [PATCH 09/23] Removed unused declarations in 'sourcemap.ts'. --- src/compiler/sourcemap.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index d98dc233c16..50644201544 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -14,7 +14,6 @@ namespace ts { reset(): void; } - const nop = <(...args: any[]) => any>Function.prototype; let nullSourceMapWriter: SourceMapWriter; export function getNullSourceMapWriter(): SourceMapWriter { From 66cf6be6d84cb79d4433723d71d73dca72542e92 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 14:55:08 -0800 Subject: [PATCH 10/23] Removed unused declarations in 'emitter.ts'. --- src/compiler/emitter.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f0b49854734..622ec14caa8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -779,12 +779,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function emitTrailingCommaIfPresent(nodeList: NodeArray): void { - if (nodeList.hasTrailingComma) { - write(","); - } - } - function emitLinePreservingList(parent: Node, nodes: NodeArray, allowTrailingComma: boolean, spacesBetweenBraces: boolean) { Debug.assert(nodes.length > 0); @@ -3248,10 +3242,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function emitDownLevelForOfStatement(node: ForOfStatement) { - emitLoop(node, emitDownLevelForOfStatementWorker); - } - function emitDownLevelForOfStatementWorker(node: ForOfStatement, loop: ConvertedLoop) { // The following ES6 code: // From 9e801c21ae368658ca5df9bcfcf2db890badb294 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 15:01:05 -0800 Subject: [PATCH 11/23] Removed unused declarations in 'harness.ts'. --- src/harness/harness.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 15f3813e54d..117be8a9afb 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -31,7 +31,6 @@ // this will work in the browser via browserify var _chai: typeof chai = require("chai"); var assert: typeof _chai.assert = _chai.assert; -var expect: typeof _chai.expect = _chai.expect; declare var __dirname: string; // Node-specific var global = Function("return this").call(null); /* tslint:enable:no-var-keyword */ @@ -513,7 +512,6 @@ namespace Harness { } const folder: any = fso.GetFolder(path); - const paths: string[] = []; return filesInFolder(folder, path); }; @@ -627,18 +625,6 @@ namespace Harness { } /// Ask the server to use node's path.resolve to resolve the given path - function getResolvedPathFromServer(path: string) { - const xhr = new XMLHttpRequest(); - try { - xhr.open("GET", path + "?resolve", /*async*/ false); - xhr.send(); - } - catch (e) { - return { status: 404, responseText: null }; - } - - return waitForXHR(xhr); - } export interface XHRResponse { status: number; From 3dee60f6ef219860202622d8560d9a883c12e4b3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 15:01:48 -0800 Subject: [PATCH 12/23] Removed unused declarations in 'harnessLanguageService.ts'. --- src/harness/harnessLanguageService.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 3c7814df562..fb5b6ce92aa 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -315,13 +315,6 @@ namespace Harness.LanguageService { class LanguageServiceShimProxy implements ts.LanguageService { constructor(private shim: ts.LanguageServiceShim) { } - private unwrappJSONCallResult(result: string): any { - const parsedResult = JSON.parse(result); - if (parsedResult.error) { - throw new Error("Language Service Shim Error: " + JSON.stringify(parsedResult.error)); - } - return parsedResult.result; - } cleanupSemanticCache(): void { this.shim.cleanupSemanticCache(); } From 4a07ee730adc0ca75242325e84ef0513985fbec4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 15:02:20 -0800 Subject: [PATCH 13/23] Removed unused declarations in 'compilerRunner.ts'. --- src/harness/compilerRunner.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 8ee287b2637..d1566c05d4e 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -251,7 +251,6 @@ class CompilerBaselineRunner extends RunnerBase { const allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName)); const fullWalker = new TypeWriterWalker(program, /*fullTypeCheck*/ true); - const pullWalker = new TypeWriterWalker(program, /*fullTypeCheck*/ false); const fullResults: ts.Map = {}; const pullResults: ts.Map = {}; From 125f0a1a232c4ffa879590775e62346cd47b59aa Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 15:03:38 -0800 Subject: [PATCH 14/23] Removed unused declarations in 'loggedIO.ts'. --- src/harness/loggedIO.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index 0bae91f7976..3d51682f745 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -305,25 +305,6 @@ namespace Playback { } } - const pathEquivCache: any = {}; - function pathsAreEquivalent(left: string, right: string, wrapper: { resolvePath(s: string): string }) { - const key = left + "-~~-" + right; - function areSame(a: string, b: string) { - return ts.normalizeSlashes(a).toLowerCase() === ts.normalizeSlashes(b).toLowerCase(); - } - function check() { - if (Harness.Path.getFileName(left).toLowerCase() === Harness.Path.getFileName(right).toLowerCase()) { - return areSame(left, right) || areSame(wrapper.resolvePath(left), right) || areSame(left, wrapper.resolvePath(right)) || areSame(wrapper.resolvePath(left), wrapper.resolvePath(right)); - } - } - if (pathEquivCache.hasOwnProperty(key)) { - return pathEquivCache[key]; - } - else { - return pathEquivCache[key] = check(); - } - } - function noOpReplay(name: string) { // console.log("Swallowed write operation during replay: " + name); } From 7fd6aa4318db062346ebea005364efca0b868498 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 15:07:37 -0800 Subject: [PATCH 15/23] Removed unused declarations in 'editorServices.ts'. --- src/server/editorServices.ts | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 0305b7595c2..d023a9827ee 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -263,13 +263,11 @@ namespace ts.server { } resolvePath(path: string): string { - const start = new Date().getTime(); const result = this.host.resolvePath(path); return result; } fileExists(path: string): boolean { - const start = new Date().getTime(); const result = this.host.fileExists(path); return result; } @@ -325,32 +323,6 @@ namespace ts.server { } } - // assumes normalized paths - function getAbsolutePath(filename: string, directory: string) { - const rootLength = ts.getRootLength(filename); - if (rootLength > 0) { - return filename; - } - else { - const splitFilename = filename.split("/"); - const splitDir = directory.split("/"); - let i = 0; - let dirTail = 0; - const sflen = splitFilename.length; - while ((i < sflen) && (splitFilename[i].charAt(0) == ".")) { - const dots = splitFilename[i]; - if (dots == "..") { - dirTail++; - } - else if (dots != ".") { - return undefined; - } - i++; - } - return splitDir.slice(0, splitDir.length - dirTail).concat(splitFilename.slice(i)).join("/"); - } - } - export interface ProjectOptions { // these fields can be present in the project file files?: string[]; @@ -583,7 +555,9 @@ namespace ts.server { } handleProjectFilelistChanges(project: Project) { - const { succeeded, projectOptions, error } = this.configFileToProjectOptions(project.projectFilename); + // TODO: Ignoring potentially returned 'error' and 'succeeded' condition + const { projectOptions } = this.configFileToProjectOptions(project.projectFilename); + const newRootFiles = projectOptions.files.map((f => this.getCanonicalFileName(f))); const currentRootFiles = project.getRootFiles().map((f => this.getCanonicalFileName(f))); @@ -611,7 +585,9 @@ namespace ts.server { this.log("Detected newly added tsconfig file: " + fileName); - const { succeeded, projectOptions, error } = this.configFileToProjectOptions(fileName); + // TODO: Ignoring potentially returned 'error' and 'succeeded' condition + const { projectOptions } = this.configFileToProjectOptions(fileName); + const rootFilesInTsconfig = projectOptions.files.map(f => this.getCanonicalFileName(f)); const openFileRoots = this.openFileRoots.map(s => this.getCanonicalFileName(s.fileName)); From 172d509c74e4376d840eb64a48254f738a638a8a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 15:09:12 -0800 Subject: [PATCH 16/23] Removed unused declarations in 'session.ts'. --- src/server/session.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/server/session.ts b/src/server/session.ts index dae2384ce54..78686b79118 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -129,9 +129,6 @@ namespace ts.server { export class Session { protected projectService: ProjectService; - private pendingOperation = false; - private fileHash: ts.Map = {}; - private nextFileId = 1; private errorTimer: any; /*NodeJS.Timer | number*/ private immediateId: any; private changeSeq = 0; @@ -239,11 +236,6 @@ namespace ts.server { } } - private errorCheck(file: string, project: Project) { - this.syntacticCheck(file, project); - this.semanticCheck(file, project); - } - private reloadProjects() { this.projectService.reloadProjects(); } @@ -901,7 +893,7 @@ namespace ts.server { } getDiagnosticsForProject(delay: number, fileName: string) { - const { configFileName, fileNames } = this.getProjectInfo(fileName, /*needFileNameList*/ true); + const { fileNames } = this.getProjectInfo(fileName, /*needFileNameList*/ true); // No need to analyze lib.d.ts let fileNamesInProject = fileNames.filter((value, index, array) => value.indexOf("lib.d.ts") < 0); From 7637f4d2a0d6fccbb200a8411359ad6b034e8237 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 15:09:39 -0800 Subject: [PATCH 17/23] Removed unused declarations in 'server.ts'. --- src/server/server.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/server/server.ts b/src/server/server.ts index e29e79ac6ed..d9f078ac0eb 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -4,9 +4,7 @@ /* tslint:disable:no-null */ namespace ts.server { - const nodeproto: typeof NodeJS._debugger = require("_debugger"); const readline: NodeJS.ReadLine = require("readline"); - const path: NodeJS.Path = require("path"); const fs: typeof NodeJS.fs = require("fs"); const rl = readline.createInterface({ From 50542946f7051726bd9b8b26c566c0abdfdd18c9 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 15:12:25 -0800 Subject: [PATCH 18/23] Removed unused declarations in 'harness/fourslash.ts'. --- src/harness/fourslash.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 24f3319285b..e8d985d40a6 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -321,11 +321,6 @@ namespace FourSlash { PlaceOpenBraceOnNewLineForControlBlocks: false, }; - this.testData.files.forEach(file => { - const fileName = file.fileName.replace(Harness.IO.directoryName(file.fileName), "").substr(1); - const fileNameWithoutExtension = fileName.substr(0, fileName.lastIndexOf(".")); - }); - // Open the first file by default this.openFile(0); } @@ -762,10 +757,6 @@ namespace FourSlash { return this.languageService.getReferencesAtPosition(this.activeFile.fileName, this.currentCaretPosition); } - private assertionMessage(name: string, actualValue: any, expectedValue: any) { - return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue; - } - public getSyntacticDiagnostics(expected: string) { const diagnostics = this.languageService.getSyntacticDiagnostics(this.activeFile.fileName); this.testDiagnostics(expected, diagnostics); @@ -910,7 +901,6 @@ namespace FourSlash { } public verifyCurrentParameterSpanIs(parameter: string) { - const activeSignature = this.getActiveSignatureHelpItem(); const activeParameter = this.getActiveParameter(); assert.equal(ts.displayPartsToString(activeParameter.displayParts), parameter); } @@ -2189,9 +2179,6 @@ namespace FourSlash { } } - // TOOD: should these just use the Harness's stdout/stderr? - const fsOutput = new Harness.Compiler.WriterAggregator(); - const fsErrors = new Harness.Compiler.WriterAggregator(); export function runFourSlashTest(basePath: string, testType: FourSlashTestType, fileName: string) { const content = Harness.IO.readFile(fileName); runFourSlashTestContent(basePath, testType, content, fileName); From 65571426bf9e47b1d364060b72cdd48039f77d74 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 16:47:00 -0800 Subject: [PATCH 19/23] Remove missed unused declaration from 'harness.ts'. --- src/harness/harness.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 117be8a9afb..7fd81973172 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -615,7 +615,6 @@ namespace Harness { export const getExecutingFilePath = () => ""; export const exit = (exitCode: number) => {}; - const supportsCodePage = () => false; export let log = (s: string) => console.log(s); namespace Http { From f6253177094cb2fb1e32c1572a7227d96269bf36 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 17:04:45 -0800 Subject: [PATCH 20/23] Added missing require for 'session' tests that relied on 'harness.ts'. --- tests/cases/unittests/session.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/cases/unittests/session.ts b/tests/cases/unittests/session.ts index c1dfd508942..1251fb7215f 100644 --- a/tests/cases/unittests/session.ts +++ b/tests/cases/unittests/session.ts @@ -1,5 +1,7 @@ /// +var expect: typeof _chai.expect = _chai.expect; + namespace ts.server { let lastWrittenToHost: string; const mockHost: ServerHost = { @@ -28,7 +30,7 @@ namespace ts.server { endGroup(): void {}, msg(s: string, type?: string): void {}, }; - + describe("the Session class", () => { let session: Session; let lastSent: protocol.Message; @@ -204,7 +206,7 @@ namespace ts.server { .to.throw(`Protocol handler already exists for command "${command}"`); }); }); - + describe("event", () => { it("can format event responses and send them", () => { const evt = "notify-test"; @@ -315,7 +317,7 @@ namespace ts.server { responseRequired: true })); } - + send(msg: protocol.Message) { this.client.handle(msg); } @@ -323,7 +325,7 @@ namespace ts.server { enqueue(msg: protocol.Request) { this.queue.unshift(msg); } - + handleRequest(msg: protocol.Request) { let response: protocol.Response; try { @@ -345,7 +347,7 @@ namespace ts.server { } } } - + class InProcClient { private server: InProcSession; private seq = 0; @@ -379,7 +381,7 @@ namespace ts.server { connect(session: InProcSession): void { this.server = session; } - + execute(command: string, args: any, callback: (resp: protocol.Response) => void): void { if (!this.server) { return; @@ -394,7 +396,7 @@ namespace ts.server { this.callbacks[this.seq] = callback; } }; - + it("can be constructed and respond to commands", (done) => { const cli = new InProcClient(); const session = new InProcSession(cli); @@ -402,23 +404,23 @@ namespace ts.server { data: true }; const toEvent = { - data: false + data: false }; let responses = 0; // Connect the client cli.connect(session); - + // Add an event handler cli.on("testevent", (eventinfo) => { expect(eventinfo).to.equal(toEvent); responses++; expect(responses).to.equal(1); }); - + // Trigger said event from the server session.event(toEvent, "testevent"); - + // Queue an echo command cli.execute("echo", toEcho, (resp) => { assert(resp.success, resp.message); @@ -426,7 +428,7 @@ namespace ts.server { expect(responses).to.equal(2); expect(resp.body).to.deep.equal(toEcho); }); - + // Queue a configure command cli.execute("configure", { hostInfo: "unit test", @@ -436,10 +438,10 @@ namespace ts.server { }, (resp) => { assert(resp.success, resp.message); responses++; - expect(responses).to.equal(3); + expect(responses).to.equal(3); done(); }); - + // Consume the queue and trigger the callbacks session.consumeQueue(); }); From 75678de6d99ecffec583804fd6ce52cc83c46618 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 19:47:01 -0800 Subject: [PATCH 21/23] Removed unused declarations from 'services.ts'. --- src/services/services.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 8f9028486aa..10f404dbcad 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2987,7 +2987,6 @@ namespace ts { function getCompletionData(fileName: string, position: number) { const typeChecker = program.getTypeChecker(); - const syntacticStart = new Date().getTime(); const sourceFile = getValidSourceFile(fileName); const isJavaScriptFile = isSourceFileJavaScript(sourceFile); @@ -6166,10 +6165,6 @@ namespace ts { return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount); } - function containErrors(diagnostics: Diagnostic[]): boolean { - return forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error); - } - function getEmitOutput(fileName: string): EmitOutput { synchronizeHostData(); @@ -7045,7 +7040,6 @@ namespace ts { * be performed. */ function getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion { - const start = new Date().getTime(); const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); // Check if in a context where we don't want to perform any insertion @@ -7339,11 +7333,17 @@ namespace ts { if (declarations && declarations.length > 0) { // Disallow rename for elements that are defined in the standard TypeScript library. const defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings()); + const canonicalDefaultLibName = getCanonicalFileName(ts.normalizePath(defaultLibFileName)); if (defaultLibFileName) { for (const current of declarations) { const sourceFile = current.getSourceFile(); + // TODO (drosen): When is there no source file? + if (!sourceFile) { + continue; + } + const canonicalName = getCanonicalFileName(ts.normalizePath(sourceFile.fileName)); - if (sourceFile && getCanonicalFileName(ts.normalizePath(sourceFile.fileName)) === getCanonicalFileName(ts.normalizePath(defaultLibFileName))) { + if (canonicalName === canonicalDefaultLibName) { return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library)); } } From a8f87bb2cafc7228c8badc3fd85d43cbf2291ce9 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 18 Dec 2015 11:21:31 -0800 Subject: [PATCH 22/23] only '++' and '--' unary operators can change exports --- src/compiler/emitter.ts | 3 +- ...prefixUnaryOperatorsOnExportedVariables.js | 58 +++++++++++++++++++ ...xUnaryOperatorsOnExportedVariables.symbols | 42 ++++++++++++++ ...fixUnaryOperatorsOnExportedVariables.types | 51 ++++++++++++++++ ...prefixUnaryOperatorsOnExportedVariables.ts | 32 ++++++++++ 5 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js create mode 100644 tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.symbols create mode 100644 tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.types create mode 100644 tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 622ec14caa8..ab775ba9fc6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2445,7 +2445,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitPrefixUnaryExpression(node: PrefixUnaryExpression) { - const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + const exportChanged = (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) && + isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); if (exportChanged) { // emit diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js new file mode 100644 index 00000000000..5d414c97d05 --- /dev/null +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js @@ -0,0 +1,58 @@ +//// [prefixUnaryOperatorsOnExportedVariables.ts] + +export var x = false; +export var y = 1; +if (!x) { + +} + +if (+x) { + +} + +if (-x) { + +} + +if (~x) { + +} + +if (void x) { + +} + +if (typeof x) { + +} + +if (++y) { + +} + +//// [prefixUnaryOperatorsOnExportedVariables.js] +System.register([], function(exports_1) { + "use strict"; + var x, y; + return { + setters:[], + execute: function() { + exports_1("x", x = false); + exports_1("y", y = 1); + if (!x) { + } + if (+x) { + } + if (-x) { + } + if (~x) { + } + if (void x) { + } + if (typeof x) { + } + if (exports_1("y", ++y)) { + } + } + } +}); diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.symbols b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.symbols new file mode 100644 index 00000000000..c8293ef1902 --- /dev/null +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.symbols @@ -0,0 +1,42 @@ +=== tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts === + +export var x = false; +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +export var y = 1; +>y : Symbol(y, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 2, 10)) + +if (!x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (+x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (-x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (~x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (void x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (typeof x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (++y) { +>y : Symbol(y, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 2, 10)) + +} diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.types b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.types new file mode 100644 index 00000000000..c75ba492c31 --- /dev/null +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.types @@ -0,0 +1,51 @@ +=== tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts === + +export var x = false; +>x : boolean +>false : boolean + +export var y = 1; +>y : number +>1 : number + +if (!x) { +>!x : boolean +>x : boolean + +} + +if (+x) { +>+x : number +>x : boolean + +} + +if (-x) { +>-x : number +>x : boolean + +} + +if (~x) { +>~x : number +>x : boolean + +} + +if (void x) { +>void x : undefined +>x : boolean + +} + +if (typeof x) { +>typeof x : string +>x : boolean + +} + +if (++y) { +>++y : number +>y : number + +} diff --git a/tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts b/tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts new file mode 100644 index 00000000000..58b05bb513a --- /dev/null +++ b/tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts @@ -0,0 +1,32 @@ +// @target: ES5 +// @module: system + +export var x = false; +export var y = 1; +if (!x) { + +} + +if (+x) { + +} + +if (-x) { + +} + +if (~x) { + +} + +if (void x) { + +} + +if (typeof x) { + +} + +if (++y) { + +} \ No newline at end of file From cc5334eb89812dcc0c180089c84fbf4292a85fe3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 18 Dec 2015 14:06:08 -0800 Subject: [PATCH 23/23] Made 'expression' non-optional in 'CaseClause'. --- src/compiler/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a8c4ee211c3..24f70373a8a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1195,7 +1195,7 @@ namespace ts { // @kind(SyntaxKind.CaseClause) export interface CaseClause extends Node { - expression?: Expression; + expression: Expression; statements: NodeArray; }