diff --git a/scripts/tslint/typeOperatorSpacingRule.ts b/scripts/tslint/typeOperatorSpacingRule.ts index 7ceef2372bf..559d1b34937 100644 --- a/scripts/tslint/typeOperatorSpacingRule.ts +++ b/scripts/tslint/typeOperatorSpacingRule.ts @@ -18,8 +18,13 @@ class TypeOperatorSpacingWalker extends Lint.RuleWalker { for (let i = 1; i < types.length; i++) { const currentType = types[i]; if (expectedStart !== currentType.pos || currentType.getLeadingTriviaWidth() !== 1) { - const failure = this.createFailure(currentType.pos, currentType.getWidth(), Rule.FAILURE_STRING); - this.addFailure(failure); + const sourceFile = currentType.getSourceFile(); + const previousTypeEndPos = sourceFile.getLineAndCharacterOfPosition(types[i - 1].end); + const currentTypeStartPos = sourceFile.getLineAndCharacterOfPosition(currentType.pos); + if (previousTypeEndPos.line === currentTypeStartPos.line) { + const failure = this.createFailure(currentType.pos, currentType.getWidth(), Rule.FAILURE_STRING); + this.addFailure(failure); + } } expectedStart = currentType.end + 2; } diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index deee2061005..bb7166beeec 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -355,11 +355,24 @@ namespace ts { ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; - forEach(symbol.declarations, declaration => { - if (hasModifier(declaration, ModifierFlags.Default)) { + if (symbol.declarations && symbol.declarations.length) { + // If the current node is a default export of some sort, then check if + // there are any other default exports that we need to error on. + // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. + if (isDefaultExport) { message = Diagnostics.A_module_cannot_have_multiple_default_exports; } - }); + else { + // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. + // Error on multiple export default in the following case: + // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default + // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers) + if (symbol.declarations && symbol.declarations.length && + (isDefaultExport || (node.kind === SyntaxKind.ExportAssignment && !(node).isExportEquals))) { + message = Diagnostics.A_module_cannot_have_multiple_default_exports; + } + } + } forEach(symbol.declarations, declaration => { file.bindDiagnostics.push(createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); @@ -1111,7 +1124,7 @@ namespace ts { } else { forEachChild(node, bind); - if (node.operator === SyntaxKind.PlusEqualsToken || node.operator === SyntaxKind.MinusMinusToken) { + if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) { bindAssignmentTargetFlow(node.operand); } } @@ -1360,7 +1373,7 @@ namespace ts { function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean { const body = node.kind === SyntaxKind.SourceFile ? node : (node).body; if (body && (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock)) { - for (const stat of (body).statements) { + for (const stat of (body).statements) { if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) { return true; } @@ -1943,12 +1956,15 @@ namespace ts { bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node)); } else { + // An export default clause with an expression exports a value + // We want to exclude both class and function here, this is necessary to issue an error when there are both + // default export-assignment and default export function and class declaration. const flags = node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(node) // An export default clause with an EntityNameExpression exports all meanings of that identifier ? SymbolFlags.Alias // An export default clause with any other expression exports a value : SymbolFlags.Property; - declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); + declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.Property | SymbolFlags.AliasExcludes | SymbolFlags.Class | SymbolFlags.Function); } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e8d2bacac63..514d225139e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -120,6 +120,7 @@ namespace ts { const resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__"); const anyType = createIntrinsicType(TypeFlags.Any, "any"); + const autoType = createIntrinsicType(TypeFlags.Any, "any"); const unknownType = createIntrinsicType(TypeFlags.Any, "unknown"); const undefinedType = createIntrinsicType(TypeFlags.Undefined, "undefined"); const undefinedWideningType = strictNullChecks ? undefinedType : createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsWideningType, "undefined"); @@ -3064,6 +3065,11 @@ namespace ts { return undefined; } + function isAutoVariableInitializer(initializer: Expression) { + const expr = initializer && skipParentheses(initializer); + return !expr || expr.kind === SyntaxKind.NullKeyword || expr.kind === SyntaxKind.Identifier && getResolvedSymbol(expr) === undefinedSymbol; + } + function addOptionality(type: Type, optional: boolean): Type { return strictNullChecks && optional ? includeFalsyTypes(type, TypeFlags.Undefined) : type; } @@ -3102,6 +3108,14 @@ namespace ts { return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality); } + // Use control flow type inference for non-ambient, non-exported var or let variables with no initializer + // or a 'null' or 'undefined' initializer. + if (declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) && + !(getCombinedNodeFlags(declaration) & NodeFlags.Const) && !(getCombinedModifierFlags(declaration) & ModifierFlags.Export) && + !isInAmbientContext(declaration) && isAutoVariableInitializer(declaration.initializer)) { + return autoType; + } + if (declaration.kind === SyntaxKind.Parameter) { const func = declaration.parent; // For a parameter of a set accessor, use the type of the get accessor if one is present @@ -3897,7 +3911,7 @@ namespace ts { if (!links.declaredType) { const enumType = getDeclaredTypeOfEnum(getParentOfSymbol(symbol)); links.declaredType = enumType.flags & TypeFlags.Union ? - enumType.memberTypes[getEnumMemberValue(symbol.valueDeclaration)] : + enumType.memberTypes[getEnumMemberValue(symbol.valueDeclaration)] : enumType; } return links.declaredType; @@ -6070,7 +6084,7 @@ namespace ts { return !node.typeParameters && areAllParametersUntyped && !isNullaryArrow; } - function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | MethodDeclaration { + function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration { return (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && isContextSensitiveFunctionLikeDeclaration(func); } @@ -8470,7 +8484,9 @@ namespace ts { if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) { return declaredType; } - const initialType = assumeInitialized ? declaredType : includeFalsyTypes(declaredType, TypeFlags.Undefined); + const initialType = assumeInitialized ? declaredType : + declaredType === autoType ? undefinedType : + includeFalsyTypes(declaredType, TypeFlags.Undefined); const visitedFlowStart = visitedFlowCount; const result = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode)); visitedFlowCount = visitedFlowStart; @@ -8544,9 +8560,12 @@ namespace ts { // Assignments only narrow the computed type if the declared type is a union type. Thus, we // only need to evaluate the assigned type if the declared type is a union type. if (isMatchingReference(reference, node)) { - const isIncrementOrDecrement = node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression; - return declaredType.flags & TypeFlags.Union && !isIncrementOrDecrement ? - getAssignmentReducedType(declaredType, getInitialOrAssignedType(node)) : + if (node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression) { + const flowType = getTypeAtFlowNode(flow.antecedent); + return createFlowType(getBaseTypeOfLiteralType(getTypeFromFlowType(flowType)), isIncomplete(flowType)); + } + return declaredType === autoType ? getBaseTypeOfLiteralType(getInitialOrAssignedType(node)) : + declaredType.flags & TypeFlags.Union ? getAssignmentReducedType(declaredType, getInitialOrAssignedType(node)) : declaredType; } // We didn't have a direct match. However, if the reference is a dotted name, this @@ -8992,7 +9011,7 @@ namespace ts { if (isRightSideOfQualifiedNameOrPropertyAccess(location)) { location = location.parent; } - if (isExpression(location) && !isAssignmentTarget(location)) { + if (isPartOfExpression(location) && !isAssignmentTarget(location)) { const type = checkExpression(location); if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) { return type; @@ -9163,13 +9182,23 @@ namespace ts { // We only look for uninitialized variables in strict null checking mode, and only when we can analyze // the entire control flow graph from the variable's declaration (i.e. when the flow container and // declaration container are the same). - const assumeInitialized = !strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isParameter || - isOuterVariable || isInAmbientContext(declaration); + const assumeInitialized = isParameter || isOuterVariable || + type !== autoType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0) || + isInAmbientContext(declaration); const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer); // A variable is considered uninitialized when it is possible to analyze the entire control flow graph // from declaration to use, and when the variable's declared type doesn't include undefined but the // control flow based type does include undefined. - if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) { + if (type === autoType) { + if (flowType === autoType) { + if (compilerOptions.noImplicitAny) { + error(declaration.name, Diagnostics.Variable_0_implicitly_has_type_any_in_some_locations_where_its_type_cannot_be_determined, symbolToString(symbol)); + error(node, Diagnostics.Variable_0_implicitly_has_an_1_type, symbolToString(symbol), typeToString(anyType)); + } + return anyType; + } + } + else if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) { error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol)); // Return the declared type to reduce follow-on errors return type; @@ -9283,7 +9312,7 @@ namespace ts { } function findFirstSuperCall(n: Node): Node { - if (isSuperCallExpression(n)) { + if (isSuperCall(n)) { return n; } else if (isFunctionLike(n)) { @@ -9792,7 +9821,7 @@ namespace ts { // corresponding set accessor has a type annotation, return statements in the function are contextually typed if (functionDecl.type || functionDecl.kind === SyntaxKind.Constructor || - functionDecl.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(getDeclarationOfKind(functionDecl.symbol, SyntaxKind.SetAccessor))) { + functionDecl.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(getDeclarationOfKind(functionDecl.symbol, SyntaxKind.SetAccessor))) { return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); } @@ -10061,7 +10090,7 @@ namespace ts { } } - function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression { + function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression | ArrowFunction { return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction; } @@ -10072,7 +10101,7 @@ namespace ts { : undefined; } - function getContextualTypeForFunctionLikeDeclaration(node: FunctionExpression | MethodDeclaration) { + function getContextualTypeForFunctionLikeDeclaration(node: FunctionExpression | ArrowFunction | MethodDeclaration) { return isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getApparentTypeOfContextualType(node); @@ -10083,7 +10112,7 @@ namespace ts { // If the contextual type is a union type, get the signature from each type possible and if they are // all identical ignoring their return type, the result is same signature but with return type as // union type of return types from these signatures - function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature { + function getContextualSignature(node: FunctionExpression | ArrowFunction | MethodDeclaration): Signature { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); const type = getContextualTypeForFunctionLikeDeclaration(node); if (!type) { @@ -11436,7 +11465,7 @@ namespace ts { argCount = getEffectiveArgumentCount(node, /*args*/ undefined, signature); } else { - const callExpression = node; + const callExpression = node; if (!callExpression.arguments) { // This only happens when we have something of the form: 'new C' Debug.assert(callExpression.kind === SyntaxKind.NewExpression); @@ -11447,7 +11476,7 @@ namespace ts { argCount = signatureHelpTrailingComma ? args.length + 1 : args.length; // If we are missing the close paren, the call is incomplete. - callIsIncomplete = (callExpression).arguments.end === callExpression.end; + callIsIncomplete = callExpression.arguments.end === callExpression.end; typeArguments = callExpression.typeArguments; spreadArgIndex = getSpreadArgumentIndex(args); @@ -12534,7 +12563,7 @@ namespace ts { * @param node The call/new expression to be checked. * @returns On success, the expression's signature's return type. On failure, anyType. */ - function checkCallExpression(node: CallExpression): Type { + function checkCallExpression(node: CallExpression | NewExpression): Type { // Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); @@ -12992,7 +13021,7 @@ namespace ts { } } - if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { + if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration) { checkCollisionWithCapturedSuperVariable(node, (node).name); checkCollisionWithCapturedThisVariable(node, (node).name); } @@ -14454,7 +14483,7 @@ namespace ts { } function containsSuperCall(n: Node): boolean { - if (isSuperCallExpression(n)) { + if (isSuperCall(n)) { return true; } else if (isFunctionLike(n)) { @@ -14510,7 +14539,7 @@ namespace ts { let superCallStatement: ExpressionStatement; for (const statement of statements) { - if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { + if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCall((statement).expression)) { superCallStatement = statement; break; } @@ -15917,6 +15946,10 @@ namespace ts { } } + function convertAutoToAny(type: Type) { + return type === autoType ? anyType : type; + } + // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { checkDecorators(node); @@ -15967,7 +16000,7 @@ namespace ts { return; } const symbol = getSymbolOfNode(node); - const type = getTypeOfVariableOrParameterOrProperty(symbol); + const type = convertAutoToAny(getTypeOfVariableOrParameterOrProperty(symbol)); if (node === symbol.valueDeclaration) { // Node is the primary declaration of the symbol, just validate the initializer // Don't validate for-in initializer as it is already an error @@ -15979,7 +16012,7 @@ namespace ts { else { // Node is a secondary declaration, check that type is identical to primary declaration and check that // initializer is consistent with type associated with the node - const declarationType = getWidenedTypeForVariableLikeDeclaration(node); + const declarationType = convertAutoToAny(getWidenedTypeForVariableLikeDeclaration(node)); if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) { error(node.name, Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, declarationNameToString(node.name), typeToString(type), typeToString(declarationType)); } @@ -16468,7 +16501,7 @@ namespace ts { } function isGetAccessorWithAnnotatedSetAccessor(node: FunctionLikeDeclaration) { - return !!(node.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(getDeclarationOfKind(node.symbol, SyntaxKind.SetAccessor))); + return !!(node.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(getDeclarationOfKind(node.symbol, SyntaxKind.SetAccessor))); } function isUnwrappedReturnTypeVoidOrAny(func: FunctionLikeDeclaration, returnType: Type): boolean { @@ -17459,9 +17492,12 @@ namespace ts { } } - checkCollisionWithCapturedThisVariable(node, node.name); - checkCollisionWithRequireExportsInGeneratedCode(node, node.name); - checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); + if (isIdentifier(node.name)) { + checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); + } + checkExportsOnMergedDeclarations(node); const symbol = getSymbolOfNode(node); @@ -19076,7 +19112,7 @@ namespace ts { return undefined; } - function isLiteralConstDeclaration(node: VariableDeclaration): boolean { + function isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean { if (isConst(node)) { const type = getTypeOfSymbol(getSymbolOfNode(node)); return !!(type.flags & TypeFlags.StringOrNumberLiteral && type.flags & TypeFlags.FreshLiteral); @@ -19084,7 +19120,7 @@ namespace ts { return false; } - function writeLiteralConstValue(node: VariableDeclaration, writer: SymbolWriter) { + function writeLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, writer: SymbolWriter) { const type = getTypeOfSymbol(getSymbolOfNode(node)); writer.writeStringLiteral(literalTypeToString(type)); } @@ -19822,7 +19858,7 @@ namespace ts { checkGrammarForAtLeastOneTypeArgument(node, typeArguments); } - function checkGrammarForOmittedArgument(node: CallExpression, args: NodeArray): boolean { + function checkGrammarForOmittedArgument(node: CallExpression | NewExpression, args: NodeArray): boolean { if (args) { const sourceFile = getSourceFileOfNode(node); for (const arg of args) { @@ -19833,7 +19869,7 @@ namespace ts { } } - function checkGrammarArguments(node: CallExpression, args: NodeArray): boolean { + function checkGrammarArguments(node: CallExpression | NewExpression, args: NodeArray): boolean { return checkGrammarForOmittedArgument(node, args); } @@ -19955,8 +19991,7 @@ namespace ts { for (const prop of node.properties) { const name = prop.name; - if (prop.kind === SyntaxKind.OmittedExpression || - name.kind === SyntaxKind.ComputedPropertyName) { + if (name.kind === SyntaxKind.ComputedPropertyName) { // If the name is not a ComputedPropertyName, the grammar checking will skip it checkGrammarComputedPropertyName(name); } @@ -20003,7 +20038,7 @@ namespace ts { currentKind = SetAccessor; } else { - Debug.fail("Unexpected syntax kind:" + prop.kind); + Debug.fail("Unexpected syntax kind:" + (prop).kind); } const effectiveName = getPropertyNameForPropertyNameNode(name); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 4a9c8d7f771..65cbae6a7d2 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -836,7 +836,9 @@ namespace ts { return path.replace(/\\/g, "/"); } - // Returns length of path root (i.e. length of "/", "x:/", "//server/share/, file:///user/files") + /** + * Returns length of path root (i.e. length of "/", "x:/", "//server/share/, file:///user/files") + */ export function getRootLength(path: string): number { if (path.charCodeAt(0) === CharacterCodes.slash) { if (path.charCodeAt(1) !== CharacterCodes.slash) return 1; @@ -865,9 +867,14 @@ namespace ts { return 0; } + /** + * Internally, we represent paths as strings with '/' as the directory separator. + * When we make system calls (eg: LanguageServiceHost.getDirectory()), + * we expect the host to correctly handle paths in our specified format. + */ export const directorySeparator = "/"; const directorySeparatorCharCode = CharacterCodes.slash; - function getNormalizedParts(normalizedSlashedPath: string, rootLength: number) { + function getNormalizedParts(normalizedSlashedPath: string, rootLength: number): string[] { const parts = normalizedSlashedPath.substr(rootLength).split(directorySeparator); const normalized: string[] = []; for (const part of parts) { @@ -907,6 +914,11 @@ namespace ts { return path.charCodeAt(path.length - 1) === directorySeparatorCharCode; } + /** + * Returns the path except for its basename. Eg: + * + * /path/to/file.ext -> /path/to + */ export function getDirectoryPath(path: Path): Path; export function getDirectoryPath(path: string): string; export function getDirectoryPath(path: string): any { @@ -1552,9 +1564,9 @@ namespace ts { export interface ObjectAllocator { getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node; - getTokenConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token; - getIdentifierConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token; - getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile; + getTokenConstructor(): new (kind: TKind, pos?: number, end?: number) => Token; + getIdentifierConstructor(): new (kind: SyntaxKind.Identifier, pos?: number, end?: number) => Identifier; + getSourceFileConstructor(): new (kind: SyntaxKind.SourceFile, pos?: number, end?: number) => SourceFile; getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol; getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type; getSignatureConstructor(): new (checker: TypeChecker) => Signature; diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 8e55df7fcf3..516bf1d4bb4 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1121,7 +1121,7 @@ namespace ts { writeLine(); } - function emitVariableDeclaration(node: VariableDeclaration) { + function emitVariableDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration) { // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted // so there is no check needed to see if declaration is visible if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { @@ -1136,7 +1136,7 @@ namespace ts { // If optional property emit ? but in the case of parameterProperty declaration with "?" indicating optional parameter for the constructor // we don't want to emit property declaration with "?" if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature || - (node.kind === SyntaxKind.Parameter && !isParameterPropertyDeclaration(node))) && hasQuestionToken(node)) { + (node.kind === SyntaxKind.Parameter && !isParameterPropertyDeclaration(node))) && hasQuestionToken(node)) { write("?"); } if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { @@ -1626,8 +1626,7 @@ namespace ts { } } - function emitBindingElement(bindingElement: BindingElement) { - + function emitBindingElement(bindingElement: BindingElement | OmittedExpression) { if (bindingElement.kind === SyntaxKind.OmittedExpression) { // If bindingElement is an omittedExpression (i.e. containing elision), // we will emit blank space (although this may differ from users' original code, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 71d7a978d1b..58c0e6ee3f2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2957,6 +2957,10 @@ "category": "Error", "code": 7033 }, + "Variable '{0}' implicitly has type 'any' in some locations where its type cannot be determined.": { + "category": "Error", + "code": 7034 + }, "You cannot rename this element.": { "category": "Error", "code": 8000 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4881bfcf3ef..75cb889e1bd 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -68,7 +68,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); @@ -655,7 +655,7 @@ const _super = (function (geti, seti) { case SyntaxKind.ModuleDeclaration: return emitModuleDeclaration(node); case SyntaxKind.ModuleBlock: - return emitModuleBlock(node); + return emitModuleBlock(node); case SyntaxKind.CaseBlock: return emitCaseBlock(node); case SyntaxKind.ImportEqualsDeclaration: @@ -1394,7 +1394,7 @@ const _super = (function (geti, seti) { } } - function emitBlockStatements(node: Block) { + function emitBlockStatements(node: BlockLike) { if (getEmitFlags(node) & EmitFlags.SingleLine) { emitList(node, node.statements, ListFormat.SingleLineBlockStatements); } @@ -1795,7 +1795,7 @@ const _super = (function (geti, seti) { } function emitModuleBlock(node: ModuleBlock) { - if (isSingleLineEmptyBlock(node)) { + if (isEmptyBlock(node)) { write("{ }"); } else { @@ -2615,7 +2615,11 @@ const _super = (function (geti, seti) { function isSingleLineEmptyBlock(block: Block) { return !block.multiLine - && block.statements.length === 0 + && isEmptyBlock(block); + } + + function isEmptyBlock(block: BlockLike) { + return block.statements.length === 0 && rangeEndIsOnSameLineAsRangeStart(block, block, currentSourceFile); } diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 93e830fa1f3..8fee7ffa95d 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -105,6 +105,7 @@ namespace ts { export function createLiteral(textSource: StringLiteral | Identifier, location?: TextRange): StringLiteral; export function createLiteral(value: string, location?: TextRange): StringLiteral; export function createLiteral(value: number, location?: TextRange): NumericLiteral; + export function createLiteral(value: boolean, location?: TextRange): BooleanLiteral; export function createLiteral(value: string | number | boolean, location?: TextRange): PrimaryExpression; export function createLiteral(value: string | number | boolean | StringLiteral | Identifier, location?: TextRange): PrimaryExpression { if (typeof value === "number") { @@ -120,7 +121,7 @@ namespace ts { node.text = value; return node; } - else { + else if (value) { const node = createNode(SyntaxKind.StringLiteral, location, /*flags*/ undefined); node.textSourceNode = value; node.text = value.text; @@ -187,8 +188,8 @@ namespace ts { // Punctuation - export function createToken(token: SyntaxKind) { - return createNode(token); + export function createToken(token: TKind) { + return >createNode(token); } // Reserved words @@ -238,7 +239,7 @@ namespace ts { ); } - export function createParameterDeclaration(decorators: Decorator[], modifiers: Modifier[], dotDotDotToken: Node, name: string | Identifier | BindingPattern, questionToken: Node, type: TypeNode, initializer: Expression, location?: TextRange, flags?: NodeFlags) { + export function createParameterDeclaration(decorators: Decorator[], modifiers: Modifier[], dotDotDotToken: DotDotDotToken, name: string | Identifier | BindingPattern, questionToken: QuestionToken, type: TypeNode, initializer: Expression, location?: TextRange, flags?: NodeFlags) { const node = createNode(SyntaxKind.Parameter, location, flags); node.decorators = decorators ? createNodeArray(decorators) : undefined; node.modifiers = modifiers ? createNodeArray(modifiers) : undefined; @@ -260,7 +261,7 @@ namespace ts { // Type members - export function createProperty(decorators: Decorator[], modifiers: Modifier[], name: string | PropertyName, questionToken: Node, type: TypeNode, initializer: Expression, location?: TextRange) { + export function createProperty(decorators: Decorator[], modifiers: Modifier[], name: string | PropertyName, questionToken: QuestionToken, type: TypeNode, initializer: Expression, location?: TextRange) { const node = createNode(SyntaxKind.PropertyDeclaration, location); node.decorators = decorators ? createNodeArray(decorators) : undefined; node.modifiers = modifiers ? createNodeArray(modifiers) : undefined; @@ -278,7 +279,7 @@ namespace ts { return node; } - export function createMethod(decorators: Decorator[], modifiers: Modifier[], asteriskToken: Node, name: string | PropertyName, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) { + export function createMethod(decorators: Decorator[], modifiers: Modifier[], asteriskToken: AsteriskToken, name: string | PropertyName, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) { const node = createNode(SyntaxKind.MethodDeclaration, location, flags); node.decorators = decorators ? createNodeArray(decorators) : undefined; node.modifiers = modifiers ? createNodeArray(modifiers) : undefined; @@ -381,7 +382,7 @@ namespace ts { return node; } - export function createBindingElement(propertyName: string | PropertyName, dotDotDotToken: Node, name: string | BindingName, initializer?: Expression, location?: TextRange) { + export function createBindingElement(propertyName: string | PropertyName, dotDotDotToken: DotDotDotToken, name: string | BindingName, initializer?: Expression, location?: TextRange) { const node = createNode(SyntaxKind.BindingElement, location); node.propertyName = typeof propertyName === "string" ? createIdentifier(propertyName) : propertyName; node.dotDotDotToken = dotDotDotToken; @@ -497,14 +498,14 @@ namespace ts { return node; } - export function createTaggedTemplate(tag: Expression, template: Template, location?: TextRange) { + export function createTaggedTemplate(tag: Expression, template: TemplateLiteral, location?: TextRange) { const node = createNode(SyntaxKind.TaggedTemplateExpression, location); node.tag = parenthesizeForAccess(tag); node.template = template; return node; } - export function updateTaggedTemplate(node: TaggedTemplateExpression, tag: Expression, template: Template) { + export function updateTaggedTemplate(node: TaggedTemplateExpression, tag: Expression, template: TemplateLiteral) { if (node.tag !== tag || node.template !== template) { return updateNode(createTaggedTemplate(tag, template, node), node); } @@ -524,7 +525,7 @@ namespace ts { return node; } - export function createFunctionExpression(asteriskToken: Node, name: string | Identifier, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) { + export function createFunctionExpression(asteriskToken: AsteriskToken, name: string | Identifier, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) { const node = createNode(SyntaxKind.FunctionExpression, location, flags); node.modifiers = undefined; node.asteriskToken = asteriskToken; @@ -543,13 +544,13 @@ namespace ts { return node; } - export function createArrowFunction(modifiers: Modifier[], typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, equalsGreaterThanToken: Node, body: ConciseBody, location?: TextRange, flags?: NodeFlags) { + export function createArrowFunction(modifiers: Modifier[], typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, equalsGreaterThanToken: EqualsGreaterThanToken, body: ConciseBody, location?: TextRange, flags?: NodeFlags) { const node = createNode(SyntaxKind.ArrowFunction, location, flags); node.modifiers = modifiers ? createNodeArray(modifiers) : undefined; node.typeParameters = typeParameters ? createNodeArray(typeParameters) : undefined; node.parameters = createNodeArray(parameters); node.type = type; - node.equalsGreaterThanToken = equalsGreaterThanToken || createNode(SyntaxKind.EqualsGreaterThanToken); + node.equalsGreaterThanToken = equalsGreaterThanToken || createToken(SyntaxKind.EqualsGreaterThanToken); node.body = parenthesizeConciseBody(body); return node; } @@ -613,7 +614,7 @@ namespace ts { return node; } - export function createPrefix(operator: SyntaxKind, operand: Expression, location?: TextRange) { + export function createPrefix(operator: PrefixUnaryOperator, operand: Expression, location?: TextRange) { const node = createNode(SyntaxKind.PrefixUnaryExpression, location); node.operator = operator; node.operand = parenthesizePrefixOperand(operand); @@ -627,7 +628,7 @@ namespace ts { return node; } - export function createPostfix(operand: Expression, operator: SyntaxKind, location?: TextRange) { + export function createPostfix(operand: Expression, operator: PostfixUnaryOperator, location?: TextRange) { const node = createNode(SyntaxKind.PostfixUnaryExpression, location); node.operand = parenthesizePostfixOperand(operand); node.operator = operator; @@ -641,8 +642,8 @@ namespace ts { return node; } - export function createBinary(left: Expression, operator: SyntaxKind | Node, right: Expression, location?: TextRange) { - const operatorToken = typeof operator === "number" ? createSynthesizedNode(operator) : operator; + export function createBinary(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression, location?: TextRange) { + const operatorToken = typeof operator === "number" ? createToken(operator) : operator; const operatorKind = operatorToken.kind; const node = createNode(SyntaxKind.BinaryExpression, location); node.left = parenthesizeBinaryOperand(operatorKind, left, /*isLeftSideOfBinary*/ true, /*leftOperand*/ undefined); @@ -658,7 +659,7 @@ namespace ts { return node; } - export function createConditional(condition: Expression, questionToken: Node, whenTrue: Expression, colonToken: Node, whenFalse: Expression, location?: TextRange) { + export function createConditional(condition: Expression, questionToken: QuestionToken, whenTrue: Expression, colonToken: ColonToken, whenFalse: Expression, location?: TextRange) { const node = createNode(SyntaxKind.ConditionalExpression, location); node.condition = condition; node.questionToken = questionToken; @@ -675,21 +676,21 @@ namespace ts { return node; } - export function createTemplateExpression(head: TemplateLiteralFragment, templateSpans: TemplateSpan[], location?: TextRange) { + export function createTemplateExpression(head: TemplateHead, templateSpans: TemplateSpan[], location?: TextRange) { const node = createNode(SyntaxKind.TemplateExpression, location); node.head = head; node.templateSpans = createNodeArray(templateSpans); return node; } - export function updateTemplateExpression(node: TemplateExpression, head: TemplateLiteralFragment, templateSpans: TemplateSpan[]) { + export function updateTemplateExpression(node: TemplateExpression, head: TemplateHead, templateSpans: TemplateSpan[]) { if (node.head !== head || node.templateSpans !== templateSpans) { return updateNode(createTemplateExpression(head, templateSpans, node), node); } return node; } - export function createYield(asteriskToken: Node, expression: Expression, location?: TextRange) { + export function createYield(asteriskToken: AsteriskToken, expression: Expression, location?: TextRange) { const node = createNode(SyntaxKind.YieldExpression, location); node.asteriskToken = asteriskToken; node.expression = expression; @@ -756,14 +757,14 @@ namespace ts { // Misc - export function createTemplateSpan(expression: Expression, literal: TemplateLiteralFragment, location?: TextRange) { + export function createTemplateSpan(expression: Expression, literal: TemplateMiddle | TemplateTail, location?: TextRange) { const node = createNode(SyntaxKind.TemplateSpan, location); node.expression = expression; node.literal = literal; return node; } - export function updateTemplateSpan(node: TemplateSpan, expression: Expression, literal: TemplateLiteralFragment) { + export function updateTemplateSpan(node: TemplateSpan, expression: Expression, literal: TemplateMiddle | TemplateTail) { if (node.expression !== expression || node.literal !== literal) { return updateNode(createTemplateSpan(expression, literal, node), node); } @@ -932,14 +933,14 @@ namespace ts { return node; } - export function updateForOf(node: ForInStatement, initializer: ForInitializer, expression: Expression, statement: Statement) { + export function updateForOf(node: ForOfStatement, initializer: ForInitializer, expression: Expression, statement: Statement) { if (node.initializer !== initializer || node.expression !== expression || node.statement !== statement) { return updateNode(createForOf(initializer, expression, statement, node), node); } return node; } - export function createContinue(label?: Identifier, location?: TextRange): BreakStatement { + export function createContinue(label?: Identifier, location?: TextRange): ContinueStatement { const node = createNode(SyntaxKind.ContinueStatement, location); if (label) { node.label = label; @@ -1065,7 +1066,7 @@ namespace ts { return node; } - export function createFunctionDeclaration(decorators: Decorator[], modifiers: Modifier[], asteriskToken: Node, name: string | Identifier, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) { + export function createFunctionDeclaration(decorators: Decorator[], modifiers: Modifier[], asteriskToken: AsteriskToken, name: string | Identifier, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) { const node = createNode(SyntaxKind.FunctionDeclaration, location, flags); node.decorators = decorators ? createNodeArray(decorators) : undefined; node.modifiers = modifiers ? createNodeArray(modifiers) : undefined; @@ -1560,7 +1561,7 @@ namespace ts { return createParameterDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, - createSynthesizedNode(SyntaxKind.DotDotDotToken), + createToken(SyntaxKind.DotDotDotToken), name, /*questionToken*/ undefined, /*type*/ undefined, @@ -1735,7 +1736,7 @@ namespace ts { export function createAwaiterHelper(externalHelpersModuleName: Identifier | undefined, hasLexicalArguments: boolean, promiseConstructor: EntityName | Expression, body: Block) { const generatorFunc = createFunctionExpression( - createNode(SyntaxKind.AsteriskToken), + createToken(SyntaxKind.AsteriskToken), /*name*/ undefined, /*typeParameters*/ undefined, /*parameters*/ [], diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9ff3f789984..55b58786e5d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -637,7 +637,7 @@ namespace ts { sourceFile.statements = parseList(ParsingContext.SourceElements, parseStatement); Debug.assert(token() === SyntaxKind.EndOfFileToken); - sourceFile.endOfFileToken = parseTokenNode(); + sourceFile.endOfFileToken = parseTokenNode(); setExternalModuleIndicator(sourceFile); @@ -1004,6 +1004,7 @@ namespace ts { return false; } + function parseOptionalToken(t: TKind): Token; function parseOptionalToken(t: SyntaxKind): Node { if (token() === t) { return parseTokenNode(); @@ -1011,6 +1012,7 @@ namespace ts { return undefined; } + function parseExpectedToken(t: TKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Token; function parseExpectedToken(t: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node { return parseOptionalToken(t) || createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0); @@ -1047,7 +1049,7 @@ namespace ts { } // note: this function creates only node - function createNode(kind: SyntaxKind, pos?: number): Node | Token | Identifier { + function createNode(kind: TKind, pos?: number): Node | Token | Identifier { nodeCount++; if (!(pos >= 0)) { pos = scanner.getStartPos(); @@ -1920,7 +1922,7 @@ namespace ts { function parseTemplateExpression(): TemplateExpression { const template = createNode(SyntaxKind.TemplateExpression); - template.head = parseTemplateLiteralFragment(); + template.head = parseTemplateHead(); Debug.assert(template.head.kind === SyntaxKind.TemplateHead, "Template head has wrong token kind"); const templateSpans = createNodeArray(); @@ -1940,14 +1942,13 @@ namespace ts { const span = createNode(SyntaxKind.TemplateSpan); span.expression = allowInAnd(parseExpression); - let literal: TemplateLiteralFragment; - + let literal: TemplateMiddle | TemplateTail; if (token() === SyntaxKind.CloseBraceToken) { reScanTemplateToken(); - literal = parseTemplateLiteralFragment(); + literal = parseTemplateMiddleOrTemplateTail(); } else { - literal = parseExpectedToken(SyntaxKind.TemplateTail, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken)); + literal = parseExpectedToken(SyntaxKind.TemplateTail, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken)); } span.literal = literal; @@ -1958,8 +1959,16 @@ namespace ts { return parseLiteralLikeNode(token(), internName); } - function parseTemplateLiteralFragment(): TemplateLiteralFragment { - return parseLiteralLikeNode(token(), /*internName*/ false); + function parseTemplateHead(): TemplateHead { + const fragment = parseLiteralLikeNode(token(), /*internName*/ false); + Debug.assert(fragment.kind === SyntaxKind.TemplateHead, "Template head has wrong token kind"); + return fragment; + } + + function parseTemplateMiddleOrTemplateTail(): TemplateMiddle | TemplateTail { + const fragment = parseLiteralLikeNode(token(), /*internName*/ false); + Debug.assert(fragment.kind === SyntaxKind.TemplateMiddle || fragment.kind === SyntaxKind.TemplateTail, "Template fragment has wrong token kind"); + return fragment; } function parseLiteralLikeNode(kind: SyntaxKind, internName: boolean): LiteralLikeNode { @@ -2719,7 +2728,7 @@ namespace ts { } let expr = parseAssignmentExpressionOrHigher(); - let operatorToken: Node; + let operatorToken: BinaryOperatorToken; while ((operatorToken = parseOptionalToken(SyntaxKind.CommaToken))) { expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher()); } @@ -2812,7 +2821,7 @@ namespace ts { // Note: we call reScanGreaterToken so that we get an appropriately merged token // for cases like > > = becoming >>= if (isLeftHandSideExpression(expr) && isAssignmentOperator(reScanGreaterToken())) { - return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher()); + return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher()); } // It wasn't an assignment or a lambda. This is a conditional expression: @@ -3247,7 +3256,7 @@ namespace ts { } } else { - leftOperand = makeBinaryExpression(leftOperand, parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence)); + leftOperand = makeBinaryExpression(leftOperand, parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence)); } } @@ -3307,7 +3316,7 @@ namespace ts { return -1; } - function makeBinaryExpression(left: Expression, operatorToken: Node, right: Expression): BinaryExpression { + function makeBinaryExpression(left: Expression, operatorToken: BinaryOperatorToken, right: Expression): BinaryExpression { const node = createNode(SyntaxKind.BinaryExpression, left.pos); node.left = left; node.operatorToken = operatorToken; @@ -3324,7 +3333,7 @@ namespace ts { function parsePrefixUnaryExpression() { const node = createNode(SyntaxKind.PrefixUnaryExpression); - node.operator = token(); + node.operator = token(); nextToken(); node.operand = parseSimpleUnaryExpression(); @@ -3511,7 +3520,7 @@ namespace ts { function parseIncrementExpression(): IncrementExpression { if (token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) { const node = createNode(SyntaxKind.PrefixUnaryExpression); - node.operator = token(); + node.operator = token(); nextToken(); node.operand = parseLeftHandSideExpressionOrHigher(); return finishNode(node); @@ -3527,7 +3536,7 @@ namespace ts { if ((token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) && !scanner.hasPrecedingLineBreak()) { const node = createNode(SyntaxKind.PostfixUnaryExpression, expression.pos); node.operand = expression; - node.operator = token(); + node.operator = token(); nextToken(); return finishNode(node); } @@ -3700,7 +3709,7 @@ namespace ts { badNode.end = invalidElement.end; badNode.left = result; badNode.right = invalidElement; - badNode.operatorToken = createMissingNode(SyntaxKind.CommaToken, /*reportAtCurrentPosition*/ false, /*diagnosticMessage*/ undefined); + badNode.operatorToken = createMissingNode(SyntaxKind.CommaToken, /*reportAtCurrentPosition*/ false, /*diagnosticMessage*/ undefined); badNode.operatorToken.pos = badNode.operatorToken.end = badNode.right.pos; return badNode; } @@ -3836,7 +3845,7 @@ namespace ts { if (token() === SyntaxKind.EqualsToken) { switch (scanJsxAttributeValue()) { case SyntaxKind.StringLiteral: - node.initializer = parseLiteralNode(); + node.initializer = parseLiteralNode(); break; default: node.initializer = parseJsxExpression(/*inExpressionContext*/ true); @@ -3921,7 +3930,7 @@ namespace ts { const tagExpression = createNode(SyntaxKind.TaggedTemplateExpression, expression.pos); tagExpression.tag = expression; tagExpression.template = token() === SyntaxKind.NoSubstitutionTemplateLiteral - ? parseLiteralNode() + ? parseLiteralNode() : parseTemplateExpression(); expression = finishNode(tagExpression); continue; @@ -4959,7 +4968,7 @@ namespace ts { return addJSDocComment(finishNode(node)); } - function parseMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: NodeArray, asteriskToken: Node, name: PropertyName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { + function parseMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: NodeArray, asteriskToken: AsteriskToken, name: PropertyName, questionToken: QuestionToken, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { const method = createNode(SyntaxKind.MethodDeclaration, fullStart); method.decorators = decorators; method.modifiers = modifiers; @@ -4973,7 +4982,7 @@ namespace ts { return addJSDocComment(finishNode(method)); } - function parsePropertyDeclaration(fullStart: number, decorators: NodeArray, modifiers: NodeArray, name: PropertyName, questionToken: Node): ClassElement { + function parsePropertyDeclaration(fullStart: number, decorators: NodeArray, modifiers: NodeArray, name: PropertyName, questionToken: QuestionToken): ClassElement { const property = createNode(SyntaxKind.PropertyDeclaration, fullStart); property.decorators = decorators; property.modifiers = modifiers; @@ -5395,7 +5404,7 @@ namespace ts { node.flags |= flags; node.name = parseIdentifier(); node.body = parseOptional(SyntaxKind.DotToken) - ? parseModuleOrNamespaceDeclaration(getNodePos(), /*decorators*/ undefined, /*modifiers*/ undefined, NodeFlags.NestedNamespace | namespaceFlag) + ? parseModuleOrNamespaceDeclaration(getNodePos(), /*decorators*/ undefined, /*modifiers*/ undefined, NodeFlags.NestedNamespace | namespaceFlag) : parseModuleBlock(); return addJSDocComment(finishNode(node)); } @@ -5574,8 +5583,10 @@ namespace ts { return finishNode(namespaceImport); } + function parseNamedImportsOrExports(kind: SyntaxKind.NamedImports): NamedImports; + function parseNamedImportsOrExports(kind: SyntaxKind.NamedExports): NamedExports; function parseNamedImportsOrExports(kind: SyntaxKind): NamedImportsOrExports { - const node = createNode(kind); + const node = createNode(kind); // NamedImports: // { } @@ -5585,7 +5596,7 @@ namespace ts { // ImportsList: // ImportSpecifier // ImportsList, ImportSpecifier - node.elements = parseBracketedList(ParsingContext.ImportOrExportSpecifiers, + node.elements = | NodeArray>parseBracketedList(ParsingContext.ImportOrExportSpecifiers, kind === SyntaxKind.NamedImports ? parseImportSpecifier : parseExportSpecifier, SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken); return finishNode(node); @@ -5969,14 +5980,15 @@ namespace ts { const parameter = createNode(SyntaxKind.Parameter); parameter.type = parseJSDocType(); if (parseOptional(SyntaxKind.EqualsToken)) { - parameter.questionToken = createNode(SyntaxKind.EqualsToken); + // TODO(rbuckton): Can this be changed to SyntaxKind.QuestionToken? + parameter.questionToken = createNode(SyntaxKind.EqualsToken); } return finishNode(parameter); } function parseJSDocTypeReference(): JSDocTypeReference { const result = createNode(SyntaxKind.JSDocTypeReference); - result.name = parseSimplePropertyName(); + result.name = parseSimplePropertyName(); if (token() === SyntaxKind.LessThanToken) { result.typeArguments = parseTypeArguments(); @@ -6304,7 +6316,7 @@ namespace ts { function parseTag(indent: number) { Debug.assert(token() === SyntaxKind.AtToken); - const atToken = createNode(SyntaxKind.AtToken, scanner.getTokenPos()); + const atToken = createNode(SyntaxKind.AtToken, scanner.getTokenPos()); atToken.end = scanner.getTextPos(); nextJSDocToken(); @@ -6410,7 +6422,7 @@ namespace ts { return comments; } - function parseUnknownTag(atToken: Node, tagName: Identifier) { + function parseUnknownTag(atToken: AtToken, tagName: Identifier) { const result = createNode(SyntaxKind.JSDocTag, atToken.pos); result.atToken = atToken; result.tagName = tagName; @@ -6440,7 +6452,7 @@ namespace ts { }); } - function parseParamTag(atToken: Node, tagName: Identifier) { + function parseParamTag(atToken: AtToken, tagName: Identifier) { let typeExpression = tryParseTypeExpression(); skipWhitespace(); @@ -6491,7 +6503,7 @@ namespace ts { return finishNode(result); } - function parseReturnTag(atToken: Node, tagName: Identifier): JSDocReturnTag { + function parseReturnTag(atToken: AtToken, tagName: Identifier): JSDocReturnTag { if (forEach(tags, t => t.kind === SyntaxKind.JSDocReturnTag)) { parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text); } @@ -6503,7 +6515,7 @@ namespace ts { return finishNode(result); } - function parseTypeTag(atToken: Node, tagName: Identifier): JSDocTypeTag { + function parseTypeTag(atToken: AtToken, tagName: Identifier): JSDocTypeTag { if (forEach(tags, t => t.kind === SyntaxKind.JSDocTypeTag)) { parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text); } @@ -6515,7 +6527,7 @@ namespace ts { return finishNode(result); } - function parsePropertyTag(atToken: Node, tagName: Identifier): JSDocPropertyTag { + function parsePropertyTag(atToken: AtToken, tagName: Identifier): JSDocPropertyTag { const typeExpression = tryParseTypeExpression(); skipWhitespace(); const name = parseJSDocIdentifierName(); @@ -6533,7 +6545,7 @@ namespace ts { return finishNode(result); } - function parseTypedefTag(atToken: Node, tagName: Identifier): JSDocTypedefTag { + function parseTypedefTag(atToken: AtToken, tagName: Identifier): JSDocTypedefTag { const typeExpression = tryParseTypeExpression(); skipWhitespace(); @@ -6555,7 +6567,7 @@ namespace ts { } } if (!typedefTag.jsDocTypeLiteral) { - typedefTag.jsDocTypeLiteral = typeExpression.type; + typedefTag.jsDocTypeLiteral = typeExpression.type; } } else { @@ -6607,7 +6619,7 @@ namespace ts { function tryParseChildTag(parentTag: JSDocTypeLiteral): boolean { Debug.assert(token() === SyntaxKind.AtToken); - const atToken = createNode(SyntaxKind.AtToken, scanner.getStartPos()); + const atToken = createNode(SyntaxKind.AtToken, scanner.getStartPos()); atToken.end = scanner.getTextPos(); nextJSDocToken(); @@ -6637,7 +6649,7 @@ namespace ts { return false; } - function parseTemplateTag(atToken: Node, tagName: Identifier): JSDocTemplateTag { + function parseTemplateTag(atToken: AtToken, tagName: Identifier): JSDocTemplateTag { if (forEach(tags, t => t.kind === SyntaxKind.JSDocTemplateTag)) { parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text); } diff --git a/src/compiler/transformers/destructuring.ts b/src/compiler/transformers/destructuring.ts index 3bfa778cf9b..c7219866df7 100644 --- a/src/compiler/transformers/destructuring.ts +++ b/src/compiler/transformers/destructuring.ts @@ -220,7 +220,7 @@ namespace ts { function flattenDestructuring( context: TransformationContext, - root: BindingElement | BinaryExpression, + root: VariableDeclaration | ParameterDeclaration | BindingElement | BinaryExpression, value: Expression, location: TextRange, emitAssignment: (name: Identifier, value: Expression, location: TextRange, original: Node) => void, @@ -320,7 +320,7 @@ namespace ts { } } - function emitBindingElement(target: BindingElement, value: Expression) { + function emitBindingElement(target: VariableDeclaration | ParameterDeclaration | BindingElement, value: Expression) { // Any temporary assignments needed to emit target = value should point to target const initializer = visitor ? visitNode(target.initializer, visitor, isExpression) : target.initializer; if (initializer) { diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 12ce9d53fd0..3b4b50bbca3 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -982,7 +982,7 @@ namespace ts { if (statementOffset < ctorStatements.length) { firstStatement = ctorStatements[statementOffset]; - if (firstStatement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((firstStatement as ExpressionStatement).expression)) { + if (firstStatement.kind === SyntaxKind.ExpressionStatement && isSuperCall((firstStatement as ExpressionStatement).expression)) { const superCall = (firstStatement as ExpressionStatement).expression as CallExpression; superCallExpression = setOriginalNode( saveStateAndInvoke(superCall, visitImmediateSuperCallInBody), @@ -3197,7 +3197,7 @@ namespace ts { * @param node The declaration. * @param allowComments Allow comments for the name. */ - function getDeclarationName(node: DeclarationStatement | ClassExpression, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: EmitFlags) { + function getDeclarationName(node: ClassDeclaration | ClassExpression | FunctionDeclaration, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: EmitFlags) { if (node.name && !isGeneratedIdentifier(node.name)) { const name = getMutableClone(node.name); emitFlags |= getEmitFlags(node.name); diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index 581ea8438eb..610b5f82d5b 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -528,7 +528,7 @@ namespace ts { * * @param node The node to visit. */ - function visitAccessorDeclaration(node: GetAccessorDeclaration) { + function visitAccessorDeclaration(node: AccessorDeclaration) { const savedInGeneratorFunctionBody = inGeneratorFunctionBody; const savedInStatementContainingYield = inStatementContainingYield; inGeneratorFunctionBody = false; @@ -660,12 +660,12 @@ namespace ts { } } - function isCompoundAssignment(kind: SyntaxKind) { + function isCompoundAssignment(kind: BinaryOperator): kind is CompoundAssignmentOperator { return kind >= SyntaxKind.FirstCompoundAssignment && kind <= SyntaxKind.LastCompoundAssignment; } - function getOperatorForCompoundAssignment(kind: SyntaxKind) { + function getOperatorForCompoundAssignment(kind: CompoundAssignmentOperator): BitwiseOperatorOrHigher { switch (kind) { case SyntaxKind.PlusEqualsToken: return SyntaxKind.PlusToken; case SyntaxKind.MinusEqualsToken: return SyntaxKind.MinusToken; diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 4003e8ce78b..de2e3c60188 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -600,7 +600,7 @@ namespace ts { } else { statements.push( - createExportStatement(node.name, setEmitFlags(getSynthesizedClone(node.name), EmitFlags.LocalName), /*location*/ node) + createExportStatement(node.name, setEmitFlags(getSynthesizedClone(node.name), EmitFlags.LocalName), /*location*/ node) ); } } @@ -796,7 +796,7 @@ namespace ts { addVarForExportedEnumOrNamespaceDeclaration(statements, original); } - addExportMemberAssignments(statements, original.name); + addExportMemberAssignments(statements, original.name); return statements; } @@ -819,7 +819,7 @@ namespace ts { } function getDeclarationName(node: DeclarationStatement) { - return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node); + return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node); } function onEmitNode(emitContext: EmitContext, node: Node, emitCallback: (emitContext: EmitContext, node: Node) => void): void { @@ -918,7 +918,7 @@ namespace ts { if (node.kind === SyntaxKind.PostfixUnaryExpression) { transformedUnaryExpression = createBinary( operand, - createNode(operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusEqualsToken : SyntaxKind.MinusEqualsToken), + createToken(operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusEqualsToken : SyntaxKind.MinusEqualsToken), createLiteral(1), /*location*/ node ); diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index a160def6941..c48dcfcba74 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -1201,7 +1201,7 @@ namespace ts { * @param node The declaration statement. */ function getDeclarationName(node: DeclarationStatement) { - return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node); + return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node); } function addExportStarFunction(statements: Statement[], localNames: Identifier) { diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 56f7dc278ac..085a4aa94fa 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -989,7 +989,7 @@ namespace ts { } const statement = statements[index]; - if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { + if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCall((statement).expression)) { result.push(visitNode(statement, visitor, isStatement)); return index + 1; } @@ -3098,7 +3098,7 @@ namespace ts { return createStatement(expression, /*location*/ undefined); } - function addExportMemberAssignment(statements: Statement[], node: DeclarationStatement) { + function addExportMemberAssignment(statements: Statement[], node: ClassDeclaration | FunctionDeclaration) { const expression = createAssignment( getExportName(node), getLocalName(node, /*noSourceMaps*/ true) @@ -3176,7 +3176,7 @@ namespace ts { * @param noSourceMaps A value indicating whether source maps may not be emitted for the name. * @param allowComments A value indicating whether comments may be emitted for the name. */ - function getLocalName(node: DeclarationStatement | ClassExpression, noSourceMaps?: boolean, allowComments?: boolean) { + function getLocalName(node: FunctionDeclaration | ClassDeclaration | ClassExpression | ModuleDeclaration | EnumDeclaration, noSourceMaps?: boolean, allowComments?: boolean) { return getDeclarationName(node, allowComments, !noSourceMaps, EmitFlags.LocalName); } @@ -3190,7 +3190,7 @@ namespace ts { * @param noSourceMaps A value indicating whether source maps may not be emitted for the name. * @param allowComments A value indicating whether comments may be emitted for the name. */ - function getExportName(node: DeclarationStatement | ClassExpression, noSourceMaps?: boolean, allowComments?: boolean) { + function getExportName(node: FunctionDeclaration | ClassDeclaration | ClassExpression | ModuleDeclaration | EnumDeclaration, noSourceMaps?: boolean, allowComments?: boolean) { if (isNamespaceExport(node)) { return getNamespaceMemberName(getDeclarationName(node), allowComments, !noSourceMaps); } @@ -3206,9 +3206,9 @@ namespace ts { * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. * @param emitFlags Additional NodeEmitFlags to specify for the name. */ - function getDeclarationName(node: DeclarationStatement | ClassExpression, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: EmitFlags) { + function getDeclarationName(node: FunctionDeclaration | ClassDeclaration | ClassExpression | ModuleDeclaration | EnumDeclaration, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: EmitFlags) { if (node.name) { - const name = getMutableClone(node.name); + const name = getMutableClone(node.name); emitFlags |= getEmitFlags(node.name); if (!allowSourceMaps) { emitFlags |= EmitFlags.NoSourceMap; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1b180c923c1..419971a8654 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -467,8 +467,6 @@ namespace ts { TypeExcludesFlags = YieldContext | AwaitContext, } - export type ModifiersArray = NodeArray; - export const enum ModifierFlags { None = 0, Export = 1 << 0, // Declarations @@ -532,21 +530,34 @@ namespace ts { hasTrailingComma?: boolean; } - export interface Token extends Node { - __tokenTag: any; + export interface Token extends Node { + kind: TKind; } - // @kind(SyntaxKind.AbstractKeyword) - // @kind(SyntaxKind.AsyncKeyword) - // @kind(SyntaxKind.ConstKeyword) - // @kind(SyntaxKind.DeclareKeyword) - // @kind(SyntaxKind.DefaultKeyword) - // @kind(SyntaxKind.ExportKeyword) - // @kind(SyntaxKind.PublicKeyword) - // @kind(SyntaxKind.PrivateKeyword) - // @kind(SyntaxKind.ProtectedKeyword) - // @kind(SyntaxKind.StaticKeyword) - export interface Modifier extends Token { } + export type DotDotDotToken = Token; + export type QuestionToken = Token; + export type ColonToken = Token; + export type EqualsToken = Token; + export type AsteriskToken = Token; + export type EqualsGreaterThanToken = Token; + export type EndOfFileToken = Token; + export type AtToken = Token; + + export type Modifier + = Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + ; + + export type ModifiersArray = NodeArray; /*@internal*/ export const enum GeneratedIdentifierKind { @@ -557,8 +568,8 @@ namespace ts { Node, // Unique name based on the node in the 'original' property. } - // @kind(SyntaxKind.Identifier) export interface Identifier extends PrimaryExpression { + kind: SyntaxKind.Identifier; text: string; // Text of identifier (with escapes converted to characters) originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later /*@internal*/ autoGenerateKind?: GeneratedIdentifierKind; // Specifies whether to auto-generate the text for an identifier. @@ -570,9 +581,8 @@ namespace ts { resolvedSymbol: Symbol; } - // @kind(SyntaxKind.QualifiedName) export interface QualifiedName extends Node { - // Must have same layout as PropertyAccess + kind: SyntaxKind.QualifiedName; left: EntityName; right: Identifier; } @@ -589,21 +599,21 @@ namespace ts { } export interface DeclarationStatement extends Declaration, Statement { - name?: Identifier; + name?: Identifier | LiteralExpression; } - // @kind(SyntaxKind.ComputedPropertyName) export interface ComputedPropertyName extends Node { + kind: SyntaxKind.ComputedPropertyName; expression: Expression; } - // @kind(SyntaxKind.Decorator) export interface Decorator extends Node { + kind: SyntaxKind.Decorator; expression: LeftHandSideExpression; } - // @kind(SyntaxKind.TypeParameter) export interface TypeParameterDeclaration extends Declaration { + kind: SyntaxKind.TypeParameter; name: Identifier; constraint?: TypeNode; @@ -618,55 +628,57 @@ namespace ts { type?: TypeNode; } - // @kind(SyntaxKind.CallSignature) - export interface CallSignatureDeclaration extends SignatureDeclaration, TypeElement { } + export interface CallSignatureDeclaration extends SignatureDeclaration, TypeElement { + kind: SyntaxKind.CallSignature; + } - // @kind(SyntaxKind.ConstructSignature) - export interface ConstructSignatureDeclaration extends SignatureDeclaration, TypeElement { } + export interface ConstructSignatureDeclaration extends SignatureDeclaration, TypeElement { + kind: SyntaxKind.ConstructSignature; + } export type BindingName = Identifier | BindingPattern; - // @kind(SyntaxKind.VariableDeclaration) export interface VariableDeclaration extends Declaration { + kind: SyntaxKind.VariableDeclaration; parent?: VariableDeclarationList; name: BindingName; // Declared variable name type?: TypeNode; // Optional type annotation initializer?: Expression; // Optional initializer } - // @kind(SyntaxKind.VariableDeclarationList) export interface VariableDeclarationList extends Node { + kind: SyntaxKind.VariableDeclarationList; declarations: NodeArray; } - // @kind(SyntaxKind.Parameter) export interface ParameterDeclaration extends Declaration { - dotDotDotToken?: Node; // Present on rest parameter + kind: SyntaxKind.Parameter; + dotDotDotToken?: DotDotDotToken; // Present on rest parameter name: BindingName; // Declared parameter name - questionToken?: Node; // Present on optional parameter + questionToken?: QuestionToken; // Present on optional parameter type?: TypeNode; // Optional type annotation initializer?: Expression; // Optional initializer } - // @kind(SyntaxKind.BindingElement) export interface BindingElement extends Declaration { + kind: SyntaxKind.BindingElement; propertyName?: PropertyName; // Binding property name (in object binding pattern) - dotDotDotToken?: Node; // Present on rest binding element + dotDotDotToken?: DotDotDotToken; // Present on rest binding element name: BindingName; // Declared binding element name initializer?: Expression; // Optional initializer } - // @kind(SyntaxKind.PropertySignature) export interface PropertySignature extends TypeElement { + kind: SyntaxKind.PropertySignature | SyntaxKind.JSDocRecordMember; name: PropertyName; // Declared property name - questionToken?: Node; // Present on optional property + questionToken?: QuestionToken; // Present on optional property type?: TypeNode; // Optional type annotation initializer?: Expression; // Optional initializer } - // @kind(SyntaxKind.PropertyDeclaration) export interface PropertyDeclaration extends ClassElement { - questionToken?: Node; // Present for use with reporting a grammar error + kind: SyntaxKind.PropertyDeclaration; + questionToken?: QuestionToken; // Present for use with reporting a grammar error name: PropertyName; type?: TypeNode; initializer?: Expression; // Optional initializer @@ -675,25 +687,24 @@ namespace ts { export interface ObjectLiteralElement extends Declaration { _objectLiteralBrandBrand: any; name?: PropertyName; - } + } export type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | MethodDeclaration | AccessorDeclaration; - // @kind(SyntaxKind.PropertyAssignment) export interface PropertyAssignment extends ObjectLiteralElement { - _propertyAssignmentBrand: any; + kind: SyntaxKind.PropertyAssignment; name: PropertyName; - questionToken?: Node; + questionToken?: QuestionToken; initializer: Expression; } - // @kind(SyntaxKind.ShorthandPropertyAssignment) export interface ShorthandPropertyAssignment extends ObjectLiteralElement { + kind: SyntaxKind.ShorthandPropertyAssignment; name: Identifier; - questionToken?: Node; + questionToken?: QuestionToken; // used when ObjectLiteralExpression is used in ObjectAssignmentPattern // it is grammar error to appear in actual object initializer - equalsToken?: Node; + equalsToken?: Token; objectAssignmentInitializer?: Expression; } @@ -707,9 +718,9 @@ namespace ts { // SyntaxKind.JSDocPropertyTag export interface VariableLikeDeclaration extends Declaration { propertyName?: PropertyName; - dotDotDotToken?: Node; + dotDotDotToken?: DotDotDotToken; name: DeclarationName; - questionToken?: Node; + questionToken?: QuestionToken; type?: TypeNode; initializer?: Expression; } @@ -722,15 +733,15 @@ namespace ts { elements: NodeArray; } - // @kind(SyntaxKind.ObjectBindingPattern) export interface ObjectBindingPattern extends BindingPattern { + kind: SyntaxKind.ObjectBindingPattern; elements: NodeArray; } export type ArrayBindingElement = BindingElement | OmittedExpression; - // @kind(SyntaxKind.ArrayBindingPattern) export interface ArrayBindingPattern extends BindingPattern { + kind: SyntaxKind.ArrayBindingPattern; elements: NodeArray; } @@ -745,19 +756,19 @@ namespace ts { export interface FunctionLikeDeclaration extends SignatureDeclaration { _functionLikeDeclarationBrand: any; - asteriskToken?: Node; - questionToken?: Node; + asteriskToken?: AsteriskToken; + questionToken?: QuestionToken; body?: Block | Expression; } - // @kind(SyntaxKind.FunctionDeclaration) export interface FunctionDeclaration extends FunctionLikeDeclaration, DeclarationStatement { + kind: SyntaxKind.FunctionDeclaration; name?: Identifier; body?: FunctionBody; } - // @kind(SyntaxKind.MethodSignature) export interface MethodSignature extends SignatureDeclaration, TypeElement { + kind: SyntaxKind.MethodSignature; name: PropertyName; } @@ -770,126 +781,132 @@ namespace ts { // Because of this, it may be necessary to determine what sort of MethodDeclaration you have // at later stages of the compiler pipeline. In that case, you can either check the parent kind // of the method, or use helpers like isObjectLiteralMethodDeclaration - // @kind(SyntaxKind.MethodDeclaration) export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { + kind: SyntaxKind.MethodDeclaration; name: PropertyName; body?: FunctionBody; } - // @kind(SyntaxKind.Constructor) export interface ConstructorDeclaration extends FunctionLikeDeclaration, ClassElement { + kind: SyntaxKind.Constructor; body?: FunctionBody; } // For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. - // @kind(SyntaxKind.SemicolonClassElement) export interface SemicolonClassElement extends ClassElement { - _semicolonClassElementBrand: any; + kind: SyntaxKind.SemicolonClassElement; } - // See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a + // See the comment on MethodDeclaration for the intuition behind GetAccessorDeclaration being a // ClassElement and an ObjectLiteralElement. - export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { - _accessorDeclarationBrand: any; + export interface GetAccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { + kind: SyntaxKind.GetAccessor; name: PropertyName; body: FunctionBody; } - // @kind(SyntaxKind.GetAccessor) - export interface GetAccessorDeclaration extends AccessorDeclaration { } - - // @kind(SyntaxKind.SetAccessor) - export interface SetAccessorDeclaration extends AccessorDeclaration { } - - // @kind(SyntaxKind.IndexSignature) - export interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement, TypeElement { - _indexSignatureDeclarationBrand: any; + // See the comment on MethodDeclaration for the intuition behind SetAccessorDeclaration being a + // ClassElement and an ObjectLiteralElement. + export interface SetAccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { + kind: SyntaxKind.SetAccessor; + name: PropertyName; + body: FunctionBody; + } + + export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; + + export interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement, TypeElement { + kind: SyntaxKind.IndexSignature; } - // @kind(SyntaxKind.AnyKeyword) - // @kind(SyntaxKind.NumberKeyword) - // @kind(SyntaxKind.BooleanKeyword) - // @kind(SyntaxKind.StringKeyword) - // @kind(SyntaxKind.SymbolKeyword) - // @kind(SyntaxKind.VoidKeyword) export interface TypeNode extends Node { _typeNodeBrand: any; } - // @kind(SyntaxKind.ThisType) + export interface KeywordTypeNode extends TypeNode { + kind: SyntaxKind.AnyKeyword + | SyntaxKind.NumberKeyword + | SyntaxKind.BooleanKeyword + | SyntaxKind.StringKeyword + | SyntaxKind.SymbolKeyword + | SyntaxKind.VoidKeyword; + } + export interface ThisTypeNode extends TypeNode { - _thisTypeNodeBrand: any; + kind: SyntaxKind.ThisType; } export interface FunctionOrConstructorTypeNode extends TypeNode, SignatureDeclaration { - _functionOrConstructorTypeNodeBrand: any; + kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; } - // @kind(SyntaxKind.FunctionType) - export interface FunctionTypeNode extends FunctionOrConstructorTypeNode { } + export interface FunctionTypeNode extends FunctionOrConstructorTypeNode { + kind: SyntaxKind.FunctionType; + } - // @kind(SyntaxKind.ConstructorType) - export interface ConstructorTypeNode extends FunctionOrConstructorTypeNode { } + export interface ConstructorTypeNode extends FunctionOrConstructorTypeNode { + kind: SyntaxKind.ConstructorType; + } - // @kind(SyntaxKind.TypeReference) export interface TypeReferenceNode extends TypeNode { + kind: SyntaxKind.TypeReference; typeName: EntityName; typeArguments?: NodeArray; } - // @kind(SyntaxKind.TypePredicate) export interface TypePredicateNode extends TypeNode { + kind: SyntaxKind.TypePredicate; parameterName: Identifier | ThisTypeNode; type: TypeNode; } - // @kind(SyntaxKind.TypeQuery) export interface TypeQueryNode extends TypeNode { + kind: SyntaxKind.TypeQuery; exprName: EntityName; } // A TypeLiteral is the declaration node for an anonymous symbol. - // @kind(SyntaxKind.TypeLiteral) export interface TypeLiteralNode extends TypeNode, Declaration { + kind: SyntaxKind.TypeLiteral; members: NodeArray; } - // @kind(SyntaxKind.ArrayType) export interface ArrayTypeNode extends TypeNode { + kind: SyntaxKind.ArrayType; elementType: TypeNode; } - // @kind(SyntaxKind.TupleType) export interface TupleTypeNode extends TypeNode { + kind: SyntaxKind.TupleType; elementTypes: NodeArray; } export interface UnionOrIntersectionTypeNode extends TypeNode { + kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType; types: NodeArray; } - // @kind(SyntaxKind.UnionType) - export interface UnionTypeNode extends UnionOrIntersectionTypeNode { } + export interface UnionTypeNode extends UnionOrIntersectionTypeNode { + kind: SyntaxKind.UnionType; + } - // @kind(SyntaxKind.IntersectionType) - export interface IntersectionTypeNode extends UnionOrIntersectionTypeNode { } + export interface IntersectionTypeNode extends UnionOrIntersectionTypeNode { + kind: SyntaxKind.IntersectionType; + } - // @kind(SyntaxKind.ParenthesizedType) export interface ParenthesizedTypeNode extends TypeNode { + kind: SyntaxKind.ParenthesizedType; type: TypeNode; } - // @kind(SyntaxKind.StringLiteralType) export interface LiteralTypeNode extends TypeNode { - _stringLiteralTypeBrand: any; + kind: SyntaxKind.LiteralType; literal: Expression; } - // @kind(SyntaxKind.StringLiteral) export interface StringLiteral extends LiteralExpression { - _stringLiteralBrand: any; - /* @internal */ - textSourceNode?: Identifier | StringLiteral; // Allows a StringLiteral to get its text from another node (used by transforms). + kind: SyntaxKind.StringLiteral; + /* @internal */ textSourceNode?: Identifier | StringLiteral; // Allows a StringLiteral to get its text from another node (used by transforms). } // Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing. @@ -904,16 +921,15 @@ namespace ts { contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution } - // @kind(SyntaxKind.OmittedExpression) export interface OmittedExpression extends Expression { - _omittedExpressionBrand: any; + kind: SyntaxKind.OmittedExpression; } // Represents an expression that is elided as part of a transformation to emit comments on a // not-emitted node. The 'expression' property of a NotEmittedExpression should be emitted. // @internal - // @kind(SyntaxKind.NotEmittedExpression) export interface PartiallyEmittedExpression extends LeftHandSideExpression { + kind: SyntaxKind.PartiallyEmittedExpression; expression: Expression; } @@ -925,16 +941,33 @@ namespace ts { _incrementExpressionBrand: any; } - // @kind(SyntaxKind.PrefixUnaryExpression) + // see: https://tc39.github.io/ecma262/#prod-UpdateExpression + // see: https://tc39.github.io/ecma262/#prod-UnaryExpression + export type PrefixUnaryOperator + = SyntaxKind.PlusPlusToken + | SyntaxKind.MinusMinusToken + | SyntaxKind.PlusToken + | SyntaxKind.MinusToken + | SyntaxKind.TildeToken + | SyntaxKind.ExclamationToken + ; + export interface PrefixUnaryExpression extends IncrementExpression { - operator: SyntaxKind; + kind: SyntaxKind.PrefixUnaryExpression; + operator: PrefixUnaryOperator; operand: UnaryExpression; } - // @kind(SyntaxKind.PostfixUnaryExpression) + // see: https://tc39.github.io/ecma262/#prod-UpdateExpression + export type PostfixUnaryOperator + = SyntaxKind.PlusPlusToken + | SyntaxKind.MinusMinusToken + ; + export interface PostfixUnaryExpression extends IncrementExpression { + kind: SyntaxKind.PostfixUnaryExpression; operand: LeftHandSideExpression; - operator: SyntaxKind; + operator: PostfixUnaryOperator; } export interface PostfixExpression extends UnaryExpression { @@ -949,73 +982,226 @@ namespace ts { _memberExpressionBrand: any; } - // @kind(SyntaxKind.TrueKeyword) - // @kind(SyntaxKind.FalseKeyword) - // @kind(SyntaxKind.NullKeyword) - // @kind(SyntaxKind.ThisKeyword) - // @kind(SyntaxKind.SuperKeyword) export interface PrimaryExpression extends MemberExpression { _primaryExpressionBrand: any; } - // @kind(SyntaxKind.DeleteExpression) + export interface NullLiteral extends PrimaryExpression { + kind: SyntaxKind.NullKeyword; + } + + export interface BooleanLiteral extends PrimaryExpression { + kind: SyntaxKind.TrueKeyword | SyntaxKind.FalseKeyword; + } + + export interface ThisExpression extends PrimaryExpression { + kind: SyntaxKind.ThisKeyword; + } + + export interface SuperExpression extends PrimaryExpression { + kind: SyntaxKind.SuperKeyword; + } + export interface DeleteExpression extends UnaryExpression { + kind: SyntaxKind.DeleteExpression; expression: UnaryExpression; } - // @kind(SyntaxKind.TypeOfExpression) export interface TypeOfExpression extends UnaryExpression { + kind: SyntaxKind.TypeOfExpression; expression: UnaryExpression; } - // @kind(SyntaxKind.VoidExpression) export interface VoidExpression extends UnaryExpression { + kind: SyntaxKind.VoidExpression; expression: UnaryExpression; } - // @kind(SyntaxKind.AwaitExpression) export interface AwaitExpression extends UnaryExpression { + kind: SyntaxKind.AwaitExpression; expression: UnaryExpression; } - // @kind(SyntaxKind.YieldExpression) export interface YieldExpression extends Expression { - asteriskToken?: Node; + kind: SyntaxKind.YieldExpression; + asteriskToken?: AsteriskToken; expression?: Expression; } - // @kind(SyntaxKind.BinaryExpression) + // see: https://tc39.github.io/ecma262/#prod-ExponentiationExpression + export type ExponentiationOperator + = SyntaxKind.AsteriskAsteriskToken + ; + + // see: https://tc39.github.io/ecma262/#prod-MultiplicativeOperator + export type MultiplicativeOperator + = SyntaxKind.AsteriskToken + | SyntaxKind.SlashToken + | SyntaxKind.PercentToken + ; + + // see: https://tc39.github.io/ecma262/#prod-MultiplicativeExpression + export type MultiplicativeOperatorOrHigher + = ExponentiationOperator + | MultiplicativeOperator + ; + + // see: https://tc39.github.io/ecma262/#prod-AdditiveExpression + export type AdditiveOperator + = SyntaxKind.PlusToken + | SyntaxKind.MinusToken + ; + + // see: https://tc39.github.io/ecma262/#prod-AdditiveExpression + export type AdditiveOperatorOrHigher + = MultiplicativeOperatorOrHigher + | AdditiveOperator + ; + + // see: https://tc39.github.io/ecma262/#prod-ShiftExpression + export type ShiftOperator + = SyntaxKind.LessThanLessThanToken + | SyntaxKind.GreaterThanGreaterThanToken + | SyntaxKind.GreaterThanGreaterThanGreaterThanToken + ; + + // see: https://tc39.github.io/ecma262/#prod-ShiftExpression + export type ShiftOperatorOrHigher + = AdditiveOperatorOrHigher + | ShiftOperator + ; + + // see: https://tc39.github.io/ecma262/#prod-RelationalExpression + export type RelationalOperator + = SyntaxKind.LessThanToken + | SyntaxKind.LessThanEqualsToken + | SyntaxKind.GreaterThanToken + | SyntaxKind.GreaterThanEqualsToken + | SyntaxKind.InstanceOfKeyword + | SyntaxKind.InKeyword + ; + + // see: https://tc39.github.io/ecma262/#prod-RelationalExpression + export type RelationalOperatorOrHigher + = ShiftOperatorOrHigher + | RelationalOperator + ; + + // see: https://tc39.github.io/ecma262/#prod-EqualityExpression + export type EqualityOperator + = SyntaxKind.EqualsEqualsToken + | SyntaxKind.EqualsEqualsEqualsToken + | SyntaxKind.ExclamationEqualsEqualsToken + | SyntaxKind.ExclamationEqualsToken + ; + + // see: https://tc39.github.io/ecma262/#prod-EqualityExpression + export type EqualityOperatorOrHigher + = RelationalOperatorOrHigher + | EqualityOperator; + + // see: https://tc39.github.io/ecma262/#prod-BitwiseANDExpression + // see: https://tc39.github.io/ecma262/#prod-BitwiseXORExpression + // see: https://tc39.github.io/ecma262/#prod-BitwiseORExpression + export type BitwiseOperator + = SyntaxKind.AmpersandToken + | SyntaxKind.BarToken + | SyntaxKind.CaretToken + ; + + // see: https://tc39.github.io/ecma262/#prod-BitwiseANDExpression + // see: https://tc39.github.io/ecma262/#prod-BitwiseXORExpression + // see: https://tc39.github.io/ecma262/#prod-BitwiseORExpression + export type BitwiseOperatorOrHigher + = EqualityOperatorOrHigher + | BitwiseOperator + ; + + // see: https://tc39.github.io/ecma262/#prod-LogicalANDExpression + // see: https://tc39.github.io/ecma262/#prod-LogicalORExpression + export type LogicalOperator + = SyntaxKind.AmpersandAmpersandToken + | SyntaxKind.BarBarToken + ; + + // see: https://tc39.github.io/ecma262/#prod-LogicalANDExpression + // see: https://tc39.github.io/ecma262/#prod-LogicalORExpression + export type LogicalOperatorOrHigher + = BitwiseOperatorOrHigher + | LogicalOperator + ; + + // see: https://tc39.github.io/ecma262/#prod-AssignmentOperator + export type CompoundAssignmentOperator + = SyntaxKind.PlusEqualsToken + | SyntaxKind.MinusEqualsToken + | SyntaxKind.AsteriskAsteriskEqualsToken + | SyntaxKind.AsteriskEqualsToken + | SyntaxKind.SlashEqualsToken + | SyntaxKind.PercentEqualsToken + | SyntaxKind.AmpersandEqualsToken + | SyntaxKind.BarEqualsToken + | SyntaxKind.CaretEqualsToken + | SyntaxKind.LessThanLessThanEqualsToken + | SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken + | SyntaxKind.GreaterThanGreaterThanEqualsToken + ; + + // see: https://tc39.github.io/ecma262/#prod-AssignmentExpression + export type AssignmentOperator + = SyntaxKind.EqualsToken + | CompoundAssignmentOperator + ; + + // see: https://tc39.github.io/ecma262/#prod-AssignmentExpression + export type AssignmentOperatorOrHigher + = LogicalOperatorOrHigher + | AssignmentOperator + ; + + // see: https://tc39.github.io/ecma262/#prod-Expression + export type BinaryOperator + = AssignmentOperatorOrHigher + | SyntaxKind.CommaToken + ; + + export type BinaryOperatorToken = Token; + // Binary expressions can be declarations if they are 'exports.foo = bar' expressions in JS files export interface BinaryExpression extends Expression, Declaration { + kind: SyntaxKind.BinaryExpression; left: Expression; - operatorToken: Node; + operatorToken: BinaryOperatorToken; right: Expression; } - // @kind(SyntaxKind.ConditionalExpression) export interface ConditionalExpression extends Expression { + kind: SyntaxKind.ConditionalExpression; condition: Expression; - questionToken: Node; + questionToken: QuestionToken; whenTrue: Expression; - colonToken: Node; + colonToken: ColonToken; whenFalse: Expression; } export type FunctionBody = Block; export type ConciseBody = FunctionBody | Expression; - // @kind(SyntaxKind.FunctionExpression) export interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclaration { + kind: SyntaxKind.FunctionExpression; name?: Identifier; body: FunctionBody; // Required, whereas the member inherited from FunctionDeclaration is optional } - // @kind(SyntaxKind.ArrowFunction) export interface ArrowFunction extends Expression, FunctionLikeDeclaration { - equalsGreaterThanToken: Node; + kind: SyntaxKind.ArrowFunction; + equalsGreaterThanToken: EqualsGreaterThanToken; body: ConciseBody; } + // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, + // or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters. + // For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". export interface LiteralLikeNode extends Node { text: string; isUnterminated?: boolean; @@ -1027,55 +1213,65 @@ namespace ts { // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, // or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters. // For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". - // @kind(SyntaxKind.RegularExpressionLiteral) - // @kind(SyntaxKind.NoSubstitutionTemplateLiteral) export interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { _literalExpressionBrand: any; } - // @kind(SyntaxKind.NumericLiteral) + export interface RegularExpressionLiteral extends LiteralExpression { + kind: SyntaxKind.RegularExpressionLiteral; + } + + export interface NoSubstitutionTemplateLiteral extends LiteralExpression { + kind: SyntaxKind.NoSubstitutionTemplateLiteral; + } + export interface NumericLiteral extends LiteralExpression { - _numericLiteralBrand: any; + kind: SyntaxKind.NumericLiteral; trailingComment?: string; } - // @kind(SyntaxKind.TemplateHead) - // @kind(SyntaxKind.TemplateMiddle) - // @kind(SyntaxKind.TemplateTail) - export interface TemplateLiteralFragment extends LiteralLikeNode { - _templateLiteralFragmentBrand: any; + export interface TemplateHead extends LiteralLikeNode { + kind: SyntaxKind.TemplateHead; } - export type Template = TemplateExpression | LiteralExpression; + export interface TemplateMiddle extends LiteralLikeNode { + kind: SyntaxKind.TemplateMiddle; + } + + export interface TemplateTail extends LiteralLikeNode { + kind: SyntaxKind.TemplateTail; + } + + export type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; - // @kind(SyntaxKind.TemplateExpression) export interface TemplateExpression extends PrimaryExpression { - head: TemplateLiteralFragment; + kind: SyntaxKind.TemplateExpression; + head: TemplateHead; templateSpans: NodeArray; } // Each of these corresponds to a substitution expression and a template literal, in that order. // The template literal must have kind TemplateMiddleLiteral or TemplateTailLiteral. - // @kind(SyntaxKind.TemplateSpan) export interface TemplateSpan extends Node { + kind: SyntaxKind.TemplateSpan; expression: Expression; - literal: TemplateLiteralFragment; + literal: TemplateMiddle | TemplateTail; } - // @kind(SyntaxKind.ParenthesizedExpression) export interface ParenthesizedExpression extends PrimaryExpression { + kind: SyntaxKind.ParenthesizedExpression; expression: Expression; } - // @kind(SyntaxKind.ArrayLiteralExpression) export interface ArrayLiteralExpression extends PrimaryExpression { + kind: SyntaxKind.ArrayLiteralExpression; elements: NodeArray; /* @internal */ multiLine?: boolean; } - // @kind(SyntaxKind.SpreadElementExpression) export interface SpreadElementExpression extends Expression { + kind: SyntaxKind.SpreadElementExpression; expression: Expression; } @@ -1090,8 +1286,8 @@ namespace ts { } // An ObjectLiteralExpression is the declaration node for an anonymous symbol. - // @kind(SyntaxKind.ObjectLiteralExpression) export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase { + kind: SyntaxKind.ObjectLiteralExpression; /* @internal */ multiLine?: boolean; } @@ -1099,69 +1295,93 @@ namespace ts { export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression; export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; - // @kind(SyntaxKind.PropertyAccessExpression) export interface PropertyAccessExpression extends MemberExpression, Declaration { + kind: SyntaxKind.PropertyAccessExpression; expression: LeftHandSideExpression; name: Identifier; } + + export interface SuperPropertyAccessExpression extends PropertyAccessExpression { + expression: SuperExpression; + } + /** Brand for a PropertyAccessExpression which, like a QualifiedName, consists of a sequence of identifiers separated by dots. */ export interface PropertyAccessEntityNameExpression extends PropertyAccessExpression { _propertyAccessExpressionLikeQualifiedNameBrand?: any; expression: EntityNameExpression; } - // @kind(SyntaxKind.ElementAccessExpression) export interface ElementAccessExpression extends MemberExpression { + kind: SyntaxKind.ElementAccessExpression; expression: LeftHandSideExpression; argumentExpression?: Expression; } - // @kind(SyntaxKind.CallExpression) + export interface SuperElementAccessExpression extends ElementAccessExpression { + expression: SuperExpression; + } + + // see: https://tc39.github.io/ecma262/#prod-SuperProperty + export type SuperProperty + = SuperPropertyAccessExpression + | SuperElementAccessExpression + ; + export interface CallExpression extends LeftHandSideExpression, Declaration { + kind: SyntaxKind.CallExpression; expression: LeftHandSideExpression; typeArguments?: NodeArray; arguments: NodeArray; } - // @kind(SyntaxKind.ExpressionWithTypeArguments) + // see: https://tc39.github.io/ecma262/#prod-SuperCall + export interface SuperCall extends CallExpression { + expression: SuperExpression; + } + export interface ExpressionWithTypeArguments extends TypeNode { + kind: SyntaxKind.ExpressionWithTypeArguments; expression: LeftHandSideExpression; typeArguments?: NodeArray; } - // @kind(SyntaxKind.NewExpression) - export interface NewExpression extends CallExpression, PrimaryExpression { } + export interface NewExpression extends PrimaryExpression, Declaration { + kind: SyntaxKind.NewExpression; + expression: LeftHandSideExpression; + typeArguments?: NodeArray; + arguments: NodeArray; + } - // @kind(SyntaxKind.TaggedTemplateExpression) export interface TaggedTemplateExpression extends MemberExpression { + kind: SyntaxKind.TaggedTemplateExpression; tag: LeftHandSideExpression; - template: Template; + template: TemplateLiteral; } export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator; - // @kind(SyntaxKind.AsExpression) export interface AsExpression extends Expression { + kind: SyntaxKind.AsExpression; expression: Expression; type: TypeNode; } - // @kind(SyntaxKind.TypeAssertionExpression) export interface TypeAssertion extends UnaryExpression { + kind: SyntaxKind.TypeAssertionExpression; type: TypeNode; expression: UnaryExpression; } export type AssertionExpression = TypeAssertion | AsExpression; - // @kind(SyntaxKind.NonNullExpression) export interface NonNullExpression extends LeftHandSideExpression { + kind: SyntaxKind.NonNullExpression; expression: Expression; } /// A JSX expression of the form ... - // @kind(SyntaxKind.JsxElement) export interface JsxElement extends PrimaryExpression { + kind: SyntaxKind.JsxElement; openingElement: JsxOpeningElement; children: NodeArray; closingElement: JsxClosingElement; @@ -1170,17 +1390,17 @@ namespace ts { export type JsxTagNameExpression = PrimaryExpression | PropertyAccessExpression; /// The opening element of a ... JsxElement - // @kind(SyntaxKind.JsxOpeningElement) export interface JsxOpeningElement extends Expression { - _openingElementBrand?: any; + kind: SyntaxKind.JsxOpeningElement; tagName: JsxTagNameExpression; attributes: NodeArray; } /// A JSX expression of the form - // @kind(SyntaxKind.JsxSelfClosingElement) - export interface JsxSelfClosingElement extends PrimaryExpression, JsxOpeningElement { - _selfClosingElementBrand?: any; + export interface JsxSelfClosingElement extends PrimaryExpression { + kind: SyntaxKind.JsxSelfClosingElement; + tagName: JsxTagNameExpression; + attributes: NodeArray; } /// Either the opening tag in a ... pair, or the lone in a self-closing form @@ -1188,31 +1408,30 @@ namespace ts { export type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute; - // @kind(SyntaxKind.JsxAttribute) export interface JsxAttribute extends Node { + kind: SyntaxKind.JsxAttribute; name: Identifier; /// JSX attribute initializers are optional; is sugar for initializer?: StringLiteral | JsxExpression; } - // @kind(SyntaxKind.JsxSpreadAttribute) export interface JsxSpreadAttribute extends Node { + kind: SyntaxKind.JsxSpreadAttribute; expression: Expression; } - // @kind(SyntaxKind.JsxClosingElement) export interface JsxClosingElement extends Node { + kind: SyntaxKind.JsxClosingElement; tagName: JsxTagNameExpression; } - // @kind(SyntaxKind.JsxExpression) export interface JsxExpression extends Expression { + kind: SyntaxKind.JsxExpression; expression?: Expression; } - // @kind(SyntaxKind.JsxText) export interface JsxText extends Node { - _jsxTextExpressionBrand: any; + kind: SyntaxKind.JsxText; } export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement; @@ -1224,41 +1443,43 @@ namespace ts { // Represents a statement that is elided as part of a transformation to emit comments on a // not-emitted node. // @internal - // @kind(SyntaxKind.NotEmittedStatement) export interface NotEmittedStatement extends Statement { + kind: SyntaxKind.NotEmittedStatement; } - // @kind(SyntaxKind.EmptyStatement) - export interface EmptyStatement extends Statement { } + export interface EmptyStatement extends Statement { + kind: SyntaxKind.EmptyStatement; + } - // @kind(SyntaxKind.DebuggerStatement) - export interface DebuggerStatement extends Statement { } + export interface DebuggerStatement extends Statement { + kind: SyntaxKind.DebuggerStatement; + } - // @kind(SyntaxKind.MissingDeclaration) export interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElement, TypeElement { + kind: SyntaxKind.MissingDeclaration; name?: Identifier; } export type BlockLike = SourceFile | Block | ModuleBlock | CaseClause; - // @kind(SyntaxKind.Block) export interface Block extends Statement { + kind: SyntaxKind.Block; statements: NodeArray; /*@internal*/ multiLine?: boolean; } - // @kind(SyntaxKind.VariableStatement) export interface VariableStatement extends Statement { + kind: SyntaxKind.VariableStatement; declarationList: VariableDeclarationList; } - // @kind(SyntaxKind.ExpressionStatement) export interface ExpressionStatement extends Statement { + kind: SyntaxKind.ExpressionStatement; expression: Expression; } - // @kind(SyntaxKind.IfStatement) export interface IfStatement extends Statement { + kind: SyntaxKind.IfStatement; expression: Expression; thenStatement: Statement; elseStatement?: Statement; @@ -1268,105 +1489,105 @@ namespace ts { statement: Statement; } - // @kind(SyntaxKind.DoStatement) export interface DoStatement extends IterationStatement { + kind: SyntaxKind.DoStatement; expression: Expression; } - // @kind(SyntaxKind.WhileStatement) export interface WhileStatement extends IterationStatement { + kind: SyntaxKind.WhileStatement; expression: Expression; } export type ForInitializer = VariableDeclarationList | Expression; - // @kind(SyntaxKind.ForStatement) export interface ForStatement extends IterationStatement { + kind: SyntaxKind.ForStatement; initializer?: ForInitializer; condition?: Expression; incrementor?: Expression; } - // @kind(SyntaxKind.ForInStatement) export interface ForInStatement extends IterationStatement { + kind: SyntaxKind.ForInStatement; initializer: ForInitializer; expression: Expression; } - // @kind(SyntaxKind.ForOfStatement) export interface ForOfStatement extends IterationStatement { + kind: SyntaxKind.ForOfStatement; initializer: ForInitializer; expression: Expression; } - // @kind(SyntaxKind.BreakStatement) export interface BreakStatement extends Statement { + kind: SyntaxKind.BreakStatement; label?: Identifier; } - // @kind(SyntaxKind.ContinueStatement) export interface ContinueStatement extends Statement { + kind: SyntaxKind.ContinueStatement; label?: Identifier; } export type BreakOrContinueStatement = BreakStatement | ContinueStatement; - // @kind(SyntaxKind.ReturnStatement) export interface ReturnStatement extends Statement { + kind: SyntaxKind.ReturnStatement; expression?: Expression; } - // @kind(SyntaxKind.WithStatement) export interface WithStatement extends Statement { + kind: SyntaxKind.WithStatement; expression: Expression; statement: Statement; } - // @kind(SyntaxKind.SwitchStatement) export interface SwitchStatement extends Statement { + kind: SyntaxKind.SwitchStatement; expression: Expression; caseBlock: CaseBlock; possiblyExhaustive?: boolean; } - // @kind(SyntaxKind.CaseBlock) export interface CaseBlock extends Node { + kind: SyntaxKind.CaseBlock; clauses: NodeArray; } - // @kind(SyntaxKind.CaseClause) export interface CaseClause extends Node { + kind: SyntaxKind.CaseClause; expression: Expression; statements: NodeArray; } - // @kind(SyntaxKind.DefaultClause) export interface DefaultClause extends Node { + kind: SyntaxKind.DefaultClause; statements: NodeArray; } export type CaseOrDefaultClause = CaseClause | DefaultClause; - // @kind(SyntaxKind.LabeledStatement) export interface LabeledStatement extends Statement { + kind: SyntaxKind.LabeledStatement; label: Identifier; statement: Statement; } - // @kind(SyntaxKind.ThrowStatement) export interface ThrowStatement extends Statement { + kind: SyntaxKind.ThrowStatement; expression: Expression; } - // @kind(SyntaxKind.TryStatement) export interface TryStatement extends Statement { + kind: SyntaxKind.TryStatement; tryBlock: Block; catchClause?: CatchClause; finallyBlock?: Block; } - // @kind(SyntaxKind.CatchClause) export interface CatchClause extends Node { + kind: SyntaxKind.CatchClause; variableDeclaration: VariableDeclaration; block: Block; } @@ -1380,13 +1601,13 @@ namespace ts { members: NodeArray; } - // @kind(SyntaxKind.ClassDeclaration) export interface ClassDeclaration extends ClassLikeDeclaration, DeclarationStatement { + kind: SyntaxKind.ClassDeclaration; name?: Identifier; } - // @kind(SyntaxKind.ClassExpression) export interface ClassExpression extends ClassLikeDeclaration, PrimaryExpression { + kind: SyntaxKind.ClassExpression; } export interface ClassElement extends Declaration { @@ -1397,40 +1618,40 @@ namespace ts { export interface TypeElement extends Declaration { _typeElementBrand: any; name?: PropertyName; - questionToken?: Node; + questionToken?: QuestionToken; } - // @kind(SyntaxKind.InterfaceDeclaration) export interface InterfaceDeclaration extends DeclarationStatement { + kind: SyntaxKind.InterfaceDeclaration; name: Identifier; typeParameters?: NodeArray; heritageClauses?: NodeArray; members: NodeArray; } - // @kind(SyntaxKind.HeritageClause) export interface HeritageClause extends Node { + kind: SyntaxKind.HeritageClause; token: SyntaxKind; types?: NodeArray; } - // @kind(SyntaxKind.TypeAliasDeclaration) export interface TypeAliasDeclaration extends DeclarationStatement { + kind: SyntaxKind.TypeAliasDeclaration; name: Identifier; typeParameters?: NodeArray; type: TypeNode; } - // @kind(SyntaxKind.EnumMember) export interface EnumMember extends Declaration { + kind: SyntaxKind.EnumMember; // This does include ComputedPropertyName, but the parser will give an error // if it parses a ComputedPropertyName in an EnumMember name: PropertyName; initializer?: Expression; } - // @kind(SyntaxKind.EnumDeclaration) export interface EnumDeclaration extends DeclarationStatement { + kind: SyntaxKind.EnumDeclaration; name: Identifier; members: NodeArray; } @@ -1439,21 +1660,26 @@ namespace ts { export type ModuleName = Identifier | StringLiteral; - // @kind(SyntaxKind.ModuleDeclaration) export interface ModuleDeclaration extends DeclarationStatement { + kind: SyntaxKind.ModuleDeclaration; name: Identifier | LiteralExpression; - body?: ModuleBlock | ModuleDeclaration; + body?: ModuleBlock | NamespaceDeclaration; + } + + export interface NamespaceDeclaration extends ModuleDeclaration { + name: Identifier; + body: ModuleBlock | NamespaceDeclaration; } - // @kind(SyntaxKind.ModuleBlock) export interface ModuleBlock extends Node, Statement { + kind: SyntaxKind.ModuleBlock; statements: NodeArray; } export type ModuleReference = EntityName | ExternalModuleReference; - // @kind(SyntaxKind.ImportEqualsDeclaration) export interface ImportEqualsDeclaration extends DeclarationStatement { + kind: SyntaxKind.ImportEqualsDeclaration; name: Identifier; // 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external @@ -1461,8 +1687,8 @@ namespace ts { moduleReference: ModuleReference; } - // @kind(SyntaxKind.ExternalModuleReference) export interface ExternalModuleReference extends Node { + kind: SyntaxKind.ExternalModuleReference; expression?: Expression; } @@ -1470,8 +1696,8 @@ namespace ts { // import "mod" => importClause = undefined, moduleSpecifier = "mod" // In rest of the cases, module specifier is string literal corresponding to module // ImportClause information is shown at its declaration below. - // @kind(SyntaxKind.ImportDeclaration) export interface ImportDeclaration extends Statement { + kind: SyntaxKind.ImportDeclaration; importClause?: ImportClause; moduleSpecifier: Expression; } @@ -1484,57 +1710,57 @@ namespace ts { // import d, * as ns from "mod" => name = d, namedBinding: NamespaceImport = { name: ns } // import { a, b as x } from "mod" => name = undefined, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} // import d, { a, b as x } from "mod" => name = d, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} - // @kind(SyntaxKind.ImportClause) export interface ImportClause extends Declaration { + kind: SyntaxKind.ImportClause; name?: Identifier; // Default binding namedBindings?: NamedImportBindings; } - // @kind(SyntaxKind.NamespaceImport) export interface NamespaceImport extends Declaration { + kind: SyntaxKind.NamespaceImport; name: Identifier; } - // @kind(SyntaxKind.NamespaceExportDeclaration) export interface NamespaceExportDeclaration extends DeclarationStatement { + kind: SyntaxKind.NamespaceExportDeclaration; name: Identifier; moduleReference: LiteralLikeNode; } - // @kind(SyntaxKind.ExportDeclaration) export interface ExportDeclaration extends DeclarationStatement { + kind: SyntaxKind.ExportDeclaration; exportClause?: NamedExports; moduleSpecifier?: Expression; } - // @kind(SyntaxKind.NamedImports) export interface NamedImports extends Node { + kind: SyntaxKind.NamedImports; elements: NodeArray; } - // @kind(SyntaxKind.NamedExports) export interface NamedExports extends Node { + kind: SyntaxKind.NamedExports; elements: NodeArray; } export type NamedImportsOrExports = NamedImports | NamedExports; - // @kind(SyntaxKind.ImportSpecifier) export interface ImportSpecifier extends Declaration { + kind: SyntaxKind.ImportSpecifier; propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) name: Identifier; // Declared name } - // @kind(SyntaxKind.ExportSpecifier) export interface ExportSpecifier extends Declaration { + kind: SyntaxKind.ExportSpecifier; propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) name: Identifier; // Declared name } export type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; - // @kind(SyntaxKind.ExportAssignment) export interface ExportAssignment extends DeclarationStatement { + kind: SyntaxKind.ExportAssignment; isExportEquals?: boolean; expression: Expression; } @@ -1549,8 +1775,8 @@ namespace ts { } // represents a top level: { type } expression in a JSDoc comment. - // @kind(SyntaxKind.JSDocTypeExpression) export interface JSDocTypeExpression extends Node { + kind: SyntaxKind.JSDocTypeExpression; type: JSDocType; } @@ -1558,139 +1784,141 @@ namespace ts { _jsDocTypeBrand: any; } - // @kind(SyntaxKind.JSDocAllType) export interface JSDocAllType extends JSDocType { - _JSDocAllTypeBrand: any; + kind: SyntaxKind.JSDocAllType; } - // @kind(SyntaxKind.JSDocUnknownType) export interface JSDocUnknownType extends JSDocType { - _JSDocUnknownTypeBrand: any; + kind: SyntaxKind.JSDocUnknownType; } - // @kind(SyntaxKind.JSDocArrayType) export interface JSDocArrayType extends JSDocType { + kind: SyntaxKind.JSDocArrayType; elementType: JSDocType; } - // @kind(SyntaxKind.JSDocUnionType) export interface JSDocUnionType extends JSDocType { + kind: SyntaxKind.JSDocUnionType; types: NodeArray; } - // @kind(SyntaxKind.JSDocTupleType) export interface JSDocTupleType extends JSDocType { + kind: SyntaxKind.JSDocTupleType; types: NodeArray; } - // @kind(SyntaxKind.JSDocNonNullableType) export interface JSDocNonNullableType extends JSDocType { + kind: SyntaxKind.JSDocNonNullableType; type: JSDocType; } - // @kind(SyntaxKind.JSDocNullableType) export interface JSDocNullableType extends JSDocType { + kind: SyntaxKind.JSDocNullableType; type: JSDocType; } - // @kind(SyntaxKind.JSDocRecordType) - export interface JSDocRecordType extends JSDocType, TypeLiteralNode { + export interface JSDocRecordType extends JSDocType { + kind: SyntaxKind.JSDocRecordType; literal: TypeLiteralNode; } - // @kind(SyntaxKind.JSDocTypeReference) export interface JSDocTypeReference extends JSDocType { + kind: SyntaxKind.JSDocTypeReference; name: EntityName; typeArguments: NodeArray; } - // @kind(SyntaxKind.JSDocOptionalType) export interface JSDocOptionalType extends JSDocType { + kind: SyntaxKind.JSDocOptionalType; type: JSDocType; } - // @kind(SyntaxKind.JSDocFunctionType) export interface JSDocFunctionType extends JSDocType, SignatureDeclaration { + kind: SyntaxKind.JSDocFunctionType; parameters: NodeArray; type: JSDocType; } - // @kind(SyntaxKind.JSDocVariadicType) export interface JSDocVariadicType extends JSDocType { + kind: SyntaxKind.JSDocVariadicType; type: JSDocType; } - // @kind(SyntaxKind.JSDocConstructorType) export interface JSDocConstructorType extends JSDocType { + kind: SyntaxKind.JSDocConstructorType; type: JSDocType; } - // @kind(SyntaxKind.JSDocThisType) export interface JSDocThisType extends JSDocType { + kind: SyntaxKind.JSDocThisType; type: JSDocType; } export interface JSDocLiteralType extends JSDocType { + kind: SyntaxKind.JSDocLiteralType; literal: LiteralTypeNode; } export type JSDocTypeReferencingNode = JSDocThisType | JSDocConstructorType | JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; - // @kind(SyntaxKind.JSDocRecordMember) export interface JSDocRecordMember extends PropertySignature { + kind: SyntaxKind.JSDocRecordMember; name: Identifier | LiteralExpression; type?: JSDocType; } - // @kind(SyntaxKind.JSDocComment) export interface JSDoc extends Node { + kind: SyntaxKind.JSDocComment; tags: NodeArray | undefined; comment: string | undefined; } - // @kind(SyntaxKind.JSDocTag) export interface JSDocTag extends Node { - atToken: Node; + atToken: AtToken; tagName: Identifier; comment: string | undefined; } - // @kind(SyntaxKind.JSDocTemplateTag) + export interface JSDocUnknownTag extends JSDocTag { + kind: SyntaxKind.JSDocTag; + } + export interface JSDocTemplateTag extends JSDocTag { + kind: SyntaxKind.JSDocTemplateTag; typeParameters: NodeArray; } - // @kind(SyntaxKind.JSDocReturnTag) export interface JSDocReturnTag extends JSDocTag { + kind: SyntaxKind.JSDocReturnTag; typeExpression: JSDocTypeExpression; } - // @kind(SyntaxKind.JSDocTypeTag) export interface JSDocTypeTag extends JSDocTag { + kind: SyntaxKind.JSDocTypeTag; typeExpression: JSDocTypeExpression; } - // @kind(SyntaxKind.JSDocTypedefTag) export interface JSDocTypedefTag extends JSDocTag, Declaration { + kind: SyntaxKind.JSDocTypedefTag; name?: Identifier; typeExpression?: JSDocTypeExpression; jsDocTypeLiteral?: JSDocTypeLiteral; } - // @kind(SyntaxKind.JSDocPropertyTag) export interface JSDocPropertyTag extends JSDocTag, TypeElement { + kind: SyntaxKind.JSDocPropertyTag; name: Identifier; typeExpression: JSDocTypeExpression; } - // @kind(SyntaxKind.JSDocTypeLiteral) export interface JSDocTypeLiteral extends JSDocType { + kind: SyntaxKind.JSDocTypeLiteral; jsDocPropertyTags?: NodeArray; jsDocTypeTag?: JSDocTypeTag; } - // @kind(SyntaxKind.JSDocParameterTag) export interface JSDocParameterTag extends JSDocTag { + kind: SyntaxKind.JSDocParameterTag; /** the parameter name, if provided *before* the type (TypeScript-style) */ preParameterName?: Identifier; typeExpression?: JSDocTypeExpression; @@ -1770,10 +1998,10 @@ namespace ts { } // Source files are declarations when they are external modules. - // @kind(SyntaxKind.SourceFile) export interface SourceFile extends Declaration { + kind: SyntaxKind.SourceFile; statements: NodeArray; - endOfFileToken: Node; + endOfFileToken: Token; fileName: string; /* internal */ path: Path; @@ -2117,13 +2345,12 @@ namespace ts { type: Type; } - // @kind (TypePredicateKind.This) export interface ThisTypePredicate extends TypePredicateBase { - _thisTypePredicateBrand: any; + kind: TypePredicateKind.This; } - // @kind (TypePredicateKind.Identifier) export interface IdentifierTypePredicate extends TypePredicateBase { + kind: TypePredicateKind.Identifier; parameterName: string; parameterIndex: number; } @@ -2198,8 +2425,8 @@ namespace ts { getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration): SourceFile; getTypeReferenceDirectivesForEntityName(name: EntityNameOrEntityNameExpression): string[]; getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[]; - isLiteralConstDeclaration(node: VariableDeclaration): boolean; - writeLiteralConstValue(node: VariableDeclaration, writer: SymbolWriter): void; + isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean; + writeLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, writer: SymbolWriter): void; } export const enum SymbolFlags { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bafc0361dc6..865f15a7b1b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -609,7 +609,7 @@ namespace ts { return !!(getCombinedNodeFlags(node) & NodeFlags.Let); } - export function isSuperCallExpression(n: Node): boolean { + export function isSuperCall(n: Node): n is SuperCall { return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; } @@ -1047,7 +1047,7 @@ namespace ts { /** * Determines whether a node is a property or element access expression for super. */ - export function isSuperProperty(node: Node): node is (PropertyAccessExpression | ElementAccessExpression) { + export function isSuperProperty(node: Node): node is SuperProperty { const kind = node.kind; return (kind === SyntaxKind.PropertyAccessExpression || kind === SyntaxKind.ElementAccessExpression) && (node).expression.kind === SyntaxKind.SuperKeyword; @@ -1375,7 +1375,7 @@ namespace ts { } } - export function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) { + export function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): ImportEqualsDeclaration | NamespaceImport { if (node.kind === SyntaxKind.ImportEqualsDeclaration) { return node; } @@ -2458,7 +2458,7 @@ namespace ts { return file.moduleName || getExternalModuleNameFromPath(host, file.fileName); } - export function getExternalModuleNameFromDeclaration(host: EmitHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration): string { + export function getExternalModuleNameFromDeclaration(host: EmitHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration): string { const file = resolver.getExternalModuleFileFromDeclaration(declaration); if (!file || isDeclarationFile(file)) { return undefined; @@ -3625,14 +3625,14 @@ namespace ts { return SyntaxKind.FirstTemplateToken <= kind && kind <= SyntaxKind.LastTemplateToken; } - function isTemplateLiteralFragmentKind(kind: SyntaxKind) { - return kind === SyntaxKind.TemplateHead - || kind === SyntaxKind.TemplateMiddle - || kind === SyntaxKind.TemplateTail; + export function isTemplateHead(node: Node): node is TemplateHead { + return node.kind === SyntaxKind.TemplateHead; } - export function isTemplateLiteralFragment(node: Node): node is TemplateLiteralFragment { - return isTemplateLiteralFragmentKind(node.kind); + export function isTemplateMiddleOrTemplateTail(node: Node): node is TemplateMiddle | TemplateTail { + const kind = node.kind; + return kind === SyntaxKind.TemplateMiddle + || kind === SyntaxKind.TemplateTail; } // Identifiers @@ -3797,7 +3797,7 @@ namespace ts { return node.kind === SyntaxKind.CallExpression; } - export function isTemplate(node: Node): node is Template { + export function isTemplateLiteral(node: Node): node is TemplateLiteral { const kind = node.kind; return kind === SyntaxKind.TemplateExpression || kind === SyntaxKind.NoSubstitutionTemplateLiteral; diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index bfb8cb2605e..b461d6da4e8 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -799,7 +799,7 @@ namespace ts { case SyntaxKind.TaggedTemplateExpression: return updateTaggedTemplate(node, visitNode((node).tag, visitor, isExpression), - visitNode((node).template, visitor, isTemplate)); + visitNode((node).template, visitor, isTemplateLiteral)); case SyntaxKind.ParenthesizedExpression: return updateParen(node, @@ -862,7 +862,7 @@ namespace ts { case SyntaxKind.TemplateExpression: return updateTemplateExpression(node, - visitNode((node).head, visitor, isTemplateLiteralFragment), + visitNode((node).head, visitor, isTemplateHead), visitNodes((node).templateSpans, visitor, isTemplateSpan)); case SyntaxKind.YieldExpression: @@ -890,7 +890,7 @@ namespace ts { case SyntaxKind.TemplateSpan: return updateTemplateSpan(node, visitNode((node).expression, visitor, isExpression), - visitNode((node).literal, visitor, isTemplateLiteralFragment)); + visitNode((node).literal, visitor, isTemplateMiddleOrTemplateTail)); // Element case SyntaxKind.Block: diff --git a/src/server/lsHost.ts b/src/server/lsHost.ts index 6585a267b84..d05b7897157 100644 --- a/src/server/lsHost.ts +++ b/src/server/lsHost.ts @@ -171,12 +171,16 @@ namespace ts.server { return this.host.fileExists(path); } + readFile(fileName: string): string { + return this.host.readFile(fileName); + } + directoryExists(path: string): boolean { return this.host.directoryExists(path); } - readFile(fileName: string): string { - return this.host.readFile(fileName); + readDirectory(path: string, extensions?: string[], exclude?: string[], include?: string[]): string[] { + return this.host.readDirectory(path, extensions, exclude, include); } getDirectories(path: string): string[] { diff --git a/src/services/completions.ts b/src/services/completions.ts index c0560e011eb..d003afb0def 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -324,15 +324,28 @@ namespace ts.Completions { return result; } + /** + * Given a path ending at a directory, gets the completions for the path, and filters for those entries containing the basename. + */ function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] { + if (fragment === undefined) { + fragment = ""; + } + + fragment = normalizeSlashes(fragment); + + /** + * Remove the basename from the path. Note that we don't use the basename to filter completions; + * the client is responsible for refining completions. + */ fragment = getDirectoryPath(fragment); - if (!fragment) { - fragment = "./"; - } - else { - fragment = ensureTrailingDirectorySeparator(fragment); + + if (fragment === "") { + fragment = "." + directorySeparator; } + fragment = ensureTrailingDirectorySeparator(fragment); + const absolutePath = normalizeAndPreserveTrailingSlash(isRootedDiskPath(fragment) ? fragment : combinePaths(scriptPath, fragment)); const baseDirectory = getDirectoryPath(absolutePath); const ignoreCase = !(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames()); @@ -342,6 +355,12 @@ namespace ts.Completions { const files = tryReadDirectory(host, baseDirectory, extensions, /*exclude*/undefined, /*include*/["./*"]); if (files) { + /** + * Multiple file entries might map to the same truncated name once we remove extensions + * (happens iff includeExtensions === false)so we use a set-like data structure. Eg: + * + * both foo.ts and foo.tsx become foo + */ const foundFiles = new StringSet(); for (let filePath of files) { filePath = normalizePath(filePath); @@ -538,36 +557,44 @@ namespace ts.Completions { return undefined; } + const completionInfo: CompletionInfo = { + /** + * We don't want the editor to offer any other completions, such as snippets, inside a comment. + */ + isGlobalCompletion: false, + isMemberCompletion: false, + /** + * The user may type in a path that doesn't yet exist, creating a "new identifier" + * with respect to the collection of identifiers the server is aware of. + */ + isNewIdentifierLocation: true, + + entries: [] + }; + const text = sourceFile.text.substr(range.pos, position - range.pos); const match = tripleSlashDirectiveFragmentRegex.exec(text); + if (match) { const prefix = match[1]; const kind = match[2]; const toComplete = match[3]; const scriptPath = getDirectoryPath(sourceFile.path); - let entries: CompletionEntry[]; if (kind === "path") { // Give completions for a relative path const span: TextSpan = getDirectoryFragmentTextSpan(toComplete, range.pos + prefix.length); - entries = getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getSupportedExtensions(compilerOptions), /*includeExtensions*/true, span, sourceFile.path); + completionInfo.entries = getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getSupportedExtensions(compilerOptions), /*includeExtensions*/true, span, sourceFile.path); } else { // Give completions based on the typings available const span: TextSpan = { start: range.pos + prefix.length, length: match[0].length - prefix.length }; - entries = getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, span); + completionInfo.entries = getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, span); } - - return { - isGlobalCompletion: false, - isMemberCompletion: false, - isNewIdentifierLocation: true, - entries - }; } - return undefined; + return completionInfo; } function getCompletionEntriesFromTypings(host: LanguageServiceHost, options: CompilerOptions, scriptPath: string, span: TextSpan, result: CompletionEntry[] = []): CompletionEntry[] { @@ -1673,9 +1700,15 @@ namespace ts.Completions { * Matches a triple slash reference directive with an incomplete string literal for its path. Used * to determine if the caret is currently within the string literal and capture the literal fragment * for completions. - * For example, this matches /// parent).members, node); case SyntaxKind.ModuleDeclaration: const body = (parent).body; - return body && body.kind === SyntaxKind.Block && rangeContainsRange((body).statements, node); + return body && body.kind === SyntaxKind.ModuleBlock && rangeContainsRange((body).statements, node); case SyntaxKind.SourceFile: case SyntaxKind.Block: case SyntaxKind.ModuleBlock: diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 4fffa394fc5..84f83a9c7db 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -332,7 +332,7 @@ namespace ts.formatting { (node.parent).expression !== node) { const fullCallOrNewExpression = (node.parent).expression; - const startingExpression = getStartingExpression(fullCallOrNewExpression); + const startingExpression = getStartingExpression(fullCallOrNewExpression); if (fullCallOrNewExpression === startingExpression) { return Value.Unknown; @@ -350,15 +350,14 @@ namespace ts.formatting { return Value.Unknown; - function getStartingExpression(node: PropertyAccessExpression | CallExpression | ElementAccessExpression) { + function getStartingExpression(node: Expression) { while (true) { switch (node.kind) { case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: - - node = node.expression; + node = (node).expression; break; default: return node; diff --git a/src/services/services.ts b/src/services/services.ts index 7e96e17003e..d6e3d633228 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -29,9 +29,9 @@ namespace ts { /** The version of the language service API */ export const servicesVersion = "0.5"; - function createNode(kind: SyntaxKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject | IdentifierObject { + function createNode(kind: TKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject | IdentifierObject { const node = kind >= SyntaxKind.FirstNode ? new NodeObject(kind, pos, end) : - kind === SyntaxKind.Identifier ? new IdentifierObject(kind, pos, end) : + kind === SyntaxKind.Identifier ? new IdentifierObject(SyntaxKind.Identifier, pos, end) : new TokenObject(kind, pos, end); node.parent = parent; return node; @@ -210,14 +210,13 @@ namespace ts { } } - class TokenOrIdentifierObject implements Token { + class TokenOrIdentifierObject implements Node { public kind: SyntaxKind; public pos: number; public end: number; public flags: NodeFlags; public parent: Node; public jsDocComments: JSDoc[]; - public __tokenTag: any; constructor(pos: number, end: number) { // Set properties in same order as NodeObject @@ -319,16 +318,25 @@ namespace ts { } } - class TokenObject extends TokenOrIdentifierObject { - public kind: SyntaxKind; - constructor(kind: SyntaxKind, pos: number, end: number) { + class TokenObject extends TokenOrIdentifierObject implements Token { + public kind: TKind; + + constructor(kind: TKind, pos: number, end: number) { super(pos, end); this.kind = kind; } } - class IdentifierObject extends TokenOrIdentifierObject { - constructor(kind: SyntaxKind, pos: number, end: number) { + class IdentifierObject extends TokenOrIdentifierObject implements Identifier { + public kind: SyntaxKind.Identifier; + public text: string; + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _incrementExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + constructor(kind: SyntaxKind.Identifier, pos: number, end: number) { super(pos, end); } } @@ -424,6 +432,7 @@ namespace ts { } class SourceFileObject extends NodeObject implements SourceFile { + public kind: SyntaxKind.SourceFile; public _declarationBrand: any; public fileName: string; public path: Path; @@ -432,7 +441,7 @@ namespace ts { public lineMap: number[]; public statements: NodeArray; - public endOfFileToken: Node; + public endOfFileToken: Token; public amdDependencies: { name: string; path: string }[]; public moduleName: string; diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 8b4d986df53..c9141278b10 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -114,12 +114,12 @@ namespace ts.SymbolDisplay { } // try get the call/construct signature from the type if it matches - let callExpression: CallExpression; + let callExpression: CallExpression | NewExpression; if (location.kind === SyntaxKind.CallExpression || location.kind === SyntaxKind.NewExpression) { - callExpression = location; + callExpression = location; } else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) { - callExpression = location.parent; + callExpression = location.parent; } if (callExpression) { diff --git a/src/services/types.ts b/src/services/types.ts index 7b8a8f9b166..d686d1a16ce 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -505,7 +505,11 @@ namespace ts { export interface CompletionInfo { isGlobalCompletion: boolean; isMemberCompletion: boolean; - isNewIdentifierLocation: boolean; // true when the current location also allows for a new identifier + + /** + * true when the current location also allows for a new identifier + */ + isNewIdentifierLocation: boolean; entries: CompletionEntry[]; } diff --git a/tests/baselines/reference/ES5SymbolProperty2.errors.txt b/tests/baselines/reference/ES5SymbolProperty2.errors.txt index 9a6526a2f86..97579a4f27a 100644 --- a/tests/baselines/reference/ES5SymbolProperty2.errors.txt +++ b/tests/baselines/reference/ES5SymbolProperty2.errors.txt @@ -4,7 +4,7 @@ tests/cases/conformance/Symbols/ES5SymbolProperty2.ts(10,11): error TS2304: Cann ==== tests/cases/conformance/Symbols/ES5SymbolProperty2.ts (2 errors) ==== module M { - var Symbol; + var Symbol: any; export class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/ES5SymbolProperty2.js b/tests/baselines/reference/ES5SymbolProperty2.js index f04a4671d3f..0cfe717ae56 100644 --- a/tests/baselines/reference/ES5SymbolProperty2.js +++ b/tests/baselines/reference/ES5SymbolProperty2.js @@ -1,6 +1,6 @@ //// [ES5SymbolProperty2.ts] module M { - var Symbol; + var Symbol: any; export class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/ES5SymbolProperty3.errors.txt b/tests/baselines/reference/ES5SymbolProperty3.errors.txt index 7c6cc5a9cd7..2953ed6ac6a 100644 --- a/tests/baselines/reference/ES5SymbolProperty3.errors.txt +++ b/tests/baselines/reference/ES5SymbolProperty3.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/Symbols/ES5SymbolProperty3.ts(4,6): error TS2471: A comp ==== tests/cases/conformance/Symbols/ES5SymbolProperty3.ts (1 errors) ==== - var Symbol; + var Symbol: any; class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/ES5SymbolProperty3.js b/tests/baselines/reference/ES5SymbolProperty3.js index 6589858625c..084f79bd077 100644 --- a/tests/baselines/reference/ES5SymbolProperty3.js +++ b/tests/baselines/reference/ES5SymbolProperty3.js @@ -1,5 +1,5 @@ //// [ES5SymbolProperty3.ts] -var Symbol; +var Symbol: any; class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/anyPlusAny1.js b/tests/baselines/reference/anyPlusAny1.js index 457688933d7..4b28a1d22e2 100644 --- a/tests/baselines/reference/anyPlusAny1.js +++ b/tests/baselines/reference/anyPlusAny1.js @@ -1,5 +1,5 @@ //// [anyPlusAny1.ts] -var x; +var x: any; x.name = "hello"; var z = x + x; diff --git a/tests/baselines/reference/anyPlusAny1.symbols b/tests/baselines/reference/anyPlusAny1.symbols index e0552e4541f..3b33a11987e 100644 --- a/tests/baselines/reference/anyPlusAny1.symbols +++ b/tests/baselines/reference/anyPlusAny1.symbols @@ -1,5 +1,5 @@ === tests/cases/compiler/anyPlusAny1.ts === -var x; +var x: any; >x : Symbol(x, Decl(anyPlusAny1.ts, 0, 3)) x.name = "hello"; diff --git a/tests/baselines/reference/anyPlusAny1.types b/tests/baselines/reference/anyPlusAny1.types index f6ca9c4996e..67323a10fd6 100644 --- a/tests/baselines/reference/anyPlusAny1.types +++ b/tests/baselines/reference/anyPlusAny1.types @@ -1,5 +1,5 @@ === tests/cases/compiler/anyPlusAny1.ts === -var x; +var x: any; >x : any x.name = "hello"; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types index 7492a698e3a..c2d9213ca60 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types @@ -10,10 +10,10 @@ var Foo; >Foo : any type ->type : any +>type : undefined Foo = string; ->Foo = string : any +>Foo = string : undefined >Foo : any ->string : any +>string : undefined diff --git a/tests/baselines/reference/assignEveryTypeToAny.types b/tests/baselines/reference/assignEveryTypeToAny.types index cfc24e1da65..fd1dccefae0 100644 --- a/tests/baselines/reference/assignEveryTypeToAny.types +++ b/tests/baselines/reference/assignEveryTypeToAny.types @@ -59,9 +59,9 @@ var e = undefined; >undefined : undefined x = e; ->x = e : any +>x = e : undefined >x : any ->e : any +>e : undefined var e2: typeof undefined; >e2 : any diff --git a/tests/baselines/reference/assignmentLHSIsReference.js b/tests/baselines/reference/assignmentLHSIsReference.js index f0af56ebc3b..85d2aab2c46 100644 --- a/tests/baselines/reference/assignmentLHSIsReference.js +++ b/tests/baselines/reference/assignmentLHSIsReference.js @@ -1,5 +1,5 @@ //// [assignmentLHSIsReference.ts] -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/baselines/reference/assignmentLHSIsReference.symbols b/tests/baselines/reference/assignmentLHSIsReference.symbols index b551557708f..417ba3c07ea 100644 --- a/tests/baselines/reference/assignmentLHSIsReference.symbols +++ b/tests/baselines/reference/assignmentLHSIsReference.symbols @@ -1,5 +1,5 @@ === tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts === -var value; +var value: any; >value : Symbol(value, Decl(assignmentLHSIsReference.ts, 0, 3)) // identifiers: variable and parameter diff --git a/tests/baselines/reference/assignmentLHSIsReference.types b/tests/baselines/reference/assignmentLHSIsReference.types index dfb3b236c0a..2a7fa2982aa 100644 --- a/tests/baselines/reference/assignmentLHSIsReference.types +++ b/tests/baselines/reference/assignmentLHSIsReference.types @@ -1,5 +1,5 @@ === tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts === -var value; +var value: any; >value : any // identifiers: variable and parameter diff --git a/tests/baselines/reference/assignmentLHSIsValue.errors.txt b/tests/baselines/reference/assignmentLHSIsValue.errors.txt index bf253df5e70..f97ae2bcfa5 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/assignmentLHSIsValue.errors.txt @@ -41,7 +41,7 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7 ==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (39 errors) ==== // expected error for all the LHS of assignments - var value; + var value: any; // this class C { diff --git a/tests/baselines/reference/assignmentLHSIsValue.js b/tests/baselines/reference/assignmentLHSIsValue.js index ab3f80eff21..155fa26fa81 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.js +++ b/tests/baselines/reference/assignmentLHSIsValue.js @@ -1,6 +1,6 @@ //// [assignmentLHSIsValue.ts] // expected error for all the LHS of assignments -var value; +var value: any; // this class C { diff --git a/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js b/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js index 7eb2157c026..fe99be204fc 100644 --- a/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js +++ b/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js @@ -44,7 +44,7 @@ module M { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js b/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js index 4022fde7f54..98d11d72bfb 100644 --- a/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js +++ b/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js @@ -43,7 +43,7 @@ module M { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncAwait_es5.js b/tests/baselines/reference/asyncAwait_es5.js index 67f7d000351..043e68abeab 100644 --- a/tests/baselines/reference/asyncAwait_es5.js +++ b/tests/baselines/reference/asyncAwait_es5.js @@ -43,7 +43,7 @@ module M { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncAwait_es6.js b/tests/baselines/reference/asyncAwait_es6.js index be2eb90e3e4..4ba9e096e10 100644 --- a/tests/baselines/reference/asyncAwait_es6.js +++ b/tests/baselines/reference/asyncAwait_es6.js @@ -43,7 +43,7 @@ module M { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncFunctionNoReturnType.js b/tests/baselines/reference/asyncFunctionNoReturnType.js index fc7b0b52f1c..fd39fc74d0e 100644 --- a/tests/baselines/reference/asyncFunctionNoReturnType.js +++ b/tests/baselines/reference/asyncFunctionNoReturnType.js @@ -9,7 +9,7 @@ async () => { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncFunctionReturnType.js b/tests/baselines/reference/asyncFunctionReturnType.js index 12cb44fbcf0..76f9952ab9f 100644 --- a/tests/baselines/reference/asyncFunctionReturnType.js +++ b/tests/baselines/reference/asyncFunctionReturnType.js @@ -14,7 +14,7 @@ async function fAsyncExplicit(): Promise<[number, boolean]> { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncFunctionsAcrossFiles.js b/tests/baselines/reference/asyncFunctionsAcrossFiles.js index 94ccff2358c..e9b5710dc07 100644 --- a/tests/baselines/reference/asyncFunctionsAcrossFiles.js +++ b/tests/baselines/reference/asyncFunctionsAcrossFiles.js @@ -19,7 +19,7 @@ export const b = { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); @@ -34,7 +34,7 @@ export const b = { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.js b/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.js index 3e351c37046..ac9a558a53f 100644 --- a/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.js +++ b/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.js @@ -30,7 +30,7 @@ async function sample2(x?: number) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncImportedPromise_es5.js b/tests/baselines/reference/asyncImportedPromise_es5.js index 76ffbc833aa..e5c28eb2dc1 100644 --- a/tests/baselines/reference/asyncImportedPromise_es5.js +++ b/tests/baselines/reference/asyncImportedPromise_es5.js @@ -29,7 +29,7 @@ exports.Task = Task; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncImportedPromise_es6.js b/tests/baselines/reference/asyncImportedPromise_es6.js index 56a41b0283f..17c9de51ee6 100644 --- a/tests/baselines/reference/asyncImportedPromise_es6.js +++ b/tests/baselines/reference/asyncImportedPromise_es6.js @@ -19,7 +19,7 @@ exports.Task = Task; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncMultiFile_es5.js b/tests/baselines/reference/asyncMultiFile_es5.js index cfc3cb235b0..6b44f5393fc 100644 --- a/tests/baselines/reference/asyncMultiFile_es5.js +++ b/tests/baselines/reference/asyncMultiFile_es5.js @@ -9,7 +9,7 @@ function g() { } var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/asyncMultiFile_es6.js b/tests/baselines/reference/asyncMultiFile_es6.js index 08d63521fb5..0c45aa6c8a3 100644 --- a/tests/baselines/reference/asyncMultiFile_es6.js +++ b/tests/baselines/reference/asyncMultiFile_es6.js @@ -9,7 +9,7 @@ function g() { } var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/await_unaryExpression_es6.js b/tests/baselines/reference/await_unaryExpression_es6.js index 46065bdada9..6609cc6f3f4 100644 --- a/tests/baselines/reference/await_unaryExpression_es6.js +++ b/tests/baselines/reference/await_unaryExpression_es6.js @@ -20,7 +20,7 @@ async function bar4() { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/await_unaryExpression_es6_1.js b/tests/baselines/reference/await_unaryExpression_es6_1.js index c6f5f1142c0..48f50d76f4a 100644 --- a/tests/baselines/reference/await_unaryExpression_es6_1.js +++ b/tests/baselines/reference/await_unaryExpression_es6_1.js @@ -24,7 +24,7 @@ async function bar4() { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/await_unaryExpression_es6_2.js b/tests/baselines/reference/await_unaryExpression_es6_2.js index 3c341018ed1..5e9d63a21d2 100644 --- a/tests/baselines/reference/await_unaryExpression_es6_2.js +++ b/tests/baselines/reference/await_unaryExpression_es6_2.js @@ -16,7 +16,7 @@ async function bar3() { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/await_unaryExpression_es6_3.js b/tests/baselines/reference/await_unaryExpression_es6_3.js index 077e264c450..469c8ea3ee9 100644 --- a/tests/baselines/reference/await_unaryExpression_es6_3.js +++ b/tests/baselines/reference/await_unaryExpression_es6_3.js @@ -22,7 +22,7 @@ async function bar4() { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/capturedLetConstInLoop9.types b/tests/baselines/reference/capturedLetConstInLoop9.types index 486697b8d84..453176a40c9 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9.types +++ b/tests/baselines/reference/capturedLetConstInLoop9.types @@ -39,7 +39,7 @@ for (let x = 0; x < 1; ++x) { } switch (x) { ->x : any +>x : undefined case 1: >1 : 1 diff --git a/tests/baselines/reference/capturedLetConstInLoop9_ES6.types b/tests/baselines/reference/capturedLetConstInLoop9_ES6.types index be4457315ee..df118279f30 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop9_ES6.types @@ -40,7 +40,7 @@ for (let x = 0; x < 1; ++x) { } switch (x) { ->x : any +>x : undefined case 1: >1 : 1 diff --git a/tests/baselines/reference/castOfAwait.js b/tests/baselines/reference/castOfAwait.js index 26e9812bf43..1f66d49e0f3 100644 --- a/tests/baselines/reference/castOfAwait.js +++ b/tests/baselines/reference/castOfAwait.js @@ -12,7 +12,7 @@ async function f() { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/commentsArgumentsOfCallExpression2.types b/tests/baselines/reference/commentsArgumentsOfCallExpression2.types index 7ec29aa9124..bc6bf5baa90 100644 --- a/tests/baselines/reference/commentsArgumentsOfCallExpression2.types +++ b/tests/baselines/reference/commentsArgumentsOfCallExpression2.types @@ -17,7 +17,7 @@ foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b); >1 : 1 >2 : 2 >a + b : any ->a : any +>a : undefined >b : any foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b); @@ -26,7 +26,7 @@ foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b); >function () { } : () => void >() => { } : () => void >a + /*e3*/ b : any ->a : any +>a : undefined >b : any foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b)); @@ -36,7 +36,7 @@ foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b)); >() => { } : () => void >(a + b) : any >a + b : any ->a : any +>a : undefined >b : any foo( diff --git a/tests/baselines/reference/compoundAssignmentLHSIsReference.types b/tests/baselines/reference/compoundAssignmentLHSIsReference.types index 4816307f508..a82eb17426d 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsReference.types +++ b/tests/baselines/reference/compoundAssignmentLHSIsReference.types @@ -9,12 +9,12 @@ var x1: number; x1 *= value; >x1 *= value : number >x1 : number ->value : any +>value : undefined x1 += value; ->x1 += value : any +>x1 += value : number >x1 : number ->value : any +>value : undefined function fn1(x2: number) { >fn1 : (x2: number) => void @@ -41,41 +41,41 @@ x3.a *= value; >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined x3.a += value; ->x3.a += value : any +>x3.a += value : number >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined x3['a'] *= value; >x3['a'] *= value : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined x3['a'] += value; ->x3['a'] += value : any +>x3['a'] += value : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined // parentheses, the contained expression is reference (x1) *= value; >(x1) *= value : number >(x1) : number >x1 : number ->value : any +>value : undefined (x1) += value; ->(x1) += value : any +>(x1) += value : number >(x1) : number >x1 : number ->value : any +>value : undefined function fn2(x4: number) { >fn2 : (x4: number) => void @@ -100,15 +100,15 @@ function fn2(x4: number) { >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined (x3.a) += value; ->(x3.a) += value : any +>(x3.a) += value : number >(x3.a) : number >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined (x3['a']) *= value; >(x3['a']) *= value : number @@ -116,13 +116,13 @@ function fn2(x4: number) { >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined (x3['a']) += value; ->(x3['a']) += value : any +>(x3['a']) += value : number >(x3['a']) : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt index 392e1781dd5..61f893ba88f 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt @@ -77,7 +77,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa ==== tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts (74 errors) ==== // expected error for all the LHS of compound assignments (arithmetic and addition) - var value; + var value: any; // this class C { diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.js b/tests/baselines/reference/compoundAssignmentLHSIsValue.js index bfea11911bf..df3015731c7 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.js +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.js @@ -1,7 +1,7 @@ //// [compoundAssignmentLHSIsValue.ts] // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js index dfee41fad81..d5104f1dbdc 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js @@ -1,5 +1,5 @@ //// [compoundExponentiationAssignmentLHSIsReference.ts] -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols index 775d43b0c58..b69c1afdb9b 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols @@ -1,5 +1,5 @@ === tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts === -var value; +var value: any; >value : Symbol(value, Decl(compoundExponentiationAssignmentLHSIsReference.ts, 0, 3)) // identifiers: variable and parameter diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types index 55b90382d7b..32230f7f8ef 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types @@ -1,5 +1,5 @@ === tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts === -var value; +var value: any; >value : any // identifiers: variable and parameter diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt index 23720468bb7..0d9bab910ef 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt @@ -40,7 +40,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm ==== tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts (38 errors) ==== // expected error for all the LHS of compound assignments (arithmetic and addition) - var value; + var value: any; // this class C { diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js index c8fb8c6a222..d188a592588 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js @@ -1,6 +1,6 @@ //// [compoundExponentiationAssignmentLHSIsValue.ts] // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/baselines/reference/constraintSatisfactionWithAny.types b/tests/baselines/reference/constraintSatisfactionWithAny.types index f3363fe1a90..2f9c7553288 100644 --- a/tests/baselines/reference/constraintSatisfactionWithAny.types +++ b/tests/baselines/reference/constraintSatisfactionWithAny.types @@ -35,20 +35,20 @@ var a; >a : any foo(a); ->foo(a) : any +>foo(a) : undefined >foo : (x: T) => T ->a : any +>a : undefined foo2(a); ->foo2(a) : any +>foo2(a) : undefined >foo2 : (x: T) => T ->a : any +>a : undefined //foo3(a); foo4(a); ->foo4(a) : any +>foo4(a) : undefined >foo4 : (x: T) => void>(x: T) => T ->a : any +>a : undefined var b: number; >b : number @@ -84,10 +84,10 @@ class C { } var c1 = new C(a); ->c1 : C ->new C(a) : C +>c1 : C +>new C(a) : C >C : typeof C ->a : any +>a : undefined var c2 = new C(b); >c2 : C @@ -106,10 +106,10 @@ class C2 { } var c3 = new C2(a); ->c3 : C2 ->new C2(a) : C2 +>c3 : C2 +>new C2(a) : C2 >C2 : typeof C2 ->a : any +>a : undefined var c4 = new C2(b); >c4 : C2 @@ -138,10 +138,10 @@ class C4(x:T) => T> { } var c7 = new C4(a); ->c7 : C4 ->new C4(a) : C4 +>c7 : C4 +>new C4(a) : C4 >C4 : typeof C4 ->a : any +>a : undefined var c8 = new C4(b); >c8 : C4 diff --git a/tests/baselines/reference/controlFlowCaching.errors.txt b/tests/baselines/reference/controlFlowCaching.errors.txt new file mode 100644 index 00000000000..1086695313e --- /dev/null +++ b/tests/baselines/reference/controlFlowCaching.errors.txt @@ -0,0 +1,128 @@ +tests/cases/compiler/controlFlowCaching.ts(38,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(38,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(40,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(40,29): error TS2339: Property 'x' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(42,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(42,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(44,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(44,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(46,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(46,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(48,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(48,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(53,5): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(53,14): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(55,14): error TS2678: Type '"start"' is not comparable to type 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(58,14): error TS2678: Type '"end"' is not comparable to type 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(61,14): error TS2678: Type '"middle"' is not comparable to type 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(62,13): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(62,25): error TS2339: Property 'y' does not exist on type 'never'. + + +==== tests/cases/compiler/controlFlowCaching.ts (19 errors) ==== + + // Repro for #8401 + + function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) { + var isRtl = this._isRtl(); // chart mirroring + // prepare variable + var o = this.opt, ta = this.chart.theme.axis, position = o.position, + leftBottom = position !== "rightOrTop", rotation = o.rotation % 360, + start, stop, titlePos, titleRotation = 0, titleOffset, axisVector, tickVector, anchorOffset, labelOffset, labelAlign, + labelGap = this.chart.theme.axis.tick.labelGap, + taFont = o.font || (ta.majorTick && ta.majorTick.font) || (ta.tick && ta.tick.font), + taTitleFont = o.titleFont || (ta.title && ta.title.font), + taFontColor = o.fontColor || (ta.majorTick && ta.majorTick.fontColor) || (ta.tick && ta.tick.fontColor) || "black", + taTitleFontColor = o.titleFontColor || (ta.title && ta.title.fontColor) || "black", + taTitleGap = (o.titleGap == 0) ? 0 : o.titleGap || (ta.title && ta.title.gap) || 15, + taTitleOrientation = o.titleOrientation || (ta.title && ta.title.orientation) || "axis", + taMajorTick = this.chart.theme.getTick("major", o), + taMinorTick = this.chart.theme.getTick("minor", o), + taMicroTick = this.chart.theme.getTick("micro", o), + + taStroke = "stroke" in o ? o.stroke : ta.stroke, + size = taFont ? g.normalizedLength(g.splitFontString(taFont).size) : 0, + cosr = Math.abs(Math.cos(rotation * Math.PI / 180)), + sinr = Math.abs(Math.sin(rotation * Math.PI / 180)), + tsize = taTitleFont ? g.normalizedLength(g.splitFontString(taTitleFont).size) : 0; + if (rotation < 0) { + rotation += 360; + } + var cachedLabelW = this._getMaxLabelSize(); + cachedLabelW = cachedLabelW && cachedLabelW.majLabelW; + titleOffset = size * cosr + (cachedLabelW || 0) * sinr + labelGap + Math.max(taMajorTick.length > 0 ? taMajorTick.length : 0, + taMinorTick.length > 0 ? taMinorTick.length : 0) + + tsize + taTitleGap; + axisVector = { x: isRtl ? -1 : 1, y: 0 }; // chart mirroring + switch (rotation) { + default: + if (rotation < (90 - centerAnchorLimit)) { + labelOffset.y = leftBottom ? size : 0; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else if (rotation < (90 + centerAnchorLimit)) { + labelOffset.x = -size * 0.4; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'x' does not exist on type 'never'. + } else if (rotation < 180) { + labelOffset.y = leftBottom ? 0 : -size; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else if (rotation < (270 - centerAnchorLimit)) { + labelOffset.y = leftBottom ? 0 : -size; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else if (rotation < (270 + centerAnchorLimit)) { + labelOffset.y = leftBottom ? size * 0.4 : 0; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else { + labelOffset.y = leftBottom ? size : 0; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } + } + + titleRotation = (taTitleOrientation && taTitleOrientation == "away") ? 180 : 0; + titlePos.y = offsets.t - titleOffset + (titleRotation ? 0 : tsize); + ~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + switch (labelAlign) { + case "start": + ~~~~~~~ +!!! error TS2678: Type '"start"' is not comparable to type 'undefined'. + labelAlign = "end"; + break; + case "end": + ~~~~~ +!!! error TS2678: Type '"end"' is not comparable to type 'undefined'. + labelAlign = "start"; + break; + case "middle": + ~~~~~~~~ +!!! error TS2678: Type '"middle"' is not comparable to type 'undefined'. + labelOffset.y -= size; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + break; + } + + let _ = rotation; + } + \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowIIFE.types b/tests/baselines/reference/controlFlowIIFE.types index 6173e79dbbb..7cf4337b53b 100644 --- a/tests/baselines/reference/controlFlowIIFE.types +++ b/tests/baselines/reference/controlFlowIIFE.types @@ -118,7 +118,7 @@ maybeNumber++; if (maybeNumber !== undefined) { >maybeNumber !== undefined : boolean ->maybeNumber : number | undefined +>maybeNumber : number >undefined : undefined maybeNumber++; diff --git a/tests/baselines/reference/controlFlowLetVar.js b/tests/baselines/reference/controlFlowLetVar.js new file mode 100644 index 00000000000..24ad95259b1 --- /dev/null +++ b/tests/baselines/reference/controlFlowLetVar.js @@ -0,0 +1,247 @@ +//// [controlFlowLetVar.ts] + +declare let cond: boolean; + +// CFA for 'let' with no type annotation and initializer +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'let' with with type annotation +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'var' with with type annotation +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// No CFA for captured outer variables +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + } +} + +// No CFA for captured outer variables +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + }; +} + +//// [controlFlowLetVar.js] +// CFA for 'let' with no type annotation and initializer +function f1() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | null +} +// No CFA for 'let' with with type annotation +function f4() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // any +} +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | null +} +// No CFA for 'var' with with type annotation +function f8() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // any +} +// No CFA for captured outer variables +function f9() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined + function f() { + var z = x; // any + } +} +// No CFA for captured outer variables +function f10() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined + var f = function () { + var z = x; // any + }; +} diff --git a/tests/baselines/reference/controlFlowLetVar.symbols b/tests/baselines/reference/controlFlowLetVar.symbols new file mode 100644 index 00000000000..f58edd781b7 --- /dev/null +++ b/tests/baselines/reference/controlFlowLetVar.symbols @@ -0,0 +1,263 @@ +=== tests/cases/compiler/controlFlowLetVar.ts === + +declare let cond: boolean; +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + +// CFA for 'let' with no type annotation and initializer +function f1() { +>f1 : Symbol(f1, Decl(controlFlowLetVar.ts, 1, 26)) + + let x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 12, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { +>f2 : Symbol(f2, Decl(controlFlowLetVar.ts, 13, 1)) + + let x = undefined; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) +>undefined : Symbol(undefined) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 24, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { +>f3 : Symbol(f3, Decl(controlFlowLetVar.ts, 25, 1)) + + let x = null; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) + } + const y = x; // string | number | null +>y : Symbol(y, Decl(controlFlowLetVar.ts, 36, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) +} + +// No CFA for 'let' with with type annotation +function f4() { +>f4 : Symbol(f4, Decl(controlFlowLetVar.ts, 37, 1)) + + let x: any; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) + } + const y = x; // any +>y : Symbol(y, Decl(controlFlowLetVar.ts, 48, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) +} + +// CFA for 'var' with no type annotation and initializer +function f5() { +>f5 : Symbol(f5, Decl(controlFlowLetVar.ts, 49, 1)) + + var x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 60, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { +>f6 : Symbol(f6, Decl(controlFlowLetVar.ts, 61, 1)) + + var x = undefined; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) +>undefined : Symbol(undefined) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 72, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { +>f7 : Symbol(f7, Decl(controlFlowLetVar.ts, 73, 1)) + + var x = null; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) + } + const y = x; // string | number | null +>y : Symbol(y, Decl(controlFlowLetVar.ts, 84, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) +} + +// No CFA for 'var' with with type annotation +function f8() { +>f8 : Symbol(f8, Decl(controlFlowLetVar.ts, 85, 1)) + + var x: any; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) + } + const y = x; // any +>y : Symbol(y, Decl(controlFlowLetVar.ts, 96, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) +} + +// No CFA for captured outer variables +function f9() { +>f9 : Symbol(f9, Decl(controlFlowLetVar.ts, 97, 1)) + + let x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 108, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) + + function f() { +>f : Symbol(f, Decl(controlFlowLetVar.ts, 108, 16)) + + const z = x; // any +>z : Symbol(z, Decl(controlFlowLetVar.ts, 110, 13)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) + } +} + +// No CFA for captured outer variables +function f10() { +>f10 : Symbol(f10, Decl(controlFlowLetVar.ts, 112, 1)) + + let x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 123, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) + + const f = () => { +>f : Symbol(f, Decl(controlFlowLetVar.ts, 124, 9)) + + const z = x; // any +>z : Symbol(z, Decl(controlFlowLetVar.ts, 125, 13)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) + + }; +} diff --git a/tests/baselines/reference/controlFlowLetVar.types b/tests/baselines/reference/controlFlowLetVar.types new file mode 100644 index 00000000000..09f0ea83488 --- /dev/null +++ b/tests/baselines/reference/controlFlowLetVar.types @@ -0,0 +1,306 @@ +=== tests/cases/compiler/controlFlowLetVar.ts === + +declare let cond: boolean; +>cond : boolean + +// CFA for 'let' with no type annotation and initializer +function f1() { +>f1 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { +>f2 : () => void + + let x = undefined; +>x : any +>undefined : undefined + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { +>f3 : () => void + + let x = null; +>x : any +>null : null + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | null +>y : string | number | null +>x : string | number | null +} + +// No CFA for 'let' with with type annotation +function f4() { +>f4 : () => void + + let x: any; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // any +>y : any +>x : any +} + +// CFA for 'var' with no type annotation and initializer +function f5() { +>f5 : () => void + + var x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { +>f6 : () => void + + var x = undefined; +>x : any +>undefined : undefined + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { +>f7 : () => void + + var x = null; +>x : any +>null : null + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | null +>y : string | number | null +>x : string | number | null +} + +// No CFA for 'var' with with type annotation +function f8() { +>f8 : () => void + + var x: any; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // any +>y : any +>x : any +} + +// No CFA for captured outer variables +function f9() { +>f9 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined + + function f() { +>f : () => void + + const z = x; // any +>z : any +>x : any + } +} + +// No CFA for captured outer variables +function f10() { +>f10 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined + + const f = () => { +>f : () => void +>() => { const z = x; // any } : () => void + + const z = x; // any +>z : any +>x : any + + }; +} diff --git a/tests/baselines/reference/controlFlowNoImplicitAny.errors.txt b/tests/baselines/reference/controlFlowNoImplicitAny.errors.txt new file mode 100644 index 00000000000..d081f29d511 --- /dev/null +++ b/tests/baselines/reference/controlFlowNoImplicitAny.errors.txt @@ -0,0 +1,143 @@ +tests/cases/compiler/controlFlowNoImplicitAny.ts(102,9): error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. +tests/cases/compiler/controlFlowNoImplicitAny.ts(111,19): error TS7005: Variable 'x' implicitly has an 'any' type. +tests/cases/compiler/controlFlowNoImplicitAny.ts(117,9): error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. +tests/cases/compiler/controlFlowNoImplicitAny.ts(126,19): error TS7005: Variable 'x' implicitly has an 'any' type. + + +==== tests/cases/compiler/controlFlowNoImplicitAny.ts (4 errors) ==== + + declare let cond: boolean; + + // CFA for 'let' with no type annotation and initializer + function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + } + + // CFA for 'let' with no type annotation and 'undefined' initializer + function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + } + + // CFA for 'let' with no type annotation and 'null' initializer + function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null + } + + // No CFA for 'let' with with type annotation + function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any + } + + // CFA for 'var' with no type annotation and initializer + function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + } + + // CFA for 'var' with no type annotation and 'undefined' initializer + function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + } + + // CFA for 'var' with no type annotation and 'null' initializer + function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null + } + + // No CFA for 'var' with with type annotation + function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any + } + + // No CFA for captured outer variables + function f9() { + let x; + ~ +!!! error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + ~ +!!! error TS7005: Variable 'x' implicitly has an 'any' type. + } + } + + // No CFA for captured outer variables + function f10() { + let x; + ~ +!!! error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + ~ +!!! error TS7005: Variable 'x' implicitly has an 'any' type. + }; + } \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowNoImplicitAny.js b/tests/baselines/reference/controlFlowNoImplicitAny.js new file mode 100644 index 00000000000..9a5f302d87a --- /dev/null +++ b/tests/baselines/reference/controlFlowNoImplicitAny.js @@ -0,0 +1,247 @@ +//// [controlFlowNoImplicitAny.ts] + +declare let cond: boolean; + +// CFA for 'let' with no type annotation and initializer +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'let' with with type annotation +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'var' with with type annotation +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// No CFA for captured outer variables +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + } +} + +// No CFA for captured outer variables +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + }; +} + +//// [controlFlowNoImplicitAny.js] +// CFA for 'let' with no type annotation and initializer +function f1() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | null +} +// No CFA for 'let' with with type annotation +function f4() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // any +} +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | null +} +// No CFA for 'var' with with type annotation +function f8() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // any +} +// No CFA for captured outer variables +function f9() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined + function f() { + var z = x; // any + } +} +// No CFA for captured outer variables +function f10() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined + var f = function () { + var z = x; // any + }; +} diff --git a/tests/baselines/reference/declarationEmitPromise.js b/tests/baselines/reference/declarationEmitPromise.js index a4bbdd74dde..e6f3f922b46 100644 --- a/tests/baselines/reference/declarationEmitPromise.js +++ b/tests/baselines/reference/declarationEmitPromise.js @@ -27,7 +27,7 @@ export async function runSampleBreaks( var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/decoratorMetadataPromise.js b/tests/baselines/reference/decoratorMetadataPromise.js index 56a66216dea..52449f91755 100644 --- a/tests/baselines/reference/decoratorMetadataPromise.js +++ b/tests/baselines/reference/decoratorMetadataPromise.js @@ -25,7 +25,7 @@ var __metadata = (this && this.__metadata) || function (k, v) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.js b/tests/baselines/reference/decrementOperatorWithAnyOtherType.js index 51015cf44ed..f3ff58b80ca 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.js +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.js @@ -2,7 +2,7 @@ // -- operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols b/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols index cbef7442578..8d1b023c97a 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols @@ -4,7 +4,7 @@ var ANY: any; >ANY : Symbol(ANY, Decl(decrementOperatorWithAnyOtherType.ts, 2, 3)) -var ANY1; +var ANY1: any; >ANY1 : Symbol(ANY1, Decl(decrementOperatorWithAnyOtherType.ts, 3, 3)) var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.types b/tests/baselines/reference/decrementOperatorWithAnyOtherType.types index c8b8852e4d2..74fbd0012d1 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.types @@ -4,7 +4,7 @@ var ANY: any; >ANY : any -var ANY1; +var ANY1: any; >ANY1 : any var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 46e5515633a..2e1d594164d 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -52,7 +52,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp ==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts (50 errors) ==== // -- operator on any type - var ANY1; + var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} @@ -63,7 +63,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js index 94f5c942bfc..88d045ab378 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js @@ -1,6 +1,6 @@ //// [decrementOperatorWithAnyOtherTypeInvalidOperations.ts] // -- operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} @@ -11,7 +11,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/defaultExportInAwaitExpression01.js b/tests/baselines/reference/defaultExportInAwaitExpression01.js index b57b6237d7a..a16e2f07f5f 100644 --- a/tests/baselines/reference/defaultExportInAwaitExpression01.js +++ b/tests/baselines/reference/defaultExportInAwaitExpression01.js @@ -30,7 +30,7 @@ import x from './a'; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/defaultExportInAwaitExpression02.js b/tests/baselines/reference/defaultExportInAwaitExpression02.js index db2150c66f1..db05d62a2ad 100644 --- a/tests/baselines/reference/defaultExportInAwaitExpression02.js +++ b/tests/baselines/reference/defaultExportInAwaitExpression02.js @@ -22,7 +22,7 @@ exports.default = x; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/downlevelLetConst14.types b/tests/baselines/reference/downlevelLetConst14.types index 29c87e76cce..493c17b97cd 100644 --- a/tests/baselines/reference/downlevelLetConst14.types +++ b/tests/baselines/reference/downlevelLetConst14.types @@ -77,22 +77,22 @@ use(x); use(z0); >use(z0) : any >use : (a: any) => any ->z0 : any +>z0 : undefined use(z1); >use(z1) : any >use : (a: any) => any ->z1 : any +>z1 : undefined use(z2); >use(z2) : any >use : (a: any) => any ->z2 : any +>z2 : undefined use(z3); >use(z3) : any >use : (a: any) => any ->z3 : any +>z3 : undefined var z6; >z6 : any @@ -149,7 +149,7 @@ use(y); use(z6); >use(z6) : any >use : (a: any) => any ->z6 : any +>z6 : undefined var z = false; >z : boolean diff --git a/tests/baselines/reference/downlevelLetConst15.types b/tests/baselines/reference/downlevelLetConst15.types index 9e58c648821..6d224b6310d 100644 --- a/tests/baselines/reference/downlevelLetConst15.types +++ b/tests/baselines/reference/downlevelLetConst15.types @@ -83,22 +83,22 @@ use(x); use(z0); >use(z0) : any >use : (a: any) => any ->z0 : any +>z0 : undefined use(z1); >use(z1) : any >use : (a: any) => any ->z1 : any +>z1 : undefined use(z2); >use(z2) : any >use : (a: any) => any ->z2 : any +>z2 : undefined use(z3); >use(z3) : any >use : (a: any) => any ->z3 : any +>z3 : undefined var z6; >z6 : any @@ -155,7 +155,7 @@ use(y); use(z6); >use(z6) : any >use : (a: any) => any ->z6 : any +>z6 : undefined var z = false; >z : boolean diff --git a/tests/baselines/reference/es5-asyncFunction.js b/tests/baselines/reference/es5-asyncFunction.js index d6cd770e454..5123566dc8c 100644 --- a/tests/baselines/reference/es5-asyncFunction.js +++ b/tests/baselines/reference/es5-asyncFunction.js @@ -12,7 +12,7 @@ async function singleAwait() { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/es5-asyncFunctionTryStatements.js b/tests/baselines/reference/es5-asyncFunctionTryStatements.js index c9c5507afa7..513420dd6f4 100644 --- a/tests/baselines/reference/es5-asyncFunctionTryStatements.js +++ b/tests/baselines/reference/es5-asyncFunctionTryStatements.js @@ -1,8 +1,8 @@ //// [es5-asyncFunctionTryStatements.ts] -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; async function tryCatch0() { - var x, y; + var x: any, y: any; try { x; } @@ -12,7 +12,7 @@ async function tryCatch0() { } async function tryCatch1() { - var x, y; + var x: any, y: any; try { await x; } @@ -22,7 +22,7 @@ async function tryCatch1() { } async function tryCatch2() { - var x, y; + var x: any, y: any; try { x; } @@ -32,7 +32,7 @@ async function tryCatch2() { } async function tryCatch3(): Promise { - var x, y; + var x: any, y: any; try { await x; } @@ -41,7 +41,7 @@ async function tryCatch3(): Promise { } } async function tryFinally0() { - var x, y; + var x: any, y: any; try { x; } @@ -51,7 +51,7 @@ async function tryFinally0() { } async function tryFinally1() { - var x, y; + var x: any, y: any; try { await x; } @@ -61,7 +61,7 @@ async function tryFinally1() { } async function tryFinally2() { - var x, y; + var x: any, y: any; try { x; } @@ -71,7 +71,7 @@ async function tryFinally2() { } async function tryCatchFinally0() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -84,7 +84,7 @@ async function tryCatchFinally0() { } async function tryCatchFinally1() { - var x, y, z; + var x: any, y: any, z: any; try { await x; } @@ -97,7 +97,7 @@ async function tryCatchFinally1() { } async function tryCatchFinally2() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -110,7 +110,7 @@ async function tryCatchFinally2() { } async function tryCatchFinally3() { - var x, y, z; + var x: any, y: any, z: any; try { x; } diff --git a/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols b/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols index ecf8fbc505b..52a4ec8df76 100644 --- a/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols +++ b/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols @@ -1,18 +1,18 @@ === tests/cases/compiler/es5-asyncFunctionTryStatements.ts === -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 0, 11)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 0, 14)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 0, 17)) ->a : Symbol(a, Decl(es5-asyncFunctionTryStatements.ts, 0, 20)) ->b : Symbol(b, Decl(es5-asyncFunctionTryStatements.ts, 0, 23)) ->c : Symbol(c, Decl(es5-asyncFunctionTryStatements.ts, 0, 26)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 0, 19)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 0, 27)) +>a : Symbol(a, Decl(es5-asyncFunctionTryStatements.ts, 0, 35)) +>b : Symbol(b, Decl(es5-asyncFunctionTryStatements.ts, 0, 43)) +>c : Symbol(c, Decl(es5-asyncFunctionTryStatements.ts, 0, 51)) async function tryCatch0() { ->tryCatch0 : Symbol(tryCatch0, Decl(es5-asyncFunctionTryStatements.ts, 0, 29)) +>tryCatch0 : Symbol(tryCatch0, Decl(es5-asyncFunctionTryStatements.ts, 0, 59)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 3, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 15)) try { x; @@ -22,16 +22,16 @@ async function tryCatch0() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 7, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 15)) } } async function tryCatch1() { >tryCatch1 : Symbol(tryCatch1, Decl(es5-asyncFunctionTryStatements.ts, 10, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 13, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 15)) try { await x; @@ -41,16 +41,16 @@ async function tryCatch1() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 17, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 15)) } } async function tryCatch2() { >tryCatch2 : Symbol(tryCatch2, Decl(es5-asyncFunctionTryStatements.ts, 20, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 23, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 15)) try { x; @@ -60,7 +60,7 @@ async function tryCatch2() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 27, 11)) await y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 15)) } } @@ -69,9 +69,9 @@ async function tryCatch3(): Promise { >Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 33, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 33, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 33, 15)) try { await x; @@ -87,9 +87,9 @@ async function tryCatch3(): Promise { async function tryFinally0() { >tryFinally0 : Symbol(tryFinally0, Decl(es5-asyncFunctionTryStatements.ts, 40, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 42, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 15)) try { x; @@ -97,16 +97,16 @@ async function tryFinally0() { } finally { y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 15)) } } async function tryFinally1() { >tryFinally1 : Symbol(tryFinally1, Decl(es5-asyncFunctionTryStatements.ts, 49, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 52, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 15)) try { await x; @@ -114,16 +114,16 @@ async function tryFinally1() { } finally { y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 15)) } } async function tryFinally2() { >tryFinally2 : Symbol(tryFinally2, Decl(es5-asyncFunctionTryStatements.ts, 59, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 62, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 15)) try { x; @@ -131,17 +131,17 @@ async function tryFinally2() { } finally { await y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 15)) } } async function tryCatchFinally0() { >tryCatchFinally0 : Symbol(tryCatchFinally0, Decl(es5-asyncFunctionTryStatements.ts, 69, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 72, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 23)) try { x; @@ -151,21 +151,21 @@ async function tryCatchFinally0() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 76, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 15)) } finally { z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 23)) } } async function tryCatchFinally1() { >tryCatchFinally1 : Symbol(tryCatchFinally1, Decl(es5-asyncFunctionTryStatements.ts, 82, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 85, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 23)) try { await x; @@ -175,21 +175,21 @@ async function tryCatchFinally1() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 89, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 15)) } finally { z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 23)) } } async function tryCatchFinally2() { >tryCatchFinally2 : Symbol(tryCatchFinally2, Decl(es5-asyncFunctionTryStatements.ts, 95, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 98, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 23)) try { x; @@ -199,21 +199,21 @@ async function tryCatchFinally2() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 102, 11)) await y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 15)) } finally { z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 23)) } } async function tryCatchFinally3() { >tryCatchFinally3 : Symbol(tryCatchFinally3, Decl(es5-asyncFunctionTryStatements.ts, 108, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 111, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 23)) try { x; @@ -223,10 +223,10 @@ async function tryCatchFinally3() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 115, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 15)) } finally { await z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 23)) } } diff --git a/tests/baselines/reference/es5-asyncFunctionTryStatements.types b/tests/baselines/reference/es5-asyncFunctionTryStatements.types index ab1cd845616..f4c4536c6fc 100644 --- a/tests/baselines/reference/es5-asyncFunctionTryStatements.types +++ b/tests/baselines/reference/es5-asyncFunctionTryStatements.types @@ -1,5 +1,5 @@ === tests/cases/compiler/es5-asyncFunctionTryStatements.ts === -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; >x : any >y : any >z : any @@ -10,7 +10,7 @@ declare var x, y, z, a, b, c; async function tryCatch0() { >tryCatch0 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -29,7 +29,7 @@ async function tryCatch0() { async function tryCatch1() { >tryCatch1 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -49,7 +49,7 @@ async function tryCatch1() { async function tryCatch2() { >tryCatch2 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -71,7 +71,7 @@ async function tryCatch3(): Promise { >Promise : Promise >Function : Function - var x, y; + var x: any, y: any; >x : any >y : any @@ -91,7 +91,7 @@ async function tryCatch3(): Promise { async function tryFinally0() { >tryFinally0 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -108,7 +108,7 @@ async function tryFinally0() { async function tryFinally1() { >tryFinally1 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -126,7 +126,7 @@ async function tryFinally1() { async function tryFinally2() { >tryFinally2 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -144,7 +144,7 @@ async function tryFinally2() { async function tryCatchFinally0() { >tryCatchFinally0 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any @@ -168,7 +168,7 @@ async function tryCatchFinally0() { async function tryCatchFinally1() { >tryCatchFinally1 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any @@ -193,7 +193,7 @@ async function tryCatchFinally1() { async function tryCatchFinally2() { >tryCatchFinally2 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any @@ -218,7 +218,7 @@ async function tryCatchFinally2() { async function tryCatchFinally3() { >tryCatchFinally3 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any diff --git a/tests/baselines/reference/es5-importHelpersAsyncFunctions.js b/tests/baselines/reference/es5-importHelpersAsyncFunctions.js index 6c9a16b546f..0fd308cee3b 100644 --- a/tests/baselines/reference/es5-importHelpersAsyncFunctions.js +++ b/tests/baselines/reference/es5-importHelpersAsyncFunctions.js @@ -32,7 +32,7 @@ exports.foo = foo; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt b/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt index af17a7ddf7a..134a883540e 100644 --- a/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt +++ b/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt @@ -84,7 +84,7 @@ tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxE ==== tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts (81 errors) ==== // Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without () - var temp; + var temp: any; delete --temp ** 3; ~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/exponentiationOperatorSyntaxError2.js b/tests/baselines/reference/exponentiationOperatorSyntaxError2.js index 9e07273522f..e443b756575 100644 --- a/tests/baselines/reference/exponentiationOperatorSyntaxError2.js +++ b/tests/baselines/reference/exponentiationOperatorSyntaxError2.js @@ -1,7 +1,7 @@ //// [exponentiationOperatorSyntaxError2.ts] // Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without () -var temp; +var temp: any; delete --temp ** 3; delete ++temp ** 3; diff --git a/tests/baselines/reference/exportDefaultAsyncFunction.js b/tests/baselines/reference/exportDefaultAsyncFunction.js index a06b41b5e73..22f686b6ec8 100644 --- a/tests/baselines/reference/exportDefaultAsyncFunction.js +++ b/tests/baselines/reference/exportDefaultAsyncFunction.js @@ -7,7 +7,7 @@ foo(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/exportDefaultAsyncFunction2.js b/tests/baselines/reference/exportDefaultAsyncFunction2.js index ff242eec6a1..aed6eb6c879 100644 --- a/tests/baselines/reference/exportDefaultAsyncFunction2.js +++ b/tests/baselines/reference/exportDefaultAsyncFunction2.js @@ -38,7 +38,7 @@ export default async(() => await(Promise.resolve(1))); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/expr.errors.txt b/tests/baselines/reference/expr.errors.txt index 17e39cc80be..23215cac6ba 100644 --- a/tests/baselines/reference/expr.errors.txt +++ b/tests/baselines/reference/expr.errors.txt @@ -78,7 +78,7 @@ tests/cases/compiler/expr.ts(242,7): error TS2363: The right-hand side of an ari } function f() { - var a; + var a: any; var n=3; var s=""; var b=false; diff --git a/tests/baselines/reference/expr.js b/tests/baselines/reference/expr.js index 9baf55084c1..689ff1e27dc 100644 --- a/tests/baselines/reference/expr.js +++ b/tests/baselines/reference/expr.js @@ -7,7 +7,7 @@ enum E { } function f() { - var a; + var a: any; var n=3; var s=""; var b=false; diff --git a/tests/baselines/reference/for-inStatements.errors.txt b/tests/baselines/reference/for-inStatements.errors.txt index 7e20b8ca316..f0e6c950ebb 100644 --- a/tests/baselines/reference/for-inStatements.errors.txt +++ b/tests/baselines/reference/for-inStatements.errors.txt @@ -18,7 +18,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): for (var x in /[a-z]/) { } for (var x in new Date()) { } - var c, d, e; + var c: any, d: any, e: any; for (var x in c || d) { } for (var x in e ? c : d) { } diff --git a/tests/baselines/reference/for-inStatements.js b/tests/baselines/reference/for-inStatements.js index 4f52b5e1456..15d771bf587 100644 --- a/tests/baselines/reference/for-inStatements.js +++ b/tests/baselines/reference/for-inStatements.js @@ -15,7 +15,7 @@ for (var x in fn()) { } for (var x in /[a-z]/) { } for (var x in new Date()) { } -var c, d, e; +var c: any, d: any, e: any; for (var x in c || d) { } for (var x in e ? c : d) { } diff --git a/tests/baselines/reference/for-of3.errors.txt b/tests/baselines/reference/for-of3.errors.txt index ba8e3e4a5c6..99ed3098a63 100644 --- a/tests/baselines/reference/for-of3.errors.txt +++ b/tests/baselines/reference/for-of3.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of3.ts(2,6): error TS2487: Inva ==== tests/cases/conformance/es6/for-ofStatements/for-of3.ts (1 errors) ==== - var v; + var v: any; for (v++ of []) { } ~~~ !!! error TS2487: Invalid left-hand side in 'for...of' statement. \ No newline at end of file diff --git a/tests/baselines/reference/for-of3.js b/tests/baselines/reference/for-of3.js index 7ef27187702..15918223e6b 100644 --- a/tests/baselines/reference/for-of3.js +++ b/tests/baselines/reference/for-of3.js @@ -1,5 +1,5 @@ //// [for-of3.ts] -var v; +var v: any; for (v++ of []) { } //// [for-of3.js] diff --git a/tests/baselines/reference/forIn.errors.txt b/tests/baselines/reference/forIn.errors.txt index ccc1423f1aa..a7dd629698a 100644 --- a/tests/baselines/reference/forIn.errors.txt +++ b/tests/baselines/reference/forIn.errors.txt @@ -1,17 +1,24 @@ tests/cases/compiler/forIn.ts(2,10): error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation. +tests/cases/compiler/forIn.ts(2,22): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. +tests/cases/compiler/forIn.ts(7,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. +tests/cases/compiler/forIn.ts(18,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. tests/cases/compiler/forIn.ts(20,4): error TS2304: Cannot find name 'k'. -==== tests/cases/compiler/forIn.ts (2 errors) ==== +==== tests/cases/compiler/forIn.ts (5 errors) ==== var arr = null; for (var i:number in arr) { // error ~ !!! error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation. + ~~~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. var x1 = arr[i]; var y1 = arr[i]; } for (var j in arr) { // ok + ~~~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. var x2 = arr[j]; var y2 = arr[j]; } @@ -23,6 +30,8 @@ tests/cases/compiler/forIn.ts(20,4): error TS2304: Cannot find name 'k'. } for (var l in arr) { + ~~~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. // error in the body k[l] = 1; ~ diff --git a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt index 3acb6e47e10..36993750ccf 100644 --- a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt +++ b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt @@ -1,19 +1,23 @@ -tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(2,5): error TS7005: Variable 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(3,13): error TS7005: Variable 'foo' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(4,15): error TS7006: Parameter 'k' implicitly has an 'any' type. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(3,5): error TS7034: Variable 'y' implicitly has type 'any' in some locations where its type cannot be determined. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(4,13): error TS7005: Variable 'foo' implicitly has an 'any' type. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(5,15): error TS7006: Parameter 'k' implicitly has an 'any' type. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(5,20): error TS7005: Variable 'y' implicitly has an 'any' type. -==== tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts (3 errors) ==== +==== tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts (4 errors) ==== // this should be an error - var x; // error at "x" + var x; // no error, control flow typed + var y; // error because captured ~ -!!! error TS7005: Variable 'x' implicitly has an 'any' type. - declare var foo; // error at "foo" +!!! error TS7034: Variable 'y' implicitly has type 'any' in some locations where its type cannot be determined. + declare var foo; // error at "foo" ~~~ !!! error TS7005: Variable 'foo' implicitly has an 'any' type. - function func(k) { }; //error at "k" + function func(k) { y }; // error at "k" ~ !!! error TS7006: Parameter 'k' implicitly has an 'any' type. + ~ +!!! error TS7005: Variable 'y' implicitly has an 'any' type. func(x); // this shouldn't be an error diff --git a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js index e3c44e9b783..5770050d449 100644 --- a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js +++ b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js @@ -1,8 +1,9 @@ //// [implicitAnyDeclareVariablesWithoutTypeAndInit.ts] // this should be an error -var x; // error at "x" -declare var foo; // error at "foo" -function func(k) { }; //error at "k" +var x; // no error, control flow typed +var y; // error because captured +declare var foo; // error at "foo" +function func(k) { y }; // error at "k" func(x); // this shouldn't be an error @@ -13,9 +14,10 @@ var x1: any; var y1 = new x1; //// [implicitAnyDeclareVariablesWithoutTypeAndInit.js] // this should be an error -var x; // error at "x" -function func(k) { } -; //error at "k" +var x; // no error, control flow typed +var y; // error because captured +function func(k) { y; } +; // error at "k" func(x); // this shouldn't be an error var bar = 3; diff --git a/tests/baselines/reference/implicitAnyFunctionInvocationWithAnyArguements.errors.txt b/tests/baselines/reference/implicitAnyFunctionInvocationWithAnyArguements.errors.txt index b15fb779b51..55108bb803e 100644 --- a/tests/baselines/reference/implicitAnyFunctionInvocationWithAnyArguements.errors.txt +++ b/tests/baselines/reference/implicitAnyFunctionInvocationWithAnyArguements.errors.txt @@ -1,4 +1,3 @@ -tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(2,5): error TS7005: Variable 'arg0' implicitly has an 'any' type. tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(3,5): error TS7005: Variable 'anyArray' implicitly has an 'any[]' type. tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(4,13): error TS7008: Member 'v' implicitly has an 'any' type. tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(4,16): error TS7008: Member 'w' implicitly has an 'any' type. @@ -7,11 +6,9 @@ tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(6,16): er tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(10,36): error TS7006: Parameter 'y2' implicitly has an 'any' type. -==== tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts (7 errors) ==== +==== tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts (6 errors) ==== // this should be errors var arg0 = null; // error at "arg0" - ~~~~ -!!! error TS7005: Variable 'arg0' implicitly has an 'any' type. var anyArray = [null, undefined]; // error at array literal ~~~~~~~~ !!! error TS7005: Variable 'anyArray' implicitly has an 'any[]' type. diff --git a/tests/baselines/reference/implicitAnyWidenToAny.errors.txt b/tests/baselines/reference/implicitAnyWidenToAny.errors.txt index 3b86c52c2ea..95739a450a8 100644 --- a/tests/baselines/reference/implicitAnyWidenToAny.errors.txt +++ b/tests/baselines/reference/implicitAnyWidenToAny.errors.txt @@ -1,17 +1,11 @@ -tests/cases/compiler/implicitAnyWidenToAny.ts(2,5): error TS7005: Variable 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyWidenToAny.ts(3,5): error TS7005: Variable 'x1' implicitly has an 'any' type. tests/cases/compiler/implicitAnyWidenToAny.ts(4,5): error TS7005: Variable 'widenArray' implicitly has an 'any[]' type. tests/cases/compiler/implicitAnyWidenToAny.ts(5,5): error TS7005: Variable 'emptyArray' implicitly has an 'any[]' type. -==== tests/cases/compiler/implicitAnyWidenToAny.ts (4 errors) ==== +==== tests/cases/compiler/implicitAnyWidenToAny.ts (2 errors) ==== // these should be errors var x = null; // error at "x" - ~ -!!! error TS7005: Variable 'x' implicitly has an 'any' type. var x1 = undefined; // error at "x1" - ~~ -!!! error TS7005: Variable 'x1' implicitly has an 'any' type. var widenArray = [null, undefined]; // error at "widenArray" ~~~~~~~~~~ !!! error TS7005: Variable 'widenArray' implicitly has an 'any[]' type. diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.js b/tests/baselines/reference/incrementOperatorWithAnyOtherType.js index e99340a53e2..989d4d900d3 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.js +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.js @@ -2,7 +2,7 @@ // ++ operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols b/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols index 338ab905064..2eceb1a2431 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols @@ -4,7 +4,7 @@ var ANY: any; >ANY : Symbol(ANY, Decl(incrementOperatorWithAnyOtherType.ts, 2, 3)) -var ANY1; +var ANY1: any; >ANY1 : Symbol(ANY1, Decl(incrementOperatorWithAnyOtherType.ts, 3, 3)) var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.types b/tests/baselines/reference/incrementOperatorWithAnyOtherType.types index 715de620bff..13a39410df7 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.types @@ -4,7 +4,7 @@ var ANY: any; >ANY : any -var ANY1; +var ANY1: any; >ANY1 : any var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 92e639df21e..4aae7f5b51e 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -47,7 +47,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp ==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts (45 errors) ==== // ++ operator on any type - var ANY1; + var ANY1: any; var ANY2: any[] = [1, 2]; var obj: () => {} @@ -58,7 +58,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js index 636ca74ba08..be2726f083b 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js @@ -1,6 +1,6 @@ //// [incrementOperatorWithAnyOtherTypeInvalidOperations.ts] // ++ operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = [1, 2]; var obj: () => {} @@ -11,7 +11,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/inferenceLimit.js b/tests/baselines/reference/inferenceLimit.js index a3fa5226830..b9423ebd655 100644 --- a/tests/baselines/reference/inferenceLimit.js +++ b/tests/baselines/reference/inferenceLimit.js @@ -47,7 +47,7 @@ export interface MyModel { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.types b/tests/baselines/reference/initializePropertiesWithRenamedLet.types index 65ea68059a7..d6937da8983 100644 --- a/tests/baselines/reference/initializePropertiesWithRenamedLet.types +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.types @@ -10,15 +10,15 @@ if (true) { >x0 : any var obj1 = { x0: x0 }; ->obj1 : { x0: any; } ->{ x0: x0 } : { x0: any; } ->x0 : any ->x0 : any +>obj1 : { x0: undefined; } +>{ x0: x0 } : { x0: undefined; } +>x0 : undefined +>x0 : undefined var obj2 = { x0 }; ->obj2 : { x0: any; } ->{ x0 } : { x0: any; } ->x0 : any +>obj2 : { x0: undefined; } +>{ x0 } : { x0: undefined; } +>x0 : undefined } var x, y, z; diff --git a/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt b/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt index 4c1d237aa47..05fecf03d30 100644 --- a/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt +++ b/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt @@ -1,9 +1,15 @@ +tests/cases/compiler/a.js(1,22): error TS2528: A module cannot have multiple default exports. +tests/cases/compiler/a.js(3,1): error TS2528: A module cannot have multiple default exports. tests/cases/compiler/a.js(3,16): error TS1109: Expression expected. -==== tests/cases/compiler/a.js (1 errors) ==== +==== tests/cases/compiler/a.js (3 errors) ==== export default class a { + ~ +!!! error TS2528: A module cannot have multiple default exports. } export default var a = 10; + ~~~~~~~~~~~~~~ +!!! error TS2528: A module cannot have multiple default exports. ~~~ !!! error TS1109: Expression expected. \ No newline at end of file diff --git a/tests/baselines/reference/json.stringify.types b/tests/baselines/reference/json.stringify.types index b063b06d8d0..8ff84885d9c 100644 --- a/tests/baselines/reference/json.stringify.types +++ b/tests/baselines/reference/json.stringify.types @@ -1,7 +1,7 @@ === tests/cases/compiler/json.stringify.ts === var value = null; ->value : null +>value : any >null : null JSON.stringify(value, undefined, 2); diff --git a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.js b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.js index 9a5ed619b2d..180b53028ff 100644 --- a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.js +++ b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.js @@ -85,7 +85,7 @@ const o1 = { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.js b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.js index c4c2d6853af..cf69f260223 100644 --- a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.js +++ b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.js @@ -85,7 +85,7 @@ const o1 = { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.js b/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.js index 8736c51cd16..350113ec6a0 100644 --- a/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.js +++ b/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.js @@ -85,7 +85,7 @@ const o1 = { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/multipleDefaultExports01.errors.txt b/tests/baselines/reference/multipleDefaultExports01.errors.txt index b3e7d757289..16aa3b2f7b1 100644 --- a/tests/baselines/reference/multipleDefaultExports01.errors.txt +++ b/tests/baselines/reference/multipleDefaultExports01.errors.txt @@ -1,16 +1,13 @@ -tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2323: Cannot redeclare exported variable 'default'. tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2528: A module cannot have multiple default exports. tests/cases/conformance/es6/modules/m1.ts(6,25): error TS2528: A module cannot have multiple default exports. -tests/cases/conformance/es6/modules/m1.ts(11,1): error TS2323: Cannot redeclare exported variable 'default'. +tests/cases/conformance/es6/modules/m1.ts(11,1): error TS2528: A module cannot have multiple default exports. tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof foo' is not callable. Did you mean to include 'new'? -==== tests/cases/conformance/es6/modules/m1.ts (4 errors) ==== +==== tests/cases/conformance/es6/modules/m1.ts (3 errors) ==== export default class foo { ~~~ -!!! error TS2323: Cannot redeclare exported variable 'default'. - ~~~ !!! error TS2528: A module cannot have multiple default exports. } @@ -24,7 +21,7 @@ tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typ var x = 10; export default x; ~~~~~~~~~~~~~~~~~ -!!! error TS2323: Cannot redeclare exported variable 'default'. +!!! error TS2528: A module cannot have multiple default exports. ==== tests/cases/conformance/es6/modules/m2.ts (1 errors) ==== import Entity from "./m1" diff --git a/tests/baselines/reference/multipleExportDefault1.errors.txt b/tests/baselines/reference/multipleExportDefault1.errors.txt new file mode 100644 index 00000000000..3da6afc41e0 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault1.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/externalModules/multipleExportDefault1.ts(1,25): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault1.ts(5,1): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault1.ts (2 errors) ==== + export default function Foo (){ + ~~~ +!!! error TS2528: A module cannot have multiple default exports. + + } + + export default { + ~~~~~~~~~~~~~~~~ + uhoh: "another default", + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }; + ~~ +!!! error TS2528: A module cannot have multiple default exports. + \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault1.js b/tests/baselines/reference/multipleExportDefault1.js new file mode 100644 index 00000000000..bec4fb48969 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault1.js @@ -0,0 +1,20 @@ +//// [multipleExportDefault1.ts] +export default function Foo (){ + +} + +export default { + uhoh: "another default", +}; + + +//// [multipleExportDefault1.js] +"use strict"; +function Foo() { +} +exports.__esModule = true; +exports["default"] = Foo; +exports.__esModule = true; +exports["default"] = { + uhoh: "another default" +}; diff --git a/tests/baselines/reference/multipleExportDefault2.errors.txt b/tests/baselines/reference/multipleExportDefault2.errors.txt new file mode 100644 index 00000000000..0543e25a163 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/externalModules/multipleExportDefault2.ts(1,1): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault2.ts(5,25): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault2.ts (2 errors) ==== + export default { + ~~~~~~~~~~~~~~~~ + uhoh: "another default", + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }; + ~~ +!!! error TS2528: A module cannot have multiple default exports. + + export default function Foo() { } + ~~~ +!!! error TS2528: A module cannot have multiple default exports. + + \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault2.js b/tests/baselines/reference/multipleExportDefault2.js new file mode 100644 index 00000000000..dc82500a1d9 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault2.js @@ -0,0 +1,18 @@ +//// [multipleExportDefault2.ts] +export default { + uhoh: "another default", +}; + +export default function Foo() { } + + + +//// [multipleExportDefault2.js] +"use strict"; +exports.__esModule = true; +exports["default"] = { + uhoh: "another default" +}; +function Foo() { } +exports.__esModule = true; +exports["default"] = Foo; diff --git a/tests/baselines/reference/multipleExportDefault3.errors.txt b/tests/baselines/reference/multipleExportDefault3.errors.txt new file mode 100644 index 00000000000..f1e55da9112 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault3.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/externalModules/multipleExportDefault3.ts(1,1): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault3.ts(5,22): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault3.ts (2 errors) ==== + export default { + ~~~~~~~~~~~~~~~~ + uhoh: "another default", + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }; + ~~ +!!! error TS2528: A module cannot have multiple default exports. + + export default class C { } + ~ +!!! error TS2528: A module cannot have multiple default exports. + + \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault3.js b/tests/baselines/reference/multipleExportDefault3.js new file mode 100644 index 00000000000..5d7ad48e0ca --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault3.js @@ -0,0 +1,22 @@ +//// [multipleExportDefault3.ts] +export default { + uhoh: "another default", +}; + +export default class C { } + + + +//// [multipleExportDefault3.js] +"use strict"; +exports.__esModule = true; +exports["default"] = { + uhoh: "another default" +}; +var C = (function () { + function C() { + } + return C; +}()); +exports.__esModule = true; +exports["default"] = C; diff --git a/tests/baselines/reference/multipleExportDefault4.errors.txt b/tests/baselines/reference/multipleExportDefault4.errors.txt new file mode 100644 index 00000000000..bba15527d00 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault4.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/externalModules/multipleExportDefault4.ts(1,22): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault4.ts(3,1): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault4.ts (2 errors) ==== + export default class C { } + ~ +!!! error TS2528: A module cannot have multiple default exports. + + export default { + ~~~~~~~~~~~~~~~~ + uhoh: "another default", + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }; + ~~ +!!! error TS2528: A module cannot have multiple default exports. \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault4.js b/tests/baselines/reference/multipleExportDefault4.js new file mode 100644 index 00000000000..1199fa91c9c --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault4.js @@ -0,0 +1,20 @@ +//// [multipleExportDefault4.ts] +export default class C { } + +export default { + uhoh: "another default", +}; + +//// [multipleExportDefault4.js] +"use strict"; +var C = (function () { + function C() { + } + return C; +}()); +exports.__esModule = true; +exports["default"] = C; +exports.__esModule = true; +exports["default"] = { + uhoh: "another default" +}; diff --git a/tests/baselines/reference/multipleExportDefault5.errors.txt b/tests/baselines/reference/multipleExportDefault5.errors.txt new file mode 100644 index 00000000000..30c87339ff2 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault5.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/externalModules/multipleExportDefault5.ts(1,25): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault5.ts(2,22): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault5.ts (2 errors) ==== + export default function bar() { } + ~~~ +!!! error TS2528: A module cannot have multiple default exports. + export default class C {} + ~ +!!! error TS2528: A module cannot have multiple default exports. \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault5.js b/tests/baselines/reference/multipleExportDefault5.js new file mode 100644 index 00000000000..7ae33aee9f4 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault5.js @@ -0,0 +1,16 @@ +//// [multipleExportDefault5.ts] +export default function bar() { } +export default class C {} + +//// [multipleExportDefault5.js] +"use strict"; +function bar() { } +exports.__esModule = true; +exports["default"] = bar; +var C = (function () { + function C() { + } + return C; +}()); +exports.__esModule = true; +exports["default"] = C; diff --git a/tests/baselines/reference/multipleExportDefault6.errors.txt b/tests/baselines/reference/multipleExportDefault6.errors.txt new file mode 100644 index 00000000000..a8bf80e8df0 --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault6.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/externalModules/multipleExportDefault6.ts(1,1): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/externalModules/multipleExportDefault6.ts(5,1): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/conformance/externalModules/multipleExportDefault6.ts (2 errors) ==== + export default { + ~~~~~~~~~~~~~~~~ + lol: 1 + ~~~~~~~~~~ + } + ~ +!!! error TS2528: A module cannot have multiple default exports. + + export default { + ~~~~~~~~~~~~~~~~ + lol: 2 + ~~~~~~~~~~ + } + ~ +!!! error TS2528: A module cannot have multiple default exports. \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportDefault6.js b/tests/baselines/reference/multipleExportDefault6.js new file mode 100644 index 00000000000..a8b93459e4e --- /dev/null +++ b/tests/baselines/reference/multipleExportDefault6.js @@ -0,0 +1,19 @@ +//// [multipleExportDefault6.ts] +export default { + lol: 1 +} + +export default { + lol: 2 +} + +//// [multipleExportDefault6.js] +"use strict"; +exports.__esModule = true; +exports["default"] = { + lol: 1 +}; +exports.__esModule = true; +exports["default"] = { + lol: 2 +}; diff --git a/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt index f008b4698ed..03e596aca41 100644 --- a/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperator // - operator on any type var ANY: any; - var ANY1; + var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = { x: "", y: () => { }}; @@ -16,7 +16,7 @@ tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperator } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/negateOperatorWithAnyOtherType.js b/tests/baselines/reference/negateOperatorWithAnyOtherType.js index 6a2fe74c7ba..eb5f70d8c9c 100644 --- a/tests/baselines/reference/negateOperatorWithAnyOtherType.js +++ b/tests/baselines/reference/negateOperatorWithAnyOtherType.js @@ -2,7 +2,7 @@ // - operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = { x: "", y: () => { }}; @@ -13,7 +13,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.types b/tests/baselines/reference/nestedBlockScopedBindings3.types index 0de8123861d..ca13759bac4 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings3.types +++ b/tests/baselines/reference/nestedBlockScopedBindings3.types @@ -31,7 +31,7 @@ function a1() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : undefined >1 : 1 () => x; @@ -53,24 +53,24 @@ function a2() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -82,14 +82,14 @@ function a3() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } switch (1) { @@ -111,14 +111,14 @@ function a4() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; @@ -145,14 +145,14 @@ function a5() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.types b/tests/baselines/reference/nestedBlockScopedBindings4.types index 65b5d73db9d..9e0147f25f7 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings4.types +++ b/tests/baselines/reference/nestedBlockScopedBindings4.types @@ -5,24 +5,24 @@ function a0() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -33,14 +33,14 @@ function a1() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; @@ -51,10 +51,10 @@ function a1() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -65,24 +65,24 @@ function a2() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; @@ -98,14 +98,14 @@ function a3() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; @@ -116,10 +116,10 @@ function a3() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.types b/tests/baselines/reference/nestedBlockScopedBindings6.types index 865dea31e37..bf38f46d508 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings6.types +++ b/tests/baselines/reference/nestedBlockScopedBindings6.types @@ -18,10 +18,10 @@ function a0() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -49,10 +49,10 @@ function a1() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -76,10 +76,10 @@ function a2() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; @@ -111,10 +111,10 @@ function a3() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; diff --git a/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt b/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt index f7e6475b971..cedbbc8ed3d 100644 --- a/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt +++ b/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt @@ -2,14 +2,10 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,5): error TS1 tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,6): error TS7031: Binding element 'a' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,10): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,11): error TS7031: Binding element 'b' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,15): error TS7005: Variable 'c' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,18): error TS7005: Variable 'd' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,5): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,6): error TS7031: Binding element 'a1' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,23): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,24): error TS7031: Binding element 'b1' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,36): error TS7005: Variable 'c1' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,52): error TS7005: Variable 'd1' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(5,5): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(5,18): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,5): error TS1182: A destructuring declaration must have an initializer. @@ -17,12 +13,10 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,13): error TS tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,25): error TS7008: Member 'b3' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,6): error TS7031: Binding element 'a4' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,26): error TS7031: Binding element 'b4' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,46): error TS7005: Variable 'c4' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,62): error TS7005: Variable 'd4' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS7031: Binding element 'a5' implicitly has an 'any' type. -==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (22 errors) ==== +==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (16 errors) ==== var [a], {b}, c, d; // error ~~~ !!! error TS1182: A destructuring declaration must have an initializer. @@ -32,10 +26,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS !!! error TS1182: A destructuring declaration must have an initializer. ~ !!! error TS7031: Binding element 'b' implicitly has an 'any' type. - ~ -!!! error TS7005: Variable 'c' implicitly has an 'any' type. - ~ -!!! error TS7005: Variable 'd' implicitly has an 'any' type. var [a1 = undefined], {b1 = null}, c1 = undefined, d1 = null; // error ~~~~~~~~~~~~~~~~ @@ -46,10 +36,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS !!! error TS1182: A destructuring declaration must have an initializer. ~~ !!! error TS7031: Binding element 'b1' implicitly has an 'any' type. - ~~ -!!! error TS7005: Variable 'c1' implicitly has an 'any' type. - ~~ -!!! error TS7005: Variable 'd1' implicitly has an 'any' type. var [a2]: [any], {b2}: { b2: any }, c2: any, d2: any; ~~~~ @@ -70,10 +56,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS !!! error TS7031: Binding element 'a4' implicitly has an 'any' type. ~~ !!! error TS7031: Binding element 'b4' implicitly has an 'any' type. - ~~ -!!! error TS7005: Variable 'c4' implicitly has an 'any' type. - ~~ -!!! error TS7005: Variable 'd4' implicitly has an 'any' type. var [a5 = undefined] = []; // error ~~ diff --git a/tests/baselines/reference/noImplicitAnyForIn.errors.txt b/tests/baselines/reference/noImplicitAnyForIn.errors.txt index 2fb8e5a4103..69b5cd34906 100644 --- a/tests/baselines/reference/noImplicitAnyForIn.errors.txt +++ b/tests/baselines/reference/noImplicitAnyForIn.errors.txt @@ -1,11 +1,10 @@ tests/cases/compiler/noImplicitAnyForIn.ts(8,18): error TS7017: Index signature of object type implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyForIn.ts(15,18): error TS7017: Index signature of object type implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyForIn.ts(21,9): error TS7005: Variable 'b' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyForIn.ts(29,5): error TS7005: Variable 'n' implicitly has an 'any[][]' type. tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -==== tests/cases/compiler/noImplicitAnyForIn.ts (5 errors) ==== +==== tests/cases/compiler/noImplicitAnyForIn.ts (4 errors) ==== var x: {}[] = [[1, 2, 3], ["hello"]]; @@ -31,8 +30,6 @@ tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand si for (var a in x) { // Should yield an implicit 'any' error. var b; - ~ -!!! error TS7005: Variable 'b' implicitly has an 'any' type. var c = a || b; } diff --git a/tests/baselines/reference/noImplicitReturnsInAsync1.js b/tests/baselines/reference/noImplicitReturnsInAsync1.js index 6192e9e7f24..5274264a6b1 100644 --- a/tests/baselines/reference/noImplicitReturnsInAsync1.js +++ b/tests/baselines/reference/noImplicitReturnsInAsync1.js @@ -11,7 +11,7 @@ async function test(isError: boolean = false) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/noImplicitReturnsInAsync2.js b/tests/baselines/reference/noImplicitReturnsInAsync2.js index 5e034237fef..93f8c97d1fb 100644 --- a/tests/baselines/reference/noImplicitReturnsInAsync2.js +++ b/tests/baselines/reference/noImplicitReturnsInAsync2.js @@ -40,7 +40,7 @@ async function test7(isError: boolean = true) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/null.types b/tests/baselines/reference/null.types index 35c084c3cbf..ab5ae728dea 100644 --- a/tests/baselines/reference/null.types +++ b/tests/baselines/reference/null.types @@ -5,10 +5,10 @@ var x=null; >null : null var y=3+x; ->y : any ->3+x : any +>y : number +>3+x : number >3 : 3 ->x : any +>x : null var z=3+null; >z : number diff --git a/tests/baselines/reference/objectLiteralShorthandProperties.types b/tests/baselines/reference/objectLiteralShorthandProperties.types index 4f4482906aa..168fcc07af7 100644 --- a/tests/baselines/reference/objectLiteralShorthandProperties.types +++ b/tests/baselines/reference/objectLiteralShorthandProperties.types @@ -5,35 +5,35 @@ var a, b, c; >c : any var x1 = { ->x1 : { a: any; } ->{ a} : { a: any; } +>x1 : { a: undefined; } +>{ a} : { a: undefined; } a ->a : any +>a : undefined }; var x2 = { ->x2 : { a: any; } ->{ a,} : { a: any; } +>x2 : { a: undefined; } +>{ a,} : { a: undefined; } a, ->a : any +>a : undefined } var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: undefined; c: undefined; d(): void; x3: any; parent: any; } a: 0, >a : number >0 : 0 b, ->b : any +>b : undefined c, ->c : any +>c : undefined d() { }, >d : () => void diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types index 1565be04625..80cbe304040 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types @@ -5,35 +5,35 @@ var a, b, c; >c : any var x1 = { ->x1 : { a: any; } ->{ a} : { a: any; } +>x1 : { a: undefined; } +>{ a} : { a: undefined; } a ->a : any +>a : undefined }; var x2 = { ->x2 : { a: any; } ->{ a,} : { a: any; } +>x2 : { a: undefined; } +>{ a,} : { a: undefined; } a, ->a : any +>a : undefined } var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: undefined; c: undefined; d(): void; x3: any; parent: any; } a: 0, >a : number >0 : 0 b, ->b : any +>b : undefined c, ->c : any +>c : undefined d() { }, >d : () => void diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types index 234375fb46d..ca7d65c9c34 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types @@ -10,12 +10,12 @@ function f1() { if (a < b || b > (c + 1)) { } >a < b || b > (c + 1) : boolean >a < b : boolean ->a : any ->b : any +>a : undefined +>b : undefined >b > (c + 1) : boolean ->b : any ->(c + 1) : any ->c + 1 : any ->c : any +>b : undefined +>(c + 1) : number +>c + 1 : number +>c : undefined >1 : 1 } diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types index ed3b4b903bb..f4c1c2ac690 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types @@ -10,12 +10,12 @@ function f() { if (a < b && b > (c + 1)) { } >a < b && b > (c + 1) : boolean >a < b : boolean ->a : any ->b : any +>a : undefined +>b : undefined >b > (c + 1) : boolean ->b : any ->(c + 1) : any ->c + 1 : any ->c : any +>b : undefined +>(c + 1) : number +>c + 1 : number +>c : undefined >1 : 1 } diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types index 61601d8bdf6..b1129656342 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types @@ -10,13 +10,13 @@ function f() { if (a < b && b < (c + 1)) { } >a < b && b < (c + 1) : boolean >a < b : boolean ->a : any ->b : any +>a : undefined +>b : undefined >b < (c + 1) : boolean ->b : any ->(c + 1) : any ->c + 1 : any ->c : any +>b : undefined +>(c + 1) : number +>c + 1 : number +>c : undefined >1 : 1 } diff --git a/tests/baselines/reference/parserharness.errors.txt b/tests/baselines/reference/parserharness.errors.txt index d3d0c4056a1..90ac8e0e760 100644 --- a/tests/baselines/reference/parserharness.errors.txt +++ b/tests/baselines/reference/parserharness.errors.txt @@ -25,6 +25,9 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(776,42): e tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(781,23): error TS2503: Cannot find namespace 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(794,49): error TS2304: Cannot find name 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(795,49): error TS2304: Cannot find name 'TypeScript'. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(820,31): error TS2339: Property 'length' does not exist on type 'null'. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(976,28): error TS2339: Property 'length' does not exist on type 'null'. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(977,82): error TS2339: Property 'join' does not exist on type 'null'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,53): error TS2304: Cannot find name 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,89): error TS2304: Cannot find name 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,115): error TS2503: Cannot find namespace 'TypeScript'. @@ -110,7 +113,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(1787,68): tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): error TS2304: Cannot find name 'Diff'. -==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (110 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (113 errors) ==== // // Copyright (c) Microsoft Corporation. All rights reserved. // @@ -985,6 +988,8 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): }) return errors.length === 0; + ~~~~~~ +!!! error TS2339: Property 'length' does not exist on type 'null'. } public isSubtypeOf(other: Type) { @@ -1141,7 +1146,11 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): }) if (errors.length > 0) + ~~~~~~ +!!! error TS2339: Property 'length' does not exist on type 'null'. throw new Error("Type definition contains errors: " + errors.join(",")); + ~~~~ +!!! error TS2339: Property 'join' does not exist on type 'null'. var matchingIdentifiers: Type[] = []; diff --git a/tests/baselines/reference/promiseType.js b/tests/baselines/reference/promiseType.js index fc49dda9db4..9fbdb2ab2b6 100644 --- a/tests/baselines/reference/promiseType.js +++ b/tests/baselines/reference/promiseType.js @@ -159,7 +159,7 @@ const p85 = p.then(() => Promise.reject(1), () => Promise.reject(1)); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/promiseTypeStrictNull.js b/tests/baselines/reference/promiseTypeStrictNull.js index cba4f7735ce..8c5cef4c7c4 100644 --- a/tests/baselines/reference/promiseTypeStrictNull.js +++ b/tests/baselines/reference/promiseTypeStrictNull.js @@ -159,7 +159,7 @@ const p85 = p.then(() => Promise.reject(1), () => Promise.reject(1)); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/protoAsIndexInIndexExpression.types b/tests/baselines/reference/protoAsIndexInIndexExpression.types index b761aa2c7a7..6d1374d1f78 100644 --- a/tests/baselines/reference/protoAsIndexInIndexExpression.types +++ b/tests/baselines/reference/protoAsIndexInIndexExpression.types @@ -14,11 +14,11 @@ var WorkspacePrototype = { } }; WorkspacePrototype['__proto__'] = EntityPrototype; ->WorkspacePrototype['__proto__'] = EntityPrototype : any +>WorkspacePrototype['__proto__'] = EntityPrototype : undefined >WorkspacePrototype['__proto__'] : any >WorkspacePrototype : { serialize: () => any; } >'__proto__' : "___proto__" ->EntityPrototype : any +>EntityPrototype : undefined var o = { >o : { "__proto__": number; } diff --git a/tests/baselines/reference/reachabilityChecks7.js b/tests/baselines/reference/reachabilityChecks7.js index 0a6b5b0dac7..b8334f4276b 100644 --- a/tests/baselines/reference/reachabilityChecks7.js +++ b/tests/baselines/reference/reachabilityChecks7.js @@ -34,7 +34,7 @@ let x1 = () => { use("Test"); } var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/strictNullChecksNoWidening.types b/tests/baselines/reference/strictNullChecksNoWidening.types index a544f9cef94..375977ae375 100644 --- a/tests/baselines/reference/strictNullChecksNoWidening.types +++ b/tests/baselines/reference/strictNullChecksNoWidening.types @@ -1,11 +1,11 @@ === tests/cases/conformance/types/typeRelationships/widenedTypes/strictNullChecksNoWidening.ts === var a1 = null; ->a1 : null +>a1 : any >null : null var a2 = undefined; ->a2 : undefined +>a2 : any >undefined : undefined var a3 = void 0; diff --git a/tests/baselines/reference/transformNestedGeneratorsWithTry.js b/tests/baselines/reference/transformNestedGeneratorsWithTry.js index 4ad1b2b7e88..69273e62633 100644 --- a/tests/baselines/reference/transformNestedGeneratorsWithTry.js +++ b/tests/baselines/reference/transformNestedGeneratorsWithTry.js @@ -27,7 +27,7 @@ declare module "bluebird" { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); diff --git a/tests/baselines/reference/tsxEmit1.types b/tests/baselines/reference/tsxEmit1.types index 84f00b4758a..c3ca7a2b1b0 100644 --- a/tests/baselines/reference/tsxEmit1.types +++ b/tests/baselines/reference/tsxEmit1.types @@ -61,7 +61,7 @@ var selfClosed7 =
; >
: JSX.Element >div : any >x : any ->p : any +>p : undefined >y : any var openClosed1 =
; @@ -82,7 +82,7 @@ var openClosed3 =
{p}
; >
{p}
: JSX.Element >div : any >n : any ->p : any +>p : undefined >div : any var openClosed4 =
{p < p}
; @@ -91,8 +91,8 @@ var openClosed4 =
{p < p}
; >div : any >n : any >p < p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any var openClosed5 =
{p > p}
; @@ -101,8 +101,8 @@ var openClosed5 =
{p > p}
; >div : any >n : any >p > p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any class SomeClass { @@ -180,7 +180,7 @@ var whitespace2 =
{p}
; >whitespace2 : JSX.Element >
{p}
: JSX.Element >div : any ->p : any +>p : undefined >div : any var whitespace3 =
@@ -189,7 +189,7 @@ var whitespace3 =
>div : any {p} ->p : any +>p : undefined
; >div : any diff --git a/tests/baselines/reference/tsxEmit2.types b/tests/baselines/reference/tsxEmit2.types index 5b267d8b802..d306dc9ffe0 100644 --- a/tests/baselines/reference/tsxEmit2.types +++ b/tests/baselines/reference/tsxEmit2.types @@ -22,16 +22,16 @@ var spreads1 =
{p2}
; >spreads1 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads2 =
{p2}
; >spreads2 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads3 =
{p2}
; @@ -39,19 +39,19 @@ var spreads3 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p3 : any ->p1 : any ->p2 : any +>p3 : undefined +>p1 : undefined +>p2 : undefined >div : any var spreads4 =
{p2}
; >spreads4 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any +>p1 : undefined >x : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any var spreads5 =
{p2}
; @@ -59,10 +59,10 @@ var spreads5 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p2 : any ->p1 : any +>p2 : undefined +>p1 : undefined >y : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js index e77e832cb0a..7dbb2477db5 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js @@ -3,7 +3,7 @@ declare module JSX { interface Element { isElement; } } -var T, T1, T2; +var T: any, T1: any, T2: any; // This is an element var x1 = () => {}; diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols b/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols index 6d90c583a66..2d3c1f18d48 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols @@ -7,10 +7,10 @@ declare module JSX { >isElement : Symbol(Element.isElement, Decl(file.tsx, 1, 20)) } -var T, T1, T2; +var T: any, T1: any, T2: any; >T : Symbol(T, Decl(file.tsx, 4, 3)) ->T1 : Symbol(T1, Decl(file.tsx, 4, 6)) ->T2 : Symbol(T2, Decl(file.tsx, 4, 10)) +>T1 : Symbol(T1, Decl(file.tsx, 4, 11)) +>T2 : Symbol(T2, Decl(file.tsx, 4, 20)) // This is an element var x1 = () => {}; diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.types b/tests/baselines/reference/tsxGenericArrowFunctionParsing.types index 693f920195d..0f746a07136 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.types +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.types @@ -7,7 +7,7 @@ declare module JSX { >isElement : any } -var T, T1, T2; +var T: any, T1: any, T2: any; >T : any >T1 : any >T2 : any diff --git a/tests/baselines/reference/tsxReactEmit1.types b/tests/baselines/reference/tsxReactEmit1.types index 8eb14e91963..b2cb2f73eba 100644 --- a/tests/baselines/reference/tsxReactEmit1.types +++ b/tests/baselines/reference/tsxReactEmit1.types @@ -63,7 +63,7 @@ var selfClosed7 =
; >
: JSX.Element >div : any >x : any ->p : any +>p : undefined >y : any >b : any @@ -85,7 +85,7 @@ var openClosed3 =
{p}
; >
{p}
: JSX.Element >div : any >n : any ->p : any +>p : undefined >div : any var openClosed4 =
{p < p}
; @@ -94,8 +94,8 @@ var openClosed4 =
{p < p}
; >div : any >n : any >p < p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any var openClosed5 =
{p > p}
; @@ -105,8 +105,8 @@ var openClosed5 =
{p > p}
; >n : any >b : any >p > p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any class SomeClass { @@ -184,7 +184,7 @@ var whitespace2 =
{p}
; >whitespace2 : JSX.Element >
{p}
: JSX.Element >div : any ->p : any +>p : undefined >div : any var whitespace3 =
@@ -193,7 +193,7 @@ var whitespace3 =
>div : any {p} ->p : any +>p : undefined
; >div : any diff --git a/tests/baselines/reference/tsxReactEmit2.types b/tests/baselines/reference/tsxReactEmit2.types index 928eeecadfa..b05764e996f 100644 --- a/tests/baselines/reference/tsxReactEmit2.types +++ b/tests/baselines/reference/tsxReactEmit2.types @@ -24,16 +24,16 @@ var spreads1 =
{p2}
; >spreads1 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads2 =
{p2}
; >spreads2 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads3 =
{p2}
; @@ -41,19 +41,19 @@ var spreads3 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p3 : any ->p1 : any ->p2 : any +>p3 : undefined +>p1 : undefined +>p2 : undefined >div : any var spreads4 =
{p2}
; >spreads4 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any +>p1 : undefined >x : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any var spreads5 =
{p2}
; @@ -61,10 +61,10 @@ var spreads5 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p2 : any ->p1 : any +>p2 : undefined +>p1 : undefined >y : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any diff --git a/tests/baselines/reference/tsxReactEmit5.types b/tests/baselines/reference/tsxReactEmit5.types index fb1c6594f30..73e7e6ff391 100644 --- a/tests/baselines/reference/tsxReactEmit5.types +++ b/tests/baselines/reference/tsxReactEmit5.types @@ -32,6 +32,6 @@ var spread1 =
; >
: JSX.Element >div : any >x : any ->foo : any +>foo : undefined >y : any diff --git a/tests/baselines/reference/tsxReactEmit6.types b/tests/baselines/reference/tsxReactEmit6.types index b8a307eb9d7..ae56de052cc 100644 --- a/tests/baselines/reference/tsxReactEmit6.types +++ b/tests/baselines/reference/tsxReactEmit6.types @@ -35,7 +35,7 @@ namespace M { >
: JSX.Element >div : any >x : any ->foo : any +>foo : undefined >y : any // Quotes diff --git a/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.errors.txt b/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.errors.txt new file mode 100644 index 00000000000..3f8cdf56c3d --- /dev/null +++ b/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/file1.ts(3,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. + + +==== tests/cases/compiler/file2.ts (0 errors) ==== + import f = require('./file1'); + f.foo(); + +==== tests/cases/compiler/file1.ts (1 errors) ==== + export function foo() { + var classes = undefined; + return new classes(null); + ~~~~~~~~~~~~~~~~~ +!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. + } + \ No newline at end of file diff --git a/tests/baselines/reference/unusedSwitchStatment.errors.txt b/tests/baselines/reference/unusedSwitchStatment.errors.txt index a22c252f60d..591e9deca7a 100644 --- a/tests/baselines/reference/unusedSwitchStatment.errors.txt +++ b/tests/baselines/reference/unusedSwitchStatment.errors.txt @@ -4,9 +4,10 @@ tests/cases/compiler/unusedSwitchStatment.ts(7,15): error TS6133: 'c' is declare tests/cases/compiler/unusedSwitchStatment.ts(10,13): error TS6133: 'z' is declared but never used. tests/cases/compiler/unusedSwitchStatment.ts(15,10): error TS2678: Type '0' is not comparable to type '2'. tests/cases/compiler/unusedSwitchStatment.ts(17,10): error TS2678: Type '1' is not comparable to type '2'. +tests/cases/compiler/unusedSwitchStatment.ts(18,9): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -==== tests/cases/compiler/unusedSwitchStatment.ts (6 errors) ==== +==== tests/cases/compiler/unusedSwitchStatment.ts (7 errors) ==== switch (1) { case 0: @@ -37,4 +38,6 @@ tests/cases/compiler/unusedSwitchStatment.ts(17,10): error TS2678: Type '1' is n ~ !!! error TS2678: Type '1' is not comparable to type '2'. x++; + ~ +!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. } \ No newline at end of file diff --git a/tests/cases/compiler/anyPlusAny1.ts b/tests/cases/compiler/anyPlusAny1.ts index 084dcc02be3..c1bee9b97b0 100644 --- a/tests/cases/compiler/anyPlusAny1.ts +++ b/tests/cases/compiler/anyPlusAny1.ts @@ -1,3 +1,3 @@ -var x; +var x: any; x.name = "hello"; var z = x + x; \ No newline at end of file diff --git a/tests/cases/compiler/controlFlowLetVar.ts b/tests/cases/compiler/controlFlowLetVar.ts new file mode 100644 index 00000000000..a56a3382642 --- /dev/null +++ b/tests/cases/compiler/controlFlowLetVar.ts @@ -0,0 +1,129 @@ +// @strictNullChecks: true + +declare let cond: boolean; + +// CFA for 'let' with no type annotation and initializer +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'let' with with type annotation +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'var' with with type annotation +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// No CFA for captured outer variables +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + } +} + +// No CFA for captured outer variables +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + }; +} \ No newline at end of file diff --git a/tests/cases/compiler/controlFlowNoImplicitAny.ts b/tests/cases/compiler/controlFlowNoImplicitAny.ts new file mode 100644 index 00000000000..a388a495f08 --- /dev/null +++ b/tests/cases/compiler/controlFlowNoImplicitAny.ts @@ -0,0 +1,130 @@ +// @strictNullChecks: true +// @noImplicitAny: true + +declare let cond: boolean; + +// CFA for 'let' with no type annotation and initializer +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'let' with with type annotation +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'var' with with type annotation +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// No CFA for captured outer variables +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + } +} + +// No CFA for captured outer variables +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + }; +} \ No newline at end of file diff --git a/tests/cases/compiler/es5-asyncFunctionTryStatements.ts b/tests/cases/compiler/es5-asyncFunctionTryStatements.ts index 11459295f47..0d14b5f4242 100644 --- a/tests/cases/compiler/es5-asyncFunctionTryStatements.ts +++ b/tests/cases/compiler/es5-asyncFunctionTryStatements.ts @@ -1,10 +1,10 @@ // @lib: es5,es2015.promise // @noEmitHelpers: true // @target: ES5 -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; async function tryCatch0() { - var x, y; + var x: any, y: any; try { x; } @@ -14,7 +14,7 @@ async function tryCatch0() { } async function tryCatch1() { - var x, y; + var x: any, y: any; try { await x; } @@ -24,7 +24,7 @@ async function tryCatch1() { } async function tryCatch2() { - var x, y; + var x: any, y: any; try { x; } @@ -34,7 +34,7 @@ async function tryCatch2() { } async function tryCatch3(): Promise { - var x, y; + var x: any, y: any; try { await x; } @@ -43,7 +43,7 @@ async function tryCatch3(): Promise { } } async function tryFinally0() { - var x, y; + var x: any, y: any; try { x; } @@ -53,7 +53,7 @@ async function tryFinally0() { } async function tryFinally1() { - var x, y; + var x: any, y: any; try { await x; } @@ -63,7 +63,7 @@ async function tryFinally1() { } async function tryFinally2() { - var x, y; + var x: any, y: any; try { x; } @@ -73,7 +73,7 @@ async function tryFinally2() { } async function tryCatchFinally0() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -86,7 +86,7 @@ async function tryCatchFinally0() { } async function tryCatchFinally1() { - var x, y, z; + var x: any, y: any, z: any; try { await x; } @@ -99,7 +99,7 @@ async function tryCatchFinally1() { } async function tryCatchFinally2() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -112,7 +112,7 @@ async function tryCatchFinally2() { } async function tryCatchFinally3() { - var x, y, z; + var x: any, y: any, z: any; try { x; } diff --git a/tests/cases/compiler/expr.ts b/tests/cases/compiler/expr.ts index b76aba88103..8d6f7beed7e 100644 --- a/tests/cases/compiler/expr.ts +++ b/tests/cases/compiler/expr.ts @@ -6,7 +6,7 @@ enum E { } function f() { - var a; + var a: any; var n=3; var s=""; var b=false; diff --git a/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts b/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts index 88812001c9e..a84ab03f4b3 100644 --- a/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts +++ b/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts @@ -1,8 +1,9 @@ // @noimplicitany: true // this should be an error -var x; // error at "x" -declare var foo; // error at "foo" -function func(k) { }; //error at "k" +var x; // no error, control flow typed +var y; // error because captured +declare var foo; // error at "foo" +function func(k) { y }; // error at "k" func(x); // this shouldn't be an error diff --git a/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts b/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts index 07c95eb27d9..6bfce5fc58d 100644 --- a/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts +++ b/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts @@ -1,6 +1,6 @@ //@target: ES5 module M { - var Symbol; + var Symbol: any; export class C { [Symbol.iterator]() { } diff --git a/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts b/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts index 262e47557f8..a6eecc72124 100644 --- a/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts +++ b/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts @@ -1,5 +1,5 @@ //@target: ES5 -var Symbol; +var Symbol: any; class C { [Symbol.iterator]() { } diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of3.ts b/tests/cases/conformance/es6/for-ofStatements/for-of3.ts index 7eb1e1fd220..850daee8368 100644 --- a/tests/cases/conformance/es6/for-ofStatements/for-of3.ts +++ b/tests/cases/conformance/es6/for-ofStatements/for-of3.ts @@ -1,3 +1,3 @@ //@target: ES6 -var v; +var v: any; for (v++ of []) { } \ No newline at end of file diff --git a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts index 02e6acfa685..7339704fc65 100644 --- a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts +++ b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts @@ -1,4 +1,4 @@ -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts index 0eac581bfe4..176c2043344 100644 --- a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts +++ b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts @@ -1,5 +1,5 @@ // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts b/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts index e5118d18551..13f5ce14e7d 100644 --- a/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts +++ b/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts @@ -1,7 +1,7 @@ // @target: es5 // Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without () -var temp; +var temp: any; delete --temp ** 3; delete ++temp ** 3; diff --git a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts index de5dbf6d747..91db91a3a9b 100644 --- a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts +++ b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts @@ -1,4 +1,4 @@ -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts index 467a750b418..30b8df4268a 100644 --- a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts +++ b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts @@ -1,5 +1,5 @@ // expected error for all the LHS of assignments -var value; +var value: any; // this class C { diff --git a/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts b/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts index 62311ee75c9..8eb50d2f64a 100644 --- a/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts +++ b/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts @@ -1,7 +1,7 @@ // @allowUnusedLabels: true // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts index 4ca37129f60..f8efeb81ecb 100644 --- a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts @@ -1,7 +1,7 @@ // -- operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts index 10dc05a4a33..d5dd62de442 100644 --- a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts +++ b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts @@ -1,5 +1,5 @@ // -- operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} @@ -10,7 +10,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts index f1fa058745f..09f272442e1 100644 --- a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts @@ -1,7 +1,7 @@ // ++ operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts index 2e6b14d7727..397024d45d6 100644 --- a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts +++ b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts @@ -1,5 +1,5 @@ // ++ operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = [1, 2]; var obj: () => {} @@ -10,7 +10,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts b/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts index 189f1f000d8..d29b1a845eb 100644 --- a/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts @@ -1,7 +1,7 @@ // - operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = { x: "", y: () => { }}; @@ -12,7 +12,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/cases/conformance/externalModules/multipleExportDefault1.ts b/tests/cases/conformance/externalModules/multipleExportDefault1.ts new file mode 100644 index 00000000000..623cc2acc20 --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault1.ts @@ -0,0 +1,7 @@ +export default function Foo (){ + +} + +export default { + uhoh: "another default", +}; diff --git a/tests/cases/conformance/externalModules/multipleExportDefault2.ts b/tests/cases/conformance/externalModules/multipleExportDefault2.ts new file mode 100644 index 00000000000..0e14b570aa1 --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault2.ts @@ -0,0 +1,6 @@ +export default { + uhoh: "another default", +}; + +export default function Foo() { } + diff --git a/tests/cases/conformance/externalModules/multipleExportDefault3.ts b/tests/cases/conformance/externalModules/multipleExportDefault3.ts new file mode 100644 index 00000000000..3b5460e8141 --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault3.ts @@ -0,0 +1,6 @@ +export default { + uhoh: "another default", +}; + +export default class C { } + diff --git a/tests/cases/conformance/externalModules/multipleExportDefault4.ts b/tests/cases/conformance/externalModules/multipleExportDefault4.ts new file mode 100644 index 00000000000..6181c360798 --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault4.ts @@ -0,0 +1,5 @@ +export default class C { } + +export default { + uhoh: "another default", +}; \ No newline at end of file diff --git a/tests/cases/conformance/externalModules/multipleExportDefault5.ts b/tests/cases/conformance/externalModules/multipleExportDefault5.ts new file mode 100644 index 00000000000..d2b67fce46f --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault5.ts @@ -0,0 +1,2 @@ +export default function bar() { } +export default class C {} \ No newline at end of file diff --git a/tests/cases/conformance/externalModules/multipleExportDefault6.ts b/tests/cases/conformance/externalModules/multipleExportDefault6.ts new file mode 100644 index 00000000000..889ae64376b --- /dev/null +++ b/tests/cases/conformance/externalModules/multipleExportDefault6.ts @@ -0,0 +1,7 @@ +export default { + lol: 1 +} + +export default { + lol: 2 +} \ No newline at end of file diff --git a/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx b/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx index b3d3d34020a..deb7ba57b5d 100644 --- a/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx +++ b/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx @@ -4,7 +4,7 @@ declare module JSX { interface Element { isElement; } } -var T, T1, T2; +var T: any, T1: any, T2: any; // This is an element var x1 = () => {}; diff --git a/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser537152.ts b/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser537152.ts deleted file mode 100644 index d418f92b7ec..00000000000 --- a/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser537152.ts +++ /dev/null @@ -1,2 +0,0 @@ -var t; -var y = t.e1; diff --git a/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts b/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts index 1ff19b3e412..89cc0314d36 100644 --- a/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts +++ b/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts @@ -14,7 +14,7 @@ for (var x in fn()) { } for (var x in /[a-z]/) { } for (var x in new Date()) { } -var c, d, e; +var c: any, d: any, e: any; for (var x in c || d) { } for (var x in e ? c : d) { } diff --git a/tests/cases/fourslash/completionForStringLiteralRelativeImport1.ts b/tests/cases/fourslash/completionForStringLiteralRelativeImport1.ts deleted file mode 100644 index 3ba82fb0acf..00000000000 --- a/tests/cases/fourslash/completionForStringLiteralRelativeImport1.ts +++ /dev/null @@ -1,70 +0,0 @@ -/// - -// Should give completions for ts files when allowJs is false - -// @Filename: test0.ts -//// import * as foo1 from "./*import_as0*/ -//// import * as foo2 from ".//*import_as1*/ -//// import * as foo4 from "./folder//*import_as2*/ - -//// import foo6 = require("./*import_equals0*/ -//// import foo7 = require(".//*import_equals1*/ -//// import foo9 = require("./folder//*import_equals2*/ - -//// var foo11 = require("./*require0*/ -//// var foo12 = require(".//*require1*/ -//// var foo14 = require("./folder//*require2*/ - -// @Filename: parentTest/sub/test5.ts -//// import * as foo16 from "../g/*import_as3*/ -//// import foo17 = require("../g/*import_equals3*/ -//// var foo18 = require("../g/*require3*/ - - -// @Filename: f1.ts -//// /*f1*/ -// @Filename: f1.js -//// /*f1j*/ -// @Filename: f1.d.ts -//// /*f1d*/ -// @Filename: f2.tsx -//// /f2*/ -// @Filename: f3.js -//// /*f3*/ -// @Filename: f4.jsx -//// /*f4*/ -// @Filename: e1.ts -//// /*e1*/ -// @Filename: folder/f3.ts -//// /*subf1*/ -// @Filename: folder/h1.ts -//// /*subh1*/ -// @Filename: parentTest/f4.ts -//// /*parentf1*/ -// @Filename: parentTest/g1.ts -//// /*parentg1*/ -const kinds = ["import_as", "import_equals", "require"]; - -for (const kind of kinds) { - goTo.marker(kind + "0"); - verify.completionListIsEmpty(); - - goTo.marker(kind + "1"); - verify.completionListContains("f1"); - verify.completionListContains("f2"); - verify.completionListContains("e1"); - verify.completionListContains("folder"); - verify.completionListContains("parentTest"); - verify.not.completionListItemsCountIsGreaterThan(5); - - goTo.marker(kind + "2"); - verify.completionListContains("f3"); - verify.completionListContains("h1"); - verify.not.completionListItemsCountIsGreaterThan(2); - - goTo.marker(kind + "3"); - verify.completionListContains("f4"); - verify.completionListContains("g1"); - verify.completionListContains("sub"); - verify.not.completionListItemsCountIsGreaterThan(3); -} \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralRelativeImportAllowJSFalse.ts b/tests/cases/fourslash/completionForStringLiteralRelativeImportAllowJSFalse.ts new file mode 100644 index 00000000000..f343ce8699b --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralRelativeImportAllowJSFalse.ts @@ -0,0 +1,72 @@ +/// + +// Should give completions for ts files only when allowJs is false. + +// @Filename: test0.ts +//// import * as foo1 from "./*import_as0*/ +//// import * as foo2 from ".//*import_as1*/ +//// import * as foo4 from "./d1//*import_as2*/ + +//// import foo6 = require("./*import_equals0*/ +//// import foo7 = require(".//*import_equals1*/ +//// import foo9 = require("./d1//*import_equals2*/ + +//// var foo11 = require("./*require0*/ +//// var foo12 = require(".//*require1*/ +//// var foo14 = require("./d1//*require2*/ + +// @Filename: d2/d3/test1.ts +//// import * as foo16 from "..//*import_as3*/ +//// import foo17 = require("..//*import_equals3*/ +//// var foo18 = require("..//*require3*/ + + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f2.js +//// /*f2*/ +// @Filename: f3.d.ts +//// /*f3*/ +// @Filename: f4.tsx +//// /f4*/ +// @Filename: f5.js +//// /*f5*/ +// @Filename: f6.jsx +//// /*f6*/ +// @Filename: f7.ts +//// /*f7*/ +// @Filename: d1/f8.ts +//// /*d1f1*/ +// @Filename: d1/f9.ts +//// /*d1f9*/ +// @Filename: d2/f10.ts +//// /*d2f1*/ +// @Filename: d2/f11.ts +//// /*d2f11*/ + +const kinds = ["import_as", "import_equals", "require"]; + +for (const kind of kinds) { + goTo.marker(kind + "0"); + verify.completionListIsEmpty(); + + goTo.marker(kind + "1"); + verify.completionListContains("f1"); + verify.completionListContains("f3"); + verify.completionListContains("f4"); + verify.completionListContains("f7"); + verify.completionListContains("d1"); + verify.completionListContains("d2"); + verify.not.completionListItemsCountIsGreaterThan(6); + + goTo.marker(kind + "2"); + verify.completionListContains("f8"); + verify.completionListContains("f9"); + verify.not.completionListItemsCountIsGreaterThan(2); + + goTo.marker(kind + "3"); + verify.completionListContains("f10"); + verify.completionListContains("f11"); + verify.completionListContains("d3"); + verify.not.completionListItemsCountIsGreaterThan(3); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralRelativeImport2.ts b/tests/cases/fourslash/completionForStringLiteralRelativeImportAllowJSTrue.ts similarity index 51% rename from tests/cases/fourslash/completionForStringLiteralRelativeImport2.ts rename to tests/cases/fourslash/completionForStringLiteralRelativeImportAllowJSTrue.ts index 18a80ab3481..6eab9aaeca2 100644 --- a/tests/cases/fourslash/completionForStringLiteralRelativeImport2.ts +++ b/tests/cases/fourslash/completionForStringLiteralRelativeImportAllowJSTrue.ts @@ -1,6 +1,6 @@ /// -// Should give completions for ts and js files when allowJs is true +// Should give completions for ts and js files when allowJs is true. // @allowJs: true @@ -16,38 +16,33 @@ // @Filename: f1.ts //// /f1*/ -// @Filename: f1.js -//// /*f1j*/ -// @Filename: f1.d.ts -//// /*f1d*/ -// @Filename: f2.tsx +// @Filename: f2.js //// /*f2*/ -// @Filename: f3.js +// @Filename: f3.d.ts //// /*f3*/ -// @Filename: f4.jsx +// @Filename: f4.tsx //// /*f4*/ -// @Filename: e1.ts -//// /*e1*/ -// @Filename: e2.js -//// /*e2*/ +// @Filename: f5.js +//// /*f5*/ +// @Filename: f6.jsx +//// /*f6*/ +// @Filename: g1.ts +//// /*g1*/ +// @Filename: g2.js +//// /*g2*/ const kinds = ["import_as", "import_equals", "require"]; for (const kind of kinds) { - goTo.marker(kind + "0"); + for(let i = 0; i < 2; ++i) { + goTo.marker(kind + i); verify.completionListContains("f1"); verify.completionListContains("f2"); verify.completionListContains("f3"); verify.completionListContains("f4"); - verify.completionListContains("e1"); - verify.completionListContains("e2"); - verify.not.completionListItemsCountIsGreaterThan(6); - - goTo.marker(kind + "1"); - verify.completionListContains("f1"); - verify.completionListContains("f2"); - verify.completionListContains("f3"); - verify.completionListContains("f4"); - verify.completionListContains("e1"); - verify.completionListContains("e2"); - verify.not.completionListItemsCountIsGreaterThan(6); + verify.completionListContains("f5"); + verify.completionListContains("f6"); + verify.completionListContains("g1"); + verify.completionListContains("g2"); + verify.not.completionListItemsCountIsGreaterThan(8); + } } \ No newline at end of file diff --git a/tests/cases/fourslash/completionForTripleSlashReference1.ts b/tests/cases/fourslash/completionForTripleSlashReference1.ts deleted file mode 100644 index 2ce4de2e72e..00000000000 --- a/tests/cases/fourslash/completionForTripleSlashReference1.ts +++ /dev/null @@ -1,51 +0,0 @@ -/// - -// Should give completions for relative references to ts files when allowJs is false - -// @Filename: test0.ts -//// /// -//// /// -// Should give completions for absolute paths +// Exercises completions for absolute paths. // @Filename: tests/test0.ts //// /// + +// Exercises whether completions are supplied, conditional on the caret position in the ref comment. + +// @Filename: f.ts +//// /*f*/ + +// @Filename: test.ts +//// /// /*7*/ + +for(let m = 0; m < 8; ++m) { + goTo.marker("" + m); + verify.not.completionListItemsCountIsGreaterThan(0); +} + +for(let m of ["8", "9"]) { + goTo.marker(m); + verify.completionListContains("f.ts"); + verify.not.completionListItemsCountIsGreaterThan(1); +} \ No newline at end of file diff --git a/tests/cases/fourslash/tripleSlashRefPathCompletionExtensionsAllowJSFalse.ts b/tests/cases/fourslash/tripleSlashRefPathCompletionExtensionsAllowJSFalse.ts new file mode 100644 index 00000000000..95a4cd01b60 --- /dev/null +++ b/tests/cases/fourslash/tripleSlashRefPathCompletionExtensionsAllowJSFalse.ts @@ -0,0 +1,31 @@ +/// + +// Should give completions for relative references to ts files only when allowJs is false. + +// @Filename: test0.ts +//// /// -// Should give completions for relative references to js and ts files when allowJs is true +// Should give completions for relative references to ts and js files when allowJs is true. // @allowJs: true // @Filename: test0.ts //// /// +//// /// + +// Exercises completions for hidden files (ie: those beginning with '.') + +// @Filename: f.ts +//// /*f*/ +// @Filename: .hidden.ts +//// /*hidden*/ + +// @Filename: test.ts +//// /// + +// Exercises how changes in the basename change the completions offered. +// They should have no effect, as filtering completions is the responsibility of the editor. + +// @Filename: f1.ts +//// /*f1*/ +// @Filename: f2.ts +//// /*f2*/ +// @Filename: d/g.ts +//// /*g*/ + +// @Filename: test.ts +//// /// + +// Exercises relative path completions going up and down 2 directories +// and the use of forward- and back-slashes and combinations thereof. + +// @Filename: f.ts +//// /*f1*/ +// @Filename: d1/g.ts +//// /*g1*/ +// @Filename: d1/d2/h.ts +//// /*h1*/ +// @Filename: d1/d2/d3/i.ts +//// /*i1*/ +// @Filename: d1/d2/d3/d4/j.ts +//// /*j1*/ + +// @Filename: d1/d2/test.ts +//// ///